diff options
author | Sam Clegg <sbc@chromium.org> | 2019-06-06 12:51:39 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-06-06 12:51:39 -0700 |
commit | 4e299e978fd56692d2a2f5169008009567a36046 (patch) | |
tree | 06907937bd42abb4003e6ca45a2c99fa941c281d | |
parent | 616abe47020c90278eaf8d14ae9815c31d2d14fb (diff) | |
download | binaryen-4e299e978fd56692d2a2f5169008009567a36046.tar.gz binaryen-4e299e978fd56692d2a2f5169008009567a36046.tar.bz2 binaryen-4e299e978fd56692d2a2f5169008009567a36046.zip |
Split binaryenjs tests out from main check.py script (#2163)
-rwxr-xr-x | check.py | 59 | ||||
-rwxr-xr-x | scripts/test/binaryenjs.py | 77 | ||||
-rw-r--r-- | scripts/test/shared.py | 1 | ||||
-rwxr-xr-x | travis-emcc-tests.sh | 2 |
4 files changed, 82 insertions, 57 deletions
@@ -20,9 +20,9 @@ import subprocess import sys import unittest -from scripts.test.support import run_command, split_wast, node_test_glue, node_has_webassembly +from scripts.test.support import run_command, split_wast from scripts.test.shared import ( - BIN_DIR, MOZJS, NATIVECC, NATIVEXX, NODEJS, BINARYEN_JS, WASM_AS, + BIN_DIR, NATIVECC, NATIVEXX, NODEJS, WASM_AS, WASM_CTOR_EVAL, WASM_OPT, WASM_SHELL, WASM_METADCE, WASM_DIS, WASM_REDUCE, binary_format_check, delete_from_orbit, fail, fail_with_error, fail_if_not_identical, fail_if_not_contained, has_vanilla_emcc, @@ -36,6 +36,7 @@ from scripts.test import shared from scripts.test import asm2wasm from scripts.test import lld from scripts.test import wasm2js +from scripts.test import binaryenjs if options.interpreter: print '[ using wasm interpreter at "%s" ]' % options.interpreter @@ -387,58 +388,6 @@ 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 or NODEJS): - 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' - return - - 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 - f = open('a.js', 'w') - # avoid stdout/stderr ordering issues in some js shells - use just stdout - f.write(''' - console.warn = function(x) { console.log(x) }; - ''') - binaryen_js = open(BINARYEN_JS).read() - f.write(binaryen_js) - if NODEJS: - f.write(node_test_glue()) - test_path = os.path.join(options.binaryen_test, 'binaryen.js', s) - test_src = open(test_path).read() - f.write(test_src) - f.close() - - def test(engine): - cmd = [engine, 'a.js'] - if 'fatal' not in s: - out = run_command(cmd, stderr=subprocess.STDOUT) - else: - # expect an error - the specific error code will depend on the vm - out = run_command(cmd, stderr=subprocess.STDOUT, expected_status=None) - expected = open(os.path.join(options.binaryen_test, 'binaryen.js', s + '.txt')).read() - if expected not in out: - fail(out, expected) - - # run in all possible shells - if MOZJS: - test(MOZJS) - if NODEJS: - if node_has_wasm or 'WebAssembly.' not in test_src: - test(NODEJS) - else: - print 'Skipping ' + test_path + ' because WebAssembly might not be supported' - - def run_validator_tests(): print '\n[ running validation tests... ]\n' # Ensure the tests validate by default @@ -579,7 +528,7 @@ def main(): run_wasm_reduce_tests() run_spec_tests() - run_binaryen_js_tests() + binaryenjs.test_binaryen_js() lld.test_wasm_emscripten_finalize() wasm2js.test_wasm2js() run_validator_tests() diff --git a/scripts/test/binaryenjs.py b/scripts/test/binaryenjs.py new file mode 100755 index 000000000..2eb2c4683 --- /dev/null +++ b/scripts/test/binaryenjs.py @@ -0,0 +1,77 @@ +#!/usr/bin/env python +# +# Copyright 2016 WebAssembly Community Group participants +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import os +import subprocess + +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' + return + + node_has_wasm = NODEJS and node_has_webassembly(NODEJS) + + if not os.path.exists(BINARYEN_JS): + print 'no binaryen.js build to test' + return + + 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 + f = open('a.js', 'w') + # avoid stdout/stderr ordering issues in some js shells - use just stdout + f.write(''' + console.warn = function(x) { console.log(x) }; + ''') + binaryen_js = open(BINARYEN_JS).read() + f.write(binaryen_js) + if NODEJS: + f.write(node_test_glue()) + test_path = os.path.join(options.binaryen_test, 'binaryen.js', s) + test_src = open(test_path).read() + f.write(test_src) + f.close() + + def test(engine): + cmd = [engine, 'a.js'] + if 'fatal' not in s: + out = run_command(cmd, stderr=subprocess.STDOUT) + else: + # expect an error - the specific error code will depend on the vm + out = run_command(cmd, stderr=subprocess.STDOUT, expected_status=None) + expected = open(os.path.join(options.binaryen_test, 'binaryen.js', s + '.txt')).read() + if expected not in out: + fail(out, expected) + + # run in all possible shells + if MOZJS: + test(MOZJS) + if NODEJS: + if node_has_wasm or 'WebAssembly.' not in test_src: + test(NODEJS) + else: + print 'Skipping ' + test_path + ' because WebAssembly might not be supported' + + +if __name__ == "__main__": + test_binaryen_js() diff --git a/scripts/test/shared.py b/scripts/test/shared.py index 6fb66a21a..9352f0b9d 100644 --- a/scripts/test/shared.py +++ b/scripts/test/shared.py @@ -72,7 +72,6 @@ def parse_args(args): action='store_true', default=False, help=('If specified, all unfreed (but still referenced) pointers at the' ' end of execution are considered memory leaks. Default: disabled.')) - parser.add_argument( 'positional_args', metavar='tests', nargs=argparse.REMAINDER, help='Names specific tests to run.') diff --git a/travis-emcc-tests.sh b/travis-emcc-tests.sh index 70507a2aa..7ad55d123 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" -python -c "import check ; check.run_binaryen_js_tests()" +./scripts/test/binaryenjs.py echo "travis-test yay!" |