summaryrefslogtreecommitdiff
path: root/scripts/test
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/test')
-rwxr-xr-xscripts/test/asm2wasm.py42
-rwxr-xr-xscripts/test/binaryenjs.py16
-rwxr-xr-xscripts/test/lld.py14
-rw-r--r--scripts/test/shared.py71
-rw-r--r--scripts/test/support.py32
-rwxr-xr-xscripts/test/wasm2js.py26
6 files changed, 95 insertions, 106 deletions
diff --git a/scripts/test/asm2wasm.py b/scripts/test/asm2wasm.py
index fa38b9c3b..356d8c0f2 100755
--- a/scripts/test/asm2wasm.py
+++ b/scripts/test/asm2wasm.py
@@ -17,15 +17,15 @@
import os
import subprocess
-from support import run_command
-from shared import (
+from .support import run_command
+from .shared import (
ASM2WASM, WASM_OPT, binary_format_check, delete_from_orbit,
fail_with_error, options, tests, fail_if_not_identical_to_file
)
def test_asm2wasm():
- print '[ checking asm2wasm testcases... ]\n'
+ print('[ checking asm2wasm testcases... ]\n')
for asm in tests:
if not asm.endswith('.asm.js'):
@@ -54,7 +54,7 @@ def test_asm2wasm():
cmd += ['--no-legalize-javascript-ffi']
if precise and opts:
# test mem init importing
- open('a.mem', 'wb').write(asm)
+ open('a.mem', 'w').write(asm)
cmd += ['--mem-init=a.mem']
if asm[0] == 'e':
cmd += ['--mem-base=1024']
@@ -63,7 +63,7 @@ def test_asm2wasm():
if 'i64' in asm or 'wasm-only' in asm or 'noffi' in asm:
cmd += ['--wasm-only']
wasm = os.path.join(options.binaryen_test, wasm)
- print '..', asm, wasm
+ print('..', asm, wasm)
def do_asm2wasm_test():
actual = run_command(cmd)
@@ -80,10 +80,10 @@ def test_asm2wasm():
old_pass_debug = os.environ.get('BINARYEN_PASS_DEBUG')
try:
os.environ['BINARYEN_PASS_DEBUG'] = '1'
- print "With BINARYEN_PASS_DEBUG=1:"
+ print("With BINARYEN_PASS_DEBUG=1:")
do_asm2wasm_test()
del os.environ['BINARYEN_PASS_DEBUG']
- print "With BINARYEN_PASS_DEBUG disabled:"
+ print("With BINARYEN_PASS_DEBUG disabled:")
do_asm2wasm_test()
finally:
if old_pass_debug is not None:
@@ -107,13 +107,13 @@ def test_asm2wasm():
start, end = reported.split('-')
start_line, start_col = map(int, start.split('.'))
lines = open('ztemp.wast').read().split('\n')
- print
- print '=' * 80
- print lines[start_line - 1]
- print (' ' * (start_col - 1)) + '^'
- print (' ' * (start_col - 2)) + '/_\\'
- print '=' * 80
- print err
+ print()
+ print('=' * 80)
+ print(lines[start_line - 1])
+ print((' ' * (start_col - 1)) + '^')
+ print((' ' * (start_col - 2)) + '/_\\')
+ print('=' * 80)
+ print(err)
except Exception:
# failed to pretty-print
fail_with_error('wasm interpreter error: ' + err)
@@ -131,12 +131,12 @@ def test_asm2wasm():
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_section_name = bytes([16]) + bytes('sourceMappingURL', 'utf-8')
url = 'http://example.org/' + jsmap
assert len(url) < 256, 'name too long'
- url_section_contents = bytearray([len(url)]) + bytearray(url)
- print url_section_name
- binary_contents = bytearray(binary.read())
+ url_section_contents = bytes([len(url)]) + bytes(url, 'utf-8')
+ 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')
url_section_index = binary_contents.index(url_section_name)
@@ -145,15 +145,15 @@ def test_asm2wasm():
def test_asm2wasm_binary():
- print '\n[ checking asm2wasm binary reading/writing... ]\n'
+ 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'])
- assert open('a.wasm', 'rb').read()[0] == '\0', 'we emit binary by default'
+ assert open('a.wasm', 'rb').read()[0] == 0, 'we emit binary by default'
run_command(ASM2WASM + [asmjs, '-o', 'b.wast', '-S'])
- assert open('b.wast', 'rb').read()[0] != '\0', 'we emit text with -S'
+ assert open('b.wast', 'rb').read()[0] != 0, 'we emit text with -S'
if __name__ == '__main__':
diff --git a/scripts/test/binaryenjs.py b/scripts/test/binaryenjs.py
index 2eb2c4683..f701f25c1 100755
--- a/scripts/test/binaryenjs.py
+++ b/scripts/test/binaryenjs.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
#
# Copyright 2016 WebAssembly Community Group participants
#
@@ -17,27 +17,27 @@
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 .support import run_command, node_has_webassembly, node_test_glue
+from .shared import BINARYEN_JS, MOZJS, NODEJS, options, fail
def test_binaryen_js():
if not (MOZJS or NODEJS):
- print 'no vm to run binaryen.js tests'
+ print('no vm to run binaryen.js tests')
return
node_has_wasm = NODEJS and node_has_webassembly(NODEJS)
if not os.path.exists(BINARYEN_JS):
- print 'no binaryen.js build to test'
+ print('no binaryen.js build to test')
return
- print '\n[ checking binaryen.js testcases... ]\n'
+ print('\n[ checking binaryen.js testcases... ]\n')
for s in sorted(os.listdir(os.path.join(options.binaryen_test, 'binaryen.js'))):
if not s.endswith('.js'):
continue
- print s
+ print(s)
f = open('a.js', 'w')
# avoid stdout/stderr ordering issues in some js shells - use just stdout
f.write('''
@@ -70,7 +70,7 @@ def test_binaryen_js():
if node_has_wasm or 'WebAssembly.' not in test_src:
test(NODEJS)
else:
- print 'Skipping ' + test_path + ' because WebAssembly might not be supported'
+ print('Skipping ' + test_path + ' because WebAssembly might not be supported')
if __name__ == "__main__":
diff --git a/scripts/test/lld.py b/scripts/test/lld.py
index c573f6480..fc68a4620 100755
--- a/scripts/test/lld.py
+++ b/scripts/test/lld.py
@@ -14,8 +14,8 @@
# limitations under the License.
import os
-from support import run_command
-from shared import (
+from .support import run_command
+from .shared import (
fail_with_error, files_with_pattern, options,
WASM_EMSCRIPTEN_FINALIZE, fail_if_not_identical_to_file
)
@@ -29,10 +29,10 @@ def args_for_finalize(filename):
def test_wasm_emscripten_finalize():
- print '\n[ checking wasm-emscripten-finalize testcases... ]\n'
+ print('\n[ checking wasm-emscripten-finalize testcases... ]\n')
for wast_path in files_with_pattern(options.binaryen_test, 'lld', '*.wast'):
- print '..', wast_path
+ print('..', wast_path)
is_passive = '.passive.' in wast_path
mem_file = wast_path + '.mem'
extension_arg_map = {
@@ -52,7 +52,7 @@ def test_wasm_emscripten_finalize():
actual = run_command(cmd)
if not os.path.exists(expected_file):
- print actual
+ print(actual)
fail_with_error('output ' + expected_file + ' does not exist')
fail_if_not_identical_to_file(actual, expected_file)
if ext == '.mem.out':
@@ -63,10 +63,10 @@ def test_wasm_emscripten_finalize():
def update_lld_tests():
- print '\n[ updatring wasm-emscripten-finalize testcases... ]\n'
+ print('\n[ updatring wasm-emscripten-finalize testcases... ]\n')
for wast_path in files_with_pattern(options.binaryen_test, 'lld', '*.wast'):
- print '..', wast_path
+ print('..', wast_path)
is_passive = '.passive.' in wast_path
mem_file = wast_path + '.mem'
extension_arg_map = {
diff --git a/scripts/test/shared.py b/scripts/test/shared.py
index 37874e61e..959f02a6a 100644
--- a/scripts/test/shared.py
+++ b/scripts/test/shared.py
@@ -89,7 +89,7 @@ warnings = []
def warn(text):
global warnings
warnings.append(text)
- print 'warning:', text
+ print('warning:', text)
# setup
@@ -201,7 +201,8 @@ os.environ['BINARYEN'] = in_binaryen()
def get_platform():
- return {'linux2': 'linux',
+ return {'linux': 'linux',
+ 'linux2': 'linux',
'darwin': 'mac',
'win32': 'windows',
'cygwin': 'windows'}[sys.platform]
@@ -308,45 +309,18 @@ class Py2CalledProcessError(subprocess.CalledProcessError):
self.stderr = stderr
-# https://docs.python.org/3/library/subprocess.html#subprocess.CompletedProcess
-class Py2CompletedProcess:
- def __init__(self, args, returncode, stdout, stderr):
- self.args = args
- self.returncode = returncode
- self.stdout = stdout
- self.stderr = stderr
-
- def __repr__(self):
- _repr = ['args=%s, returncode=%s' % (self.args, self.returncode)]
- if self.stdout is not None:
- _repr += 'stdout=' + repr(self.stdout)
- if self.stderr is not None:
- _repr += 'stderr=' + repr(self.stderr)
- return 'CompletedProcess(%s)' % ', '.join(_repr)
-
- def check_returncode(self):
- if self.returncode != 0:
- raise Py2CalledProcessError(returncode=self.returncode, cmd=self.args,
- output=self.stdout, stderr=self.stderr)
-
-
def run_process(cmd, check=True, input=None, capture_output=False, *args, **kw):
- if hasattr(subprocess, "run"):
- ret = subprocess.run(cmd, check=check, input=input, *args, **kw)
- return ret
-
- # Python 2 compatibility: Introduce Python 3 subprocess.run-like behavior
- if input is not None:
- kw['stdin'] = subprocess.PIPE
+ if input and type(input) == str:
+ input = bytes(input, 'utf-8')
if capture_output:
kw['stdout'] = subprocess.PIPE
kw['stderr'] = subprocess.PIPE
- proc = subprocess.Popen(cmd, *args, **kw)
- stdout, stderr = proc.communicate(input)
- result = Py2CompletedProcess(cmd, proc.returncode, stdout, stderr)
- if check:
- result.check_returncode()
- return result
+ ret = subprocess.run(cmd, check=check, input=input, *args, **kw)
+ if ret.stdout is not None:
+ ret.stdout = ret.stdout.decode('utf-8')
+ if ret.stderr is not None:
+ ret.stderr = ret.stderr.decode('utf-8')
+ return ret
def fail_with_error(msg):
@@ -354,8 +328,8 @@ def fail_with_error(msg):
try:
num_failures += 1
raise Exception(msg)
- except Exception, e:
- print >> sys.stderr, str(e)
+ except Exception as e:
+ print(str(e))
if options.abort_on_first_failure:
raise
@@ -379,7 +353,8 @@ def fail_if_not_contained(actual, expected):
def fail_if_not_identical_to_file(actual, expected_file):
- with open(expected_file, 'rb' if expected_file.endswith(".wasm") else 'r') as f:
+ binary = expected_file.endswith(".wasm") or type(actual) == bytes
+ with open(expected_file, 'rb' if binary else 'r') as f:
fail_if_not_identical(actual, f.read(), fromfile=expected_file)
@@ -401,19 +376,19 @@ if not has_vanilla_emcc:
def validate_binary(wasm):
if V8:
cmd = [V8] + V8_OPTS + [in_binaryen('scripts', 'validation_shell.js'), '--', wasm]
- print ' ', ' '.join(cmd)
+ print(' ', ' '.join(cmd))
subprocess.check_call(cmd, stdout=subprocess.PIPE)
else:
- print '(skipping v8 binary validation)'
+ print('(skipping v8 binary validation)')
def binary_format_check(wast, verify_final_result=True, wasm_as_args=['-g'],
binary_suffix='.fromBinary', original_wast=None):
# checks we can convert the wast to binary and back
- print ' (binary format check)'
+ print(' (binary format check)')
cmd = WASM_AS + [wast, '-o', 'a.wasm', '-all'] + wasm_as_args
- print ' ', ' '.join(cmd)
+ print(' ', ' '.join(cmd))
if os.path.exists('a.wasm'):
os.unlink('a.wasm')
subprocess.check_call(cmd, stdout=subprocess.PIPE)
@@ -427,7 +402,7 @@ def binary_format_check(wast, verify_final_result=True, wasm_as_args=['-g'],
validate_binary('a.wasm')
cmd = WASM_DIS + ['a.wasm', '-o', 'ab.wast']
- print ' ', ' '.join(cmd)
+ print(' ', ' '.join(cmd))
if os.path.exists('ab.wast'):
os.unlink('ab.wast')
subprocess.check_call(cmd, stdout=subprocess.PIPE)
@@ -435,7 +410,7 @@ def binary_format_check(wast, verify_final_result=True, wasm_as_args=['-g'],
# make sure it is a valid wast
cmd = WASM_OPT + ['ab.wast', '-all']
- print ' ', ' '.join(cmd)
+ print(' ', ' '.join(cmd))
subprocess.check_call(cmd, stdout=subprocess.PIPE)
if verify_final_result:
@@ -448,9 +423,9 @@ def binary_format_check(wast, verify_final_result=True, wasm_as_args=['-g'],
def minify_check(wast, verify_final_result=True):
# checks we can parse minified output
- print ' (minify check)'
+ print(' (minify check)')
cmd = WASM_OPT + [wast, '--print-minified', '-all']
- print ' ', ' '.join(cmd)
+ print(' ', ' '.join(cmd))
subprocess.check_call(cmd, stdout=open('a.wast', 'w'), stderr=subprocess.PIPE)
assert os.path.exists('a.wast')
subprocess.check_call(
diff --git a/scripts/test/support.py b/scripts/test/support.py
index 5d03419b9..90bc531eb 100644
--- a/scripts/test/support.py
+++ b/scripts/test/support.py
@@ -88,16 +88,20 @@ def untar(tarfile, outdir):
def split_wast(wastFile):
+ # if it's a binary, leave it as is, we can't split it
+ wast = None
+ if not wastFile.endswith('.wasm'):
+ try:
+ wast = open(wastFile, 'r').read()
+ except Exception:
+ pass
+
+ if not wast:
+ return ((open(wastFile, 'rb').read(), []),)
+
# .wast files can contain multiple modules, and assertions for each one.
# this splits out a wast into [(module, assertions), ..]
# we ignore module invalidity tests here.
- wast = open(wastFile, 'rb').read()
-
- # if it's a binary, leave it as is
- if wast[0] == '\0':
- return [[wast, '']]
-
- wast = open(wastFile, 'r').read()
ret = []
def to_end(j):
@@ -146,13 +150,25 @@ def split_wast(wastFile):
return ret
+# write a split wast from split_wast. the wast may be binary if the original
+# file was binary
+def write_wast(filename, wast, asserts=[]):
+ if type(wast) == bytes:
+ assert not asserts
+ with open(filename, 'wb') as o:
+ o.write(wast)
+ else:
+ with open(filename, 'w') as o:
+ o.write(wast + '\n'.join(asserts))
+
+
def run_command(cmd, expected_status=0, stderr=None,
expected_err=None, err_contains=False, err_ignore=None):
if expected_err is not None:
assert stderr == subprocess.PIPE or stderr is None,\
"Can't redirect stderr if using expected_err"
stderr = subprocess.PIPE
- print 'executing: ', ' '.join(cmd)
+ print('executing: ', ' '.join(cmd))
proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=stderr, universal_newlines=True)
out, err = proc.communicate()
code = proc.returncode
diff --git a/scripts/test/wasm2js.py b/scripts/test/wasm2js.py
index 09ba82a09..8c8f9a840 100755
--- a/scripts/test/wasm2js.py
+++ b/scripts/test/wasm2js.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
#
# Copyright 2016 WebAssembly Community Group participants
#
@@ -16,8 +16,8 @@
import os
-from support import run_command, split_wast
-from shared import (
+from .support import run_command, split_wast, write_wast
+from .shared import (
WASM2JS, MOZJS, NODEJS, fail_if_not_identical, options, tests,
fail_if_not_identical_to_file, with_pass_debug
)
@@ -52,15 +52,14 @@ def test_wasm2js_output():
if not os.path.exists(expected_file):
continue
- print '..', wasm
+ print('..', wasm)
t = os.path.join(options.binaryen_test, wasm)
all_out = []
for module, asserts in split_wast(t):
- with open('split.wast', 'w') as o:
- o.write(module + '\n'.join(asserts))
+ write_wast('split.wast', module, asserts)
cmd = WASM2JS + ['split.wast']
if opt:
@@ -71,7 +70,7 @@ def test_wasm2js_output():
all_out.append(out)
if not NODEJS and not MOZJS:
- print 'No JS interpreters. Skipping spec tests.'
+ print('No JS interpreters. Skipping spec tests.')
continue
open('a.2asm.mjs', 'w').write(out)
@@ -102,7 +101,7 @@ def test_wasm2js_output():
def test_asserts_output():
for wasm in assert_tests:
- print '..', wasm
+ print('..', wasm)
asserts = os.path.basename(wasm).replace('.wast.asserts', '.asserts.js')
traps = os.path.basename(wasm).replace('.wast.asserts', '.traps.js')
@@ -120,13 +119,13 @@ def test_asserts_output():
def test_wasm2js():
- print '\n[ checking wasm2js testcases... ]\n'
+ print('\n[ checking wasm2js testcases... ]\n')
test_wasm2js_output()
test_asserts_output()
def update_wasm2js_tests():
- print '\n[ checking wasm2js ]\n'
+ print('\n[ checking wasm2js ]\n')
for opt in (0, 1):
for wasm in tests + spec_tests + extra_wasm2js_tests:
@@ -148,15 +147,14 @@ def update_wasm2js_tests():
if wasm not in extra_wasm2js_tests and not os.path.exists(expected_file):
continue
- print '..', wasm
+ print('..', wasm)
t = os.path.join(options.binaryen_test, wasm)
all_out = []
for module, asserts in split_wast(t):
- with open('split.wast', 'w') as o:
- o.write(module + '\n'.join(asserts))
+ write_wast('split.wast', module, asserts)
cmd = WASM2JS + ['split.wast']
if opt:
@@ -170,7 +168,7 @@ def update_wasm2js_tests():
o.write(''.join(all_out))
for wasm in assert_tests:
- print '..', wasm
+ print('..', wasm)
asserts = os.path.basename(wasm).replace('.wast.asserts', '.asserts.js')
traps = os.path.basename(wasm).replace('.wast.asserts', '.traps.js')