checkpoint-tester.py revision 7489
15818Sgblack@eecs.umich.edu#! /usr/bin/env python 25818Sgblack@eecs.umich.edu 35818Sgblack@eecs.umich.edu# Copyright (c) 2010 Advanced Micro Devices, Inc. 45818Sgblack@eecs.umich.edu# All rights reserved. 55818Sgblack@eecs.umich.edu# 65818Sgblack@eecs.umich.edu# Redistribution and use in source and binary forms, with or without 75818Sgblack@eecs.umich.edu# modification, are permitted provided that the following conditions are 85818Sgblack@eecs.umich.edu# met: redistributions of source code must retain the above copyright 95818Sgblack@eecs.umich.edu# notice, this list of conditions and the following disclaimer; 105818Sgblack@eecs.umich.edu# redistributions in binary form must reproduce the above copyright 115818Sgblack@eecs.umich.edu# notice, this list of conditions and the following disclaimer in the 125818Sgblack@eecs.umich.edu# documentation and/or other materials provided with the distribution; 135818Sgblack@eecs.umich.edu# neither the name of the copyright holders nor the names of its 145818Sgblack@eecs.umich.edu# contributors may be used to endorse or promote products derived from 155818Sgblack@eecs.umich.edu# this software without specific prior written permission. 165818Sgblack@eecs.umich.edu# 175818Sgblack@eecs.umich.edu# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 185818Sgblack@eecs.umich.edu# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 195818Sgblack@eecs.umich.edu# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 205818Sgblack@eecs.umich.edu# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 215818Sgblack@eecs.umich.edu# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 225818Sgblack@eecs.umich.edu# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 235818Sgblack@eecs.umich.edu# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 245818Sgblack@eecs.umich.edu# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 255818Sgblack@eecs.umich.edu# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 265818Sgblack@eecs.umich.edu# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 275818Sgblack@eecs.umich.edu# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 285818Sgblack@eecs.umich.edu# 295818Sgblack@eecs.umich.edu# Author: Steve Reinhardt 305818Sgblack@eecs.umich.edu# 315818Sgblack@eecs.umich.edu 325818Sgblack@eecs.umich.edu# Basic test script for checkpointing. 335818Sgblack@eecs.umich.edu# 345818Sgblack@eecs.umich.edu# Given an M5 command and an interval (in ticks), this script will: 355818Sgblack@eecs.umich.edu# 1. Run the command, dumping periodic checkpoints at the given interval. 365818Sgblack@eecs.umich.edu# 2. Rerun the command for each pair of adjacent checkpoints: 375818Sgblack@eecs.umich.edu# a. Restore from checkpoint N 385818Sgblack@eecs.umich.edu# b. Run until the timestamp of checkpoint N+1 395818Sgblack@eecs.umich.edu# c. Dump a checkpoint and end the simulation 405818Sgblack@eecs.umich.edu# d. Diff the new checkpoint with the original checkpoint N+1 415818Sgblack@eecs.umich.edu# 425818Sgblack@eecs.umich.edu# Note that '--' must be used to separate the script options from the 435818Sgblack@eecs.umich.edu# M5 command line. 445818Sgblack@eecs.umich.edu# 455818Sgblack@eecs.umich.edu# Caveats: 465818Sgblack@eecs.umich.edu# 475818Sgblack@eecs.umich.edu# - This script relies on the checkpoint options implemented in 485818Sgblack@eecs.umich.edu# configs/common/Simulation.py, so it works with commands based on 495818Sgblack@eecs.umich.edu# the se.py and fs.py scripts in configs/example, but does not work 505818Sgblack@eecs.umich.edu# directly with the existing regression tests. 515818Sgblack@eecs.umich.edu# - Interleaving simulator and program output can cause discrepancies 525818Sgblack@eecs.umich.edu# in the file position checkpoint information since different runs 535818Sgblack@eecs.umich.edu# have different amount of simulator output. 545818Sgblack@eecs.umich.edu# - Probably lots more issues we don't even know about yet. 559808Sstever@gmail.com# 565818Sgblack@eecs.umich.edu# Examples: 575818Sgblack@eecs.umich.edu# 585818Sgblack@eecs.umich.edu# util/checkpoint-tester.py -i 400000 -- build/ALPHA_SE/m5.opt \ 595818Sgblack@eecs.umich.edu# configs/example/se.py -c tests/test-progs/hello/bin/alpha/tru64/hello \ 605818Sgblack@eecs.umich.edu# --output=progout --errout=progerr 617903Shestness@cs.utexas.edu# 627903Shestness@cs.utexas.edu# util/checkpoint-tester.py -i 200000000000 -- build/ALPHA_FS/m5.opt \ 637903Shestness@cs.utexas.edu# configs/example/fs.py --script tests/halt.sh 645818Sgblack@eecs.umich.edu# 655818Sgblack@eecs.umich.edu 667811Ssteve.reinhardt@amd.com 675818Sgblack@eecs.umich.eduimport os, sys, re 685818Sgblack@eecs.umich.eduimport subprocess 69import optparse 70 71parser = optparse.OptionParser() 72 73parser.add_option('-i', '--interval', type='int') 74parser.add_option('-d', '--directory', default='checkpoint-test') 75 76(options, args) = parser.parse_args() 77 78interval = options.interval 79 80if os.path.exists(options.directory): 81 print 'Error: test directory', options.directory, 'exists' 82 print ' Tester needs to create directory from scratch' 83 sys.exit(1) 84 85top_dir = options.directory 86os.mkdir(top_dir) 87 88cmd_echo = open(os.path.join(top_dir, 'command'), 'w') 89print >>cmd_echo, ' '.join(sys.argv) 90cmd_echo.close() 91 92m5_binary = args[0] 93 94options = args[1:] 95 96initial_args = ['--take-checkpoints', '%d,%d' % (interval, interval)] 97 98cptdir = os.path.join(top_dir, 'm5out') 99 100print '===> Running initial simulation.' 101subprocess.call([m5_binary] + ['-red', cptdir] + options + initial_args) 102 103dirs = os.listdir(cptdir) 104expr = re.compile('cpt\.([0-9]*)') 105cpts = [] 106for dir in dirs: 107 match = expr.match(dir) 108 if match: 109 cpts.append(int(match.group(1))) 110 111cpts.sort() 112 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. 117for 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) 129 diffout.close() 130 # print out the diff 131 diffout = open(diff_name) 132 print diffout.read(), 133 diffout.close() 134 135 136