SConscript revision 4776
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 332178SN/Aimport sys 342178SN/Aimport glob 352178SN/Afrom 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 442155SN/Adef contents(node): 455865Sksewell@umich.edu return file(str(node)).read() 466181Sksewell@umich.edu 476181Sksewell@umich.edudef check_test(target, source, env): 485865Sksewell@umich.edu """Check output from running test. 493918Ssaidi@eecs.umich.edu 505865Sksewell@umich.edu Targets are as follows: 512623SN/A target[0] : outdiff 523918Ssaidi@eecs.umich.edu target[1] : statsdiff 532155SN/A target[2] : status 542155SN/A 552292SN/A """ 566181Sksewell@umich.edu # make sure target files are all gone 576181Sksewell@umich.edu for t in target: 583918Ssaidi@eecs.umich.edu if os.path.exists(t.abspath): 592292SN/A Execute(Delete(t.abspath)) 602292SN/A # Run diff on output & ref directories to find differences. 612292SN/A # Exclude m5stats.txt since we will use diff-out on that. 623918Ssaidi@eecs.umich.edu 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 652766Sktlim@umich.edu '-I "^M5 started " ' + # for stderr file 662766Sktlim@umich.edu '-I "^M5 executing on " ' + # for stderr file 672766Sktlim@umich.edu '-I "^Simulation complete at" ' + # for stderr file 682921Sktlim@umich.edu '-I "^Listening for" ' + # for stderr file 692921Sktlim@umich.edu '-I "listening for remote gdb" ' + # for stderr file 702766Sktlim@umich.edu '--exclude=m5stats.txt --exclude=SCCS ' + 712766Sktlim@umich.edu '--exclude=${TARGETS[0].file} ' + 725529Snate@binkert.org '> ${TARGETS[0]}', target=target, source=source), None) 732766Sktlim@umich.edu print "===== Output differences =====" 744762Snate@binkert.org print contents(target[0]) 752155SN/A # Run diff-out on m5stats.txt file 762155SN/A status = Execute(env.subst('$DIFFOUT $SOURCES > ${TARGETS[1]}', 772155SN/A target=target, source=source), 782155SN/A strfunction=None) 792155SN/A print "===== Statistics differences =====" 802155SN/A print contents(target[1]) 812766Sktlim@umich.edu # Generate status file contents based on exit status of diff-out 822155SN/A if status == 0: 835865Sksewell@umich.edu status_str = "passed." 842155SN/A else: 852155SN/A status_str = "FAILED!" 862155SN/A f = file(str(target[2]), 'w') 872155SN/A print >>f, env.subst('${TARGETS[2].dir}', target=target, source=source), \ 882178SN/A status_str 892178SN/A f.close() 902178SN/A # done 912766Sktlim@umich.edu return 0 922178SN/A 932178SN/Adef check_test_string(target, source, env): 946994Snate@binkert.org return env.subst("Comparing outputs in ${TARGETS[0].dir}.", 952178SN/A target=target, source=source) 962766Sktlim@umich.edu 972766Sktlim@umich.edutestAction = env.Action(check_test, check_test_string) 982766Sktlim@umich.edu 992788Sktlim@umich.edudef print_test(target, source, env): 1002178SN/A print '***** ' + contents(source[0]) 1012733Sktlim@umich.edu return 0 1022733Sktlim@umich.edu 1032817Sksewell@umich.eduprintAction = env.Action(print_test, strfunction = None) 1042733Sktlim@umich.edu 1054486Sbinkertn@umich.edudef update_test(target, source, env): 1064486Sbinkertn@umich.edu """Update reference test outputs. 1074776Sgblack@eecs.umich.edu 1084776Sgblack@eecs.umich.edu Target is phony. First two sources are the ref & new m5stats.txt 1096365Sgblack@eecs.umich.edu files, respectively. We actually copy everything in the 1104486Sbinkertn@umich.edu respective directories except the status & diff output files. 1114202Sbinkertn@umich.edu 1124202Sbinkertn@umich.edu """ 1134202Sbinkertn@umich.edu dest_dir = str(source[0].get_dir()) 1144202Sbinkertn@umich.edu src_dir = str(source[1].get_dir()) 1154202Sbinkertn@umich.edu dest_files = os.listdir(dest_dir) 1164776Sgblack@eecs.umich.edu src_files = os.listdir(src_dir) 1176365Sgblack@eecs.umich.edu for f in ('stdout', 'stderr', 'm5stats.txt', 'config.ini', 'config.out'): 1184202Sbinkertn@umich.edu if f in dest_files: 1194202Sbinkertn@umich.edu print " Replacing file", f 1204202Sbinkertn@umich.edu dest_files.remove(f) 1214202Sbinkertn@umich.edu else: 1225217Ssaidi@eecs.umich.edu print " Creating new file", f 1234202Sbinkertn@umich.edu copyAction = Copy(os.path.join(dest_dir, f), os.path.join(src_dir, f)) 1242155SN/A copyAction.strfunction = None 1254202Sbinkertn@umich.edu Execute(copyAction) 1264486Sbinkertn@umich.edu # warn about any files in dest not overwritten (other than SCCS dir) 1274486Sbinkertn@umich.edu if 'SCCS' in dest_files: 1284202Sbinkertn@umich.edu dest_files.remove('SCCS') 1294202Sbinkertn@umich.edu if dest_files: 1302821Sktlim@umich.edu print "Warning: file(s) in", dest_dir, "not updated:", 1314776Sgblack@eecs.umich.edu print ', '.join(dest_files) 1324776Sgblack@eecs.umich.edu return 0 1334776Sgblack@eecs.umich.edu 1344776Sgblack@eecs.umich.edudef update_test_string(target, source, env): 1352766Sktlim@umich.edu return env.subst("Updating ${SOURCES[0].dir} from ${SOURCES[1].dir}", 1364202Sbinkertn@umich.edu target=target, source=source) 1375192Ssaidi@eecs.umich.edu 1382733Sktlim@umich.eduupdateAction = env.Action(update_test, update_test_string) 1392733Sktlim@umich.edu 1402733Sktlim@umich.edudef test_builder(env, ref_dir): 1412733Sktlim@umich.edu """Define a test.""" 1422733Sktlim@umich.edu 1432874Sktlim@umich.edu (category, name, _ref, isa, opsys, config) = ref_dir.split('/') 1442874Sktlim@umich.edu assert(_ref == 'ref') 1452874Sktlim@umich.edu 1464202Sbinkertn@umich.edu # target path (where test output goes) is the same except without 1472733Sktlim@umich.edu # the 'ref' component 1485192Ssaidi@eecs.umich.edu tgt_dir = os.path.join(category, name, isa, opsys, config) 1495192Ssaidi@eecs.umich.edu 1505192Ssaidi@eecs.umich.edu # prepend file name with tgt_dir 1515217Ssaidi@eecs.umich.edu def tgt(f): 1525192Ssaidi@eecs.umich.edu return os.path.join(tgt_dir, f) 1535192Ssaidi@eecs.umich.edu 1545192Ssaidi@eecs.umich.edu ref_stats = os.path.join(ref_dir, 'm5stats.txt') 1555192Ssaidi@eecs.umich.edu new_stats = tgt('m5stats.txt') 1565192Ssaidi@eecs.umich.edu status_file = tgt('status') 1576667Ssteve.reinhardt@amd.com 1585192Ssaidi@eecs.umich.edu # Base command for running test. We mess around with indirectly 1595192Ssaidi@eecs.umich.edu # referring to files via SOURCES and TARGETS so that scons can 1605192Ssaidi@eecs.umich.edu # mess with paths all it wants to and we still get the right 1615192Ssaidi@eecs.umich.edu # files. 1625192Ssaidi@eecs.umich.edu base_cmd = '${SOURCES[0]} -d $TARGET.dir ${SOURCES[1]} %s' % tgt_dir 1635192Ssaidi@eecs.umich.edu # stdout and stderr files 1645192Ssaidi@eecs.umich.edu cmd_stdout = '${TARGETS[0]}' 1655192Ssaidi@eecs.umich.edu cmd_stderr = '${TARGETS[1]}' 1665784Sgblack@eecs.umich.edu 1675784Sgblack@eecs.umich.edu # Prefix test run with batch job submission command if appropriate. 1685192Ssaidi@eecs.umich.edu # Output redirection is also different for batch runs. 1695192Ssaidi@eecs.umich.edu # Batch command also supports timeout arg (in seconds, not minutes). 1705192Ssaidi@eecs.umich.edu timeout = 15 # used to be a param, probably should be again 1715192Ssaidi@eecs.umich.edu if env['BATCH']: 1725192Ssaidi@eecs.umich.edu cmd = [env['BATCH_CMD'], '-t', str(timeout * 60), 1735192Ssaidi@eecs.umich.edu '-o', cmd_stdout, '-e', cmd_stderr, base_cmd] 1746667Ssteve.reinhardt@amd.com else: 1756036Sksewell@umich.edu cmd = [base_cmd, '>', cmd_stdout, '2>', cmd_stderr] 1766667Ssteve.reinhardt@amd.com 177 env.Command([tgt('stdout'), tgt('stderr'), new_stats], 178 [env.M5Binary, 'run.py'], ' '.join(cmd)) 179 180 # order of targets is important... see check_test 181 env.Command([tgt('outdiff'), tgt('statsdiff'), status_file], 182 [ref_stats, new_stats], 183 testAction) 184 185 # phony target to echo status 186 if env['update_ref']: 187 p = env.Command(tgt('_update'), 188 [ref_stats, new_stats, status_file], 189 updateAction) 190 else: 191 p = env.Command(tgt('_print'), [status_file], printAction) 192 193 env.AlwaysBuild(p) 194 195 196# Figure out applicable configs based on build type 197configs = [] 198if env['FULL_SYSTEM']: 199 if env['TARGET_ISA'] == 'alpha': 200 if not env['ALPHA_TLASER']: 201 configs += ['tsunami-simple-atomic', 202 'tsunami-simple-timing', 203 'tsunami-simple-atomic-dual', 204 'tsunami-simple-timing-dual', 205 'twosys-tsunami-simple-atomic'] 206 if env['TARGET_ISA'] == 'sparc': 207 configs += ['t1000-simple-atomic', 208 't1000-simple-timing'] 209 210else: 211 configs += ['simple-atomic', 'simple-timing', 'o3-timing', 'memtest'] 212 213cwd = os.getcwd() 214os.chdir(str(Dir('.').srcdir)) 215for config in configs: 216 dirs = glob.glob('*/*/ref/%s/*/%s' % (env['TARGET_ISA'], config)) 217 for d in dirs: 218 test_builder(env, d) 219os.chdir(cwd) 220