SConscript revision 4202
1955SN/A# -*- mode:python -*- 2955SN/A 31762SN/A# Copyright (c) 2004-2006 The Regents of The University of Michigan 4955SN/A# All rights reserved. 5955SN/A# 6955SN/A# Redistribution and use in source and binary forms, with or without 7955SN/A# modification, are permitted provided that the following conditions are 8955SN/A# met: redistributions of source code must retain the above copyright 9955SN/A# notice, this list of conditions and the following disclaimer; 10955SN/A# redistributions in binary form must reproduce the above copyright 11955SN/A# notice, this list of conditions and the following disclaimer in the 12955SN/A# documentation and/or other materials provided with the distribution; 13955SN/A# neither the name of the copyright holders nor the names of its 14955SN/A# contributors may be used to endorse or promote products derived from 15955SN/A# this software without specific prior written permission. 16955SN/A# 17955SN/A# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18955SN/A# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19955SN/A# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20955SN/A# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21955SN/A# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22955SN/A# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23955SN/A# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24955SN/A# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25955SN/A# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26955SN/A# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27955SN/A# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 282665Ssaidi@eecs.umich.edu# 292665Ssaidi@eecs.umich.edu# Authors: Steve Reinhardt 30955SN/A# Kevin Lim 31955SN/A 32955SN/Aimport os 331608SN/Aimport sys 34955SN/Aimport glob 35955SN/Afrom SCons.Script.SConscript import SConsEnvironment 36955SN/A 37955SN/AImport('env') 38955SN/A 39955SN/Aenv['DIFFOUT'] = File('diff-out') 40955SN/A 41955SN/A# Dict that accumulates lists of tests by category (quick, medium, long) 42955SN/Aenv.Tests = {} 43955SN/A 44955SN/Adef contents(node): 45955SN/A return file(str(node)).read() 46955SN/A 47955SN/Adef check_test(target, source, env): 482023SN/A """Check output from running test. 49955SN/A 50955SN/A Targets are as follows: 51955SN/A target[0] : outdiff 52955SN/A target[1] : statsdiff 53955SN/A target[2] : status 54955SN/A 55955SN/A """ 56955SN/A # make sure target files are all gone 57955SN/A for t in target: 581031SN/A if os.path.exists(t.abspath): 59955SN/A Execute(Delete(t.abspath)) 601388SN/A # Run diff on output & ref directories to find differences. 61955SN/A # Exclude m5stats.txt since we will use diff-out on that. 62955SN/A Execute(env.subst('diff -ubr ${SOURCES[0].dir} ${SOURCES[1].dir} ' + 631296SN/A '-I "^command line:" ' + # for stdout file 64955SN/A '-I "^M5 compiled " ' + # for stderr file 652609SN/A '-I "^M5 started " ' + # for stderr file 66955SN/A '-I "^M5 executing on " ' + # for stderr file 67955SN/A '-I "^Simulation complete at" ' + # for stderr file 68955SN/A '-I "^Listening for" ' + # for stderr file 69955SN/A '-I "listening for remote gdb" ' + # for stderr file 70955SN/A '--exclude=m5stats.txt --exclude=SCCS ' + 71955SN/A '--exclude=${TARGETS[0].file} ' + 72955SN/A '> ${TARGETS[0]}', target=target, source=source), None) 73955SN/A print "===== Output differences =====" 74955SN/A print contents(target[0]) 75955SN/A # Run diff-out on m5stats.txt file 76955SN/A status = Execute(env.subst('$DIFFOUT $SOURCES > ${TARGETS[1]}', 77955SN/A target=target, source=source), 78955SN/A strfunction=None) 79955SN/A print "===== Statistics differences =====" 80955SN/A print contents(target[1]) 81955SN/A # Generate status file contents based on exit status of diff-out 82955SN/A if status == 0: 83955SN/A status_str = "passed." 842325SN/A else: 851717SN/A status_str = "FAILED!" 862652Ssaidi@eecs.umich.edu f = file(str(target[2]), 'w') 87955SN/A print >>f, env.subst('${TARGETS[2].dir}', target=target, source=source), \ 882736Sktlim@umich.edu status_str 892410SN/A f.close() 90955SN/A # done 912290SN/A return 0 92955SN/A 931717SN/Adef check_test_string(target, source, env): 942683Sktlim@umich.edu return env.subst("Comparing outputs in ${TARGETS[0].dir}.", 952683Sktlim@umich.edu target=target, source=source) 962669Sktlim@umich.edu 972568SN/AtestAction = env.Action(check_test, check_test_string) 982568SN/A 992499SN/Adef print_test(target, source, env): 1002462SN/A print '***** ' + contents(source[0]) 1012568SN/A return 0 1022395SN/A 1032405SN/AprintAction = env.Action(print_test, strfunction = None) 104955SN/A 105955SN/Adef update_test(target, source, env): 106955SN/A """Update reference test outputs. 107955SN/A 108955SN/A Target is phony. First two sources are the ref & new m5stats.txt 1092090SN/A files, respectively. We actually copy everything in the 110955SN/A respective directories except the status & diff output files. 1112667Sstever@eecs.umich.edu 112955SN/A """ 113955SN/A dest_dir = str(source[0].get_dir()) 1141696SN/A src_dir = str(source[1].get_dir()) 115955SN/A dest_files = os.listdir(dest_dir) 116955SN/A src_files = os.listdir(src_dir) 117955SN/A for f in ('stdout', 'stderr', 'm5stats.txt', 'config.ini', 'config.out'): 1181127SN/A if f in dest_files: 119955SN/A print " Replacing file", f 120955SN/A dest_files.remove(f) 1212379SN/A else: 122955SN/A print " Creating new file", f 123955SN/A copyAction = Copy(os.path.join(dest_dir, f), os.path.join(src_dir, f)) 124955SN/A copyAction.strfunction = None 1252155SN/A Execute(copyAction) 1262155SN/A # warn about any files in dest not overwritten (other than SCCS dir) 1272155SN/A if 'SCCS' in dest_files: 1282155SN/A dest_files.remove('SCCS') 1292155SN/A if dest_files: 1302155SN/A print "Warning: file(s) in", dest_dir, "not updated:", 1312155SN/A print ', '.join(dest_files) 1322155SN/A return 0 1332155SN/A 1342155SN/Adef update_test_string(target, source, env): 1352155SN/A return env.subst("Updating ${SOURCES[0].dir} from ${SOURCES[1].dir}", 1362155SN/A target=target, source=source) 1372155SN/A 1382155SN/AupdateAction = env.Action(update_test, update_test_string) 1392155SN/A 1402155SN/Adef test_builder(env, ref_dir): 1412155SN/A """Define a test.""" 1422155SN/A 1432155SN/A (category, name, _ref, isa, opsys, config) = ref_dir.split('/') 1442155SN/A assert(_ref == 'ref') 1452155SN/A 1462155SN/A # target path (where test output goes) is the same except without 1472155SN/A # the 'ref' component 1482155SN/A tgt_dir = os.path.join(category, name, isa, opsys, config) 1492155SN/A 1502155SN/A # prepend file name with tgt_dir 1512155SN/A def tgt(f): 1522155SN/A return os.path.join(tgt_dir, f) 1532155SN/A 1542155SN/A ref_stats = os.path.join(ref_dir, 'm5stats.txt') 1552155SN/A new_stats = tgt('m5stats.txt') 1562155SN/A status_file = tgt('status') 1572155SN/A 1582155SN/A # Base command for running test. We mess around with indirectly 1592155SN/A # referring to files via SOURCES and TARGETS so that scons can 1602155SN/A # mess with paths all it wants to and we still get the right 1612155SN/A # files. 1622155SN/A base_cmd = '${SOURCES[0]} -d $TARGET.dir ${SOURCES[1]} %s' % tgt_dir 1632155SN/A # stdout and stderr files 1642422SN/A cmd_stdout = '${TARGETS[0]}' 1652422SN/A cmd_stderr = '${TARGETS[1]}' 1662422SN/A 1672422SN/A # Prefix test run with batch job submission command if appropriate. 1682422SN/A # Output redirection is also different for batch runs. 1692422SN/A # Batch command also supports timeout arg (in seconds, not minutes). 1702422SN/A timeout = 15 # used to be a param, probably should be again 1712397SN/A if env['BATCH']: 1722397SN/A cmd = [env['BATCH_CMD'], '-t', str(timeout * 60), 1732422SN/A '-o', cmd_stdout, '-e', cmd_stderr, base_cmd] 1742422SN/A else: 175955SN/A cmd = [base_cmd, '>', cmd_stdout, '2>', cmd_stderr] 176955SN/A 177955SN/A env.Command([tgt('stdout'), tgt('stderr'), new_stats], 178955SN/A [env.M5Binary, 'run.py'], ' '.join(cmd)) 179955SN/A 180955SN/A # order of targets is important... see check_test 181955SN/A env.Command([tgt('outdiff'), tgt('statsdiff'), status_file], 182955SN/A [ref_stats, new_stats], 1831078SN/A testAction) 184955SN/A 185955SN/A # phony target to echo status 186955SN/A if env['update_ref']: 187955SN/A p = env.Command(tgt('_update'), 1881917SN/A [ref_stats, new_stats, status_file], 189955SN/A updateAction) 190955SN/A else: 191955SN/A p = env.Command(tgt('_print'), [status_file], printAction) 192955SN/A 193974SN/A env.AlwaysBuild(p) 194955SN/A 195955SN/A 196955SN/A# Figure out applicable configs based on build type 197955SN/Aconfigs = [] 1982566SN/Aif env['FULL_SYSTEM']: 1992566SN/A if env['TARGET_ISA'] == 'alpha': 200955SN/A if not env['ALPHA_TLASER']: 201955SN/A configs += ['tsunami-simple-atomic', 2022539SN/A 'tsunami-simple-timing', 203955SN/A 'tsunami-simple-atomic-dual', 204955SN/A 'tsunami-simple-timing-dual', 205955SN/A 'twosys-tsunami-simple-atomic'] 2061817SN/A if env['TARGET_ISA'] == 'sparc': 2071154SN/A configs += ['t1000-simple-atomic', 2081840SN/A 't1000-simple-timing'] 2092522SN/A 2102522SN/Aelse: 2112629SN/A configs += ['simple-atomic', 'simple-timing', 'o3-timing', 'memtest'] 212955SN/A 213955SN/Acwd = os.getcwd() 214955SN/Aos.chdir(str(Dir('.').srcdir)) 2152539SN/Afor config in configs: 216955SN/A dirs = glob.glob('*/*/ref/%s/*/%s' % (env['TARGET_ISA'], config)) 2172539SN/A for d in dirs: 218955SN/A test_builder(env, d) 2191730SN/Aos.chdir(cwd) 220955SN/A