SConscript revision 5299
12155SN/A# -*- mode:python -*- 22155SN/A 32155SN/A# Copyright (c) 2004-2006 The Regents of The University of Michigan 42155SN/A# All rights reserved. 52155SN/A# 62155SN/A# Redistribution and use in source and binary forms, with or without 72155SN/A# modification, are permitted provided that the following conditions are 82155SN/A# met: redistributions of source code must retain the above copyright 92155SN/A# notice, this list of conditions and the following disclaimer; 102155SN/A# redistributions in binary form must reproduce the above copyright 112155SN/A# notice, this list of conditions and the following disclaimer in the 122155SN/A# documentation and/or other materials provided with the distribution; 132155SN/A# neither the name of the copyright holders nor the names of its 142155SN/A# contributors may be used to endorse or promote products derived from 152155SN/A# this software without specific prior written permission. 162155SN/A# 172155SN/A# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 182155SN/A# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 192155SN/A# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 202155SN/A# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 212155SN/A# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 222155SN/A# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 232155SN/A# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 242155SN/A# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 252155SN/A# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 262155SN/A# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 272155SN/A# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 282665Ssaidi@eecs.umich.edu# 292665Ssaidi@eecs.umich.edu# Authors: Steve Reinhardt 302155SN/A# Kevin Lim 312155SN/A 322155SN/Aimport os 332155SN/Aimport sys 342155SN/Aimport glob 352155SN/Afrom SCons.Script.SConscript import SConsEnvironment 362155SN/A 372178SN/AImport('env') 382178SN/A 392178SN/Aenv['DIFFOUT'] = File('diff-out') 402178SN/A 412178SN/A# Dict that accumulates lists of tests by category (quick, medium, long) 422178SN/Aenv.Tests = {} 432178SN/A 442178SN/Adef contents(node): 452178SN/A return file(str(node)).read() 462178SN/A 472178SN/Adef check_test(target, source, env): 482178SN/A """Check output from running test. 492155SN/A 502178SN/A Targets are as follows: 512155SN/A target[0] : outdiff 522155SN/A target[1] : statsdiff 532178SN/A target[2] : status 542155SN/A 552155SN/A """ 562623SN/A # make sure target files are all gone 572623SN/A for t in target: 582623SN/A if os.path.exists(t.abspath): 592623SN/A Execute(Delete(t.abspath)) 602623SN/A # Run diff on output & ref directories to find differences. 612155SN/A # Exclude m5stats.txt since we will use diff-out on that. 622155SN/A Execute(env.subst('diff -ubr ${SOURCES[0].dir} ${SOURCES[1].dir} ' + 632292SN/A '-I "^command line:" ' + # for stdout file 642292SN/A '-I "^M5 compiled " ' + # for stderr file 652292SN/A '-I "^M5 started " ' + # for stderr file 662292SN/A '-I "^M5 executing on " ' + # for stderr file 672292SN/A '-I "^Simulation complete at" ' + # for stderr file 682292SN/A '-I "^Listening for" ' + # for stderr file 692292SN/A '-I "listening for remote gdb" ' + # for stderr file 702292SN/A '--exclude=m5stats.txt --exclude=SCCS ' + 712766Sktlim@umich.edu '--exclude=${TARGETS[0].file} ' + 722766Sktlim@umich.edu '> ${TARGETS[0]}', target=target, source=source), None) 732766Sktlim@umich.edu print "===== Output differences =====" 742921Sktlim@umich.edu print contents(target[0]) 752921Sktlim@umich.edu # Run diff-out on m5stats.txt file 762766Sktlim@umich.edu status = Execute(env.subst('$DIFFOUT $SOURCES > ${TARGETS[1]}', 772766Sktlim@umich.edu target=target, source=source), 782766Sktlim@umich.edu strfunction=None) 792178SN/A print "===== Statistics differences =====" 802155SN/A print contents(target[1]) 812155SN/A # Generate status file contents based on exit status of diff-out 822155SN/A if status == 0: 832155SN/A status_str = "passed." 842155SN/A else: 852155SN/A status_str = "FAILED!" 862766Sktlim@umich.edu f = file(str(target[2]), 'w') 872155SN/A print >>f, env.subst('${TARGETS[2].dir}', target=target, source=source), \ 882623SN/A status_str 892155SN/A f.close() 902155SN/A # done 912155SN/A return 0 922155SN/A 932178SN/Adef check_test_string(target, source, env): 942178SN/A return env.subst("Comparing outputs in ${TARGETS[0].dir}.", 952178SN/A target=target, source=source) 962766Sktlim@umich.edu 972178SN/AtestAction = env.Action(check_test, check_test_string) 982178SN/A 992178SN/Adef print_test(target, source, env): 1002178SN/A print '***** ' + contents(source[0]) 1012766Sktlim@umich.edu return 0 1022766Sktlim@umich.edu 1032766Sktlim@umich.eduprintAction = env.Action(print_test, strfunction = None) 1042788Sktlim@umich.edu 1052178SN/A# Static vars for update_test: 1062733Sktlim@umich.edu# - long-winded message about ignored sources 1072733Sktlim@umich.eduignore_msg = ''' 1082817Sksewell@umich.eduNote: The following file(s) will not be copied. New non-standard 1092733Sktlim@umich.edu output files must be copied manually once before update_ref will 1102178SN/A recognize them as outputs. Otherwise they are assumed to be 1112178SN/A inputs and are ignored. 1122178SN/A''' 1132178SN/A# - reference files always needed 1142178SN/Aneeded_files = set(['stdout', 'stderr', 'm5stats.txt', 'config.ini']) 1152178SN/A# - source files we always want to ignore 1162155SN/Aknown_ignores = set(['status', 'outdiff', 'statsdiff']) 1172929Sktlim@umich.edu 1182929Sktlim@umich.edudef update_test(target, source, env): 1192929Sktlim@umich.edu """Update reference test outputs. 1202155SN/A 1212155SN/A Target is phony. First two sources are the ref & new m5stats.txt 1222623SN/A files, respectively. We actually copy everything in the 1232623SN/A respective directories except the status & diff output files. 1242623SN/A 1252623SN/A """ 1262623SN/A dest_dir = str(source[0].get_dir()) 1272623SN/A src_dir = str(source[1].get_dir()) 1282623SN/A dest_files = set(os.listdir(dest_dir)) 1292623SN/A src_files = set(os.listdir(src_dir)) 1302623SN/A # Copy all of the required files plus any existing dest files. 1312623SN/A wanted_files = needed_files | dest_files 1322623SN/A missing_files = wanted_files - src_files 1332155SN/A if len(missing_files) > 0: 1342155SN/A print " WARNING: the following file(s) are missing " \ 1352155SN/A "and will not be updated:" 1362155SN/A print " ", " ,".join(missing_files) 1372821Sktlim@umich.edu copy_files = wanted_files - missing_files 1382817Sksewell@umich.edu warn_ignored_files = (src_files - copy_files) - known_ignores 1392821Sktlim@umich.edu if len(warn_ignored_files) > 0: 1402817Sksewell@umich.edu print ignore_msg, 1412155SN/A print " ", ", ".join(warn_ignored_files) 1422765Sktlim@umich.edu for f in copy_files: 1432155SN/A if f in dest_files: 1442155SN/A print " Replacing file", f 1452155SN/A dest_files.remove(f) 1462155SN/A else: 1472155SN/A print " Creating new file", f 1482292SN/A copyAction = Copy(os.path.join(dest_dir, f), os.path.join(src_dir, f)) 1492155SN/A copyAction.strfunction = None 1502155SN/A Execute(copyAction) 1512155SN/A return 0 1522292SN/A 1532292SN/Adef update_test_string(target, source, env): 1542155SN/A return env.subst("Updating ${SOURCES[0].dir} from ${SOURCES[1].dir}", 1552155SN/A target=target, source=source) 1562155SN/A 1572155SN/AupdateAction = env.Action(update_test, update_test_string) 1582292SN/A 1592155SN/Adef test_builder(env, ref_dir): 1602155SN/A """Define a test.""" 1612766Sktlim@umich.edu 1622765Sktlim@umich.edu (category, name, _ref, isa, opsys, config) = ref_dir.split('/') 1632932Sktlim@umich.edu assert(_ref == 'ref') 1642932Sktlim@umich.edu 1652155SN/A # target path (where test output goes) is the same except without 1662792Sktlim@umich.edu # the 'ref' component 1672821Sktlim@umich.edu tgt_dir = os.path.join(category, name, isa, opsys, config) 1682292SN/A 1692792Sktlim@umich.edu # prepend file name with tgt_dir 1702792Sktlim@umich.edu def tgt(f): 1712292SN/A return os.path.join(tgt_dir, f) 1722292SN/A 1732292SN/A ref_stats = os.path.join(ref_dir, 'm5stats.txt') 1742292SN/A new_stats = tgt('m5stats.txt') 1752297SN/A status_file = tgt('status') 1762297SN/A 1772792Sktlim@umich.edu # Base command for running test. We mess around with indirectly 1782292SN/A # referring to files via SOURCES and TARGETS so that scons can 1792766Sktlim@umich.edu # mess with paths all it wants to and we still get the right 1802765Sktlim@umich.edu # files. 1812292SN/A base_cmd = '${SOURCES[0]} -d $TARGET.dir ${SOURCES[1]} %s' % tgt_dir 1822821Sktlim@umich.edu # stdout and stderr files 1832821Sktlim@umich.edu cmd_stdout = '${TARGETS[0]}' 1842821Sktlim@umich.edu cmd_stderr = '${TARGETS[1]}' 1852821Sktlim@umich.edu 1862821Sktlim@umich.edu # Prefix test run with batch job submission command if appropriate. 1872821Sktlim@umich.edu # Output redirection is also different for batch runs. 1882821Sktlim@umich.edu # Batch command also supports timeout arg (in seconds, not minutes). 1892821Sktlim@umich.edu timeout = 15 # used to be a param, probably should be again 1902766Sktlim@umich.edu if env['BATCH']: 1912789Sktlim@umich.edu cmd = [env['BATCH_CMD'], '-t', str(timeout * 60), 1922733Sktlim@umich.edu '-o', cmd_stdout, '-e', cmd_stderr, base_cmd] 1932733Sktlim@umich.edu else: 1942733Sktlim@umich.edu cmd = [base_cmd, '>', cmd_stdout, '2>', cmd_stderr] 1952733Sktlim@umich.edu 1962733Sktlim@umich.edu env.Command([tgt('stdout'), tgt('stderr'), new_stats], 1972874Sktlim@umich.edu [env.M5Binary, 'run.py'], ' '.join(cmd)) 1982874Sktlim@umich.edu 1992874Sktlim@umich.edu # order of targets is important... see check_test 2002874Sktlim@umich.edu env.Command([tgt('outdiff'), tgt('statsdiff'), status_file], 2012733Sktlim@umich.edu [ref_stats, new_stats], 2022733Sktlim@umich.edu testAction) 2032315SN/A 2042761Sstever@eecs.umich.edu # phony target to echo status 2052155SN/A if env['update_ref']: 2062155SN/A p = env.Command(tgt('_update'), 2072155SN/A [ref_stats, new_stats, status_file], 2082155SN/A updateAction) 2092155SN/A else: 2102155SN/A p = env.Command(tgt('_print'), [status_file], printAction) 2112155SN/A 2122155SN/A env.AlwaysBuild(p) 213 214 215# Figure out applicable configs based on build type 216configs = [] 217if env['FULL_SYSTEM']: 218 if env['TARGET_ISA'] == 'alpha': 219 if not env['ALPHA_TLASER']: 220 configs += ['tsunami-simple-atomic', 221 'tsunami-simple-timing', 222 'tsunami-simple-atomic-dual', 223 'tsunami-simple-timing-dual', 224 'twosys-tsunami-simple-atomic'] 225 if env['TARGET_ISA'] == 'sparc': 226 configs += ['t1000-simple-atomic', 227 't1000-simple-timing'] 228 229else: 230 configs += ['simple-atomic', 'simple-timing', 'o3-timing', 'memtest'] 231 232cwd = os.getcwd() 233os.chdir(str(Dir('.').srcdir)) 234for config in configs: 235 dirs = glob.glob('*/*/ref/%s/*/%s' % (env['TARGET_ISA'], config)) 236 for d in dirs: 237 test_builder(env, d) 238os.chdir(cwd) 239