SConscript (13438:924abb66cea7) SConscript (13458:6ccb61e12fc7)
1# Copyright 2018 Google, Inc.
2#
3# Redistribution and use in source and binary forms, with or without
4# modification, are permitted provided that the following conditions are
5# met: redistributions of source code must retain the above copyright
6# notice, this list of conditions and the following disclaimer;
7# redistributions in binary form must reproduce the above copyright
8# notice, this list of conditions and the following disclaimer in the

--- 30 unchanged lines hidden (view full) ---

39 src = str(Dir('.').srcdir)
40
41 class SystemCTest(object):
42 def __init__(self, dirname, name):
43 self.name = name
44 self.reldir = os.path.relpath(dirname, src)
45 self.target = os.path.join(self.reldir, name)
46 self.sources = []
1# Copyright 2018 Google, Inc.
2#
3# Redistribution and use in source and binary forms, with or without
4# modification, are permitted provided that the following conditions are
5# met: redistributions of source code must retain the above copyright
6# notice, this list of conditions and the following disclaimer;
7# redistributions in binary form must reproduce the above copyright
8# notice, this list of conditions and the following disclaimer in the

--- 30 unchanged lines hidden (view full) ---

39 src = str(Dir('.').srcdir)
40
41 class SystemCTest(object):
42 def __init__(self, dirname, name):
43 self.name = name
44 self.reldir = os.path.relpath(dirname, src)
45 self.target = os.path.join(self.reldir, name)
46 self.sources = []
47 self.deps = []
47
48 self.compile_only = False
49
50 def add_source(self, source):
51 self.sources.append(os.path.join(self.reldir, source))
52
53 def add_sources(self, sources):
54 for source in sources:
55 self.sources.append(os.path.join(self.reldir, '..', source))
56
57 def properties(self):
58 return {
59 'name' : self.name,
60 'path' : self.reldir,
48
49 self.compile_only = False
50
51 def add_source(self, source):
52 self.sources.append(os.path.join(self.reldir, source))
53
54 def add_sources(self, sources):
55 for source in sources:
56 self.sources.append(os.path.join(self.reldir, '..', source))
57
58 def properties(self):
59 return {
60 'name' : self.name,
61 'path' : self.reldir,
61 'compile_only' : self.compile_only
62 'compile_only' : self.compile_only,
63 'deps' : self.deps
62 }
63
64 test_dir = Dir('.')
65 class SystemCTestBin(Executable):
66 def __init__(self, test):
67 super(SystemCTestBin, self).__init__(test.target, *test.sources)
64 }
65
66 test_dir = Dir('.')
67 class SystemCTestBin(Executable):
68 def __init__(self, test):
69 super(SystemCTestBin, self).__init__(test.target, *test.sources)
70 self.reldir = test.reldir
71 self.test_deps = test.deps
68
69 @classmethod
70 def declare_all(cls, env):
71 env = env.Clone()
72
73 # Turn off extra warnings and Werror for the tests.
74 to_remove = ['-Wall', '-Wundef', '-Wextra', '-Werror']
75 env['CCFLAGS'] = \

--- 14 unchanged lines hidden (view full) ---

90 sources = Source.all.apply_filter(f)
91 objs = self.srcs_to_objs(env, sources)
92 objs = objs + env['MAIN_OBJS']
93 relpath = os.path.relpath(
94 env['SHARED_LIB'][0].dir.abspath,
95 self.path(env).dir.abspath)
96 env.Append(LINKFLAGS=Split('-z origin'))
97 env.Append(RPATH=env.Literal(os.path.join('\\$$ORIGIN', relpath)))
72
73 @classmethod
74 def declare_all(cls, env):
75 env = env.Clone()
76
77 # Turn off extra warnings and Werror for the tests.
78 to_remove = ['-Wall', '-Wundef', '-Wextra', '-Werror']
79 env['CCFLAGS'] = \

--- 14 unchanged lines hidden (view full) ---

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=env.Literal(os.path.join('\\$$ORIGIN', relpath)))
98 return super(SystemCTestBin, self).declare(env, objs)
102 test_bin = super(SystemCTestBin, self).declare(env, objs)
103 test_dir = self.dir.Dir(self.reldir)
104 for dep in self.test_deps:
105 env.Depends(test_bin, test_dir.File(dep))
106 return test_bin
99
100 tests = []
101 def new_test(dirname, name):
102 test = SystemCTest(dirname, name)
103 tests.append(test)
104 return test
105
106

