SConscript revision 3045
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#
292665Ssaidi@eecs.umich.edu# Authors: Steve Reinhardt
30955SN/A#          Kevin Lim
31955SN/A
32955SN/Aimport os
331608SN/Aimport sys
34955SN/Aimport glob
35955SN/Afrom SCons.Script.SConscript import SConsEnvironment
36955SN/A
37955SN/AImport('env')
38955SN/A
39955SN/Aenv['DIFFOUT'] = File('diff-out')
40955SN/A
41955SN/A# Dict that accumulates lists of tests by category (quick, medium, long)
42955SN/Aenv.Tests = {}
43955SN/A
44955SN/Adef contents(node):
45955SN/A    return file(str(node)).read()
46955SN/A
47955SN/Adef check_test(target, source, env):
482023SN/A    """Check output from running test.
49955SN/A
50955SN/A    Targets are as follows:
51955SN/A    target[0] : outdiff
52955SN/A    target[1] : statsdiff
53955SN/A    target[2] : status
54955SN/A
55955SN/A    """
56955SN/A    # make sure target files are all gone
57955SN/A    for t in target:
581031SN/A        if os.path.exists(t.abspath):
59955SN/A            Execute(Delete(t.abspath))
601388SN/A    # Run diff on output & ref directories to find differences.
61955SN/A    # Exclude m5stats.txt since we will use diff-out on that.
62955SN/A    Execute(env.subst('diff -ubr ${SOURCES[0].dir} ${SOURCES[1].dir} ' +
631296SN/A                      '-I "^command line:" ' +		# for stdout file
64955SN/A                      '-I "^M5 compiled " ' +		# for stderr file
652609SN/A                      '-I "^M5 started " ' +		# for stderr file
66955SN/A                      '-I "^M5 executing on " ' +	# for stderr file
67955SN/A                      '-I "^Simulation complete at" ' +	# for stderr file
68955SN/A                      '-I "^Listening for" ' +		# for stderr file
69955SN/A                      '-I "listening for remote gdb" ' + # for stderr file
70955SN/A                      '--exclude=m5stats.txt --exclude=SCCS ' +
71955SN/A                      '--exclude=${TARGETS[0].file} ' +
72955SN/A                      '> ${TARGETS[0]}', target=target, source=source), None)
73955SN/A    print "===== Output differences ====="
74955SN/A    print contents(target[0])
75955SN/A    # Run diff-out on m5stats.txt file
76955SN/A    status = Execute(env.subst('$DIFFOUT $SOURCES > ${TARGETS[1]}',
77955SN/A                               target=target, source=source),
78955SN/A                     strfunction=None)
79955SN/A    print "===== Statistics differences ====="
80955SN/A    print contents(target[1])
81955SN/A    # Generate status file contents based on exit status of diff-out
82955SN/A    if status == 0:
83955SN/A        status_str = "passed."
841717SN/A    else:
852190SN/A        status_str = "FAILED!"
862652Ssaidi@eecs.umich.edu    f = file(str(target[2]), 'w')
87955SN/A    print >>f, env.subst('${TARGETS[2].dir}', target=target, source=source), \
882410SN/A          status_str
89955SN/A    f.close()
90955SN/A    # done
911717SN/A    return 0
922568SN/A
932568SN/Adef check_test_string(target, source, env):
942568SN/A    return env.subst("Comparing outputs in ${TARGETS[0].dir}.",
952499SN/A                     target=target, source=source)
962462SN/A
972568SN/AtestAction = env.Action(check_test, check_test_string)
982395SN/A
992405SN/Adef print_test(target, source, env):
100955SN/A    print '***** ' + contents(source[0])
101955SN/A    return 0
102955SN/A
103955SN/AprintAction = env.Action(print_test, strfunction = None)
104955SN/A
1052090SN/Adef update_test(target, source, env):
106955SN/A    """Update reference test outputs.
1072667Sstever@eecs.umich.edu
108955SN/A    Target is phony.  First two sources are the ref & new m5stats.txt
109955SN/A    files, respectively.  We actually copy everything in the
1101696SN/A    respective directories except the status & diff output files.
111955SN/A
112955SN/A    """
113955SN/A    dest_dir = str(source[0].get_dir())
1141127SN/A    src_dir = str(source[1].get_dir())
115955SN/A    dest_files = os.listdir(dest_dir)
116955SN/A    src_files = os.listdir(src_dir)
1172379SN/A    # Exclude status & diff outputs
118955SN/A    for f in ('outdiff', 'statsdiff', 'status'):
119955SN/A        if f in src_files:
120955SN/A            src_files.remove(f)
1212155SN/A    for f in src_files:
1222155SN/A        if f in dest_files:
1232155SN/A            print "  Replacing file", f
1242155SN/A            dest_files.remove(f)
1252155SN/A        else:
1262155SN/A            print "  Creating new file", f
1272155SN/A        copyAction = Copy(os.path.join(dest_dir, f), os.path.join(src_dir, f))
1282155SN/A        copyAction.strfunction = None
1292155SN/A        Execute(copyAction)
1302155SN/A    # warn about any files in dest not overwritten (other than SCCS dir)
1312155SN/A    if 'SCCS' in dest_files:
1322155SN/A        dest_files.remove('SCCS')
1332155SN/A    if dest_files:
1342155SN/A        print "Warning: file(s) in", dest_dir, "not updated:",
1352155SN/A        print ', '.join(dest_files)
1362155SN/A    return 0
1372155SN/A
1382155SN/Adef update_test_string(target, source, env):
1392155SN/A    return env.subst("Updating ${SOURCES[0].dir} from ${SOURCES[1].dir}",
1402155SN/A                     target=target, source=source)
1412155SN/A
1422155SN/AupdateAction = env.Action(update_test, update_test_string)
1432155SN/A
1442155SN/Adef test_builder(env, ref_dir):
1452155SN/A    """Define a test."""
1462155SN/A
1472155SN/A    (category, name, _ref, isa, opsys, config) = ref_dir.split('/')
1482155SN/A    assert(_ref == 'ref')
1492155SN/A
1502155SN/A    # target path (where test output goes) is the same except without
1512155SN/A    # the 'ref' component
1522155SN/A    tgt_dir = os.path.join(category, name, isa, opsys, config)
1532155SN/A
1542155SN/A    # prepend file name with tgt_dir
1552155SN/A    def tgt(f):
1562155SN/A        return os.path.join(tgt_dir, f)
1572155SN/A
1582155SN/A    ref_stats = os.path.join(ref_dir, 'm5stats.txt')
1592155SN/A    new_stats = tgt('m5stats.txt')
1602422SN/A    status_file = tgt('status')
1612422SN/A
1622422SN/A    # Base command for running test.  We mess around with indirectly
1632422SN/A    # referring to files via SOURCES and TARGETS so that scons can
1642422SN/A    # mess with paths all it wants to and we still get the right
1652422SN/A    # files.
1662422SN/A    base_cmd = '${SOURCES[0]} -d $TARGET.dir ${SOURCES[1]} %s' % tgt_dir
1672397SN/A    # stdout and stderr files
1682397SN/A    cmd_stdout = '${TARGETS[0]}'
1692422SN/A    cmd_stderr = '${TARGETS[1]}'
1702422SN/A
171955SN/A    # Prefix test run with batch job submission command if appropriate.
172955SN/A    # Output redirection is also different for batch runs.
173955SN/A    # Batch command also supports timeout arg (in seconds, not minutes).
174955SN/A    timeout = 15 # used to be a param, probably should be again
175955SN/A    if env['BATCH']:
176955SN/A        cmd = [env['BATCH_CMD'], '-t', str(timeout * 60),
177955SN/A               '-o', cmd_stdout, '-e', cmd_stderr, base_cmd]
178955SN/A    else:
1791078SN/A        cmd = [base_cmd, '>', cmd_stdout, '2>', cmd_stderr]
180955SN/A            
181955SN/A    env.Command([tgt('stdout'), tgt('stderr'), new_stats],
182955SN/A                [env.M5Binary, 'run.py'], ' '.join(cmd))
183955SN/A
1841917SN/A    # order of targets is important... see check_test
185955SN/A    env.Command([tgt('outdiff'), tgt('statsdiff'), status_file],
186955SN/A                [ref_stats, new_stats],
187955SN/A                testAction)
188955SN/A
189974SN/A    # phony target to echo status
190955SN/A    if env['update_ref']:
191955SN/A        p = env.Command(tgt('_update'),
192955SN/A                        [ref_stats, new_stats, status_file],
193955SN/A                        updateAction)
1942566SN/A    else:
1952566SN/A        p = env.Command(tgt('_print'), [status_file], printAction)
196955SN/A
197955SN/A    env.AlwaysBuild(p)
1982539SN/A
199955SN/A
200955SN/A# Figure out applicable configs based on build type
201955SN/Aconfigs = []
2021817SN/Aif env['FULL_SYSTEM']:
2031154SN/A    if env['TARGET_ISA'] == 'alpha':
2041840SN/A        if not env['ALPHA_TLASER']:
2052522SN/A            configs += ['tsunami-simple-atomic',
2062522SN/A                        'tsunami-simple-timing',
2072629SN/A                        'tsunami-simple-atomic-dual',
208955SN/A                        'tsunami-simple-timing-dual']
209955SN/Aelse:
210955SN/A    configs += ['simple-atomic', 'simple-timing']
2112539SN/A
212955SN/Acwd = os.getcwd()
2132539SN/Aos.chdir(str(Dir('.').srcdir))
214955SN/Afor config in configs:
2151730SN/A    dirs = glob.glob('*/*/ref/%s/*/%s' % (env['TARGET_ISA'], config))
216955SN/A    for d in dirs:
2171070SN/A        test_builder(env, d)
218955SN/Aos.chdir(cwd)
219955SN/A