SConscript revision 12922
16019Shines@cs.fsu.edu# Copyright 2018 Google, Inc. 26019Shines@cs.fsu.edu# 37100Sgblack@eecs.umich.edu# Redistribution and use in source and binary forms, with or without 47100Sgblack@eecs.umich.edu# modification, are permitted provided that the following conditions are 57100Sgblack@eecs.umich.edu# met: redistributions of source code must retain the above copyright 67100Sgblack@eecs.umich.edu# notice, this list of conditions and the following disclaimer; 77100Sgblack@eecs.umich.edu# redistributions in binary form must reproduce the above copyright 87100Sgblack@eecs.umich.edu# notice, this list of conditions and the following disclaimer in the 97100Sgblack@eecs.umich.edu# documentation and/or other materials provided with the distribution; 107100Sgblack@eecs.umich.edu# neither the name of the copyright holders nor the names of its 117100Sgblack@eecs.umich.edu# contributors may be used to endorse or promote products derived from 127100Sgblack@eecs.umich.edu# this software without specific prior written permission. 137100Sgblack@eecs.umich.edu# 147100Sgblack@eecs.umich.edu# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 156019Shines@cs.fsu.edu# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 166019Shines@cs.fsu.edu# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 176019Shines@cs.fsu.edu# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 186019Shines@cs.fsu.edu# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 196019Shines@cs.fsu.edu# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 206019Shines@cs.fsu.edu# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 216019Shines@cs.fsu.edu# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 226019Shines@cs.fsu.edu# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 236019Shines@cs.fsu.edu# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 246019Shines@cs.fsu.edu# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 256019Shines@cs.fsu.edu# 266019Shines@cs.fsu.edu# Authors: Gabe Black 276019Shines@cs.fsu.edu 286019Shines@cs.fsu.edufrom __future__ import print_function 296019Shines@cs.fsu.edu 306019Shines@cs.fsu.eduImport('*') 316019Shines@cs.fsu.edu 326019Shines@cs.fsu.eduif env['USE_SYSTEMC']: 336019Shines@cs.fsu.edu 346019Shines@cs.fsu.edu from gem5_scons import Transform 356019Shines@cs.fsu.edu 366019Shines@cs.fsu.edu import os.path 376019Shines@cs.fsu.edu import json 386019Shines@cs.fsu.edu 396019Shines@cs.fsu.edu src = str(Dir('.').srcdir) 406019Shines@cs.fsu.edu 416019Shines@cs.fsu.edu class SystemCTest(object): 426757SAli.Saidi@ARM.com def __init__(self, dirname, name): 436019Shines@cs.fsu.edu self.name = name 446019Shines@cs.fsu.edu self.reldir = os.path.relpath(dirname, src) 456019Shines@cs.fsu.edu self.target = os.path.join(self.reldir, name) 466019Shines@cs.fsu.edu self.sources = [] 476019Shines@cs.fsu.edu 486019Shines@cs.fsu.edu self.compile_only = False 496019Shines@cs.fsu.edu 509022Sgblack@eecs.umich.edu def add_source(self, source): 516019Shines@cs.fsu.edu self.sources.append(os.path.join(self.reldir, source)) 527170Sgblack@eecs.umich.edu 536253Sgblack@eecs.umich.edu def add_sources(self, sources): 547202Sgblack@eecs.umich.edu for source in sources: 556253Sgblack@eecs.umich.edu self.sources.append(os.path.join(self.reldir, '..', source)) 566253Sgblack@eecs.umich.edu 577396Sgblack@eecs.umich.edu def properties(self): 588745Sgblack@eecs.umich.edu return { 597405SAli.Saidi@ARM.com 'name' : self.name, 608782Sgblack@eecs.umich.edu 'path' : self.reldir, 618782Sgblack@eecs.umich.edu 'compile_only' : self.compile_only 628782Sgblack@eecs.umich.edu } 637259Sgblack@eecs.umich.edu 648757Sgblack@eecs.umich.edu ext_dir = Dir('..').Dir('ext') 658782Sgblack@eecs.umich.edu test_dir = Dir('.') 668757Sgblack@eecs.umich.edu class SystemCTestBin(Executable): 678777Sgblack@eecs.umich.edu def __init__(self, test): 688782Sgblack@eecs.umich.edu super(SystemCTestBin, self).__init__(test.target, *test.sources) 698756Sgblack@eecs.umich.edu 706019Shines@cs.fsu.edu @classmethod 716757SAli.Saidi@ARM.com def declare_all(cls, env): 728757Sgblack@eecs.umich.edu env = env.Clone() 736019Shines@cs.fsu.edu 748745Sgblack@eecs.umich.edu # Turn off extra warnings and Werror for the tests. 756397Sgblack@eecs.umich.edu to_remove = ['-Wall', '-Wundef', '-Wextra', '-Werror'] 768782Sgblack@eecs.umich.edu env['CCFLAGS'] = \ 776019Shines@cs.fsu.edu filter(lambda f: f not in to_remove, env['CCFLAGS']) 786397Sgblack@eecs.umich.edu 798335Snate@binkert.org env.Append(CPPPATH=test_dir.Dir('include')) 809023Sgblack@eecs.umich.edu env.Append(CPPPATH=ext_dir) 819023Sgblack@eecs.umich.edu 828335Snate@binkert.org super(SystemCTestBin, cls).declare_all(env) 836019Shines@cs.fsu.edu 846019Shines@cs.fsu.edu def declare(self, env): 856019Shines@cs.fsu.edu sources = list(self.sources) 866019Shines@cs.fsu.edu for f in self.filters: 876019Shines@cs.fsu.edu sources = Source.all.apply_filter(f) 886019Shines@cs.fsu.edu objs = self.srcs_to_objs(env, sources) 896019Shines@cs.fsu.edu objs = objs + env['SHARED_LIB'] + env['MAIN_OBJS'] 906019Shines@cs.fsu.edu return super(SystemCTestBin, self).declare(env, objs) 91 92 tests = [] 93 def new_test(dirname, name): 94 test = SystemCTest(dirname, name) 95 tests.append(test) 96 return test 97 98 99 def scan_dir_for_tests(subdir): 100 def visitor(arg, dirname, names): 101 # If there's a 'DONTRUN' file in this directory, skip it and any 102 # child directories. 103 if 'DONTRUN' in names: 104 del names[:] 105 return 106 107 endswith = lambda sfx: filter(lambda n: n.endswith(sfx), names) 108 109 cpps = endswith('.cpp') 110 if not cpps: 111 return 112 113 # If there's only one source file, then that files name is the test 114 # name, and it's the source for that test. 115 if len(cpps) == 1: 116 cpp = cpps[0] 117 118 test = new_test(dirname, os.path.splitext(cpp)[0]) 119 test.add_source(cpp) 120 121 # Otherwise, expect there to be a file that ends in .f. That files 122 # name is the test name, and it will list the source files with 123 # one preceeding path component. 124 else: 125 fs = endswith('.f') 126 if len(fs) != 1: 127 print("In %s, expected 1 *.f file, but found %d.", 128 dirname, len(fs)) 129 for f in fs: 130 print(os.path.join(dirname, f)) 131 return 132 f = fs[0] 133 134 test = new_test(dirname, os.path.splitext(f)[0]) 135 with open(os.path.join(dirname, f)) as content: 136 lines = content.readlines 137 # Get rid of leading and trailing whitespace. 138 lines = map(lambda x: x.strip(), content.readlines()) 139 # Get rid of blank lines. 140 lines = filter(lambda x: x, lines) 141 # Add all the sources to this test. 142 test.add_sources(lines) 143 144 if 'COMPILE' in names: 145 test.compile_only = True 146 147 subdir_src = Dir('.').srcdir.Dir(subdir) 148 os.path.walk(str(subdir_src), visitor, None) 149 150 scan_dir_for_tests('systemc') 151 152 153 def build_tests_json(target, source, env): 154 data = { test.target : test.properties() for test in tests } 155 with open(str(target[0]), "w") as tests_json: 156 json.dump(data, tests_json) 157 158 AlwaysBuild(env.Command(File('tests.json'), None, 159 MakeAction(build_tests_json, Transform("TESTJSON")))) 160 161 162 for test in tests: 163 SystemCTestBin(test) 164