SConscript revision 3691
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# 294762Snate@binkert.org# Authors: Steve Reinhardt 30955SN/A# Kevin Lim 315522Snate@binkert.org 326143Snate@binkert.orgimport os 334762Snate@binkert.orgimport sys 345522Snate@binkert.orgimport glob 35955SN/Afrom SCons.Script.SConscript import SConsEnvironment 365522Snate@binkert.org 3711974Sgabeblack@google.comImport('env') 38955SN/A 395522Snate@binkert.orgenv['DIFFOUT'] = File('diff-out') 404202Sbinkertn@umich.edu 415742Snate@binkert.org# Dict that accumulates lists of tests by category (quick, medium, long) 42955SN/Aenv.Tests = {} 434381Sbinkertn@umich.edu 444381Sbinkertn@umich.edudef contents(node): 4512246Sgabeblack@google.com return file(str(node)).read() 4612246Sgabeblack@google.com 478334Snate@binkert.orgdef check_test(target, source, env): 48955SN/A """Check output from running test. 49955SN/A 504202Sbinkertn@umich.edu Targets are as follows: 51955SN/A target[0] : outdiff 524382Sbinkertn@umich.edu target[1] : statsdiff 534382Sbinkertn@umich.edu target[2] : status 544382Sbinkertn@umich.edu 556654Snate@binkert.org """ 565517Snate@binkert.org # make sure target files are all gone 578614Sgblack@eecs.umich.edu for t in target: 587674Snate@binkert.org if os.path.exists(t.abspath): 596143Snate@binkert.org Execute(Delete(t.abspath)) 606143Snate@binkert.org # Run diff on output & ref directories to find differences. 616143Snate@binkert.org # Exclude m5stats.txt since we will use diff-out on that. 6212302Sgabeblack@google.com Execute(env.subst('diff -ubr ${SOURCES[0].dir} ${SOURCES[1].dir} ' + 6312302Sgabeblack@google.com '-I "^command line:" ' + # for stdout file 6412302Sgabeblack@google.com '-I "^M5 compiled " ' + # for stderr file 6512302Sgabeblack@google.com '-I "^M5 started " ' + # for stderr file 6612302Sgabeblack@google.com '-I "^M5 executing on " ' + # for stderr file 6712302Sgabeblack@google.com '-I "^Simulation complete at" ' + # for stderr file 6812302Sgabeblack@google.com '-I "^Listening for" ' + # for stderr file 6912302Sgabeblack@google.com '-I "listening for remote gdb" ' + # for stderr file 7012302Sgabeblack@google.com '--exclude=m5stats.txt --exclude=SCCS ' + 7112302Sgabeblack@google.com '--exclude=${TARGETS[0].file} ' + 7212302Sgabeblack@google.com '> ${TARGETS[0]}', target=target, source=source), None) 7312302Sgabeblack@google.com print "===== Output differences =====" 7412363Sgabeblack@google.com print contents(target[0]) 7512302Sgabeblack@google.com # Run diff-out on m5stats.txt file 7612302Sgabeblack@google.com status = Execute(env.subst('$DIFFOUT $SOURCES > ${TARGETS[1]}', 7712302Sgabeblack@google.com target=target, source=source), 7812363Sgabeblack@google.com strfunction=None) 7912302Sgabeblack@google.com print "===== Statistics differences =====" 8012302Sgabeblack@google.com print contents(target[1]) 8112302Sgabeblack@google.com # Generate status file contents based on exit status of diff-out 8212302Sgabeblack@google.com if status == 0: 8312302Sgabeblack@google.com status_str = "passed." 8412302Sgabeblack@google.com else: 8512302Sgabeblack@google.com status_str = "FAILED!" 8612363Sgabeblack@google.com f = file(str(target[2]), 'w') 8712302Sgabeblack@google.com print >>f, env.subst('${TARGETS[2].dir}', target=target, source=source), \ 8812302Sgabeblack@google.com status_str 8912302Sgabeblack@google.com f.close() 9012302Sgabeblack@google.com # done 9111983Sgabeblack@google.com return 0 926143Snate@binkert.org 938233Snate@binkert.orgdef check_test_string(target, source, env): 9412302Sgabeblack@google.com return env.subst("Comparing outputs in ${TARGETS[0].dir}.", 956143Snate@binkert.org target=target, source=source) 966143Snate@binkert.org 9712302Sgabeblack@google.comtestAction = env.Action(check_test, check_test_string) 984762Snate@binkert.org 996143Snate@binkert.orgdef print_test(target, source, env): 1008233Snate@binkert.org print '***** ' + contents(source[0]) 1018233Snate@binkert.org return 0 10212302Sgabeblack@google.com 10312302Sgabeblack@google.comprintAction = env.Action(print_test, strfunction = None) 1046143Snate@binkert.org 10512362Sgabeblack@google.comdef update_test(target, source, env): 10612362Sgabeblack@google.com """Update reference test outputs. 10712362Sgabeblack@google.com 10812362Sgabeblack@google.com Target is phony. First two sources are the ref & new m5stats.txt 10912302Sgabeblack@google.com files, respectively. We actually copy everything in the 11012302Sgabeblack@google.com respective directories except the status & diff output files. 11112302Sgabeblack@google.com 11212302Sgabeblack@google.com """ 11312302Sgabeblack@google.com dest_dir = str(source[0].get_dir()) 11412363Sgabeblack@google.com src_dir = str(source[1].get_dir()) 11512363Sgabeblack@google.com dest_files = os.listdir(dest_dir) 11612363Sgabeblack@google.com src_files = os.listdir(src_dir) 11712363Sgabeblack@google.com # Exclude status & diff outputs 11812302Sgabeblack@google.com for f in ('outdiff', 'statsdiff', 'status'): 11912363Sgabeblack@google.com if f in src_files: 12012363Sgabeblack@google.com src_files.remove(f) 12112363Sgabeblack@google.com for f in src_files: 12212363Sgabeblack@google.com if f in dest_files: 12312363Sgabeblack@google.com print " Replacing file", f 1248233Snate@binkert.org dest_files.remove(f) 1256143Snate@binkert.org else: 1266143Snate@binkert.org print " Creating new file", f 1276143Snate@binkert.org copyAction = Copy(os.path.join(dest_dir, f), os.path.join(src_dir, f)) 1286143Snate@binkert.org copyAction.strfunction = None 1296143Snate@binkert.org Execute(copyAction) 1306143Snate@binkert.org # warn about any files in dest not overwritten (other than SCCS dir) 1316143Snate@binkert.org if 'SCCS' in dest_files: 1326143Snate@binkert.org dest_files.remove('SCCS') 1336143Snate@binkert.org if dest_files: 1347065Snate@binkert.org print "Warning: file(s) in", dest_dir, "not updated:", 1356143Snate@binkert.org print ', '.join(dest_files) 13612362Sgabeblack@google.com return 0 13712362Sgabeblack@google.com 13812362Sgabeblack@google.comdef update_test_string(target, source, env): 13912362Sgabeblack@google.com return env.subst("Updating ${SOURCES[0].dir} from ${SOURCES[1].dir}", 14012362Sgabeblack@google.com target=target, source=source) 14112362Sgabeblack@google.com 14212362Sgabeblack@google.comupdateAction = env.Action(update_test, update_test_string) 14312362Sgabeblack@google.com 14412362Sgabeblack@google.comdef test_builder(env, ref_dir): 14512362Sgabeblack@google.com """Define a test.""" 14612362Sgabeblack@google.com 14712362Sgabeblack@google.com (category, name, _ref, isa, opsys, config) = ref_dir.split('/') 1488233Snate@binkert.org assert(_ref == 'ref') 1498233Snate@binkert.org 1508233Snate@binkert.org # target path (where test output goes) is the same except without 1518233Snate@binkert.org # the 'ref' component 1528233Snate@binkert.org tgt_dir = os.path.join(category, name, isa, opsys, config) 1538233Snate@binkert.org 1548233Snate@binkert.org # prepend file name with tgt_dir 1558233Snate@binkert.org def tgt(f): 1568233Snate@binkert.org return os.path.join(tgt_dir, f) 1578233Snate@binkert.org 1588233Snate@binkert.org ref_stats = os.path.join(ref_dir, 'm5stats.txt') 1598233Snate@binkert.org new_stats = tgt('m5stats.txt') 1608233Snate@binkert.org status_file = tgt('status') 1618233Snate@binkert.org 1628233Snate@binkert.org # Base command for running test. We mess around with indirectly 1638233Snate@binkert.org # referring to files via SOURCES and TARGETS so that scons can 1648233Snate@binkert.org # mess with paths all it wants to and we still get the right 1658233Snate@binkert.org # files. 1668233Snate@binkert.org base_cmd = '${SOURCES[0]} -d $TARGET.dir ${SOURCES[1]} %s' % tgt_dir 1678233Snate@binkert.org # stdout and stderr files 1688233Snate@binkert.org cmd_stdout = '${TARGETS[0]}' 1696143Snate@binkert.org cmd_stderr = '${TARGETS[1]}' 1706143Snate@binkert.org 1716143Snate@binkert.org # Prefix test run with batch job submission command if appropriate. 1726143Snate@binkert.org # Output redirection is also different for batch runs. 1736143Snate@binkert.org # Batch command also supports timeout arg (in seconds, not minutes). 1746143Snate@binkert.org timeout = 15 # used to be a param, probably should be again 1759982Satgutier@umich.edu if env['BATCH']: 1766143Snate@binkert.org cmd = [env['BATCH_CMD'], '-t', str(timeout * 60), 17712302Sgabeblack@google.com '-o', cmd_stdout, '-e', cmd_stderr, base_cmd] 17812302Sgabeblack@google.com else: 17912302Sgabeblack@google.com cmd = [base_cmd, '>', cmd_stdout, '2>', cmd_stderr] 18012302Sgabeblack@google.com 18112302Sgabeblack@google.com env.Command([tgt('stdout'), tgt('stderr'), new_stats], 18212302Sgabeblack@google.com [env.M5Binary, 'run.py'], ' '.join(cmd)) 18312302Sgabeblack@google.com 18412302Sgabeblack@google.com # order of targets is important... see check_test 18511983Sgabeblack@google.com env.Command([tgt('outdiff'), tgt('statsdiff'), status_file], 18611983Sgabeblack@google.com [ref_stats, new_stats], 18711983Sgabeblack@google.com testAction) 18812302Sgabeblack@google.com 18912302Sgabeblack@google.com # phony target to echo status 19012302Sgabeblack@google.com if env['update_ref']: 19112302Sgabeblack@google.com p = env.Command(tgt('_update'), 19212302Sgabeblack@google.com [ref_stats, new_stats, status_file], 19312302Sgabeblack@google.com updateAction) 19411983Sgabeblack@google.com else: 1956143Snate@binkert.org p = env.Command(tgt('_print'), [status_file], printAction) 19612305Sgabeblack@google.com 19712302Sgabeblack@google.com env.AlwaysBuild(p) 19812302Sgabeblack@google.com 19912302Sgabeblack@google.com 2006143Snate@binkert.org# Figure out applicable configs based on build type 2016143Snate@binkert.orgconfigs = [] 2026143Snate@binkert.orgif env['FULL_SYSTEM']: 2035522Snate@binkert.org if env['TARGET_ISA'] == 'alpha': 2046143Snate@binkert.org if not env['ALPHA_TLASER']: 2056143Snate@binkert.org configs += ['tsunami-simple-atomic', 2066143Snate@binkert.org 'tsunami-simple-timing', 2079982Satgutier@umich.edu 'tsunami-simple-atomic-dual', 20812302Sgabeblack@google.com 'tsunami-simple-timing-dual', 20912302Sgabeblack@google.com 'twosys-tsunami-simple-atomic'] 21012302Sgabeblack@google.com 2116143Snate@binkert.orgelse: 2126143Snate@binkert.org configs += ['simple-atomic', 'simple-timing', 'o3-timing'] 2136143Snate@binkert.org 2146143Snate@binkert.orgcwd = os.getcwd() 2155522Snate@binkert.orgos.chdir(str(Dir('.').srcdir)) 2165522Snate@binkert.orgfor config in configs: 2175522Snate@binkert.org dirs = glob.glob('*/*/ref/%s/*/%s' % (env['TARGET_ISA'], config)) 2185522Snate@binkert.org for d in dirs: 2195604Snate@binkert.org test_builder(env, d) 2205604Snate@binkert.orgos.chdir(cwd) 2216143Snate@binkert.org