SConscript revision 7799
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 6610453SAndrew.Bardsley@arm.com '^Simulation complete at', # for stderr file 6710453SAndrew.Bardsley@arm.com '^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]) 728233Snate@binkert.org 738233Snate@binkert.orgoutput_ignore_args += ' --exclude=stats.txt --exclude=outdiff' 746143Snate@binkert.org 758233Snate@binkert.orgdef run_test(target, source, env): 768233Snate@binkert.org """Check output from running test. 778233Snate@binkert.org 786143Snate@binkert.org Targets are as follows: 796143Snate@binkert.org target[0] : status 806143Snate@binkert.org 8111308Santhony.gutierrez@amd.com Sources are: 828233Snate@binkert.org source[0] : M5 binary 838233Snate@binkert.org source[1] : tests/run.py script 848233Snate@binkert.org source[2] : reference stats file 856143Snate@binkert.org 868233Snate@binkert.org """ 878233Snate@binkert.org # make sure target files are all gone 888233Snate@binkert.org for t in target: 898233Snate@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])) 934762Snate@binkert.org 946143Snate@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) 988233Snate@binkert.org 998233Snate@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). 1018233Snate@binkert.org timeout = 15 * 60 # used to be a param, probably should be again 1028233Snate@binkert.org if env['BATCH']: 1038233Snate@binkert.org cmd = '%s -t %d %s' % (env['BATCH_CMD'], timeout, cmd) 1048233Snate@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 1126143Snate@binkert.org # NFS file systems can be annoying and not have updated yet 1136143Snate@binkert.org # wait until we see the file modified 1147065Snate@binkert.org statsdiff = os.path.join(tgt_dir, 'statsdiff') 1156143Snate@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. 1458233Snate@binkert.org # Hand the return status to scons and let scons decide what 1468233Snate@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 1539982Satgutier@umich.edu 15410196SCurtis.Dunham@arm.com # Generate status file contents based on exit status of m5 or diff-out 15510196SCurtis.Dunham@arm.com if status == 0: 15610196SCurtis.Dunham@arm.com status_str = "passed." 15710196SCurtis.Dunham@arm.com else: 15810196SCurtis.Dunham@arm.com status_str = "FAILED!" 15910196SCurtis.Dunham@arm.com f = file(str(target[0]), 'w') 16010196SCurtis.Dunham@arm.com print >>f, tgt_dir, status_str 16110196SCurtis.Dunham@arm.com f.close() 1626143Snate@binkert.org # done 1636143Snate@binkert.org return 0 1648945Ssteve.reinhardt@amd.com 1658233Snate@binkert.orgdef run_test_string(target, source, env): 1668233Snate@binkert.org return env.subst("Running test in ${TARGETS[0].dir}.", 1676143Snate@binkert.org target=target, source=source) 1688945Ssteve.reinhardt@amd.com 1696143Snate@binkert.orgtestAction = env.Action(run_test, run_test_string) 1706143Snate@binkert.org 1716143Snate@binkert.orgdef print_test(target, source, env): 1726143Snate@binkert.org print '***** ' + contents(source[0]) 1735522Snate@binkert.org return 0 1746143Snate@binkert.org 1756143Snate@binkert.orgprintAction = env.Action(print_test, strfunction = None) 1766143Snate@binkert.org 1779982Satgutier@umich.edu# Static vars for update_test: 1788233Snate@binkert.org# - long-winded message about ignored sources 1798233Snate@binkert.orgignore_msg = ''' 1808233Snate@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 1836143Snate@binkert.org inputs and are ignored. 1846143Snate@binkert.org''' 1855522Snate@binkert.org# - reference files always needed 1865522Snate@binkert.orgneeded_files = set(['simout', 'simerr', 'stats.txt', 'config.ini']) 1875522Snate@binkert.org# - source files we always want to ignore 1885522Snate@binkert.orgknown_ignores = set(['status', 'outdiff', 'statsdiff']) 1895604Snate@binkert.org 1905604Snate@binkert.orgdef update_test(target, source, env): 1916143Snate@binkert.org """Update reference test outputs. 1926143Snate@binkert.org 1934762Snate@binkert.org Target is phony. First two sources are the ref & new stats.txt file 1944762Snate@binkert.org files, respectively. We actually copy everything in the 1956143Snate@binkert.org respective directories except the status & diff output files. 1966727Ssteve.reinhardt@amd.com 1976727Ssteve.reinhardt@amd.com """ 1986727Ssteve.reinhardt@amd.com dest_dir = str(source[0].get_dir()) 1994762Snate@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)) 2026143Snate@binkert.org # Copy all of the required files plus any existing dest files. 2036143Snate@binkert.org wanted_files = needed_files | dest_files 2046727Ssteve.reinhardt@amd.com missing_files = wanted_files - src_files 2056143Snate@binkert.org if len(missing_files) > 0: 2067674Snate@binkert.org print " WARNING: the following file(s) are missing " \ 2077674Snate@binkert.org "and will not be updated:" 2085604Snate@binkert.org print " ", " ,".join(missing_files) 2096143Snate@binkert.org copy_files = wanted_files - missing_files 2106143Snate@binkert.org warn_ignored_files = (src_files - copy_files) - known_ignores 2116143Snate@binkert.org if len(warn_ignored_files) > 0: 2124762Snate@binkert.org print ignore_msg, 2136143Snate@binkert.org print " ", ", ".join(warn_ignored_files) 2144762Snate@binkert.org for f in copy_files: 2154762Snate@binkert.org if f in dest_files: 2164762Snate@binkert.org print " Replacing file", f 2176143Snate@binkert.org dest_files.remove(f) 2186143Snate@binkert.org else: 2194762Snate@binkert.org print " Creating new file", f 2208233Snate@binkert.org copyAction = Copy(os.path.join(dest_dir, f), os.path.join(src_dir, f)) 2218233Snate@binkert.org copyAction.strfunction = None 2228233Snate@binkert.org env.Execute(copyAction) 2238233Snate@binkert.org return 0 2246143Snate@binkert.org 2256143Snate@binkert.orgdef update_test_string(target, source, env): 2264762Snate@binkert.org return env.subst("Updating ${SOURCES[0].dir} from ${SOURCES[1].dir}", 2276143Snate@binkert.org target=target, source=source) 2284762Snate@binkert.org 2296143Snate@binkert.orgupdateAction = env.Action(update_test, update_test_string) 2304762Snate@binkert.org 2316143Snate@binkert.orgdef test_builder(env, ref_dir): 2328233Snate@binkert.org """Define a test.""" 2338233Snate@binkert.org 23410453SAndrew.Bardsley@arm.com (category, name, _ref, isa, opsys, config) = ref_dir.split('/') 2356143Snate@binkert.org assert(_ref == 'ref') 2366143Snate@binkert.org 2376143Snate@binkert.org # target path (where test output goes) is the same except without 2386143Snate@binkert.org # the 'ref' component 2396143Snate@binkert.org tgt_dir = os.path.join(category, name, isa, opsys, config) 2406143Snate@binkert.org 2416143Snate@binkert.org # prepend file name with tgt_dir 2426143Snate@binkert.org def tgt(f): 24310453SAndrew.Bardsley@arm.com return os.path.join(tgt_dir, f) 24410453SAndrew.Bardsley@arm.com 245955SN/A 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) 2529396Sandreas.hansson@arm.com 2539396Sandreas.hansson@arm.com # phony target to echo status 2549396Sandreas.hansson@arm.com if env['update_ref']: 2559396Sandreas.hansson@arm.com p = env.Command(tgt('_update'), 2569396Sandreas.hansson@arm.com [ref_stats, new_stats, status_file], 2579396Sandreas.hansson@arm.com updateAction) 2589396Sandreas.hansson@arm.com else: 2599930Sandreas.hansson@arm.com p = env.Command(tgt('_print'), [status_file], printAction) 2609930Sandreas.hansson@arm.com 2619396Sandreas.hansson@arm.com env.AlwaysBuild(p) 2628235Snate@binkert.org 2638235Snate@binkert.org 2646143Snate@binkert.org# Figure out applicable configs based on build type 2658235Snate@binkert.orgconfigs = [] 2669003SAli.Saidi@ARM.comif 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', 2718235Snate@binkert.org 'tsunami-simple-timing-dual', 2728235Snate@binkert.org 'twosys-tsunami-simple-atomic', 2738235Snate@binkert.org 'tsunami-o3', 'tsunami-o3-dual'] 2748235Snate@binkert.org if env['TARGET_ISA'] == 'sparc': 2758235Snate@binkert.org configs += ['t1000-simple-atomic', 2768235Snate@binkert.org 't1000-simple-timing'] 2778235Snate@binkert.org if env['TARGET_ISA'] == 'arm': 2788235Snate@binkert.org configs += ['realview-simple-atomic', 2798235Snate@binkert.org 'realview-simple-timing'] 2808235Snate@binkert.org 2819003SAli.Saidi@ARM.comelse: 2828235Snate@binkert.org configs += ['simple-atomic', 'simple-timing', 'o3-timing', 'memtest', 2835584Snate@binkert.org 'simple-atomic-mp', 'simple-timing-mp', 'o3-timing-mp', 2844382Sbinkertn@umich.edu 'inorder-timing', 'rubytest'] 2854202Sbinkertn@umich.edu 2864382Sbinkertn@umich.eduif env['RUBY']: 2874382Sbinkertn@umich.edu # With Ruby, A protocol must be specified in the environment 2884382Sbinkertn@umich.edu assert(env['PROTOCOL']) 2899396Sandreas.hansson@arm.com 2905584Snate@binkert.org # 2914382Sbinkertn@umich.edu # Is there a way to determine what is Protocol EnumVariable 2924382Sbinkertn@umich.edu # default and eliminate the need to hard code the default protocol below? 2934382Sbinkertn@umich.edu # 2948232Snate@binkert.org # If the binary includes the default ruby protocol, run both ruby and 2955192Ssaidi@eecs.umich.edu # non-ruby versions of the tests. Otherwise just run the ruby versions. 2968232Snate@binkert.org # 2978232Snate@binkert.org if env['PROTOCOL'] == 'MI_example': 2988232Snate@binkert.org configs += [c + "-ruby" for c in configs] 2995192Ssaidi@eecs.umich.edu else: 3008232Snate@binkert.org configs = [c + "-ruby-" + env['PROTOCOL'] for c in configs] 3015192Ssaidi@eecs.umich.edu 3025799Snate@binkert.orgcwd = os.getcwd() 3038232Snate@binkert.orgos.chdir(str(Dir('.').srcdir)) 3045192Ssaidi@eecs.umich.edufor config in configs: 3055192Ssaidi@eecs.umich.edu dirs = glob.glob('*/*/ref/%s/*/%s' % (env['TARGET_ISA'], config)) 3065192Ssaidi@eecs.umich.edu for d in dirs: 3078232Snate@binkert.org if not os.path.exists(os.path.join(d, 'skip')): 3085192Ssaidi@eecs.umich.edu test_builder(env, d) 3098232Snate@binkert.orgos.chdir(cwd) 3105192Ssaidi@eecs.umich.edu