SConscript revision 11983
12929Sktlim@umich.edu# -*- mode:python -*-
211504Sandreas.sandberg@arm.com#
311504Sandreas.sandberg@arm.com# Copyright (c) 2016 ARM Limited
411504Sandreas.sandberg@arm.com# All rights reserved
511504Sandreas.sandberg@arm.com#
611504Sandreas.sandberg@arm.com# The license below extends only to copyright in the software and shall
711504Sandreas.sandberg@arm.com# not be construed as granting a license to any other intellectual
811504Sandreas.sandberg@arm.com# property including but not limited to intellectual property relating
911504Sandreas.sandberg@arm.com# to a hardware implementation of the functionality of the software
1011504Sandreas.sandberg@arm.com# licensed hereunder.  You may use the software subject to the license
1111504Sandreas.sandberg@arm.com# terms below provided that you ensure that this notice is replicated
1211504Sandreas.sandberg@arm.com# unmodified and in its entirety in all distributions of the software,
1311504Sandreas.sandberg@arm.com# modified or unmodified, in source code or in binary form.
1411504Sandreas.sandberg@arm.com#
152932Sktlim@umich.edu# Copyright (c) 2004-2006 The Regents of The University of Michigan
162929Sktlim@umich.edu# All rights reserved.
172929Sktlim@umich.edu#
182929Sktlim@umich.edu# Redistribution and use in source and binary forms, with or without
192929Sktlim@umich.edu# modification, are permitted provided that the following conditions are
202929Sktlim@umich.edu# met: redistributions of source code must retain the above copyright
212929Sktlim@umich.edu# notice, this list of conditions and the following disclaimer;
222929Sktlim@umich.edu# redistributions in binary form must reproduce the above copyright
232929Sktlim@umich.edu# notice, this list of conditions and the following disclaimer in the
242929Sktlim@umich.edu# documentation and/or other materials provided with the distribution;
252929Sktlim@umich.edu# neither the name of the copyright holders nor the names of its
262929Sktlim@umich.edu# contributors may be used to endorse or promote products derived from
272929Sktlim@umich.edu# this software without specific prior written permission.
282929Sktlim@umich.edu#
292929Sktlim@umich.edu# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
302929Sktlim@umich.edu# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
312929Sktlim@umich.edu# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
322929Sktlim@umich.edu# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
332929Sktlim@umich.edu# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
342929Sktlim@umich.edu# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
352929Sktlim@umich.edu# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
362929Sktlim@umich.edu# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
372929Sktlim@umich.edu# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
382929Sktlim@umich.edu# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
392929Sktlim@umich.edu# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
402932Sktlim@umich.edu#
412932Sktlim@umich.edu# Authors: Steve Reinhardt
422932Sktlim@umich.edu#          Kevin Lim
4311504Sandreas.sandberg@arm.com#          Andreas Sandberg
442929Sktlim@umich.edu
452929Sktlim@umich.edufrom SCons.Script.SConscript import SConsEnvironment
4611504Sandreas.sandberg@arm.comimport os
4711504Sandreas.sandberg@arm.comimport pickle
4811504Sandreas.sandberg@arm.comimport sys
4911504Sandreas.sandberg@arm.com
5011504Sandreas.sandberg@arm.comsys.path.insert(0, Dir(".").srcnode().abspath)
5111504Sandreas.sandberg@arm.comimport testing.tests as tests
5211504Sandreas.sandberg@arm.comimport testing.results as results
532929Sktlim@umich.edu
542929Sktlim@umich.eduImport('env')
552929Sktlim@umich.edu
568947Sandreas.hansson@arm.com# get the termcap from the environment
578947Sandreas.hansson@arm.comtermcap = env['TERMCAP']
588947Sandreas.hansson@arm.com
592929Sktlim@umich.edu# Dict that accumulates lists of tests by category (quick, medium, long)
602929Sktlim@umich.eduenv.Tests = {}
6111504Sandreas.sandberg@arm.comgpu_isa = env['TARGET_GPU_ISA'] if env['BUILD_GPU'] else None
6211504Sandreas.sandberg@arm.comfor cat in tests.all_categories:
6311504Sandreas.sandberg@arm.com    env.Tests[cat] = tuple(
6411504Sandreas.sandberg@arm.com        tests.get_tests(env["TARGET_ISA"],
6511504Sandreas.sandberg@arm.com                        categories=(cat, ),
6611504Sandreas.sandberg@arm.com                        ruby_protocol=env["PROTOCOL"],
6711504Sandreas.sandberg@arm.com                        gpu_isa=gpu_isa))
682929Sktlim@umich.edu
6911504Sandreas.sandberg@arm.comdef color_message(color, msg):
7011504Sandreas.sandberg@arm.com    return color + msg + termcap.Normal
716007Ssteve.reinhardt@amd.com
726007Ssteve.reinhardt@amd.comdef run_test(target, source, env):
7311504Sandreas.sandberg@arm.com    """Run a test and produce results as a pickle file.
742929Sktlim@umich.edu
752929Sktlim@umich.edu    Targets are as follows:
7611504Sandreas.sandberg@arm.com    target[0] : Pickle file
776007Ssteve.reinhardt@amd.com
786007Ssteve.reinhardt@amd.com    Sources are:
799781Sandreas.hansson@arm.com    source[0] : gem5 binary
806007Ssteve.reinhardt@amd.com    source[1] : tests/run.py script
8111504Sandreas.sandberg@arm.com    source[2:] : reference files
822929Sktlim@umich.edu
832929Sktlim@umich.edu    """
8411504Sandreas.sandberg@arm.com    tgt_dir = os.path.dirname(str(target[0]))
8511504Sandreas.sandberg@arm.com    config = tests.ClassicConfig(*tgt_dir.split('/')[-6:])
8611504Sandreas.sandberg@arm.com    test = tests.ClassicTest(source[0].abspath, tgt_dir, config,
8711504Sandreas.sandberg@arm.com                             timeout=5*60*60,
8811504Sandreas.sandberg@arm.com                             skip_diff_out=True)
896007Ssteve.reinhardt@amd.com
9011504Sandreas.sandberg@arm.com    for ref in test.ref_files():
9111504Sandreas.sandberg@arm.com        out_file = os.path.join(tgt_dir, ref)
9211504Sandreas.sandberg@arm.com        if os.path.exists(out_file):
9311504Sandreas.sandberg@arm.com            env.Execute(Delete(out_file))
946007Ssteve.reinhardt@amd.com
9511504Sandreas.sandberg@arm.com    with open(target[0].abspath, "wb") as fout:
9611504Sandreas.sandberg@arm.com        formatter = results.Pickle(fout=fout)
9711504Sandreas.sandberg@arm.com        formatter.dump_suites([ test.run() ])
986007Ssteve.reinhardt@amd.com
992929Sktlim@umich.edu    return 0
1002929Sktlim@umich.edu
1016007Ssteve.reinhardt@amd.comdef run_test_string(target, source, env):
1026007Ssteve.reinhardt@amd.com    return env.subst("Running test in ${TARGETS[0].dir}.",
1032929Sktlim@umich.edu                     target=target, source=source)
1042929Sktlim@umich.edu
1056007Ssteve.reinhardt@amd.comtestAction = env.Action(run_test, run_test_string)
1062929Sktlim@umich.edu
1072929Sktlim@umich.edudef print_test(target, source, env):
10811504Sandreas.sandberg@arm.com    """Run a test and produce results as a pickle file.
1098947Sandreas.hansson@arm.com
11011504Sandreas.sandberg@arm.com    Targets are as follows:
11111504Sandreas.sandberg@arm.com    target[*] : Dummy targets
1128947Sandreas.hansson@arm.com
11311504Sandreas.sandberg@arm.com    Sources are:
11411504Sandreas.sandberg@arm.com    source[0] : Pickle file
1158947Sandreas.hansson@arm.com
11611504Sandreas.sandberg@arm.com    """
11711504Sandreas.sandberg@arm.com    with open(source[0].abspath, "rb") as fin:
11811504Sandreas.sandberg@arm.com        result = pickle.load(fin)
1198947Sandreas.hansson@arm.com
12011504Sandreas.sandberg@arm.com    assert len(result) == 1
12111504Sandreas.sandberg@arm.com    result = result[0]
12211504Sandreas.sandberg@arm.com
12311504Sandreas.sandberg@arm.com    formatter = None
12411542Sandreas.sandberg@arm.com    if result.skipped():
12511542Sandreas.sandberg@arm.com        status = color_message(termcap.Cyan, "skipped.")
12611542Sandreas.sandberg@arm.com    elif result.changed():
12711542Sandreas.sandberg@arm.com        status = color_message(termcap.Yellow, "CHANGED!")
12811504Sandreas.sandberg@arm.com        formatter = results.Text()
12911504Sandreas.sandberg@arm.com    elif result:
13011504Sandreas.sandberg@arm.com        status = color_message(termcap.Green, "passed.")
13111504Sandreas.sandberg@arm.com    else:
13211542Sandreas.sandberg@arm.com        status = color_message(termcap.Red, "FAILED!")
13311504Sandreas.sandberg@arm.com        formatter = results.Text()
13411504Sandreas.sandberg@arm.com
13511504Sandreas.sandberg@arm.com    if formatter:
13611504Sandreas.sandberg@arm.com        formatter.dump_suites([result])
13711504Sandreas.sandberg@arm.com
13811504Sandreas.sandberg@arm.com    print "***** %s: %s" % (source[0].dir, status)
1392929Sktlim@umich.edu    return 0
1402929Sktlim@umich.edu
14111504Sandreas.sandberg@arm.comprintAction = env.Action(print_test, strfunction=None)
1424937Sstever@gmail.com
1432929Sktlim@umich.edudef update_test(target, source, env):
14411504Sandreas.sandberg@arm.com    """Update test reference data
1452929Sktlim@umich.edu
14611504Sandreas.sandberg@arm.com    Targets are as follows:
14711504Sandreas.sandberg@arm.com    target[0] : Dummy file
1482929Sktlim@umich.edu
14911504Sandreas.sandberg@arm.com    Sources are:
15011504Sandreas.sandberg@arm.com    source[0] : Pickle file
1512929Sktlim@umich.edu    """
15211504Sandreas.sandberg@arm.com
15311504Sandreas.sandberg@arm.com    src_dir = os.path.dirname(str(source[0]))
15411504Sandreas.sandberg@arm.com    config = tests.ClassicConfig(*src_dir.split('/')[-6:])
15511504Sandreas.sandberg@arm.com    test = tests.ClassicTest(source[0].abspath, src_dir, config)
15611504Sandreas.sandberg@arm.com    ref_dir = test.ref_dir
15711504Sandreas.sandberg@arm.com
15811504Sandreas.sandberg@arm.com    with open(source[0].abspath, "rb") as fin:
15911504Sandreas.sandberg@arm.com        result = pickle.load(fin)
16011504Sandreas.sandberg@arm.com
16111504Sandreas.sandberg@arm.com    assert len(result) == 1
16211504Sandreas.sandberg@arm.com    result = result[0]
16311504Sandreas.sandberg@arm.com
16411542Sandreas.sandberg@arm.com    if result.skipped():
16511504Sandreas.sandberg@arm.com        print "*** %s: %s: Test skipped, not updating." % (
16611504Sandreas.sandberg@arm.com            source[0].dir, color_message(termcap.Yellow, "WARNING"), )
16711504Sandreas.sandberg@arm.com        return 0
16811504Sandreas.sandberg@arm.com    elif result:
16911504Sandreas.sandberg@arm.com        print "*** %s: %s: Test successful, not updating." % (
17011504Sandreas.sandberg@arm.com            source[0].dir, color_message(termcap.Green, "skipped"), )
17111504Sandreas.sandberg@arm.com        return 0
17211542Sandreas.sandberg@arm.com    elif result.failed_run():
17311504Sandreas.sandberg@arm.com        print "*** %s: %s: Test failed, not updating." % (
17411504Sandreas.sandberg@arm.com            source[0].dir, color_message(termcap.Red, "ERROR"), )
17511504Sandreas.sandberg@arm.com        return 1
17611504Sandreas.sandberg@arm.com
17711504Sandreas.sandberg@arm.com    print "** Updating %s" % (test, )
17811504Sandreas.sandberg@arm.com    test.update_ref()
17911504Sandreas.sandberg@arm.com
1802929Sktlim@umich.edu    return 0
1812929Sktlim@umich.edu
1822929Sktlim@umich.edudef update_test_string(target, source, env):
18311504Sandreas.sandberg@arm.com    return env.subst("Updating ${SOURCES[0].dir}",
1842929Sktlim@umich.edu                     target=target, source=source)
1852929Sktlim@umich.edu
1862929Sktlim@umich.eduupdateAction = env.Action(update_test, update_test_string)
1872929Sktlim@umich.edu
18811504Sandreas.sandberg@arm.comdef test_builder(test_tuple):
1892997Sstever@eecs.umich.edu    """Define a test."""
1902929Sktlim@umich.edu
19111504Sandreas.sandberg@arm.com    out_dir = "/".join(test_tuple)
19211504Sandreas.sandberg@arm.com    binary = env.M5Binary.abspath
19311504Sandreas.sandberg@arm.com    test = tests.ClassicTest(binary, out_dir, test_tuple)
1942929Sktlim@umich.edu
19511504Sandreas.sandberg@arm.com    def tgt(name):
19611504Sandreas.sandberg@arm.com        return os.path.join(out_dir, name)
1972929Sktlim@umich.edu
19811504Sandreas.sandberg@arm.com    def ref(name):
19911504Sandreas.sandberg@arm.com        return os.path.join(test.ref_dir, name)
2002997Sstever@eecs.umich.edu
20111504Sandreas.sandberg@arm.com    pickle_file = tgt("status.pickle")
20211504Sandreas.sandberg@arm.com    targets = [
20311504Sandreas.sandberg@arm.com        pickle_file,
20411504Sandreas.sandberg@arm.com    ]
2052997Sstever@eecs.umich.edu
20611504Sandreas.sandberg@arm.com    sources = [
20711504Sandreas.sandberg@arm.com        env.M5Binary,
20811504Sandreas.sandberg@arm.com        "run.py",
20911504Sandreas.sandberg@arm.com    ] + [ ref(f) for f in test.ref_files() ]
21011504Sandreas.sandberg@arm.com
21111504Sandreas.sandberg@arm.com    env.Command(targets, sources, testAction)
2122929Sktlim@umich.edu
2132997Sstever@eecs.umich.edu    # phony target to echo status
2148120Sgblack@eecs.umich.edu    if GetOption('update_ref'):
21511504Sandreas.sandberg@arm.com        p = env.Command(tgt("_update"), [pickle_file], updateAction)
2162997Sstever@eecs.umich.edu    else:
21711504Sandreas.sandberg@arm.com        p = env.Command(tgt("_print"), [pickle_file], printAction)
2182929Sktlim@umich.edu
2192997Sstever@eecs.umich.edu    env.AlwaysBuild(p)
2202929Sktlim@umich.edu
22111504Sandreas.sandberg@arm.comdef list_tests(target, source, env):
22211504Sandreas.sandberg@arm.com    """Create a list of tests
2232929Sktlim@umich.edu
22411504Sandreas.sandberg@arm.com    Targets are as follows:
22511504Sandreas.sandberg@arm.com    target[0] : List file (e.g., tests/opt/all.list,  tests/opt/quick.list)
2263691Shsul@eecs.umich.edu
22711504Sandreas.sandberg@arm.com    Sources are: -
2283005Sstever@eecs.umich.edu
22911504Sandreas.sandberg@arm.com    """
23011105Spower.jg@gmail.com
23111504Sandreas.sandberg@arm.com    tgt_name = os.path.basename(str(target[0]))
23211504Sandreas.sandberg@arm.com    base, ext = os.path.splitext(tgt_name)
23311504Sandreas.sandberg@arm.com    categories = tests.all_categories if base == "all" else (base, )
2346166Ssteve.reinhardt@amd.com
23511504Sandreas.sandberg@arm.com    with open(target[0].abspath, "w") as fout:
23611504Sandreas.sandberg@arm.com        for cat in categories:
23711504Sandreas.sandberg@arm.com            for test in env.Tests[cat]:
23811504Sandreas.sandberg@arm.com                print >> fout,"/".join(test)
23911504Sandreas.sandberg@arm.com
24011504Sandreas.sandberg@arm.com    return 0
24111504Sandreas.sandberg@arm.com
24211504Sandreas.sandberg@arm.comtestListAction = env.Action(list_tests, strfunction=None)
24311504Sandreas.sandberg@arm.com
24411504Sandreas.sandberg@arm.comenv.Command("all.list", tuple(), testListAction)
24511504Sandreas.sandberg@arm.comfor cat, test_list in env.Tests.items():
24611504Sandreas.sandberg@arm.com    env.Command("%s.list" % cat, tuple(), testListAction)
24711504Sandreas.sandberg@arm.com    for test in test_list:
24811504Sandreas.sandberg@arm.com        test_builder(test)
249