SConscript revision 2953
12929Sktlim@umich.edu# -*- mode:python -*- 22929Sktlim@umich.edu 32932Sktlim@umich.edu# Copyright (c) 2004-2006 The Regents of The University of Michigan 42929Sktlim@umich.edu# All rights reserved. 52929Sktlim@umich.edu# 62929Sktlim@umich.edu# Redistribution and use in source and binary forms, with or without 72929Sktlim@umich.edu# modification, are permitted provided that the following conditions are 82929Sktlim@umich.edu# met: redistributions of source code must retain the above copyright 92929Sktlim@umich.edu# notice, this list of conditions and the following disclaimer; 102929Sktlim@umich.edu# redistributions in binary form must reproduce the above copyright 112929Sktlim@umich.edu# notice, this list of conditions and the following disclaimer in the 122929Sktlim@umich.edu# documentation and/or other materials provided with the distribution; 132929Sktlim@umich.edu# neither the name of the copyright holders nor the names of its 142929Sktlim@umich.edu# contributors may be used to endorse or promote products derived from 152929Sktlim@umich.edu# this software without specific prior written permission. 162929Sktlim@umich.edu# 172929Sktlim@umich.edu# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 182929Sktlim@umich.edu# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 192929Sktlim@umich.edu# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 202929Sktlim@umich.edu# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 212929Sktlim@umich.edu# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 222929Sktlim@umich.edu# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 232929Sktlim@umich.edu# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 242929Sktlim@umich.edu# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 252929Sktlim@umich.edu# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 262929Sktlim@umich.edu# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 272929Sktlim@umich.edu# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 282932Sktlim@umich.edu# 292932Sktlim@umich.edu# Authors: Steve Reinhardt 302932Sktlim@umich.edu# Kevin Lim 312929Sktlim@umich.edu 326007Ssteve.reinhardt@amd.comimport os 332929Sktlim@umich.eduimport sys 342929Sktlim@umich.eduimport glob 352929Sktlim@umich.edufrom SCons.Script.SConscript import SConsEnvironment 362929Sktlim@umich.edu 372929Sktlim@umich.eduImport('env') 382929Sktlim@umich.edu 392929Sktlim@umich.eduenv['DIFFOUT'] = File('diff-out') 402929Sktlim@umich.edu 412929Sktlim@umich.edu# Dict that accumulates lists of tests by category (quick, medium, long) 422929Sktlim@umich.eduenv.Tests = {} 432929Sktlim@umich.edu 442929Sktlim@umich.edudef contents(node): 452929Sktlim@umich.edu return file(str(node)).read() 462929Sktlim@umich.edu 476007Ssteve.reinhardt@amd.comdef check_test(target, source, env): 486007Ssteve.reinhardt@amd.com """Check output from running test. 496007Ssteve.reinhardt@amd.com 506007Ssteve.reinhardt@amd.com Targets are as follows: 516007Ssteve.reinhardt@amd.com target[0] : outdiff 526007Ssteve.reinhardt@amd.com target[1] : statsdiff 536007Ssteve.reinhardt@amd.com target[2] : status 546007Ssteve.reinhardt@amd.com 556007Ssteve.reinhardt@amd.com """ 566007Ssteve.reinhardt@amd.com # make sure target files are all gone 576007Ssteve.reinhardt@amd.com for t in target: 586007Ssteve.reinhardt@amd.com if os.path.exists(t.abspath): 596007Ssteve.reinhardt@amd.com Execute(Delete(t.abspath)) 606007Ssteve.reinhardt@amd.com # Run diff on output & ref directories to find differences. 616007Ssteve.reinhardt@amd.com # Exclude m5stats.txt since we will use diff-out on that. 626007Ssteve.reinhardt@amd.com Execute(env.subst('diff -ubr ${SOURCES[0].dir} ${SOURCES[1].dir} ' + 636007Ssteve.reinhardt@amd.com '-I "^command line:" ' + # for stdout file 646007Ssteve.reinhardt@amd.com '-I "^M5 compiled on" ' + # for stderr file 656007Ssteve.reinhardt@amd.com '-I "^M5 simulation started" ' + # for stderr file 666007Ssteve.reinhardt@amd.com '-I "^Simulation complete at" ' + # for stderr file 676007Ssteve.reinhardt@amd.com '-I "^Listening for" ' + # for stderr file 686007Ssteve.reinhardt@amd.com '--exclude=m5stats.txt --exclude=SCCS ' + 696007Ssteve.reinhardt@amd.com '--exclude=${TARGETS[0].file} ' + 706007Ssteve.reinhardt@amd.com '> ${TARGETS[0]}', target=target, source=source), None) 716007Ssteve.reinhardt@amd.com print "===== Output differences =====" 726007Ssteve.reinhardt@amd.com print contents(target[0]) 736007Ssteve.reinhardt@amd.com # Run diff-out on m5stats.txt file 746007Ssteve.reinhardt@amd.com status = Execute(env.subst('$DIFFOUT $SOURCES > ${TARGETS[1]}', 756007Ssteve.reinhardt@amd.com target=target, source=source), 762929Sktlim@umich.edu strfunction=None) 772929Sktlim@umich.edu print "===== Statistics differences =====" 782929Sktlim@umich.edu print contents(target[1]) 796007Ssteve.reinhardt@amd.com # Generate status file contents based on exit status of diff-out 806007Ssteve.reinhardt@amd.com if status == 0: 816007Ssteve.reinhardt@amd.com status_str = "passed." 826007Ssteve.reinhardt@amd.com else: 836007Ssteve.reinhardt@amd.com status_str = "FAILED!" 846007Ssteve.reinhardt@amd.com f = file(str(target[2]), 'w') 852929Sktlim@umich.edu print >>f, env.subst('${TARGETS[2].dir}', target=target, source=source), \ 862929Sktlim@umich.edu status_str 872929Sktlim@umich.edu f.close() 882929Sktlim@umich.edu # done 892929Sktlim@umich.edu return 0 906011Ssteve.reinhardt@amd.com 916007Ssteve.reinhardt@amd.comdef check_test_string(target, source, env): 926007Ssteve.reinhardt@amd.com return env.subst("Comparing outputs in ${TARGETS[0].dir}.", 936007Ssteve.reinhardt@amd.com target=target, source=source) 946007Ssteve.reinhardt@amd.com 956007Ssteve.reinhardt@amd.comtestAction = env.Action(check_test, check_test_string) 966007Ssteve.reinhardt@amd.com 976007Ssteve.reinhardt@amd.comdef print_test(target, source, env): 986007Ssteve.reinhardt@amd.com print '***** ' + contents(source[0]) 996007Ssteve.reinhardt@amd.com return 0 1006007Ssteve.reinhardt@amd.com 1016007Ssteve.reinhardt@amd.comprintAction = env.Action(print_test, strfunction = None) 1026007Ssteve.reinhardt@amd.com 1036007Ssteve.reinhardt@amd.comdef update_test(target, source, env): 1046007Ssteve.reinhardt@amd.com """Update reference test outputs. 1056011Ssteve.reinhardt@amd.com 1066007Ssteve.reinhardt@amd.com Target is phony. First two sources are the ref & new m5stats.txt 1076007Ssteve.reinhardt@amd.com files, respectively. We actually copy everything in the 1086007Ssteve.reinhardt@amd.com respective directories except the status & diff output files. 1096007Ssteve.reinhardt@amd.com 1106007Ssteve.reinhardt@amd.com """ 1116007Ssteve.reinhardt@amd.com dest_dir = str(source[0].get_dir()) 1126007Ssteve.reinhardt@amd.com src_dir = str(source[1].get_dir()) 1136011Ssteve.reinhardt@amd.com dest_files = os.listdir(dest_dir) 1146007Ssteve.reinhardt@amd.com src_files = os.listdir(src_dir) 1156007Ssteve.reinhardt@amd.com # Exclude status & diff outputs 1166007Ssteve.reinhardt@amd.com for f in ('outdiff', 'statsdiff', 'status'): 1176007Ssteve.reinhardt@amd.com if f in src_files: 1186007Ssteve.reinhardt@amd.com src_files.remove(f) 1196007Ssteve.reinhardt@amd.com for f in src_files: 1206007Ssteve.reinhardt@amd.com if f in dest_files: 1216011Ssteve.reinhardt@amd.com print " Replacing file", f 1226007Ssteve.reinhardt@amd.com dest_files.remove(f) 1236007Ssteve.reinhardt@amd.com else: 1246007Ssteve.reinhardt@amd.com print " Creating new file", f 1256007Ssteve.reinhardt@amd.com copyAction = Copy(os.path.join(dest_dir, f), os.path.join(src_dir, f)) 1266007Ssteve.reinhardt@amd.com copyAction.strfunction = None 1276008Ssteve.reinhardt@amd.com Execute(copyAction) 1286007Ssteve.reinhardt@amd.com # warn about any files in dest not overwritten (other than SCCS dir) 1296008Ssteve.reinhardt@amd.com if 'SCCS' in dest_files: 1306008Ssteve.reinhardt@amd.com dest_files.remove('SCCS') 1316008Ssteve.reinhardt@amd.com if dest_files: 1326008Ssteve.reinhardt@amd.com print "Warning: file(s) in", dest_dir, "not updated:", 1336008Ssteve.reinhardt@amd.com print ', '.join(dest_files) 1346008Ssteve.reinhardt@amd.com return 0 1356008Ssteve.reinhardt@amd.com 1366007Ssteve.reinhardt@amd.comdef update_test_string(target, source, env): 1376007Ssteve.reinhardt@amd.com return env.subst("Updating ${SOURCES[0].dir} from ${SOURCES[1].dir}", 1386007Ssteve.reinhardt@amd.com target=target, source=source) 1396007Ssteve.reinhardt@amd.com 1406007Ssteve.reinhardt@amd.comupdateAction = env.Action(update_test, update_test_string) 1412929Sktlim@umich.edu 1422929Sktlim@umich.edudef test_builder(env, category, cpu_list=[], os_list=[], refdir='ref', 1432929Sktlim@umich.edu timeout=15): 1442929Sktlim@umich.edu """Define a test. 1456007Ssteve.reinhardt@amd.com 1466007Ssteve.reinhardt@amd.com Args: 1472929Sktlim@umich.edu category -- string describing test category (e.g., 'quick') 1482929Sktlim@umich.edu cpu_list -- list of CPUs to runs this test on (blank means all compiled CPUs) 1492929Sktlim@umich.edu os_list -- list of OSs to run this test on 1502929Sktlim@umich.edu refdir -- subdirectory containing reference output (default 'ref') 1516007Ssteve.reinhardt@amd.com timeout -- test timeout in minutes (only enforced on pool) 1526007Ssteve.reinhardt@amd.com 1532929Sktlim@umich.edu """ 1542929Sktlim@umich.edu 1556007Ssteve.reinhardt@amd.com default_refdir = False 1562929Sktlim@umich.edu if refdir == 'ref': 1572929Sktlim@umich.edu default_refdir = True 1582929Sktlim@umich.edu valid_cpu_list = [] 1592929Sktlim@umich.edu if len(cpu_list) == 0: 1602929Sktlim@umich.edu valid_cpu_list = env['CPU_MODELS'] 1612929Sktlim@umich.edu else: 1622929Sktlim@umich.edu for i in cpu_list: 1634937Sstever@gmail.com if i in env['CPU_MODELS']: 1644937Sstever@gmail.com valid_cpu_list.append(i) 1654937Sstever@gmail.com cpu_list = valid_cpu_list 1664937Sstever@gmail.com if env['TEST_CPU_MODELS']: 1674937Sstever@gmail.com valid_cpu_list = [] 1684937Sstever@gmail.com for i in env['TEST_CPU_MODELS']: 1694937Sstever@gmail.com if i in cpu_list: 1704937Sstever@gmail.com valid_cpu_list.append(i) 1714937Sstever@gmail.com cpu_list = valid_cpu_list 1725773Snate@binkert.org# Code commented out that shows the general structure if we want to test 1734937Sstever@gmail.com# different OS's as well. 1744937Sstever@gmail.com# if len(os_list) == 0: 1754937Sstever@gmail.com# for test_cpu in cpu_list: 1762929Sktlim@umich.edu# build_cpu_test(env, category, '', test_cpu, refdir, timeout) 1772929Sktlim@umich.edu# else: 1782929Sktlim@umich.edu# for test_os in os_list: 1795773Snate@binkert.org# for test_cpu in cpu_list: 1802929Sktlim@umich.edu# build_cpu_test(env, category, test_os, test_cpu, refdir, 1812929Sktlim@umich.edu# timeout) 1822929Sktlim@umich.edu # Loop through CPU models and generate proper options, ref directories 1832929Sktlim@umich.edu for cpu in cpu_list: 1842929Sktlim@umich.edu test_os = '' 1852929Sktlim@umich.edu if cpu == "AtomicSimpleCPU": 1864937Sstever@gmail.com cpu_option = ('','atomic/') 1874937Sstever@gmail.com elif cpu == "TimingSimpleCPU": 1884937Sstever@gmail.com cpu_option = ('--timing','timing/') 1894937Sstever@gmail.com elif cpu == "O3CPU": 1904937Sstever@gmail.com cpu_option = ('--detailed','detailed/') 1914937Sstever@gmail.com else: 1924937Sstever@gmail.com raise TypeError, "Unknown CPU model specified" 1934937Sstever@gmail.com 1944937Sstever@gmail.com if default_refdir: 1954937Sstever@gmail.com # Reference stats located in ref/arch/os/cpu or ref/arch/cpu 1964937Sstever@gmail.com # if no OS specified 1974937Sstever@gmail.com test_refdir = os.path.join(refdir, env['TARGET_ISA']) 1984937Sstever@gmail.com if test_os != '': 1994937Sstever@gmail.com test_refdir = os.path.join(test_refdir, test_os) 2004937Sstever@gmail.com cpu_refdir = os.path.join(test_refdir, cpu_option[1]) 2012929Sktlim@umich.edu 2022929Sktlim@umich.edu ref_stats = os.path.join(cpu_refdir, 'm5stats.txt') 2032929Sktlim@umich.edu 2042929Sktlim@umich.edu # base command for running test 2052929Sktlim@umich.edu base_cmd = '${SOURCES[0]} -d $TARGET.dir ${SOURCES[1]}' 2062929Sktlim@umich.edu base_cmd = base_cmd + ' ' + cpu_option[0] 2072929Sktlim@umich.edu # stdout and stderr files 2086011Ssteve.reinhardt@amd.com cmd_stdout = '${TARGETS[0]}' 2092929Sktlim@umich.edu cmd_stderr = '${TARGETS[1]}' 2102929Sktlim@umich.edu 2112929Sktlim@umich.edu stdout_string = cpu_option[1] + 'stdout' 2122929Sktlim@umich.edu stderr_string = cpu_option[1] + 'stderr' 2132929Sktlim@umich.edu m5stats_string = cpu_option[1] + 'm5stats.txt' 2142929Sktlim@umich.edu outdiff_string = cpu_option[1] + 'outdiff' 2152929Sktlim@umich.edu statsdiff_string = cpu_option[1] + 'statsdiff' 2162929Sktlim@umich.edu status_string = cpu_option[1] + 'status' 2172997Sstever@eecs.umich.edu 2182997Sstever@eecs.umich.edu # Prefix test run with batch job submission command if appropriate. 2192929Sktlim@umich.edu # Output redirection is also different for batch runs. 2202997Sstever@eecs.umich.edu # Batch command also supports timeout arg (in seconds, not minutes). 2212997Sstever@eecs.umich.edu if env['BATCH']: 2222929Sktlim@umich.edu cmd = [env['BATCH_CMD'], '-t', str(timeout * 60), 2232997Sstever@eecs.umich.edu '-o', cmd_stdout, '-e', cmd_stderr, base_cmd] 2242997Sstever@eecs.umich.edu else: 2252997Sstever@eecs.umich.edu cmd = [base_cmd, '>', cmd_stdout, '2>', cmd_stderr] 2262929Sktlim@umich.edu 2272997Sstever@eecs.umich.edu env.Command([stdout_string, stderr_string, m5stats_string], 2282997Sstever@eecs.umich.edu [env.M5Binary, 'run.py'], ' '.join(cmd)) 2292997Sstever@eecs.umich.edu 2302997Sstever@eecs.umich.edu # order of targets is important... see check_test 2315773Snate@binkert.org env.Command([outdiff_string, statsdiff_string, status_string], 2325773Snate@binkert.org [ref_stats, m5stats_string], 2332997Sstever@eecs.umich.edu testAction) 2342997Sstever@eecs.umich.edu 2356007Ssteve.reinhardt@amd.com # phony target to echo status 2366007Ssteve.reinhardt@amd.com if env['update_ref']: 2372997Sstever@eecs.umich.edu p = env.Command(cpu_option[1] + '_update', 2382929Sktlim@umich.edu [ref_stats, m5stats_string, status_string], 2392997Sstever@eecs.umich.edu updateAction) 2402997Sstever@eecs.umich.edu else: 2412997Sstever@eecs.umich.edu p = env.Command(cpu_option[1] + '_print', [status_string], 2422997Sstever@eecs.umich.edu printAction) 2432997Sstever@eecs.umich.edu env.AlwaysBuild(p) 2442997Sstever@eecs.umich.edu 2452997Sstever@eecs.umich.edu env.Tests.setdefault(category, []) 2462929Sktlim@umich.edu env.Tests[category] += p 2472997Sstever@eecs.umich.edu 2482929Sktlim@umich.edu# Make test_builder a "wrapper" function. See SCons wiki page at 2492929Sktlim@umich.edu# http://www.scons.org/cgi-bin/wiki/WrapperFunctions. 2503005Sstever@eecs.umich.eduSConsEnvironment.Test = test_builder 2513005Sstever@eecs.umich.edu 2523005Sstever@eecs.umich.educwd = os.getcwd() 2533005Sstever@eecs.umich.eduos.chdir(str(Dir('.').srcdir)) 2546025Snate@binkert.orgscripts = glob.glob('*/SConscript') 2556025Snate@binkert.orgos.chdir(cwd) 2566025Snate@binkert.org 2576025Snate@binkert.orgfor s in scripts: 2586025Snate@binkert.org SConscript(s, exports = 'env', duplicate = False) 2596025Snate@binkert.org 2604130Ssaidi@eecs.umich.edu# Set up phony commands for various test categories 2614130Ssaidi@eecs.umich.eduallTests = [] 2624130Ssaidi@eecs.umich.edufor (key, val) in env.Tests.iteritems(): 2633691Shsul@eecs.umich.edu env.Command(key, val, env.NoAction) 2643005Sstever@eecs.umich.edu allTests += val 2655721Shsul@eecs.umich.edu 2666194Sksewell@umich.edu# The 'all' target is redundant since just specifying the test 2676194Sksewell@umich.edu# directory name (e.g., ALPHA_SE/test/opt) has the same effect. 2683005Sstever@eecs.umich.eduenv.Command('all', allTests, env.NoAction) 2696168Snate@binkert.org