def test_wasm2js(): print('\n[ checking wasm2js testcases... ]\n') check_for_stale_files() if shared.skip_if_on_windows('wasm2js'): return test_wasm2js_output() test_asserts_output()
def update_example_tests(): print('\n[ checking example testcases... ]\n') for src in shared.get_tests(shared.get_test_dir('example')): basename = os.path.basename(src) output_file = os.path.join(shared.options.binaryen_bin, 'example') libdir = os.path.join(shared.BINARYEN_INSTALL_DIR, 'lib') cmd = [ '-I' + os.path.join(shared.options.binaryen_root, 'src'), '-g', '-pthread', '-o', output_file ] if not src.endswith(('.c', '.cpp')): continue expected = os.path.splitext(src)[0] + '.txt' # windows + gcc will need some work if shared.skip_if_on_windows('gcc'): return # build the C file separately extra = [ os.environ.get('CC') or 'gcc', src, '-c', '-o', 'example.o', '-I' + os.path.join(shared.options.binaryen_root, 'src'), '-g', '-L' + libdir, '-pthread' ] print('build: ', ' '.join(extra)) if src.endswith('.cpp'): extra += ['-std=c++' + str(shared.cxx_standard)] print(os.getcwd()) subprocess.check_call(extra) # Link against the binaryen C library DSO, using rpath cmd = [ 'example.o', '-L' + libdir, '-lbinaryen', '-Wl,-rpath,' + os.path.abspath(libdir) ] + cmd print(' ', basename, src, expected) if os.environ.get('COMPILER_FLAGS'): for f in os.environ.get('COMPILER_FLAGS').split(' '): cmd.append(f) cmd = [ os.environ.get('CXX') or 'g++', '-std=c++' + str(shared.cxx_standard) ] + cmd try: print('link: ', ' '.join(cmd)) subprocess.check_call(cmd) print('run...', output_file) proc = subprocess.Popen([output_file], stdout=subprocess.PIPE, stderr=subprocess.PIPE) actual, err = proc.communicate() assert proc.returncode == 0, [proc.returncode, actual, err] with open(expected, 'wb') as o: o.write(actual) finally: os.remove(output_file)
def run_gcc_tests(): print('\n[ checking native gcc testcases...]\n') if not shared.NATIVECC or not shared.NATIVEXX: shared.fail_with_error( 'Native compiler (e.g. gcc/g++) was not found in PATH!') return # windows + gcc will need some work if shared.skip_if_on_windows('gcc'): return for t in sorted(os.listdir(shared.get_test_dir('example'))): output_file = 'example' cmd = [ '-I' + os.path.join(shared.options.binaryen_root, 't'), '-g', '-pthread', '-o', output_file ] if not t.endswith(('.c', '.cpp')): continue src = os.path.join(shared.get_test_dir('example'), t) expected = os.path.join(shared.get_test_dir('example'), '.'.join(t.split('.')[:-1]) + '.txt') # build the C file separately libpath = os.path.join(os.path.dirname(shared.options.binaryen_bin), 'lib') extra = [ shared.NATIVECC, src, '-c', '-o', 'example.o', '-I' + os.path.join(shared.options.binaryen_root, 'src'), '-g', '-L' + libpath, '-pthread' ] if src.endswith('.cpp'): extra += ['-std=c++' + str(shared.cxx_standard)] if os.environ.get('COMPILER_FLAGS'): for f in os.environ.get('COMPILER_FLAGS').split(' '): extra.append(f) print('build: ', ' '.join(extra)) subprocess.check_call(extra) # Link against the binaryen C library DSO, using an executable-relative rpath cmd = ['example.o', '-L' + libpath, '-lbinaryen' ] + cmd + ['-Wl,-rpath,' + libpath] print(' ', t, src, expected) if os.environ.get('COMPILER_FLAGS'): for f in os.environ.get('COMPILER_FLAGS').split(' '): cmd.append(f) cmd = [shared.NATIVEXX, '-std=c++' + str(shared.cxx_standard)] + cmd print('link: ', ' '.join(cmd)) subprocess.check_call(cmd) print('run...', output_file) actual = subprocess.check_output([os.path.abspath(output_file) ]).decode('utf-8') os.remove(output_file) shared.fail_if_not_identical_to_file(actual, expected)
def run_unittest(): print('\n[ checking unit tests...]\n') # windows has some failures that need to be investigated if shared.skip_if_on_windows('unit'): return # equivalent to `python -m unittest discover -s ./test -v` suite = unittest.defaultTestLoader.discover( os.path.dirname(shared.options.binaryen_test)) result = unittest.TextTestRunner( verbosity=2, failfast=shared.options.abort_on_first_failure).run(suite) shared.num_failures += len(result.errors) + len(result.failures) if shared.options.abort_on_first_failure and shared.num_failures: raise Exception("unittest failed")
def run_spec_tests(): print('\n[ checking wasm-shell spec testcases... ]\n') for wast in shared.options.spec_tests: base = os.path.basename(wast) print('..', base) # windows has some failures that need to be investigated if base == 'names.wast' and shared.skip_if_on_windows('spec: ' + base): continue # FIXME Reenable this after updating interpreter for EH if base == 'exception-handling.wast': continue def run_spec_test(wast): cmd = shared.WASM_SHELL + [wast] output = support.run_command(cmd, stderr=subprocess.PIPE) # filter out binaryen interpreter logging that the spec suite # doesn't expect filtered = [ line for line in output.splitlines() if not line.startswith('[trap') ] return '\n'.join(filtered) + '\n' def run_opt_test(wast): # check optimization validation cmd = shared.WASM_OPT + [wast, '-O', '-all'] support.run_command(cmd) def check_expected(actual, expected): if expected and os.path.exists(expected): expected = open(expected).read() print(' (using expected output)') actual = actual.strip() expected = expected.strip() if actual != expected: shared.fail(actual, expected) expected = os.path.join(shared.get_test_dir('spec'), 'expected-output', base + '.log') # some spec tests should fail (actual process failure, not just assert_invalid) try: actual = run_spec_test(wast) except Exception as e: if ('wasm-validator error' in str(e) or 'parse exception' in str(e)) and '.fail.' in base: print('<< test failed as expected >>') continue # don't try all the binary format stuff TODO else: shared.fail_with_error(str(e)) check_expected(actual, expected) # skip binary checks for tests that reuse previous modules by name, as that's a wast-only feature if 'exports.wast' in base: # FIXME continue # check binary format. here we can verify execution of the final # result, no need for an output verification # some wast files cannot be split: # * comments.wast: contains characters that are not valid utf-8, # so our string splitting code fails there # FIXME Remove reference type tests from this list after nullref is # implemented in V8 if base not in [ 'comments.wast', 'ref_null.wast', 'ref_is_null.wast', 'ref_func.wast', 'old_select.wast' ]: split_num = 0 actual = '' for module, asserts in support.split_wast(wast): print(' testing split module', split_num) split_num += 1 support.write_wast('split.wast', module, asserts) run_spec_test( 'split.wast' ) # before binary stuff - just check it's still ok split out run_opt_test('split.wast' ) # also that our optimizer doesn't break on it result_wast = shared.binary_format_check( 'split.wast', verify_final_result=False, original_wast=wast) # add the asserts, and verify that the test still passes open(result_wast, 'a').write('\n' + '\n'.join(asserts)) actual += run_spec_test(result_wast) # compare all the outputs to the expected output check_expected( actual, os.path.join(shared.get_test_dir('spec'), 'expected-output', base + '.log')) else: # handle unsplittable wast files run_spec_test(wast)