summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2017-11-14 12:10:51 -0800
committerGitHub <noreply@github.com>2017-11-14 12:10:51 -0800
commit82d693b2bd23778b29bbd1019936a2857580c7ed (patch)
tree6a8d169578687f596c476d17ee2000e74a644e99
parent47a27b1ae440cec5272c4460f3a6c2e0b3e97021 (diff)
downloadbinaryen-82d693b2bd23778b29bbd1019936a2857580c7ed.tar.gz
binaryen-82d693b2bd23778b29bbd1019936a2857580c7ed.tar.bz2
binaryen-82d693b2bd23778b29bbd1019936a2857580c7ed.zip
Run binaryen.js tests using node, and on travis (#1275)
-rw-r--r--.travis.yml2
-rwxr-xr-xcheck.py97
-rw-r--r--test/binaryen.js/kitchen-sink.js2
3 files changed, 59 insertions, 42 deletions
diff --git a/.travis.yml b/.travis.yml
index f2a487bba..6d6c8adef 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -72,7 +72,7 @@ jobs:
before_install:
- docker run -dit --name emscripten -v $(pwd):/src trzeci/emscripten:sdk-incoming-64bit bash
script:
- - docker exec -it emscripten bash ./build-js.sh -g
+ - docker exec -it emscripten bash ./build-js.sh -g && python -c "import check ; check.run_binaryen_js_tests()"
# Build with gcc 6.3 and run tests on Alpine Linux (inside chroot).
# Note: Alpine uses musl libc.
diff --git a/check.py b/check.py
index f3f2f5188..b7c7cf3ed 100755
--- a/check.py
+++ b/check.py
@@ -321,6 +321,9 @@ def run_spec_tests():
check_expected(actual, os.path.join(options.binaryen_test, 'spec', 'expected-output', os.path.basename(wast) + '.log'))
def run_binaryen_js_tests():
+ if not MOZJS and not NODEJS:
+ return
+
print '\n[ checking binaryen.js testcases... ]\n'
for s in sorted(os.listdir(os.path.join(options.binaryen_test, 'binaryen.js'))):
@@ -328,9 +331,20 @@ def run_binaryen_js_tests():
print s
f = open('a.js', 'w')
f.write(open(os.path.join(options.binaryen_bin, 'binaryen.js')).read())
- f.write(open(os.path.join(options.binaryen_test, 'binaryen.js', s)).read())
+ # node test support
+ f.write('\nif (typeof require === "function") var Binaryen = module.exports;\n')
+ test_path = os.path.join(options.binaryen_test, 'binaryen.js', s)
+ test = open(test_path).read()
+ need_wasm = 'WebAssembly.' in test # some tests use wasm support in the VM
+ if MOZJS:
+ cmd = [MOZJS]
+ elif NODEJS and not need_wasm: # TODO: check if node is new and has wasm support
+ cmd = [NODEJS]
+ else:
+ continue # we can't run it
+ cmd += ['a.js']
+ f.write(test)
f.close()
- cmd = [MOZJS, 'a.js']
out = run_command(cmd, stderr=subprocess.STDOUT)
expected = open(os.path.join(options.binaryen_test, 'binaryen.js', s + '.txt')).read()
if expected not in out:
@@ -537,43 +551,46 @@ def run_emscripten_tests():
assert proc.returncode != 0, err
assert 'hello, world!' not in out, out
-
# Run all the tests
-run_help_tests()
-run_wasm_opt_tests()
-asm2wasm.test_asm2wasm()
-asm2wasm.test_asm2wasm_binary()
-run_wasm_dis_tests()
-run_wasm_merge_tests()
-run_ctor_eval_tests()
-if has_shell_timeout():
- run_wasm_reduce_tests()
-
-run_spec_tests()
-if MOZJS:
+def main():
+ run_help_tests()
+ run_wasm_opt_tests()
+ asm2wasm.test_asm2wasm()
+ asm2wasm.test_asm2wasm_binary()
+ run_wasm_dis_tests()
+ run_wasm_merge_tests()
+ run_ctor_eval_tests()
+ if has_shell_timeout():
+ run_wasm_reduce_tests()
+
+ run_spec_tests()
run_binaryen_js_tests()
-s2wasm.test_s2wasm()
-s2wasm.test_linker()
-wasm2asm.test_wasm2asm()
-run_validator_tests()
-if options.torture and options.test_waterfall:
- run_torture_tests()
-if has_vanilla_emcc and has_vanilla_llvm and 0:
- run_vanilla_tests()
-print '\n[ checking example testcases... ]\n'
-if options.run_gcc_tests:
- run_gcc_torture_tests()
-if EMCC:
- run_emscripten_tests()
-
-# Check/display the results
-if num_failures == 0:
- print '\n[ success! ]'
-
-if warnings:
- print '\n' + '\n'.join(warnings)
-
-if num_failures > 0:
- print '\n[ ' + str(num_failures) + ' failures! ]'
-
-sys.exit(num_failures)
+ s2wasm.test_s2wasm()
+ s2wasm.test_linker()
+ wasm2asm.test_wasm2asm()
+ run_validator_tests()
+ if options.torture and options.test_waterfall:
+ run_torture_tests()
+ if has_vanilla_emcc and has_vanilla_llvm and 0:
+ run_vanilla_tests()
+ print '\n[ checking example testcases... ]\n'
+ if options.run_gcc_tests:
+ run_gcc_torture_tests()
+ if EMCC:
+ run_emscripten_tests()
+
+ # Check/display the results
+ if num_failures == 0:
+ print '\n[ success! ]'
+
+ if warnings:
+ print '\n' + '\n'.join(warnings)
+
+ if num_failures > 0:
+ print '\n[ ' + str(num_failures) + ' failures! ]'
+
+ sys.exit(num_failures)
+
+if __name__ == '__main__':
+ main()
+
diff --git a/test/binaryen.js/kitchen-sink.js b/test/binaryen.js/kitchen-sink.js
index 16b5e4fb7..234cac1fe 100644
--- a/test/binaryen.js/kitchen-sink.js
+++ b/test/binaryen.js/kitchen-sink.js
@@ -545,7 +545,7 @@ function test_parsing() {
text = module.emitText();
module.dispose();
module = null;
- print('test_parsing text:\n' + text);
+ console.log('test_parsing text:\n' + text);
text = text.replace('adder', 'ADD_ER');