diff options
-rwxr-xr-x | auto_update_tests.py | 111 | ||||
-rwxr-xr-x | check.py | 110 | ||||
-rwxr-xr-x | scripts/test/binaryenjs.py | 32 | ||||
-rw-r--r-- | scripts/test/wasm_opt.py | 200 |
4 files changed, 238 insertions, 215 deletions
diff --git a/auto_update_tests.py b/auto_update_tests.py index c2bcf47df..86f47def3 100755 --- a/auto_update_tests.py +++ b/auto_update_tests.py @@ -20,10 +20,12 @@ import subprocess import sys from collections import OrderedDict +from scripts.test import binaryenjs from scripts.test import lld from scripts.test import shared from scripts.test import support from scripts.test import wasm2js +from scripts.test import wasm_opt def update_asm_js_tests(): @@ -71,79 +73,6 @@ def update_asm_js_tests(): support.run_command(cmd) -def update_wasm_opt_tests(): - print('\n[ checking wasm-opt -o notation... ]\n') - wast = os.path.join(shared.options.binaryen_test, 'hello_world.wat') - cmd = shared.WASM_OPT + [wast, '-o', 'a.wast', '-S'] - support.run_command(cmd) - open(wast, 'w').write(open('a.wast').read()) - - print('\n[ checking wasm-opt parsing & printing... ]\n') - for t in shared.get_tests(shared.get_test_dir('print'), ['.wast']): - print('..', os.path.basename(t)) - wasm = t.replace('.wast', '') - cmd = shared.WASM_OPT + [t, '--print', '-all'] - print(' ', ' '.join(cmd)) - actual = subprocess.check_output(cmd) - print(cmd, actual) - with open(wasm + '.txt', 'wb') as o: - o.write(actual) - cmd = shared.WASM_OPT + [t, '--print-minified', '-all'] - print(' ', ' '.join(cmd)) - actual = subprocess.check_output(cmd) - with open(wasm + '.minified.txt', 'wb') as o: - o.write(actual) - - print('\n[ checking wasm-opt passes... ]\n') - for t in shared.get_tests(shared.get_test_dir('passes'), ['.wast', '.wasm']): - print('..', os.path.basename(t)) - binary = t.endswith('.wasm') - base = os.path.basename(t).replace('.wast', '').replace('.wasm', '') - passname = base - passes_file = os.path.join(shared.get_test_dir('passes'), passname + '.passes') - if os.path.exists(passes_file): - passname = open(passes_file).read().strip() - opts = [('--' + p if not p.startswith('O') and p != 'g' else '-' + p) for p in passname.split('_')] - actual = '' - for module, asserts in support.split_wast(t): - assert len(asserts) == 0 - support.write_wast('split.wast', module) - cmd = shared.WASM_OPT + opts + ['split.wast'] - if 'noprint' not in t: - cmd.append('--print') - actual += support.run_command(cmd) - with open(os.path.join(shared.options.binaryen_test, 'passes', base + ('.bin' if binary else '') + '.txt'), 'w') as o: - o.write(actual) - if 'emit-js-wrapper' in t: - with open('a.js') as i: - with open(t + '.js', 'w') as o: - o.write(i.read()) - if 'emit-spec-wrapper' in t: - with open('a.wat') as i: - with open(t + '.wat', 'w') as o: - o.write(i.read()) - - print('\n[ checking wasm-opt testcases... ]\n') - for t in shared.get_tests(shared.options.binaryen_test, ['.wast']): - print('..', os.path.basename(t)) - f = t + '.from-wast' - cmd = shared.WASM_OPT + [t, '--print', '-all'] - actual = support.run_command(cmd) - actual = actual.replace('printing before:\n', '') - open(f, 'w').write(actual) - - print('\n[ checking wasm-opt debugInfo read-write... ]\n') - for t in shared.get_tests(shared.options.binaryen_test, ['.fromasm']): - if 'debugInfo' not in t: - continue - print('..', os.path.basename(t)) - f = t + '.read-written' - support.run_command(shared.WASM_AS + [t, '--source-map=a.map', '-o', 'a.wasm', '-g']) - support.run_command(shared.WASM_OPT + ['a.wasm', '--input-source-map=a.map', '-o', 'b.wasm', '--output-source-map=b.map', '-g']) - actual = support.run_command(shared.WASM_DIS + ['b.wasm', '--source-map=b.map']) - open(f, 'w').write(actual) - - def update_bin_fmt_tests(): print('\n[ checking binary format testcases... ]\n') for wast in shared.get_tests(shared.options.binaryen_test, ['.wast']): @@ -238,38 +167,6 @@ def update_wasm_dis_tests(): open(t + '.fromBinary', 'w').write(actual) -def update_binaryen_js_tests(): - if not (shared.MOZJS or shared.NODEJS): - print('no vm to run binaryen.js tests') - return - - if not os.path.exists(shared.BINARYEN_JS): - print('no binaryen.js build to test') - return - - print('\n[ checking binaryen.js testcases... ]\n') - node_has_wasm = shared.NODEJS and support.node_has_webassembly(shared.NODEJS) - for s in shared.get_tests(shared.get_test_dir('binaryen.js'), ['.js']): - basename = os.path.basename(s) - print(basename) - f = open('a.js', 'w') - f.write(open(shared.BINARYEN_JS).read()) - test_src = open(s).read() - f.write(support.js_test_wrap().replace('%TEST%', test_src)) - f.close() - if shared.MOZJS or node_has_wasm or 'WebAssembly.' not in test_src: - cmd = [shared.MOZJS or shared.NODEJS, 'a.js'] - if 'fatal' not in basename: - out = support.run_command(cmd, stderr=subprocess.STDOUT) - else: - # expect an error - the specific error code will depend on the vm - out = support.run_command(cmd, stderr=subprocess.STDOUT, expected_status=None) - with open(s + '.txt', 'w') as o: - o.write(out) - else: - print('Skipping ' + basename + ' because WebAssembly might not be supported') - - def update_ctor_eval_tests(): print('\n[ checking wasm-ctor-eval... ]\n') for t in shared.get_tests(shared.get_test_dir('ctor-eval'), ['.wast', '.wasm']): @@ -326,7 +223,7 @@ def update_spec_tests(): TEST_SUITES = OrderedDict([ - ('wasm-opt', update_wasm_opt_tests), + ('wasm-opt', wasm_opt.update_wasm_opt_tests), ('asm2wasm', update_asm_js_tests), ('wasm-dis', update_wasm_dis_tests), ('example', update_example_tests), @@ -337,7 +234,7 @@ TEST_SUITES = OrderedDict([ ('lld', lld.update_lld_tests), ('wasm2js', wasm2js.update_wasm2js_tests), ('binfmt', update_bin_fmt_tests), - ('binaryenjs', update_binaryen_js_tests), + ('binaryenjs', binaryenjs.update_binaryen_js_tests), ]) @@ -28,6 +28,7 @@ from scripts.test import lld from scripts.test import shared from scripts.test import support from scripts.test import wasm2js +from scripts.test import wasm_opt if shared.options.interpreter: @@ -83,113 +84,6 @@ def run_help_tests(): assert version == changelog_version -def run_wasm_opt_tests(): - print('\n[ checking wasm-opt -o notation... ]\n') - - for extra_args in [[], ['--no-validation']]: - wast = os.path.join(shared.options.binaryen_test, 'hello_world.wat') - shared.delete_from_orbit('a.wat') - out = 'a.wat' - cmd = shared.WASM_OPT + [wast, '-o', out, '-S'] + extra_args - support.run_command(cmd) - shared.fail_if_not_identical_to_file(open(out).read(), wast) - - print('\n[ checking wasm-opt binary reading/writing... ]\n') - - shutil.copyfile(os.path.join(shared.options.binaryen_test, 'hello_world.wat'), 'a.wat') - shared.delete_from_orbit('a.wasm') - shared.delete_from_orbit('b.wast') - support.run_command(shared.WASM_OPT + ['a.wat', '-o', 'a.wasm']) - assert open('a.wasm', 'rb').read()[0] == 0, 'we emit binary by default' - support.run_command(shared.WASM_OPT + ['a.wasm', '-o', 'b.wast', '-S']) - assert open('b.wast', 'rb').read()[0] != 0, 'we emit text with -S' - - print('\n[ checking wasm-opt passes... ]\n') - - for t in shared.get_tests(shared.get_test_dir('passes'), ['.wast', '.wasm']): - print('..', os.path.basename(t)) - binary = '.wasm' in t - base = os.path.basename(t).replace('.wast', '').replace('.wasm', '') - passname = base - passes_file = os.path.join(shared.get_test_dir('passes'), passname + '.passes') - if os.path.exists(passes_file): - passname = open(passes_file).read().strip() - opts = [('--' + p if not p.startswith('O') and p != 'g' else '-' + p) for p in passname.split('_')] - actual = '' - for module, asserts in support.split_wast(t): - assert len(asserts) == 0 - support.write_wast('split.wast', module) - cmd = shared.WASM_OPT + opts + ['split.wast'] - if 'noprint' not in t: - cmd.append('--print') - curr = support.run_command(cmd) - actual += curr - # also check debug mode output is valid - debugged = support.run_command(cmd + ['--debug'], stderr=subprocess.PIPE) - shared.fail_if_not_contained(actual, debugged) - - # also check pass-debug mode - def check(): - pass_debug = support.run_command(cmd) - shared.fail_if_not_identical(curr, pass_debug) - shared.with_pass_debug(check) - - expected_file = os.path.join(shared.get_test_dir('passes'), base + ('.bin' if binary else '') + '.txt') - shared.fail_if_not_identical_to_file(actual, expected_file) - - if 'emit-js-wrapper' in t: - with open('a.js') as actual: - shared.fail_if_not_identical_to_file(actual.read(), t + '.js') - if 'emit-spec-wrapper' in t: - with open('a.wat') as actual: - shared.fail_if_not_identical_to_file(actual.read(), t + '.wat') - - print('\n[ checking wasm-opt parsing & printing... ]\n') - - for t in shared.get_tests(shared.get_test_dir('print'), ['.wast']): - print('..', os.path.basename(t)) - wasm = os.path.basename(t).replace('.wast', '') - cmd = shared.WASM_OPT + [t, '--print', '-all'] - print(' ', ' '.join(cmd)) - actual, err = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True).communicate() - expected_file = os.path.join(shared.get_test_dir('print'), wasm + '.txt') - shared.fail_if_not_identical_to_file(actual, expected_file) - cmd = shared.WASM_OPT + [os.path.join(shared.get_test_dir('print'), t), '--print-minified', '-all'] - print(' ', ' '.join(cmd)) - actual, err = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True).communicate() - shared.fail_if_not_identical(actual.strip(), open(os.path.join(shared.get_test_dir('print'), wasm + '.minified.txt')).read().strip()) - - print('\n[ checking wasm-opt testcases... ]\n') - - for t in shared.get_tests(shared.options.binaryen_test, ['.wast']): - print('..', os.path.basename(t)) - f = t + '.from-wast' - cmd = shared.WASM_OPT + [t, '--print', '-all'] - actual = support.run_command(cmd) - actual = actual.replace('printing before:\n', '') - - shared.fail_if_not_identical_to_file(actual, f) - - # FIXME Remove this condition after nullref is implemented in V8 - if 'reference-types.wast' not in t: - shared.binary_format_check(t, wasm_as_args=['-g']) # test with debuginfo - shared.binary_format_check(t, wasm_as_args=[], binary_suffix='.fromBinary.noDebugInfo') # test without debuginfo - - shared.minify_check(t) - - print('\n[ checking wasm-opt debugInfo read-write... ]\n') - - for t in shared.get_tests(shared.options.binaryen_test, ['.fromasm']): - if 'debugInfo' not in t: - continue - print('..', os.path.basename(t)) - f = t + '.read-written' - support.run_command(shared.WASM_AS + [t, '--source-map=a.map', '-o', 'a.wasm', '-g']) - support.run_command(shared.WASM_OPT + ['a.wasm', '--input-source-map=a.map', '-o', 'b.wasm', '--output-source-map=b.map', '-g']) - actual = support.run_command(shared.WASM_DIS + ['b.wasm', '--source-map=b.map']) - shared.fail_if_not_identical_to_file(actual, f) - - def run_wasm_dis_tests(): print('\n[ checking wasm-dis on provided binaries... ]\n') @@ -451,7 +345,7 @@ def run_unittest(): TEST_SUITES = OrderedDict([ ('help-messages', run_help_tests), - ('wasm-opt', run_wasm_opt_tests), + ('wasm-opt', wasm_opt.test_wasm_opt), ('asm2wasm', asm2wasm.test_asm2wasm), ('asm2wasm-binary', asm2wasm.test_asm2wasm_binary), ('wasm-dis', run_wasm_dis_tests), diff --git a/scripts/test/binaryenjs.py b/scripts/test/binaryenjs.py index 43d039542..f79bf96a1 100755 --- a/scripts/test/binaryenjs.py +++ b/scripts/test/binaryenjs.py @@ -72,6 +72,38 @@ def do_test_binaryen_js_with(which): print('Skipping ' + test_path + ' because WebAssembly might not be supported') +def update_binaryen_js_tests(): + if not (shared.MOZJS or shared.NODEJS): + print('no vm to run binaryen.js tests') + return + + if not os.path.exists(shared.BINARYEN_JS): + print('no binaryen.js build to test') + return + + print('\n[ checking binaryen.js testcases... ]\n') + node_has_wasm = shared.NODEJS and support.node_has_webassembly(shared.NODEJS) + for s in shared.get_tests(shared.get_test_dir('binaryen.js'), ['.js']): + basename = os.path.basename(s) + print(basename) + f = open('a.js', 'w') + f.write(open(shared.BINARYEN_JS).read()) + test_src = open(s).read() + f.write(support.js_test_wrap().replace('%TEST%', test_src)) + f.close() + if shared.MOZJS or node_has_wasm or 'WebAssembly.' not in test_src: + cmd = [shared.MOZJS or shared.NODEJS, 'a.js'] + if 'fatal' not in basename: + out = support.run_command(cmd, stderr=subprocess.STDOUT) + else: + # expect an error - the specific error code will depend on the vm + out = support.run_command(cmd, stderr=subprocess.STDOUT, expected_status=None) + with open(s + '.txt', 'w') as o: + o.write(out) + else: + print('Skipping ' + basename + ' because WebAssembly might not be supported') + + def test_binaryen_js(): do_test_binaryen_js_with(shared.BINARYEN_JS) diff --git a/scripts/test/wasm_opt.py b/scripts/test/wasm_opt.py new file mode 100644 index 000000000..8c6bbdec5 --- /dev/null +++ b/scripts/test/wasm_opt.py @@ -0,0 +1,200 @@ +# 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 shutil +import subprocess + +from . import shared +from . import support + + +def test_wasm_opt(): + print('\n[ checking wasm-opt -o notation... ]\n') + + for extra_args in [[], ['--no-validation']]: + wast = os.path.join(shared.options.binaryen_test, 'hello_world.wat') + shared.delete_from_orbit('a.wat') + out = 'a.wat' + cmd = shared.WASM_OPT + [wast, '-o', out, '-S'] + extra_args + support.run_command(cmd) + shared.fail_if_not_identical_to_file(open(out).read(), wast) + + print('\n[ checking wasm-opt binary reading/writing... ]\n') + + shutil.copyfile(os.path.join(shared.options.binaryen_test, 'hello_world.wat'), 'a.wat') + shared.delete_from_orbit('a.wasm') + shared.delete_from_orbit('b.wast') + support.run_command(shared.WASM_OPT + ['a.wat', '-o', 'a.wasm']) + assert open('a.wasm', 'rb').read()[0] == 0, 'we emit binary by default' + support.run_command(shared.WASM_OPT + ['a.wasm', '-o', 'b.wast', '-S']) + assert open('b.wast', 'rb').read()[0] != 0, 'we emit text with -S' + + print('\n[ checking wasm-opt passes... ]\n') + + for t in shared.get_tests(shared.get_test_dir('passes'), ['.wast', '.wasm']): + print('..', os.path.basename(t)) + binary = '.wasm' in t + base = os.path.basename(t).replace('.wast', '').replace('.wasm', '') + passname = base + passes_file = os.path.join(shared.get_test_dir('passes'), passname + '.passes') + if os.path.exists(passes_file): + passname = open(passes_file).read().strip() + opts = [('--' + p if not p.startswith('O') and p != 'g' else '-' + p) for p in passname.split('_')] + actual = '' + for module, asserts in support.split_wast(t): + assert len(asserts) == 0 + support.write_wast('split.wast', module) + cmd = shared.WASM_OPT + opts + ['split.wast'] + if 'noprint' not in t: + cmd.append('--print') + curr = support.run_command(cmd) + actual += curr + # also check debug mode output is valid + debugged = support.run_command(cmd + ['--debug'], stderr=subprocess.PIPE) + shared.fail_if_not_contained(actual, debugged) + + # also check pass-debug mode + def check(): + pass_debug = support.run_command(cmd) + shared.fail_if_not_identical(curr, pass_debug) + shared.with_pass_debug(check) + + expected_file = os.path.join(shared.get_test_dir('passes'), base + ('.bin' if binary else '') + '.txt') + shared.fail_if_not_identical_to_file(actual, expected_file) + + if 'emit-js-wrapper' in t: + with open('a.js') as actual: + shared.fail_if_not_identical_to_file(actual.read(), t + '.js') + if 'emit-spec-wrapper' in t: + with open('a.wat') as actual: + shared.fail_if_not_identical_to_file(actual.read(), t + '.wat') + + print('\n[ checking wasm-opt parsing & printing... ]\n') + + for t in shared.get_tests(shared.get_test_dir('print'), ['.wast']): + print('..', os.path.basename(t)) + wasm = os.path.basename(t).replace('.wast', '') + cmd = shared.WASM_OPT + [t, '--print', '-all'] + print(' ', ' '.join(cmd)) + actual, err = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True).communicate() + expected_file = os.path.join(shared.get_test_dir('print'), wasm + '.txt') + shared.fail_if_not_identical_to_file(actual, expected_file) + cmd = shared.WASM_OPT + [os.path.join(shared.get_test_dir('print'), t), '--print-minified', '-all'] + print(' ', ' '.join(cmd)) + actual, err = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True).communicate() + shared.fail_if_not_identical(actual.strip(), open(os.path.join(shared.get_test_dir('print'), wasm + '.minified.txt')).read().strip()) + + print('\n[ checking wasm-opt testcases... ]\n') + + for t in shared.get_tests(shared.options.binaryen_test, ['.wast']): + print('..', os.path.basename(t)) + f = t + '.from-wast' + cmd = shared.WASM_OPT + [t, '--print', '-all'] + actual = support.run_command(cmd) + actual = actual.replace('printing before:\n', '') + + shared.fail_if_not_identical_to_file(actual, f) + + # FIXME Remove this condition after nullref is implemented in V8 + if 'reference-types.wast' not in t: + shared.binary_format_check(t, wasm_as_args=['-g']) # test with debuginfo + shared.binary_format_check(t, wasm_as_args=[], binary_suffix='.fromBinary.noDebugInfo') # test without debuginfo + + shared.minify_check(t) + + print('\n[ checking wasm-opt debugInfo read-write... ]\n') + + for t in shared.get_tests(shared.options.binaryen_test, ['.fromasm']): + if 'debugInfo' not in t: + continue + print('..', os.path.basename(t)) + f = t + '.read-written' + support.run_command(shared.WASM_AS + [t, '--source-map=a.map', '-o', 'a.wasm', '-g']) + support.run_command(shared.WASM_OPT + ['a.wasm', '--input-source-map=a.map', '-o', 'b.wasm', '--output-source-map=b.map', '-g']) + actual = support.run_command(shared.WASM_DIS + ['b.wasm', '--source-map=b.map']) + shared.fail_if_not_identical_to_file(actual, f) + + +def update_wasm_opt_tests(): + print('\n[ checking wasm-opt -o notation... ]\n') + wast = os.path.join(shared.options.binaryen_test, 'hello_world.wat') + cmd = shared.WASM_OPT + [wast, '-o', 'a.wast', '-S'] + support.run_command(cmd) + open(wast, 'w').write(open('a.wast').read()) + + print('\n[ checking wasm-opt parsing & printing... ]\n') + for t in shared.get_tests(shared.get_test_dir('print'), ['.wast']): + print('..', os.path.basename(t)) + wasm = t.replace('.wast', '') + cmd = shared.WASM_OPT + [t, '--print', '-all'] + print(' ', ' '.join(cmd)) + actual = subprocess.check_output(cmd) + print(cmd, actual) + with open(wasm + '.txt', 'wb') as o: + o.write(actual) + cmd = shared.WASM_OPT + [t, '--print-minified', '-all'] + print(' ', ' '.join(cmd)) + actual = subprocess.check_output(cmd) + with open(wasm + '.minified.txt', 'wb') as o: + o.write(actual) + + print('\n[ checking wasm-opt passes... ]\n') + for t in shared.get_tests(shared.get_test_dir('passes'), ['.wast', '.wasm']): + print('..', os.path.basename(t)) + binary = t.endswith('.wasm') + base = os.path.basename(t).replace('.wast', '').replace('.wasm', '') + passname = base + passes_file = os.path.join(shared.get_test_dir('passes'), passname + '.passes') + if os.path.exists(passes_file): + passname = open(passes_file).read().strip() + opts = [('--' + p if not p.startswith('O') and p != 'g' else '-' + p) for p in passname.split('_')] + actual = '' + for module, asserts in support.split_wast(t): + assert len(asserts) == 0 + support.write_wast('split.wast', module) + cmd = shared.WASM_OPT + opts + ['split.wast'] + if 'noprint' not in t: + cmd.append('--print') + actual += support.run_command(cmd) + with open(os.path.join(shared.options.binaryen_test, 'passes', base + ('.bin' if binary else '') + '.txt'), 'w') as o: + o.write(actual) + if 'emit-js-wrapper' in t: + with open('a.js') as i: + with open(t + '.js', 'w') as o: + o.write(i.read()) + if 'emit-spec-wrapper' in t: + with open('a.wat') as i: + with open(t + '.wat', 'w') as o: + o.write(i.read()) + + print('\n[ checking wasm-opt testcases... ]\n') + for t in shared.get_tests(shared.options.binaryen_test, ['.wast']): + print('..', os.path.basename(t)) + f = t + '.from-wast' + cmd = shared.WASM_OPT + [t, '--print', '-all'] + actual = support.run_command(cmd) + actual = actual.replace('printing before:\n', '') + open(f, 'w').write(actual) + + print('\n[ checking wasm-opt debugInfo read-write... ]\n') + for t in shared.get_tests(shared.options.binaryen_test, ['.fromasm']): + if 'debugInfo' not in t: + continue + print('..', os.path.basename(t)) + f = t + '.read-written' + support.run_command(shared.WASM_AS + [t, '--source-map=a.map', '-o', 'a.wasm', '-g']) + support.run_command(shared.WASM_OPT + ['a.wasm', '--input-source-map=a.map', '-o', 'b.wasm', '--output-source-map=b.map', '-g']) + actual = support.run_command(shared.WASM_DIS + ['b.wasm', '--source-map=b.map']) + open(f, 'w').write(actual) |