Skip to content

Commit 82d693b

Browse files
authored
Run binaryen.js tests using node, and on travis (#1275)
1 parent 47a27b1 commit 82d693b

3 files changed

Lines changed: 59 additions & 42 deletions

File tree

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ jobs:
7272
before_install:
7373
- docker run -dit --name emscripten -v $(pwd):/src trzeci/emscripten:sdk-incoming-64bit bash
7474
script:
75-
- docker exec -it emscripten bash ./build-js.sh -g
75+
- docker exec -it emscripten bash ./build-js.sh -g && python -c "import check ; check.run_binaryen_js_tests()"
7676

7777
# Build with gcc 6.3 and run tests on Alpine Linux (inside chroot).
7878
# Note: Alpine uses musl libc.

check.py

Lines changed: 57 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -321,16 +321,30 @@ def fix(x):
321321
check_expected(actual, os.path.join(options.binaryen_test, 'spec', 'expected-output', os.path.basename(wast) + '.log'))
322322

323323
def run_binaryen_js_tests():
324+
if not MOZJS and not NODEJS:
325+
return
326+
324327
print '\n[ checking binaryen.js testcases... ]\n'
325328

326329
for s in sorted(os.listdir(os.path.join(options.binaryen_test, 'binaryen.js'))):
327330
if not s.endswith('.js'): continue
328331
print s
329332
f = open('a.js', 'w')
330333
f.write(open(os.path.join(options.binaryen_bin, 'binaryen.js')).read())
331-
f.write(open(os.path.join(options.binaryen_test, 'binaryen.js', s)).read())
334+
# node test support
335+
f.write('\nif (typeof require === "function") var Binaryen = module.exports;\n')
336+
test_path = os.path.join(options.binaryen_test, 'binaryen.js', s)
337+
test = open(test_path).read()
338+
need_wasm = 'WebAssembly.' in test # some tests use wasm support in the VM
339+
if MOZJS:
340+
cmd = [MOZJS]
341+
elif NODEJS and not need_wasm: # TODO: check if node is new and has wasm support
342+
cmd = [NODEJS]
343+
else:
344+
continue # we can't run it
345+
cmd += ['a.js']
346+
f.write(test)
332347
f.close()
333-
cmd = [MOZJS, 'a.js']
334348
out = run_command(cmd, stderr=subprocess.STDOUT)
335349
expected = open(os.path.join(options.binaryen_test, 'binaryen.js', s + '.txt')).read()
336350
if expected not in out:
@@ -537,43 +551,46 @@ def break_cashew():
537551
assert proc.returncode != 0, err
538552
assert 'hello, world!' not in out, out
539553

540-
541554
# Run all the tests
542-
run_help_tests()
543-
run_wasm_opt_tests()
544-
asm2wasm.test_asm2wasm()
545-
asm2wasm.test_asm2wasm_binary()
546-
run_wasm_dis_tests()
547-
run_wasm_merge_tests()
548-
run_ctor_eval_tests()
549-
if has_shell_timeout():
550-
run_wasm_reduce_tests()
551-
552-
run_spec_tests()
553-
if MOZJS:
555+
def main():
556+
run_help_tests()
557+
run_wasm_opt_tests()
558+
asm2wasm.test_asm2wasm()
559+
asm2wasm.test_asm2wasm_binary()
560+
run_wasm_dis_tests()
561+
run_wasm_merge_tests()
562+
run_ctor_eval_tests()
563+
if has_shell_timeout():
564+
run_wasm_reduce_tests()
565+
566+
run_spec_tests()
554567
run_binaryen_js_tests()
555-
s2wasm.test_s2wasm()
556-
s2wasm.test_linker()
557-
wasm2asm.test_wasm2asm()
558-
run_validator_tests()
559-
if options.torture and options.test_waterfall:
560-
run_torture_tests()
561-
if has_vanilla_emcc and has_vanilla_llvm and 0:
562-
run_vanilla_tests()
563-
print '\n[ checking example testcases... ]\n'
564-
if options.run_gcc_tests:
565-
run_gcc_torture_tests()
566-
if EMCC:
567-
run_emscripten_tests()
568-
569-
# Check/display the results
570-
if num_failures == 0:
571-
print '\n[ success! ]'
572-
573-
if warnings:
574-
print '\n' + '\n'.join(warnings)
575-
576-
if num_failures > 0:
577-
print '\n[ ' + str(num_failures) + ' failures! ]'
578-
579-
sys.exit(num_failures)
568+
s2wasm.test_s2wasm()
569+
s2wasm.test_linker()
570+
wasm2asm.test_wasm2asm()
571+
run_validator_tests()
572+
if options.torture and options.test_waterfall:
573+
run_torture_tests()
574+
if has_vanilla_emcc and has_vanilla_llvm and 0:
575+
run_vanilla_tests()
576+
print '\n[ checking example testcases... ]\n'
577+
if options.run_gcc_tests:
578+
run_gcc_torture_tests()
579+
if EMCC:
580+
run_emscripten_tests()
581+
582+
# Check/display the results
583+
if num_failures == 0:
584+
print '\n[ success! ]'
585+
586+
if warnings:
587+
print '\n' + '\n'.join(warnings)
588+
589+
if num_failures > 0:
590+
print '\n[ ' + str(num_failures) + ' failures! ]'
591+
592+
sys.exit(num_failures)
593+
594+
if __name__ == '__main__':
595+
main()
596+

test/binaryen.js/kitchen-sink.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -545,7 +545,7 @@ function test_parsing() {
545545
text = module.emitText();
546546
module.dispose();
547547
module = null;
548-
print('test_parsing text:\n' + text);
548+
console.log('test_parsing text:\n' + text);
549549

550550
text = text.replace('adder', 'ADD_ER');
551551

0 commit comments

Comments
 (0)