summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.travis.yml6
-rwxr-xr-xauto_update_tests.py97
-rwxr-xr-xcheck.py141
-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
-rw-r--r--src/passes/Asyncify.cpp4
-rw-r--r--test/passes/flatten.bin.txt2
-rw-r--r--test/passes/flatten.wasmbin458 -> 458 bytes
-rw-r--r--test/unit/test_asyncify.py4
-rw-r--r--test/unit/test_datacount.py2
-rw-r--r--test/unit/test_features.py2
-rw-r--r--test/unit/test_memory_packing.py2
-rw-r--r--test/unit/test_parsing_error.py2
-rw-r--r--test/unit/test_tail_call_type.py2
-rw-r--r--test/unit/utils.py7
-rw-r--r--test/wasm2js/comments.2asm.js30
-rwxr-xr-xtravis-emcc-tests.sh2
21 files changed, 233 insertions, 271 deletions
diff --git a/.travis.yml b/.travis.yml
index ea0d1fd2c..e490fec9d 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -69,7 +69,7 @@ jobs:
- if [ -f clang-tidy-diff.sh ]; then ./clang-tidy-diff.sh; fi
- make -j2 install
- cd ${TRAVIS_BUILD_DIR}
- - ./check.py --binaryen-bin=${BUILD_SUBDIR}/install/bin
+ - python3 ./check.py --binaryen-bin=${BUILD_SUBDIR}/install/bin
- <<: *test-ubuntu
env: |
@@ -125,11 +125,11 @@ jobs:
- alpine() { docker exec -it alpine "$@"; }
install:
- alpine apk update
- - alpine apk add build-base cmake git python2
+ - alpine apk add build-base cmake git python2 python3
script:
- alpine cmake .
- alpine make -j2
- - alpine ./check.py
+ - alpine python3 ./check.py
# Build statically linked release binaries with gcc 6.3 on Alpine Linux
# (inside chroot). If building a tagged commit, then deploy release tarball
diff --git a/auto_update_tests.py b/auto_update_tests.py
index cbb1246a5..93071f01a 100755
--- a/auto_update_tests.py
+++ b/auto_update_tests.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
#
# Copyright 2015 WebAssembly Community Group participants
#
@@ -19,7 +19,7 @@ import shutil
import subprocess
import sys
-from scripts.test.support import run_command, split_wast, node_test_glue, node_has_webassembly
+from scripts.test.support import run_command, split_wast, write_wast, node_test_glue, node_has_webassembly
from scripts.test.shared import (
ASM2WASM, MOZJS, NODEJS, WASM_OPT, WASM_AS, WASM_DIS,
WASM_CTOR_EVAL, WASM_REDUCE, WASM_METADCE, BINARYEN_INSTALL_DIR,
@@ -30,7 +30,7 @@ from scripts.test import wasm2js
def update_asm_js_tests():
- print '[ processing and updating testcases... ]\n'
+ print('[ processing and updating testcases... ]\n')
for asm in sorted(os.listdir('test')):
if asm.endswith('.asm.js'):
for precise in [0, 1, 2]:
@@ -57,7 +57,7 @@ def update_asm_js_tests():
cmd += ['--no-legalize-javascript-ffi']
if precise and opts:
# test mem init importing
- open('a.mem', 'wb').write(asm)
+ open('a.mem', 'wb').write(bytes(asm, 'utf-8'))
cmd += ['--mem-init=a.mem']
if asm[0] == 'e':
cmd += ['--mem-base=1024']
@@ -65,7 +65,7 @@ def update_asm_js_tests():
cmd += ['--mem-max=4294967296']
if 'i64' in asm or 'wasm-only' in asm or 'noffi' in asm:
cmd += ['--wasm-only']
- print ' '.join(cmd)
+ print(' '.join(cmd))
actual = run_command(cmd)
with open(os.path.join('test', wasm), 'w') as o:
o.write(actual)
@@ -75,33 +75,33 @@ def update_asm_js_tests():
def update_wasm_opt_tests():
- print '\n[ checking wasm-opt -o notation... ]\n'
+ print('\n[ checking wasm-opt -o notation... ]\n')
wast = os.path.join('test', 'hello_world.wast')
cmd = WASM_OPT + [wast, '-o', 'a.wast', '-S']
run_command(cmd)
open(wast, 'w').write(open('a.wast').read())
- print '\n[ checking wasm-opt parsing & printing... ]\n'
+ print('\n[ checking wasm-opt parsing & printing... ]\n')
for t in sorted(os.listdir(os.path.join('test', 'print'))):
if t.endswith('.wast'):
- print '..', t
+ print('..', t)
wasm = os.path.basename(t).replace('.wast', '')
cmd = WASM_OPT + [os.path.join('test', 'print', t), '--print', '-all']
- print ' ', ' '.join(cmd)
+ print(' ', ' '.join(cmd))
actual = subprocess.check_output(cmd)
- print cmd, actual
- with open(os.path.join('test', 'print', wasm + '.txt'), 'w') as o:
+ print(cmd, actual)
+ with open(os.path.join('test', 'print', wasm + '.txt'), 'wb') as o:
o.write(actual)
cmd = WASM_OPT + [os.path.join('test', 'print', t), '--print-minified', '-all']
- print ' ', ' '.join(cmd)
+ print(' ', ' '.join(cmd))
actual = subprocess.check_output(cmd)
- with open(os.path.join('test', 'print', wasm + '.minified.txt'), 'w') as o:
+ with open(os.path.join('test', 'print', wasm + '.minified.txt'), 'wb') as o:
o.write(actual)
- print '\n[ checking wasm-opt passes... ]\n'
+ print('\n[ checking wasm-opt passes... ]\n')
for t in sorted(os.listdir(os.path.join('test', 'passes'))):
if t.endswith(('.wast', '.wasm')):
- print '..', t
+ print('..', t)
binary = '.wasm' in t
base = os.path.basename(t).replace('.wast', '').replace('.wasm', '')
passname = base
@@ -112,8 +112,7 @@ def update_wasm_opt_tests():
actual = ''
for module, asserts in split_wast(t):
assert len(asserts) == 0
- with open('split.wast', 'w') as o:
- o.write(module)
+ write_wast('split.wast', module)
cmd = WASM_OPT + opts + ['split.wast', '--print']
actual += run_command(cmd)
with open(os.path.join('test', 'passes', base + ('.bin' if binary else '') + '.txt'), 'w') as o:
@@ -127,10 +126,10 @@ def update_wasm_opt_tests():
with open(t + '.wat', 'w') as o:
o.write(i.read())
- print '\n[ checking wasm-opt testcases... ]\n'
+ print('\n[ checking wasm-opt testcases... ]\n')
for t in os.listdir('test'):
if t.endswith('.wast') and not t.startswith('spec'):
- print '..', t
+ print('..', t)
t = os.path.join('test', t)
f = t + '.from-wast'
cmd = WASM_OPT + [t, '--print', '-all']
@@ -138,10 +137,10 @@ def update_wasm_opt_tests():
actual = actual.replace('printing before:\n', '')
open(f, 'w').write(actual)
- print '\n[ checking wasm-opt debugInfo read-write... ]\n'
+ print('\n[ checking wasm-opt debugInfo read-write... ]\n')
for t in os.listdir('test'):
if t.endswith('.fromasm') and 'debugInfo' in t:
- print '..', t
+ print('..', t)
t = os.path.join('test', t)
f = t + '.read-written'
run_command(WASM_AS + [t, '--source-map=a.map', '-o', 'a.wasm', '-g'])
@@ -151,21 +150,21 @@ def update_wasm_opt_tests():
def update_bin_fmt_tests():
- print '\n[ checking binary format testcases... ]\n'
+ print('\n[ checking binary format testcases... ]\n')
for wast in sorted(os.listdir('test')):
if wast.endswith('.wast') and wast not in []: # blacklist some known failures
for debug_info in [0, 1]:
cmd = WASM_AS + [os.path.join('test', wast), '-o', 'a.wasm', '-all']
if debug_info:
cmd += ['-g']
- print ' '.join(cmd)
+ print(' '.join(cmd))
if os.path.exists('a.wasm'):
os.unlink('a.wasm')
subprocess.check_call(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
assert os.path.exists('a.wasm')
cmd = WASM_DIS + ['a.wasm', '-o', 'a.wast']
- print ' '.join(cmd)
+ print(' '.join(cmd))
if os.path.exists('a.wast'):
os.unlink('a.wast')
subprocess.check_call(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
@@ -179,7 +178,7 @@ def update_bin_fmt_tests():
def update_example_tests():
- print '\n[ checking example testcases... ]\n'
+ print('\n[ checking example testcases... ]\n')
for t in sorted(os.listdir(os.path.join('test', 'example'))):
output_file = os.path.join(options.binaryen_bin, 'example')
libdir = os.path.join(BINARYEN_INSTALL_DIR, 'lib')
@@ -188,11 +187,11 @@ def update_example_tests():
# check if there is a trace in the file, if so, we should build it
out = subprocess.Popen([os.path.join('scripts', 'clean_c_api_trace.py'), os.path.join('test', 'example', t)], stdout=subprocess.PIPE).communicate()[0]
if len(out) == 0:
- print ' (no trace in ', t, ')'
+ print(' (no trace in ', t, ')')
continue
- print ' (will check trace in ', t, ')'
+ print(' (will check trace in ', t, ')')
src = 'trace.cpp'
- with open(src, 'w') as o:
+ with open(src, 'wb') as o:
o.write(out)
expected = os.path.join('test', 'example', t + '.txt')
else:
@@ -204,26 +203,26 @@ def update_example_tests():
extra = [os.environ.get('CC') or 'gcc',
src, '-c', '-o', 'example.o',
'-Isrc', '-g', '-L' + libdir, '-pthread']
- print 'build: ', ' '.join(extra)
+ print('build: ', ' '.join(extra))
if src.endswith('.cpp'):
extra += ['-std=c++11']
- print os.getcwd()
+ 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 ' ', t, src, expected
+ print(' ', t, 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++11'] + cmd
try:
- print 'link: ', ' '.join(cmd)
+ print('link: ', ' '.join(cmd))
subprocess.check_call(cmd)
- print 'run...', output_file
+ 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, 'w') as o:
+ with open(expected, 'wb') as o:
o.write(actual)
finally:
os.remove(output_file)
@@ -233,10 +232,10 @@ def update_example_tests():
def update_wasm_dis_tests():
- print '\n[ checking wasm-dis on provided binaries... ]\n'
+ print('\n[ checking wasm-dis on provided binaries... ]\n')
for t in os.listdir('test'):
if t.endswith('.wasm') and not t.startswith('spec'):
- print '..', t
+ print('..', t)
t = os.path.join('test', t)
cmd = WASM_DIS + [t]
if os.path.isfile(t + '.map'):
@@ -248,19 +247,19 @@ def update_wasm_dis_tests():
def update_binaryen_js_tests():
if not (MOZJS or NODEJS):
- print 'no vm to run binaryen.js tests'
+ print('no vm to run binaryen.js tests')
return
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')
node_has_wasm = NODEJS and node_has_webassembly(NODEJS)
for s in sorted(os.listdir(os.path.join('test', 'binaryen.js'))):
if not s.endswith('.js'):
continue
- print s
+ print(s)
f = open('a.js', 'w')
f.write(open(BINARYEN_JS).read())
if NODEJS:
@@ -279,14 +278,14 @@ def update_binaryen_js_tests():
with open(os.path.join('test', 'binaryen.js', s + '.txt'), 'w') as o:
o.write(out)
else:
- print 'Skipping ' + test_path + ' because WebAssembly might not be supported'
+ print('Skipping ' + test_path + ' because WebAssembly might not be supported')
def update_ctor_eval_tests():
- print '\n[ checking wasm-ctor-eval... ]\n'
+ print('\n[ checking wasm-ctor-eval... ]\n')
for t in os.listdir(os.path.join('test', 'ctor-eval')):
if t.endswith(('.wast', '.wasm')):
- print '..', t
+ print('..', t)
t = os.path.join('test', 'ctor-eval', t)
ctors = open(t + '.ctors').read().strip()
cmd = WASM_CTOR_EVAL + [t, '-o', 'a.wast', '-S', '--ctors', ctors]
@@ -298,10 +297,10 @@ def update_ctor_eval_tests():
def update_metadce_tests():
- print '\n[ checking wasm-metadce... ]\n'
+ print('\n[ checking wasm-metadce... ]\n')
for t in os.listdir(os.path.join('test', 'metadce')):
if t.endswith(('.wast', '.wasm')):
- print '..', t
+ print('..', t)
t = os.path.join('test', 'metadce', t)
graph = t + '.graph.txt'
cmd = WASM_METADCE + [t, '--graph-file=' + graph, '-o', 'a.wast', '-S']
@@ -317,14 +316,14 @@ def update_metadce_tests():
def update_reduce_tests():
if not has_shell_timeout():
return
- print '\n[ checking wasm-reduce ]\n'
+ print('\n[ checking wasm-reduce ]\n')
for t in os.listdir(os.path.join('test', 'reduce')):
if t.endswith('.wast'):
- print '..', t
+ print('..', t)
t = os.path.join('test', 'reduce', t)
# convert to wasm
run_command(WASM_AS + [t, '-o', 'a.wasm'])
- print run_command(WASM_REDUCE + ['a.wasm', '--command=%s b.wasm --fuzz-exec' % WASM_OPT[0], '-t', 'b.wasm', '-w', 'c.wasm'])
+ print(run_command(WASM_REDUCE + ['a.wasm', '--command=%s b.wasm --fuzz-exec' % WASM_OPT[0], '-t', 'b.wasm', '-w', 'c.wasm']))
expected = t + '.txt'
run_command(WASM_DIS + ['c.wasm', '-o', expected])
@@ -342,7 +341,7 @@ def main():
update_reduce_tests()
update_binaryen_js_tests()
- print '\n[ success! ]'
+ print('\n[ success! ]')
if __name__ == '__main__':
diff --git a/check.py b/check.py
index a143650b1..871008982 100755
--- a/check.py
+++ b/check.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python2
+#!/usr/bin/env python3
#
# Copyright 2015 WebAssembly Community Group participants
#
@@ -20,7 +20,7 @@ import subprocess
import sys
import unittest
-from scripts.test.support import run_command, split_wast
+from scripts.test.support import run_command, split_wast, write_wast
from scripts.test.shared import (
BIN_DIR, NATIVECC, NATIVEXX, NODEJS, WASM_AS,
WASM_CTOR_EVAL, WASM_OPT, WASM_SHELL, WASM_METADCE, WASM_DIS, WASM_REDUCE,
@@ -40,19 +40,19 @@ from scripts.test import wasm2js
from scripts.test import binaryenjs
if options.interpreter:
- print '[ using wasm interpreter at "%s" ]' % options.interpreter
+ print('[ using wasm interpreter at "%s" ]' % options.interpreter)
assert os.path.exists(options.interpreter), 'interpreter not found'
def run_help_tests():
- print '[ checking --help is useful... ]\n'
+ print('[ checking --help is useful... ]\n')
not_executable_suffix = ['.txt', '.js', '.ilk', '.pdb', '.dll', '.wasm']
executables = sorted(filter(lambda x: not any(x.endswith(s) for s in
not_executable_suffix) and os.path.isfile(x),
os.listdir(options.binaryen_bin)))
for e in executables:
- print '.. %s --help' % e
+ print('.. %s --help' % e)
out, err = subprocess.Popen([os.path.join(options.binaryen_bin, e), '--help'],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE).communicate()
@@ -62,7 +62,7 @@ def run_help_tests():
def run_wasm_opt_tests():
- print '\n[ checking wasm-opt -o notation... ]\n'
+ print('\n[ checking wasm-opt -o notation... ]\n')
for extra_args in [[], ['--no-validation']]:
wast = os.path.join(options.binaryen_test, 'hello_world.wast')
@@ -71,21 +71,21 @@ def run_wasm_opt_tests():
run_command(cmd)
fail_if_not_identical_to_file(open('a.wast').read(), wast)
- print '\n[ checking wasm-opt binary reading/writing... ]\n'
+ print('\n[ checking wasm-opt binary reading/writing... ]\n')
shutil.copyfile(os.path.join(options.binaryen_test, 'hello_world.wast'), 'a.wast')
delete_from_orbit('a.wasm')
delete_from_orbit('b.wast')
run_command(WASM_OPT + ['a.wast', '-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(WASM_OPT + ['a.wasm', '-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'
- print '\n[ checking wasm-opt passes... ]\n'
+ print('\n[ checking wasm-opt passes... ]\n')
for t in sorted(os.listdir(os.path.join(options.binaryen_test, 'passes'))):
if t.endswith(('.wast', '.wasm')):
- print '..', t
+ print('..', t)
binary = '.wasm' in t
base = os.path.basename(t).replace('.wast', '').replace('.wasm', '')
passname = base
@@ -96,8 +96,7 @@ def run_wasm_opt_tests():
actual = ''
for module, asserts in split_wast(t):
assert len(asserts) == 0
- with open('split.wast', "wb" if binary else 'w') as o:
- o.write(module)
+ write_wast('split.wast', module)
cmd = WASM_OPT + opts + ['split.wast', '--print']
curr = run_command(cmd)
actual += curr
@@ -122,27 +121,27 @@ def run_wasm_opt_tests():
with open('a.wat') as actual:
fail_if_not_identical_to_file(actual.read(), t + '.wat')
- print '\n[ checking wasm-opt parsing & printing... ]\n'
+ print('\n[ checking wasm-opt parsing & printing... ]\n')
for t in sorted(os.listdir(os.path.join(options.binaryen_test, 'print'))):
if t.endswith('.wast'):
- print '..', t
+ print('..', t)
wasm = os.path.basename(t).replace('.wast', '')
cmd = WASM_OPT + [os.path.join(options.binaryen_test, 'print', t), '--print', '-all']
- print ' ', ' '.join(cmd)
+ print(' ', ' '.join(cmd))
actual, err = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True).communicate()
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', '-all']
- print ' ', ' '.join(cmd)
+ print(' ', ' '.join(cmd))
actual, err = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True).communicate()
fail_if_not_identical(actual.strip(), open(os.path.join(options.binaryen_test, 'print', wasm + '.minified.txt')).read().strip())
- print '\n[ checking wasm-opt testcases... ]\n'
+ print('\n[ checking wasm-opt testcases... ]\n')
for t in tests:
if t.endswith('.wast') and not t.startswith('spec'):
- print '..', t
+ print('..', t)
t = os.path.join(options.binaryen_test, t)
f = t + '.from-wast'
cmd = WASM_OPT + [t, '--print', '-all']
@@ -156,11 +155,11 @@ def run_wasm_opt_tests():
minify_check(t)
- print '\n[ checking wasm-opt debugInfo read-write... ]\n'
+ print('\n[ checking wasm-opt debugInfo read-write... ]\n')
for t in os.listdir('test'):
if t.endswith('.fromasm') and 'debugInfo' in t:
- print '..', t
+ print('..', t)
t = os.path.join('test', t)
f = t + '.read-written'
run_command(WASM_AS + [t, '--source-map=a.map', '-o', 'a.wasm', '-g'])
@@ -170,11 +169,11 @@ def run_wasm_opt_tests():
def run_wasm_dis_tests():
- print '\n[ checking wasm-dis on provided binaries... ]\n'
+ print('\n[ checking wasm-dis on provided binaries... ]\n')
for t in tests:
if t.endswith('.wasm') and not t.startswith('spec'):
- print '..', t
+ print('..', t)
t = os.path.join(options.binaryen_test, t)
cmd = WASM_DIS + [t]
if os.path.isfile(t + '.map'):
@@ -194,12 +193,12 @@ def run_wasm_dis_tests():
def run_crash_tests():
- print "\n[ checking we don't crash on tricky inputs... ]\n"
+ print("\n[ checking we don't crash on tricky inputs... ]\n")
test_dir = os.path.join(options.binaryen_test, 'crash')
for t in os.listdir(test_dir):
if t.endswith(('.wast', '.wasm')):
- print '..', t
+ print('..', t)
t = os.path.join(test_dir, t)
cmd = WASM_OPT + [t]
# expect a parse error to be reported
@@ -207,27 +206,27 @@ def run_crash_tests():
def run_dylink_tests():
- print "\n[ we emit dylink sections properly... ]\n"
+ print("\n[ we emit dylink sections properly... ]\n")
for t in os.listdir(options.binaryen_test):
if t.startswith('dylib') and t.endswith('.wasm'):
- print '..', t
+ print('..', t)
t = os.path.join(options.binaryen_test, t)
cmd = WASM_OPT + [t, '-o', 'a.wasm']
run_command(cmd)
- with open('a.wasm') as output:
- index = output.read().find('dylink')
- print ' ', index
+ with open('a.wasm', 'rb') as output:
+ index = output.read().find(b'dylink')
+ print(' ', index)
assert index == 11, 'dylink section must be first, right after the magic number etc.'
def run_ctor_eval_tests():
- print '\n[ checking wasm-ctor-eval... ]\n'
+ print('\n[ checking wasm-ctor-eval... ]\n')
test_dir = os.path.join(options.binaryen_test, 'ctor-eval')
for t in os.listdir(test_dir):
if t.endswith(('.wast', '.wasm')):
- print '..', t
+ print('..', t)
t = os.path.join(test_dir, t)
ctors = open(t + '.ctors').read().strip()
cmd = WASM_CTOR_EVAL + [t, '-o', 'a.wast', '-S', '--ctors', ctors]
@@ -238,12 +237,12 @@ def run_ctor_eval_tests():
def run_wasm_metadce_tests():
- print '\n[ checking wasm-metadce ]\n'
+ print('\n[ checking wasm-metadce ]\n')
test_dir = os.path.join(options.binaryen_test, 'metadce')
for t in os.listdir(test_dir):
if t.endswith(('.wast', '.wasm')):
- print '..', t
+ print('..', t)
t = os.path.join(test_dir, t)
graph = t + '.graph.txt'
cmd = WASM_METADCE + [t, '--graph-file=' + graph, '-o', 'a.wast', '-S']
@@ -255,13 +254,13 @@ def run_wasm_metadce_tests():
def run_wasm_reduce_tests():
- print '\n[ checking wasm-reduce testcases]\n'
+ print('\n[ checking wasm-reduce testcases]\n')
# fixed testcases
test_dir = os.path.join(options.binaryen_test, 'reduce')
for t in os.listdir(test_dir):
if t.endswith('.wast'):
- print '..', t
+ print('..', t)
t = os.path.join(test_dir, t)
# convert to wasm
run_command(WASM_AS + [t, '-o', 'a.wasm'])
@@ -274,7 +273,7 @@ def run_wasm_reduce_tests():
# run on a nontrivial fuzz testcase, for general coverage
# this is very slow in ThreadSanitizer, so avoid it there
if 'fsanitize=thread' not in str(os.environ):
- print '\n[ checking wasm-reduce fuzz testcase ]\n'
+ print('\n[ checking wasm-reduce fuzz testcase ]\n')
run_command(WASM_OPT + [os.path.join(options.binaryen_test, 'unreachable-import_wasm-only.asm.js'), '-ttf', '-Os', '-o', 'a.wasm', '-all'])
before = os.stat('a.wasm').st_size
@@ -284,7 +283,7 @@ def run_wasm_reduce_tests():
def run_spec_tests():
- print '\n[ checking wasm-shell spec testcases... ]\n'
+ print('\n[ checking wasm-shell spec testcases... ]\n')
if len(requested) == 0:
# FIXME we support old and new memory formats, for now, until 0xc, and so can't pass this old-style test.
@@ -296,7 +295,7 @@ def run_spec_tests():
for t in spec_tests:
if t.startswith('spec') and t.endswith('.wast'):
- print '..', t
+ print('..', t)
wast = os.path.join(options.binaryen_test, t)
# skip checks for some tests
@@ -337,7 +336,7 @@ def run_spec_tests():
expected = '\n'.join(map(fix_expected, expected.split('\n')))
actual = '\n'.join(map(fix_actual, actual.split('\n')))
- print ' (using expected output)'
+ print(' (using expected output)')
actual = actual.strip()
expected = expected.strip()
if actual != expected:
@@ -348,9 +347,9 @@ def run_spec_tests():
# some spec tests should fail (actual process failure, not just assert_invalid)
try:
actual = run_spec_test(wast)
- except Exception, e:
+ except Exception as e:
if ('wasm-validator error' in str(e) or 'parse exception' in str(e)) and '.fail.' in t:
- print '<< test failed as expected >>'
+ print('<< test failed as expected >>')
continue # don't try all the binary format stuff TODO
else:
fail_with_error(str(e))
@@ -368,19 +367,20 @@ def run_spec_tests():
}
# check binary format. here we can verify execution of the final result, no need for an output verification
- split_num = 0
- if os.path.basename(wast) not in []: # avoid some tests with things still being sorted out in the spec
+ # some wast files cannot be split:
+ # * comments.wast: contains characters that are not valid utf-8, so our string splitting code fails there
+ if os.path.basename(wast) not in ['comments.wast']:
+ split_num = 0
actual = ''
for module, asserts in split_wast(wast):
skip = splits_to_skip.get(os.path.basename(wast)) or []
if split_num in skip:
- print ' skipping split module', split_num - 1
+ print(' skipping split module', split_num - 1)
split_num += 1
continue
- print ' testing split module', split_num
+ print(' testing split module', split_num)
split_num += 1
- with open('split.wast', 'w') as o:
- o.write(module + '\n' + '\n'.join(asserts))
+ 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 = binary_format_check('split.wast', verify_final_result=False, original_wast=wast)
@@ -389,10 +389,13 @@ def run_spec_tests():
actual += run_spec_test(result_wast)
# compare all the outputs to the expected output
check_expected(actual, os.path.join(options.binaryen_test, 'spec', 'expected-output', os.path.basename(wast) + '.log'))
+ else:
+ # handle unsplittable wast files
+ run_spec_test(wast)
def run_validator_tests():
- print '\n[ running validation tests... ]\n'
+ print('\n[ running validation tests... ]\n')
# Ensure the tests validate by default
cmd = WASM_AS + [os.path.join(options.binaryen_test, 'validator', 'invalid_export.wast')]
run_command(cmd)
@@ -409,7 +412,7 @@ def run_validator_tests():
def run_vanilla_tests():
- print '\n[ checking emcc WASM_BACKEND testcases...]\n'
+ print('\n[ checking emcc WASM_BACKEND testcases...]\n')
try:
if has_vanilla_llvm:
@@ -417,30 +420,30 @@ def run_vanilla_tests():
else:
# if we did not set vanilla llvm, then we must set this env var to make emcc use the wasm backend.
# (if we are using vanilla llvm, things should just work)
- print '(not using vanilla llvm, so setting env var to tell emcc to use wasm backend)'
+ print('(not using vanilla llvm, so setting env var to tell emcc to use wasm backend)')
os.environ['EMCC_WASM_BACKEND'] = '1'
VANILLA_EMCC = os.path.join(options.binaryen_test, 'emscripten', 'emcc')
# run emcc to make sure it sets itself up properly, if it was never run before
command = [VANILLA_EMCC, '-v']
- print '____' + ' '.join(command)
+ print('____' + ' '.join(command))
subprocess.check_call(command)
for c in sorted(os.listdir(os.path.join(options.binaryen_test, 'wasm_backend'))):
if not c.endswith('cpp'):
continue
- print '..', c
+ print('..', c)
base = c.replace('.cpp', '').replace('.c', '')
expected = open(os.path.join(options.binaryen_test, 'wasm_backend', base + '.txt')).read()
for opts in [[], ['-O1'], ['-O2']]:
# only my code is a hack we used early in wasm backend dev, which somehow worked, but only with -O1
only = [] if opts != ['-O1'] or '_only' not in base else ['-s', 'ONLY_MY_CODE=1']
command = [VANILLA_EMCC, '-o', 'a.wasm.js', os.path.join(options.binaryen_test, 'wasm_backend', c)] + opts + only
- print '....' + ' '.join(command)
+ print('....' + ' '.join(command))
if os.path.exists('a.wasm.js'):
os.unlink('a.wasm.js')
subprocess.check_call(command)
if NODEJS:
- print ' (check in node)'
+ print(' (check in node)')
cmd = [NODEJS, 'a.wasm.js']
out = run_command(cmd)
if out.strip() != expected.strip():
@@ -453,7 +456,7 @@ def run_vanilla_tests():
def run_gcc_tests():
- print '\n[ checking native gcc testcases...]\n'
+ print('\n[ checking native gcc testcases...]\n')
if not NATIVECC or not NATIVEXX:
fail_with_error('Native compiler (e.g. gcc/g++) was not found in PATH!')
return
@@ -465,11 +468,11 @@ def run_gcc_tests():
# check if there is a trace in the file, if so, we should build it
out = subprocess.Popen([os.path.join('scripts', 'clean_c_api_trace.py'), os.path.join(options.binaryen_test, 'example', t)], stdout=subprocess.PIPE).communicate()[0]
if len(out) == 0:
- print ' (no trace in ', t, ')'
+ print(' (no trace in ', t, ')')
continue
- print ' (will check trace in ', t, ')'
+ print(' (will check trace in ', t, ')')
src = 'trace.cpp'
- with open(src, 'w') as o:
+ with open(src, 'wb') as o:
o.write(out)
expected = os.path.join(options.binaryen_test, 'example', t + '.txt')
else:
@@ -485,20 +488,20 @@ def run_gcc_tests():
if os.environ.get('COMPILER_FLAGS'):
for f in os.environ.get('COMPILER_FLAGS').split(' '):
extra.append(f)
- print 'build: ', ' '.join(extra)
+ 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]
else:
continue
- print ' ', t, src, expected
+ print(' ', t, src, expected)
if os.environ.get('COMPILER_FLAGS'):
for f in os.environ.get('COMPILER_FLAGS').split(' '):
cmd.append(f)
cmd = [NATIVEXX, '-std=c++11'] + cmd
- print 'link: ', ' '.join(cmd)
+ print('link: ', ' '.join(cmd))
subprocess.check_call(cmd)
- print 'run...', output_file
+ print('run...', output_file)
actual = subprocess.check_output([os.path.abspath(output_file)])
os.remove(output_file)
if sys.platform == 'darwin':
@@ -509,7 +512,7 @@ def run_gcc_tests():
def run_unittest():
- print '\n[ checking unit tests...]\n'
+ print('\n[ checking unit tests...]\n')
# equivalent to `python -m unittest discover -s ./test -v`
suite = unittest.defaultTestLoader.discover(os.path.dirname(options.binaryen_test))
@@ -532,7 +535,6 @@ def main():
run_wasm_metadce_tests()
if has_shell_timeout():
run_wasm_reduce_tests()
-
run_spec_tests()
binaryenjs.test_binaryen_js()
lld.test_wasm_emscripten_finalize()
@@ -540,21 +542,20 @@ def main():
run_validator_tests()
if has_vanilla_emcc and has_vanilla_llvm and 0:
run_vanilla_tests()
- print '\n[ checking example testcases... ]\n'
+ print('\n[ checking example testcases... ]\n')
if options.run_gcc_tests:
run_gcc_tests()
-
run_unittest()
# Check/display the results
if shared.num_failures == 0:
- print '\n[ success! ]'
+ print('\n[ success! ]')
if warnings:
- print '\n' + '\n'.join(warnings)
+ print('\n' + '\n'.join(warnings))
if shared.num_failures > 0:
- print '\n[ ' + str(shared.num_failures) + ' failures! ]'
+ print('\n[ ' + str(shared.num_failures) + ' failures! ]')
return 1
return 0
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')
diff --git a/src/passes/Asyncify.cpp b/src/passes/Asyncify.cpp
index 7d6dd9f76..361976fc3 100644
--- a/src/passes/Asyncify.cpp
+++ b/src/passes/Asyncify.cpp
@@ -230,6 +230,10 @@
// will be instrumented. Like the blacklist, getting this wrong will
// break your application.
//
+// TODO When wasm has GC, extending the live ranges of locals can keep things
+// alive unnecessarily. We may want to set locals to null at the end
+// of their original range.
+//
#include "ir/effects.h"
#include "ir/literal-utils.h"
diff --git a/test/passes/flatten.bin.txt b/test/passes/flatten.bin.txt
index e030c825a..d0e2fa944 100644
--- a/test/passes/flatten.bin.txt
+++ b/test/passes/flatten.bin.txt
@@ -15,7 +15,7 @@
(export "type-local-f64" (func $3))
(export "type-param-i32" (func $4))
(export "type-param-i64" (func $5))
- (export "tÿÿe-param-f32" (func $6))
+ (export "type-param-f32" (func $6))
(export "type-param-f64" (func $7))
(export "type-mixed" (func $8))
(export "read" (func $9))
diff --git a/test/passes/flatten.wasm b/test/passes/flatten.wasm
index 0ba6a86fe..fd3e0e7dd 100644
--- a/test/passes/flatten.wasm
+++ b/test/passes/flatten.wasm
Binary files differ
diff --git a/test/unit/test_asyncify.py b/test/unit/test_asyncify.py
index 40ee160d2..3856c262d 100644
--- a/test/unit/test_asyncify.py
+++ b/test/unit/test_asyncify.py
@@ -2,7 +2,7 @@ import os
import subprocess
from scripts.test.shared import WASM_OPT, WASM_DIS, WASM_SHELL, NODEJS, run_process
-from utils import BinaryenTestCase
+from .utils import BinaryenTestCase
class AsyncifyTest(BinaryenTestCase):
@@ -26,7 +26,7 @@ class AsyncifyTest(BinaryenTestCase):
run_process(WASM_OPT + [self.input_path('asyncify-pure.wast'), '--asyncify', '-o', 'a.wasm'])
run_process(WASM_DIS + ['a.wasm', '-o', 'a.wast'])
output = run_process(WASM_SHELL + ['a.wast'], capture_output=True).stdout
- with open(self.input_path('asyncify-pure.txt')) as f:
+ with open(self.input_path('asyncify-pure.txt'), 'r') as f:
self.assertEqual(f.read(), output)
def test_asyncify_list_bad(self):
diff --git a/test/unit/test_datacount.py b/test/unit/test_datacount.py
index 5ec98c549..d0d8e9f2b 100644
--- a/test/unit/test_datacount.py
+++ b/test/unit/test_datacount.py
@@ -1,5 +1,5 @@
from scripts.test.shared import WASM_OPT, run_process
-from utils import BinaryenTestCase
+from .utils import BinaryenTestCase
class DataCountTest(BinaryenTestCase):
diff --git a/test/unit/test_features.py b/test/unit/test_features.py
index 2a0eca39b..1836aa08a 100644
--- a/test/unit/test_features.py
+++ b/test/unit/test_features.py
@@ -1,6 +1,6 @@
import os
from scripts.test.shared import WASM_OPT, run_process
-from utils import BinaryenTestCase
+from .utils import BinaryenTestCase
class FeatureValidationTest(BinaryenTestCase):
diff --git a/test/unit/test_memory_packing.py b/test/unit/test_memory_packing.py
index a0ccd3006..5d64ccc6c 100644
--- a/test/unit/test_memory_packing.py
+++ b/test/unit/test_memory_packing.py
@@ -1,6 +1,6 @@
import os
from scripts.test.shared import WASM_OPT, run_process
-from utils import BinaryenTestCase
+from .utils import BinaryenTestCase
'''Test that MemoryPacking correctly respects the web limitations by not
generating more than 100K data segments'''
diff --git a/test/unit/test_parsing_error.py b/test/unit/test_parsing_error.py
index 93aab1d16..fde77c6c2 100644
--- a/test/unit/test_parsing_error.py
+++ b/test/unit/test_parsing_error.py
@@ -1,5 +1,5 @@
from scripts.test.shared import WASM_OPT, run_process
-from utils import BinaryenTestCase
+from .utils import BinaryenTestCase
import os
diff --git a/test/unit/test_tail_call_type.py b/test/unit/test_tail_call_type.py
index 4db0589c4..42da89d26 100644
--- a/test/unit/test_tail_call_type.py
+++ b/test/unit/test_tail_call_type.py
@@ -1,5 +1,5 @@
from scripts.test.shared import WASM_OPT, run_process
-from utils import BinaryenTestCase
+from .utils import BinaryenTestCase
import os
diff --git a/test/unit/utils.py b/test/unit/utils.py
index 876f2f4ec..6b18235b5 100644
--- a/test/unit/utils.py
+++ b/test/unit/utils.py
@@ -9,12 +9,11 @@ class BinaryenTestCase(unittest.TestCase):
def roundtrip(self, filename, opts=[]):
path = self.input_path(filename)
- p = run_process(WASM_OPT + ['-g', '-o', '-', path] + opts, check=False,
- capture_output=True)
+ p = run_process(WASM_OPT + ['-g', '-o', 'a.wasm', path] + opts)
self.assertEqual(p.returncode, 0)
- self.assertEqual(p.stderr, '')
with open(path, 'rb') as f:
- self.assertEqual(str(p.stdout), str(f.read()))
+ with open('a.wasm', 'rb') as g:
+ self.assertEqual(g.read(), f.read())
def disassemble(self, filename):
path = self.input_path(filename)
diff --git a/test/wasm2js/comments.2asm.js b/test/wasm2js/comments.2asm.js
index 81100c40c..e31607d1d 100644
--- a/test/wasm2js/comments.2asm.js
+++ b/test/wasm2js/comments.2asm.js
@@ -28,33 +28,3 @@ function asmFunc(global, env, buffer) {
var memasmFunc = new ArrayBuffer(65536);
var retasmFunc = asmFunc({Math,Int8Array,Uint8Array,Int16Array,Uint16Array,Int32Array,Uint32Array,Float32Array,Float64Array,NaN,Infinity}, {abort:function() { throw new Error('abort'); }},memasmFunc);
-
-function asmFunc(global, env, buffer) {
- var HEAP8 = new global.Int8Array(buffer);
- var HEAP16 = new global.Int16Array(buffer);
- var HEAP32 = new global.Int32Array(buffer);
- var HEAPU8 = new global.Uint8Array(buffer);
- var HEAPU16 = new global.Uint16Array(buffer);
- var HEAPU32 = new global.Uint32Array(buffer);
- var HEAPF32 = new global.Float32Array(buffer);
- var HEAPF64 = new global.Float64Array(buffer);
- var Math_imul = global.Math.imul;
- var Math_fround = global.Math.fround;
- var Math_abs = global.Math.abs;
- var Math_clz32 = global.Math.clz32;
- var Math_min = global.Math.min;
- var Math_max = global.Math.max;
- var Math_floor = global.Math.floor;
- var Math_ceil = global.Math.ceil;
- var Math_sqrt = global.Math.sqrt;
- var abort = env.abort;
- var nan = global.NaN;
- var infinity = global.Infinity;
- var FUNCTION_TABLE = [];
- return {
-
- };
-}
-
-var memasmFunc = new ArrayBuffer(65536);
-var retasmFunc = asmFunc({Math,Int8Array,Uint8Array,Int16Array,Uint16Array,Int32Array,Uint32Array,Float32Array,Float64Array,NaN,Infinity}, {abort:function() { throw new Error('abort'); }},memasmFunc);
diff --git a/travis-emcc-tests.sh b/travis-emcc-tests.sh
index 7ad55d123..cd6c2eee0 100755
--- a/travis-emcc-tests.sh
+++ b/travis-emcc-tests.sh
@@ -2,5 +2,5 @@ set -e
echo "travis-test build"
./build-js.sh -g
echo "travis-test test"
-./scripts/test/binaryenjs.py
+python -m scripts.test.binaryenjs
echo "travis-test yay!"