Skip to content

Commit 4e299e9

Browse files
authored
Split binaryenjs tests out from main check.py script (#2163)
1 parent 616abe4 commit 4e299e9

4 files changed

Lines changed: 82 additions & 57 deletions

File tree

check.py

Lines changed: 4 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@
2020
import sys
2121
import unittest
2222

23-
from scripts.test.support import run_command, split_wast, node_test_glue, node_has_webassembly
23+
from scripts.test.support import run_command, split_wast
2424
from scripts.test.shared import (
25-
BIN_DIR, MOZJS, NATIVECC, NATIVEXX, NODEJS, BINARYEN_JS, WASM_AS,
25+
BIN_DIR, NATIVECC, NATIVEXX, NODEJS, WASM_AS,
2626
WASM_CTOR_EVAL, WASM_OPT, WASM_SHELL, WASM_METADCE, WASM_DIS, WASM_REDUCE,
2727
binary_format_check, delete_from_orbit, fail, fail_with_error,
2828
fail_if_not_identical, fail_if_not_contained, has_vanilla_emcc,
@@ -36,6 +36,7 @@
3636
from scripts.test import asm2wasm
3737
from scripts.test import lld
3838
from scripts.test import wasm2js
39+
from scripts.test import binaryenjs
3940

4041
if options.interpreter:
4142
print '[ using wasm interpreter at "%s" ]' % options.interpreter
@@ -387,58 +388,6 @@ def fix_actual(x):
387388
check_expected(actual, os.path.join(options.binaryen_test, 'spec', 'expected-output', os.path.basename(wast) + '.log'))
388389

389390

390-
def run_binaryen_js_tests():
391-
if not (MOZJS or NODEJS):
392-
print 'no vm to run binaryen.js tests'
393-
return
394-
395-
node_has_wasm = NODEJS and node_has_webassembly(NODEJS)
396-
397-
if not os.path.exists(BINARYEN_JS):
398-
print 'no binaryen.js build to test'
399-
return
400-
401-
print '\n[ checking binaryen.js testcases... ]\n'
402-
403-
for s in sorted(os.listdir(os.path.join(options.binaryen_test, 'binaryen.js'))):
404-
if not s.endswith('.js'):
405-
continue
406-
print s
407-
f = open('a.js', 'w')
408-
# avoid stdout/stderr ordering issues in some js shells - use just stdout
409-
f.write('''
410-
console.warn = function(x) { console.log(x) };
411-
''')
412-
binaryen_js = open(BINARYEN_JS).read()
413-
f.write(binaryen_js)
414-
if NODEJS:
415-
f.write(node_test_glue())
416-
test_path = os.path.join(options.binaryen_test, 'binaryen.js', s)
417-
test_src = open(test_path).read()
418-
f.write(test_src)
419-
f.close()
420-
421-
def test(engine):
422-
cmd = [engine, 'a.js']
423-
if 'fatal' not in s:
424-
out = run_command(cmd, stderr=subprocess.STDOUT)
425-
else:
426-
# expect an error - the specific error code will depend on the vm
427-
out = run_command(cmd, stderr=subprocess.STDOUT, expected_status=None)
428-
expected = open(os.path.join(options.binaryen_test, 'binaryen.js', s + '.txt')).read()
429-
if expected not in out:
430-
fail(out, expected)
431-
432-
# run in all possible shells
433-
if MOZJS:
434-
test(MOZJS)
435-
if NODEJS:
436-
if node_has_wasm or 'WebAssembly.' not in test_src:
437-
test(NODEJS)
438-
else:
439-
print 'Skipping ' + test_path + ' because WebAssembly might not be supported'
440-
441-
442391
def run_validator_tests():
443392
print '\n[ running validation tests... ]\n'
444393
# Ensure the tests validate by default
@@ -579,7 +528,7 @@ def main():
579528
run_wasm_reduce_tests()
580529

581530
run_spec_tests()
582-
run_binaryen_js_tests()
531+
binaryenjs.test_binaryen_js()
583532
lld.test_wasm_emscripten_finalize()
584533
wasm2js.test_wasm2js()
585534
run_validator_tests()

scripts/test/binaryenjs.py

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
#!/usr/bin/env python
2+
#
3+
# Copyright 2016 WebAssembly Community Group participants
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
import os
18+
import subprocess
19+
20+
from support import run_command, node_has_webassembly, node_test_glue
21+
from shared import BINARYEN_JS, MOZJS, NODEJS, options, fail
22+
23+
24+
def test_binaryen_js():
25+
if not (MOZJS or NODEJS):
26+
print 'no vm to run binaryen.js tests'
27+
return
28+
29+
node_has_wasm = NODEJS and node_has_webassembly(NODEJS)
30+
31+
if not os.path.exists(BINARYEN_JS):
32+
print 'no binaryen.js build to test'
33+
return
34+
35+
print '\n[ checking binaryen.js testcases... ]\n'
36+
37+
for s in sorted(os.listdir(os.path.join(options.binaryen_test, 'binaryen.js'))):
38+
if not s.endswith('.js'):
39+
continue
40+
print s
41+
f = open('a.js', 'w')
42+
# avoid stdout/stderr ordering issues in some js shells - use just stdout
43+
f.write('''
44+
console.warn = function(x) { console.log(x) };
45+
''')
46+
binaryen_js = open(BINARYEN_JS).read()
47+
f.write(binaryen_js)
48+
if NODEJS:
49+
f.write(node_test_glue())
50+
test_path = os.path.join(options.binaryen_test, 'binaryen.js', s)
51+
test_src = open(test_path).read()
52+
f.write(test_src)
53+
f.close()
54+
55+
def test(engine):
56+
cmd = [engine, 'a.js']
57+
if 'fatal' not in s:
58+
out = run_command(cmd, stderr=subprocess.STDOUT)
59+
else:
60+
# expect an error - the specific error code will depend on the vm
61+
out = run_command(cmd, stderr=subprocess.STDOUT, expected_status=None)
62+
expected = open(os.path.join(options.binaryen_test, 'binaryen.js', s + '.txt')).read()
63+
if expected not in out:
64+
fail(out, expected)
65+
66+
# run in all possible shells
67+
if MOZJS:
68+
test(MOZJS)
69+
if NODEJS:
70+
if node_has_wasm or 'WebAssembly.' not in test_src:
71+
test(NODEJS)
72+
else:
73+
print 'Skipping ' + test_path + ' because WebAssembly might not be supported'
74+
75+
76+
if __name__ == "__main__":
77+
test_binaryen_js()

scripts/test/shared.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@ def parse_args(args):
7272
action='store_true', default=False,
7373
help=('If specified, all unfreed (but still referenced) pointers at the'
7474
' end of execution are considered memory leaks. Default: disabled.'))
75-
7675
parser.add_argument(
7776
'positional_args', metavar='tests', nargs=argparse.REMAINDER,
7877
help='Names specific tests to run.')

travis-emcc-tests.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@ set -e
22
echo "travis-test build"
33
./build-js.sh -g
44
echo "travis-test test"
5-
python -c "import check ; check.run_binaryen_js_tests()"
5+
./scripts/test/binaryenjs.py
66
echo "travis-test yay!"

0 commit comments

Comments
 (0)