summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xcheck.py49
-rwxr-xr-x[-rw-r--r--]scripts/test/asm2wasm.py11
-rwxr-xr-xscripts/test/lld.py8
-rwxr-xr-xscripts/test/s2wasm.py8
-rw-r--r--scripts/test/shared.py17
-rwxr-xr-xscripts/test/wasm2asm.py12
6 files changed, 43 insertions, 62 deletions
diff --git a/check.py b/check.py
index 2fbcfd598..fef48a92a 100755
--- a/check.py
+++ b/check.py
@@ -27,7 +27,7 @@ from scripts.test.shared import (
WASM_DIS, WASM_REDUCE, binary_format_check, delete_from_orbit, fail, fail_with_error,
fail_if_not_identical, fail_if_not_contained, has_vanilla_emcc,
has_vanilla_llvm, minify_check, num_failures, options, tests,
- requested, warnings, has_shell_timeout
+ requested, warnings, has_shell_timeout, fail_if_not_identical_to_file
)
import scripts.test.asm2wasm as asm2wasm
@@ -64,7 +64,7 @@ def run_wasm_opt_tests():
delete_from_orbit('a.wast')
cmd = WASM_OPT + [wast, '-o', 'a.wast', '-S']
run_command(cmd)
- fail_if_not_identical(open('a.wast').read(), open(wast).read())
+ fail_if_not_identical_to_file(open('a.wast').read(), wast)
print '\n[ checking wasm-opt binary reading/writing... ]\n'
@@ -111,16 +111,16 @@ def run_wasm_opt_tests():
if 'BINARYEN_PASS_DEBUG' in os.environ:
del os.environ['BINARYEN_PASS_DEBUG']
- fail_if_not_identical(actual, open(os.path.join(options.binaryen_test, 'passes', base + ('.bin' if binary else '') + '.txt'), 'rb').read())
+ expected_file = os.path.join(options.binaryen_test, 'passes',
+ base + ('.bin' if binary else '') + '.txt')
+ fail_if_not_identical_to_file(actual, expected_file)
if 'emit-js-wrapper' in t:
with open('a.js') as actual:
- with open(t + '.js') as expected:
- fail_if_not_identical(actual.read(), expected.read())
+ fail_if_not_identical_to_file(actual.read(), t + '.js')
if 'emit-spec-wrapper' in t:
with open('a.wat') as actual:
- with open(t + '.wat') as expected:
- fail_if_not_identical(actual.read(), expected.read())
+ fail_if_not_identical_to_file(actual.read(), t + '.wat')
print '\n[ checking wasm-opt parsing & printing... ]\n'
@@ -131,7 +131,8 @@ def run_wasm_opt_tests():
cmd = WASM_OPT + [os.path.join(options.binaryen_test, 'print', t), '--print']
print ' ', ' '.join(cmd)
actual, err = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()
- fail_if_not_identical(actual, open(os.path.join(options.binaryen_test, 'print', wasm + '.txt')).read())
+ expected_file = os.path.join(options.binaryen_test, 'print', wasm + '.txt')
+ fail_if_not_identical_to_file(actual, expected_file)
cmd = WASM_OPT + [os.path.join(options.binaryen_test, 'print', t), '--print-minified']
print ' ', ' '.join(cmd)
actual, err = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()
@@ -148,10 +149,7 @@ def run_wasm_opt_tests():
actual = run_command(cmd)
actual = actual.replace('printing before:\n', '')
- expected = open(f, 'rb').read()
-
- if actual != expected:
- fail(actual, expected)
+ fail_if_not_identical_to_file(actual, f)
binary_format_check(t, wasm_as_args=['-g']) # test with debuginfo
binary_format_check(t, wasm_as_args=[], binary_suffix='.fromBinary.noDebugInfo') # test without debuginfo
@@ -170,10 +168,7 @@ def run_wasm_dis_tests():
actual = run_command(cmd)
- with open(t + '.fromBinary') as f:
- expected = f.read()
- if actual != expected:
- fail(actual, expected)
+ fail_if_not_identical_to_file(actual, t + '.fromBinary')
def run_wasm_merge_tests():
print '\n[ checking wasm-merge... ]\n'
@@ -194,10 +189,8 @@ def run_wasm_merge_tests():
out = t + '.combined'
if finalize: out += '.finalized'
if opt: out += '.opt'
- with open(out) as f:
- fail_if_not_identical(f.read(), actual)
- with open(out + '.stdout') as f:
- fail_if_not_identical(f.read(), stdout)
+ fail_if_not_identical_to_file(actual, out)
+ fail_if_not_identical_to_file(stdout, out + '.stdout')
def run_crash_tests():
print "\n[ checking we don't crash on tricky inputs... ]\n"
@@ -224,8 +217,7 @@ def run_ctor_eval_tests():
stdout = run_command(cmd)
actual = open('a.wast').read()
out = t + '.out'
- with open(out) as f:
- fail_if_not_identical(f.read(), actual)
+ fail_if_not_identical_to_file(actual, out)
def run_wasm_metadce_tests():
print '\n[ checking wasm-metadce ]\n'
@@ -240,10 +232,8 @@ def run_wasm_metadce_tests():
stdout = run_command(cmd)
expected = t + '.dced'
with open('a.wast') as seen:
- with open(expected) as correct:
- fail_if_not_identical(seen.read(), correct.read())
- with open(expected + '.stdout') as correct:
- fail_if_not_identical(stdout, correct.read())
+ fail_if_not_identical_to_file(seen.read(), expected)
+ fail_if_not_identical_to_file(stdout, expected + '.stdout')
def run_wasm_reduce_tests():
print '\n[ checking wasm-reduce ]\n'
@@ -259,8 +249,7 @@ def run_wasm_reduce_tests():
expected = t + '.txt'
run_command(WASM_DIS + ['c.wasm', '-o', 'a.wast'])
with open('a.wast') as seen:
- with open(expected) as correct:
- fail_if_not_identical(seen.read(), correct.read())
+ fail_if_not_identical_to_file(seen.read(), expected)
def run_spec_tests():
print '\n[ checking wasm-shell spec testcases... ]\n'
@@ -539,9 +528,7 @@ def run_gcc_torture_tests():
# Also removes debug directory produced on Mac OS
shutil.rmtree(output_file + '.dSYM')
- expected = open(expected).read()
- if actual != expected:
- fail(actual, expected)
+ fail_if_not_identical_to_file(actual, expected)
def run_emscripten_tests():
print '\n[ checking wasm.js methods... ]\n'
diff --git a/scripts/test/asm2wasm.py b/scripts/test/asm2wasm.py
index abcd41bb4..3fb94fd1d 100644..100755
--- a/scripts/test/asm2wasm.py
+++ b/scripts/test/asm2wasm.py
@@ -20,7 +20,7 @@ import subprocess
from support import run_command
from shared import (
ASM2WASM, WASM_OPT, binary_format_check, delete_from_orbit,
- fail, fail_with_error, fail_if_not_identical, options, tests
+ fail_with_error, options, tests, fail_if_not_identical_to_file
)
@@ -69,9 +69,7 @@ def test_asm2wasm():
# 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)
+ fail_if_not_identical_to_file(actual, wasm)
binary_format_check(wasm, verify_final_result=False)
@@ -128,9 +126,8 @@ def test_asm2wasm():
run_command(cmd)
if not os.path.isfile(jsmap):
fail_with_error('Debug info map not created: %s' % jsmap)
- with open(wasm + '.map', 'rb') as expected:
- with open(jsmap, 'rb') as actual:
- fail_if_not_identical(actual.read(), expected.read())
+ with open(jsmap, 'rb') as actual:
+ fail_if_not_identical_to_file(actual.read(), wasm + '.map')
with open('a.wasm', 'rb') as binary:
url_section_name = bytearray([16]) + bytearray('sourceMappingURL')
url = 'http://example.org/' + jsmap
diff --git a/scripts/test/lld.py b/scripts/test/lld.py
index f6aa91e6f..01ed51a4a 100755
--- a/scripts/test/lld.py
+++ b/scripts/test/lld.py
@@ -17,8 +17,8 @@
import os
from support import run_command
from shared import (
- fail, fail_with_error, files_with_pattern, options,
- WASM_EMSCRIPTEN_FINALIZE
+ fail_with_error, files_with_pattern, options,
+ WASM_EMSCRIPTEN_FINALIZE, fail_if_not_identical_to_file
)
@@ -44,9 +44,7 @@ def test_wasm_emscripten_finalize():
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)
+ fail_if_not_identical_to_file(actual, expected_file)
if __name__ == '__main__':
diff --git a/scripts/test/s2wasm.py b/scripts/test/s2wasm.py
index a3345f87b..0e0bec621 100755
--- a/scripts/test/s2wasm.py
+++ b/scripts/test/s2wasm.py
@@ -17,8 +17,8 @@
import os
from support import run_command
from shared import (
- fail, fail_with_error, fail_if_not_contained,
- options, S2WASM, WASM_SHELL
+ fail_with_error, fail_if_not_contained,
+ options, S2WASM, WASM_SHELL, fail_if_not_identical_to_file
)
@@ -64,9 +64,7 @@ def test_s2wasm():
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)
+ fail_if_not_identical_to_file(actual, expected_file)
# verify with options
cmd = S2WASM + [full, '--global-base=1024'] + stack_alloc
diff --git a/scripts/test/shared.py b/scripts/test/shared.py
index 23f10ca2c..9921d0ada 100644
--- a/scripts/test/shared.py
+++ b/scripts/test/shared.py
@@ -344,17 +344,17 @@ def fail_with_error(msg):
raise
-def fail(actual, expected):
+def fail(actual, expected, fromfile='expected'):
diff_lines = difflib.unified_diff(
expected.split('\n'), actual.split('\n'),
- fromfile='expected', tofile='actual')
+ fromfile=fromfile, tofile='actual')
diff_str = ''.join([a.rstrip() + '\n' for a in diff_lines])[:]
fail_with_error("incorrect output, diff:\n\n%s" % diff_str)
-def fail_if_not_identical(actual, expected):
+def fail_if_not_identical(actual, expected, fromfile='expected'):
if expected != actual:
- fail(actual, expected)
+ fail(actual, expected, fromfile=fromfile)
def fail_if_not_contained(actual, expected):
@@ -362,6 +362,11 @@ def fail_if_not_contained(actual, expected):
fail(actual, expected)
+def fail_if_not_identical_to_file(actual, expected_file):
+ with open(expected_file, 'rb') as f:
+ fail_if_not_identical(actual, f.read(), fromfile=expected_file)
+
+
if len(requested) == 0:
tests = sorted(os.listdir(os.path.join(options.binaryen_test)))
else:
@@ -401,10 +406,8 @@ def binary_format_check(wast, verify_final_result=True, wasm_as_args=['-g'],
subprocess.check_call(cmd, stdout=subprocess.PIPE)
if verify_final_result:
- expected = open(wast + binary_suffix).read()
actual = open('ab.wast').read()
- if actual != expected:
- fail(actual, expected)
+ fail_if_not_identical_to_file(actual, wast + binary_suffix)
return 'ab.wast'
diff --git a/scripts/test/wasm2asm.py b/scripts/test/wasm2asm.py
index 6e6b32c81..81cb9b5c5 100755
--- a/scripts/test/wasm2asm.py
+++ b/scripts/test/wasm2asm.py
@@ -4,7 +4,8 @@ import os
from support import run_command
from shared import (
- WASM2ASM, MOZJS, NODEJS, fail_if_not_identical, options, tests
+ WASM2ASM, MOZJS, NODEJS, fail_if_not_identical, options, tests,
+ fail_if_not_identical_to_file
)
# tests with i64s, invokes, etc.
@@ -33,8 +34,7 @@ def test_wasm2asm_output():
cmd = WASM2ASM + [os.path.join(options.binaryen_test, wasm)]
out = run_command(cmd)
- expected = open(expected_file).read()
- fail_if_not_identical(out, expected)
+ fail_if_not_identical_to_file(out, expected_file)
if not NODEJS and not MOZJS:
print 'No JS interpreters. Skipping spec tests.'
@@ -79,13 +79,11 @@ def test_asserts_output():
wasm = os.path.join(options.binaryen_test, wasm)
cmd = WASM2ASM + [wasm, '--allow-asserts']
out = run_command(cmd)
- expected = open(asserts_expected_file).read()
- fail_if_not_identical(out, expected)
+ fail_if_not_identical_to_file(out, asserts_expected_file)
cmd += ['--pedantic']
out = run_command(cmd)
- expected = open(traps_expected_file).read()
- fail_if_not_identical(out, expected)
+ fail_if_not_identical_to_file(out, traps_expected_file)
def test_wasm2asm():