diff options
Diffstat (limited to 'scripts/test')
-rwxr-xr-x | scripts/test/asm2wasm.py | 49 | ||||
-rwxr-xr-x | scripts/test/binaryenjs.py | 36 | ||||
-rwxr-xr-x | scripts/test/generate_lld_tests.py | 11 | ||||
-rwxr-xr-x | scripts/test/lld.py | 29 | ||||
-rwxr-xr-x | scripts/test/wasm2js.py | 85 |
5 files changed, 103 insertions, 107 deletions
diff --git a/scripts/test/asm2wasm.py b/scripts/test/asm2wasm.py index 662daf387..74f34e789 100755 --- a/scripts/test/asm2wasm.py +++ b/scripts/test/asm2wasm.py @@ -17,21 +17,18 @@ import os import subprocess -from .support import run_command -from .shared import ( - ASM2WASM, WASM_OPT, binary_format_check, delete_from_orbit, - fail_with_error, options, fail_if_not_identical_to_file, get_tests -) +from scripts.test import shared +from scripts.test import support def test_asm2wasm(): print('[ checking asm2wasm testcases... ]\n') - for asm in get_tests(options.binaryen_test, ['.asm.js']): + for asm in shared.get_tests(shared.options.binaryen_test, ['.asm.js']): basename = os.path.basename(asm) for precise in [0, 1, 2]: for opts in [1, 0]: - cmd = ASM2WASM + [asm] + cmd = shared.ASM2WASM + [asm] if 'threads' in asm: cmd += ['--enable-threads'] wasm = asm.replace('.asm.js', '.fromasm') @@ -64,14 +61,14 @@ def test_asm2wasm(): print('..', basename, os.path.basename(wasm)) def do_asm2wasm_test(): - actual = run_command(cmd) + actual = support.run_command(cmd) # verify output if not os.path.exists(wasm): - fail_with_error('output .wast file %s does not exist' % wasm) - fail_if_not_identical_to_file(actual, wasm) + shared.fail_with_error('output .wast file %s does not exist' % wasm) + shared.fail_if_not_identical_to_file(actual, wasm) - binary_format_check(wasm, verify_final_result=False) + shared.binary_format_check(wasm, verify_final_result=False) # test both normally and with pass debug (so each inter-pass state # is validated) @@ -91,12 +88,12 @@ def test_asm2wasm(): del os.environ['BINARYEN_PASS_DEBUG'] # verify in wasm - if options.interpreter: + if shared.options.interpreter: # remove imports, spec interpreter doesn't know what to do with them - subprocess.check_call(WASM_OPT + ['--remove-imports', wasm], + subprocess.check_call(shared.WASM_OPT + ['--remove-imports', wasm], stdout=open('ztemp.wast', 'w'), stderr=subprocess.PIPE) - proc = subprocess.Popen([options.interpreter, 'ztemp.wast'], + proc = subprocess.Popen([shared.options.interpreter, 'ztemp.wast'], stderr=subprocess.PIPE) out, err = proc.communicate() if proc.returncode != 0: @@ -114,8 +111,8 @@ def test_asm2wasm(): print(err) except Exception: # failed to pretty-print - fail_with_error('wasm interpreter error: ' + err) - fail_with_error('wasm interpreter error') + shared.fail_with_error('wasm interpreter error: ' + err) + shared.fail_with_error('wasm interpreter error') # verify debug info if 'debugInfo' in asm: @@ -123,11 +120,11 @@ def test_asm2wasm(): cmd += ['--source-map', jsmap, '--source-map-url', 'http://example.org/' + jsmap, '-o', 'a.wasm'] - run_command(cmd) + support.run_command(cmd) if not os.path.isfile(jsmap): - fail_with_error('Debug info map not created: %s' % jsmap) + shared.fail_with_error('Debug info map not created: %s' % jsmap) with open(jsmap, 'rb') as actual: - fail_if_not_identical_to_file(actual.read(), wasm + '.map') + shared.fail_if_not_identical_to_file(actual.read(), wasm + '.map') with open('a.wasm', 'rb') as binary: url_section_name = bytes([16]) + bytes('sourceMappingURL', 'utf-8') url = 'http://example.org/' + jsmap @@ -136,21 +133,21 @@ def test_asm2wasm(): print(url_section_name) binary_contents = binary.read() if url_section_name not in binary_contents: - fail_with_error('source map url section not found in binary') + shared.fail_with_error('source map url section not found in binary') url_section_index = binary_contents.index(url_section_name) if url_section_contents not in binary_contents[url_section_index:]: - fail_with_error('source map url not found in url section') + shared.fail_with_error('source map url not found in url section') def test_asm2wasm_binary(): print('\n[ checking asm2wasm binary reading/writing... ]\n') - asmjs = os.path.join(options.binaryen_test, 'hello_world.asm.js') - delete_from_orbit('a.wasm') - delete_from_orbit('b.wast') - run_command(ASM2WASM + [asmjs, '-o', 'a.wasm']) + asmjs = os.path.join(shared.options.binaryen_test, 'hello_world.asm.js') + shared.delete_from_orbit('a.wasm') + shared.delete_from_orbit('b.wast') + support.run_command(shared.ASM2WASM + [asmjs, '-o', 'a.wasm']) assert open('a.wasm', 'rb').read()[0] == 0, 'we emit binary by default' - run_command(ASM2WASM + [asmjs, '-o', 'b.wast', '-S']) + support.run_command(shared.ASM2WASM + [asmjs, '-o', 'b.wast', '-S']) assert open('b.wast', 'rb').read()[0] != 0, 'we emit text with -S' diff --git a/scripts/test/binaryenjs.py b/scripts/test/binaryenjs.py index a102c2ae4..4f97ce889 100755 --- a/scripts/test/binaryenjs.py +++ b/scripts/test/binaryenjs.py @@ -17,24 +17,24 @@ import os import subprocess -from .support import run_command, node_has_webassembly, node_test_glue -from .shared import BINARYEN_JS, MOZJS, NODEJS, options, fail +from . import shared +from . import support def test_binaryen_js(): - if not (MOZJS or NODEJS): + if not (shared.MOZJS or shared.NODEJS): print('no vm to run binaryen.js tests') return - node_has_wasm = NODEJS and node_has_webassembly(NODEJS) + node_has_wasm = shared.NODEJS and support.node_has_webassembly(shared.NODEJS) - if not os.path.exists(BINARYEN_JS): + if not os.path.exists(shared.BINARYEN_JS): print('no binaryen.js build to test') return print('\n[ checking binaryen.js testcases... ]\n') - for s in sorted(os.listdir(os.path.join(options.binaryen_test, 'binaryen.js'))): + for s in sorted(os.listdir(os.path.join(shared.options.binaryen_test, 'binaryen.js'))): if not s.endswith('.js'): continue print(s) @@ -43,11 +43,11 @@ def test_binaryen_js(): f.write(''' console.warn = function(x) { console.log(x) }; ''') - binaryen_js = open(BINARYEN_JS).read() + binaryen_js = open(shared.BINARYEN_JS).read() f.write(binaryen_js) - if NODEJS: - f.write(node_test_glue()) - test_path = os.path.join(options.binaryen_test, 'binaryen.js', s) + if shared.NODEJS: + f.write(support.node_test_glue()) + test_path = os.path.join(shared.options.binaryen_test, 'binaryen.js', s) test_src = open(test_path).read() f.write(test_src) f.close() @@ -55,20 +55,20 @@ def test_binaryen_js(): def test(engine): cmd = [engine, 'a.js'] if 'fatal' not in s: - out = run_command(cmd, stderr=subprocess.STDOUT) + out = support.run_command(cmd, stderr=subprocess.STDOUT) else: # expect an error - the specific error code will depend on the vm - out = run_command(cmd, stderr=subprocess.STDOUT, expected_status=None) - expected = open(os.path.join(options.binaryen_test, 'binaryen.js', s + '.txt')).read() + out = support.run_command(cmd, stderr=subprocess.STDOUT, expected_status=None) + expected = open(os.path.join(shared.options.binaryen_test, 'binaryen.js', s + '.txt')).read() if expected not in out: - fail(out, expected) + shared.fail(out, expected) # run in all possible shells - if MOZJS: - test(MOZJS) - if NODEJS: + if shared.MOZJS: + test(shared.MOZJS) + if shared.NODEJS: if node_has_wasm or 'WebAssembly.' not in test_src: - test(NODEJS) + test(shared.NODEJS) else: print('Skipping ' + test_path + ' because WebAssembly might not be supported') diff --git a/scripts/test/generate_lld_tests.py b/scripts/test/generate_lld_tests.py index 2279482eb..c16415d7e 100755 --- a/scripts/test/generate_lld_tests.py +++ b/scripts/test/generate_lld_tests.py @@ -18,8 +18,9 @@ from __future__ import print_function import os import sys -from support import run_command -import shared + +from . import shared +from . import support def files_with_extensions(path, extensions): @@ -76,9 +77,9 @@ def generate_wast_files(llvm_bin, emscripten_root): link_cmd.append('--entry=main') try: - run_command(compile_cmd) - run_command(link_cmd) - run_command(shared.WASM_DIS + [wasm_path, '-o', wast_path]) + support.run_command(compile_cmd) + support.run_command(link_cmd) + support.run_command(shared.WASM_DIS + [wasm_path, '-o', wast_path]) finally: # Don't need the .o or .wasm files, don't leave them around shared.delete_from_orbit(obj_path) diff --git a/scripts/test/lld.py b/scripts/test/lld.py index 41db2baa2..46e1023ec 100755 --- a/scripts/test/lld.py +++ b/scripts/test/lld.py @@ -14,11 +14,8 @@ # limitations under the License. import os -from .support import run_command -from .shared import ( - fail_with_error, get_test_dir, get_tests, - WASM_EMSCRIPTEN_FINALIZE, fail_if_not_identical_to_file -) +from . import shared +from . import support def args_for_finalize(filename): @@ -35,7 +32,7 @@ def args_for_finalize(filename): def test_wasm_emscripten_finalize(): print('\n[ checking wasm-emscripten-finalize testcases... ]\n') - for wast_path in get_tests(get_test_dir('lld'), ['.wast']): + for wast_path in shared.get_tests(shared.get_test_dir('lld'), ['.wast']): print('..', wast_path) is_passive = '.passive.' in wast_path mem_file = wast_path + '.mem' @@ -51,25 +48,28 @@ def test_wasm_emscripten_finalize(): if ext != '.out' and not os.path.exists(expected_file): continue - cmd = WASM_EMSCRIPTEN_FINALIZE + [wast_path, '-S'] + ext_args + cmd = shared.WASM_EMSCRIPTEN_FINALIZE + [wast_path, '-S'] + \ + ext_args cmd += args_for_finalize(os.path.basename(wast_path)) - actual = run_command(cmd) + actual = support.run_command(cmd) if not os.path.exists(expected_file): print(actual) - fail_with_error('output ' + expected_file + ' does not exist') - fail_if_not_identical_to_file(actual, expected_file) + shared.fail_with_error('output ' + expected_file + + ' does not exist') + shared.fail_if_not_identical_to_file(actual, expected_file) if ext == '.mem.out': with open(mem_file) as mf: mem = mf.read() - fail_if_not_identical_to_file(mem, wast_path + '.mem.mem') + shared.fail_if_not_identical_to_file(mem, wast_path + + '.mem.mem') os.remove(mem_file) def update_lld_tests(): print('\n[ updatring wasm-emscripten-finalize testcases... ]\n') - for wast_path in get_tests(get_test_dir('lld'), ['.wast']): + for wast_path in shared.get_tests(shared.get_test_dir('lld'), ['.wast']): print('..', wast_path) is_passive = '.passive.' in wast_path mem_file = wast_path + '.mem' @@ -84,9 +84,10 @@ def update_lld_tests(): out_path = wast_path + ext if ext != '.out' and not os.path.exists(out_path): continue - cmd = WASM_EMSCRIPTEN_FINALIZE + [wast_path, '-S'] + ext_args + cmd = shared.WASM_EMSCRIPTEN_FINALIZE + [wast_path, '-S'] + \ + ext_args cmd += args_for_finalize(os.path.basename(wast_path)) - actual = run_command(cmd) + actual = support.run_command(cmd) with open(out_path, 'w') as o: o.write(actual) 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) |