diff options
author | Thomas Lively <7121787+tlively@users.noreply.github.com> | 2019-03-25 18:11:45 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-03-25 18:11:45 -0700 |
commit | 56c5ff78310ad956e70bf1a00a64c72ee81d18bd (patch) | |
tree | 28d0a5ed42a44f18f314d57cd66dc1e545669b02 | |
parent | 5e19a7b05144736ec17ee6b0bb366afa744137c6 (diff) | |
download | binaryen-56c5ff78310ad956e70bf1a00a64c72ee81d18bd.tar.gz binaryen-56c5ff78310ad956e70bf1a00a64c72ee81d18bd.tar.bz2 binaryen-56c5ff78310ad956e70bf1a00a64c72ee81d18bd.zip |
More validation tests and fixes for SIMD (#1964)
Moves the feature validation unit test file to a new directory,
'unit', and adds new tests for SIMD and sign-ext. Adds validation for
v128 globals and v128.const.
-rw-r--r-- | src/wasm/wasm-validator.cpp | 8 | ||||
-rw-r--r-- | test/crash/test_features.py | 18 | ||||
-rw-r--r-- | test/unit/__init__.py (renamed from test/crash/__init__.py) | 0 | ||||
-rw-r--r-- | test/unit/test_features.py | 88 |
4 files changed, 96 insertions, 18 deletions
diff --git a/src/wasm/wasm-validator.cpp b/src/wasm/wasm-validator.cpp index 91e7e7398..5c0e0d542 100644 --- a/src/wasm/wasm-validator.cpp +++ b/src/wasm/wasm-validator.cpp @@ -235,6 +235,7 @@ public: void visitSwitch(Switch* curr); void visitCall(Call* curr); void visitCallIndirect(CallIndirect* curr); + void visitConst(Const* curr); void visitGetLocal(GetLocal* curr); void visitSetLocal(SetLocal* curr); void visitGetGlobal(GetGlobal* curr); @@ -475,6 +476,11 @@ void FunctionValidator::visitCallIndirect(CallIndirect* curr) { } } +void FunctionValidator::visitConst(Const* curr) { + shouldBeTrue(getFeatures(curr->type) <= info.features, curr, + "all used features should be allowed"); +} + void FunctionValidator::visitGetLocal(GetLocal* curr) { shouldBeTrue(curr->index < getFunction()->getNumLocals(), curr, "local.get index must be small enough"); shouldBeTrue(isConcreteType(curr->type), curr, "local.get must have a valid type - check what you provided when you constructed the node"); @@ -1270,6 +1276,8 @@ static void validateExports(Module& module, ValidationInfo& info) { static void validateGlobals(Module& module, ValidationInfo& info) { ModuleUtils::iterDefinedGlobals(module, [&](Global* curr) { + info.shouldBeTrue(getFeatures(curr->type) <= info.features, curr->name, + "all used types should be allowed"); info.shouldBeTrue(curr->init != nullptr, curr->name, "global init must be non-null"); info.shouldBeTrue(curr->init->is<Const>() || curr->init->is<GetGlobal>(), curr->name, "global init must be valid"); if (!info.shouldBeEqual(curr->type, curr->init->type, curr->init, "global init must have correct type") && !info.quiet) { diff --git a/test/crash/test_features.py b/test/crash/test_features.py deleted file mode 100644 index 87521d4c0..000000000 --- a/test/crash/test_features.py +++ /dev/null @@ -1,18 +0,0 @@ -import unittest -from scripts.test.shared import WASM_OPT, run_process - - -class FeatureValidationTest(unittest.TestCase): - def test_simd_type(self): - module = """ - (module - (func $foo (param $0 v128) (result v128) - (local.get $0) - ) - ) - """ - p = run_process(WASM_OPT + ['--mvp-features', '--print'], - input=module, check=False, capture_output=True) - self.assertIn("all used types should be allowed", p.stderr) - self.assertIn("Fatal: error in validating input", p.stderr) - self.assertNotEqual(p.returncode, 0) diff --git a/test/crash/__init__.py b/test/unit/__init__.py index e69de29bb..e69de29bb 100644 --- a/test/crash/__init__.py +++ b/test/unit/__init__.py diff --git a/test/unit/test_features.py b/test/unit/test_features.py new file mode 100644 index 000000000..9f9f618b0 --- /dev/null +++ b/test/unit/test_features.py @@ -0,0 +1,88 @@ +import unittest +from scripts.test.shared import WASM_OPT, run_process + + +class FeatureValidationTest(unittest.TestCase): + def check_feature(self, module, error, flag): + p = run_process(WASM_OPT + ['--mvp-features', '--print'], + input=module, check=False, capture_output=True) + self.assertIn(error, p.stderr) + self.assertIn("Fatal: error in validating input", p.stderr) + self.assertNotEqual(p.returncode, 0) + p = run_process(WASM_OPT + ['--mvp-features', flag, '--print'], + input=module, check=False, capture_output=True) + self.assertEqual(p.returncode, 0) + + def check_simd(self, module, error): + self.check_feature(module, error, '--enable-simd') + + def check_sign_ext(self, module, error): + self.check_feature(module, error, '--enable-sign-ext') + + def test_v128_signature(self): + module = """ + (module + (func $foo (param $0 v128) (result v128) + (local.get $0) + ) + ) + """ + self.check_simd(module, "all used types should be allowed") + + def test_v128_global(self): + module = """ + (module + (global $foo (mut v128) (v128.const i32x4 0 0 0 0)) + ) + """ + self.check_simd(module, "all used types should be allowed") + + def test_v128_local(self): + module = """ + (module + (func $foo + (local v128) + ) + ) + """ + self.check_simd(module, "all used types should be allowed") + + def test_simd_const(self): + module = """ + (module + (func $foo + (drop (v128.const i32x4 0 0 0 0)) + ) + ) + """ + self.check_simd(module, "all used features should be allowed") + + def test_simd_load(self): + module = """ + (module + (func $foo + (drop (v128.load (i32.const 0))) + ) + ) + """ + self.check_simd(module, "SIMD operation (SIMD is disabled)") + + def test_simd_splat(self): + module = """ + (module + (func $foo + (drop (i32x4.splat (i32.const 0))) + ) + ) + """ + self.check_simd(module, "all used features should be allowed") + + def test_sign_ext(self): + module = """ + (module + (func $foo + (drop (i32.extend8_s (i32.const 7))) + ) + ) + """ + self.check_sign_ext(module, "all used features should be allowed") |