diff options
27 files changed, 51 insertions, 173 deletions
@@ -200,19 +200,10 @@ $ out/wasm-interp test.json --spec $ out/wasm-interp test.wasm -V 100 --run-all-exports ``` -As a convenience, you can use `test/run-interp.py` to convert a .wat file to -binary first, then run it in the interpreter: - -```console -$ test/run-interp.py --spec spec-test.wat -20/20 tests.passed. -``` - You can use `-h` to get additional help: ```console $ out/wasm-interp -h -$ out/run-interp.py -h ``` ## Running the test suite diff --git a/src/binary-reader-interp.cc b/src/binary-reader-interp.cc index d053b325..10180e2a 100644 --- a/src/binary-reader-interp.cc +++ b/src/binary-reader-interp.cc @@ -624,7 +624,9 @@ wabt::Result BinaryReaderInterp::AppendExport(Module* module, ExternalKind kind, Index item_index, string_view name) { - if (module->export_bindings.FindIndex(name) != kInvalidIndex) { + // Host modules are allowed to have duplicated exports; e.g. "spectest.print" + if (isa<DefinedModule>(module) && + module->export_bindings.FindIndex(name) != kInvalidIndex) { PrintError("duplicate export \"" PRIstringview "\"", WABT_PRINTF_STRING_VIEW_ARG(name)); return wabt::Result::Error; diff --git a/test/README.md b/test/README.md index 80905dff..1fdd7449 100644 --- a/test/README.md +++ b/test/README.md @@ -103,6 +103,8 @@ The currently supported list of keys: - `RUN`: the executable to run, defaults to out/wat2wasm - `STDIN_FILE`: the file to use for STDIN instead of the contents of this file. - `ARGS`: additional args to pass to the executable +- `ARGS{N}`: additional args to the Nth `RUN` command (zero-based) +- `ARGS*`: additional args to all `RUN` commands - `ENV`: environment variables to set, separated by spaces - `ERROR`: the expected return value from the executable, defaults to 0 - `SLOW`: if defined, this test's timeout is doubled. diff --git a/test/interp/atomic-load.txt b/test/interp/atomic-load.txt index 17a5901c..fb244cab 100644 --- a/test/interp/atomic-load.txt +++ b/test/interp/atomic-load.txt @@ -1,5 +1,5 @@ ;;; TOOL: run-interp -;;; ARGS: --enable-threads +;;; ARGS*: --enable-threads (module (memory 1 1 shared) (data (i32.const 0) "\ff\ff\ff\ff") diff --git a/test/interp/atomic-rmw-add.txt b/test/interp/atomic-rmw-add.txt index 9ee920fe..655629c8 100644 --- a/test/interp/atomic-rmw-add.txt +++ b/test/interp/atomic-rmw-add.txt @@ -1,5 +1,5 @@ ;;; TOOL: run-interp -;;; ARGS: --enable-threads +;;; ARGS*: --enable-threads (module (memory 1 1 shared) diff --git a/test/interp/atomic-rmw-and.txt b/test/interp/atomic-rmw-and.txt index 5820a5fd..7534ecc1 100644 --- a/test/interp/atomic-rmw-and.txt +++ b/test/interp/atomic-rmw-and.txt @@ -1,5 +1,5 @@ ;;; TOOL: run-interp -;;; ARGS: --enable-threads +;;; ARGS*: --enable-threads (module (memory 1 1 shared) diff --git a/test/interp/atomic-rmw-cmpxchg.txt b/test/interp/atomic-rmw-cmpxchg.txt index e4a3e46a..937ac4ad 100644 --- a/test/interp/atomic-rmw-cmpxchg.txt +++ b/test/interp/atomic-rmw-cmpxchg.txt @@ -1,5 +1,5 @@ ;;; TOOL: run-interp -;;; ARGS: --enable-threads +;;; ARGS*: --enable-threads (module (memory 1 1 shared) diff --git a/test/interp/atomic-rmw-or.txt b/test/interp/atomic-rmw-or.txt index 9a33db0d..c1791ea1 100644 --- a/test/interp/atomic-rmw-or.txt +++ b/test/interp/atomic-rmw-or.txt @@ -1,5 +1,5 @@ ;;; TOOL: run-interp -;;; ARGS: --enable-threads +;;; ARGS*: --enable-threads (module (memory 1 1 shared) diff --git a/test/interp/atomic-rmw-sub.txt b/test/interp/atomic-rmw-sub.txt index 1463ce99..9c31479e 100644 --- a/test/interp/atomic-rmw-sub.txt +++ b/test/interp/atomic-rmw-sub.txt @@ -1,5 +1,5 @@ ;;; TOOL: run-interp -;;; ARGS: --enable-threads +;;; ARGS*: --enable-threads (module (memory 1 1 shared) diff --git a/test/interp/atomic-rmw-xchg.txt b/test/interp/atomic-rmw-xchg.txt index 345791dd..786aa05d 100644 --- a/test/interp/atomic-rmw-xchg.txt +++ b/test/interp/atomic-rmw-xchg.txt @@ -1,5 +1,5 @@ ;;; TOOL: run-interp -;;; ARGS: --enable-threads +;;; ARGS*: --enable-threads (module (memory 1 1 shared) diff --git a/test/interp/atomic-rmw-xor.txt b/test/interp/atomic-rmw-xor.txt index f8c97989..fa31d9b8 100644 --- a/test/interp/atomic-rmw-xor.txt +++ b/test/interp/atomic-rmw-xor.txt @@ -1,5 +1,5 @@ ;;; TOOL: run-interp -;;; ARGS: --enable-threads +;;; ARGS*: --enable-threads (module (memory 1 1 shared) diff --git a/test/interp/atomic-store.txt b/test/interp/atomic-store.txt index a5fbde63..d106ad26 100644 --- a/test/interp/atomic-store.txt +++ b/test/interp/atomic-store.txt @@ -1,5 +1,5 @@ ;;; TOOL: run-interp -;;; ARGS: --enable-threads +;;; ARGS*: --enable-threads (module (memory 1 1 shared) diff --git a/test/interp/basic-logging.txt b/test/interp/basic-logging.txt index d7d412d1..89818302 100644 --- a/test/interp/basic-logging.txt +++ b/test/interp/basic-logging.txt @@ -1,5 +1,5 @@ ;;; TOOL: run-interp -;;; ARGS: -v +;;; ARGS*: -v (module (func (export "main") (result i32) i32.const 42 diff --git a/test/interp/convert-sat.txt b/test/interp/convert-sat.txt index 7c640ae9..5fdcf7af 100644 --- a/test/interp/convert-sat.txt +++ b/test/interp/convert-sat.txt @@ -1,5 +1,5 @@ ;;; TOOL: run-interp -;;; ARGS: --enable-saturating-float-to-int +;;; ARGS*: --enable-saturating-float-to-int (module (func (export "i32.trunc_s:sat/f32") (result i32) f32.const -100.12345 diff --git a/test/interp/import.txt b/test/interp/import.txt index 69505fff..a29fa9bb 100644 --- a/test/interp/import.txt +++ b/test/interp/import.txt @@ -1,5 +1,5 @@ ;;; TOOL: run-interp -;;; ARGS: --host-print +;;; ARGS1: --host-print (module (import "host" "print" (func $print_i32 (param i32))) (import "host" "print" (func $print_i32_i32 (param i32 i32))) diff --git a/test/interp/logging-all-opcodes.txt b/test/interp/logging-all-opcodes.txt index aeca871d..0714f536 100644 --- a/test/interp/logging-all-opcodes.txt +++ b/test/interp/logging-all-opcodes.txt @@ -1,5 +1,6 @@ ;;; TOOL: run-interp -;;; ARGS: -v --host-print --enable-threads --enable-saturating-float-to-int --enable-sign-extension +;;; ARGS*: -v --enable-threads --enable-saturating-float-to-int --enable-sign-extension +;;; ARGS1: --host-print (module (import "host" "print" (func $print (param i32))) diff --git a/test/interp/simd-basic.txt b/test/interp/simd-basic.txt index 7cb551a5..701a7037 100644 --- a/test/interp/simd-basic.txt +++ b/test/interp/simd-basic.txt @@ -1,5 +1,5 @@ ;;; TOOL: run-interp -;;; ARGS: --enable-simd +;;; ARGS*: --enable-simd (module (func (export "main") (result v128) v128.const i32 0x00000001 0x00000002 0x00000003 0x00000004 diff --git a/test/interp/simd-binary.txt b/test/interp/simd-binary.txt index 9cbcd019..8fb856b5 100644 --- a/test/interp/simd-binary.txt +++ b/test/interp/simd-binary.txt @@ -1,5 +1,5 @@ ;;; TOOL: run-interp -;;; ARGS: --enable-simd +;;; ARGS*: --enable-simd (module ;; i8x16 add (func (export "i8x16_add_0") (result v128) diff --git a/test/interp/simd-splat.txt b/test/interp/simd-splat.txt index 62b3b740..dbbbf81d 100644 --- a/test/interp/simd-splat.txt +++ b/test/interp/simd-splat.txt @@ -1,5 +1,5 @@ ;;; TOOL: run-interp -;;; ARGS: --enable-simd +;;; ARGS*: --enable-simd (module ;; i8x16 diff --git a/test/interp/simd-unary.txt b/test/interp/simd-unary.txt index 82c9f0da..c7c467f8 100644 --- a/test/interp/simd-unary.txt +++ b/test/interp/simd-unary.txt @@ -1,5 +1,5 @@ ;;; TOOL: run-interp -;;; ARGS: --enable-simd +;;; ARGS*: --enable-simd (module ;; i8x16 neg (func (export "i8x16_neg_0") (result v128) diff --git a/test/interp/tracing-all-opcodes.txt b/test/interp/tracing-all-opcodes.txt index 77aa6b25..dce39891 100644 --- a/test/interp/tracing-all-opcodes.txt +++ b/test/interp/tracing-all-opcodes.txt @@ -1,5 +1,6 @@ ;;; TOOL: run-interp -;;; ARGS: --trace --host-print --enable-threads --enable-saturating-float-to-int --enable-sign-extension +;;; ARGS*: --enable-threads --enable-saturating-float-to-int --enable-sign-extension +;;; ARGS1: --trace --host-print (module (import "host" "print" (func $print (param i32))) diff --git a/test/interp/unary-extend.txt b/test/interp/unary-extend.txt index 79d4738d..6b80e650 100644 --- a/test/interp/unary-extend.txt +++ b/test/interp/unary-extend.txt @@ -1,5 +1,5 @@ ;;; TOOL: run-interp -;;; ARGS: --enable-sign-extension +;;; ARGS*: --enable-sign-extension (module (func (export "i32.extend8_s 0x7f") (result i32) i32.const 0x7f diff --git a/test/regress/regress-17.txt b/test/regress/regress-17.txt index 35dc3d38..7359d33d 100644 --- a/test/regress/regress-17.txt +++ b/test/regress/regress-17.txt @@ -5,7 +5,6 @@ ;; Make sure that the error below has the correct location. (invoke "foo" (i32.const 1)) (;; STDERR ;;; -Error running "wast2json": out/test/regress/regress-17.txt:6:26: error: type mismatch for argument 0 of invoke. got i32, expected i64 (invoke "foo" (i32.const 1)) ^ diff --git a/test/run-interp.py b/test/run-interp.py deleted file mode 100755 index 6d6bb4d3..00000000 --- a/test/run-interp.py +++ /dev/null @@ -1,121 +0,0 @@ -#!/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 argparse -import os -import subprocess -import sys - -import find_exe -import utils -from utils import Error - -SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__)) - - -def main(args): - parser = argparse.ArgumentParser() - parser.add_argument('-o', '--out-dir', metavar='PATH', - help='output directory for files.') - parser.add_argument('-v', '--verbose', help='print more diagnotic messages.', - action='store_true') - parser.add_argument('--bindir', metavar='PATH', - default=find_exe.GetDefaultPath(), - help='directory to search for all executables.') - parser.add_argument('--no-error-cmdline', - help='don\'t display the subprocess\'s commandline when' - + ' an error occurs', dest='error_cmdline', - action='store_false') - parser.add_argument('-p', '--print-cmd', - help='print the commands that are run.', - action='store_true') - parser.add_argument('--run-all-exports', action='store_true') - parser.add_argument('--host-print', action='store_true') - parser.add_argument('--spec', action='store_true') - parser.add_argument('-t', '--trace', action='store_true') - parser.add_argument('file', help='test file.') - parser.add_argument('--enable-exceptions', action='store_true') - parser.add_argument('--enable-mutable-globals', action='store_true') - parser.add_argument('--enable-saturating-float-to-int', action='store_true') - parser.add_argument('--enable-sign-extension', action='store_true') - parser.add_argument('--enable-simd', action='store_true') - parser.add_argument('--enable-threads', action='store_true') - options = parser.parse_args(args) - - wast_tool = None - interp_tool = None - if options.spec: - wast_tool = utils.Executable( - find_exe.GetWast2JsonExecutable(options.bindir), - error_cmdline=options.error_cmdline) - interp_tool = utils.Executable( - find_exe.GetSpectestInterpExecutable(options.bindir), - error_cmdline=options.error_cmdline) - else: - wast_tool = utils.Executable( - find_exe.GetWat2WasmExecutable(options.bindir), - error_cmdline=options.error_cmdline) - interp_tool = utils.Executable( - find_exe.GetWasmInterpExecutable(options.bindir), - error_cmdline=options.error_cmdline) - interp_tool.AppendOptionalArgs({ - '--host-print': options.host_print, - '--run-all-exports': options.run_all_exports, - }) - - wast_tool.AppendOptionalArgs({ - '-v': options.verbose, - '--enable-exceptions': options.enable_exceptions, - '--enable-mutable-globals': options.enable_mutable_globals, - '--enable-saturating-float-to-int': - options.enable_saturating_float_to_int, - '--enable-sign-extension': options.enable_sign_extension, - '--enable-simd': options.enable_simd, - '--enable-threads': options.enable_threads, - }) - - interp_tool.AppendOptionalArgs({ - '-v': options.verbose, - '--run-all-exports': options.run_all_exports, - '--trace': options.trace, - '--enable-exceptions': options.enable_exceptions, - '--enable-mutable-globals': options.enable_mutable_globals, - '--enable-saturating-float-to-int': - options.enable_saturating_float_to_int, - '--enable-sign-extension': options.enable_sign_extension, - '--enable-simd': options.enable_simd, - '--enable-threads': options.enable_threads, - }) - - wast_tool.verbose = options.print_cmd - interp_tool.verbose = options.print_cmd - - with utils.TempDirectory(options.out_dir, 'run-interp-') as out_dir: - new_ext = '.json' if options.spec else '.wasm' - out_file = utils.ChangeDir(utils.ChangeExt(options.file, new_ext), out_dir) - wast_tool.RunWithArgs(options.file, '-o', out_file) - interp_tool.RunWithArgs(out_file) - - return 0 - - -if __name__ == '__main__': - try: - sys.exit(main(sys.argv[1:])) - except Error as e: - sys.stderr.write(str(e) + '\n') - sys.exit(1) diff --git a/test/run-tests.py b/test/run-tests.py index 51eebc93..7e73b0c3 100755 --- a/test/run-tests.py +++ b/test/run-tests.py @@ -83,27 +83,13 @@ TOOLS = { ('VERBOSE-ARGS', ['--print-cmd', '-v']), ], 'run-interp': [ - ('RUN', 'test/run-interp.py'), - ('ARGS', [ - '%(in_file)s', - '--bindir=%(bindir)s', - '--run-all-exports', - '--no-error-cmdline', - '-o', - '%(out_dir)s', - ]), + ('RUN', '%(wat2wasm)s %(in_file)s -o %(temp_file)s.wasm'), + ('RUN', '%(wasm-interp)s %(temp_file)s.wasm --run-all-exports'), ('VERBOSE-ARGS', ['--print-cmd', '-v']), ], 'run-interp-spec': [ - ('RUN', 'test/run-interp.py'), - ('ARGS', [ - '%(in_file)s', - '--bindir=%(bindir)s', - '--spec', - '--no-error-cmdline', - '-o', - '%(out_dir)s', - ]), + ('RUN', '%(wast2json)s %(in_file)s -o %(temp_file)s.json'), + ('RUN', '%(spectest-interp)s %(temp_file)s.json'), ('VERBOSE-ARGS', ['--print-cmd', '-v']), ], 'run-gen-wasm': [ @@ -424,20 +410,33 @@ class TestInfo(object): for tool_key, tool_value in TOOLS[tool]: self.ParseDirective(tool_key, tool_value) + def GetCommand(self, index): + if index >= len(self.cmds): + raise Error('Invalid command index: %s' % index) + return self.cmds[index] + def GetLastCommand(self): if not self.cmds: self.SetTool('wat2wasm') return self.cmds[-1] + def AppendArgsToAllCommands(self, args): + for cmd in self.cmds: + cmd.AppendArgs(args) + def ParseDirective(self, key, value): if key == 'RUN': self.cmds.append(CommandTemplate(value)) elif key == 'STDIN_FILE': self.input_filename = value elif key == 'ARGS': - if not isinstance(value, list): - value = shlex.split(value) self.GetLastCommand().AppendArgs(value) + elif key.startswith('ARGS'): + suffix = key[len('ARGS'):] + if suffix == '*': + self.AppendArgsToAllCommands(value) + elif re.match(r'^\d+$', suffix): + self.GetCommand(int(suffix)).AppendArgs(value) elif key == 'ERROR': self.expected_error = int(value) elif key == 'SLOW': @@ -680,6 +679,12 @@ def RunTest(info, options, variables, verbose_level=0): os.makedirs(out_dir) variables['out_dir'] = out_dir + # Temporary files typically are placed in `out_dir` and use the same test's + # basename. This name does include an extension. + input_basename = os.path.basename(rel_gen_input_path) + variables['temp_file'] = os.path.join( + out_dir, os.path.splitext(input_basename)[0]) + final_result = RunResult() for cmd_template in info.cmds: diff --git a/test/spec/linking.txt b/test/spec/linking.txt index d4536c01..1d24dcdd 100644 --- a/test/spec/linking.txt +++ b/test/spec/linking.txt @@ -23,7 +23,6 @@ out/test/spec/linking.wast:266: assert_unlinkable passed: error: data segment is out of bounds: [65536, 65537) >= max value 65536 0000020: error: OnDataSegmentData callback failed out/test/spec/linking.wast:291: assert_unlinkable passed: - error: duplicate export "print" error: unknown module field "tab" 0000037: error: OnImportTable callback failed out/test/spec/linking.wast:302: assert_unlinkable passed: diff --git a/test/spec/memory.txt b/test/spec/memory.txt index 9f848699..5551d8b7 100644 --- a/test/spec/memory.txt +++ b/test/spec/memory.txt @@ -61,7 +61,6 @@ out/test/spec/memory.wast:105: assert_unlinkable passed: error: data segment is out of bounds: [4294967295, 4294967295) >= max value 65536 0000016: error: OnDataSegmentData callback failed out/test/spec/memory.wast:114: assert_unlinkable passed: - error: duplicate export "global" error: data segment is out of bounds: [666, 667) >= max value 0 000002c: error: OnDataSegmentData callback failed out/test/spec/memory.wast:131: assert_invalid passed: |