SConscript revision 12246
12929Sktlim@umich.edu# -*- mode:python -*-
22929Sktlim@umich.edu#
32932Sktlim@umich.edu# Copyright (c) 2016 ARM Limited
42929Sktlim@umich.edu# All rights reserved
52929Sktlim@umich.edu#
62929Sktlim@umich.edu# The license below extends only to copyright in the software and shall
72929Sktlim@umich.edu# not be construed as granting a license to any other intellectual
82929Sktlim@umich.edu# property including but not limited to intellectual property relating
92929Sktlim@umich.edu# to a hardware implementation of the functionality of the software
102929Sktlim@umich.edu# licensed hereunder.  You may use the software subject to the license
112929Sktlim@umich.edu# terms below provided that you ensure that this notice is replicated
122929Sktlim@umich.edu# unmodified and in its entirety in all distributions of the software,
132929Sktlim@umich.edu# modified or unmodified, in source code or in binary form.
142929Sktlim@umich.edu#
152929Sktlim@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.
282932Sktlim@umich.edu#
292932Sktlim@umich.edu# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
302932Sktlim@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.
402929Sktlim@umich.edu#
412929Sktlim@umich.edu# Authors: Steve Reinhardt
422929Sktlim@umich.edu#          Kevin Lim
432929Sktlim@umich.edu#          Andreas Sandberg
442929Sktlim@umich.edu
452929Sktlim@umich.edufrom SCons.Script.SConscript import SConsEnvironment
462929Sktlim@umich.eduimport os
472929Sktlim@umich.eduimport pickle
482929Sktlim@umich.eduimport sys
492929Sktlim@umich.edu
502929Sktlim@umich.edusys.path.insert(0, Dir(".").srcnode().abspath)
512929Sktlim@umich.eduimport testing.tests as tests
522929Sktlim@umich.eduimport testing.results as results
532929Sktlim@umich.edufrom gem5_scons.util import get_termcap
542929Sktlim@umich.edu
552929Sktlim@umich.eduImport('env')
562929Sktlim@umich.edu
572929Sktlim@umich.edu# get the termcap from the environment
582929Sktlim@umich.edutermcap = get_termcap()
592929Sktlim@umich.edu
602929Sktlim@umich.edu# Dict that accumulates lists of tests by category (quick, medium, long)
612929Sktlim@umich.eduenv.Tests = {}
622929Sktlim@umich.edugpu_isa = env['TARGET_GPU_ISA'] if env['BUILD_GPU'] else None
632929Sktlim@umich.edufor cat in tests.all_categories:
642929Sktlim@umich.edu    env.Tests[cat] = tuple(
652929Sktlim@umich.edu        tests.get_tests(env["TARGET_ISA"],
662929Sktlim@umich.edu                        categories=(cat, ),
672929Sktlim@umich.edu                        ruby_protocol=env["PROTOCOL"],
682929Sktlim@umich.edu                        gpu_isa=gpu_isa))
692929Sktlim@umich.edu
702929Sktlim@umich.edudef color_message(color, msg):
712929Sktlim@umich.edu    return color + msg + termcap.Normal
722929Sktlim@umich.edu
732929Sktlim@umich.edudef run_test(target, source, env):
742929Sktlim@umich.edu    """Run a test and produce results as a pickle file.
752929Sktlim@umich.edu
762929Sktlim@umich.edu    Targets are as follows:
772929Sktlim@umich.edu    target[0] : Pickle file
782929Sktlim@umich.edu
792929Sktlim@umich.edu    Sources are:
802929Sktlim@umich.edu    source[0] : gem5 binary
812929Sktlim@umich.edu    source[1] : tests/run.py script
822929Sktlim@umich.edu    source[2:] : reference files
832929Sktlim@umich.edu
842929Sktlim@umich.edu    """
852929Sktlim@umich.edu    tgt_dir = os.path.dirname(str(target[0]))
862929Sktlim@umich.edu    config = tests.ClassicConfig(*tgt_dir.split('/')[-6:])
872929Sktlim@umich.edu    test = tests.ClassicTest(source[0].abspath, tgt_dir, config,
882929Sktlim@umich.edu                             timeout=5*60*60,
892929Sktlim@umich.edu                             skip_diff_out=True)
902929Sktlim@umich.edu
912929Sktlim@umich.edu    for ref in test.ref_files():
922929Sktlim@umich.edu        out_file = os.path.join(tgt_dir, ref)
932929Sktlim@umich.edu        if os.path.exists(out_file):
942929Sktlim@umich.edu            env.Execute(Delete(out_file))
952929Sktlim@umich.edu
962929Sktlim@umich.edu    with open(target[0].abspath, "wb") as fout:
972929Sktlim@umich.edu        formatter = results.Pickle(fout=fout)
982929Sktlim@umich.edu        formatter.dump_suites([ test.run() ])
992929Sktlim@umich.edu
1002929Sktlim@umich.edu    return 0
1012929Sktlim@umich.edu
1022929Sktlim@umich.edudef run_test_string(target, source, env):
1032929Sktlim@umich.edu    return env.subst("Running test in ${TARGETS[0].dir}.",
1042929Sktlim@umich.edu                     target=target, source=source)
1052929Sktlim@umich.edu
1062929Sktlim@umich.edutestAction = env.Action(run_test, run_test_string)
1072929Sktlim@umich.edu
1082929Sktlim@umich.edudef print_test(target, source, env):
1092929Sktlim@umich.edu    """Run a test and produce results as a pickle file.
1102929Sktlim@umich.edu
1112929Sktlim@umich.edu    Targets are as follows:
1122929Sktlim@umich.edu    target[*] : Dummy targets
1132929Sktlim@umich.edu
1142929Sktlim@umich.edu    Sources are:
1152929Sktlim@umich.edu    source[0] : Pickle file
1162929Sktlim@umich.edu
1172929Sktlim@umich.edu    """
1182929Sktlim@umich.edu    with open(source[0].abspath, "rb") as fin:
1192929Sktlim@umich.edu        result = pickle.load(fin)
1202929Sktlim@umich.edu
1212929Sktlim@umich.edu    assert len(result) == 1
1222929Sktlim@umich.edu    result = result[0]
1232929Sktlim@umich.edu
1242929Sktlim@umich.edu    formatter = None
1252929Sktlim@umich.edu    if result.skipped():
1262929Sktlim@umich.edu        status = color_message(termcap.Cyan, "skipped.")
1272929Sktlim@umich.edu    elif result.changed():
1282929Sktlim@umich.edu        status = color_message(termcap.Yellow, "CHANGED!")
1292929Sktlim@umich.edu        formatter = results.Text()
1302929Sktlim@umich.edu    elif result:
1312929Sktlim@umich.edu        status = color_message(termcap.Green, "passed.")
1322929Sktlim@umich.edu    else:
1332929Sktlim@umich.edu        status = color_message(termcap.Red, "FAILED!")
1342929Sktlim@umich.edu        formatter = results.Text()
1352929Sktlim@umich.edu
1362929Sktlim@umich.edu    if formatter:
1372929Sktlim@umich.edu        formatter.dump_suites([result])
1382929Sktlim@umich.edu
1392929Sktlim@umich.edu    print "***** %s: %s" % (source[0].dir, status)
1402929Sktlim@umich.edu    return 0
1412929Sktlim@umich.edu
1422997Sstever@eecs.umich.eduprintAction = env.Action(print_test, strfunction=None)
1432997Sstever@eecs.umich.edu
1442929Sktlim@umich.edudef update_test(target, source, env):
1452997Sstever@eecs.umich.edu    """Update test reference data
1462997Sstever@eecs.umich.edu
1472929Sktlim@umich.edu    Targets are as follows:
1482997Sstever@eecs.umich.edu    target[0] : Dummy file
1492997Sstever@eecs.umich.edu
1502997Sstever@eecs.umich.edu    Sources are:
1512929Sktlim@umich.edu    source[0] : Pickle file
1522997Sstever@eecs.umich.edu    """
1532997Sstever@eecs.umich.edu
1542997Sstever@eecs.umich.edu    src_dir = os.path.dirname(str(source[0]))
1552997Sstever@eecs.umich.edu    config = tests.ClassicConfig(*src_dir.split('/')[-6:])
1562997Sstever@eecs.umich.edu    test = tests.ClassicTest(source[0].abspath, src_dir, config)
1572997Sstever@eecs.umich.edu    ref_dir = test.ref_dir
1582997Sstever@eecs.umich.edu
1592997Sstever@eecs.umich.edu    with open(source[0].abspath, "rb") as fin:
1602997Sstever@eecs.umich.edu        result = pickle.load(fin)
1612997Sstever@eecs.umich.edu
1622997Sstever@eecs.umich.edu    assert len(result) == 1
1632997Sstever@eecs.umich.edu    result = result[0]
1642997Sstever@eecs.umich.edu
1652997Sstever@eecs.umich.edu    if result.skipped():
1662997Sstever@eecs.umich.edu        print "*** %s: %s: Test skipped, not updating." % (
1672997Sstever@eecs.umich.edu            source[0].dir, color_message(termcap.Yellow, "WARNING"), )
1682997Sstever@eecs.umich.edu        return 0
1692997Sstever@eecs.umich.edu    elif result:
1702997Sstever@eecs.umich.edu        print "*** %s: %s: Test successful, not updating." % (
1712997Sstever@eecs.umich.edu            source[0].dir, color_message(termcap.Green, "skipped"), )
1722997Sstever@eecs.umich.edu        return 0
1732997Sstever@eecs.umich.edu    elif result.failed_run():
1742997Sstever@eecs.umich.edu        print "*** %s: %s: Test failed, not updating." % (
1752953Sktlim@umich.edu            source[0].dir, color_message(termcap.Red, "ERROR"), )
1762997Sstever@eecs.umich.edu        return 1
1772997Sstever@eecs.umich.edu
1782997Sstever@eecs.umich.edu    print "** Updating %s" % (test, )
1792997Sstever@eecs.umich.edu    test.update_ref()
1802929Sktlim@umich.edu
1812997Sstever@eecs.umich.edu    return 0
1822997Sstever@eecs.umich.edu
1832997Sstever@eecs.umich.edudef update_test_string(target, source, env):
1842997Sstever@eecs.umich.edu    return env.subst("Updating ${SOURCES[0].dir}",
1852929Sktlim@umich.edu                     target=target, source=source)
1862997Sstever@eecs.umich.edu
1872997Sstever@eecs.umich.eduupdateAction = env.Action(update_test, update_test_string)
1882997Sstever@eecs.umich.edu
1892997Sstever@eecs.umich.edudef test_builder(test_tuple):
1902997Sstever@eecs.umich.edu    """Define a test."""
1912997Sstever@eecs.umich.edu
1922997Sstever@eecs.umich.edu    out_dir = "/".join(test_tuple)
1932929Sktlim@umich.edu    binary = env.M5Binary.abspath
1942997Sstever@eecs.umich.edu    test = tests.ClassicTest(binary, out_dir, test_tuple)
1952929Sktlim@umich.edu
1962929Sktlim@umich.edu    def tgt(name):
1972929Sktlim@umich.edu        return os.path.join(out_dir, name)
1982929Sktlim@umich.edu
1992997Sstever@eecs.umich.edu    def ref(name):
2002997Sstever@eecs.umich.edu        return os.path.join(test.ref_dir, name)
2012997Sstever@eecs.umich.edu
2022997Sstever@eecs.umich.edu    pickle_file = tgt("status.pickle")
2032929Sktlim@umich.edu    targets = [
204        pickle_file,
205    ]
206
207    sources = [
208        env.M5Binary,
209        "run.py",
210    ] + [ ref(f) for f in test.ref_files() ]
211
212    env.Command(targets, sources, testAction)
213
214    # phony target to echo status
215    if GetOption('update_ref'):
216        p = env.Command(tgt("_update"), [pickle_file], updateAction)
217    else:
218        p = env.Command(tgt("_print"), [pickle_file], printAction)
219
220    env.AlwaysBuild(p)
221
222def list_tests(target, source, env):
223    """Create a list of tests
224
225    Targets are as follows:
226    target[0] : List file (e.g., tests/opt/all.list,  tests/opt/quick.list)
227
228    Sources are: -
229
230    """
231
232    tgt_name = os.path.basename(str(target[0]))
233    base, ext = os.path.splitext(tgt_name)
234    categories = tests.all_categories if base == "all" else (base, )
235
236    with open(target[0].abspath, "w") as fout:
237        for cat in categories:
238            for test in env.Tests[cat]:
239                print >> fout,"/".join(test)
240
241    return 0
242
243testListAction = env.Action(list_tests, strfunction=None)
244
245env.Command("all.list", tuple(), testListAction)
246for cat, test_list in env.Tests.items():
247    env.Command("%s.list" % cat, tuple(), testListAction)
248    for test in test_list:
249        test_builder(test)
250