SConscript revision 4781
14120Sgblack@eecs.umich.edu# -*- mode:python -*- 24120Sgblack@eecs.umich.edu 37087Snate@binkert.org# Copyright (c) 2004-2006 The Regents of The University of Michigan 47087Snate@binkert.org# All rights reserved. 57087Snate@binkert.org# 67087Snate@binkert.org# Redistribution and use in source and binary forms, with or without 77087Snate@binkert.org# modification, are permitted provided that the following conditions are 87087Snate@binkert.org# met: redistributions of source code must retain the above copyright 97087Snate@binkert.org# notice, this list of conditions and the following disclaimer; 107087Snate@binkert.org# redistributions in binary form must reproduce the above copyright 117087Snate@binkert.org# notice, this list of conditions and the following disclaimer in the 127087Snate@binkert.org# documentation and/or other materials provided with the distribution; 137087Snate@binkert.org# neither the name of the copyright holders nor the names of its 147087Snate@binkert.org# contributors may be used to endorse or promote products derived from 154120Sgblack@eecs.umich.edu# this software without specific prior written permission. 164120Sgblack@eecs.umich.edu# 174120Sgblack@eecs.umich.edu# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 184120Sgblack@eecs.umich.edu# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 194120Sgblack@eecs.umich.edu# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 204120Sgblack@eecs.umich.edu# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 214120Sgblack@eecs.umich.edu# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 224120Sgblack@eecs.umich.edu# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 234120Sgblack@eecs.umich.edu# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 244120Sgblack@eecs.umich.edu# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 254120Sgblack@eecs.umich.edu# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 264120Sgblack@eecs.umich.edu# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 274120Sgblack@eecs.umich.edu# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 284120Sgblack@eecs.umich.edu# 294120Sgblack@eecs.umich.edu# Authors: Steve Reinhardt 304120Sgblack@eecs.umich.edu# Kevin Lim 314120Sgblack@eecs.umich.edu 324120Sgblack@eecs.umich.eduimport os 334120Sgblack@eecs.umich.eduimport sys 344120Sgblack@eecs.umich.eduimport glob 354120Sgblack@eecs.umich.edufrom SCons.Script.SConscript import SConsEnvironment 364120Sgblack@eecs.umich.edu 374120Sgblack@eecs.umich.eduImport('env') 384120Sgblack@eecs.umich.edu 394120Sgblack@eecs.umich.eduenv['DIFFOUT'] = File('diff-out') 404120Sgblack@eecs.umich.edu 414120Sgblack@eecs.umich.edu# Dict that accumulates lists of tests by category (quick, medium, long) 424120Sgblack@eecs.umich.eduenv.Tests = {} 434202Sbinkertn@umich.edu 445069Sgblack@eecs.umich.edudef contents(node): 454202Sbinkertn@umich.edu return file(str(node)).read() 465659Sgblack@eecs.umich.edu 479022Sgblack@eecs.umich.edudef check_test(target, source, env): 489023Sgblack@eecs.umich.edu """Check output from running test. 494601Sgblack@eecs.umich.edu 505124Sgblack@eecs.umich.edu Targets are as follows: 517966Sgblack@eecs.umich.edu target[0] : outdiff 525083Sgblack@eecs.umich.edu target[1] : statsdiff 534679Sgblack@eecs.umich.edu target[2] : status 546515Sgblack@eecs.umich.edu 555083Sgblack@eecs.umich.edu """ 564679Sgblack@eecs.umich.edu # make sure target files are all gone 574679Sgblack@eecs.umich.edu for t in target: 588745Sgblack@eecs.umich.edu if os.path.exists(t.abspath): 596313Sgblack@eecs.umich.edu Execute(Delete(t.abspath)) 608771Sgblack@eecs.umich.edu # Run diff on output & ref directories to find differences. 618771Sgblack@eecs.umich.edu # Exclude m5stats.txt since we will use diff-out on that. 628771Sgblack@eecs.umich.edu Execute(env.subst('diff -ubr ${SOURCES[0].dir} ${SOURCES[1].dir} ' + 638771Sgblack@eecs.umich.edu '-I "^command line:" ' + # for stdout file 646365Sgblack@eecs.umich.edu '-I "^M5 compiled " ' + # for stderr file 655124Sgblack@eecs.umich.edu '-I "^M5 started " ' + # for stderr file 668752Sgblack@eecs.umich.edu '-I "^M5 executing on " ' + # for stderr file 678771Sgblack@eecs.umich.edu '-I "^Simulation complete at" ' + # for stderr file 684202Sbinkertn@umich.edu '-I "^Listening for" ' + # for stderr file 698771Sgblack@eecs.umich.edu '-I "listening for remote gdb" ' + # for stderr file 708771Sgblack@eecs.umich.edu '--exclude=m5stats.txt --exclude=SCCS ' + 714997Sgblack@eecs.umich.edu '--exclude=${TARGETS[0].file} ' + 727624Sgblack@eecs.umich.edu '> ${TARGETS[0]}', target=target, source=source), None) 735135Sgblack@eecs.umich.edu print "===== Output differences =====" 748753Sgblack@eecs.umich.edu print contents(target[0]) 754997Sgblack@eecs.umich.edu # Run diff-out on m5stats.txt file 769384SAndreas.Sandberg@arm.com status = Execute(env.subst('$DIFFOUT $SOURCES > ${TARGETS[1]}', 778745Sgblack@eecs.umich.edu target=target, source=source), 786365Sgblack@eecs.umich.edu strfunction=None) 798771Sgblack@eecs.umich.edu print "===== Statistics differences =====" 808740Sgblack@eecs.umich.edu print contents(target[1]) 816365Sgblack@eecs.umich.edu # Generate status file contents based on exit status of diff-out 828740Sgblack@eecs.umich.edu if status == 0: 838745Sgblack@eecs.umich.edu status_str = "passed." 848752Sgblack@eecs.umich.edu else: 858752Sgblack@eecs.umich.edu status_str = "FAILED!" 869023Sgblack@eecs.umich.edu f = file(str(target[2]), 'w') 878335Snate@binkert.org print >>f, env.subst('${TARGETS[2].dir}', target=target, source=source), \ 884120Sgblack@eecs.umich.edu status_str 895069Sgblack@eecs.umich.edu f.close() 905081Sgblack@eecs.umich.edu # done 915081Sgblack@eecs.umich.edu return 0 925081Sgblack@eecs.umich.edu 935081Sgblack@eecs.umich.edudef check_test_string(target, source, env): 945081Sgblack@eecs.umich.edu return env.subst("Comparing outputs in ${TARGETS[0].dir}.", 955081Sgblack@eecs.umich.edu target=target, source=source) 965081Sgblack@eecs.umich.edu 975081Sgblack@eecs.umich.edutestAction = env.Action(check_test, check_test_string) 985081Sgblack@eecs.umich.edu 995081Sgblack@eecs.umich.edudef print_test(target, source, env): 1005081Sgblack@eecs.umich.edu print '***** ' + contents(source[0]) 1015081Sgblack@eecs.umich.edu return 0 1025081Sgblack@eecs.umich.edu 1035081Sgblack@eecs.umich.eduprintAction = env.Action(print_test, strfunction = None) 1045081Sgblack@eecs.umich.edu 1055081Sgblack@eecs.umich.edudef update_test(target, source, env): 1065081Sgblack@eecs.umich.edu """Update reference test outputs. 1075081Sgblack@eecs.umich.edu 1085081Sgblack@eecs.umich.edu Target is phony. First two sources are the ref & new m5stats.txt 1095081Sgblack@eecs.umich.edu files, respectively. We actually copy everything in the 1105081Sgblack@eecs.umich.edu respective directories except the status & diff output files. 1115081Sgblack@eecs.umich.edu 1125081Sgblack@eecs.umich.edu """ 1135081Sgblack@eecs.umich.edu dest_dir = str(source[0].get_dir()) 1145081Sgblack@eecs.umich.edu src_dir = str(source[1].get_dir()) 1155081Sgblack@eecs.umich.edu dest_files = os.listdir(dest_dir) 1165081Sgblack@eecs.umich.edu src_files = os.listdir(src_dir) 1175081Sgblack@eecs.umich.edu for f in ('stdout', 'stderr', 'm5stats.txt', 'config.ini', 'config.out'): 1185081Sgblack@eecs.umich.edu if f in dest_files: 1195081Sgblack@eecs.umich.edu print " Replacing file", f 1205081Sgblack@eecs.umich.edu dest_files.remove(f) 1215081Sgblack@eecs.umich.edu else: 1225081Sgblack@eecs.umich.edu print " Creating new file", f 1235081Sgblack@eecs.umich.edu copyAction = Copy(os.path.join(dest_dir, f), os.path.join(src_dir, f)) 1245081Sgblack@eecs.umich.edu copyAction.strfunction = None 1255081Sgblack@eecs.umich.edu Execute(copyAction) 1265081Sgblack@eecs.umich.edu # warn about any files in dest not overwritten (other than SCCS dir) 1275081Sgblack@eecs.umich.edu if 'SCCS' in dest_files: 1285081Sgblack@eecs.umich.edu dest_files.remove('SCCS') 1295081Sgblack@eecs.umich.edu if dest_files: 1305081Sgblack@eecs.umich.edu print "Warning: file(s) in", dest_dir, "not updated:", 1315081Sgblack@eecs.umich.edu print ', '.join(dest_files) 1325081Sgblack@eecs.umich.edu return 0 1335081Sgblack@eecs.umich.edu 1345081Sgblack@eecs.umich.edudef update_test_string(target, source, env): 1355081Sgblack@eecs.umich.edu return env.subst("Updating ${SOURCES[0].dir} from ${SOURCES[1].dir}", 1365081Sgblack@eecs.umich.edu target=target, source=source) 1375081Sgblack@eecs.umich.edu 1385081Sgblack@eecs.umich.eduupdateAction = env.Action(update_test, update_test_string) 1395081Sgblack@eecs.umich.edu 1405081Sgblack@eecs.umich.edudef test_builder(env, ref_dir): 1415081Sgblack@eecs.umich.edu """Define a test.""" 1425081Sgblack@eecs.umich.edu 1435081Sgblack@eecs.umich.edu (category, name, _ref, isa, opsys, config) = ref_dir.split('/') 1445081Sgblack@eecs.umich.edu assert(_ref == 'ref') 1455680Sgblack@eecs.umich.edu 1465081Sgblack@eecs.umich.edu # target path (where test output goes) is the same except without 1475933Sgblack@eecs.umich.edu # the 'ref' component 1485173Sgblack@eecs.umich.edu tgt_dir = os.path.join(category, name, isa, opsys, config) 1495359Sgblack@eecs.umich.edu 1505081Sgblack@eecs.umich.edu # prepend file name with tgt_dir 1515149Sgblack@eecs.umich.edu def tgt(f): 1525298Sgblack@eecs.umich.edu return os.path.join(tgt_dir, f) 1535081Sgblack@eecs.umich.edu 1545081Sgblack@eecs.umich.edu ref_stats = os.path.join(ref_dir, 'm5stats.txt') 1555081Sgblack@eecs.umich.edu new_stats = tgt('m5stats.txt') 1565081Sgblack@eecs.umich.edu status_file = tgt('status') 1575081Sgblack@eecs.umich.edu 1585081Sgblack@eecs.umich.edu # Base command for running test. We mess around with indirectly 1595081Sgblack@eecs.umich.edu # referring to files via SOURCES and TARGETS so that scons can 1605081Sgblack@eecs.umich.edu # mess with paths all it wants to and we still get the right 1615081Sgblack@eecs.umich.edu # files. 1625081Sgblack@eecs.umich.edu base_cmd = '${SOURCES[0]} -d $TARGET.dir ${SOURCES[1]} %s' % tgt_dir 1635081Sgblack@eecs.umich.edu # stdout and stderr files 1645081Sgblack@eecs.umich.edu cmd_stdout = '${TARGETS[0]}' 1655081Sgblack@eecs.umich.edu cmd_stderr = '${TARGETS[1]}' 1665081Sgblack@eecs.umich.edu 1675081Sgblack@eecs.umich.edu # Prefix test run with batch job submission command if appropriate. 1685081Sgblack@eecs.umich.edu # Output redirection is also different for batch runs. 1695081Sgblack@eecs.umich.edu # Batch command also supports timeout arg (in seconds, not minutes). 1705081Sgblack@eecs.umich.edu timeout = 15 # used to be a param, probably should be again 1715081Sgblack@eecs.umich.edu if env['BATCH']: 1725081Sgblack@eecs.umich.edu cmd = [env['BATCH_CMD'], '-t', str(timeout * 60), 1735081Sgblack@eecs.umich.edu '-o', cmd_stdout, '-e', cmd_stderr, base_cmd] 1745081Sgblack@eecs.umich.edu else: 1755081Sgblack@eecs.umich.edu cmd = [base_cmd, '>', cmd_stdout, '2>', cmd_stderr] 1765081Sgblack@eecs.umich.edu 1775081Sgblack@eecs.umich.edu env.Command([tgt('stdout'), tgt('stderr'), new_stats], 1785081Sgblack@eecs.umich.edu [env.M5Binary, 'run.py'], ' '.join(cmd)) 1795081Sgblack@eecs.umich.edu 1805081Sgblack@eecs.umich.edu # order of targets is important... see check_test 1815081Sgblack@eecs.umich.edu env.Command([tgt('outdiff'), tgt('statsdiff'), status_file], 1825081Sgblack@eecs.umich.edu [ref_stats, new_stats], 1835081Sgblack@eecs.umich.edu testAction) 1845081Sgblack@eecs.umich.edu 1855081Sgblack@eecs.umich.edu # phony target to echo status 1865081Sgblack@eecs.umich.edu if env['update_ref']: 1875081Sgblack@eecs.umich.edu p = env.Command(tgt('_update'), 1885081Sgblack@eecs.umich.edu [ref_stats, new_stats, status_file], 1895081Sgblack@eecs.umich.edu updateAction) 1905081Sgblack@eecs.umich.edu else: 1915081Sgblack@eecs.umich.edu p = env.Command(tgt('_print'), [status_file], printAction) 1925081Sgblack@eecs.umich.edu 1935081Sgblack@eecs.umich.edu env.AlwaysBuild(p) 1945081Sgblack@eecs.umich.edu 1955081Sgblack@eecs.umich.edu 1965081Sgblack@eecs.umich.edu# Figure out applicable configs based on build type 1975081Sgblack@eecs.umich.educonfigs = [] 1985081Sgblack@eecs.umich.eduif env['FULL_SYSTEM']: 1995081Sgblack@eecs.umich.edu if env['TARGET_ISA'] == 'alpha': 2005081Sgblack@eecs.umich.edu if not env['ALPHA_TLASER']: 2015081Sgblack@eecs.umich.edu configs += ['tsunami-simple-atomic', 2025081Sgblack@eecs.umich.edu 'tsunami-simple-timing', 2035081Sgblack@eecs.umich.edu 'tsunami-simple-atomic-dual', 2045081Sgblack@eecs.umich.edu 'tsunami-simple-timing-dual', 2055081Sgblack@eecs.umich.edu 'twosys-tsunami-simple-atomic'] 2065081Sgblack@eecs.umich.edu if env['TARGET_ISA'] == 'sparc': 2075081Sgblack@eecs.umich.edu configs += ['t1000-simple-atomic', 2085081Sgblack@eecs.umich.edu 't1000-simple-timing'] 2095081Sgblack@eecs.umich.edu 2105081Sgblack@eecs.umich.eduelse: 2115081Sgblack@eecs.umich.edu configs += ['simple-atomic', 'simple-timing', 'o3-timing', 'memtest'] 2125081Sgblack@eecs.umich.edu 2135081Sgblack@eecs.umich.educwd = os.getcwd() 2145081Sgblack@eecs.umich.eduos.chdir(str(Dir('.').srcdir)) 2155081Sgblack@eecs.umich.edufor config in configs: 2165081Sgblack@eecs.umich.edu dirs = glob.glob('*/*/ref/%s/*/%s' % (env['TARGET_ISA'], config)) 2175081Sgblack@eecs.umich.edu for d in dirs: 2185081Sgblack@eecs.umich.edu test_builder(env, d) 2195081Sgblack@eecs.umich.eduos.chdir(cwd) 2205081Sgblack@eecs.umich.edu