SConscript revision 5228
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 314202Sbinkertn@umich.edu 322155SN/Aimport os 337768SAli.Saidi@ARM.comimport sys 347768SAli.Saidi@ARM.comimport glob 357768SAli.Saidi@ARM.comfrom SCons.Script.SConscript import SConsEnvironment 362178SN/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 472155SN/Adef check_test(target, source, env): 485865Sksewell@umich.edu """Check output from running test. 496181Sksewell@umich.edu 506181Sksewell@umich.edu Targets are as follows: 515865Sksewell@umich.edu target[0] : outdiff 523918Ssaidi@eecs.umich.edu target[1] : statsdiff 535865Sksewell@umich.edu target[2] : status 542623SN/A 553918Ssaidi@eecs.umich.edu """ 562155SN/A # make sure target files are all gone 572155SN/A for t in target: 582292SN/A if os.path.exists(t.abspath): 596181Sksewell@umich.edu Execute(Delete(t.abspath)) 606181Sksewell@umich.edu # Run diff on output & ref directories to find differences. 613918Ssaidi@eecs.umich.edu # Exclude m5stats.txt since we will use diff-out on that. 622292SN/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 653918Ssaidi@eecs.umich.edu '-I "^M5 started " ' + # for stderr file 662292SN/A '-I "^M5 executing on " ' + # for stderr file 672292SN/A '-I "^Simulation complete at" ' + # for stderr file 682766Sktlim@umich.edu '-I "^Listening for" ' + # for stderr file 692766Sktlim@umich.edu '-I "listening for remote gdb" ' + # for stderr file 702766Sktlim@umich.edu '--exclude=m5stats.txt --exclude=SCCS ' + 712921Sktlim@umich.edu '--exclude=${TARGETS[0].file} ' + 722921Sktlim@umich.edu '> ${TARGETS[0]}', target=target, source=source), None) 732766Sktlim@umich.edu print "===== Output differences =====" 742766Sktlim@umich.edu print contents(target[0]) 755529Snate@binkert.org # Run diff-out on m5stats.txt file 762766Sktlim@umich.edu status = Execute(env.subst('$DIFFOUT $SOURCES > ${TARGETS[1]}', 774762Snate@binkert.org target=target, source=source), 782155SN/A strfunction=None) 792155SN/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." 842766Sktlim@umich.edu else: 852155SN/A status_str = "FAILED!" 865865Sksewell@umich.edu f = file(str(target[2]), 'w') 872155SN/A print >>f, env.subst('${TARGETS[2].dir}', target=target, source=source), \ 882155SN/A status_str 892155SN/A f.close() 902155SN/A # done 912178SN/A return 0 922178SN/A 937756SAli.Saidi@ARM.comdef check_test_string(target, source, env): 942766Sktlim@umich.edu return env.subst("Comparing outputs in ${TARGETS[0].dir}.", 952178SN/A target=target, source=source) 962178SN/A 976994Snate@binkert.orgtestAction = env.Action(check_test, check_test_string) 982178SN/A 992766Sktlim@umich.edudef print_test(target, source, env): 1002766Sktlim@umich.edu print '***** ' + contents(source[0]) 1012766Sktlim@umich.edu return 0 1022788Sktlim@umich.edu 1032178SN/AprintAction = env.Action(print_test, strfunction = None) 1042733Sktlim@umich.edu 1052733Sktlim@umich.edu# Static vars for update_test: 1062817Sksewell@umich.edu# - long-winded message about ignored sources 1072733Sktlim@umich.eduignore_msg = ''' 1084486Sbinkertn@umich.eduNote: The following file(s) will not be copied. New non-standard 1094486Sbinkertn@umich.edu output files must be copied manually once before update_ref will 1104776Sgblack@eecs.umich.edu recognize them as outputs. Otherwise they are assumed to be 1114776Sgblack@eecs.umich.edu inputs and are ignored. 1128739Sgblack@eecs.umich.edu''' 1136365Sgblack@eecs.umich.edu# - reference files always needed 1144486Sbinkertn@umich.eduneeded_files = set(['stdout', 'stderr', 'm5stats.txt', 'config.ini']) 1154202Sbinkertn@umich.edu# - source files we always want to ignore 1164202Sbinkertn@umich.eduknown_ignores = set(['status', 'outdiff', 'statsdiff']) 1174202Sbinkertn@umich.edu 1188541Sgblack@eecs.umich.edudef update_test(target, source, env): 1194202Sbinkertn@umich.edu """Update reference test outputs. 1204202Sbinkertn@umich.edu 1214776Sgblack@eecs.umich.edu Target is phony. First two sources are the ref & new m5stats.txt 1228739Sgblack@eecs.umich.edu files, respectively. We actually copy everything in the 1236365Sgblack@eecs.umich.edu respective directories except the status & diff output files. 1244202Sbinkertn@umich.edu 1258777Sgblack@eecs.umich.edu """ 1264202Sbinkertn@umich.edu dest_dir = str(source[0].get_dir()) 1274202Sbinkertn@umich.edu src_dir = str(source[1].get_dir()) 1284202Sbinkertn@umich.edu dest_files = set(os.listdir(dest_dir)) 1295217Ssaidi@eecs.umich.edu src_files = set(os.listdir(src_dir)) 1304202Sbinkertn@umich.edu # Copy all of the required files plus any existing dest files. 1312155SN/A wanted_files = needed_files | dest_files 1324202Sbinkertn@umich.edu missing_files = wanted_files - src_files 1334776Sgblack@eecs.umich.edu if len(missing_files) > 0: 1344776Sgblack@eecs.umich.edu print " WARNING: the following file(s) are missing " \ 1354776Sgblack@eecs.umich.edu "and will not be updated:" 1364776Sgblack@eecs.umich.edu print " ", " ,".join(missing_files) 1372766Sktlim@umich.edu copy_files = wanted_files - missing_files 1384202Sbinkertn@umich.edu warn_ignored_files = (src_files - copy_files) - known_ignores 1398335Snate@binkert.org if len(warn_ignored_files) > 0: 1402733Sktlim@umich.edu print ignore_msg, 1412733Sktlim@umich.edu print " ", ", ".join(warn_ignored_files) 1422733Sktlim@umich.edu for f in copy_files: 1432733Sktlim@umich.edu if f in dest_files: 1442733Sktlim@umich.edu print " Replacing file", f 1452874Sktlim@umich.edu dest_files.remove(f) 1462874Sktlim@umich.edu else: 1472874Sktlim@umich.edu print " Creating new file", f 1484202Sbinkertn@umich.edu copyAction = Copy(os.path.join(dest_dir, f), os.path.join(src_dir, f)) 1492733Sktlim@umich.edu copyAction.strfunction = None 1505192Ssaidi@eecs.umich.edu Execute(copyAction) 1518335Snate@binkert.org return 0 1528335Snate@binkert.org 1538335Snate@binkert.orgdef update_test_string(target, source, env): 1548335Snate@binkert.org return env.subst("Updating ${SOURCES[0].dir} from ${SOURCES[1].dir}", 1558335Snate@binkert.org target=target, source=source) 1568335Snate@binkert.org 1578335Snate@binkert.orgupdateAction = env.Action(update_test, update_test_string) 1588335Snate@binkert.org 1598335Snate@binkert.orgdef test_builder(env, ref_dir): 1608335Snate@binkert.org """Define a test.""" 1618335Snate@binkert.org 1628335Snate@binkert.org (category, name, _ref, isa, opsys, config) = ref_dir.split('/') 1638335Snate@binkert.org assert(_ref == 'ref') 1648335Snate@binkert.org 1658335Snate@binkert.org # target path (where test output goes) is the same except without 1668335Snate@binkert.org # the 'ref' component 1678335Snate@binkert.org tgt_dir = os.path.join(category, name, isa, opsys, config) 1688335Snate@binkert.org 1698335Snate@binkert.org # prepend file name with tgt_dir 1708335Snate@binkert.org def tgt(f): 1718335Snate@binkert.org return os.path.join(tgt_dir, f) 1728335Snate@binkert.org 1738335Snate@binkert.org ref_stats = os.path.join(ref_dir, 'm5stats.txt') 1748335Snate@binkert.org new_stats = tgt('m5stats.txt') 1758471SGiacomo.Gabrielli@arm.com status_file = tgt('status') 1768335Snate@binkert.org 1778335Snate@binkert.org # Base command for running test. We mess around with indirectly 1785192Ssaidi@eecs.umich.edu # referring to files via SOURCES and TARGETS so that scons can 1798232Snate@binkert.org # mess with paths all it wants to and we still get the right 1808232Snate@binkert.org # files. 1818232Snate@binkert.org base_cmd = '${SOURCES[0]} -d $TARGET.dir ${SOURCES[1]} %s' % tgt_dir 1828300Schander.sudanthi@arm.com # stdout and stderr files 1838300Schander.sudanthi@arm.com cmd_stdout = '${TARGETS[0]}' 1845192Ssaidi@eecs.umich.edu cmd_stderr = '${TARGETS[1]}' 1858300Schander.sudanthi@arm.com 1868300Schander.sudanthi@arm.com # Prefix test run with batch job submission command if appropriate. 1876036Sksewell@umich.edu # Output redirection is also different for batch runs. 1888300Schander.sudanthi@arm.com # Batch command also supports timeout arg (in seconds, not minutes). 1898300Schander.sudanthi@arm.com timeout = 15 # used to be a param, probably should be again 190 if env['BATCH']: 191 cmd = [env['BATCH_CMD'], '-t', str(timeout * 60), 192 '-o', cmd_stdout, '-e', cmd_stderr, base_cmd] 193 else: 194 cmd = [base_cmd, '>', cmd_stdout, '2>', cmd_stderr] 195 196 env.Command([tgt('stdout'), tgt('stderr'), new_stats], 197 [env.M5Binary, 'run.py'], ' '.join(cmd)) 198 199 # order of targets is important... see check_test 200 env.Command([tgt('outdiff'), tgt('statsdiff'), status_file], 201 [ref_stats, new_stats], 202 testAction) 203 204 # phony target to echo status 205 if env['update_ref']: 206 p = env.Command(tgt('_update'), 207 [ref_stats, new_stats, status_file], 208 updateAction) 209 else: 210 p = env.Command(tgt('_print'), [status_file], printAction) 211 212 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