SConscript revision 8745
12139SN/A# -*- mode:python -*- 22139SN/A 32139SN/A# Copyright (c) 2004-2006 The Regents of The University of Michigan 42139SN/A# All rights reserved. 52139SN/A# 62139SN/A# Redistribution and use in source and binary forms, with or without 72139SN/A# modification, are permitted provided that the following conditions are 82139SN/A# met: redistributions of source code must retain the above copyright 92139SN/A# notice, this list of conditions and the following disclaimer; 102139SN/A# redistributions in binary form must reproduce the above copyright 112139SN/A# notice, this list of conditions and the following disclaimer in the 122139SN/A# documentation and/or other materials provided with the distribution; 132139SN/A# neither the name of the copyright holders nor the names of its 142139SN/A# contributors may be used to endorse or promote products derived from 152139SN/A# this software without specific prior written permission. 162139SN/A# 172139SN/A# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 182139SN/A# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 192139SN/A# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 202139SN/A# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 212139SN/A# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 222139SN/A# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 232139SN/A# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 242139SN/A# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 252139SN/A# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 262139SN/A# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 272139SN/A# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 282665Ssaidi@eecs.umich.edu# 292665Ssaidi@eecs.umich.edu# Authors: Steve Reinhardt 302139SN/A# Kevin Lim 314202Sbinkertn@umich.edu 322139SN/Aimport os, signal 334202Sbinkertn@umich.eduimport sys, time 342152SN/Aimport glob 352152SN/Afrom SCons.Script.SConscript import SConsEnvironment 362139SN/A 372139SN/AImport('env') 382139SN/A 392139SN/Aenv['DIFFOUT'] = File('diff-out') 402139SN/A 412152SN/A# Dict that accumulates lists of tests by category (quick, medium, long) 422152SN/Aenv.Tests = {} 432139SN/A 442139SN/Adef contents(node): 452139SN/A return file(str(node)).read() 462984Sgblack@eecs.umich.edu 472439SN/A# functions to parse return value from scons Execute()... not the same 483520Sgblack@eecs.umich.edu# as wait() etc., so python built-in os funcs don't work. 492139SN/Adef signaled(status): 503565Sgblack@eecs.umich.edu return (status & 0x80) != 0; 513170Sstever@eecs.umich.edu 523806Ssaidi@eecs.umich.edudef signum(status): 532439SN/A return (status & 0x7f); 544182Sgblack@eecs.umich.edu 552460SN/A# List of signals that indicate that we should retry the test rather 563536Sgblack@eecs.umich.edu# than consider it failed. 572439SN/Aretry_signals = (signal.SIGTERM, signal.SIGKILL, signal.SIGINT, 582972Sgblack@eecs.umich.edu signal.SIGQUIT, signal.SIGHUP) 592171SN/A 602439SN/A# regular expressions of lines to ignore when diffing outputs 612439SN/Aoutput_ignore_regexes = ( 622170SN/A '^command line:', # for stdout file 632139SN/A '^M5 compiled ', # for stderr file 642139SN/A '^M5 started ', # for stderr file 653546Sgblack@eecs.umich.edu '^M5 executing on ', # for stderr file 664202Sbinkertn@umich.edu '^Simulation complete at', # for stderr file 672152SN/A '^Listening for', # for stderr file 682152SN/A 'listening for remote gdb', # for stderr file 692152SN/A ) 702152SN/A 712152SN/Aoutput_ignore_args = ' '.join(["-I '"+s+"'" for s in output_ignore_regexes]) 722152SN/A 732152SN/Aoutput_ignore_args += ' --exclude=stats.txt --exclude=outdiff' 742152SN/A 752152SN/Adef run_test(target, source, env): 762152SN/A """Check output from running test. 772152SN/A 782152SN/A Targets are as follows: 792504SN/A target[0] : status 802504SN/A 812504SN/A Sources are: 822504SN/A source[0] : M5 binary 832152SN/A source[1] : tests/run.py script 842504SN/A source[2] : reference stats file 852152SN/A 862152SN/A """ 872152SN/A # make sure target files are all gone 882152SN/A for t in target: 892152SN/A if os.path.exists(t.abspath): 902152SN/A env.Execute(Delete(t.abspath)) 912152SN/A 922152SN/A tgt_dir = os.path.dirname(str(target[0])) 932632Sstever@eecs.umich.edu 942155SN/A # Base command for running test. We mess around with indirectly 952155SN/A # referring to files via SOURCES and TARGETS so that scons can mess 962155SN/A # with paths all it wants to and we still get the right files. 972155SN/A cmd = '${SOURCES[0]} -d %s -re ${SOURCES[1]} %s' % (tgt_dir, tgt_dir) 982155SN/A 992155SN/A # Prefix test run with batch job submission command if appropriate. 1004202Sbinkertn@umich.edu # Batch command also supports timeout arg (in seconds, not minutes). 1012155SN/A timeout = 15 * 60 # used to be a param, probably should be again 1022155SN/A if env['BATCH']: 1032155SN/A cmd = '%s -t %d %s' % (env['BATCH_CMD'], timeout, cmd) 1042152SN/A 1052766Sktlim@umich.edu pre_exec_time = time.time() 1062766Sktlim@umich.edu status = env.Execute(env.subst(cmd, target=target, source=source)) 1072766Sktlim@umich.edu if status == 0: 1082766Sktlim@umich.edu # M5 terminated normally. 1092766Sktlim@umich.edu # Run diff on output & ref directories to find differences. 1102152SN/A # Exclude the stats file since we will use diff-out on that. 1112152SN/A 1122152SN/A # NFS file systems can be annoying and not have updated yet 1132155SN/A # wait until we see the file modified 1142152SN/A statsdiff = os.path.join(tgt_dir, 'statsdiff') 1152152SN/A m_time = 0 1162718Sstever@eecs.umich.edu nap = 0 1172921Sktlim@umich.edu while m_time < pre_exec_time and nap < 10: 1182921Sktlim@umich.edu try: 1192921Sktlim@umich.edu m_time = os.stat(statsdiff).st_mtime 1202921Sktlim@umich.edu except OSError: 1212921Sktlim@umich.edu pass 1222921Sktlim@umich.edu time.sleep(1) 1232921Sktlim@umich.edu nap += 1 1242921Sktlim@umich.edu 1252921Sktlim@umich.edu outdiff = os.path.join(tgt_dir, 'outdiff') 1262152SN/A diffcmd = 'diff -ubrs %s ${SOURCES[2].dir} %s > %s' \ 1272152SN/A % (output_ignore_args, tgt_dir, outdiff) 128 env.Execute(env.subst(diffcmd, target=target, source=source)) 129 print "===== Output differences =====" 130 print contents(outdiff) 131 # Run diff-out on stats.txt file 132 diffcmd = '$DIFFOUT ${SOURCES[2]} %s > %s' \ 133 % (os.path.join(tgt_dir, 'stats.txt'), statsdiff) 134 diffcmd = env.subst(diffcmd, target=target, source=source) 135 status = env.Execute(diffcmd, strfunction=None) 136 print "===== Statistics differences =====" 137 print contents(statsdiff) 138 139 else: # m5 exit status != 0 140 # M5 did not terminate properly, so no need to check the output 141 if signaled(status): 142 print 'M5 terminated with signal', signum(status) 143 if signum(status) in retry_signals: 144 # Consider the test incomplete; don't create a 'status' output. 145 # Hand the return status to scons and let scons decide what 146 # to do about it (typically terminate unless run with -k). 147 return status 148 else: 149 print 'M5 exited with non-zero status', status 150 # complete but failed execution (call to exit() with non-zero 151 # status, SIGABORT due to assertion failure, etc.)... fall through 152 # and generate FAILED status as if output comparison had failed 153 154 # Generate status file contents based on exit status of m5 or diff-out 155 if status == 0: 156 status_str = "passed." 157 else: 158 status_str = "FAILED!" 159 f = file(str(target[0]), 'w') 160 print >>f, tgt_dir, status_str 161 f.close() 162 # done 163 return 0 164 165def run_test_string(target, source, env): 166 return env.subst("Running test in ${TARGETS[0].dir}.", 167 target=target, source=source) 168 169testAction = env.Action(run_test, run_test_string) 170 171def print_test(target, source, env): 172 print '***** ' + contents(source[0]) 173 return 0 174 175printAction = env.Action(print_test, strfunction = None) 176 177# Static vars for update_test: 178# - long-winded message about ignored sources 179ignore_msg = ''' 180Note: The following file(s) will not be copied. New non-standard 181 output files must be copied manually once before --update-ref will 182 recognize them as outputs. Otherwise they are assumed to be 183 inputs and are ignored. 184''' 185# - reference files always needed 186needed_files = set(['simout', 'simerr', 'stats.txt', 'config.ini']) 187# - source files we always want to ignore 188known_ignores = set(['status', 'outdiff', 'statsdiff']) 189 190def update_test(target, source, env): 191 """Update reference test outputs. 192 193 Target is phony. First two sources are the ref & new stats.txt file 194 files, respectively. We actually copy everything in the 195 respective directories except the status & diff output files. 196 197 """ 198 dest_dir = str(source[0].get_dir()) 199 src_dir = str(source[1].get_dir()) 200 dest_files = set(os.listdir(dest_dir)) 201 src_files = set(os.listdir(src_dir)) 202 # Copy all of the required files plus any existing dest files. 203 wanted_files = needed_files | dest_files 204 missing_files = wanted_files - src_files 205 if len(missing_files) > 0: 206 print " WARNING: the following file(s) are missing " \ 207 "and will not be updated:" 208 print " ", " ,".join(missing_files) 209 copy_files = wanted_files - missing_files 210 warn_ignored_files = (src_files - copy_files) - known_ignores 211 if len(warn_ignored_files) > 0: 212 print ignore_msg, 213 print " ", ", ".join(warn_ignored_files) 214 for f in copy_files: 215 if f in dest_files: 216 print " Replacing file", f 217 dest_files.remove(f) 218 else: 219 print " Creating new file", f 220 copyAction = Copy(os.path.join(dest_dir, f), os.path.join(src_dir, f)) 221 copyAction.strfunction = None 222 env.Execute(copyAction) 223 return 0 224 225def update_test_string(target, source, env): 226 return env.subst("Updating ${SOURCES[0].dir} from ${SOURCES[1].dir}", 227 target=target, source=source) 228 229updateAction = env.Action(update_test, update_test_string) 230 231def test_builder(env, ref_dir): 232 """Define a test.""" 233 234 (category, name, _ref, isa, opsys, config) = ref_dir.split('/') 235 assert(_ref == 'ref') 236 237 # target path (where test output goes) is the same except without 238 # the 'ref' component 239 tgt_dir = os.path.join(category, name, isa, opsys, config) 240 241 # prepend file name with tgt_dir 242 def tgt(f): 243 return os.path.join(tgt_dir, f) 244 245 ref_stats = os.path.join(ref_dir, 'stats.txt') 246 new_stats = tgt('stats.txt') 247 status_file = tgt('status') 248 249 env.Command([status_file], 250 [env.M5Binary, 'run.py', ref_stats], 251 testAction) 252 253 # phony target to echo status 254 if GetOption('update_ref'): 255 p = env.Command(tgt('_update'), 256 [ref_stats, new_stats, status_file], 257 updateAction) 258 else: 259 p = env.Command(tgt('_print'), [status_file], printAction) 260 261 env.AlwaysBuild(p) 262 263 264# Figure out applicable configs based on build type 265configs = [] 266if env['FULL_SYSTEM']: 267 if env['TARGET_ISA'] == 'alpha': 268 configs += ['tsunami-simple-atomic', 269 'tsunami-simple-timing', 270 'tsunami-simple-atomic-dual', 271 'tsunami-simple-timing-dual', 272 'twosys-tsunami-simple-atomic', 273 'tsunami-o3', 'tsunami-o3-dual', 274 'tsunami-inorder'] 275 if env['TARGET_ISA'] == 'sparc': 276 configs += ['t1000-simple-atomic', 277 't1000-simple-timing'] 278 if env['TARGET_ISA'] == 'arm': 279 configs += ['realview-simple-atomic', 280 'realview-simple-atomic-dual', 281 'realview-simple-timing', 282 'realview-simple-timing-dual', 283 'realview-o3', 284 'realview-o3-dual'] 285 if env['TARGET_ISA'] == 'x86': 286 configs += ['pc-simple-atomic', 287 'pc-simple-timing', 288 'pc-o3-timing'] 289 290else: 291 configs += ['simple-atomic', 'simple-timing', 'o3-timing', 'memtest', 292 'simple-atomic-mp', 'simple-timing-mp', 'o3-timing-mp', 293 'inorder-timing', 'rubytest'] 294 295if env['PROTOCOL'] != 'None': 296 if env['PROTOCOL'] == 'MI_example': 297 configs += [c + "-ruby" for c in configs] 298 else: 299 configs = [c + "-ruby-" + env['PROTOCOL'] for c in configs] 300 301cwd = os.getcwd() 302os.chdir(str(Dir('.').srcdir)) 303for config in configs: 304 dirs = glob.glob('*/*/ref/%s/*/%s' % (env['TARGET_ISA'], config)) 305 for d in dirs: 306 if not os.path.exists(os.path.join(d, 'skip')): 307 test_builder(env, d) 308os.chdir(cwd) 309