SConscript revision 7506
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, signal 334762Snate@binkert.orgimport sys 345522Snate@binkert.orgimport glob 35955SN/Afrom SCons.Script.SConscript import SConsEnvironment 365522Snate@binkert.org 37955SN/AImport('env') 385522Snate@binkert.org 394202Sbinkertn@umich.eduenv['DIFFOUT'] = File('diff-out') 405742Snate@binkert.org 41955SN/A# Dict that accumulates lists of tests by category (quick, medium, long) 424381Sbinkertn@umich.eduenv.Tests = {} 434381Sbinkertn@umich.edu 44955SN/Adef contents(node): 45955SN/A return file(str(node)).read() 46955SN/A 474202Sbinkertn@umich.edu# functions to parse return value from scons Execute()... not the same 48955SN/A# as wait() etc., so python built-in os funcs don't work. 494382Sbinkertn@umich.edudef signaled(status): 504382Sbinkertn@umich.edu return (status & 0x80) != 0; 514382Sbinkertn@umich.edu 526108Snate@binkert.orgdef signum(status): 535517Snate@binkert.org return (status & 0x7f); 546143Snate@binkert.org 556143Snate@binkert.org# List of signals that indicate that we should retry the test rather 566143Snate@binkert.org# than consider it failed. 576143Snate@binkert.orgretry_signals = (signal.SIGTERM, signal.SIGKILL, signal.SIGINT, 586143Snate@binkert.org signal.SIGQUIT, signal.SIGHUP) 596143Snate@binkert.org 606143Snate@binkert.org# regular expressions of lines to ignore when diffing outputs 616143Snate@binkert.orgoutput_ignore_regexes = ( 626143Snate@binkert.org '^command line:', # for stdout file 636143Snate@binkert.org '^M5 compiled ', # for stderr file 646143Snate@binkert.org '^M5 started ', # for stderr file 656143Snate@binkert.org '^M5 executing on ', # for stderr file 666143Snate@binkert.org '^Simulation complete at', # for stderr file 676143Snate@binkert.org '^Listening for', # for stderr file 686143Snate@binkert.org 'listening for remote gdb', # for stderr file 694762Snate@binkert.org ) 706143Snate@binkert.org 716143Snate@binkert.orgoutput_ignore_args = ' '.join(["-I '"+s+"'" for s in output_ignore_regexes]) 726143Snate@binkert.org 736143Snate@binkert.orgoutput_ignore_args += ' --exclude=stats.txt --exclude=outdiff' 746143Snate@binkert.org 756143Snate@binkert.orgdef run_test(target, source, env): 766143Snate@binkert.org """Check output from running test. 776143Snate@binkert.org 786143Snate@binkert.org Targets are as follows: 796143Snate@binkert.org target[0] : status 806143Snate@binkert.org 816143Snate@binkert.org Sources are: 826143Snate@binkert.org source[0] : M5 binary 836143Snate@binkert.org source[1] : tests/run.py script 846143Snate@binkert.org source[2] : reference stats file 856143Snate@binkert.org 866143Snate@binkert.org """ 876143Snate@binkert.org # make sure target files are all gone 886143Snate@binkert.org for t in target: 896143Snate@binkert.org if os.path.exists(t.abspath): 906143Snate@binkert.org env.Execute(Delete(t.abspath)) 916143Snate@binkert.org 926143Snate@binkert.org tgt_dir = os.path.dirname(str(target[0])) 936143Snate@binkert.org 946143Snate@binkert.org # Base command for running test. We mess around with indirectly 956143Snate@binkert.org # referring to files via SOURCES and TARGETS so that scons can mess 966143Snate@binkert.org # with paths all it wants to and we still get the right files. 976143Snate@binkert.org cmd = '${SOURCES[0]} -d %s -re ${SOURCES[1]} %s' % (tgt_dir, tgt_dir) 986143Snate@binkert.org 996143Snate@binkert.org # Prefix test run with batch job submission command if appropriate. 1006143Snate@binkert.org # Batch command also supports timeout arg (in seconds, not minutes). 1016143Snate@binkert.org timeout = 15 * 60 # used to be a param, probably should be again 1026143Snate@binkert.org if env['BATCH']: 1036143Snate@binkert.org cmd = '%s -t %d %s' % (env['BATCH_CMD'], timeout, cmd) 1046143Snate@binkert.org 1056143Snate@binkert.org status = env.Execute(env.subst(cmd, target=target, source=source)) 1066143Snate@binkert.org if status == 0: 1076143Snate@binkert.org # M5 terminated normally. 1086143Snate@binkert.org # Run diff on output & ref directories to find differences. 1096143Snate@binkert.org # Exclude the stats file since we will use diff-out on that. 1106143Snate@binkert.org outdiff = os.path.join(tgt_dir, 'outdiff') 1116143Snate@binkert.org diffcmd = 'diff -ubr %s ${SOURCES[2].dir} %s > %s' \ 1126143Snate@binkert.org % (output_ignore_args, tgt_dir, outdiff) 1135522Snate@binkert.org env.Execute(env.subst(diffcmd, target=target, source=source)) 1146143Snate@binkert.org print "===== Output differences =====" 1156143Snate@binkert.org print contents(outdiff) 1166143Snate@binkert.org # Run diff-out on stats.txt file 1176143Snate@binkert.org statsdiff = os.path.join(tgt_dir, 'statsdiff') 1186143Snate@binkert.org diffcmd = '$DIFFOUT ${SOURCES[2]} %s > %s' \ 1196143Snate@binkert.org % (os.path.join(tgt_dir, 'stats.txt'), statsdiff) 1206143Snate@binkert.org diffcmd = env.subst(diffcmd, target=target, source=source) 1216143Snate@binkert.org status = env.Execute(diffcmd, strfunction=None) 1226143Snate@binkert.org print "===== Statistics differences =====" 1236143Snate@binkert.org print contents(statsdiff) 1245522Snate@binkert.org 1255522Snate@binkert.org else: # m5 exit status != 0 1265522Snate@binkert.org # M5 did not terminate properly, so no need to check the output 1275522Snate@binkert.org if signaled(status): 1285604Snate@binkert.org print 'M5 terminated with signal', signum(status) 1295604Snate@binkert.org if signum(status) in retry_signals: 1306143Snate@binkert.org # Consider the test incomplete; don't create a 'status' output. 1316143Snate@binkert.org # Hand the return status to scons and let scons decide what 1324762Snate@binkert.org # to do about it (typically terminate unless run with -k). 1334762Snate@binkert.org return status 1346143Snate@binkert.org else: 1356143Snate@binkert.org print 'M5 exited with non-zero status', status 1366143Snate@binkert.org # complete but failed execution (call to exit() with non-zero 1376143Snate@binkert.org # status, SIGABORT due to assertion failure, etc.)... fall through 1384762Snate@binkert.org # and generate FAILED status as if output comparison had failed 1396143Snate@binkert.org 1406143Snate@binkert.org # Generate status file contents based on exit status of m5 or diff-out 1416143Snate@binkert.org if status == 0: 1426143Snate@binkert.org status_str = "passed." 1436143Snate@binkert.org else: 1446143Snate@binkert.org status_str = "FAILED!" 1456143Snate@binkert.org f = file(str(target[0]), 'w') 1466143Snate@binkert.org print >>f, tgt_dir, status_str 1475604Snate@binkert.org f.close() 1486143Snate@binkert.org # done 1496143Snate@binkert.org return 0 1506143Snate@binkert.org 1514762Snate@binkert.orgdef run_test_string(target, source, env): 1526143Snate@binkert.org return env.subst("Running test in ${TARGETS[0].dir}.", 1534762Snate@binkert.org target=target, source=source) 1544762Snate@binkert.org 1554762Snate@binkert.orgtestAction = env.Action(run_test, run_test_string) 1566143Snate@binkert.org 1576143Snate@binkert.orgdef print_test(target, source, env): 1584762Snate@binkert.org print '***** ' + contents(source[0]) 1596143Snate@binkert.org return 0 1606143Snate@binkert.org 1616143Snate@binkert.orgprintAction = env.Action(print_test, strfunction = None) 1626143Snate@binkert.org 1634762Snate@binkert.org# Static vars for update_test: 1646143Snate@binkert.org# - long-winded message about ignored sources 1654762Snate@binkert.orgignore_msg = ''' 1666143Snate@binkert.orgNote: The following file(s) will not be copied. New non-standard 1674762Snate@binkert.org output files must be copied manually once before update_ref will 1686143Snate@binkert.org recognize them as outputs. Otherwise they are assumed to be 1696143Snate@binkert.org inputs and are ignored. 1706143Snate@binkert.org''' 1716143Snate@binkert.org# - reference files always needed 1726143Snate@binkert.orgneeded_files = set(['simout', 'simerr', 'stats.txt', 'config.ini']) 1736143Snate@binkert.org# - source files we always want to ignore 1746143Snate@binkert.orgknown_ignores = set(['status', 'outdiff', 'statsdiff']) 1756143Snate@binkert.org 1766143Snate@binkert.orgdef update_test(target, source, env): 1776143Snate@binkert.org """Update reference test outputs. 1786143Snate@binkert.org 1796143Snate@binkert.org Target is phony. First two sources are the ref & new stats.txt file 1806143Snate@binkert.org files, respectively. We actually copy everything in the 181955SN/A respective directories except the status & diff output files. 1825584Snate@binkert.org 1835584Snate@binkert.org """ 1845584Snate@binkert.org dest_dir = str(source[0].get_dir()) 1855584Snate@binkert.org src_dir = str(source[1].get_dir()) 1866143Snate@binkert.org dest_files = set(os.listdir(dest_dir)) 1876143Snate@binkert.org src_files = set(os.listdir(src_dir)) 1886143Snate@binkert.org # Copy all of the required files plus any existing dest files. 1895584Snate@binkert.org wanted_files = needed_files | dest_files 1904382Sbinkertn@umich.edu missing_files = wanted_files - src_files 1914202Sbinkertn@umich.edu if len(missing_files) > 0: 1924382Sbinkertn@umich.edu print " WARNING: the following file(s) are missing " \ 1934382Sbinkertn@umich.edu "and will not be updated:" 1944382Sbinkertn@umich.edu print " ", " ,".join(missing_files) 1955584Snate@binkert.org copy_files = wanted_files - missing_files 1964382Sbinkertn@umich.edu warn_ignored_files = (src_files - copy_files) - known_ignores 1974382Sbinkertn@umich.edu if len(warn_ignored_files) > 0: 1984382Sbinkertn@umich.edu print ignore_msg, 1995192Ssaidi@eecs.umich.edu print " ", ", ".join(warn_ignored_files) 2005192Ssaidi@eecs.umich.edu for f in copy_files: 2015799Snate@binkert.org if f in dest_files: 2025799Snate@binkert.org print " Replacing file", f 2035799Snate@binkert.org dest_files.remove(f) 2045192Ssaidi@eecs.umich.edu else: 2055799Snate@binkert.org print " Creating new file", f 2065192Ssaidi@eecs.umich.edu copyAction = Copy(os.path.join(dest_dir, f), os.path.join(src_dir, f)) 2075799Snate@binkert.org copyAction.strfunction = None 2085799Snate@binkert.org env.Execute(copyAction) 2095192Ssaidi@eecs.umich.edu return 0 2105192Ssaidi@eecs.umich.edu 2115192Ssaidi@eecs.umich.edudef update_test_string(target, source, env): 2125799Snate@binkert.org return env.subst("Updating ${SOURCES[0].dir} from ${SOURCES[1].dir}", 2135192Ssaidi@eecs.umich.edu target=target, source=source) 2145192Ssaidi@eecs.umich.edu 2155192Ssaidi@eecs.umich.eduupdateAction = env.Action(update_test, update_test_string) 2165192Ssaidi@eecs.umich.edu 2175192Ssaidi@eecs.umich.edudef test_builder(env, ref_dir): 2185192Ssaidi@eecs.umich.edu """Define a test.""" 2194382Sbinkertn@umich.edu 2204382Sbinkertn@umich.edu (category, name, _ref, isa, opsys, config) = ref_dir.split('/') 2214382Sbinkertn@umich.edu assert(_ref == 'ref') 2222667Sstever@eecs.umich.edu 2232667Sstever@eecs.umich.edu # target path (where test output goes) is the same except without 2242667Sstever@eecs.umich.edu # the 'ref' component 2252667Sstever@eecs.umich.edu tgt_dir = os.path.join(category, name, isa, opsys, config) 2262667Sstever@eecs.umich.edu 2272667Sstever@eecs.umich.edu # prepend file name with tgt_dir 2285742Snate@binkert.org def tgt(f): 2295742Snate@binkert.org return os.path.join(tgt_dir, f) 2305742Snate@binkert.org 2312037SN/A ref_stats = os.path.join(ref_dir, 'stats.txt') 2322037SN/A new_stats = tgt('stats.txt') 2332037SN/A status_file = tgt('status') 2345793Snate@binkert.org 2355793Snate@binkert.org env.Command([status_file], 2365793Snate@binkert.org [env.M5Binary, 'run.py', ref_stats], 2375793Snate@binkert.org testAction) 2385793Snate@binkert.org 2394382Sbinkertn@umich.edu # phony target to echo status 2404762Snate@binkert.org if env['update_ref']: 2415344Sstever@gmail.com p = env.Command(tgt('_update'), 2424382Sbinkertn@umich.edu [ref_stats, new_stats, status_file], 2435341Sstever@gmail.com updateAction) 2445742Snate@binkert.org else: 2455742Snate@binkert.org p = env.Command(tgt('_print'), [status_file], printAction) 2465742Snate@binkert.org 2475742Snate@binkert.org env.AlwaysBuild(p) 2485742Snate@binkert.org 2494762Snate@binkert.org 2505742Snate@binkert.org# Figure out applicable configs based on build type 2515742Snate@binkert.orgconfigs = [] 2525742Snate@binkert.orgif env['FULL_SYSTEM']: 2535742Snate@binkert.org if env['TARGET_ISA'] == 'alpha': 2545742Snate@binkert.org configs += ['tsunami-simple-atomic', 2555742Snate@binkert.org 'tsunami-simple-timing', 2565742Snate@binkert.org 'tsunami-simple-atomic-dual', 2575341Sstever@gmail.com 'tsunami-simple-timing-dual', 2585742Snate@binkert.org 'twosys-tsunami-simple-atomic', 2595341Sstever@gmail.com 'tsunami-o3', 'tsunami-o3-dual'] 2604773Snate@binkert.org if env['TARGET_ISA'] == 'sparc': 2616108Snate@binkert.org configs += ['t1000-simple-atomic', 2621858SN/A 't1000-simple-timing'] 2631085SN/A 2644382Sbinkertn@umich.eduelse: 2654382Sbinkertn@umich.edu configs += ['simple-atomic', 'simple-timing', 'o3-timing', 'memtest', 2664762Snate@binkert.org 'simple-atomic-mp', 'simple-timing-mp', 'o3-timing-mp', 2674762Snate@binkert.org 'inorder-timing', 'rubytest'] 2684762Snate@binkert.org 2695517Snate@binkert.orgif env['RUBY']: 2705517Snate@binkert.org # With Ruby, A protocol must be specified in the environment 2715517Snate@binkert.org assert(env['PROTOCOL']) 2725517Snate@binkert.org 2735517Snate@binkert.org # 2745517Snate@binkert.org # Is there a way to determine what is Protocol EnumVariable 2755517Snate@binkert.org # default and eliminate the need to hard code the default protocol below? 2765517Snate@binkert.org # 2775517Snate@binkert.org # If the binary includes the default ruby protocol, run both ruby and 2785517Snate@binkert.org # non-ruby versions of the tests. Otherwise just run the ruby versions. 2795517Snate@binkert.org # 2805517Snate@binkert.org if env['PROTOCOL'] == 'MI_example': 2815517Snate@binkert.org configs += [c + "-ruby" for c in configs] 2825517Snate@binkert.org else: 2835517Snate@binkert.org configs = [c + "-ruby-" + env['PROTOCOL'] for c in configs] 2845517Snate@binkert.org 2855517Snate@binkert.orgcwd = os.getcwd() 2865798Snate@binkert.orgos.chdir(str(Dir('.').srcdir)) 2875517Snate@binkert.orgfor config in configs: 2885517Snate@binkert.org dirs = glob.glob('*/*/ref/%s/*/%s' % (env['TARGET_ISA'], config)) 2895517Snate@binkert.org for d in dirs: 2905517Snate@binkert.org if not os.path.exists(os.path.join(d, 'skip')): 2915517Snate@binkert.org test_builder(env, d) 2925517Snate@binkert.orgos.chdir(cwd) 2935517Snate@binkert.org