tests: arch-power: Add 64-bit hello binaries
[gem5.git] / util / tracediff
1 #! /usr/bin/env perl
2 # Copyright (c) 2003-2007 The Regents of The University of Michigan
3 # All rights reserved.
4 #
5 # Redistribution and use in source and binary forms, with or without
6 # modification, are permitted provided that the following conditions are
7 # met: redistributions of source code must retain the above copyright
8 # notice, this list of conditions and the following disclaimer;
9 # redistributions in binary form must reproduce the above copyright
10 # notice, this list of conditions and the following disclaimer in the
11 # documentation and/or other materials provided with the distribution;
12 # neither the name of the copyright holders nor the names of its
13 # contributors may be used to endorse or promote products derived from
14 # this software without specific prior written permission.
15 #
16 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
28 # Script to simplify using rundiff on trace outputs from two
29 # invocations of m5. Takes a common m5 command line with embedded
30 # alternatives and executes the two alternative commands in separate
31 # subdirectories with output piped to rundiff.
32 #
33 # ******Note that you need to enable some trace flags in the args in order
34 # to do anything useful!******
35 #
36 # Script arguments are handled uniformly as follows:
37 # - If the argument does not contain a '|' character, it is appended
38 # to both command lines.
39 # - If the argument has a '|' character in it, the text on either side
40 # of the '|' is appended to the respective command lines. Note that
41 # you'll have to quote the arg or escape the '|' with a backslash
42 # so that the shell doesn't think you're doing a pipe.
43 # - Arguments with '#' characters are split at those characters,
44 # processed for alternatives ('|'s) as independent terms, then
45 # pasted back into a single argument (without the '#'s). (Sort of
46 # inspired by the C preprocessor '##' token pasting operator.)
47 #
48 # In other words, the arguments should look like the command line you
49 # want to run, with "|" used to list the alternatives for the parts
50 # that you want to differ between the two runs.
51 #
52 # For example:
53 #
54 # % tracediff m5.opt --opt1 '--opt2|--opt3' --opt4
55 # would compare these two runs:
56 # m5.opt --opt1 --opt2 --opt4
57 # m5.opt --opt1 --opt3 --opt4
58 #
59 # % tracediff 'path1|path2#/m5.opt' --opt1 --opt2
60 # would compare these two runs:
61 # path1/m5.opt --opt1 --opt2
62 # path2/m5.opt --opt1 --opt2
63 #
64 # If you want to add arguments to one run only, just put a '|' in with
65 # text only on one side ('--onlyOn1|'). You can do this with multiple
66 # arguments together too ('|-a -b -c' adds three args to the second
67 # run only).
68 #
69 # The '-n' argument to tracediff allows you to preview the two
70 # generated command lines without running them.
71 #
72
73 use FindBin;
74
75 $dryrun = 0;
76
77 if (@ARGV >= 1 && $ARGV[0] eq '-n') {
78 $dryrun = 1;
79 shift @ARGV;
80 }
81
82 if (@ARGV < 1) {
83 die "Usage: tracediff [-n] \"sim1|sim2\" [common-arg \"arg1|arg2\" ...]\n";
84 }
85
86 foreach $arg (@ARGV) {
87 $a1 = $a2 = '';
88 @subargs = split('#', $arg);
89 foreach $subarg (@subargs) {
90 if ($subarg eq '') {
91 next;
92 }
93 @pair = split('\|', $subarg, -1); # -1 enables null trailing fields
94 if (@pair == 1) {
95 $a1 .= $subarg;
96 $a2 .= $subarg;
97 } elsif (@pair == 2) {
98 $a1 .= $pair[0];
99 $a2 .= $pair[1];
100 } else {
101 print 'Parse error: too many |s in ', $arg, "\n";
102 exit(1);
103 }
104 }
105
106 push @cmd1, $a1;
107 push @cmd2, $a2;
108 }
109
110
111 if ($dryrun) {
112 print "CMD1: ", join(' ', @cmd1), "\n";
113 print "CMD2: ", join(' ', @cmd2), "\n";
114 exit(0);
115 }
116
117 # First two args are the two simulator binaries to compare
118 $sim1 = shift @cmd1;
119 $sim2 = shift @cmd2;
120
121 # Everything else is a simulator arg.
122 $args1 = join(' ', @cmd1);
123 $args2 = join(' ', @cmd2);
124
125 # Common mistake: if you don't set any debugflags this often isn't
126 # doing what you want.
127 if ($args1 !~ /--debug-flags/) {
128 print "****\n";
129 print "**** WARNING: no debug flags set... you may not be diffing much!\n";
130 print "****\n";
131 }
132
133 # Run individual invocations in separate dirs so output and intermediate
134 # files (particularly config.py and config.ini) don't conflict.
135 $dir1 = "tracediff-$$-1";
136 $dir2 = "tracediff-$$-2";
137 mkdir($dir1) or die "Can't create dir $dir1\n";
138 mkdir($dir2) or die "Can't create dir $dir2\n";
139
140 $cmd1 = "$sim1 -d $dir1 $args1 2>&1 |";
141 $cmd2 = "$sim2 -d $dir2 $args2 2>&1 |";
142
143 # Expect that rundiff is in the same dir as the tracediff script.
144 # FindBin figures that out for us.
145 $fullcmd = "$FindBin::Bin/rundiff '$cmd1' '$cmd2' 2>&1 > tracediff-$$.out";
146
147 print "Executing $fullcmd\n";
148 system($fullcmd);
149
150
151