SConscript revision 12305
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 5312246Sgabeblack@google.comfrom gem5_scons.util import get_termcap 542929Sktlim@umich.edu 552929Sktlim@umich.eduImport('env') 562929Sktlim@umich.edu 578947Sandreas.hansson@arm.com# get the termcap from the environment 5812246Sgabeblack@google.comtermcap = get_termcap() 598947Sandreas.hansson@arm.com 602929Sktlim@umich.edu# Dict that accumulates lists of tests by category (quick, medium, long) 612929Sktlim@umich.eduenv.Tests = {} 6211504Sandreas.sandberg@arm.comgpu_isa = env['TARGET_GPU_ISA'] if env['BUILD_GPU'] else None 6311504Sandreas.sandberg@arm.comfor cat in tests.all_categories: 6411504Sandreas.sandberg@arm.com env.Tests[cat] = tuple( 6511504Sandreas.sandberg@arm.com tests.get_tests(env["TARGET_ISA"], 6611504Sandreas.sandberg@arm.com categories=(cat, ), 6711504Sandreas.sandberg@arm.com ruby_protocol=env["PROTOCOL"], 6811504Sandreas.sandberg@arm.com gpu_isa=gpu_isa)) 692929Sktlim@umich.edu 7011504Sandreas.sandberg@arm.comdef color_message(color, msg): 7111504Sandreas.sandberg@arm.com return color + msg + termcap.Normal 726007Ssteve.reinhardt@amd.com 736007Ssteve.reinhardt@amd.comdef run_test(target, source, env): 7411504Sandreas.sandberg@arm.com """Run a test and produce results as a pickle file. 752929Sktlim@umich.edu 762929Sktlim@umich.edu Targets are as follows: 7711504Sandreas.sandberg@arm.com target[0] : Pickle file 786007Ssteve.reinhardt@amd.com 796007Ssteve.reinhardt@amd.com Sources are: 809781Sandreas.hansson@arm.com source[0] : gem5 binary 816007Ssteve.reinhardt@amd.com source[1] : tests/run.py script 8211504Sandreas.sandberg@arm.com source[2:] : reference files 832929Sktlim@umich.edu 842929Sktlim@umich.edu """ 8511504Sandreas.sandberg@arm.com tgt_dir = os.path.dirname(str(target[0])) 8611504Sandreas.sandberg@arm.com config = tests.ClassicConfig(*tgt_dir.split('/')[-6:]) 8711504Sandreas.sandberg@arm.com test = tests.ClassicTest(source[0].abspath, tgt_dir, config, 8811504Sandreas.sandberg@arm.com timeout=5*60*60, 8911504Sandreas.sandberg@arm.com skip_diff_out=True) 906007Ssteve.reinhardt@amd.com 9111504Sandreas.sandberg@arm.com for ref in test.ref_files(): 9211504Sandreas.sandberg@arm.com out_file = os.path.join(tgt_dir, ref) 9311504Sandreas.sandberg@arm.com if os.path.exists(out_file): 9411504Sandreas.sandberg@arm.com env.Execute(Delete(out_file)) 956007Ssteve.reinhardt@amd.com 9611504Sandreas.sandberg@arm.com with open(target[0].abspath, "wb") as fout: 9711504Sandreas.sandberg@arm.com formatter = results.Pickle(fout=fout) 9811504Sandreas.sandberg@arm.com formatter.dump_suites([ test.run() ]) 996007Ssteve.reinhardt@amd.com 1002929Sktlim@umich.edu return 0 1012929Sktlim@umich.edu 1026007Ssteve.reinhardt@amd.comdef run_test_string(target, source, env): 1036007Ssteve.reinhardt@amd.com return env.subst("Running test in ${TARGETS[0].dir}.", 1042929Sktlim@umich.edu target=target, source=source) 1052929Sktlim@umich.edu 1066007Ssteve.reinhardt@amd.comtestAction = env.Action(run_test, run_test_string) 1072929Sktlim@umich.edu 1082929Sktlim@umich.edudef print_test(target, source, env): 10911504Sandreas.sandberg@arm.com """Run a test and produce results as a pickle file. 1108947Sandreas.hansson@arm.com 11111504Sandreas.sandberg@arm.com Targets are as follows: 11211504Sandreas.sandberg@arm.com target[*] : Dummy targets 1138947Sandreas.hansson@arm.com 11411504Sandreas.sandberg@arm.com Sources are: 11511504Sandreas.sandberg@arm.com source[0] : Pickle file 1168947Sandreas.hansson@arm.com 11711504Sandreas.sandberg@arm.com """ 11811504Sandreas.sandberg@arm.com with open(source[0].abspath, "rb") as fin: 11911504Sandreas.sandberg@arm.com result = pickle.load(fin) 1208947Sandreas.hansson@arm.com 12111504Sandreas.sandberg@arm.com assert len(result) == 1 12211504Sandreas.sandberg@arm.com result = result[0] 12311504Sandreas.sandberg@arm.com 12411504Sandreas.sandberg@arm.com formatter = None 12511542Sandreas.sandberg@arm.com if result.skipped(): 12611542Sandreas.sandberg@arm.com status = color_message(termcap.Cyan, "skipped.") 12711542Sandreas.sandberg@arm.com elif result.changed(): 12811542Sandreas.sandberg@arm.com status = color_message(termcap.Yellow, "CHANGED!") 12911504Sandreas.sandberg@arm.com formatter = results.Text() 13011504Sandreas.sandberg@arm.com elif result: 13111504Sandreas.sandberg@arm.com status = color_message(termcap.Green, "passed.") 13211504Sandreas.sandberg@arm.com else: 13311542Sandreas.sandberg@arm.com status = color_message(termcap.Red, "FAILED!") 13411504Sandreas.sandberg@arm.com formatter = results.Text() 13511504Sandreas.sandberg@arm.com 13611504Sandreas.sandberg@arm.com if formatter: 13711504Sandreas.sandberg@arm.com formatter.dump_suites([result]) 13811504Sandreas.sandberg@arm.com 13911504Sandreas.sandberg@arm.com print "***** %s: %s" % (source[0].dir, status) 1402929Sktlim@umich.edu return 0 1412929Sktlim@umich.edu 14211504Sandreas.sandberg@arm.comprintAction = env.Action(print_test, strfunction=None) 1434937Sstever@gmail.com 1442929Sktlim@umich.edudef update_test(target, source, env): 14511504Sandreas.sandberg@arm.com """Update test reference data 1462929Sktlim@umich.edu 14711504Sandreas.sandberg@arm.com Targets are as follows: 14811504Sandreas.sandberg@arm.com target[0] : Dummy file 1492929Sktlim@umich.edu 15011504Sandreas.sandberg@arm.com Sources are: 15111504Sandreas.sandberg@arm.com source[0] : Pickle file 1522929Sktlim@umich.edu """ 15311504Sandreas.sandberg@arm.com 15411504Sandreas.sandberg@arm.com src_dir = os.path.dirname(str(source[0])) 15511504Sandreas.sandberg@arm.com config = tests.ClassicConfig(*src_dir.split('/')[-6:]) 15611504Sandreas.sandberg@arm.com test = tests.ClassicTest(source[0].abspath, src_dir, config) 15711504Sandreas.sandberg@arm.com ref_dir = test.ref_dir 15811504Sandreas.sandberg@arm.com 15911504Sandreas.sandberg@arm.com with open(source[0].abspath, "rb") as fin: 16011504Sandreas.sandberg@arm.com result = pickle.load(fin) 16111504Sandreas.sandberg@arm.com 16211504Sandreas.sandberg@arm.com assert len(result) == 1 16311504Sandreas.sandberg@arm.com result = result[0] 16411504Sandreas.sandberg@arm.com 16511542Sandreas.sandberg@arm.com if result.skipped(): 16611504Sandreas.sandberg@arm.com print "*** %s: %s: Test skipped, not updating." % ( 16711504Sandreas.sandberg@arm.com source[0].dir, color_message(termcap.Yellow, "WARNING"), ) 16811504Sandreas.sandberg@arm.com return 0 16911504Sandreas.sandberg@arm.com elif result: 17011504Sandreas.sandberg@arm.com print "*** %s: %s: Test successful, not updating." % ( 17111504Sandreas.sandberg@arm.com source[0].dir, color_message(termcap.Green, "skipped"), ) 17211504Sandreas.sandberg@arm.com return 0 17311542Sandreas.sandberg@arm.com elif result.failed_run(): 17411504Sandreas.sandberg@arm.com print "*** %s: %s: Test failed, not updating." % ( 17511504Sandreas.sandberg@arm.com source[0].dir, color_message(termcap.Red, "ERROR"), ) 17611504Sandreas.sandberg@arm.com return 1 17711504Sandreas.sandberg@arm.com 17811504Sandreas.sandberg@arm.com print "** Updating %s" % (test, ) 17911504Sandreas.sandberg@arm.com test.update_ref() 18011504Sandreas.sandberg@arm.com 1812929Sktlim@umich.edu return 0 1822929Sktlim@umich.edu 1832929Sktlim@umich.edudef update_test_string(target, source, env): 18411504Sandreas.sandberg@arm.com return env.subst("Updating ${SOURCES[0].dir}", 1852929Sktlim@umich.edu target=target, source=source) 1862929Sktlim@umich.edu 1872929Sktlim@umich.eduupdateAction = env.Action(update_test, update_test_string) 1882929Sktlim@umich.edu 18911504Sandreas.sandberg@arm.comdef test_builder(test_tuple): 1902997Sstever@eecs.umich.edu """Define a test.""" 1912929Sktlim@umich.edu 19211504Sandreas.sandberg@arm.com out_dir = "/".join(test_tuple) 19311504Sandreas.sandberg@arm.com binary = env.M5Binary.abspath 19411504Sandreas.sandberg@arm.com test = tests.ClassicTest(binary, out_dir, test_tuple) 1952929Sktlim@umich.edu 19611504Sandreas.sandberg@arm.com def tgt(name): 19711504Sandreas.sandberg@arm.com return os.path.join(out_dir, name) 1982929Sktlim@umich.edu 19911504Sandreas.sandberg@arm.com def ref(name): 20011504Sandreas.sandberg@arm.com return os.path.join(test.ref_dir, name) 2012997Sstever@eecs.umich.edu 20211504Sandreas.sandberg@arm.com pickle_file = tgt("status.pickle") 20311504Sandreas.sandberg@arm.com targets = [ 20411504Sandreas.sandberg@arm.com pickle_file, 20511504Sandreas.sandberg@arm.com ] 2062997Sstever@eecs.umich.edu 20711504Sandreas.sandberg@arm.com sources = [ 20811504Sandreas.sandberg@arm.com env.M5Binary, 20911504Sandreas.sandberg@arm.com "run.py", 21011504Sandreas.sandberg@arm.com ] + [ ref(f) for f in test.ref_files() ] 21111504Sandreas.sandberg@arm.com 21211504Sandreas.sandberg@arm.com env.Command(targets, sources, testAction) 2132929Sktlim@umich.edu 2142997Sstever@eecs.umich.edu # phony target to echo status 2158120Sgblack@eecs.umich.edu if GetOption('update_ref'): 21611504Sandreas.sandberg@arm.com p = env.Command(tgt("_update"), [pickle_file], updateAction) 2172997Sstever@eecs.umich.edu else: 21811504Sandreas.sandberg@arm.com p = env.Command(tgt("_print"), [pickle_file], printAction) 2192929Sktlim@umich.edu 2202997Sstever@eecs.umich.edu env.AlwaysBuild(p) 2212929Sktlim@umich.edu 22211504Sandreas.sandberg@arm.comdef list_tests(target, source, env): 22311504Sandreas.sandberg@arm.com """Create a list of tests 2242929Sktlim@umich.edu 22511504Sandreas.sandberg@arm.com Targets are as follows: 22611504Sandreas.sandberg@arm.com target[0] : List file (e.g., tests/opt/all.list, tests/opt/quick.list) 2273691Shsul@eecs.umich.edu 22811504Sandreas.sandberg@arm.com Sources are: - 2293005Sstever@eecs.umich.edu 23011504Sandreas.sandberg@arm.com """ 23111105Spower.jg@gmail.com 23211504Sandreas.sandberg@arm.com tgt_name = os.path.basename(str(target[0])) 23311504Sandreas.sandberg@arm.com base, ext = os.path.splitext(tgt_name) 23411504Sandreas.sandberg@arm.com categories = tests.all_categories if base == "all" else (base, ) 2356166Ssteve.reinhardt@amd.com 23611504Sandreas.sandberg@arm.com with open(target[0].abspath, "w") as fout: 23711504Sandreas.sandberg@arm.com for cat in categories: 23811504Sandreas.sandberg@arm.com for test in env.Tests[cat]: 23911504Sandreas.sandberg@arm.com print >> fout,"/".join(test) 24011504Sandreas.sandberg@arm.com 24111504Sandreas.sandberg@arm.com return 0 24211504Sandreas.sandberg@arm.com 24311504Sandreas.sandberg@arm.comtestListAction = env.Action(list_tests, strfunction=None) 24411504Sandreas.sandberg@arm.com 24511504Sandreas.sandberg@arm.comenv.Command("all.list", tuple(), testListAction) 24611504Sandreas.sandberg@arm.comfor cat, test_list in env.Tests.items(): 24711504Sandreas.sandberg@arm.com env.Command("%s.list" % cat, tuple(), testListAction) 24811504Sandreas.sandberg@arm.com for test in test_list: 24911504Sandreas.sandberg@arm.com test_builder(test) 250