SConscript revision 11504
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    run = result.results[0]
12411504Sandreas.sandberg@arm.com    assert run.name == "gem5"
12511504Sandreas.sandberg@arm.com
12611504Sandreas.sandberg@arm.com    formatter = None
12711504Sandreas.sandberg@arm.com    if not run:
12811504Sandreas.sandberg@arm.com        status = color_message(termcap.Red, "FAILED!")
12911504Sandreas.sandberg@arm.com        formatter = results.Text()
13011504Sandreas.sandberg@arm.com    elif run.skipped():
13111504Sandreas.sandberg@arm.com        status = color_message(termcap.Cyan, "skipped.")
13211504Sandreas.sandberg@arm.com    elif result:
13311504Sandreas.sandberg@arm.com        status = color_message(termcap.Green, "passed.")
13411504Sandreas.sandberg@arm.com    else:
13511504Sandreas.sandberg@arm.com        status = color_message(termcap.Yellow, "CHANGED!")
13611504Sandreas.sandberg@arm.com        formatter = results.Text()
13711504Sandreas.sandberg@arm.com
13811504Sandreas.sandberg@arm.com    if formatter:
13911504Sandreas.sandberg@arm.com        formatter.dump_suites([result])
14011504Sandreas.sandberg@arm.com
14111504Sandreas.sandberg@arm.com    print "***** %s: %s" % (source[0].dir, status)
1422929Sktlim@umich.edu    return 0
1432929Sktlim@umich.edu
14411504Sandreas.sandberg@arm.comprintAction = env.Action(print_test, strfunction=None)
1454937Sstever@gmail.com
1462929Sktlim@umich.edudef update_test(target, source, env):
14711504Sandreas.sandberg@arm.com    """Update test reference data
1482929Sktlim@umich.edu
14911504Sandreas.sandberg@arm.com    Targets are as follows:
15011504Sandreas.sandberg@arm.com    target[0] : Dummy file
1512929Sktlim@umich.edu
15211504Sandreas.sandberg@arm.com    Sources are:
15311504Sandreas.sandberg@arm.com    source[0] : Pickle file
1542929Sktlim@umich.edu    """
15511504Sandreas.sandberg@arm.com
15611504Sandreas.sandberg@arm.com    src_dir = os.path.dirname(str(source[0]))
15711504Sandreas.sandberg@arm.com    config = tests.ClassicConfig(*src_dir.split('/')[-6:])
15811504Sandreas.sandberg@arm.com    test = tests.ClassicTest(source[0].abspath, src_dir, config)
15911504Sandreas.sandberg@arm.com    ref_dir = test.ref_dir
16011504Sandreas.sandberg@arm.com
16111504Sandreas.sandberg@arm.com    with open(source[0].abspath, "rb") as fin:
16211504Sandreas.sandberg@arm.com        result = pickle.load(fin)
16311504Sandreas.sandberg@arm.com
16411504Sandreas.sandberg@arm.com    assert len(result) == 1
16511504Sandreas.sandberg@arm.com    result = result[0]
16611504Sandreas.sandberg@arm.com
16711504Sandreas.sandberg@arm.com    run = result.results[0]
16811504Sandreas.sandberg@arm.com    assert run.name == "gem5"
16911504Sandreas.sandberg@arm.com
17011504Sandreas.sandberg@arm.com    if run.skipped():
17111504Sandreas.sandberg@arm.com        print "*** %s: %s: Test skipped, not updating." % (
17211504Sandreas.sandberg@arm.com            source[0].dir, color_message(termcap.Yellow, "WARNING"), )
17311504Sandreas.sandberg@arm.com        return 0
17411504Sandreas.sandberg@arm.com    elif result:
17511504Sandreas.sandberg@arm.com        print "*** %s: %s: Test successful, not updating." % (
17611504Sandreas.sandberg@arm.com            source[0].dir, color_message(termcap.Green, "skipped"), )
17711504Sandreas.sandberg@arm.com        return 0
17811504Sandreas.sandberg@arm.com    elif not run.success():
17911504Sandreas.sandberg@arm.com        print "*** %s: %s: Test failed, not updating." % (
18011504Sandreas.sandberg@arm.com            source[0].dir, color_message(termcap.Red, "ERROR"), )
18111504Sandreas.sandberg@arm.com        return 1
18211504Sandreas.sandberg@arm.com
18311504Sandreas.sandberg@arm.com    print "** Updating %s" % (test, )
18411504Sandreas.sandberg@arm.com    test.update_ref()
18511504Sandreas.sandberg@arm.com
1862929Sktlim@umich.edu    return 0
1872929Sktlim@umich.edu
1882929Sktlim@umich.edudef update_test_string(target, source, env):
18911504Sandreas.sandberg@arm.com    return env.subst("Updating ${SOURCES[0].dir}",
1902929Sktlim@umich.edu                     target=target, source=source)
1912929Sktlim@umich.edu
1922929Sktlim@umich.eduupdateAction = env.Action(update_test, update_test_string)
1932929Sktlim@umich.edu
19411504Sandreas.sandberg@arm.comdef test_builder(test_tuple):
1952997Sstever@eecs.umich.edu    """Define a test."""
1962929Sktlim@umich.edu
19711504Sandreas.sandberg@arm.com    out_dir = "/".join(test_tuple)
19811504Sandreas.sandberg@arm.com    binary = env.M5Binary.abspath
19911504Sandreas.sandberg@arm.com    test = tests.ClassicTest(binary, out_dir, test_tuple)
2002929Sktlim@umich.edu
20111504Sandreas.sandberg@arm.com    def tgt(name):
20211504Sandreas.sandberg@arm.com        return os.path.join(out_dir, name)
2032929Sktlim@umich.edu
20411504Sandreas.sandberg@arm.com    def ref(name):
20511504Sandreas.sandberg@arm.com        return os.path.join(test.ref_dir, name)
2062997Sstever@eecs.umich.edu
20711504Sandreas.sandberg@arm.com    pickle_file = tgt("status.pickle")
20811504Sandreas.sandberg@arm.com    targets = [
20911504Sandreas.sandberg@arm.com        pickle_file,
21011504Sandreas.sandberg@arm.com    ]
2112997Sstever@eecs.umich.edu
21211504Sandreas.sandberg@arm.com    sources = [
21311504Sandreas.sandberg@arm.com        env.M5Binary,
21411504Sandreas.sandberg@arm.com        "run.py",
21511504Sandreas.sandberg@arm.com    ] + [ ref(f) for f in test.ref_files() ]
21611504Sandreas.sandberg@arm.com
21711504Sandreas.sandberg@arm.com    env.Command(targets, sources, testAction)
2182929Sktlim@umich.edu
2192997Sstever@eecs.umich.edu    # phony target to echo status
2208120Sgblack@eecs.umich.edu    if GetOption('update_ref'):
22111504Sandreas.sandberg@arm.com        p = env.Command(tgt("_update"), [pickle_file], updateAction)
2222997Sstever@eecs.umich.edu    else:
22311504Sandreas.sandberg@arm.com        p = env.Command(tgt("_print"), [pickle_file], printAction)
2242929Sktlim@umich.edu
2252997Sstever@eecs.umich.edu    env.AlwaysBuild(p)
2262929Sktlim@umich.edu
22711504Sandreas.sandberg@arm.comdef list_tests(target, source, env):
22811504Sandreas.sandberg@arm.com    """Create a list of tests
2292929Sktlim@umich.edu
23011504Sandreas.sandberg@arm.com    Targets are as follows:
23111504Sandreas.sandberg@arm.com    target[0] : List file (e.g., tests/opt/all.list,  tests/opt/quick.list)
2323691Shsul@eecs.umich.edu
23311504Sandreas.sandberg@arm.com    Sources are: -
2343005Sstever@eecs.umich.edu
23511504Sandreas.sandberg@arm.com    """
23611105Spower.jg@gmail.com
23711504Sandreas.sandberg@arm.com    tgt_name = os.path.basename(str(target[0]))
23811504Sandreas.sandberg@arm.com    base, ext = os.path.splitext(tgt_name)
23911504Sandreas.sandberg@arm.com    categories = tests.all_categories if base == "all" else (base, )
2406166Ssteve.reinhardt@amd.com
24111504Sandreas.sandberg@arm.com    with open(target[0].abspath, "w") as fout:
24211504Sandreas.sandberg@arm.com        for cat in categories:
24311504Sandreas.sandberg@arm.com            for test in env.Tests[cat]:
24411504Sandreas.sandberg@arm.com                print >> fout,"/".join(test)
24511504Sandreas.sandberg@arm.com
24611504Sandreas.sandberg@arm.com    return 0
24711504Sandreas.sandberg@arm.com
24811504Sandreas.sandberg@arm.comtestListAction = env.Action(list_tests, strfunction=None)
24911504Sandreas.sandberg@arm.com
25011504Sandreas.sandberg@arm.comenv.Command("all.list", tuple(), testListAction)
25111504Sandreas.sandberg@arm.comfor cat, test_list in env.Tests.items():
25211504Sandreas.sandberg@arm.com    env.Command("%s.list" % cat, tuple(), testListAction)
25311504Sandreas.sandberg@arm.com    for test in test_list:
25411504Sandreas.sandberg@arm.com        test_builder(test)
255