diff options
Diffstat (limited to 'scripts/test')
-rwxr-xr-x | scripts/test/generate_lld_tests.py | 77 | ||||
-rwxr-xr-x | scripts/test/lld.py | 32 | ||||
-rw-r--r-- | scripts/test/shared.py | 1 | ||||
-rwxr-xr-x | scripts/test/wasm2js.py | 46 |
4 files changed, 119 insertions, 37 deletions
diff --git a/scripts/test/generate_lld_tests.py b/scripts/test/generate_lld_tests.py index 4b18107e1..31634e7b0 100755 --- a/scripts/test/generate_lld_tests.py +++ b/scripts/test/generate_lld_tests.py @@ -22,48 +22,58 @@ import shared def files_with_extensions(path, extensions): for file in sorted(os.listdir(path)): - _, ext = os.path.splitext(file) + ext = os.path.splitext(file)[1] if ext in extensions: yield file, ext -def generate_wast_files(clang_bin, lld_bin, emscripten_root): +def generate_wast_files(llvm_bin, emscripten_root): print '\n[ building wast files from C sources... ]\n' lld_path = os.path.join(shared.options.binaryen_test, 'lld') for src_file, ext in files_with_extensions(lld_path, ['.c', '.cpp']): print '..', src_file - try: - obj_file = src_file.replace(ext, '.o') + obj_file = src_file.replace(ext, '.o') + + src_path = os.path.join(lld_path, src_file) + obj_path = os.path.join(lld_path, obj_file) + + wasm_file = src_file.replace(ext, '.wasm') + wast_file = src_file.replace(ext, '.wast') - src_path = os.path.join(lld_path, src_file) - obj_path = os.path.join(lld_path, obj_file) - run_command([ - clang_bin, src_path, '-o', obj_path, - '--target=wasm32-unknown-unknown-wasm', - '-c', - '-nostdinc', - '-Xclang', '-nobuiltininc', - '-Xclang', '-nostdsysteminc', - '-Xclang', '-I%s/system/include' % emscripten_root, - '-O1', - ]) + obj_path = os.path.join(lld_path, obj_file) + wasm_path = os.path.join(lld_path, wasm_file) + wast_path = os.path.join(lld_path, wast_file) + is_shared = 'shared' in src_file - wasm_file = src_file.replace(ext, '.wasm') - wast_file = src_file.replace(ext, '.wast') + compile_cmd = [ + os.path.join(llvm_bin, 'clang'), src_path, '-o', obj_path, + '--target=wasm32-unknown-unknown-wasm', + '-c', + '-nostdinc', + '-Xclang', '-nobuiltininc', + '-Xclang', '-nostdsysteminc', + '-Xclang', '-I%s/system/include' % emscripten_root, + '-O1', + ] - obj_path = os.path.join(lld_path, obj_file) - wasm_path = os.path.join(lld_path, wasm_file) - wast_path = os.path.join(lld_path, wast_file) - run_command([ - lld_bin, '-flavor', 'wasm', - '-z', '-stack-size=1048576', - obj_path, '-o', wasm_path, - '--entry=main', - '--allow-undefined', - '--export', '__wasm_call_ctors', - '--global-base=568', - ]) + link_cmd = [ + os.path.join(llvm_bin, 'wasm-ld'), '-flavor', 'wasm', + '-z', '-stack-size=1048576', + obj_path, '-o', wasm_path, + '--entry=main', + '--allow-undefined', + '--export', '__wasm_call_ctors', + '--global-base=568', + ] + if is_shared: + compile_cmd.append('-fPIC') + compile_cmd.append('-fvisibility=default') + link_cmd.append('-shared') + + try: + run_command(compile_cmd) + run_command(link_cmd) run_command(shared.WASM_DIS + [wasm_path, '-o', wast_path]) finally: # Don't need the .o or .wasm files, don't leave them around @@ -72,8 +82,7 @@ def generate_wast_files(clang_bin, lld_bin, emscripten_root): if __name__ == '__main__': - if len(sys.argv) != 4: - print 'Usage: generate_lld_tests.py [path/to/clang] [path/to/lld] \ -[path/to/emscripten]' + if len(shared.options.positional_args) != 2: + print 'Usage: generate_lld_tests.py [llvm/bin/dir] [path/to/emscripten]' sys.exit(1) - generate_wast_files(*sys.argv[1:]) + generate_wast_files(*shared.options.positional_args) diff --git a/scripts/test/lld.py b/scripts/test/lld.py index 94736f03f..fae551f0d 100755 --- a/scripts/test/lld.py +++ b/scripts/test/lld.py @@ -21,6 +21,13 @@ from shared import ( ) +def args_for_finalize(filename): + if 'shared' in filename: + return ['--side-module'] + else: + return ['--global-base=568', '--initial-stack-pointer=16384'] + + def test_wasm_emscripten_finalize(): print '\n[ checking wasm-emscripten-finalize testcases... ]\n' @@ -36,8 +43,8 @@ def test_wasm_emscripten_finalize(): if ext != '.out' and not os.path.exists(expected_file): continue - cmd = (WASM_EMSCRIPTEN_FINALIZE + - [wast_path, '-S', '--global-base=568', '--initial-stack-pointer=16384'] + ext_args) + cmd = WASM_EMSCRIPTEN_FINALIZE + [wast_path, '-S'] + ext_args + cmd += args_for_finalize(os.path.basename(wast_path)) actual = run_command(cmd) if not os.path.exists(expected_file): @@ -51,5 +58,26 @@ def test_wasm_emscripten_finalize(): os.remove(mem_file) +def update_lld_tests(): + print '\n[ updatring wasm-emscripten-finalize testcases... ]\n' + + for wast_path in files_with_pattern(options.binaryen_test, 'lld', '*.wast'): + print '..', wast_path + mem_file = wast_path + '.mem' + extension_arg_map = { + '.out': [], + '.mem.out': ['--separate-data-segments', mem_file + '.mem'], + } + for ext, ext_args in extension_arg_map.items(): + 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 += args_for_finalize(os.path.basename(wast_path)) + actual = run_command(cmd) + with open(out_path, 'w') as o: + o.write(actual) + + if __name__ == '__main__': test_wasm_emscripten_finalize() diff --git a/scripts/test/shared.py b/scripts/test/shared.py index 7c456db8f..7723f7cee 100644 --- a/scripts/test/shared.py +++ b/scripts/test/shared.py @@ -169,7 +169,6 @@ ASM2WASM = [os.path.join(options.binaryen_bin, 'asm2wasm')] WASM2JS = [os.path.join(options.binaryen_bin, 'wasm2js')] WASM_CTOR_EVAL = [os.path.join(options.binaryen_bin, 'wasm-ctor-eval')] WASM_SHELL = [os.path.join(options.binaryen_bin, 'wasm-shell')] -WASM_MERGE = [os.path.join(options.binaryen_bin, 'wasm-merge')] WASM_REDUCE = [os.path.join(options.binaryen_bin, 'wasm-reduce')] WASM_METADCE = [os.path.join(options.binaryen_bin, 'wasm-metadce')] WASM_EMSCRIPTEN_FINALIZE = [os.path.join(options.binaryen_bin, diff --git a/scripts/test/wasm2js.py b/scripts/test/wasm2js.py index 9a72895c1..afa399da2 100755 --- a/scripts/test/wasm2js.py +++ b/scripts/test/wasm2js.py @@ -106,5 +106,51 @@ def test_wasm2js(): test_asserts_output() +def update_wasm2js_tests(): + print '\n[ checking wasm2js ]\n' + + for wasm in tests + spec_tests + extra_wasm2js_tests: + if not wasm.endswith('.wast'): + continue + + if os.path.basename(wasm) in wasm2js_blacklist: + continue + + asm = os.path.basename(wasm).replace('.wast', '.2asm.js') + expected_file = os.path.join(wasm2js_dir, asm) + + # we run wasm2js on tests and spec tests only if the output + # exists - only some work so far. the tests in extra are in + # the test/wasm2js dir and so are specific to wasm2js, and + # we run all of those. + if wasm not in extra_wasm2js_tests and not os.path.exists(expected_file): + continue + + print '..', wasm + + cmd = WASM2JS + [os.path.join('test', wasm)] + out = run_command(cmd) + with open(expected_file, 'w') as o: + o.write(out) + + for wasm in assert_tests: + print '..', wasm + + 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('test', asserts) + traps_expected_file = os.path.join('test', traps) + + cmd = WASM2JS + [os.path.join(wasm2js_dir, wasm), '--allow-asserts'] + out = run_command(cmd) + with open(asserts_expected_file, 'w') as o: + o.write(out) + + cmd += ['--pedantic'] + out = run_command(cmd) + with open(traps_expected_file, 'w') as o: + o.write(out) + + if __name__ == "__main__": test_wasm2js() |