SConscript revision 5773:7434b2271b0c
17860SN/A# -*- mode:python -*-
27860SN/A
37860SN/A# Copyright (c) 2004-2006 The Regents of The University of Michigan
49988Snilay@cs.wisc.edu# All rights reserved.
58825Snilay@cs.wisc.edu#
69988Snilay@cs.wisc.edu# Redistribution and use in source and binary forms, with or without
77935SN/A# modification, are permitted provided that the following conditions are
87935SN/A# met: redistributions of source code must retain the above copyright
97935SN/A# notice, this list of conditions and the following disclaimer;
107860SN/A# redistributions in binary form must reproduce the above copyright
117860SN/A# notice, this list of conditions and the following disclaimer in the
127860SN/A# documentation and/or other materials provided with the distribution;
139885Sstever@gmail.com# neither the name of the copyright holders nor the names of its
148825Snilay@cs.wisc.edu# contributors may be used to endorse or promote products derived from
159885Sstever@gmail.com# this software without specific prior written permission.
169885Sstever@gmail.com#
179988Snilay@cs.wisc.edu# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
188825Snilay@cs.wisc.edu# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
198825Snilay@cs.wisc.edu# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
208825Snilay@cs.wisc.edu# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
2110038SAli.Saidi@ARM.com# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
229449SAli.Saidi@ARM.com# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
239449SAli.Saidi@ARM.com# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
248464SN/A# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
258721SN/A# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
268825Snilay@cs.wisc.edu# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
278825Snilay@cs.wisc.edu# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
287935SN/A#
297935SN/A# Authors: Steve Reinhardt
307935SN/A#          Kevin Lim
317935SN/A
327935SN/Aimport os
337935SN/Aimport sys
347935SN/Aimport glob
358893Ssaidi@eecs.umich.edufrom SCons.Script.SConscript import SConsEnvironment
367860SN/A
379885Sstever@gmail.comImport('env')
389885Sstever@gmail.com
399885Sstever@gmail.comenv['DIFFOUT'] = File('diff-out')
409988Snilay@cs.wisc.edu
419885Sstever@gmail.com# Dict that accumulates lists of tests by category (quick, medium, long)
429885Sstever@gmail.comenv.Tests = {}
437860SN/A
447860SN/Adef contents(node):
4510038SAli.Saidi@ARM.com    return file(str(node)).read()
467860SN/A
477860SN/Adef check_test(target, source, env):
488210SN/A    """Check output from running test.
498210SN/A
507860SN/A    Targets are as follows:
517860SN/A    target[0] : outdiff
527860SN/A    target[1] : statsdiff
537860SN/A    target[2] : status
549481Snilay@cs.wisc.edu
557860SN/A    """
567860SN/A    # make sure target files are all gone
579885Sstever@gmail.com    for t in target:
587860SN/A        if os.path.exists(t.abspath):
597860SN/A            Execute(Delete(t.abspath))
607860SN/A    # Run diff on output & ref directories to find differences.
617860SN/A    # Exclude the stats file since we will use diff-out on that.
627860SN/A    Execute(env.subst('diff -ubr ${SOURCES[0].dir} ${SOURCES[1].dir} ' +
637860SN/A                      '-I "^command line:" ' +		# for stdout file
647860SN/A                      '-I "^M5 compiled " ' +		# for stderr file
657860SN/A                      '-I "^M5 started " ' +		# for stderr file
667860SN/A                      '-I "^M5 executing on " ' +	# for stderr file
677860SN/A                      '-I "^Simulation complete at" ' +	# for stderr file
687860SN/A                      '-I "^Listening for" ' +		# for stderr file
698825Snilay@cs.wisc.edu                      '-I "listening for remote gdb" ' + # for stderr file
707860SN/A                      '--exclude=stats.txt --exclude=SCCS ' +
7110038SAli.Saidi@ARM.com                      '--exclude=${TARGETS[0].file} ' +
727860SN/A                      '> ${TARGETS[0]}', target=target, source=source), None)
739988Snilay@cs.wisc.edu    print "===== Output differences ====="
749988Snilay@cs.wisc.edu    print contents(target[0])
757860SN/A    # Run diff-out on stats.txt file
767860SN/A    status = Execute(env.subst('$DIFFOUT $SOURCES > ${TARGETS[1]}',
777860SN/A                               target=target, source=source),
787860SN/A                     strfunction=None)
797860SN/A    print "===== Statistics differences ====="
807860SN/A    print contents(target[1])
817860SN/A    # Generate status file contents based on exit status of diff-out
827860SN/A    if status == 0:
837860SN/A        status_str = "passed."
847860SN/A    else:
857860SN/A        status_str = "FAILED!"
868825Snilay@cs.wisc.edu    f = file(str(target[2]), 'w')
879449SAli.Saidi@ARM.com    print >>f, env.subst('${TARGETS[2].dir}', target=target, source=source), \
887860SN/A          status_str
897860SN/A    f.close()
9010038SAli.Saidi@ARM.com    # done
917860SN/A    return 0
927860SN/A
937860SN/Adef check_test_string(target, source, env):
947860SN/A    return env.subst("Comparing outputs in ${TARGETS[0].dir}.",
957860SN/A                     target=target, source=source)
968825Snilay@cs.wisc.edu
977860SN/AtestAction = env.Action(check_test, check_test_string)
989924Ssteve.reinhardt@amd.com
997860SN/Adef print_test(target, source, env):
1007860SN/A    print '***** ' + contents(source[0])
1017860SN/A    return 0
1027860SN/A
1037860SN/AprintAction = env.Action(print_test, strfunction = None)
1048825Snilay@cs.wisc.edu
1057860SN/A# Static vars for update_test:
1067860SN/A# - long-winded message about ignored sources
1077860SN/Aignore_msg = '''
1087860SN/ANote: The following file(s) will not be copied.  New non-standard
1097860SN/A      output files must be copied manually once before update_ref will
1107860SN/A      recognize them as outputs.  Otherwise they are assumed to be
1119885Sstever@gmail.com      inputs and are ignored.
1127860SN/A'''
1137860SN/A# - reference files always needed
1147860SN/Aneeded_files = set(['simout', 'simerr', 'stats.txt', 'config.ini'])
1157860SN/A# - source files we always want to ignore
1167860SN/Aknown_ignores = set(['status', 'outdiff', 'statsdiff'])
1177860SN/A
1187860SN/Adef update_test(target, source, env):
1197860SN/A    """Update reference test outputs.
1207860SN/A
1217860SN/A    Target is phony.  First two sources are the ref & new stats.txt file
1228521SN/A    files, respectively.  We actually copy everything in the
1239449SAli.Saidi@ARM.com    respective directories except the status & diff output files.
1247860SN/A
1257860SN/A    """
1267860SN/A    dest_dir = str(source[0].get_dir())
1277860SN/A    src_dir = str(source[1].get_dir())
1287860SN/A    dest_files = set(os.listdir(dest_dir))
1297860SN/A    src_files = set(os.listdir(src_dir))
1307860SN/A    # Copy all of the required files plus any existing dest files.
1317860SN/A    wanted_files = needed_files | dest_files
1327860SN/A    missing_files = wanted_files - src_files
1339481Snilay@cs.wisc.edu    if len(missing_files) > 0:
1349481Snilay@cs.wisc.edu        print "  WARNING: the following file(s) are missing " \
1359481Snilay@cs.wisc.edu              "and will not be updated:"
1369481Snilay@cs.wisc.edu        print "    ", " ,".join(missing_files)
1379481Snilay@cs.wisc.edu    copy_files = wanted_files - missing_files
1389481Snilay@cs.wisc.edu    warn_ignored_files = (src_files - copy_files) - known_ignores
1399481Snilay@cs.wisc.edu    if len(warn_ignored_files) > 0:
1409988Snilay@cs.wisc.edu        print ignore_msg,
1419481Snilay@cs.wisc.edu        print "       ", ", ".join(warn_ignored_files)
1429481Snilay@cs.wisc.edu    for f in copy_files:
1439481Snilay@cs.wisc.edu        if f in dest_files:
1449481Snilay@cs.wisc.edu            print "  Replacing file", f
1459481Snilay@cs.wisc.edu            dest_files.remove(f)
1469481Snilay@cs.wisc.edu        else:
1479481Snilay@cs.wisc.edu            print "  Creating new file", f
1489481Snilay@cs.wisc.edu        copyAction = Copy(os.path.join(dest_dir, f), os.path.join(src_dir, f))
1499481Snilay@cs.wisc.edu        copyAction.strfunction = None
1507860SN/A        Execute(copyAction)
1517860SN/A    return 0
1529885Sstever@gmail.com
1538893Ssaidi@eecs.umich.edudef update_test_string(target, source, env):
1547860SN/A    return env.subst("Updating ${SOURCES[0].dir} from ${SOURCES[1].dir}",
1559885Sstever@gmail.com                     target=target, source=source)
1569988Snilay@cs.wisc.edu
1577860SN/AupdateAction = env.Action(update_test, update_test_string)
1589348SAli.Saidi@ARM.com
1598150SN/Adef test_builder(env, ref_dir):
1607860SN/A    """Define a test."""
1619348SAli.Saidi@ARM.com
1627860SN/A    (category, name, _ref, isa, opsys, config) = ref_dir.split('/')
1638835SAli.Saidi@ARM.com    assert(_ref == 'ref')
1649348SAli.Saidi@ARM.com
16510036SAli.Saidi@ARM.com    # target path (where test output goes) is the same except without
1667860SN/A    # the 'ref' component
1678835SAli.Saidi@ARM.com    tgt_dir = os.path.join(category, name, isa, opsys, config)
1689885Sstever@gmail.com
1697860SN/A    # prepend file name with tgt_dir
1707860SN/A    def tgt(f):
1717860SN/A        return os.path.join(tgt_dir, f)
1727860SN/A
1738893Ssaidi@eecs.umich.edu    ref_stats = os.path.join(ref_dir, 'stats.txt')
1747860SN/A    new_stats = tgt('stats.txt')
1759885Sstever@gmail.com    status_file = tgt('status')
1769885Sstever@gmail.com
1779885Sstever@gmail.com    # Base command for running test.  We mess around with indirectly
1789885Sstever@gmail.com    # referring to files via SOURCES and TARGETS so that scons can
1799885Sstever@gmail.com    # mess with paths all it wants to and we still get the right
1809988Snilay@cs.wisc.edu    # files.
1819885Sstever@gmail.com    cmd = '${SOURCES[0]} -d $TARGET.dir -re ${SOURCES[1]} %s' % tgt_dir
18210036SAli.Saidi@ARM.com
1839885Sstever@gmail.com    # Prefix test run with batch job submission command if appropriate.
1849885Sstever@gmail.com    # Batch command also supports timeout arg (in seconds, not minutes).
18510038SAli.Saidi@ARM.com    timeout = 15 * 60 # used to be a param, probably should be again
18610038SAli.Saidi@ARM.com    if env['BATCH']:
18710038SAli.Saidi@ARM.com        cmd = '%s -t %d %s' % (env['BATCH_CMD'], timeout, cmd)
18810038SAli.Saidi@ARM.com
18910038SAli.Saidi@ARM.com    env.Command([tgt('simout'), tgt('simerr'), new_stats],
19010038SAli.Saidi@ARM.com                [env.M5Binary, 'run.py'], cmd)
19110038SAli.Saidi@ARM.com
19210038SAli.Saidi@ARM.com    # order of targets is important... see check_test
19310038SAli.Saidi@ARM.com    env.Command([tgt('outdiff'), tgt('statsdiff'), status_file],
19410038SAli.Saidi@ARM.com                [ref_stats, new_stats],
19510038SAli.Saidi@ARM.com                testAction)
19610038SAli.Saidi@ARM.com
19710038SAli.Saidi@ARM.com    # phony target to echo status
19810038SAli.Saidi@ARM.com    if env['update_ref']:
19910038SAli.Saidi@ARM.com        p = env.Command(tgt('_update'),
20010038SAli.Saidi@ARM.com                        [ref_stats, new_stats, status_file],
20110038SAli.Saidi@ARM.com                        updateAction)
20210038SAli.Saidi@ARM.com    else:
20310038SAli.Saidi@ARM.com        p = env.Command(tgt('_print'), [status_file], printAction)
20410038SAli.Saidi@ARM.com
20510038SAli.Saidi@ARM.com    env.AlwaysBuild(p)
20610038SAli.Saidi@ARM.com
20710038SAli.Saidi@ARM.com
20810038SAli.Saidi@ARM.com# Figure out applicable configs based on build type
2097860SN/Aconfigs = []
2107860SN/Aif env['FULL_SYSTEM']:
2118825Snilay@cs.wisc.edu    if env['TARGET_ISA'] == 'alpha':
2129988Snilay@cs.wisc.edu        if not env['ALPHA_TLASER']:
21310038SAli.Saidi@ARM.com            configs += ['tsunami-simple-atomic',
2147860SN/A                        'tsunami-simple-timing',
2158825Snilay@cs.wisc.edu                        'tsunami-simple-atomic-dual',
2168825Snilay@cs.wisc.edu                        'tsunami-simple-timing-dual',
2178825Snilay@cs.wisc.edu                        'twosys-tsunami-simple-atomic',
2188825Snilay@cs.wisc.edu                        'tsunami-o3', 'tsunami-o3-dual']
2199885Sstever@gmail.com    if env['TARGET_ISA'] == 'sparc':
2209988Snilay@cs.wisc.edu        configs += ['t1000-simple-atomic',
22110038SAli.Saidi@ARM.com                    't1000-simple-timing']
2229265SAli.Saidi@ARM.com
2238825Snilay@cs.wisc.eduelse:
2248893Ssaidi@eecs.umich.edu    configs += ['simple-atomic', 'simple-timing', 'o3-timing', 'memtest',
2257860SN/A                'simple-atomic-mp', 'simple-timing-mp']
2267860SN/A
2277860SN/Acwd = os.getcwd()
2287860SN/Aos.chdir(str(Dir('.').srcdir))
2297860SN/Afor config in configs:
2309988Snilay@cs.wisc.edu    dirs = glob.glob('*/*/ref/%s/*/%s' % (env['TARGET_ISA'], config))
2317860SN/A    for d in dirs:
2327860SN/A        test_builder(env, d)
2337860SN/Aos.chdir(cwd)
2347860SN/A