SConscript revision 3005
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 on" ' +		# for stderr file
6512302Sgabeblack@google.com                      '-I "^M5 simulation started" ' +	# for stderr file
6612302Sgabeblack@google.com                      '-I "^Simulation complete at" ' +	# for stderr file
6712302Sgabeblack@google.com                      '-I "^Listening for" ' +		# for stderr file
6812371Sgabeblack@google.com                      '--exclude=m5stats.txt --exclude=SCCS ' +
6912371Sgabeblack@google.com                      '--exclude=${TARGETS[0].file} ' +
7012371Sgabeblack@google.com                      '> ${TARGETS[0]}', target=target, source=source), None)
7112371Sgabeblack@google.com    print "===== Output differences ====="
7212371Sgabeblack@google.com    print contents(target[0])
7312371Sgabeblack@google.com    # Run diff-out on m5stats.txt file
7412371Sgabeblack@google.com    status = Execute(env.subst('$DIFFOUT $SOURCES > ${TARGETS[1]}',
7512371Sgabeblack@google.com                               target=target, source=source),
7612371Sgabeblack@google.com                     strfunction=None)
7712371Sgabeblack@google.com    print "===== Statistics differences ====="
7812371Sgabeblack@google.com    print contents(target[1])
7912371Sgabeblack@google.com    # Generate status file contents based on exit status of diff-out
8012371Sgabeblack@google.com    if status == 0:
8112371Sgabeblack@google.com        status_str = "passed."
8212371Sgabeblack@google.com    else:
8312371Sgabeblack@google.com        status_str = "FAILED!"
8412371Sgabeblack@google.com    f = file(str(target[2]), 'w')
8512371Sgabeblack@google.com    print >>f, env.subst('${TARGETS[2].dir}', target=target, source=source), \
8612371Sgabeblack@google.com          status_str
8712371Sgabeblack@google.com    f.close()
8812371Sgabeblack@google.com    # done
8912371Sgabeblack@google.com    return 0
9012371Sgabeblack@google.com
9112371Sgabeblack@google.comdef check_test_string(target, source, env):
9212371Sgabeblack@google.com    return env.subst("Comparing outputs in ${TARGETS[0].dir}.",
9312371Sgabeblack@google.com                     target=target, source=source)
9412371Sgabeblack@google.com
9512371Sgabeblack@google.comtestAction = env.Action(check_test, check_test_string)
9612371Sgabeblack@google.com
9712371Sgabeblack@google.comdef print_test(target, source, env):
9812371Sgabeblack@google.com    print '***** ' + contents(source[0])
9912371Sgabeblack@google.com    return 0
10012371Sgabeblack@google.com
10112371Sgabeblack@google.comprintAction = env.Action(print_test, strfunction = None)
10212371Sgabeblack@google.com
10312371Sgabeblack@google.comdef update_test(target, source, env):
10412371Sgabeblack@google.com    """Update reference test outputs.
10512371Sgabeblack@google.com
10612371Sgabeblack@google.com    Target is phony.  First two sources are the ref & new m5stats.txt
10712371Sgabeblack@google.com    files, respectively.  We actually copy everything in the
10812371Sgabeblack@google.com    respective directories except the status & diff output files.
10912371Sgabeblack@google.com
11012371Sgabeblack@google.com    """
11112371Sgabeblack@google.com    dest_dir = str(source[0].get_dir())
11212371Sgabeblack@google.com    src_dir = str(source[1].get_dir())
11312371Sgabeblack@google.com    dest_files = os.listdir(dest_dir)
11412371Sgabeblack@google.com    src_files = os.listdir(src_dir)
11512302Sgabeblack@google.com    # Exclude status & diff outputs
11612371Sgabeblack@google.com    for f in ('outdiff', 'statsdiff', 'status'):
11712302Sgabeblack@google.com        if f in src_files:
11812371Sgabeblack@google.com            src_files.remove(f)
11912302Sgabeblack@google.com    for f in src_files:
12012302Sgabeblack@google.com        if f in dest_files:
12112371Sgabeblack@google.com            print "  Replacing file", f
12212371Sgabeblack@google.com            dest_files.remove(f)
12312371Sgabeblack@google.com        else:
12412371Sgabeblack@google.com            print "  Creating new file", f
12512302Sgabeblack@google.com        copyAction = Copy(os.path.join(dest_dir, f), os.path.join(src_dir, f))
12612371Sgabeblack@google.com        copyAction.strfunction = None
12712371Sgabeblack@google.com        Execute(copyAction)
12812371Sgabeblack@google.com    # warn about any files in dest not overwritten (other than SCCS dir)
12912371Sgabeblack@google.com    if 'SCCS' in dest_files:
13011983Sgabeblack@google.com        dest_files.remove('SCCS')
1316143Snate@binkert.org    if dest_files:
1328233Snate@binkert.org        print "Warning: file(s) in", dest_dir, "not updated:",
13312302Sgabeblack@google.com        print ', '.join(dest_files)
1346143Snate@binkert.org    return 0
1356143Snate@binkert.org
13612302Sgabeblack@google.comdef update_test_string(target, source, env):
1374762Snate@binkert.org    return env.subst("Updating ${SOURCES[0].dir} from ${SOURCES[1].dir}",
1386143Snate@binkert.org                     target=target, source=source)
1398233Snate@binkert.org
1408233Snate@binkert.orgupdateAction = env.Action(update_test, update_test_string)
14112302Sgabeblack@google.com
14212302Sgabeblack@google.comdef test_builder(env, ref_dir):
1436143Snate@binkert.org    """Define a test."""
14412362Sgabeblack@google.com
14512362Sgabeblack@google.com    (category, name, _ref, isa, opsys, config) = ref_dir.split('/')
14612362Sgabeblack@google.com    assert(_ref == 'ref')
14712362Sgabeblack@google.com
14812302Sgabeblack@google.com    # target path (where test output goes) is the same except without
14912302Sgabeblack@google.com    # the 'ref' component
15012302Sgabeblack@google.com    tgt_dir = os.path.join(category, name, isa, opsys, config)
15112302Sgabeblack@google.com
15212302Sgabeblack@google.com    # prepend file name with tgt_dir
15312363Sgabeblack@google.com    def tgt(f):
15412363Sgabeblack@google.com        return os.path.join(tgt_dir, f)
15512363Sgabeblack@google.com
15612363Sgabeblack@google.com    ref_stats = os.path.join(ref_dir, 'm5stats.txt')
15712302Sgabeblack@google.com    new_stats = tgt('m5stats.txt')
15812363Sgabeblack@google.com    status_file = tgt('status')
15912363Sgabeblack@google.com
16012363Sgabeblack@google.com    # Base command for running test.  We mess around with indirectly
16112363Sgabeblack@google.com    # referring to files via SOURCES and TARGETS so that scons can
16212363Sgabeblack@google.com    # mess with paths all it wants to and we still get the right
1638233Snate@binkert.org    # files.
1646143Snate@binkert.org    base_cmd = '${SOURCES[0]} -d $TARGET.dir ${SOURCES[1]} %s' % tgt_dir
1656143Snate@binkert.org    # stdout and stderr files
1666143Snate@binkert.org    cmd_stdout = '${TARGETS[0]}'
1676143Snate@binkert.org    cmd_stderr = '${TARGETS[1]}'
1686143Snate@binkert.org
1696143Snate@binkert.org    # Prefix test run with batch job submission command if appropriate.
1706143Snate@binkert.org    # Output redirection is also different for batch runs.
1716143Snate@binkert.org    # Batch command also supports timeout arg (in seconds, not minutes).
1726143Snate@binkert.org    if env['BATCH']:
1737065Snate@binkert.org        cmd = [env['BATCH_CMD'], '-t', str(timeout * 60),
1746143Snate@binkert.org               '-o', cmd_stdout, '-e', cmd_stderr, base_cmd]
17512362Sgabeblack@google.com    else:
17612362Sgabeblack@google.com        cmd = [base_cmd, '>', cmd_stdout, '2>', cmd_stderr]
17712362Sgabeblack@google.com            
17812362Sgabeblack@google.com    env.Command([tgt('stdout'), tgt('stderr'), new_stats],
17912362Sgabeblack@google.com                [env.M5Binary, 'run.py'], ' '.join(cmd))
18012362Sgabeblack@google.com
18112362Sgabeblack@google.com    # order of targets is important... see check_test
18212362Sgabeblack@google.com    env.Command([tgt('outdiff'), tgt('statsdiff'), status_file],
18312362Sgabeblack@google.com                [ref_stats, new_stats],
18412362Sgabeblack@google.com                testAction)
18512362Sgabeblack@google.com
18612362Sgabeblack@google.com    # phony target to echo status
1878233Snate@binkert.org    if env['update_ref']:
1888233Snate@binkert.org        p = env.Command(tgt('_update'),
1898233Snate@binkert.org                        [ref_stats, new_stats, status_file],
1908233Snate@binkert.org                        updateAction)
1918233Snate@binkert.org    else:
1928233Snate@binkert.org        p = env.Command(tgt('_print'), [status_file], printAction)
1938233Snate@binkert.org
1948233Snate@binkert.org    env.AlwaysBuild(p)
1958233Snate@binkert.org
1968233Snate@binkert.org
1978233Snate@binkert.org# Figure out applicable configs based on build type
1988233Snate@binkert.orgconfigs = []
1998233Snate@binkert.orgif env['FULL_SYSTEM']:
2008233Snate@binkert.org    if env['TARGET_ISA'] == 'alpha':
2018233Snate@binkert.org        if not env['ALPHA_TLASER']:
2028233Snate@binkert.org            configs += ['tsunami-simple-atomic',
2038233Snate@binkert.org                        'tsunami-simple-timing',
2048233Snate@binkert.org                        'tsunami-simple-atomic-dual',
2058233Snate@binkert.org                        'tsunami-simple-timing-dual']
2068233Snate@binkert.orgelse:
2078233Snate@binkert.org    configs += ['simple-atomic', 'simple-timing']
2086143Snate@binkert.org
2096143Snate@binkert.orgcwd = os.getcwd()
2106143Snate@binkert.orgos.chdir(str(Dir('.').srcdir))
2116143Snate@binkert.orgfor config in configs:
2126143Snate@binkert.org    dirs = glob.glob('*/*/ref/%s/*/%s' % (env['TARGET_ISA'], config))
2136143Snate@binkert.org    for d in dirs:
2149982Satgutier@umich.edu        test_builder(env, d)
2156143Snate@binkert.orgos.chdir(cwd)
21612302Sgabeblack@google.com