OLD | NEW |
1 # -*- python -*- | 1 # -*- python -*- |
2 # Copyright (c) 2011 The Native Client Authors. All rights reserved. | 2 # Copyright (c) 2011 The Native Client Authors. All rights reserved. |
3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 | 5 |
6 | 6 |
7 import glob | 7 import glob |
8 import os | 8 import os |
9 import sys | 9 import sys |
10 | 10 |
11 Import('env') | 11 Import('env') |
12 | 12 |
13 # | 13 # |
14 # | 14 # |
15 # Build x86 only pieces | 15 # Build x86 only pieces |
16 # | 16 # |
17 # | 17 # |
18 if not env.Bit('target_x86'): Return() | 18 if not env.Bit('target_x86'): Return() |
19 | 19 |
20 # ------------------------------------------------------ | |
21 # General adjustments to the environment for builds. | |
22 | |
23 # Defines which test sets tests should be added to. | |
24 STANDARD_TESTS = ['small_tests', 'validator_tests'] | |
25 | |
26 # TODO(bradchen): eliminate need for the following line | |
27 env.FilterOut(CCFLAGS=['-Wextra', '-Wswitch-enum', '-Wsign-compare']) | |
28 | |
29 # Defines the source directory where validator generated files should be added. | |
30 val_src_dir = '$MAIN_DIR/src/trusted/validator_x86' | |
31 | |
32 # Create environment for command-line tools and testing, rather than | |
33 # part of the TCB. Then define compile-time flag that communicates | |
34 # that we are compiling in the test environment (rather than for the TCB). | |
35 test_env = env.Clone() | |
36 test_env.Append(CCFLAGS=['-DNACL_TRUSTED_BUT_NOT_TCB']) | |
37 | |
38 # TODO(shcherbina): remove dead test running code (tests moved to | |
39 # testscripts/run_tests.py and *.test files) | |
40 | |
41 # ====================================================================== | |
42 # Helper functions for getting automated tests from the corresponding | |
43 # test directory. | |
44 | |
45 TESTDATA_DIR = 'testdata/' | |
46 TESTDATA_SUBARCH_DIR = TESTDATA_DIR + env['TARGET_SUBARCH'] + '/' | |
47 | |
48 # Generates the set of test files with the given extension. | |
49 def __GoldenFiles(ext): | |
50 return Glob(TESTDATA_SUBARCH_DIR + '*.' + ext) | |
51 | |
52 # Generates base names (i.e. minus path and extention (ext) suffix) of | |
53 # all test data input files. | |
54 def __FilterOutTestFileBaseGen(files, ext): | |
55 for f in files: | |
56 yield os.path.basename(f.path).replace('.' + ext, '') | |
57 | |
58 # Generates the set of golden bases for the given extension. | |
59 def __GoldenBases(ext): | |
60 return __FilterOutTestFileBaseGen(__GoldenFiles(ext), ext) | |
61 | |
62 # Generates the corresponding test file from the given base. | |
63 def __BaseTestFile(base, ext): | |
64 return test_env.File(TESTDATA_SUBARCH_DIR + base + '.' + ext) | |
65 | |
66 # Generates the corresponding output file from the given base. | |
67 def __OutTestFile(test, base, ext): | |
68 return test + '_' + base + '.' + ext + '.out' | |
69 | |
70 def __AddTest(test, test_env, base, ext, command, groups): | |
71 test_env.AddNodeToTestSuite( | |
72 command, | |
73 groups, | |
74 'run_%s_%s_%s_test' % (test, base, ext)) | |
75 | |
76 | |
77 # The following are common library components that use elements | |
78 # of both x86-32 and x86-64 validators. | |
79 test_env.ComponentLibrary(test_env.NaClTargetArchSuffix('ncdis_util'), | |
80 ['ncdis_segments.c', | |
81 'nc_read_segment.c', | |
82 test_env.NaClTargetArchSuffix('ncenuminsts') + '.c']) | |
83 | |
84 # The following are copycode routines for x86-32 and x86-64. | 20 # The following are copycode routines for x86-32 and x86-64. |
85 # TODO(karl): Break this up so that we don't need to load | 21 # TODO(karl): Break this up so that we don't need to load |
86 # non-shared code in library. | 22 # non-shared code in library. |
87 env.ComponentLibrary(env.NaClTargetArchSuffix('nccopy'), [ | 23 env.ComponentLibrary(env.NaClTargetArchSuffix('nccopy'), [ |
88 'nccopycode.c', | 24 'nccopycode.c', |
89 'nccopycode_stores.S', | 25 'nccopycode_stores.S', |
90 ]) | 26 ]) |
91 | 27 |
92 # ====================================================================== | |
93 # Decoder unittests | |
94 if test_env.Bit('target_x86_32'): | |
95 # TODO(kschimpf): remove this when the validator builds as 64-bits. | |
96 if test_env.Bit('build_x86_32'): | |
97 ncdecode_tests = test_env.ComponentProgram( | |
98 'ncdecode_tests', | |
99 ['ncdecode_tests.c'], | |
100 EXTRA_LIBS=[test_env.NaClTargetArchSuffix('ncdis_seg_sfi_verbose'), | |
101 ]) | |
102 | |
103 node = test_env.CommandTest( | |
104 'ncdecode_tests.out', | |
105 [ncdecode_tests], | |
106 ) | |
107 | |
108 test_env.AddNodeToTestSuite(node, STANDARD_TESTS, 'run_nc_decode_tests') | |
109 | |
110 # ====================================================================== | |
111 # Build command line decoder. | |
112 # | |
113 ncdis = test_env.ComponentProgram( | |
114 'ncdis', [ | |
115 'ncdis.c', | |
116 ], | |
117 EXTRA_LIBS=[test_env.NaClTargetArchSuffix('ncdis_util'), | |
118 test_env.NaClTargetArchSuffix('ncfileutils'), | |
119 test_env.NaClTargetArchSuffix('ncdis_decode_tables'), | |
120 test_env.NaClTargetArchSuffix('nc_opcode_modeling_verbose'), | |
121 'utils', | |
122 ]) | |
123 | |
124 # ====================================================================== | |
125 # Valiator unittests | |
126 if test_env.Bit('target_x86_32'): | |
127 ncval_tests = test_env.ComponentProgram( | |
128 'ncval_tests', | |
129 ['ncval_tests.c'], | |
130 EXTRA_LIBS=[test_env.NaClTargetArchSuffix('ncdis_util'), | |
131 test_env.NaClTargetArchSuffix('ncval_seg_sfi'), | |
132 ]) | |
133 | |
134 node = test_env.CommandTest( | |
135 'ncval_tests.out', | |
136 [ncval_tests], | |
137 ) | |
138 | |
139 test_env.AddNodeToTestSuite(node, STANDARD_TESTS, 'run_ncval_tests') | |
140 | |
141 # ====================================================================== | |
142 # Define what decoder was historically being used for tests. This allows | |
143 # existing tests to continue to follow that historical assumption. | |
144 | |
145 if test_env.Bit('target_x86_32'): | |
146 _ncdis_historical_decoder = '--validator_decoder' | |
147 else: | |
148 _ncdis_historical_decoder = '--full_decoder' | |
149 | |
150 | |
151 # ====================================================================== | |
152 # Decoder vs objdump tests | |
153 # TODO: add tests using the toolchain binaries in the sdk | |
154 if test_env.Bit('linux') and test_env.Bit('target_x86_32'): | |
155 test = 'discmp' | |
156 ext = 'nexe' | |
157 for base in __GoldenBases(ext): | |
158 node = test_env.CommandTest( | |
159 __OutTestFile(test, base, ext), | |
160 ["${PYTHON}", test_env.File('discmp.py'), test_env.File('ncdis'), | |
161 __BaseTestFile(base, ext)], | |
162 size='large') | |
163 __AddTest(test, test_env, base, ext, node, ['large_tests']) | |
164 | |
165 # ====================================================================== | |
166 # Run tests on ncdis, where the input is self documenting (i.e. the input | |
167 # file matches the generated resulit. | |
168 def __AddNcdisSelfDocTests(validator_decoder, internals_also): | |
169 test = 'ncdis_test' | |
170 options = ['--commands=-'] | |
171 input_ext = 'input' | |
172 if internals_also: | |
173 output_ext = 'internal' | |
174 options.append('--internal') | |
175 else: | |
176 output_ext = input_ext | |
177 options.append('--self_document') | |
178 if validator_decoder: | |
179 output_ext = 'v' + output_ext | |
180 options.append('--validator_decoder') | |
181 else: | |
182 options.append('--full_decoder') | |
183 for base in __GoldenBases(output_ext): | |
184 command = [ncdis] + options | |
185 ncdis_test = test_env.CommandTest( | |
186 __OutTestFile(test, base, output_ext), | |
187 command, | |
188 stdin = __BaseTestFile(base, input_ext), | |
189 stdout_golden = __BaseTestFile(base, output_ext)) | |
190 __AddTest(test, test_env, base, output_ext, ncdis_test, | |
191 STANDARD_TESTS) | |
192 | |
193 for validator_decoder in [False, True]: | |
194 for internals_also in [False, True]: | |
195 __AddNcdisSelfDocTests(validator_decoder, internals_also) | |
196 | |
197 # ====================================================================== | |
198 # Build command line validator. | |
199 ncval = test_env.ComponentProgram( | |
200 'ncval', [ | |
201 'ncval.c', | |
202 ], | |
203 EXTRA_LIBS=[test_env.NaClTargetArchSuffix('ncdis_util'), | |
204 test_env.NaClTargetArchSuffix('ncval_seg_sfi'), | |
205 test_env.NaClTargetArchSuffix('ncfileutils'), | |
206 test_env.NaClTargetArchSuffix('ncdis_decode_tables'), | |
207 'utils', | |
208 ]) | |
209 | |
210 test_env.SDKInstallBin('ncval', ncval) | |
211 | |
212 | |
213 # ====================================================================== | |
214 # Validator tests against real nacl images | |
215 # TODO: add death tests | |
216 # TODO: add tests using binaries produced by nacl.scons files | |
217 # TODO: consider comparing the actual output (not just exit codes) | |
218 # Validate tests | |
219 if env.Bit('target_x86_32'): | |
220 test = 'validate' | |
221 ext = 'nexe' | |
222 for base in __GoldenBases(ext): | |
223 node = test_env.CommandTest( | |
224 __OutTestFile(test, base, ext), | |
225 [ncval, '-t', __BaseTestFile(base, ext)]) | |
226 __AddTest(test, test_env, base, ext, node, ['small_tests']) | |
227 | |
228 if test_env.Bit('target_x86_64'): | |
229 node = test_env.CommandTest('ncval_hello_x32.out', | |
230 [ncval, | |
231 env.File(os.path.join('${MAIN_DIR}/src/trusted', | |
232 'service_runtime', | |
233 'testdata/x86_64', | |
234 'hello_x32.nexe'))]) | |
235 env.AddNodeToTestSuite(node, STANDARD_TESTS, 'run_ncval_hello_x32_test') | |
236 | |
237 bits = env.get('TARGET_SUBARCH') | |
238 assert bits in ['32', '64'] | |
239 | |
240 tests_mask = '${MAIN_DIR}/src/trusted/validator_x86/testdata/%s/*.test' % bits | |
241 | |
242 if env.Bit('regenerate_golden'): | |
243 update_option = ['--update'] | |
244 else: | |
245 update_option = [] | |
246 | |
247 old_testdata_tests = env.AutoDepsCommand( | |
248 'x86_old_validator_testdata_tests.out', | |
249 ['${PYTHON}', | |
250 env.File('testscripts/run_old_validator_tests.py'), | |
251 '--ncval', ncval, | |
252 '--ncdis', ncdis, | |
253 '--bits', bits, | |
254 tests_mask] + update_option) | |
255 | |
256 env.AddNodeToTestSuite( | |
257 old_testdata_tests, | |
258 STANDARD_TESTS, | |
259 node_name='run_x86_old_validator_testdata_tests') | |
260 | |
261 rdfaval = '$STAGING_DIR/ncval_new$PROGSUFFIX' | |
262 | |
263 rdfa_testdata_tests = env.AutoDepsCommand( | |
264 'x86_rdfa_validator_testdata_tests.out', | |
265 ['${PYTHON}', | |
266 env.File('testscripts/run_rdfa_validator_tests.py'), | |
267 '--rdfaval', env.File(rdfaval), | |
268 '--bits', bits, | |
269 tests_mask] + update_option) | |
270 | |
271 env.AddNodeToTestSuite( | |
272 rdfa_testdata_tests, | |
273 STANDARD_TESTS, | |
274 node_name='run_x86_rdfa_validator_testdata_tests') | |
275 | |
276 compare_validators = env.AutoDepsCommand( | |
277 'compare_x86_validators_tests.out', | |
278 ['${PYTHON}', | |
279 env.File('testscripts/compare_validators.py'), | |
280 '--bits', bits, | |
281 tests_mask] + update_option) | |
282 | |
283 env.AddNodeToTestSuite( | |
284 compare_validators, | |
285 STANDARD_TESTS, | |
286 node_name='run_compare_x86_validators_tests') | |
287 | |
288 if env.Bit('regenerate_golden'): | |
289 # Don't want these tests run in parallel because they write | |
290 # to .test files. | |
291 SideEffect(tests_mask, [old_testdata_tests, rdfa_testdata_tests]) | |
292 Depends(compare_validators, [old_testdata_tests, rdfa_testdata_tests]) | |
OLD | NEW |