SConscript revision 4936:b05a404dce16
1360SN/A# -*- mode:python -*-
21458SN/A
3360SN/A# Copyright (c) 2004-2006 The Regents of The University of Michigan
4360SN/A# All rights reserved.
5360SN/A#
6360SN/A# Redistribution and use in source and binary forms, with or without
7360SN/A# modification, are permitted provided that the following conditions are
8360SN/A# met: redistributions of source code must retain the above copyright
9360SN/A# notice, this list of conditions and the following disclaimer;
10360SN/A# redistributions in binary form must reproduce the above copyright
11360SN/A# notice, this list of conditions and the following disclaimer in the
12360SN/A# documentation and/or other materials provided with the distribution;
13360SN/A# neither the name of the copyright holders nor the names of its
14360SN/A# contributors may be used to endorse or promote products derived from
15360SN/A# this software without specific prior written permission.
16360SN/A#
17360SN/A# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18360SN/A# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19360SN/A# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20360SN/A# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21360SN/A# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22360SN/A# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23360SN/A# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24360SN/A# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25360SN/A# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26360SN/A# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
272665Ssaidi@eecs.umich.edu# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
282665Ssaidi@eecs.umich.edu#
292665Ssaidi@eecs.umich.edu# Authors: Steve Reinhardt
30360SN/A#          Kevin Lim
31360SN/A
322093SN/Aimport os
33360SN/Aimport sys
34360SN/Aimport glob
35360SN/Afrom SCons.Script.SConscript import SConsEnvironment
36360SN/A
37360SN/AImport('env')
38360SN/A
392474SN/Aenv['DIFFOUT'] = File('diff-out')
40360SN/A
412680Sktlim@umich.edu# Dict that accumulates lists of tests by category (quick, medium, long)
421717SN/Aenv.Tests = {}
432474SN/A
44360SN/Adef contents(node):
456029Ssteve.reinhardt@amd.com    return file(str(node)).read()
46360SN/A
472667Sstever@eecs.umich.edudef check_test(target, source, env):
48360SN/A    """Check output from running test.
49360SN/A
502107SN/A    Targets are as follows:
51360SN/A    target[0] : outdiff
52360SN/A    target[1] : statsdiff
533114Sgblack@eecs.umich.edu    target[2] : status
54360SN/A
556111Ssteve.reinhardt@amd.com    """
566111Ssteve.reinhardt@amd.com    # make sure target files are all gone
576111Ssteve.reinhardt@amd.com    for t in target:
585958Sgblack@eecs.umich.edu        if os.path.exists(t.abspath):
595958Sgblack@eecs.umich.edu            Execute(Delete(t.abspath))
60360SN/A    # Run diff on output & ref directories to find differences.
612680Sktlim@umich.edu    # Exclude m5stats.txt since we will use diff-out on that.
62360SN/A    Execute(env.subst('diff -ubr ${SOURCES[0].dir} ${SOURCES[1].dir} ' +
632495SN/A                      '-I "^command line:" ' +		# for stdout file
642680Sktlim@umich.edu                      '-I "^M5 compiled " ' +		# for stderr file
65360SN/A                      '-I "^M5 started " ' +		# for stderr file
661450SN/A                      '-I "^M5 executing on " ' +	# for stderr file
675958Sgblack@eecs.umich.edu                      '-I "^Simulation complete at" ' +	# for stderr file
68360SN/A                      '-I "^Listening for" ' +		# for stderr file
69360SN/A                      '-I "listening for remote gdb" ' + # for stderr file
70360SN/A                      '--exclude=m5stats.txt --exclude=SCCS ' +
711450SN/A                      '--exclude=${TARGETS[0].file} ' +
723114Sgblack@eecs.umich.edu                      '> ${TARGETS[0]}', target=target, source=source), None)
732680Sktlim@umich.edu    print "===== Output differences ====="
74360SN/A    print contents(target[0])
751969SN/A    # Run diff-out on m5stats.txt file
762484SN/A    status = Execute(env.subst('$DIFFOUT $SOURCES > ${TARGETS[1]}',
772484SN/A                               target=target, source=source),
78360SN/A                     strfunction=None)
79360SN/A    print "===== Statistics differences ====="
80360SN/A    print contents(target[1])
811450SN/A    # Generate status file contents based on exit status of diff-out
823114Sgblack@eecs.umich.edu    if status == 0:
832680Sktlim@umich.edu        status_str = "passed."
84360SN/A    else:
851969SN/A        status_str = "FAILED!"
865958Sgblack@eecs.umich.edu    f = file(str(target[2]), 'w')
87360SN/A    print >>f, env.subst('${TARGETS[2].dir}', target=target, source=source), \
881458SN/A          status_str
89360SN/A    f.close()
90360SN/A    # done
91360SN/A    return 0
921450SN/A
933114Sgblack@eecs.umich.edudef check_test_string(target, source, env):
942680Sktlim@umich.edu    return env.subst("Comparing outputs in ${TARGETS[0].dir}.",
95360SN/A                     target=target, source=source)
966029Ssteve.reinhardt@amd.com
976029Ssteve.reinhardt@amd.comtestAction = env.Action(check_test, check_test_string)
985958Sgblack@eecs.umich.edu
996029Ssteve.reinhardt@amd.comdef print_test(target, source, env):
1006029Ssteve.reinhardt@amd.com    print '***** ' + contents(source[0])
1016029Ssteve.reinhardt@amd.com    return 0
1026029Ssteve.reinhardt@amd.com
1032834Sksewell@umich.eduprintAction = env.Action(print_test, strfunction = None)
104360SN/A
1051458SN/Adef update_test(target, source, env):
106360SN/A    """Update reference test outputs.
107360SN/A
108360SN/A    Target is phony.  First two sources are the ref & new m5stats.txt
1091450SN/A    files, respectively.  We actually copy everything in the
1106109Ssanchezd@stanford.edu    respective directories except the status & diff output files.
1116109Ssanchezd@stanford.edu
1126109Ssanchezd@stanford.edu    """
1136109Ssanchezd@stanford.edu    dest_dir = str(source[0].get_dir())
1146109Ssanchezd@stanford.edu    src_dir = str(source[1].get_dir())
1156109Ssanchezd@stanford.edu    dest_files = os.listdir(dest_dir)
1166109Ssanchezd@stanford.edu    src_files = os.listdir(src_dir)
1176109Ssanchezd@stanford.edu    for f in ('stdout', 'stderr', 'm5stats.txt', 'config.ini'):
1186109Ssanchezd@stanford.edu        if f in dest_files:
1196109Ssanchezd@stanford.edu            print "  Replacing file", f
1206109Ssanchezd@stanford.edu            dest_files.remove(f)
1216109Ssanchezd@stanford.edu        else:
1226109Ssanchezd@stanford.edu            print "  Creating new file", f
1233114Sgblack@eecs.umich.edu        copyAction = Copy(os.path.join(dest_dir, f), os.path.join(src_dir, f))
124360SN/A        copyAction.strfunction = None
1252107SN/A        Execute(copyAction)
126360SN/A    # warn about any files in dest not overwritten (other than SCCS dir)
127360SN/A    if 'SCCS' in dest_files:
128360SN/A        dest_files.remove('SCCS')
1291450SN/A    if dest_files:
1305748SSteve.Reinhardt@amd.com        print "Warning: file(s) in", dest_dir, "not updated:",
131360SN/A        print ', '.join(dest_files)
132360SN/A    return 0
1335958Sgblack@eecs.umich.edu
1345748SSteve.Reinhardt@amd.comdef update_test_string(target, source, env):
1355748SSteve.Reinhardt@amd.com    return env.subst("Updating ${SOURCES[0].dir} from ${SOURCES[1].dir}",
1365748SSteve.Reinhardt@amd.com                     target=target, source=source)
1375748SSteve.Reinhardt@amd.com
1385748SSteve.Reinhardt@amd.comupdateAction = env.Action(update_test, update_test_string)
1395748SSteve.Reinhardt@amd.com
1405748SSteve.Reinhardt@amd.comdef test_builder(env, ref_dir):
1415748SSteve.Reinhardt@amd.com    """Define a test."""
1422474SN/A
1432474SN/A    (category, name, _ref, isa, opsys, config) = ref_dir.split('/')
1445748SSteve.Reinhardt@amd.com    assert(_ref == 'ref')
1452474SN/A
1462474SN/A    # target path (where test output goes) is the same except without
1472474SN/A    # the 'ref' component
1481450SN/A    tgt_dir = os.path.join(category, name, isa, opsys, config)
1495748SSteve.Reinhardt@amd.com
1505748SSteve.Reinhardt@amd.com    # prepend file name with tgt_dir
1511458SN/A    def tgt(f):
1521458SN/A        return os.path.join(tgt_dir, f)
153360SN/A
154360SN/A    ref_stats = os.path.join(ref_dir, 'm5stats.txt')
155360SN/A    new_stats = tgt('m5stats.txt')
1561450SN/A    status_file = tgt('status')
1573114Sgblack@eecs.umich.edu
158360SN/A    # Base command for running test.  We mess around with indirectly
1595958Sgblack@eecs.umich.edu    # referring to files via SOURCES and TARGETS so that scons can
1601970SN/A    # mess with paths all it wants to and we still get the right
1611970SN/A    # files.
1621970SN/A    base_cmd = '${SOURCES[0]} -d $TARGET.dir ${SOURCES[1]} %s' % tgt_dir
1631970SN/A    # stdout and stderr files
164360SN/A    cmd_stdout = '${TARGETS[0]}'
165360SN/A    cmd_stderr = '${TARGETS[1]}'
166360SN/A
1671450SN/A    # Prefix test run with batch job submission command if appropriate.
1683114Sgblack@eecs.umich.edu    # Output redirection is also different for batch runs.
169360SN/A    # Batch command also supports timeout arg (in seconds, not minutes).
1705958Sgblack@eecs.umich.edu    timeout = 15 # used to be a param, probably should be again
1715958Sgblack@eecs.umich.edu    if env['BATCH']:
1725958Sgblack@eecs.umich.edu        cmd = [env['BATCH_CMD'], '-t', str(timeout * 60),
173360SN/A               '-o', cmd_stdout, '-e', cmd_stderr, base_cmd]
174360SN/A    else:
175360SN/A        cmd = [base_cmd, '>', cmd_stdout, '2>', cmd_stderr]
176360SN/A
1772680Sktlim@umich.edu    env.Command([tgt('stdout'), tgt('stderr'), new_stats],
178360SN/A                [env.M5Binary, 'run.py'], ' '.join(cmd))
1791458SN/A
180360SN/A    # order of targets is important... see check_test
181360SN/A    env.Command([tgt('outdiff'), tgt('statsdiff'), status_file],
1821450SN/A                [ref_stats, new_stats],
1833114Sgblack@eecs.umich.edu                testAction)
184360SN/A
1855958Sgblack@eecs.umich.edu    # phony target to echo status
1865958Sgblack@eecs.umich.edu    if env['update_ref']:
1875958Sgblack@eecs.umich.edu        p = env.Command(tgt('_update'),
188360SN/A                        [ref_stats, new_stats, status_file],
1892680Sktlim@umich.edu                        updateAction)
190360SN/A    else:
191360SN/A        p = env.Command(tgt('_print'), [status_file], printAction)
192360SN/A
193360SN/A    env.AlwaysBuild(p)
194360SN/A
1951458SN/A
196360SN/A# Figure out applicable configs based on build type
197360SN/Aconfigs = []
198360SN/Aif env['FULL_SYSTEM']:
1991450SN/A    if env['TARGET_ISA'] == 'alpha':
2003114Sgblack@eecs.umich.edu        if not env['ALPHA_TLASER']:
201360SN/A            configs += ['tsunami-simple-atomic',
2025958Sgblack@eecs.umich.edu                        'tsunami-simple-timing',
2035958Sgblack@eecs.umich.edu                        'tsunami-simple-atomic-dual',
2045958Sgblack@eecs.umich.edu                        'tsunami-simple-timing-dual',
205360SN/A                        'twosys-tsunami-simple-atomic']
206360SN/A    if env['TARGET_ISA'] == 'sparc':
207360SN/A        configs += ['t1000-simple-atomic',
2081458SN/A                    't1000-simple-timing']
209360SN/A
210360SN/Aelse:
211360SN/A    configs += ['simple-atomic', 'simple-timing', 'o3-timing', 'memtest']
2121450SN/A
2134118Sgblack@eecs.umich.educwd = os.getcwd()
2144118Sgblack@eecs.umich.eduos.chdir(str(Dir('.').srcdir))
2155958Sgblack@eecs.umich.edufor config in configs:
2165958Sgblack@eecs.umich.edu    dirs = glob.glob('*/*/ref/%s/*/%s' % (env['TARGET_ISA'], config))
2175958Sgblack@eecs.umich.edu    for d in dirs:
2185958Sgblack@eecs.umich.edu        test_builder(env, d)
2195958Sgblack@eecs.umich.eduos.chdir(cwd)
2204118Sgblack@eecs.umich.edu