SConscript revision 12302
1955SN/A# -*- mode:python -*-
2955SN/A#
31762SN/A# Copyright (c) 2016 ARM Limited
4955SN/A# All rights reserved
5955SN/A#
6955SN/A# The license below extends only to copyright in the software and shall
7955SN/A# not be construed as granting a license to any other intellectual
8955SN/A# property including but not limited to intellectual property relating
9955SN/A# to a hardware implementation of the functionality of the software
10955SN/A# licensed hereunder.  You may use the software subject to the license
11955SN/A# terms below provided that you ensure that this notice is replicated
12955SN/A# unmodified and in its entirety in all distributions of the software,
13955SN/A# modified or unmodified, in source code or in binary form.
14955SN/A#
15955SN/A# Copyright (c) 2004-2006 The Regents of The University of Michigan
16955SN/A# All rights reserved.
17955SN/A#
18955SN/A# Redistribution and use in source and binary forms, with or without
19955SN/A# modification, are permitted provided that the following conditions are
20955SN/A# met: redistributions of source code must retain the above copyright
21955SN/A# notice, this list of conditions and the following disclaimer;
22955SN/A# redistributions in binary form must reproduce the above copyright
23955SN/A# notice, this list of conditions and the following disclaimer in the
24955SN/A# documentation and/or other materials provided with the distribution;
25955SN/A# neither the name of the copyright holders nor the names of its
26955SN/A# contributors may be used to endorse or promote products derived from
27955SN/A# this software without specific prior written permission.
28955SN/A#
29955SN/A# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
30955SN/A# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
311608SN/A# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
32955SN/A# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
33955SN/A# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
34955SN/A# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
35955SN/A# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
36955SN/A# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
37955SN/A# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
38955SN/A# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
39955SN/A# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
40955SN/A#
41955SN/A# Authors: Steve Reinhardt
42955SN/A#          Kevin Lim
43955SN/A#          Andreas Sandberg
44955SN/A
45955SN/Afrom SCons.Script.SConscript import SConsEnvironment
462023SN/Aimport os
47955SN/Aimport pickle
48955SN/Aimport sys
49955SN/A
50955SN/Asys.path.insert(0, Dir(".").srcnode().abspath)
511310SN/Aimport testing.tests as tests
52955SN/Aimport testing.results as results
53955SN/Afrom gem5_scons.util import get_termcap
54955SN/A
55955SN/AImport('env')
56955SN/A
57955SN/A# get the termcap from the environment
581031SN/Atermcap = get_termcap()
59955SN/A
601388SN/A# Dict that accumulates lists of tests by category (quick, medium, long)
61955SN/Aenv.Tests = {}
62955SN/Agpu_isa = env['TARGET_GPU_ISA'] if env['BUILD_GPU'] else None
631296SN/Afor cat in tests.all_categories:
64955SN/A    env.Tests[cat] = tuple(
652609SN/A        tests.get_tests(env["TARGET_ISA"],
66955SN/A                        categories=(cat, ),
67955SN/A                        ruby_protocol=env["PROTOCOL"],
68955SN/A                        gpu_isa=gpu_isa))
69955SN/A
70955SN/Adef color_message(color, msg):
71955SN/A    return color + msg + termcap.Normal
72955SN/A
73955SN/Adef run_test(target, source, env):
74955SN/A    """Run a test and produce results as a pickle file.
75955SN/A
76955SN/A    Targets are as follows:
77955SN/A    target[0] : Pickle file
78955SN/A
79955SN/A    Sources are:
80955SN/A    source[0] : gem5 binary
81955SN/A    source[1] : tests/run.py script
82955SN/A    source[2:] : reference files
83955SN/A
841717SN/A    """
852190SN/A    tgt_dir = os.path.dirname(str(target[0]))
862652Ssaidi@eecs.umich.edu    config = tests.ClassicConfig(*tgt_dir.split('/')[-6:])
87955SN/A    test = tests.ClassicTest(source[0].abspath, tgt_dir, config,
882410SN/A                             timeout=5*60*60,
89955SN/A                             skip_diff_out=True)
90955SN/A
911717SN/A    for ref in test.ref_files():
922568SN/A        out_file = os.path.join(tgt_dir, ref)
932568SN/A        if os.path.exists(out_file):
942568SN/A            env.Execute(Delete(out_file))
952499SN/A
962462SN/A    with open(target[0].abspath, "wb") as fout:
972568SN/A        formatter = results.Pickle(fout=fout)
982395SN/A        formatter.dump_suites([ test.run() ])
992405SN/A
1002568SN/A    return 0
101955SN/A
1021511SN/Adef run_test_string(target, source, env):
1031511SN/A    return env.subst("Running test in ${TARGETS[0].dir}.",
1041511SN/A                     target=target, source=source)
105955SN/A
106955SN/AtestAction = env.Action(run_test, run_test_string)
107955SN/A
108955SN/Adef print_test(target, source, env):
1092090SN/A    """Run a test and produce results as a pickle file.
110955SN/A
111955SN/A    Targets are as follows:
112955SN/A    target[*] : Dummy targets
1131696SN/A
114955SN/A    Sources are:
115955SN/A    source[0] : Pickle file
116955SN/A
117955SN/A    """
1181127SN/A    with open(source[0].abspath, "rb") as fin:
119955SN/A        result = pickle.load(fin)
120955SN/A
1212379SN/A    assert len(result) == 1
122955SN/A    result = result[0]
123955SN/A
124955SN/A    formatter = None
1252155SN/A    if result.skipped():
1262155SN/A        status = color_message(termcap.Cyan, "skipped.")
1272155SN/A    elif result.changed():
1282155SN/A        status = color_message(termcap.Yellow, "CHANGED!")
1292155SN/A        formatter = results.Text()
1302155SN/A    elif result:
1312155SN/A        status = color_message(termcap.Green, "passed.")
1322155SN/A    else:
1332155SN/A        status = color_message(termcap.Red, "FAILED!")
1342155SN/A        formatter = results.Text()
1352155SN/A
1362155SN/A    if formatter:
1372155SN/A        formatter.dump_suites([result])
1382155SN/A
1392155SN/A    print "***** %s: %s" % (source[0].dir, status)
1402155SN/A    return 0
1412155SN/A
1422155SN/AprintAction = env.Action(print_test, strfunction=None)
1432155SN/A
1442155SN/Adef update_test(target, source, env):
1452155SN/A    """Update test reference data
1462155SN/A
1472155SN/A    Targets are as follows:
1482155SN/A    target[0] : Dummy file
1492155SN/A
1502155SN/A    Sources are:
1512155SN/A    source[0] : Pickle file
1522155SN/A    """
1532155SN/A
1542155SN/A    src_dir = os.path.dirname(str(source[0]))
1552155SN/A    config = tests.ClassicConfig(*src_dir.split('/')[-6:])
1562155SN/A    test = tests.ClassicTest(source[0].abspath, src_dir, config)
1572155SN/A    ref_dir = test.ref_dir
1582155SN/A
1592155SN/A    with open(source[0].abspath, "rb") as fin:
1602155SN/A        result = pickle.load(fin)
1612155SN/A
1622155SN/A    assert len(result) == 1
1632155SN/A    result = result[0]
1642422SN/A
1652422SN/A    if result.skipped():
1662422SN/A        print "*** %s: %s: Test skipped, not updating." % (
1672422SN/A            source[0].dir, color_message(termcap.Yellow, "WARNING"), )
1682422SN/A        return 0
1692422SN/A    elif result:
1702422SN/A        print "*** %s: %s: Test successful, not updating." % (
1712397SN/A            source[0].dir, color_message(termcap.Green, "skipped"), )
1722397SN/A        return 0
1732422SN/A    elif result.failed_run():
1742422SN/A        print "*** %s: %s: Test failed, not updating." % (
175955SN/A            source[0].dir, color_message(termcap.Red, "ERROR"), )
176955SN/A        return 1
177955SN/A
178955SN/A    print "** Updating %s" % (test, )
179955SN/A    test.update_ref()
180955SN/A
181955SN/A    return 0
182955SN/A
1831078SN/Adef update_test_string(target, source, env):
184955SN/A    return env.subst("Updating ${SOURCES[0].dir}",
185955SN/A                     target=target, source=source)
186955SN/A
187955SN/AupdateAction = env.Action(update_test, update_test_string)
1881917SN/A
189955SN/Adef test_builder(test_tuple):
190955SN/A    """Define a test."""
191955SN/A
192955SN/A    out_dir = "/".join(test_tuple)
193974SN/A    binary = env.M5Binary.abspath
194955SN/A    test = tests.ClassicTest(binary, out_dir, test_tuple)
195955SN/A
196955SN/A    def tgt(name):
197955SN/A        return os.path.join(out_dir, name)
1982566SN/A
1992566SN/A    def ref(name):
200955SN/A        return os.path.join(test.ref_dir, name)
201955SN/A
2022539SN/A    pickle_file = tgt("status.pickle")
203955SN/A    targets = [
204955SN/A        pickle_file,
205955SN/A    ]
2061817SN/A
2071154SN/A    sources = [
2081840SN/A        env.M5Binary,
2092522SN/A        "run.py",
2102522SN/A    ] + [ ref(f) for f in test.ref_files() ]
2112629SN/A
212955SN/A    env.Command(targets, sources, testAction)
213955SN/A
214955SN/A    # phony target to echo status
2152539SN/A    if GetOption('update_ref'):
216955SN/A        p = env.Command(tgt("_update"), [pickle_file], updateAction)
2172539SN/A    else:
218955SN/A        p = env.Command(tgt("_print"), [pickle_file], printAction)
2191730SN/A
220955SN/A    env.AlwaysBuild(p)
2211070SN/A
222955SN/Adef list_tests(target, source, env):
223955SN/A    """Create a list of tests
2242212SN/A
225955SN/A    Targets are as follows:
2261040SN/A    target[0] : List file (e.g., tests/opt/all.list,  tests/opt/quick.list)
2272507SN/A
2282521SN/A    Sources are: -
2292521SN/A
2302507SN/A    """
2312507SN/A
2322507SN/A    tgt_name = os.path.basename(str(target[0]))
2332521SN/A    base, ext = os.path.splitext(tgt_name)
2342507SN/A    categories = tests.all_categories if base == "all" else (base, )
2352507SN/A
236955SN/A    with open(target[0].abspath, "w") as fout:
237955SN/A        for cat in categories:
238955SN/A            for test in env.Tests[cat]:
239955SN/A                print >> fout,"/".join(test)
240955SN/A
241955SN/A    return 0
2421742SN/A
2431742SN/AtestListAction = env.Action(list_tests, strfunction=None)
2441742SN/A
2451742SN/Aenv.Command("all.list", tuple(), testListAction)
2461742SN/Afor cat, test_list in env.Tests.items():
2471742SN/A    env.Command("%s.list" % cat, tuple(), testListAction)
2481742SN/A    for test in test_list:
2491742SN/A        test_builder(test)
2501742SN/A