SConscript revision 12371
14484Sbinkertn@umich.edu# -*- mode:python -*-
24484Sbinkertn@umich.edu#
34484Sbinkertn@umich.edu# Copyright (c) 2016 ARM Limited
44484Sbinkertn@umich.edu# All rights reserved
54484Sbinkertn@umich.edu#
64484Sbinkertn@umich.edu# The license below extends only to copyright in the software and shall
74484Sbinkertn@umich.edu# not be construed as granting a license to any other intellectual
84484Sbinkertn@umich.edu# property including but not limited to intellectual property relating
94484Sbinkertn@umich.edu# to a hardware implementation of the functionality of the software
104484Sbinkertn@umich.edu# licensed hereunder.  You may use the software subject to the license
114484Sbinkertn@umich.edu# terms below provided that you ensure that this notice is replicated
124484Sbinkertn@umich.edu# unmodified and in its entirety in all distributions of the software,
134484Sbinkertn@umich.edu# modified or unmodified, in source code or in binary form.
144484Sbinkertn@umich.edu#
154484Sbinkertn@umich.edu# Copyright (c) 2004-2006 The Regents of The University of Michigan
164484Sbinkertn@umich.edu# All rights reserved.
174484Sbinkertn@umich.edu#
184484Sbinkertn@umich.edu# Redistribution and use in source and binary forms, with or without
194484Sbinkertn@umich.edu# modification, are permitted provided that the following conditions are
204484Sbinkertn@umich.edu# met: redistributions of source code must retain the above copyright
214484Sbinkertn@umich.edu# notice, this list of conditions and the following disclaimer;
224484Sbinkertn@umich.edu# redistributions in binary form must reproduce the above copyright
234484Sbinkertn@umich.edu# notice, this list of conditions and the following disclaimer in the
244484Sbinkertn@umich.edu# documentation and/or other materials provided with the distribution;
254484Sbinkertn@umich.edu# neither the name of the copyright holders nor the names of its
264484Sbinkertn@umich.edu# contributors may be used to endorse or promote products derived from
274484Sbinkertn@umich.edu# this software without specific prior written permission.
284484Sbinkertn@umich.edu#
294484Sbinkertn@umich.edu# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
304484Sbinkertn@umich.edu# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
314494Ssaidi@eecs.umich.edu# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
324484Sbinkertn@umich.edu# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
336121Snate@binkert.org# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
344484Sbinkertn@umich.edu# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
354484Sbinkertn@umich.edu# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
364484Sbinkertn@umich.edu# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
374484Sbinkertn@umich.edu# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
384781Snate@binkert.org# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
394484Sbinkertn@umich.edu# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
404484Sbinkertn@umich.edu#
414484Sbinkertn@umich.edu# Authors: Steve Reinhardt
424484Sbinkertn@umich.edu#          Kevin Lim
434484Sbinkertn@umich.edu#          Andreas Sandberg
444484Sbinkertn@umich.edu
454484Sbinkertn@umich.edufrom SCons.Script.SConscript import SConsEnvironment
464484Sbinkertn@umich.eduimport os
474484Sbinkertn@umich.eduimport pickle
484484Sbinkertn@umich.eduimport sys
494484Sbinkertn@umich.edu
504484Sbinkertn@umich.edusys.path.insert(0, Dir(".").srcnode().abspath)
514484Sbinkertn@umich.eduimport testing.tests as tests
524484Sbinkertn@umich.eduimport testing.results as results
534484Sbinkertn@umich.edufrom gem5_scons.util import get_termcap
544484Sbinkertn@umich.edu
554484Sbinkertn@umich.eduImport('env')
564484Sbinkertn@umich.edu
574484Sbinkertn@umich.edu# get the termcap from the environment
584484Sbinkertn@umich.edutermcap = get_termcap()
594484Sbinkertn@umich.edu
604484Sbinkertn@umich.edu# Dict that accumulates lists of tests by category (quick, medium, long)
614484Sbinkertn@umich.eduenv.Tests = {}
624484Sbinkertn@umich.edugpu_isa = env['TARGET_GPU_ISA'] if env['BUILD_GPU'] else None
634484Sbinkertn@umich.edufor cat in tests.all_categories:
644484Sbinkertn@umich.edu    env.Tests[cat] = tuple(
654484Sbinkertn@umich.edu        tests.get_tests(env["TARGET_ISA"],
664484Sbinkertn@umich.edu                        categories=(cat, ),
674484Sbinkertn@umich.edu                        ruby_protocol=env["PROTOCOL"],
684484Sbinkertn@umich.edu                        gpu_isa=gpu_isa))
694484Sbinkertn@umich.edu
704484Sbinkertn@umich.edudef color_message(color, msg):
714484Sbinkertn@umich.edu    return color + msg + termcap.Normal
724484Sbinkertn@umich.edu
734484Sbinkertn@umich.edudef run_test(target, source, env):
744484Sbinkertn@umich.edu    """Run a test and produce results as a pickle file.
754484Sbinkertn@umich.edu
764484Sbinkertn@umich.edu    Targets are as follows:
774484Sbinkertn@umich.edu    target[0] : Pickle file
784484Sbinkertn@umich.edu
794484Sbinkertn@umich.edu    Sources are:
804484Sbinkertn@umich.edu    source[0] : gem5 binary
814484Sbinkertn@umich.edu    source[1] : tests/run.py script
824484Sbinkertn@umich.edu    source[2:] : reference files
834484Sbinkertn@umich.edu
844484Sbinkertn@umich.edu    """
854484Sbinkertn@umich.edu    tgt_dir = os.path.dirname(str(target[0]))
864484Sbinkertn@umich.edu    config = tests.ClassicConfig(*tgt_dir.split('/')[-6:])
874484Sbinkertn@umich.edu    test = tests.ClassicTest(source[0].abspath, tgt_dir, config,
884484Sbinkertn@umich.edu                             timeout=5*60*60,
894484Sbinkertn@umich.edu                             skip_diff_out=True)
906121Snate@binkert.org
916121Snate@binkert.org    for ref in test.ref_files():
926121Snate@binkert.org        out_file = os.path.join(tgt_dir, ref)
935765Snate@binkert.org        if os.path.exists(out_file):
945765Snate@binkert.org            env.Execute(Delete(out_file))
955765Snate@binkert.org
965397Ssaidi@eecs.umich.edu    with open(target[0].abspath, "wb") as fout:
975274Ssaidi@eecs.umich.edu        formatter = results.Pickle(fout=fout)
984494Ssaidi@eecs.umich.edu        formatter.dump_suites([ test.run() ])
994504Ssaidi@eecs.umich.edu
1004494Ssaidi@eecs.umich.edu    return 0
1014494Ssaidi@eecs.umich.edu
1024496Ssaidi@eecs.umich.edudef run_test_string(target, source, env):
1034504Ssaidi@eecs.umich.edu    return env.subst("Running test in ${TARGETS[0].dir}.",
1044504Ssaidi@eecs.umich.edu                     target=target, source=source)
1054500Sbinkertn@umich.edu
1064500Sbinkertn@umich.edutestAction = env.Action(run_test, run_test_string)
1074496Ssaidi@eecs.umich.edu
1084496Ssaidi@eecs.umich.edudef print_test(target, source, env):
1094487Sstever@eecs.umich.edu    """Run a test and produce results as a pickle file.
1104487Sstever@eecs.umich.edu
1114484Sbinkertn@umich.edu    Targets are as follows:
1124484Sbinkertn@umich.edu    target[*] : Dummy targets
1134484Sbinkertn@umich.edu
1144484Sbinkertn@umich.edu    Sources are:
1154484Sbinkertn@umich.edu    source[0] : Pickle file
1164484Sbinkertn@umich.edu
1175601Snate@binkert.org    """
1185601Snate@binkert.org    with open(source[0].abspath, "rb") as fin:
1195601Snate@binkert.org        result = pickle.load(fin)
1205601Snate@binkert.org
1214484Sbinkertn@umich.edu    assert len(result) == 1
1226121Snate@binkert.org    result = result[0]
1236121Snate@binkert.org
1246121Snate@binkert.org    formatter = None
1254494Ssaidi@eecs.umich.edu    if result.skipped():
126        status = color_message(termcap.Cyan, "skipped.")
127    elif result.changed():
128        status = color_message(termcap.Yellow, "CHANGED!")
129        formatter = results.Text()
130    elif result:
131        status = color_message(termcap.Green, "passed.")
132    else:
133        status = color_message(termcap.Red, "FAILED!")
134        formatter = results.Text()
135
136    if formatter:
137        formatter.dump_suites([result])
138
139    print "***** %s: %s" % (source[0].dir, status)
140    return 0
141
142printAction = env.Action(print_test, strfunction=None)
143
144def update_test(target, source, env):
145    """Update test reference data
146
147    Targets are as follows:
148    target[0] : Dummy file
149
150    Sources are:
151    source[0] : Pickle file
152    """
153
154    src_dir = os.path.dirname(str(source[0]))
155    config = tests.ClassicConfig(*src_dir.split('/')[-6:])
156    test = tests.ClassicTest(source[0].abspath, src_dir, config)
157    ref_dir = test.ref_dir
158
159    with open(source[0].abspath, "rb") as fin:
160        result = pickle.load(fin)
161
162    assert len(result) == 1
163    result = result[0]
164
165    if result.skipped():
166        print "*** %s: %s: Test skipped, not updating." % (
167            source[0].dir, color_message(termcap.Yellow, "WARNING"), )
168        return 0
169    elif result:
170        print "*** %s: %s: Test successful, not updating." % (
171            source[0].dir, color_message(termcap.Green, "skipped"), )
172        return 0
173    elif result.failed_run():
174        print "*** %s: %s: Test failed, not updating." % (
175            source[0].dir, color_message(termcap.Red, "ERROR"), )
176        return 1
177
178    print "** Updating %s" % (test, )
179    test.update_ref()
180
181    return 0
182
183def update_test_string(target, source, env):
184    return env.subst("Updating ${SOURCES[0].dir}",
185                     target=target, source=source)
186
187updateAction = env.Action(update_test, update_test_string)
188
189def test_builder(test_tuple):
190    """Define a test."""
191
192    out_dir = "/".join(test_tuple)
193    binary = env.M5Binary.abspath
194    test = tests.ClassicTest(binary, out_dir, test_tuple)
195
196    def tgt(name):
197        return os.path.join(out_dir, name)
198
199    def ref(name):
200        return os.path.join(test.ref_dir, name)
201
202    pickle_file = tgt("status.pickle")
203    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