SConscript revision 13655:585ffa1a18d3
14202Sbinkertn@umich.edu# Copyright 2018 Google, Inc. 24202Sbinkertn@umich.edu# 34202Sbinkertn@umich.edu# Redistribution and use in source and binary forms, with or without 44202Sbinkertn@umich.edu# modification, are permitted provided that the following conditions are 54202Sbinkertn@umich.edu# met: redistributions of source code must retain the above copyright 64202Sbinkertn@umich.edu# notice, this list of conditions and the following disclaimer; 74202Sbinkertn@umich.edu# redistributions in binary form must reproduce the above copyright 84202Sbinkertn@umich.edu# notice, this list of conditions and the following disclaimer in the 94202Sbinkertn@umich.edu# documentation and/or other materials provided with the distribution; 104202Sbinkertn@umich.edu# neither the name of the copyright holders nor the names of its 114202Sbinkertn@umich.edu# contributors may be used to endorse or promote products derived from 124202Sbinkertn@umich.edu# this software without specific prior written permission. 134202Sbinkertn@umich.edu# 144202Sbinkertn@umich.edu# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 154202Sbinkertn@umich.edu# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 164202Sbinkertn@umich.edu# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 174202Sbinkertn@umich.edu# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 184202Sbinkertn@umich.edu# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 194202Sbinkertn@umich.edu# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 204202Sbinkertn@umich.edu# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 214202Sbinkertn@umich.edu# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 224202Sbinkertn@umich.edu# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 234202Sbinkertn@umich.edu# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 244202Sbinkertn@umich.edu# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 254202Sbinkertn@umich.edu# 264202Sbinkertn@umich.edu# Authors: Gabe Black 274202Sbinkertn@umich.edu 284202Sbinkertn@umich.edufrom __future__ import print_function 294202Sbinkertn@umich.edu 304202Sbinkertn@umich.eduImport('*') 314202Sbinkertn@umich.edu 324202Sbinkertn@umich.eduif env['USE_SYSTEMC']: 335628Sgblack@eecs.umich.edu 349157Sandreas.hansson@arm.com from gem5_scons import Transform 3510259SAndrew.Bardsley@arm.com 364486Sbinkertn@umich.edu import os.path 379793Sakash.bagdia@arm.com import json 389827Sakash.bagdia@arm.com 399850Sandreas.hansson@arm.com src = str(Dir('.').srcdir) 4010249Sstephan.diestelhorst@arm.com 414486Sbinkertn@umich.edu class SystemCTest(object): 428774Sgblack@eecs.umich.edu def __init__(self, dirname, name): 434202Sbinkertn@umich.edu self.name = name 444202Sbinkertn@umich.edu self.reldir = os.path.relpath(dirname, src) 454202Sbinkertn@umich.edu self.target = os.path.join(self.reldir, name) 464202Sbinkertn@umich.edu self.sources = [] 479983Sstever@gmail.com self.deps = [] 485522Snate@binkert.org 498233Snate@binkert.org self.compile_only = False 504202Sbinkertn@umich.edu 514202Sbinkertn@umich.edu def add_source(self, source): 529342SAndreas.Sandberg@arm.com self.sources.append(os.path.join(self.reldir, source)) 534202Sbinkertn@umich.edu 544202Sbinkertn@umich.edu def add_sources(self, sources): 5510259SAndrew.Bardsley@arm.com for source in sources: 564202Sbinkertn@umich.edu self.sources.append(os.path.join(self.reldir, '..', source)) 574202Sbinkertn@umich.edu 589793Sakash.bagdia@arm.com def properties(self): 599827Sakash.bagdia@arm.com return { 609850Sandreas.hansson@arm.com 'name' : self.name, 6110249Sstephan.diestelhorst@arm.com 'path' : self.reldir, 627768SAli.Saidi@ARM.com 'compile_only' : self.compile_only, 639850Sandreas.hansson@arm.com 'deps' : self.deps 649850Sandreas.hansson@arm.com } 658766Sgblack@eecs.umich.edu 667768SAli.Saidi@ARM.com test_dir = Dir('.') 678766Sgblack@eecs.umich.edu class SystemCTestBin(Executable): 687768SAli.Saidi@ARM.com def __init__(self, test): 699850Sandreas.hansson@arm.com super(SystemCTestBin, self).__init__(test.target, *test.sources) 705016Sgblack@eecs.umich.edu self.reldir = test.reldir 714486Sbinkertn@umich.edu self.test_deps = test.deps 728335Snate@binkert.org 738335Snate@binkert.org @classmethod 749152Satgutier@umich.edu def declare_all(cls, env): 758335Snate@binkert.org env = env.Clone() 768335Snate@binkert.org 778335Snate@binkert.org # Turn off extra warnings and Werror for the tests. 788335Snate@binkert.org to_remove = ['-Wall', '-Wundef', '-Wextra', '-Werror'] 798335Snate@binkert.org env['CCFLAGS'] = \ 808335Snate@binkert.org filter(lambda f: f not in to_remove, env['CCFLAGS']) 818335Snate@binkert.org 829733Sandreas@sandberg.pp.se env.Append(CPPPATH=test_dir.Dir('include')) 838335Snate@binkert.org 848335Snate@binkert.org shared_lib_path = env['SHARED_LIB'][0].abspath 858335Snate@binkert.org sl_dir, sl_base = os.path.split(shared_lib_path) 868335Snate@binkert.org env.Append(LIBPATH=[sl_dir], LIBS=[sl_base]) 878335Snate@binkert.org 888335Snate@binkert.org super(SystemCTestBin, cls).declare_all(env) 898335Snate@binkert.org 908335Snate@binkert.org def declare(self, env): 919793Sakash.bagdia@arm.com env = env.Clone() 929827Sakash.bagdia@arm.com sources = list(self.sources) 9310249Sstephan.diestelhorst@arm.com for f in self.filters: 94 sources = Source.all.apply_filter(f) 95 objs = self.srcs_to_objs(env, sources) 96 objs = objs + env['MAIN_OBJS'] 97 relpath = os.path.relpath( 98 env['SHARED_LIB'][0].dir.abspath, 99 self.path(env).dir.abspath) 100 env.Append(LINKFLAGS=Split('-z origin')) 101 env.Append(RPATH=[ 102 env.Literal(os.path.join('\\$$ORIGIN', relpath))]) 103 test_bin = super(SystemCTestBin, self).declare(env, objs) 104 test_dir = self.dir.Dir(self.reldir) 105 for dep in self.test_deps: 106 env.Depends(test_bin, test_dir.File(dep)) 107 return test_bin 108 109 tests = [] 110 def new_test(dirname, name): 111 test = SystemCTest(dirname, name) 112 tests.append(test) 113 return test 114 115 116 def scan_dir_for_tests(subdir): 117 def visitor(arg, dirname, names): 118 # If there's a 'DONTRUN' file in this directory, skip it and any 119 # child directories. 120 if 'DONTRUN' in names: 121 del names[:] 122 return 123 124 endswith = lambda sfx: filter(lambda n: n.endswith(sfx), names) 125 126 cpps = endswith('.cpp') 127 if not cpps: 128 return 129 130 def get_entries(fname): 131 with open(os.path.join(dirname, fname)) as content: 132 lines = content.readlines 133 # Get rid of leading and trailing whitespace. 134 lines = map(lambda x: x.strip(), content.readlines()) 135 # Get rid of blank lines. 136 lines = filter(lambda x: x, lines) 137 return lines 138 139 # If there's only one source file, then that files name is the test 140 # name, and it's the source for that test. 141 if len(cpps) == 1: 142 cpp = cpps[0] 143 144 test = new_test(dirname, os.path.splitext(cpp)[0]) 145 test.add_source(cpp) 146 147 # Otherwise, expect there to be a file that ends in .f. That files 148 # name is the test name, and it will list the source files with 149 # one preceeding path component. 150 else: 151 fs = endswith('.f') 152 if len(fs) != 1: 153 print("In %s, expected 1 *.f file, but found %d.", 154 dirname, len(fs)) 155 for f in fs: 156 print(os.path.join(dirname, f)) 157 return 158 f = fs[0] 159 160 test = new_test(dirname, os.path.splitext(f)[0]) 161 # Add all the sources to this test. 162 test.add_sources(get_entries(f)) 163 164 if 'COMPILE' in names: 165 test.compile_only = True 166 167 if 'DEPS' in names: 168 test.deps = get_entries('DEPS') 169 170 subdir_src = Dir('.').srcdir.Dir(subdir) 171 os.path.walk(str(subdir_src), visitor, None) 172 173 scan_dir_for_tests('systemc') 174 scan_dir_for_tests('tlm') 175 176 177 def build_tests_json(target, source, env): 178 data = { test.target : test.properties() for test in tests } 179 with open(str(target[0]), "w") as tests_json: 180 json.dump(data, tests_json) 181 182 AlwaysBuild(env.Command(File('tests.json'), None, 183 MakeAction(build_tests_json, Transform("TESTJSON")))) 184 185 186 for test in tests: 187 SystemCTestBin(test) 188