--- 6 unchanged lines hidden (view full) ---

113 return
114
115 endswith = lambda sfx: filter(lambda n: n.endswith(sfx), names)
116
117 cpps = endswith('.cpp')
118 if not cpps:
119 return
120
107
108 tests = []
109 def new_test(dirname, name):
110 test = SystemCTest(dirname, name)
111 tests.append(test)
112 return test
113
114

--- 6 unchanged lines hidden (view full) ---

121 return
122
123 endswith = lambda sfx: filter(lambda n: n.endswith(sfx), names)
124
125 cpps = endswith('.cpp')
126 if not cpps:
127 return
128
129 def get_entries(fname):
130 with open(os.path.join(dirname, fname)) as content:
131 lines = content.readlines
132 # Get rid of leading and trailing whitespace.
133 lines = map(lambda x: x.strip(), content.readlines())
134 # Get rid of blank lines.
135 lines = filter(lambda x: x, lines)
136 return lines
137
121 # If there's only one source file, then that files name is the test
122 # name, and it's the source for that test.
123 if len(cpps) == 1:
124 cpp = cpps[0]
125
126 test = new_test(dirname, os.path.splitext(cpp)[0])
127 test.add_source(cpp)
128

--- 6 unchanged lines hidden (view full) ---

135 print("In %s, expected 1 *.f file, but found %d.",
136 dirname, len(fs))
137 for f in fs:
138 print(os.path.join(dirname, f))
139 return
140 f = fs[0]
141
142 test = new_test(dirname, os.path.splitext(f)[0])
138 # If there's only one source file, then that files name is the test
139 # name, and it's the source for that test.
140 if len(cpps) == 1:
141 cpp = cpps[0]
142
143 test = new_test(dirname, os.path.splitext(cpp)[0])
144 test.add_source(cpp)
145

--- 6 unchanged lines hidden (view full) ---

152 print("In %s, expected 1 *.f file, but found %d.",
153 dirname, len(fs))
154 for f in fs:
155 print(os.path.join(dirname, f))
156 return
157 f = fs[0]
158
159 test = new_test(dirname, os.path.splitext(f)[0])
143 with open(os.path.join(dirname, f)) as content:
144 lines = content.readlines
145 # Get rid of leading and trailing whitespace.
146 lines = map(lambda x: x.strip(), content.readlines())
147 # Get rid of blank lines.
148 lines = filter(lambda x: x, lines)
149 # Add all the sources to this test.
150 test.add_sources(lines)
160 # Add all the sources to this test.
161 test.add_sources(get_entries(f))
151
152 if 'COMPILE' in names:
153 test.compile_only = True
154
162
163 if 'COMPILE' in names:
164 test.compile_only = True
165
166 if 'DEPS' in names:
167 test.deps = get_entries('DEPS')
168
155 subdir_src = Dir('.').srcdir.Dir(subdir)
156 os.path.walk(str(subdir_src), visitor, None)
157
158 scan_dir_for_tests('systemc')
159
160
161 def build_tests_json(target, source, env):
162 data = { test.target : test.properties() for test in tests }
163 with open(str(target[0]), "w") as tests_json:
164 json.dump(data, tests_json)
165
166 AlwaysBuild(env.Command(File('tests.json'), None,
167 MakeAction(build_tests_json, Transform("TESTJSON"))))
168
169
170 for test in tests:
171 SystemCTestBin(test)
169 subdir_src = Dir('.').srcdir.Dir(subdir)
170 os.path.walk(str(subdir_src), visitor, None)
171
172 scan_dir_for_tests('systemc')
173
174
175 def build_tests_json(target, source, env):
176 data = { test.target : test.properties() for test in tests }
177 with open(str(target[0]), "w") as tests_json:
178 json.dump(data, tests_json)
179
180 AlwaysBuild(env.Command(File('tests.json'), None,
181 MakeAction(build_tests_json, Transform("TESTJSON"))))
182
183
184 for test in tests:
185 SystemCTestBin(test)