SConscript revision 5525
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 474601Sgblack@eecs.umich.edudef check_test(target, source, env): 485124Sgblack@eecs.umich.edu """Check output from running test. 497966Sgblack@eecs.umich.edu 505083Sgblack@eecs.umich.edu Targets are as follows: 514679Sgblack@eecs.umich.edu target[0] : outdiff 526515Sgblack@eecs.umich.edu target[1] : statsdiff 535083Sgblack@eecs.umich.edu target[2] : status 544679Sgblack@eecs.umich.edu 554679Sgblack@eecs.umich.edu """ 568745Sgblack@eecs.umich.edu # make sure target files are all gone 576313Sgblack@eecs.umich.edu for t in target: 586365Sgblack@eecs.umich.edu if os.path.exists(t.abspath): 595124Sgblack@eecs.umich.edu Execute(Delete(t.abspath)) 608752Sgblack@eecs.umich.edu # Run diff on output & ref directories to find differences. 614249Sgblack@eecs.umich.edu # Exclude m5stats.txt since we will use diff-out on that. 624240Sgblack@eecs.umich.edu Execute(env.subst('diff -ubr ${SOURCES[0].dir} ${SOURCES[1].dir} ' + 634202Sbinkertn@umich.edu '-I "^command line:" ' + # for stdout file 644997Sgblack@eecs.umich.edu '-I "^M5 compiled " ' + # for stderr file 657624Sgblack@eecs.umich.edu '-I "^M5 started " ' + # for stderr file 665135Sgblack@eecs.umich.edu '-I "^M5 executing on " ' + # for stderr file 678753Sgblack@eecs.umich.edu '-I "^Simulation complete at" ' + # for stderr file 684997Sgblack@eecs.umich.edu '-I "^Listening for" ' + # for stderr file 698745Sgblack@eecs.umich.edu '-I "listening for remote gdb" ' + # for stderr file 706365Sgblack@eecs.umich.edu '--exclude=m5stats.txt --exclude=SCCS ' + 718740Sgblack@eecs.umich.edu '--exclude=${TARGETS[0].file} ' + 726365Sgblack@eecs.umich.edu '> ${TARGETS[0]}', target=target, source=source), None) 738740Sgblack@eecs.umich.edu print "===== Output differences =====" 748745Sgblack@eecs.umich.edu print contents(target[0]) 758752Sgblack@eecs.umich.edu # Run diff-out on m5stats.txt file 768752Sgblack@eecs.umich.edu status = Execute(env.subst('$DIFFOUT $SOURCES > ${TARGETS[1]}', 778335Snate@binkert.org target=target, source=source), 788335Snate@binkert.org strfunction=None) 794120Sgblack@eecs.umich.edu print "===== Statistics differences =====" 804202Sbinkertn@umich.edu print contents(target[1]) 815649Sgblack@eecs.umich.edu # Generate status file contents based on exit status of diff-out 825132Sgblack@eecs.umich.edu if status == 0: 835132Sgblack@eecs.umich.edu status_str = "passed." 844202Sbinkertn@umich.edu else: 855299Sgblack@eecs.umich.edu status_str = "FAILED!" 865132Sgblack@eecs.umich.edu f = file(str(target[2]), 'w') 875086Sgblack@eecs.umich.edu print >>f, env.subst('${TARGETS[2].dir}', target=target, source=source), \ 884202Sbinkertn@umich.edu status_str 894202Sbinkertn@umich.edu f.close() 904120Sgblack@eecs.umich.edu # done 914202Sbinkertn@umich.edu return 0 924202Sbinkertn@umich.edu 934202Sbinkertn@umich.edudef check_test_string(target, source, env): 944120Sgblack@eecs.umich.edu return env.subst("Comparing outputs in ${TARGETS[0].dir}.", 955069Sgblack@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.edu# Static vars for update_test: 1065081Sgblack@eecs.umich.edu# - long-winded message about ignored sources 1075081Sgblack@eecs.umich.eduignore_msg = ''' 1085081Sgblack@eecs.umich.eduNote: The following file(s) will not be copied. New non-standard 1095081Sgblack@eecs.umich.edu output files must be copied manually once before update_ref will 1105081Sgblack@eecs.umich.edu recognize them as outputs. Otherwise they are assumed to be 1115081Sgblack@eecs.umich.edu inputs and are ignored. 1125081Sgblack@eecs.umich.edu''' 1135081Sgblack@eecs.umich.edu# - reference files always needed 1145081Sgblack@eecs.umich.eduneeded_files = set(['stdout', 'stderr', 'm5stats.txt', 'config.ini']) 1155081Sgblack@eecs.umich.edu# - source files we always want to ignore 1165081Sgblack@eecs.umich.eduknown_ignores = set(['status', 'outdiff', 'statsdiff']) 1175081Sgblack@eecs.umich.edu 1185081Sgblack@eecs.umich.edudef update_test(target, source, env): 1195081Sgblack@eecs.umich.edu """Update reference test outputs. 1205081Sgblack@eecs.umich.edu 1215081Sgblack@eecs.umich.edu Target is phony. First two sources are the ref & new m5stats.txt 1225081Sgblack@eecs.umich.edu files, respectively. We actually copy everything in the 1235081Sgblack@eecs.umich.edu respective directories except the status & diff output files. 1245081Sgblack@eecs.umich.edu 1255081Sgblack@eecs.umich.edu """ 1265081Sgblack@eecs.umich.edu dest_dir = str(source[0].get_dir()) 1275081Sgblack@eecs.umich.edu src_dir = str(source[1].get_dir()) 1285081Sgblack@eecs.umich.edu dest_files = set(os.listdir(dest_dir)) 1295081Sgblack@eecs.umich.edu src_files = set(os.listdir(src_dir)) 1305081Sgblack@eecs.umich.edu # Copy all of the required files plus any existing dest files. 1315081Sgblack@eecs.umich.edu wanted_files = needed_files | dest_files 1325081Sgblack@eecs.umich.edu missing_files = wanted_files - src_files 1335081Sgblack@eecs.umich.edu if len(missing_files) > 0: 1345081Sgblack@eecs.umich.edu print " WARNING: the following file(s) are missing " \ 1355081Sgblack@eecs.umich.edu "and will not be updated:" 1365081Sgblack@eecs.umich.edu print " ", " ,".join(missing_files) 1375081Sgblack@eecs.umich.edu copy_files = wanted_files - missing_files 1385081Sgblack@eecs.umich.edu warn_ignored_files = (src_files - copy_files) - known_ignores 1395081Sgblack@eecs.umich.edu if len(warn_ignored_files) > 0: 1405081Sgblack@eecs.umich.edu print ignore_msg, 1415081Sgblack@eecs.umich.edu print " ", ", ".join(warn_ignored_files) 1425081Sgblack@eecs.umich.edu for f in copy_files: 1435081Sgblack@eecs.umich.edu if f in dest_files: 1445081Sgblack@eecs.umich.edu print " Replacing file", f 1455081Sgblack@eecs.umich.edu dest_files.remove(f) 1465081Sgblack@eecs.umich.edu else: 1475081Sgblack@eecs.umich.edu print " Creating new file", f 1485081Sgblack@eecs.umich.edu copyAction = Copy(os.path.join(dest_dir, f), os.path.join(src_dir, f)) 1495081Sgblack@eecs.umich.edu copyAction.strfunction = None 1505081Sgblack@eecs.umich.edu Execute(copyAction) 1515680Sgblack@eecs.umich.edu return 0 1525081Sgblack@eecs.umich.edu 1535933Sgblack@eecs.umich.edudef update_test_string(target, source, env): 1545173Sgblack@eecs.umich.edu return env.subst("Updating ${SOURCES[0].dir} from ${SOURCES[1].dir}", 1555359Sgblack@eecs.umich.edu target=target, source=source) 1565081Sgblack@eecs.umich.edu 1575149Sgblack@eecs.umich.eduupdateAction = env.Action(update_test, update_test_string) 1585298Sgblack@eecs.umich.edu 1595081Sgblack@eecs.umich.edudef test_builder(env, ref_dir): 1605081Sgblack@eecs.umich.edu """Define a test.""" 1615081Sgblack@eecs.umich.edu 1625081Sgblack@eecs.umich.edu (category, name, _ref, isa, opsys, config) = ref_dir.split('/') 1635081Sgblack@eecs.umich.edu assert(_ref == 'ref') 1645081Sgblack@eecs.umich.edu 1655081Sgblack@eecs.umich.edu # target path (where test output goes) is the same except without 1665081Sgblack@eecs.umich.edu # the 'ref' component 1675081Sgblack@eecs.umich.edu tgt_dir = os.path.join(category, name, isa, opsys, config) 1685081Sgblack@eecs.umich.edu 1695081Sgblack@eecs.umich.edu # prepend file name with tgt_dir 1705081Sgblack@eecs.umich.edu def tgt(f): 1715081Sgblack@eecs.umich.edu return os.path.join(tgt_dir, f) 1725081Sgblack@eecs.umich.edu 1735081Sgblack@eecs.umich.edu ref_stats = os.path.join(ref_dir, 'm5stats.txt') 1745081Sgblack@eecs.umich.edu new_stats = tgt('m5stats.txt') 1755081Sgblack@eecs.umich.edu status_file = tgt('status') 1765081Sgblack@eecs.umich.edu 1775081Sgblack@eecs.umich.edu # Base command for running test. We mess around with indirectly 1785081Sgblack@eecs.umich.edu # referring to files via SOURCES and TARGETS so that scons can 1795081Sgblack@eecs.umich.edu # mess with paths all it wants to and we still get the right 1805081Sgblack@eecs.umich.edu # files. 1815081Sgblack@eecs.umich.edu cmd = '${SOURCES[0]} -d $TARGET.dir' 1825081Sgblack@eecs.umich.edu cmd += ' -re --stdout-file ${TARGETS[0]} --stderr-file ${TARGETS[1]}' 1835081Sgblack@eecs.umich.edu cmd += ' ${SOURCES[1]} %s' % tgt_dir 1845081Sgblack@eecs.umich.edu 1855081Sgblack@eecs.umich.edu # Prefix test run with batch job submission command if appropriate. 1865081Sgblack@eecs.umich.edu # Batch command also supports timeout arg (in seconds, not minutes). 1875081Sgblack@eecs.umich.edu timeout = 15 * 60 # used to be a param, probably should be again 1885081Sgblack@eecs.umich.edu if env['BATCH']: 1895081Sgblack@eecs.umich.edu cmd = '%s -t %d %s' % (env['BATCH_CMD'], timeout, cmd) 1905081Sgblack@eecs.umich.edu 1915081Sgblack@eecs.umich.edu env.Command([tgt('stdout'), tgt('stderr'), new_stats], 1925081Sgblack@eecs.umich.edu [env.M5Binary, 'run.py'], cmd) 1935081Sgblack@eecs.umich.edu 1945081Sgblack@eecs.umich.edu # order of targets is important... see check_test 1955081Sgblack@eecs.umich.edu env.Command([tgt('outdiff'), tgt('statsdiff'), status_file], 1965081Sgblack@eecs.umich.edu [ref_stats, new_stats], 1975081Sgblack@eecs.umich.edu testAction) 1985081Sgblack@eecs.umich.edu 1995081Sgblack@eecs.umich.edu # phony target to echo status 2005081Sgblack@eecs.umich.edu if env['update_ref']: 2015081Sgblack@eecs.umich.edu p = env.Command(tgt('_update'), 2025081Sgblack@eecs.umich.edu [ref_stats, new_stats, status_file], 2035081Sgblack@eecs.umich.edu updateAction) 2045081Sgblack@eecs.umich.edu else: 2055081Sgblack@eecs.umich.edu p = env.Command(tgt('_print'), [status_file], printAction) 2065081Sgblack@eecs.umich.edu 2075081Sgblack@eecs.umich.edu env.AlwaysBuild(p) 2085081Sgblack@eecs.umich.edu 2095081Sgblack@eecs.umich.edu 2105081Sgblack@eecs.umich.edu# Figure out applicable configs based on build type 2115081Sgblack@eecs.umich.educonfigs = [] 2125081Sgblack@eecs.umich.eduif env['FULL_SYSTEM']: 2135081Sgblack@eecs.umich.edu if env['TARGET_ISA'] == 'alpha': 2145081Sgblack@eecs.umich.edu if not env['ALPHA_TLASER']: 2155081Sgblack@eecs.umich.edu configs += ['tsunami-simple-atomic', 2165081Sgblack@eecs.umich.edu 'tsunami-simple-timing', 2175081Sgblack@eecs.umich.edu 'tsunami-simple-atomic-dual', 2185081Sgblack@eecs.umich.edu 'tsunami-simple-timing-dual', 2195081Sgblack@eecs.umich.edu 'twosys-tsunami-simple-atomic'] 2205081Sgblack@eecs.umich.edu if env['TARGET_ISA'] == 'sparc': 2215081Sgblack@eecs.umich.edu configs += ['t1000-simple-atomic', 2225081Sgblack@eecs.umich.edu 't1000-simple-timing'] 2235081Sgblack@eecs.umich.edu 2245081Sgblack@eecs.umich.eduelse: 2255081Sgblack@eecs.umich.edu configs += ['simple-atomic', 'simple-timing', 'o3-timing', 'memtest'] 2265081Sgblack@eecs.umich.edu 2275081Sgblack@eecs.umich.educwd = os.getcwd() 2285081Sgblack@eecs.umich.eduos.chdir(str(Dir('.').srcdir)) 2295081Sgblack@eecs.umich.edufor config in configs: 2305081Sgblack@eecs.umich.edu dirs = glob.glob('*/*/ref/%s/*/%s' % (env['TARGET_ISA'], config)) 2315081Sgblack@eecs.umich.edu for d in dirs: 2325081Sgblack@eecs.umich.edu test_builder(env, d) 2335081Sgblack@eecs.umich.eduos.chdir(cwd) 2345081Sgblack@eecs.umich.edu