SConscript revision 4937
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#
294762Snate@binkert.org# Authors: Steve Reinhardt
30955SN/A#          Kevin Lim
3112563Sgabeblack@google.com
3212563Sgabeblack@google.comimport os
335522Snate@binkert.orgimport sys
346143Snate@binkert.orgimport glob
3512371Sgabeblack@google.comfrom SCons.Script.SConscript import SConsEnvironment
364762Snate@binkert.org
375522Snate@binkert.orgImport('env')
38955SN/A
395522Snate@binkert.orgenv['DIFFOUT'] = File('diff-out')
4011974Sgabeblack@google.com
41955SN/A# Dict that accumulates lists of tests by category (quick, medium, long)
425522Snate@binkert.orgenv.Tests = {}
434202Sbinkertn@umich.edu
445742Snate@binkert.orgdef contents(node):
45955SN/A    return file(str(node)).read()
464381Sbinkertn@umich.edu
474381Sbinkertn@umich.edudef check_test(target, source, env):
4812246Sgabeblack@google.com    """Check output from running test.
4912246Sgabeblack@google.com
508334Snate@binkert.org    Targets are as follows:
51955SN/A    target[0] : outdiff
52955SN/A    target[1] : statsdiff
534202Sbinkertn@umich.edu    target[2] : status
54955SN/A
554382Sbinkertn@umich.edu    """
564382Sbinkertn@umich.edu    # make sure target files are all gone
574382Sbinkertn@umich.edu    for t in target:
586654Snate@binkert.org        if os.path.exists(t.abspath):
595517Snate@binkert.org            Execute(Delete(t.abspath))
608614Sgblack@eecs.umich.edu    # Run diff on output & ref directories to find differences.
617674Snate@binkert.org    # Exclude m5stats.txt since we will use diff-out on that.
626143Snate@binkert.org    Execute(env.subst('diff -ubr ${SOURCES[0].dir} ${SOURCES[1].dir} ' +
636143Snate@binkert.org                      '-I "^command line:" ' +		# for stdout file
646143Snate@binkert.org                      '-I "^M5 compiled " ' +		# for stderr file
6512302Sgabeblack@google.com                      '-I "^M5 started " ' +		# for stderr file
6612302Sgabeblack@google.com                      '-I "^M5 executing on " ' +	# for stderr file
6712302Sgabeblack@google.com                      '-I "^Simulation complete at" ' +	# for stderr file
6812371Sgabeblack@google.com                      '-I "^Listening for" ' +		# for stderr file
6912371Sgabeblack@google.com                      '-I "listening for remote gdb" ' + # for stderr file
7012371Sgabeblack@google.com                      '--exclude=m5stats.txt --exclude=SCCS ' +
7112371Sgabeblack@google.com                      '--exclude=${TARGETS[0].file} ' +
7212371Sgabeblack@google.com                      '> ${TARGETS[0]}', target=target, source=source), None)
7312371Sgabeblack@google.com    print "===== Output differences ====="
7412371Sgabeblack@google.com    print contents(target[0])
7512371Sgabeblack@google.com    # Run diff-out on m5stats.txt file
7612371Sgabeblack@google.com    status = Execute(env.subst('$DIFFOUT $SOURCES > ${TARGETS[1]}',
7712371Sgabeblack@google.com                               target=target, source=source),
7812371Sgabeblack@google.com                     strfunction=None)
7912371Sgabeblack@google.com    print "===== Statistics differences ====="
8012371Sgabeblack@google.com    print contents(target[1])
8112371Sgabeblack@google.com    # Generate status file contents based on exit status of diff-out
8212371Sgabeblack@google.com    if status == 0:
8312371Sgabeblack@google.com        status_str = "passed."
8412371Sgabeblack@google.com    else:
8512371Sgabeblack@google.com        status_str = "FAILED!"
8612371Sgabeblack@google.com    f = file(str(target[2]), 'w')
8712371Sgabeblack@google.com    print >>f, env.subst('${TARGETS[2].dir}', target=target, source=source), \
8812371Sgabeblack@google.com          status_str
8912371Sgabeblack@google.com    f.close()
9012371Sgabeblack@google.com    # done
9112371Sgabeblack@google.com    return 0
9212371Sgabeblack@google.com
9312371Sgabeblack@google.comdef check_test_string(target, source, env):
9412371Sgabeblack@google.com    return env.subst("Comparing outputs in ${TARGETS[0].dir}.",
9512371Sgabeblack@google.com                     target=target, source=source)
9612371Sgabeblack@google.com
9712371Sgabeblack@google.comtestAction = env.Action(check_test, check_test_string)
9812371Sgabeblack@google.com
9912371Sgabeblack@google.comdef print_test(target, source, env):
10012371Sgabeblack@google.com    print '***** ' + contents(source[0])
10112371Sgabeblack@google.com    return 0
10212371Sgabeblack@google.com
10312371Sgabeblack@google.comprintAction = env.Action(print_test, strfunction = None)
10412371Sgabeblack@google.com
10512371Sgabeblack@google.com# Static vars for update_test:
10612371Sgabeblack@google.com# - long-winded message about ignored sources
10712371Sgabeblack@google.comignore_msg = '''
10812371Sgabeblack@google.comNote: The following file(s) will not be copied.  New non-standard
10912371Sgabeblack@google.com      output files must be copied manually once before update_ref will
11012371Sgabeblack@google.com      recognize them as outputs.  Otherwise they are assumed to be
11112371Sgabeblack@google.com      inputs and are ignored.
11212371Sgabeblack@google.com'''
11312371Sgabeblack@google.com# - reference files always needed
11412371Sgabeblack@google.comneeded_files = set(['stdout', 'stderr', 'm5stats.txt', 'config.ini'])
11512302Sgabeblack@google.com# - source files we always want to ignore
11612371Sgabeblack@google.comknown_ignores = set(['status', 'outdiff', 'statsdiff'])
11712302Sgabeblack@google.com
11812371Sgabeblack@google.comdef update_test(target, source, env):
11912302Sgabeblack@google.com    """Update reference test outputs.
12012302Sgabeblack@google.com
12112371Sgabeblack@google.com    Target is phony.  First two sources are the ref & new m5stats.txt
12212371Sgabeblack@google.com    files, respectively.  We actually copy everything in the
12312371Sgabeblack@google.com    respective directories except the status & diff output files.
12412371Sgabeblack@google.com
12512302Sgabeblack@google.com    """
12612371Sgabeblack@google.com    dest_dir = str(source[0].get_dir())
12712371Sgabeblack@google.com    src_dir = str(source[1].get_dir())
12812371Sgabeblack@google.com    dest_files = set(os.listdir(dest_dir))
12912371Sgabeblack@google.com    src_files = set(os.listdir(src_dir))
13011983Sgabeblack@google.com    # Copy all of the required files plus any existing dest files.
1316143Snate@binkert.org    wanted_files = needed_files | dest_files
1328233Snate@binkert.org    missing_files = wanted_files - src_files
13312302Sgabeblack@google.com    if len(missing_files) > 0:
1346143Snate@binkert.org        print "  WARNING: the following file(s) are missing " \
1356143Snate@binkert.org              "and will not be updated:"
13612302Sgabeblack@google.com        print "    ", " ,".join(missing_files)
1374762Snate@binkert.org    copy_files = wanted_files - missing_files
1386143Snate@binkert.org    warn_ignored_files = (src_files - copy_files) - known_ignores
1398233Snate@binkert.org    if len(warn_ignored_files) > 0:
1408233Snate@binkert.org        print ignore_msg,
14112302Sgabeblack@google.com        print "       ", ", ".join(warn_ignored_files)
14212302Sgabeblack@google.com    for f in copy_files:
1436143Snate@binkert.org        if f in dest_files:
14412362Sgabeblack@google.com            print "  Replacing file", f
14512362Sgabeblack@google.com            dest_files.remove(f)
14612362Sgabeblack@google.com        else:
14712362Sgabeblack@google.com            print "  Creating new file", f
14812302Sgabeblack@google.com        copyAction = Copy(os.path.join(dest_dir, f), os.path.join(src_dir, f))
14912302Sgabeblack@google.com        copyAction.strfunction = None
15012302Sgabeblack@google.com        Execute(copyAction)
15112302Sgabeblack@google.com    return 0
15212302Sgabeblack@google.com
15312363Sgabeblack@google.comdef update_test_string(target, source, env):
15412363Sgabeblack@google.com    return env.subst("Updating ${SOURCES[0].dir} from ${SOURCES[1].dir}",
15512363Sgabeblack@google.com                     target=target, source=source)
15612363Sgabeblack@google.com
15712302Sgabeblack@google.comupdateAction = env.Action(update_test, update_test_string)
15812363Sgabeblack@google.com
15912363Sgabeblack@google.comdef test_builder(env, ref_dir):
16012363Sgabeblack@google.com    """Define a test."""
16112363Sgabeblack@google.com
16212363Sgabeblack@google.com    (category, name, _ref, isa, opsys, config) = ref_dir.split('/')
1638233Snate@binkert.org    assert(_ref == 'ref')
1646143Snate@binkert.org
1656143Snate@binkert.org    # target path (where test output goes) is the same except without
1666143Snate@binkert.org    # the 'ref' component
1676143Snate@binkert.org    tgt_dir = os.path.join(category, name, isa, opsys, config)
1686143Snate@binkert.org
1696143Snate@binkert.org    # prepend file name with tgt_dir
1706143Snate@binkert.org    def tgt(f):
1716143Snate@binkert.org        return os.path.join(tgt_dir, f)
1726143Snate@binkert.org
1737065Snate@binkert.org    ref_stats = os.path.join(ref_dir, 'm5stats.txt')
1746143Snate@binkert.org    new_stats = tgt('m5stats.txt')
17512362Sgabeblack@google.com    status_file = tgt('status')
17612362Sgabeblack@google.com
17712362Sgabeblack@google.com    # Base command for running test.  We mess around with indirectly
17812362Sgabeblack@google.com    # referring to files via SOURCES and TARGETS so that scons can
17912362Sgabeblack@google.com    # mess with paths all it wants to and we still get the right
18012362Sgabeblack@google.com    # files.
18112362Sgabeblack@google.com    base_cmd = '${SOURCES[0]} -d $TARGET.dir ${SOURCES[1]} %s' % tgt_dir
18212362Sgabeblack@google.com    # stdout and stderr files
18312362Sgabeblack@google.com    cmd_stdout = '${TARGETS[0]}'
18412362Sgabeblack@google.com    cmd_stderr = '${TARGETS[1]}'
18512362Sgabeblack@google.com
18612362Sgabeblack@google.com    # Prefix test run with batch job submission command if appropriate.
1878233Snate@binkert.org    # Output redirection is also different for batch runs.
1888233Snate@binkert.org    # Batch command also supports timeout arg (in seconds, not minutes).
1898233Snate@binkert.org    timeout = 15 # used to be a param, probably should be again
1908233Snate@binkert.org    if env['BATCH']:
1918233Snate@binkert.org        cmd = [env['BATCH_CMD'], '-t', str(timeout * 60),
1928233Snate@binkert.org               '-o', cmd_stdout, '-e', cmd_stderr, base_cmd]
1938233Snate@binkert.org    else:
1948233Snate@binkert.org        cmd = [base_cmd, '>', cmd_stdout, '2>', cmd_stderr]
1958233Snate@binkert.org
1968233Snate@binkert.org    env.Command([tgt('stdout'), tgt('stderr'), new_stats],
1978233Snate@binkert.org                [env.M5Binary, 'run.py'], ' '.join(cmd))
1988233Snate@binkert.org
1998233Snate@binkert.org    # order of targets is important... see check_test
2008233Snate@binkert.org    env.Command([tgt('outdiff'), tgt('statsdiff'), status_file],
2018233Snate@binkert.org                [ref_stats, new_stats],
2028233Snate@binkert.org                testAction)
2038233Snate@binkert.org
2048233Snate@binkert.org    # phony target to echo status
2058233Snate@binkert.org    if env['update_ref']:
2068233Snate@binkert.org        p = env.Command(tgt('_update'),
2078233Snate@binkert.org                        [ref_stats, new_stats, status_file],
2086143Snate@binkert.org                        updateAction)
2096143Snate@binkert.org    else:
2106143Snate@binkert.org        p = env.Command(tgt('_print'), [status_file], printAction)
2116143Snate@binkert.org
2126143Snate@binkert.org    env.AlwaysBuild(p)
2136143Snate@binkert.org
2149982Satgutier@umich.edu
2156143Snate@binkert.org# Figure out applicable configs based on build type
21612302Sgabeblack@google.comconfigs = []
21712302Sgabeblack@google.comif env['FULL_SYSTEM']:
21812302Sgabeblack@google.com    if env['TARGET_ISA'] == 'alpha':
21912302Sgabeblack@google.com        if not env['ALPHA_TLASER']:
22012302Sgabeblack@google.com            configs += ['tsunami-simple-atomic',
22112302Sgabeblack@google.com                        'tsunami-simple-timing',
22212302Sgabeblack@google.com                        'tsunami-simple-atomic-dual',
22312302Sgabeblack@google.com                        'tsunami-simple-timing-dual',
22411983Sgabeblack@google.com                        'twosys-tsunami-simple-atomic']
22511983Sgabeblack@google.com    if env['TARGET_ISA'] == 'sparc':
22611983Sgabeblack@google.com        configs += ['t1000-simple-atomic',
22712302Sgabeblack@google.com                    't1000-simple-timing']
22812302Sgabeblack@google.com
22912302Sgabeblack@google.comelse:
23012302Sgabeblack@google.com    configs += ['simple-atomic', 'simple-timing', 'o3-timing', 'memtest']
23112302Sgabeblack@google.com
23212302Sgabeblack@google.comcwd = os.getcwd()
23311983Sgabeblack@google.comos.chdir(str(Dir('.').srcdir))
2346143Snate@binkert.orgfor config in configs:
23512305Sgabeblack@google.com    dirs = glob.glob('*/*/ref/%s/*/%s' % (env['TARGET_ISA'], config))
23612302Sgabeblack@google.com    for d in dirs:
23712302Sgabeblack@google.com        test_builder(env, d)
23812302Sgabeblack@google.comos.chdir(cwd)
2396143Snate@binkert.org