Skip to content

Commit a766b4b

Browse files
Extract more
1 parent 5bd28d6 commit a766b4b

File tree

1 file changed

+61
-59
lines changed

1 file changed

+61
-59
lines changed

check.py

Lines changed: 61 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -206,69 +206,71 @@ def check_expected(actual, expected, stdout=None):
206206
shared.fail(actual, expected)
207207

208208

209+
def run_one_spec_test(wast: Path, stdout=None, stderr=None):
210+
test_name = wast.name
211+
base_name = "-".join(wast.parts[-3:])
212+
213+
print('..', test_name, file=stdout)
214+
# windows has some failures that need to be investigated
215+
if test_name == 'names.wast' and shared.skip_if_on_windows('spec: ' + test_name):
216+
return
217+
218+
expected = os.path.join(shared.get_test_dir('spec'), 'expected-output', test_name + '.log')
219+
220+
# some spec tests should fail (actual process failure, not just assert_invalid)
221+
try:
222+
actual = run_spec_test(str(wast), stdout=stdout, stderr=stderr)
223+
except Exception as e:
224+
if ('wasm-validator error' in str(e) or 'error: ' in str(e)) and '.fail.' in test_name:
225+
print('<< test failed as expected >>', file=stdout)
226+
return # don't try all the binary format stuff TODO
227+
else:
228+
shared.fail_with_error(str(e))
229+
230+
check_expected(actual, expected, stdout=stdout)
231+
232+
# check binary format. here we can verify execution of the final
233+
# result, no need for an output verification
234+
actual = ''
235+
with open(base_name + ".transformed", 'w') as transformed_spec_file:
236+
for i, (module, asserts) in enumerate(support.split_wast(str(wast))):
237+
if not module:
238+
# Skip any initial assertions that don't have a module
239+
return
240+
print(f' testing split module {i}', file=stdout)
241+
split_name = base_name + f'_split{i}.wast'
242+
support.write_wast(split_name, module)
243+
run_opt_test(split_name, stdout=stdout, stderr=stderr) # also that our optimizer doesn't break on it
244+
245+
result_wast_file = shared.binary_format_check(split_name, verify_final_result=False, base_name=base_name, stdout=stdout, stderr=stderr)
246+
with open(result_wast_file) as f:
247+
result_wast = f.read()
248+
# add the asserts, and verify that the test still passes
249+
transformed_spec_file.write(result_wast + '\n' + '\n'.join(asserts))
250+
251+
# compare all the outputs to the expected output
252+
actual = run_spec_test(base_name + ".transformed", stdout=stdout, stderr=stderr)
253+
check_expected(actual, os.path.join(shared.get_test_dir('spec'), 'expected-output', test_name + '.log'), stdout=stdout)
254+
255+
256+
def run_spec_test_with_wrapped_stdout(output_queue, wast: Path):
257+
out = io.StringIO()
258+
try:
259+
ret = run_one_spec_test(wast, stdout=out, stderr=out)
260+
except Exception as e:
261+
print(e, file=out)
262+
raise
263+
finally:
264+
# If a test fails, it's important to keep its output
265+
output_queue.put(out.getvalue())
266+
return ret
267+
268+
209269
def run_spec_tests():
210270
print('\n[ checking wasm-shell spec testcases... ]\n')
211271

212-
def run_one(wast: Path, stdout=None, stderr=None):
213-
test_name = wast.name
214-
base_name = "-".join(wast.parts[-3:])
215-
216-
print('..', test_name, file=stdout)
217-
# windows has some failures that need to be investigated
218-
if test_name == 'names.wast' and shared.skip_if_on_windows('spec: ' + test_name):
219-
return
220-
221-
expected = os.path.join(shared.get_test_dir('spec'), 'expected-output', test_name + '.log')
222-
223-
# some spec tests should fail (actual process failure, not just assert_invalid)
224-
try:
225-
actual = run_spec_test(str(wast), stdout=stdout, stderr=stderr)
226-
except Exception as e:
227-
if ('wasm-validator error' in str(e) or 'error: ' in str(e)) and '.fail.' in test_name:
228-
print('<< test failed as expected >>', file=stdout)
229-
return # don't try all the binary format stuff TODO
230-
else:
231-
shared.fail_with_error(str(e))
232-
233-
check_expected(actual, expected, stdout=stdout)
234-
235-
# check binary format. here we can verify execution of the final
236-
# result, no need for an output verification
237-
actual = ''
238-
with open(base_name + ".transformed", 'w') as transformed_spec_file:
239-
for i, (module, asserts) in enumerate(support.split_wast(str(wast))):
240-
if not module:
241-
# Skip any initial assertions that don't have a module
242-
return
243-
print(f' testing split module {i}', file=stdout)
244-
split_name = base_name + f'_split{i}.wast'
245-
support.write_wast(split_name, module)
246-
run_opt_test(split_name, stdout=stdout, stderr=stderr) # also that our optimizer doesn't break on it
247-
248-
result_wast_file = shared.binary_format_check(split_name, verify_final_result=False, base_name=base_name, stdout=stdout, stderr=stderr)
249-
with open(result_wast_file) as f:
250-
result_wast = f.read()
251-
# add the asserts, and verify that the test still passes
252-
transformed_spec_file.write(result_wast + '\n' + '\n'.join(asserts))
253-
254-
# compare all the outputs to the expected output
255-
actual = run_spec_test(base_name + ".transformed", stdout=stdout, stderr=stderr)
256-
check_expected(actual, os.path.join(shared.get_test_dir('spec'), 'expected-output', test_name + '.log'), stdout=stdout)
257-
258272
output_queue = queue.Queue()
259273

260-
def run_with_wrapped_stdout(output_queue, wast: Path):
261-
out = io.StringIO()
262-
try:
263-
ret = run_one(wast, stdout=out, stderr=out)
264-
except Exception as e:
265-
print(e, file=out)
266-
raise
267-
finally:
268-
# If a test fails, it's important to keep its output
269-
output_queue.put(out.getvalue())
270-
return ret
271-
272274
def printer():
273275
while True:
274276
try:
@@ -282,7 +284,7 @@ def printer():
282284

283285
executor = ThreadPoolExecutor(max_workers=max(1, min(len(shared.options.spec_tests), os.cpu_count() * 4)))
284286
try:
285-
results = executor.map(partial(run_with_wrapped_stdout, output_queue), map(Path, shared.options.spec_tests))
287+
results = executor.map(partial(run_spec_test_with_wrapped_stdout, output_queue), map(Path, shared.options.spec_tests))
286288
for _ in results:
287289
# Iterating joins the threads. No return value here.
288290
pass

0 commit comments

Comments
 (0)