diff options
-rw-r--r-- | .flake8 | 2 | ||||
-rw-r--r-- | .github/workflows/ci.yml | 13 | ||||
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | CMakeLists.txt | 3 | ||||
-rwxr-xr-x | check.py | 13 | ||||
-rw-r--r-- | requirements-dev.txt | 2 | ||||
-rw-r--r-- | scripts/lit_wrapper.py | 22 | ||||
-rwxr-xr-x | scripts/not.py | 30 | ||||
-rw-r--r-- | scripts/test/lld.py | 2 | ||||
-rw-r--r-- | scripts/test/shared.py | 7 | ||||
-rw-r--r-- | test/lit/CMakeLists.txt | 1 | ||||
-rw-r--r-- | test/lit/lit.cfg.py | 21 | ||||
-rw-r--r-- | test/lit/lit.site.cfg.py.in | 7 | ||||
-rw-r--r-- | test/lit/parse-error.wast | 10 | ||||
-rw-r--r-- | test/lit/validation/shared-memory.wast | 11 | ||||
-rw-r--r-- | test/lit/wasm-emscripten-finalize/bigint.wat | 22 | ||||
-rw-r--r-- | test/lld/bigint.wat | 10 | ||||
-rw-r--r-- | test/lld/bigint.wat.out | 41 | ||||
-rw-r--r-- | test/unit/test_errors.py | 40 |
19 files changed, 161 insertions, 97 deletions
@@ -3,4 +3,4 @@ ignore = E501, # line too long E241, # space after comma (ignored for list in gen-s-parser.py) W504 # line break after binary operator -exclude = ./test/emscripten,./test/spec,./test/wasm-install +exclude = ./test/emscripten,./test/spec,./test/wasm-install,./test/lit diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4f649ec64..c7f95a9fd 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -47,6 +47,9 @@ jobs: python-version: '3.x' - uses: actions/checkout@v1 + - name: install Python dev dependencies + run: pip3 install -r requirements-dev.txt + - name: install ninja (linux) run: sudo apt-get install ninja-build if: matrix.os == 'ubuntu-latest' @@ -92,7 +95,7 @@ jobs: path: out/install - name: test - run: python check.py --binaryen-bin=out/install/bin + run: python check.py --binaryen-bin=out/bin build-clang: name: clang @@ -104,6 +107,8 @@ jobs: - uses: actions/checkout@v1 - name: install ninja run: sudo apt-get install ninja-build + - name: install Python dev dependencies + run: pip3 install -r requirements-dev.txt - name: cmake run: | mkdir -p out @@ -127,6 +132,8 @@ jobs: - uses: actions/checkout@v1 - name: install ninja run: sudo apt-get install ninja-build + - name: install Python dev dependencies + run: pip3 install -r requirements-dev.txt - name: cmake run: | mkdir -p out @@ -151,6 +158,8 @@ jobs: - uses: actions/checkout@v1 - name: install ninja run: sudo apt-get install ninja-build + - name: install Python dev dependencies + run: pip3 install -r requirements-dev.txt - name: cmake run: | mkdir -p out @@ -174,6 +183,8 @@ jobs: - uses: actions/checkout@v1 - name: install ninja run: sudo apt-get install ninja-build + - name: install Python dev dependencies + run: pip3 install -r requirements-dev.txt - name: cmake run: | mkdir -p out diff --git a/.gitignore b/.gitignore index 67a05a37c..d50e02df2 100644 --- a/.gitignore +++ b/.gitignore @@ -25,6 +25,7 @@ CMakeFiles *.o *.obj compile_commands.json +test/lit/lit.site.cfg.py # files related to bulding in-tree on windows /.vs/ diff --git a/CMakeLists.txt b/CMakeLists.txt index d879e86d7..5af62c9c8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -278,6 +278,9 @@ add_subdirectory(src/support) add_subdirectory(src/wasm) add_subdirectory(third_party) +# Configure lit tests +add_subdirectory(test/lit) + # Object files set(binaryen_objs $<TARGET_OBJECTS:passes> @@ -328,6 +328,18 @@ def run_unittest(): raise Exception("unittest failed") +def run_lit(): + lit_script = os.path.join(shared.options.binaryen_root, 'scripts', 'lit_wrapper.py') + lit_cfg = os.path.join(shared.options.binaryen_build, 'test', 'lit') + # lit expects to be run as its own executable + cmd = [sys.executable, lit_script, lit_cfg, '-vv'] + result = subprocess.run(cmd) + if result.returncode != 0: + shared.num_failures += 1 + if shared.options.abort_on_first_failure and shared.num_failures: + raise Exception("lit test failed") + + TEST_SUITES = OrderedDict([ ('help-messages', run_help_tests), ('wasm-opt', wasm_opt.test_wasm_opt), @@ -345,6 +357,7 @@ TEST_SUITES = OrderedDict([ ('unit', run_unittest), ('binaryenjs', binaryenjs.test_binaryen_js), ('binaryenjs_wasm', binaryenjs.test_binaryen_wasm), + ('lit', run_lit), ]) diff --git a/requirements-dev.txt b/requirements-dev.txt index f933898d1..6e0d367c2 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -4,3 +4,5 @@ # Install with `pip3 install -r requirements-dev.txt` flake8==3.7.8 +filecheck==0.0.17 +lit==0.11.0.post1 diff --git a/scripts/lit_wrapper.py b/scripts/lit_wrapper.py new file mode 100644 index 000000000..19473b52f --- /dev/null +++ b/scripts/lit_wrapper.py @@ -0,0 +1,22 @@ +#!/usr/bin/env python3 +# +# Copyright 2020 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. + +from lit.main import main + +# A simple wrapper around `lit`'s main function, since it isn't otherwise +# exposed. +if __name__ == '__main__': + main() diff --git a/scripts/not.py b/scripts/not.py new file mode 100755 index 000000000..98898f451 --- /dev/null +++ b/scripts/not.py @@ -0,0 +1,30 @@ +#!/usr/bin/env python3 + +# Copyright 2020 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 sys +import subprocess + + +# Emulate the `not` tool from LLVM's test infrastructure for use with lit and +# FileCheck. It succeeds if the given subcommand fails and vice versa. +def main(): + cmd = sys.argv[1:] + result = subprocess.run(cmd) + sys.exit(0 if result.returncode != 0 else 1) + + +if __name__ == '__main__': + main() diff --git a/scripts/test/lld.py b/scripts/test/lld.py index 5732f7332..328339287 100644 --- a/scripts/test/lld.py +++ b/scripts/test/lld.py @@ -26,8 +26,6 @@ def args_for_finalize(filename): ret += ['--side-module'] if 'standalone-wasm' in filename: ret += ['--standalone-wasm'] - if 'bigint' in filename: - ret += ['--bigint'] return ret diff --git a/scripts/test/shared.py b/scripts/test/shared.py index 720ad2aa9..dcb52b3fe 100644 --- a/scripts/test/shared.py +++ b/scripts/test/shared.py @@ -50,8 +50,9 @@ def parse_args(args): ' earlier errors.')) parser.add_argument( '--binaryen-bin', dest='binaryen_bin', default='', - help=('Specifies a path to where the built Binaryen executables reside at.' - ' Default: bin/ of current directory (i.e. assume an in-tree build).' + help=('Specifies the path to the Binaryen executables in the CMake build' + ' directory. Default: bin/ of current directory (i.e. assume an' + ' in-tree build).' ' If not specified, the environment variable BINARYEN_ROOT= can also' ' be used to adjust this.')) parser.add_argument( @@ -129,6 +130,8 @@ if not options.binaryen_lib: options.binaryen_lib = os.path.normpath(os.path.abspath(options.binaryen_lib)) +options.binaryen_build = os.path.dirname(options.binaryen_bin) + # ensure BINARYEN_ROOT is set up os.environ['BINARYEN_ROOT'] = os.path.dirname(options.binaryen_bin) diff --git a/test/lit/CMakeLists.txt b/test/lit/CMakeLists.txt new file mode 100644 index 000000000..141896033 --- /dev/null +++ b/test/lit/CMakeLists.txt @@ -0,0 +1 @@ +configure_file(lit.site.cfg.py.in lit.site.cfg.py @ONLY) diff --git a/test/lit/lit.cfg.py b/test/lit/lit.cfg.py new file mode 100644 index 000000000..91dc1aeff --- /dev/null +++ b/test/lit/lit.cfg.py @@ -0,0 +1,21 @@ +import lit.formats + +config.name = "Binaryen lit tests" +config.test_format = lit.formats.ShTest(True) + +config.suffixes = ['.wat', '.wast'] + +config.test_source_root = os.path.dirname(__file__) +config.test_exec_root = os.path.join(config.src_root, 'out', 'test') + +# Replace all Binaryen tools with their absolute paths +bin_dir = os.path.join(config.binaryen_root, 'bin') +for tool_file in os.listdir(bin_dir): + tool_path = config.binaryen_root + '/bin/' + tool_file + tool = tool_file[:-4] if tool_file.endswith('.exe') else tool_file + config.substitutions.append((tool, tool_path)) + +# Also make the `not` command available +not_file = config.src_root + '/scripts/not.py' +python = sys.executable.replace('\\', '/') +config.substitutions.append(('not', python + ' ' + not_file)) diff --git a/test/lit/lit.site.cfg.py.in b/test/lit/lit.site.cfg.py.in new file mode 100644 index 000000000..4b976dbad --- /dev/null +++ b/test/lit/lit.site.cfg.py.in @@ -0,0 +1,7 @@ +import os + +config.src_root = r'@CMAKE_SOURCE_DIR@' +config.binaryen_root = r'@CMAKE_BINARY_DIR@' + +lit_config.load_config( + config, os.path.join(config.src_root, 'test', 'lit', 'lit.cfg.py')) diff --git a/test/lit/parse-error.wast b/test/lit/parse-error.wast new file mode 100644 index 000000000..c301103b2 --- /dev/null +++ b/test/lit/parse-error.wast @@ -0,0 +1,10 @@ +;; Test that parse errors have helpful messages + +;; RUN: not wasm-opt %s 2>&1 | filecheck %s +;; CHECK: [parse exception: abc (at 8:4)] + +(module + (func $foo + (abc) + ) +) diff --git a/test/lit/validation/shared-memory.wast b/test/lit/validation/shared-memory.wast new file mode 100644 index 000000000..259e89b81 --- /dev/null +++ b/test/lit/validation/shared-memory.wast @@ -0,0 +1,11 @@ +;; Test that shared memory requires atomics + +;; RUN: not wasm-opt %s 2>&1 | filecheck %s --check-prefix NO-ATOMICS +;; RUN: wasm-opt %s --enable-threads -o - -S | filecheck %s --check-prefix ATOMICS + +;; NO-ATOMICS: memory is shared, but atomics are disabled +;; ATOMICS: (memory $0 (shared 10 20)) + +(module + (memory (shared 10 20)) +) diff --git a/test/lit/wasm-emscripten-finalize/bigint.wat b/test/lit/wasm-emscripten-finalize/bigint.wat new file mode 100644 index 000000000..817fc9dca --- /dev/null +++ b/test/lit/wasm-emscripten-finalize/bigint.wat @@ -0,0 +1,22 @@ +;; Test that the --bigint option prevents i64s from being split up + +;; Run without --bigint to get a baseline +;; RUN: wasm-emscripten-finalize %s -S | filecheck %s --check-prefix MVP + +;; Then run with --bigint to see the difference +;; RUN: wasm-emscripten-finalize %s -S --bigint | filecheck %s --check-prefix BIGINT + +;; MVP: (export "dynCall_jj" (func $legalstub$dynCall_jj)) +;; MVP: (func $legalstub$dynCall_jj (param $0 i32) (param $1 i32) (param $2 i32) (result i32) + +;; BIGINT-NOT: legalstub +;; BIGINT: (export "dynCall_jj" (func $dynCall_jj)) +;; BIGINT: (func $dynCall_jj (param $fptr i32) (param $0 i64) (result i64) + +(module + (table $0 1 1 funcref) + (elem (i32.const 1) $foo) + (func $foo (param i64) (result i64) + (unreachable) + ) +) diff --git a/test/lld/bigint.wat b/test/lld/bigint.wat deleted file mode 100644 index 4589f396e..000000000 --- a/test/lld/bigint.wat +++ /dev/null @@ -1,10 +0,0 @@ -(module - (table $0 1 1 funcref) - (elem (i32.const 1) $foo) - (export "__data_end" (global $global$1)) - (global $global$0 (mut i32) (i32.const 66208)) - (global $global$1 i32 (i32.const 658)) - (func $foo (param i64) (result i64) - (unreachable) - ) -) diff --git a/test/lld/bigint.wat.out b/test/lld/bigint.wat.out deleted file mode 100644 index bc966d4e7..000000000 --- a/test/lld/bigint.wat.out +++ /dev/null @@ -1,41 +0,0 @@ -(module - (type $i64_=>_i64 (func (param i64) (result i64))) - (type $i32_i64_=>_i64 (func (param i32 i64) (result i64))) - (table $0 1 1 funcref) - (elem (i32.const 1) $foo) - (global $global$0 (mut i32) (i32.const 66208)) - (global $global$1 i32 (i32.const 658)) - (export "__data_end" (global $global$1)) - (export "dynCall_jj" (func $dynCall_jj)) - (func $foo (param $0 i64) (result i64) - (unreachable) - ) - (func $dynCall_jj (param $fptr i32) (param $0 i64) (result i64) - (call_indirect (type $i64_=>_i64) - (local.get $0) - (local.get $fptr) - ) - ) -) -(; ---BEGIN METADATA -- -{ - "tableSize": 1, - "declares": [ - ], - "externs": [ - ], - "exports": [ - "dynCall_jj" - ], - "namedGlobals": { - "__data_end" : "658" - }, - "invokeFuncs": [ - ], - "mainReadsParams": 0, - "features": [ - ] -} --- END METADATA -- -;) diff --git a/test/unit/test_errors.py b/test/unit/test_errors.py deleted file mode 100644 index 15c5a44e6..000000000 --- a/test/unit/test_errors.py +++ /dev/null @@ -1,40 +0,0 @@ -import os - -from scripts.test import shared -from . import utils - - -class ErrorsTest(utils.BinaryenTestCase): - def test_parsing_error_msg(self): - module = ''' -(module - (func $foo - (abc) - ) -) -''' - p = shared.run_process(shared.WASM_OPT + ['--print', '-o', os.devnull], - input=module, check=False, capture_output=True) - self.assertNotEqual(p.returncode, 0) - self.assertIn("parse exception: abc (at 4:4)", p.stderr) - - def test_validation_error_msg(self): - def test(args=[], extra_expected=None): - module = ''' -(module - (memory (shared 10 20)) -) -''' - p = shared.run_process(shared.WASM_OPT + ['-o', os.devnull] + args, - input=module, check=False, capture_output=True) - self.assertNotEqual(p.returncode, 0) - self.assertIn('memory is shared, but atomics are disabled', p.stderr) - if extra_expected: - self.assertIn(extra_expected, p.stdout) - - test() - # when the user asks to print the module, we print it even if it is - # invalid, for debugging (otherwise, an invalid module would not reach - # the stage of runnning passes, and print is a pass, so nothing would - # be printed) - test(['--print'], '(module') |