3 # Copyright (c) 2010 Advanced Micro Devices, Inc.
6 # Redistribution and use in source and binary forms, with or without
7 # modification, are permitted provided that the following conditions are
8 # met: redistributions of source code must retain the above copyright
9 # notice, this list of conditions and the following disclaimer;
10 # redistributions in binary form must reproduce the above copyright
11 # notice, this list of conditions and the following disclaimer in the
12 # documentation and/or other materials provided with the distribution;
13 # neither the name of the copyright holders nor the names of its
14 # contributors may be used to endorse or promote products derived from
15 # this software without specific prior written permission.
17 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 # Author: Steve Reinhardt
32 # Basic test script for checkpointing.
34 # Given an M5 command and an interval (in ticks), this script will:
35 # 1. Run the command, dumping periodic checkpoints at the given interval.
36 # 2. Rerun the command for each pair of adjacent checkpoints:
37 # a. Restore from checkpoint N
38 # b. Run until the timestamp of checkpoint N+1
39 # c. Dump a checkpoint and end the simulation
40 # d. Diff the new checkpoint with the original checkpoint N+1
42 # Note that '--' must be used to separate the script options from the
47 # - This script relies on the checkpoint options implemented in
48 # configs/common/Simulation.py, so it works with commands based on
49 # the se.py and fs.py scripts in configs/example, but does not work
50 # directly with the existing regression tests.
51 # - Interleaving simulator and program output can cause discrepancies
52 # in the file position checkpoint information since different runs
53 # have different amount of simulator output.
54 # - Probably lots more issues we don't even know about yet.
58 # util/checkpoint-tester.py -i 400000 -- build/ALPHA_SE/m5.opt \
59 # configs/example/se.py -c tests/test-progs/hello/bin/alpha/tru64/hello \
60 # --output=progout --errout=progerr
62 # util/checkpoint-tester.py -i 200000000000 -- build/ALPHA_FS/m5.opt \
63 # configs/example/fs.py --script tests/halt.sh
71 parser
= optparse
.OptionParser()
73 parser
.add_option('-i', '--interval', type='int')
74 parser
.add_option('-d', '--directory', default
='checkpoint-test')
76 (options
, args
) = parser
.parse_args()
78 interval
= options
.interval
80 if os
.path
.exists(options
.directory
):
81 print 'Error: test directory', options
.directory
, 'exists'
82 print ' Tester needs to create directory from scratch'
85 top_dir
= options
.directory
88 cmd_echo
= open(os
.path
.join(top_dir
, 'command'), 'w')
89 print >>cmd_echo
, ' '.join(sys
.argv
)
96 initial_args
= ['--take-checkpoints', '%d,%d' % (interval
, interval
)]
98 cptdir
= os
.path
.join(top_dir
, 'm5out')
100 print '===> Running initial simulation.'
101 subprocess
.call([m5_binary
] + ['-red', cptdir
] + options
+ initial_args
)
103 dirs
= os
.listdir(cptdir
)
104 expr
= re
.compile('cpt\.([0-9]*)')
107 match
= expr
.match(dir)
109 cpts
.append(int(match
.group(1)))
113 # We test by loading checkpoint N, simulating to (and dumping at)
114 # checkpoint N+1, then comparing the resulting checkpoint with the
115 # original checkpoint N+1. Thus the number of tests we can run is one
116 # less than tha number of checkpoints.
117 for i
in range(1, len(cpts
)):
118 print '===> Running test %d of %d.' % (i
, len(cpts
)-1)
119 mydir
= os
.path
.join(top_dir
, 'test.%d' % i
)
120 subprocess
.call([m5_binary
] + ['-red', mydir
] + options
+ initial_args
+
121 ['--max-checkpoints' , '1', '--checkpoint-dir', cptdir
,
122 '--checkpoint-restore', str(i
)])
123 cpt_name
= 'cpt.%d' % cpts
[i
]
124 diff_name
= os
.path
.join(mydir
, 'diffout')
125 diffout
= open(diff_name
, 'w')
126 subprocess
.call(['diff', '-ru', '-I', '^##.*',
127 '%s/%s' % (cptdir
, cpt_name
),
128 '%s/%s' % (mydir
, cpt_name
)], stdout
=diffout
)
131 diffout
= open(diff_name
)
132 print diffout
.read(),