SConscript revision 5799
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
322929Sktlim@umich.eduimport 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
472929Sktlim@umich.edudef check_test(target, source, env):
482929Sktlim@umich.edu    """Check output from running test.
492929Sktlim@umich.edu
502929Sktlim@umich.edu    Targets are as follows:
512929Sktlim@umich.edu    target[0] : outdiff
522929Sktlim@umich.edu    target[1] : statsdiff
532929Sktlim@umich.edu    target[2] : status
542929Sktlim@umich.edu
552929Sktlim@umich.edu    """
562929Sktlim@umich.edu    # make sure target files are all gone
572929Sktlim@umich.edu    for t in target:
582929Sktlim@umich.edu        if os.path.exists(t.abspath):
592929Sktlim@umich.edu            Execute(Delete(t.abspath))
602929Sktlim@umich.edu    # Run diff on output & ref directories to find differences.
615773Snate@binkert.org    # Exclude the stats file since we will use diff-out on that.
622929Sktlim@umich.edu    Execute(env.subst('diff -ubr ${SOURCES[0].dir} ${SOURCES[1].dir} ' +
632929Sktlim@umich.edu                      '-I "^command line:" ' +		# for stdout file
643020Sstever@eecs.umich.edu                      '-I "^M5 compiled " ' +		# for stderr file
653020Sstever@eecs.umich.edu                      '-I "^M5 started " ' +		# for stderr file
663020Sstever@eecs.umich.edu                      '-I "^M5 executing on " ' +	# for stderr file
672929Sktlim@umich.edu                      '-I "^Simulation complete at" ' +	# for stderr file
682929Sktlim@umich.edu                      '-I "^Listening for" ' +		# for stderr file
693021Sstever@eecs.umich.edu                      '-I "listening for remote gdb" ' + # for stderr file
705773Snate@binkert.org                      '--exclude=stats.txt --exclude=SCCS ' +
712929Sktlim@umich.edu                      '--exclude=${TARGETS[0].file} ' +
722929Sktlim@umich.edu                      '> ${TARGETS[0]}', target=target, source=source), None)
732929Sktlim@umich.edu    print "===== Output differences ====="
742929Sktlim@umich.edu    print contents(target[0])
755773Snate@binkert.org    # Run diff-out on stats.txt file
762929Sktlim@umich.edu    status = Execute(env.subst('$DIFFOUT $SOURCES > ${TARGETS[1]}',
772929Sktlim@umich.edu                               target=target, source=source),
782929Sktlim@umich.edu                     strfunction=None)
792929Sktlim@umich.edu    print "===== Statistics differences ====="
802929Sktlim@umich.edu    print contents(target[1])
812929Sktlim@umich.edu    # Generate status file contents based on exit status of diff-out
822929Sktlim@umich.edu    if status == 0:
832929Sktlim@umich.edu        status_str = "passed."
842929Sktlim@umich.edu    else:
852929Sktlim@umich.edu        status_str = "FAILED!"
862929Sktlim@umich.edu    f = file(str(target[2]), 'w')
872929Sktlim@umich.edu    print >>f, env.subst('${TARGETS[2].dir}', target=target, source=source), \
882929Sktlim@umich.edu          status_str
892929Sktlim@umich.edu    f.close()
902929Sktlim@umich.edu    # done
912929Sktlim@umich.edu    return 0
922929Sktlim@umich.edu
932929Sktlim@umich.edudef check_test_string(target, source, env):
942929Sktlim@umich.edu    return env.subst("Comparing outputs in ${TARGETS[0].dir}.",
952929Sktlim@umich.edu                     target=target, source=source)
962929Sktlim@umich.edu
972929Sktlim@umich.edutestAction = env.Action(check_test, check_test_string)
982929Sktlim@umich.edu
992929Sktlim@umich.edudef print_test(target, source, env):
1002929Sktlim@umich.edu    print '***** ' + contents(source[0])
1012929Sktlim@umich.edu    return 0
1022929Sktlim@umich.edu
1032929Sktlim@umich.eduprintAction = env.Action(print_test, strfunction = None)
1042929Sktlim@umich.edu
1054937Sstever@gmail.com# Static vars for update_test:
1064937Sstever@gmail.com# - long-winded message about ignored sources
1074937Sstever@gmail.comignore_msg = '''
1084937Sstever@gmail.comNote: The following file(s) will not be copied.  New non-standard
1094937Sstever@gmail.com      output files must be copied manually once before update_ref will
1104937Sstever@gmail.com      recognize them as outputs.  Otherwise they are assumed to be
1114937Sstever@gmail.com      inputs and are ignored.
1124937Sstever@gmail.com'''
1134937Sstever@gmail.com# - reference files always needed
1145773Snate@binkert.orgneeded_files = set(['simout', 'simerr', 'stats.txt', 'config.ini'])
1154937Sstever@gmail.com# - source files we always want to ignore
1164937Sstever@gmail.comknown_ignores = set(['status', 'outdiff', 'statsdiff'])
1174937Sstever@gmail.com
1182929Sktlim@umich.edudef update_test(target, source, env):
1192929Sktlim@umich.edu    """Update reference test outputs.
1202929Sktlim@umich.edu
1215773Snate@binkert.org    Target is phony.  First two sources are the ref & new stats.txt file
1222929Sktlim@umich.edu    files, respectively.  We actually copy everything in the
1232929Sktlim@umich.edu    respective directories except the status & diff output files.
1242929Sktlim@umich.edu
1252929Sktlim@umich.edu    """
1262929Sktlim@umich.edu    dest_dir = str(source[0].get_dir())
1272929Sktlim@umich.edu    src_dir = str(source[1].get_dir())
1284937Sstever@gmail.com    dest_files = set(os.listdir(dest_dir))
1294937Sstever@gmail.com    src_files = set(os.listdir(src_dir))
1304937Sstever@gmail.com    # Copy all of the required files plus any existing dest files.
1314937Sstever@gmail.com    wanted_files = needed_files | dest_files
1324937Sstever@gmail.com    missing_files = wanted_files - src_files
1334937Sstever@gmail.com    if len(missing_files) > 0:
1344937Sstever@gmail.com        print "  WARNING: the following file(s) are missing " \
1354937Sstever@gmail.com              "and will not be updated:"
1364937Sstever@gmail.com        print "    ", " ,".join(missing_files)
1374937Sstever@gmail.com    copy_files = wanted_files - missing_files
1384937Sstever@gmail.com    warn_ignored_files = (src_files - copy_files) - known_ignores
1394937Sstever@gmail.com    if len(warn_ignored_files) > 0:
1404937Sstever@gmail.com        print ignore_msg,
1414937Sstever@gmail.com        print "       ", ", ".join(warn_ignored_files)
1424937Sstever@gmail.com    for f in copy_files:
1432929Sktlim@umich.edu        if f in dest_files:
1442929Sktlim@umich.edu            print "  Replacing file", f
1452929Sktlim@umich.edu            dest_files.remove(f)
1462929Sktlim@umich.edu        else:
1472929Sktlim@umich.edu            print "  Creating new file", f
1482929Sktlim@umich.edu        copyAction = Copy(os.path.join(dest_dir, f), os.path.join(src_dir, f))
1492929Sktlim@umich.edu        copyAction.strfunction = None
1502929Sktlim@umich.edu        Execute(copyAction)
1512929Sktlim@umich.edu    return 0
1522929Sktlim@umich.edu
1532929Sktlim@umich.edudef update_test_string(target, source, env):
1542929Sktlim@umich.edu    return env.subst("Updating ${SOURCES[0].dir} from ${SOURCES[1].dir}",
1552929Sktlim@umich.edu                     target=target, source=source)
1562929Sktlim@umich.edu
1572929Sktlim@umich.eduupdateAction = env.Action(update_test, update_test_string)
1582929Sktlim@umich.edu
1592997Sstever@eecs.umich.edudef test_builder(env, ref_dir):
1602997Sstever@eecs.umich.edu    """Define a test."""
1612929Sktlim@umich.edu
1622997Sstever@eecs.umich.edu    (category, name, _ref, isa, opsys, config) = ref_dir.split('/')
1632997Sstever@eecs.umich.edu    assert(_ref == 'ref')
1642929Sktlim@umich.edu
1652997Sstever@eecs.umich.edu    # target path (where test output goes) is the same except without
1662997Sstever@eecs.umich.edu    # the 'ref' component
1672997Sstever@eecs.umich.edu    tgt_dir = os.path.join(category, name, isa, opsys, config)
1682929Sktlim@umich.edu
1692997Sstever@eecs.umich.edu    # prepend file name with tgt_dir
1702997Sstever@eecs.umich.edu    def tgt(f):
1712997Sstever@eecs.umich.edu        return os.path.join(tgt_dir, f)
1722997Sstever@eecs.umich.edu
1735773Snate@binkert.org    ref_stats = os.path.join(ref_dir, 'stats.txt')
1745773Snate@binkert.org    new_stats = tgt('stats.txt')
1752997Sstever@eecs.umich.edu    status_file = tgt('status')
1762997Sstever@eecs.umich.edu
1772997Sstever@eecs.umich.edu    # Base command for running test.  We mess around with indirectly
1782997Sstever@eecs.umich.edu    # referring to files via SOURCES and TARGETS so that scons can
1792997Sstever@eecs.umich.edu    # mess with paths all it wants to and we still get the right
1802997Sstever@eecs.umich.edu    # files.
1815773Snate@binkert.org    cmd = '${SOURCES[0]} -d $TARGET.dir -re ${SOURCES[1]} %s' % tgt_dir
1822997Sstever@eecs.umich.edu
1832997Sstever@eecs.umich.edu    # Prefix test run with batch job submission command if appropriate.
1842997Sstever@eecs.umich.edu    # Batch command also supports timeout arg (in seconds, not minutes).
1855525Sstever@gmail.com    timeout = 15 * 60 # used to be a param, probably should be again
1862997Sstever@eecs.umich.edu    if env['BATCH']:
1875525Sstever@gmail.com        cmd = '%s -t %d %s' % (env['BATCH_CMD'], timeout, cmd)
1884781Snate@binkert.org
1895773Snate@binkert.org    env.Command([tgt('simout'), tgt('simerr'), new_stats],
1905525Sstever@gmail.com                [env.M5Binary, 'run.py'], cmd)
1912929Sktlim@umich.edu
1922997Sstever@eecs.umich.edu    # order of targets is important... see check_test
1932997Sstever@eecs.umich.edu    env.Command([tgt('outdiff'), tgt('statsdiff'), status_file],
1942997Sstever@eecs.umich.edu                [ref_stats, new_stats],
1952997Sstever@eecs.umich.edu                testAction)
1962929Sktlim@umich.edu
1972997Sstever@eecs.umich.edu    # phony target to echo status
1982997Sstever@eecs.umich.edu    if env['update_ref']:
1992997Sstever@eecs.umich.edu        p = env.Command(tgt('_update'),
2002997Sstever@eecs.umich.edu                        [ref_stats, new_stats, status_file],
2012997Sstever@eecs.umich.edu                        updateAction)
2022997Sstever@eecs.umich.edu    else:
2032997Sstever@eecs.umich.edu        p = env.Command(tgt('_print'), [status_file], printAction)
2042929Sktlim@umich.edu
2052997Sstever@eecs.umich.edu    env.AlwaysBuild(p)
2062929Sktlim@umich.edu
2072929Sktlim@umich.edu
2083005Sstever@eecs.umich.edu# Figure out applicable configs based on build type
2093005Sstever@eecs.umich.educonfigs = []
2103005Sstever@eecs.umich.eduif env['FULL_SYSTEM']:
2113005Sstever@eecs.umich.edu    if env['TARGET_ISA'] == 'alpha':
2123005Sstever@eecs.umich.edu        if not env['ALPHA_TLASER']:
2133005Sstever@eecs.umich.edu            configs += ['tsunami-simple-atomic',
2143005Sstever@eecs.umich.edu                        'tsunami-simple-timing',
2153005Sstever@eecs.umich.edu                        'tsunami-simple-atomic-dual',
2163691Shsul@eecs.umich.edu                        'tsunami-simple-timing-dual',
2175703Ssaidi@eecs.umich.edu                        'twosys-tsunami-simple-atomic',
2185703Ssaidi@eecs.umich.edu                        'tsunami-o3', 'tsunami-o3-dual']
2194130Ssaidi@eecs.umich.edu    if env['TARGET_ISA'] == 'sparc':
2204130Ssaidi@eecs.umich.edu        configs += ['t1000-simple-atomic',
2214130Ssaidi@eecs.umich.edu                    't1000-simple-timing']
2223691Shsul@eecs.umich.edu
2233005Sstever@eecs.umich.eduelse:
2245721Shsul@eecs.umich.edu    configs += ['simple-atomic', 'simple-timing', 'o3-timing', 'memtest',
2255721Shsul@eecs.umich.edu                'simple-atomic-mp', 'simple-timing-mp']
2263005Sstever@eecs.umich.edu
2272929Sktlim@umich.educwd = os.getcwd()
2282929Sktlim@umich.eduos.chdir(str(Dir('.').srcdir))
2293005Sstever@eecs.umich.edufor config in configs:
2302997Sstever@eecs.umich.edu    dirs = glob.glob('*/*/ref/%s/*/%s' % (env['TARGET_ISA'], config))
2312997Sstever@eecs.umich.edu    for d in dirs:
2322997Sstever@eecs.umich.edu        test_builder(env, d)
2332929Sktlim@umich.eduos.chdir(cwd)
234