SConscript revision 13656:2727dfddacf3
12929Sktlim@umich.edu# Copyright 2018 Google, Inc. 22929Sktlim@umich.edu# 32932Sktlim@umich.edu# Redistribution and use in source and binary forms, with or without 42929Sktlim@umich.edu# modification, are permitted provided that the following conditions are 52929Sktlim@umich.edu# met: redistributions of source code must retain the above copyright 62929Sktlim@umich.edu# notice, this list of conditions and the following disclaimer; 72929Sktlim@umich.edu# redistributions in binary form must reproduce the above copyright 82929Sktlim@umich.edu# notice, this list of conditions and the following disclaimer in the 92929Sktlim@umich.edu# documentation and/or other materials provided with the distribution; 102929Sktlim@umich.edu# neither the name of the copyright holders nor the names of its 112929Sktlim@umich.edu# contributors may be used to endorse or promote products derived from 122929Sktlim@umich.edu# this software without specific prior written permission. 132929Sktlim@umich.edu# 142929Sktlim@umich.edu# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 152929Sktlim@umich.edu# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 162929Sktlim@umich.edu# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 172929Sktlim@umich.edu# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 182929Sktlim@umich.edu# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 192929Sktlim@umich.edu# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 202929Sktlim@umich.edu# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 212929Sktlim@umich.edu# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 222929Sktlim@umich.edu# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 232929Sktlim@umich.edu# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 242929Sktlim@umich.edu# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 252929Sktlim@umich.edu# 262929Sktlim@umich.edu# Authors: Gabe Black 272929Sktlim@umich.edu 282932Sktlim@umich.edufrom __future__ import print_function 292932Sktlim@umich.edu 302932Sktlim@umich.eduImport('*') 312929Sktlim@umich.edu 326007Ssteve.reinhardt@amd.comif env['USE_SYSTEMC']: 337735SAli.Saidi@ARM.com 342929Sktlim@umich.edu from gem5_scons import Transform 352929Sktlim@umich.edu 362929Sktlim@umich.edu import os.path 372929Sktlim@umich.edu import json 382929Sktlim@umich.edu 392929Sktlim@umich.edu src = str(Dir('.').srcdir) 402929Sktlim@umich.edu 418947Sandreas.hansson@arm.com class SystemCTest(object): 428947Sandreas.hansson@arm.com def __init__(self, dirname, name): 438947Sandreas.hansson@arm.com self.name = name 442929Sktlim@umich.edu self.reldir = os.path.relpath(dirname, src) 452929Sktlim@umich.edu self.target = os.path.join(self.reldir, name) 462929Sktlim@umich.edu self.sources = [] 472929Sktlim@umich.edu self.deps = [] 482929Sktlim@umich.edu 492929Sktlim@umich.edu self.compile_only = False 506007Ssteve.reinhardt@amd.com 516007Ssteve.reinhardt@amd.com def add_source(self, source): 526007Ssteve.reinhardt@amd.com self.sources.append(os.path.join(self.reldir, source)) 536007Ssteve.reinhardt@amd.com 546007Ssteve.reinhardt@amd.com def add_sources(self, sources): 556007Ssteve.reinhardt@amd.com for source in sources: 566007Ssteve.reinhardt@amd.com self.sources.append(os.path.join(self.reldir, '..', source)) 576007Ssteve.reinhardt@amd.com 586007Ssteve.reinhardt@amd.com def properties(self): 596007Ssteve.reinhardt@amd.com return { 606007Ssteve.reinhardt@amd.com 'name' : self.name, 616007Ssteve.reinhardt@amd.com 'path' : self.reldir, 626007Ssteve.reinhardt@amd.com 'compile_only' : self.compile_only, 636007Ssteve.reinhardt@amd.com 'deps' : self.deps 646007Ssteve.reinhardt@amd.com } 656007Ssteve.reinhardt@amd.com 666007Ssteve.reinhardt@amd.com test_dir = Dir('.') 676007Ssteve.reinhardt@amd.com class SystemCTestBin(Executable): 686007Ssteve.reinhardt@amd.com def __init__(self, test): 696007Ssteve.reinhardt@amd.com super(SystemCTestBin, self).__init__(test.target, *test.sources) 706007Ssteve.reinhardt@amd.com self.reldir = test.reldir 716007Ssteve.reinhardt@amd.com self.test_deps = test.deps 726007Ssteve.reinhardt@amd.com 736007Ssteve.reinhardt@amd.com @classmethod 746007Ssteve.reinhardt@amd.com def declare_all(cls, env): 756007Ssteve.reinhardt@amd.com env = env.Clone() 766007Ssteve.reinhardt@amd.com 776007Ssteve.reinhardt@amd.com # Turn off extra warnings and Werror for the tests. 786007Ssteve.reinhardt@amd.com to_remove = ['-Wall', '-Wundef', '-Wextra', '-Werror'] 792929Sktlim@umich.edu env['CCFLAGS'] = \ 802929Sktlim@umich.edu filter(lambda f: f not in to_remove, env['CCFLAGS']) 812929Sktlim@umich.edu 826007Ssteve.reinhardt@amd.com env.Append(CPPPATH=test_dir.Dir('include')) 836007Ssteve.reinhardt@amd.com 846007Ssteve.reinhardt@amd.com shared_lib_path = env['SHARED_LIB'][0].abspath 856007Ssteve.reinhardt@amd.com sl_dir, sl_base = os.path.split(shared_lib_path) 866007Ssteve.reinhardt@amd.com env.Append(LIBPATH=[sl_dir], LIBS=[sl_base]) 876007Ssteve.reinhardt@amd.com 882929Sktlim@umich.edu super(SystemCTestBin, cls).declare_all(env) 892929Sktlim@umich.edu 902929Sktlim@umich.edu def declare(self, env): 912929Sktlim@umich.edu env = env.Clone() 922929Sktlim@umich.edu sources = list(self.sources) 936011Ssteve.reinhardt@amd.com for f in self.filters: 946007Ssteve.reinhardt@amd.com sources += Source.all.apply_filter(f) 956007Ssteve.reinhardt@amd.com objs = self.srcs_to_objs(env, sources) 966007Ssteve.reinhardt@amd.com objs = objs + env['MAIN_OBJS'] 976007Ssteve.reinhardt@amd.com relpath = os.path.relpath( 986007Ssteve.reinhardt@amd.com env['SHARED_LIB'][0].dir.abspath, 996007Ssteve.reinhardt@amd.com self.path(env).dir.abspath) 1006007Ssteve.reinhardt@amd.com env.Append(LINKFLAGS=Split('-z origin')) 1016007Ssteve.reinhardt@amd.com env.Append(RPATH=[ 1026007Ssteve.reinhardt@amd.com env.Literal(os.path.join('\\$$ORIGIN', relpath))]) 1036007Ssteve.reinhardt@amd.com test_bin = super(SystemCTestBin, self).declare(env, objs) 1046007Ssteve.reinhardt@amd.com test_dir = self.dir.Dir(self.reldir) 1056007Ssteve.reinhardt@amd.com for dep in self.test_deps: 1066007Ssteve.reinhardt@amd.com env.Depends(test_bin, test_dir.File(dep)) 1076007Ssteve.reinhardt@amd.com return test_bin 1087735SAli.Saidi@ARM.com 1096011Ssteve.reinhardt@amd.com tests = [] 1106007Ssteve.reinhardt@amd.com def new_test(dirname, name): 1116007Ssteve.reinhardt@amd.com test = SystemCTest(dirname, name) 1126007Ssteve.reinhardt@amd.com tests.append(test) 1136007Ssteve.reinhardt@amd.com return test 1147735SAli.Saidi@ARM.com 1157735SAli.Saidi@ARM.com 1167735SAli.Saidi@ARM.com def scan_dir_for_tests(subdir): 1177735SAli.Saidi@ARM.com def visitor(arg, dirname, names): 1187735SAli.Saidi@ARM.com # If there's a 'DONTRUN' file in this directory, skip it and any 1197735SAli.Saidi@ARM.com # child directories. 1207735SAli.Saidi@ARM.com if 'DONTRUN' in names: 1217735SAli.Saidi@ARM.com del names[:] 1227735SAli.Saidi@ARM.com return 1237735SAli.Saidi@ARM.com 1247735SAli.Saidi@ARM.com endswith = lambda sfx: filter(lambda n: n.endswith(sfx), names) 1257735SAli.Saidi@ARM.com 1267735SAli.Saidi@ARM.com cpps = endswith('.cpp') 1277735SAli.Saidi@ARM.com if not cpps: 1286007Ssteve.reinhardt@amd.com return 1298599Ssteve.reinhardt@amd.com 1308599Ssteve.reinhardt@amd.com def get_entries(fname): 1318599Ssteve.reinhardt@amd.com with open(os.path.join(dirname, fname)) as content: 1326007Ssteve.reinhardt@amd.com lines = content.readlines 1336011Ssteve.reinhardt@amd.com # Get rid of leading and trailing whitespace. 1346007Ssteve.reinhardt@amd.com lines = map(lambda x: x.strip(), content.readlines()) 1356007Ssteve.reinhardt@amd.com # Get rid of blank lines. 1366007Ssteve.reinhardt@amd.com lines = filter(lambda x: x, lines) 1376007Ssteve.reinhardt@amd.com return lines 1386007Ssteve.reinhardt@amd.com 1396007Ssteve.reinhardt@amd.com # If there's only one source file, then that files name is the test 1406011Ssteve.reinhardt@amd.com # name, and it's the source for that test. 1416007Ssteve.reinhardt@amd.com if len(cpps) == 1: 1426007Ssteve.reinhardt@amd.com cpp = cpps[0] 1436007Ssteve.reinhardt@amd.com 1446007Ssteve.reinhardt@amd.com test = new_test(dirname, os.path.splitext(cpp)[0]) 1456007Ssteve.reinhardt@amd.com test.add_source(cpp) 1466008Ssteve.reinhardt@amd.com 1476007Ssteve.reinhardt@amd.com # Otherwise, expect there to be a file that ends in .f. That files 1486008Ssteve.reinhardt@amd.com # name is the test name, and it will list the source files with 1496008Ssteve.reinhardt@amd.com # one preceeding path component. 1506008Ssteve.reinhardt@amd.com else: 1516008Ssteve.reinhardt@amd.com fs = endswith('.f') 1526008Ssteve.reinhardt@amd.com if len(fs) != 1: 1536008Ssteve.reinhardt@amd.com print("In %s, expected 1 *.f file, but found %d.", 1546008Ssteve.reinhardt@amd.com dirname, len(fs)) 1556007Ssteve.reinhardt@amd.com for f in fs: 1566007Ssteve.reinhardt@amd.com print(os.path.join(dirname, f)) 1576007Ssteve.reinhardt@amd.com return 1586007Ssteve.reinhardt@amd.com f = fs[0] 1596007Ssteve.reinhardt@amd.com 1602929Sktlim@umich.edu test = new_test(dirname, os.path.splitext(f)[0]) 1612929Sktlim@umich.edu # Add all the sources to this test. 1622929Sktlim@umich.edu test.add_sources(get_entries(f)) 1632929Sktlim@umich.edu 1646007Ssteve.reinhardt@amd.com if 'COMPILE' in names: 1656007Ssteve.reinhardt@amd.com test.compile_only = True 1662929Sktlim@umich.edu 1672929Sktlim@umich.edu if 'DEPS' in names: 1682929Sktlim@umich.edu test.deps = get_entries('DEPS') 1692929Sktlim@umich.edu 1706007Ssteve.reinhardt@amd.com subdir_src = Dir('.').srcdir.Dir(subdir) 1716007Ssteve.reinhardt@amd.com os.path.walk(str(subdir_src), visitor, None) 1722929Sktlim@umich.edu 1732929Sktlim@umich.edu scan_dir_for_tests('systemc') 1746007Ssteve.reinhardt@amd.com scan_dir_for_tests('tlm') 1752929Sktlim@umich.edu 1762929Sktlim@umich.edu 1778947Sandreas.hansson@arm.com def build_tests_json(target, source, env): 1788947Sandreas.hansson@arm.com data = { test.target : test.properties() for test in tests } 1798947Sandreas.hansson@arm.com with open(str(target[0]), "w") as tests_json: 1808947Sandreas.hansson@arm.com json.dump(data, tests_json) 1818947Sandreas.hansson@arm.com 1828947Sandreas.hansson@arm.com AlwaysBuild(env.Command(File('tests.json'), None, 1838947Sandreas.hansson@arm.com MakeAction(build_tests_json, Transform("TESTJSON")))) 1848947Sandreas.hansson@arm.com 1858947Sandreas.hansson@arm.com 1868947Sandreas.hansson@arm.com for test in tests: 1878947Sandreas.hansson@arm.com SystemCTestBin(test) 1888947Sandreas.hansson@arm.com