def test_s2wasm(): print '\n[ checking .s testcases... ]\n' for dot_s_dir in ['dot_s', 'llvm_autogenerated']: dot_s_path = os.path.join(options.binaryen_test, dot_s_dir) for s in sorted(os.listdir(dot_s_path)): if not s.endswith('.s'): continue print '..', s wasm = s.replace('.s', '.wast') full = os.path.join(options.binaryen_test, dot_s_dir, s) stack_alloc = (['--allocate-stack=1024'] if dot_s_dir == 'llvm_autogenerated' else []) cmd = S2WASM + [full, '--emscripten-glue'] + stack_alloc if s.startswith('start_'): cmd.append('--start') actual = run_command(cmd) # verify output expected_file = os.path.join(options.binaryen_test, dot_s_dir, wasm) if not os.path.exists(expected_file): print actual fail_with_error('output ' + expected_file + ' does not exist') expected = open(expected_file, 'rb').read() if actual != expected: fail(actual, expected) # verify with options cmd = S2WASM + [full, '--global-base=1024'] + stack_alloc run_command(cmd) # run wasm-shell on the .wast to verify that it parses cmd = WASM_SHELL + [expected_file] run_command(cmd)
def test_wasm_emscripten_finalize(): print '\n[ checking wasm-emscripten-finalize testcases... ]\n' extension_arg_map = { '.out': [], '.jscall.out': ['--emscripten-reserved-function-pointers=3'], } for wast_path in files_with_pattern(options.binaryen_test, 'lld', '*.wast'): print '..', wast_path for ext, ext_args in extension_arg_map.items(): expected_file = wast_path + ext if ext != '.out' and not os.path.exists(expected_file): continue cmd = (WASM_EMSCRIPTEN_FINALIZE + [wast_path, '-S', '--global-base=568'] + ext_args) actual = run_command(cmd) if not os.path.exists(expected_file): print actual fail_with_error('output ' + expected_file + ' does not exist') expected = open(expected_file, 'rb').read() if actual != expected: fail(actual, expected)
def test_s2wasm(): print '\n[ checking .s testcases... ]\n' cmd = S2WASM + [ os.path.join(options.binaryen_test, 'dot_s', 'basics.s'), '--import-memory' ] output = run_command(cmd) fail_if_not_contained(output, '(import "env" "memory" (memory $0 1))') extension_arg_map = { '.wast': [], '.clamp.wast': ['--trap-mode=clamp'], '.js.wast': ['--trap-mode=js'], '.jscall.wast': ['--emscripten-reserved-function-pointers=3'], } for dot_s_dir in ['dot_s', 'llvm_autogenerated']: dot_s_path = os.path.join(options.binaryen_test, dot_s_dir) for s in sorted(os.listdir(dot_s_path)): if not s.endswith('.s'): continue print '..', s for ext, ext_args in extension_arg_map.iteritems(): wasm = s.replace('.s', ext) expected_file = os.path.join(options.binaryen_test, dot_s_dir, wasm) expected_exists = os.path.exists(expected_file) if ext != '.wast' and not expected_exists: continue full = os.path.join(options.binaryen_test, dot_s_dir, s) stack_alloc = (['--allocate-stack=1024'] if dot_s_dir == 'llvm_autogenerated' else []) cmd = S2WASM + [full, '--emscripten-glue' ] + stack_alloc + ext_args if s.startswith('start_'): cmd.append('--start') actual = run_command(cmd) # verify output if not expected_exists: print actual fail_with_error('output ' + expected_file + ' does not exist') expected = open(expected_file, 'rb').read() if actual != expected: fail(actual, expected) # verify with options cmd = S2WASM + [full, '--global-base=1024'] + stack_alloc run_command(cmd) # run wasm-shell on the .wast to verify that it parses cmd = WASM_SHELL + [expected_file] run_command(cmd)
def do_asm2wasm_test(): actual = run_command(cmd) # verify output if not os.path.exists(wasm): fail_with_error('output .wast file %s does not exist' % wasm) expected = open(wasm, 'rb').read() if actual != expected: fail(actual, expected) binary_format_check(wasm, verify_final_result=False)
def test(engine): cmd = [engine, 'a.js'] if 'fatal' not in s: out = 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() if expected not in out: fail(out, expected)
def test_wasm_emscripten_finalize(): print '\n[ checking wasm-emscripten-finalize testcases... ]\n' for wast_path in files_with_pattern(options.binaryen_test, 'lld', '*.wast'): print '..', wast_path expected_file = wast_path + '.out' cmd = WASM_EMSCRIPTEN_FINALIZE + [wast_path, '-S'] actual = run_command(cmd) if not os.path.exists(expected_file): print actual fail_with_error('output ' + expected_file + ' does not exist') expected = open(expected_file, 'rb').read() if actual != expected: fail(actual, expected)
def test_wasm_link_metadata(): print '\n[ checking wasm-link-metadata testcases... ]\n' for obj_path in files_with_pattern(options.binaryen_test, 'lld', '*.o'): print '..', obj_path expected_file = obj_path.replace('.o', '.json') cmd = WASM_LINK_METADATA + [obj_path] actual = run_command(cmd) if not os.path.exists(expected_file): print actual fail_with_error('output ' + expected_file + ' does not exist') expected = open(expected_file, 'rb').read() if actual != expected: fail(actual, expected)