diff options
Diffstat (limited to 'scripts/test/wasm2js.py')
-rwxr-xr-x | scripts/test/wasm2js.py | 85 |
1 files changed, 41 insertions, 44 deletions
diff --git a/scripts/test/wasm2js.py b/scripts/test/wasm2js.py index 53a890f2c..a5e4ce6eb 100755 --- a/scripts/test/wasm2js.py +++ b/scripts/test/wasm2js.py @@ -16,16 +16,13 @@ import os -from .support import run_command, split_wast, write_wast -from .shared import ( - WASM2JS, MOZJS, NODEJS, fail_if_not_identical, options, - fail_if_not_identical_to_file, with_pass_debug, get_test_dir, get_tests, -) - -tests = get_tests(options.binaryen_test) -spec_tests = get_tests(get_test_dir('spec'), ['.wast']) +from scripts.test import shared +from scripts.test import support + +tests = shared.get_tests(shared.options.binaryen_test) +spec_tests = shared.get_tests(shared.get_test_dir('spec'), ['.wast']) spec_tests = [t for t in spec_tests if '.fail' not in t] -wasm2js_tests = get_tests(get_test_dir('wasm2js'), ['.wast']) +wasm2js_tests = shared.get_tests(shared.get_test_dir('wasm2js'), ['.wast']) assert_tests = ['wasm2js.wast.asserts'] # These tests exercise functionality not supported by wasm2js wasm2js_blacklist = ['empty_imported_table.wast'] @@ -39,7 +36,7 @@ def test_wasm2js_output(): continue asm = basename.replace('.wast', '.2asm.js') - expected_file = os.path.join(get_test_dir('wasm2js'), asm) + expected_file = os.path.join(shared.get_test_dir('wasm2js'), asm) if opt: expected_file += '.opt' @@ -50,46 +47,46 @@ def test_wasm2js_output(): all_out = [] - for module, asserts in split_wast(t): - write_wast('split.wast', module, asserts) + for module, asserts in support.split_wast(t): + support.write_wast('split.wast', module, asserts) - cmd = WASM2JS + ['split.wast', '-all'] + cmd = shared.WASM2JS + ['split.wast', '-all'] if opt: cmd += ['-O'] if 'emscripten' in t: cmd += ['--emscripten'] - out = run_command(cmd) + out = support.run_command(cmd) all_out.append(out) - if not NODEJS and not MOZJS: + if not shared.NODEJS and not shared.MOZJS: print('No JS interpreters. Skipping spec tests.') continue open('a.2asm.mjs', 'w').write(out) cmd += ['--allow-asserts'] - out = run_command(cmd) + out = support.run_command(cmd) # also verify it passes pass-debug verifications - with_pass_debug(lambda: run_command(cmd)) + shared.with_pass_debug(lambda: support.run_command(cmd)) open('a.2asm.asserts.mjs', 'w').write(out) # verify asm.js is valid js, note that we're using --experimental-modules # to enable ESM syntax and we're also passing a custom loader to handle the # `spectest` and `env` modules in our tests. - if NODEJS: - loader = os.path.join(options.binaryen_root, 'scripts', 'test', 'node-esm-loader.mjs') - node = [NODEJS, '--experimental-modules', '--loader', loader] + if shared.NODEJS: + loader = os.path.join(shared.options.binaryen_root, 'scripts', 'test', 'node-esm-loader.mjs') + node = [shared.NODEJS, '--experimental-modules', '--loader', loader] cmd = node[:] cmd.append('a.2asm.mjs') - out = run_command(cmd) - fail_if_not_identical(out, '') + out = support.run_command(cmd) + shared.fail_if_not_identical(out, '') cmd = node[:] cmd.append('a.2asm.asserts.mjs') - out = run_command(cmd, expected_err='', err_ignore='ExperimentalWarning') - fail_if_not_identical(out, '') + out = support.run_command(cmd, expected_err='', err_ignore='ExperimentalWarning') + shared.fail_if_not_identical(out, '') - fail_if_not_identical_to_file(''.join(all_out), expected_file) + shared.fail_if_not_identical_to_file(''.join(all_out), expected_file) def test_asserts_output(): @@ -98,17 +95,17 @@ def test_asserts_output(): asserts = os.path.basename(wasm).replace('.wast.asserts', '.asserts.js') traps = os.path.basename(wasm).replace('.wast.asserts', '.traps.js') - asserts_expected_file = os.path.join(options.binaryen_test, asserts) - traps_expected_file = os.path.join(options.binaryen_test, traps) + asserts_expected_file = os.path.join(shared.options.binaryen_test, asserts) + traps_expected_file = os.path.join(shared.options.binaryen_test, traps) - wasm = os.path.join(get_test_dir('wasm2js'), wasm) - cmd = WASM2JS + [wasm, '--allow-asserts', '-all'] - out = run_command(cmd) - fail_if_not_identical_to_file(out, asserts_expected_file) + wasm = os.path.join(shared.get_test_dir('wasm2js'), wasm) + cmd = shared.WASM2JS + [wasm, '--allow-asserts', '-all'] + out = support.run_command(cmd) + shared.fail_if_not_identical_to_file(out, asserts_expected_file) cmd += ['--pedantic'] - out = run_command(cmd) - fail_if_not_identical_to_file(out, traps_expected_file) + out = support.run_command(cmd) + shared.fail_if_not_identical_to_file(out, traps_expected_file) def test_wasm2js(): @@ -129,7 +126,7 @@ def update_wasm2js_tests(): continue asm = os.path.basename(wasm).replace('.wast', '.2asm.js') - expected_file = os.path.join(get_test_dir('wasm2js'), asm) + expected_file = os.path.join(shared.get_test_dir('wasm2js'), asm) if opt: expected_file += '.opt' @@ -142,19 +139,19 @@ def update_wasm2js_tests(): print('..', wasm) - t = os.path.join(options.binaryen_test, wasm) + t = os.path.join(shared.options.binaryen_test, wasm) all_out = [] - for module, asserts in split_wast(t): - write_wast('split.wast', module, asserts) + for module, asserts in support.split_wast(t): + support.write_wast('split.wast', module, asserts) - cmd = WASM2JS + ['split.wast', '-all'] + cmd = shared.WASM2JS + ['split.wast', '-all'] if opt: cmd += ['-O'] if 'emscripten' in wasm: cmd += ['--emscripten'] - out = run_command(cmd) + out = support.run_command(cmd) all_out.append(out) with open(expected_file, 'w') as o: @@ -165,16 +162,16 @@ def update_wasm2js_tests(): asserts = os.path.basename(wasm).replace('.wast.asserts', '.asserts.js') traps = os.path.basename(wasm).replace('.wast.asserts', '.traps.js') - asserts_expected_file = os.path.join(options.binaryen_test, asserts) - traps_expected_file = os.path.join(options.binaryen_test, traps) + asserts_expected_file = os.path.join(shared.options.binaryen_test, asserts) + traps_expected_file = os.path.join(shared.options.binaryen_test, traps) - cmd = WASM2JS + [os.path.join(get_test_dir('wasm2js'), wasm), '--allow-asserts', '-all'] - out = run_command(cmd) + cmd = shared.WASM2JS + [os.path.join(shared.get_test_dir('wasm2js'), wasm), '--allow-asserts', '-all'] + out = support.run_command(cmd) with open(asserts_expected_file, 'w') as o: o.write(out) cmd += ['--pedantic'] - out = run_command(cmd) + out = support.run_command(cmd) with open(traps_expected_file, 'w') as o: o.write(out) |