SConscript revision 8120
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, time 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 448334Snate@binkert.orgdef 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 526654Snate@binkert.orgdef signum(status): 535517Snate@binkert.org return (status & 0x7f); 548614Sgblack@eecs.umich.edu 557674Snate@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) 598233Snate@binkert.org 608233Snate@binkert.org# regular expressions of lines to ignore when diffing outputs 618233Snate@binkert.orgoutput_ignore_regexes = ( 628233Snate@binkert.org '^command line:', # for stdout file 638233Snate@binkert.org '^M5 compiled ', # for stderr file 648334Snate@binkert.org '^M5 started ', # for stderr file 658334Snate@binkert.org '^M5 executing on ', # for stderr file 668233Snate@binkert.org '^Simulation complete at', # for stderr file 678233Snate@binkert.org '^Listening for', # for stderr file 688233Snate@binkert.org 'listening for remote gdb', # for stderr file 698233Snate@binkert.org ) 708233Snate@binkert.org 718233Snate@binkert.orgoutput_ignore_args = ' '.join(["-I '"+s+"'" for s in output_ignore_regexes]) 726143Snate@binkert.org 738233Snate@binkert.orgoutput_ignore_args += ' --exclude=stats.txt --exclude=outdiff' 748233Snate@binkert.org 758233Snate@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 808233Snate@binkert.org 818233Snate@binkert.org Sources are: 828233Snate@binkert.org source[0] : M5 binary 836143Snate@binkert.org source[1] : tests/run.py script 848233Snate@binkert.org source[2] : reference stats file 858233Snate@binkert.org 868233Snate@binkert.org """ 878233Snate@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)) 914762Snate@binkert.org 926143Snate@binkert.org tgt_dir = os.path.dirname(str(target[0])) 938233Snate@binkert.org 948233Snate@binkert.org # Base command for running test. We mess around with indirectly 958233Snate@binkert.org # referring to files via SOURCES and TARGETS so that scons can mess 968233Snate@binkert.org # with paths all it wants to and we still get the right files. 978233Snate@binkert.org cmd = '${SOURCES[0]} -d %s -re ${SOURCES[1]} %s' % (tgt_dir, tgt_dir) 986143Snate@binkert.org 998233Snate@binkert.org # Prefix test run with batch job submission command if appropriate. 1008233Snate@binkert.org # Batch command also supports timeout arg (in seconds, not minutes). 1018233Snate@binkert.org timeout = 15 * 60 # used to be a param, probably should be again 1028233Snate@binkert.org if env['BATCH']: 1036143Snate@binkert.org cmd = '%s -t %d %s' % (env['BATCH_CMD'], timeout, cmd) 1046143Snate@binkert.org 1056143Snate@binkert.org pre_exec_time = time.time() 1066143Snate@binkert.org status = env.Execute(env.subst(cmd, target=target, source=source)) 1076143Snate@binkert.org if status == 0: 1086143Snate@binkert.org # M5 terminated normally. 1096143Snate@binkert.org # Run diff on output & ref directories to find differences. 1106143Snate@binkert.org # Exclude the stats file since we will use diff-out on that. 1116143Snate@binkert.org 1127065Snate@binkert.org # NFS file systems can be annoying and not have updated yet 1136143Snate@binkert.org # wait until we see the file modified 1148233Snate@binkert.org statsdiff = os.path.join(tgt_dir, 'statsdiff') 1158233Snate@binkert.org m_time = 0 1168233Snate@binkert.org nap = 0 1178233Snate@binkert.org while m_time < pre_exec_time and nap < 10: 1188233Snate@binkert.org try: 1198233Snate@binkert.org m_time = os.stat(statsdiff).st_mtime 1208233Snate@binkert.org except OSError: 1218233Snate@binkert.org pass 1228233Snate@binkert.org time.sleep(1) 1238233Snate@binkert.org nap += 1 1248233Snate@binkert.org 1258233Snate@binkert.org outdiff = os.path.join(tgt_dir, 'outdiff') 1268233Snate@binkert.org diffcmd = 'diff -ubrs %s ${SOURCES[2].dir} %s > %s' \ 1278233Snate@binkert.org % (output_ignore_args, tgt_dir, outdiff) 1288233Snate@binkert.org env.Execute(env.subst(diffcmd, target=target, source=source)) 1298233Snate@binkert.org print "===== Output differences =====" 1308233Snate@binkert.org print contents(outdiff) 1318233Snate@binkert.org # Run diff-out on stats.txt file 1328233Snate@binkert.org diffcmd = '$DIFFOUT ${SOURCES[2]} %s > %s' \ 1338233Snate@binkert.org % (os.path.join(tgt_dir, 'stats.txt'), statsdiff) 1348233Snate@binkert.org diffcmd = env.subst(diffcmd, target=target, source=source) 1358233Snate@binkert.org status = env.Execute(diffcmd, strfunction=None) 1368233Snate@binkert.org print "===== Statistics differences =====" 1378233Snate@binkert.org print contents(statsdiff) 1388233Snate@binkert.org 1398233Snate@binkert.org else: # m5 exit status != 0 1408233Snate@binkert.org # M5 did not terminate properly, so no need to check the output 1418233Snate@binkert.org if signaled(status): 1428233Snate@binkert.org print 'M5 terminated with signal', signum(status) 1438233Snate@binkert.org if signum(status) in retry_signals: 1448233Snate@binkert.org # Consider the test incomplete; don't create a 'status' output. 1456143Snate@binkert.org # Hand the return status to scons and let scons decide what 1466143Snate@binkert.org # to do about it (typically terminate unless run with -k). 1476143Snate@binkert.org return status 1486143Snate@binkert.org else: 1496143Snate@binkert.org print 'M5 exited with non-zero status', status 1506143Snate@binkert.org # complete but failed execution (call to exit() with non-zero 1516143Snate@binkert.org # status, SIGABORT due to assertion failure, etc.)... fall through 1526143Snate@binkert.org # and generate FAILED status as if output comparison had failed 1536143Snate@binkert.org 1548945Ssteve.reinhardt@amd.com # Generate status file contents based on exit status of m5 or diff-out 1558233Snate@binkert.org if status == 0: 1568233Snate@binkert.org status_str = "passed." 1576143Snate@binkert.org else: 1588945Ssteve.reinhardt@amd.com status_str = "FAILED!" 1596143Snate@binkert.org f = file(str(target[0]), 'w') 1606143Snate@binkert.org print >>f, tgt_dir, status_str 1616143Snate@binkert.org f.close() 1626143Snate@binkert.org # done 1635522Snate@binkert.org return 0 1646143Snate@binkert.org 1656143Snate@binkert.orgdef run_test_string(target, source, env): 1666143Snate@binkert.org return env.subst("Running test in ${TARGETS[0].dir}.", 1676143Snate@binkert.org target=target, source=source) 1688233Snate@binkert.org 1698233Snate@binkert.orgtestAction = env.Action(run_test, run_test_string) 1708233Snate@binkert.org 1716143Snate@binkert.orgdef print_test(target, source, env): 1726143Snate@binkert.org print '***** ' + contents(source[0]) 1736143Snate@binkert.org return 0 1746143Snate@binkert.org 1755522Snate@binkert.orgprintAction = env.Action(print_test, strfunction = None) 1765522Snate@binkert.org 1775522Snate@binkert.org# Static vars for update_test: 1785522Snate@binkert.org# - long-winded message about ignored sources 1795604Snate@binkert.orgignore_msg = ''' 1805604Snate@binkert.orgNote: The following file(s) will not be copied. New non-standard 1816143Snate@binkert.org output files must be copied manually once before --update-ref will 1826143Snate@binkert.org recognize them as outputs. Otherwise they are assumed to be 1834762Snate@binkert.org inputs and are ignored. 1844762Snate@binkert.org''' 1856143Snate@binkert.org# - reference files always needed 1866727Ssteve.reinhardt@amd.comneeded_files = set(['simout', 'simerr', 'stats.txt', 'config.ini']) 1876727Ssteve.reinhardt@amd.com# - source files we always want to ignore 1886727Ssteve.reinhardt@amd.comknown_ignores = set(['status', 'outdiff', 'statsdiff']) 1894762Snate@binkert.org 1906143Snate@binkert.orgdef update_test(target, source, env): 1916143Snate@binkert.org """Update reference test outputs. 1926143Snate@binkert.org 1936143Snate@binkert.org Target is phony. First two sources are the ref & new stats.txt file 1946727Ssteve.reinhardt@amd.com files, respectively. We actually copy everything in the 1956143Snate@binkert.org respective directories except the status & diff output files. 1967674Snate@binkert.org 1977674Snate@binkert.org """ 1985604Snate@binkert.org dest_dir = str(source[0].get_dir()) 1996143Snate@binkert.org src_dir = str(source[1].get_dir()) 2006143Snate@binkert.org dest_files = set(os.listdir(dest_dir)) 2016143Snate@binkert.org src_files = set(os.listdir(src_dir)) 2024762Snate@binkert.org # Copy all of the required files plus any existing dest files. 2036143Snate@binkert.org wanted_files = needed_files | dest_files 2044762Snate@binkert.org missing_files = wanted_files - src_files 2054762Snate@binkert.org if len(missing_files) > 0: 2064762Snate@binkert.org print " WARNING: the following file(s) are missing " \ 2076143Snate@binkert.org "and will not be updated:" 2086143Snate@binkert.org print " ", " ,".join(missing_files) 2094762Snate@binkert.org copy_files = wanted_files - missing_files 2108233Snate@binkert.org warn_ignored_files = (src_files - copy_files) - known_ignores 2118233Snate@binkert.org if len(warn_ignored_files) > 0: 2128233Snate@binkert.org print ignore_msg, 2138233Snate@binkert.org print " ", ", ".join(warn_ignored_files) 2146143Snate@binkert.org for f in copy_files: 2156143Snate@binkert.org if f in dest_files: 2164762Snate@binkert.org print " Replacing file", f 2176143Snate@binkert.org dest_files.remove(f) 2184762Snate@binkert.org else: 2196143Snate@binkert.org print " Creating new file", f 2204762Snate@binkert.org copyAction = Copy(os.path.join(dest_dir, f), os.path.join(src_dir, f)) 2216143Snate@binkert.org copyAction.strfunction = None 2228233Snate@binkert.org env.Execute(copyAction) 2238233Snate@binkert.org return 0 2248233Snate@binkert.org 2256143Snate@binkert.orgdef update_test_string(target, source, env): 2266143Snate@binkert.org return env.subst("Updating ${SOURCES[0].dir} from ${SOURCES[1].dir}", 2276143Snate@binkert.org target=target, source=source) 2286143Snate@binkert.org 2296143Snate@binkert.orgupdateAction = env.Action(update_test, update_test_string) 2306143Snate@binkert.org 2316143Snate@binkert.orgdef test_builder(env, ref_dir): 2326143Snate@binkert.org """Define a test.""" 2338233Snate@binkert.org 2348233Snate@binkert.org (category, name, _ref, isa, opsys, config) = ref_dir.split('/') 235955SN/A assert(_ref == 'ref') 2369396Sandreas.hansson@arm.com 2379396Sandreas.hansson@arm.com # target path (where test output goes) is the same except without 2389396Sandreas.hansson@arm.com # the 'ref' component 2399396Sandreas.hansson@arm.com tgt_dir = os.path.join(category, name, isa, opsys, config) 2409396Sandreas.hansson@arm.com 2419396Sandreas.hansson@arm.com # prepend file name with tgt_dir 2429396Sandreas.hansson@arm.com def tgt(f): 2439396Sandreas.hansson@arm.com return os.path.join(tgt_dir, f) 2449396Sandreas.hansson@arm.com 2459396Sandreas.hansson@arm.com ref_stats = os.path.join(ref_dir, 'stats.txt') 2469396Sandreas.hansson@arm.com new_stats = tgt('stats.txt') 2479396Sandreas.hansson@arm.com status_file = tgt('status') 2489396Sandreas.hansson@arm.com 2499396Sandreas.hansson@arm.com env.Command([status_file], 2509396Sandreas.hansson@arm.com [env.M5Binary, 'run.py', ref_stats], 2519396Sandreas.hansson@arm.com testAction) 2528235Snate@binkert.org 2538235Snate@binkert.org # phony target to echo status 2546143Snate@binkert.org if GetOption('update_ref'): 2558235Snate@binkert.org p = env.Command(tgt('_update'), 2569003SAli.Saidi@ARM.com [ref_stats, new_stats, status_file], 2578235Snate@binkert.org updateAction) 2588235Snate@binkert.org else: 2598235Snate@binkert.org p = env.Command(tgt('_print'), [status_file], printAction) 2608235Snate@binkert.org 2618235Snate@binkert.org env.AlwaysBuild(p) 2628235Snate@binkert.org 2638235Snate@binkert.org 2648235Snate@binkert.org# Figure out applicable configs based on build type 2658235Snate@binkert.orgconfigs = [] 2668235Snate@binkert.orgif env['FULL_SYSTEM']: 2678235Snate@binkert.org if env['TARGET_ISA'] == 'alpha': 2688235Snate@binkert.org configs += ['tsunami-simple-atomic', 2698235Snate@binkert.org 'tsunami-simple-timing', 2708235Snate@binkert.org 'tsunami-simple-atomic-dual', 2719003SAli.Saidi@ARM.com 'tsunami-simple-timing-dual', 2728235Snate@binkert.org 'twosys-tsunami-simple-atomic', 2735584Snate@binkert.org 'tsunami-o3', 'tsunami-o3-dual'] 2744382Sbinkertn@umich.edu if env['TARGET_ISA'] == 'sparc': 2754202Sbinkertn@umich.edu configs += ['t1000-simple-atomic', 2764382Sbinkertn@umich.edu 't1000-simple-timing'] 2774382Sbinkertn@umich.edu if env['TARGET_ISA'] == 'arm': 2784382Sbinkertn@umich.edu configs += ['realview-simple-atomic', 2799396Sandreas.hansson@arm.com 'realview-simple-timing'] 2805584Snate@binkert.org if env['TARGET_ISA'] == 'x86': 2814382Sbinkertn@umich.edu configs += ['pc-simple-atomic', 2824382Sbinkertn@umich.edu 'pc-simple-timing'] 2834382Sbinkertn@umich.edu 2848232Snate@binkert.orgelse: 2855192Ssaidi@eecs.umich.edu configs += ['simple-atomic', 'simple-timing', 'o3-timing', 'memtest', 2868232Snate@binkert.org 'simple-atomic-mp', 'simple-timing-mp', 'o3-timing-mp', 2878232Snate@binkert.org 'inorder-timing', 'rubytest'] 2888232Snate@binkert.org 2895192Ssaidi@eecs.umich.eduif env['RUBY']: 2908232Snate@binkert.org # With Ruby, A protocol must be specified in the environment 2915192Ssaidi@eecs.umich.edu assert(env['PROTOCOL']) 2925799Snate@binkert.org 2938232Snate@binkert.org # 2945192Ssaidi@eecs.umich.edu # Is there a way to determine what is Protocol EnumVariable 2955192Ssaidi@eecs.umich.edu # default and eliminate the need to hard code the default protocol below? 2965192Ssaidi@eecs.umich.edu # 2978232Snate@binkert.org # If the binary includes the default ruby protocol, run both ruby and 2985192Ssaidi@eecs.umich.edu # non-ruby versions of the tests. Otherwise just run the ruby versions. 2998232Snate@binkert.org # 3005192Ssaidi@eecs.umich.edu if env['PROTOCOL'] == 'MI_example': 3015192Ssaidi@eecs.umich.edu configs += [c + "-ruby" for c in configs] 3025192Ssaidi@eecs.umich.edu else: 3035192Ssaidi@eecs.umich.edu configs = [c + "-ruby-" + env['PROTOCOL'] for c in configs] 3044382Sbinkertn@umich.edu 3054382Sbinkertn@umich.educwd = os.getcwd() 3064382Sbinkertn@umich.eduos.chdir(str(Dir('.').srcdir)) 3072667Sstever@eecs.umich.edufor config in configs: 3082667Sstever@eecs.umich.edu dirs = glob.glob('*/*/ref/%s/*/%s' % (env['TARGET_ISA'], config)) 3092667Sstever@eecs.umich.edu for d in dirs: 3102667Sstever@eecs.umich.edu if not os.path.exists(os.path.join(d, 'skip')): 3112667Sstever@eecs.umich.edu test_builder(env, d) 3122667Sstever@eecs.umich.eduos.chdir(cwd) 3135742Snate@binkert.org