diff options
Diffstat (limited to 'deps/v8/test/unittests/wasm/function-body-decoder-unittest.cc')
-rw-r--r-- | deps/v8/test/unittests/wasm/function-body-decoder-unittest.cc | 40 |
1 files changed, 29 insertions, 11 deletions
diff --git a/deps/v8/test/unittests/wasm/function-body-decoder-unittest.cc b/deps/v8/test/unittests/wasm/function-body-decoder-unittest.cc index e242132a145..1968fe633be 100644 --- a/deps/v8/test/unittests/wasm/function-body-decoder-unittest.cc +++ b/deps/v8/test/unittests/wasm/function-body-decoder-unittest.cc @@ -2,6 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include "src/wasm/leb-helper.h" #include "test/unittests/test-utils.h" #include "src/init/v8.h" @@ -216,9 +217,9 @@ class TestModuleBuilder { return static_cast<byte>(mod.globals.size() - 1); } byte AddSignature(const FunctionSig* sig) { - mod.signatures.push_back(sig); - CHECK_LE(mod.signatures.size(), kMaxByteSizedLeb128); - return static_cast<byte>(mod.signatures.size() - 1); + mod.add_signature(sig); + CHECK_LE(mod.types.size(), kMaxByteSizedLeb128); + return static_cast<byte>(mod.types.size() - 1); } byte AddFunction(const FunctionSig* sig, bool declared = true) { mod.functions.push_back({sig, // sig @@ -238,7 +239,7 @@ class TestModuleBuilder { } byte AddException(WasmExceptionSig* sig) { mod.exceptions.emplace_back(sig); - CHECK_LE(mod.signatures.size(), kMaxByteSizedLeb128); + CHECK_LE(mod.types.size(), kMaxByteSizedLeb128); return static_cast<byte>(mod.exceptions.size() - 1); } @@ -2398,6 +2399,7 @@ TEST_F(FunctionBodyDecoderTest, Break_TypeCheck) { } TEST_F(FunctionBodyDecoderTest, Break_TypeCheckAll1) { + WASM_FEATURE_SCOPE(anyref); for (size_t i = 0; i < arraysize(kValueTypes); i++) { for (size_t j = 0; j < arraysize(kValueTypes); j++) { ValueType storage[] = {kValueTypes[i], kValueTypes[i], kValueTypes[j]}; @@ -2412,6 +2414,7 @@ TEST_F(FunctionBodyDecoderTest, Break_TypeCheckAll1) { } TEST_F(FunctionBodyDecoderTest, Break_TypeCheckAll2) { + WASM_FEATURE_SCOPE(anyref); for (size_t i = 0; i < arraysize(kValueTypes); i++) { for (size_t j = 0; j < arraysize(kValueTypes); j++) { ValueType storage[] = {kValueTypes[i], kValueTypes[i], kValueTypes[j]}; @@ -2426,6 +2429,7 @@ TEST_F(FunctionBodyDecoderTest, Break_TypeCheckAll2) { } TEST_F(FunctionBodyDecoderTest, Break_TypeCheckAll3) { + WASM_FEATURE_SCOPE(anyref); for (size_t i = 0; i < arraysize(kValueTypes); i++) { for (size_t j = 0; j < arraysize(kValueTypes); j++) { ValueType storage[] = {kValueTypes[i], kValueTypes[i], kValueTypes[j]}; @@ -2456,6 +2460,7 @@ TEST_F(FunctionBodyDecoderTest, Break_Unify) { } TEST_F(FunctionBodyDecoderTest, BreakIf_cond_type) { + WASM_FEATURE_SCOPE(anyref); for (size_t i = 0; i < arraysize(kValueTypes); i++) { for (size_t j = 0; j < arraysize(kValueTypes); j++) { ValueType types[] = {kValueTypes[i], kValueTypes[i], kValueTypes[j]}; @@ -2469,6 +2474,7 @@ TEST_F(FunctionBodyDecoderTest, BreakIf_cond_type) { } TEST_F(FunctionBodyDecoderTest, BreakIf_val_type) { + WASM_FEATURE_SCOPE(anyref); for (size_t i = 0; i < arraysize(kValueTypes); i++) { for (size_t j = 0; j < arraysize(kValueTypes); j++) { ValueType types[] = {kValueTypes[i], kValueTypes[i], kValueTypes[j], @@ -3628,6 +3634,20 @@ class WasmOpcodeLengthTest : public TestWithZone { EXPECT_EQ(expected, OpcodeLength(code, code + sizeof(code))) << PrintOpcodes{code, code + sizeof...(bytes)}; } + + // Helper to check for prefixed opcodes, which can have multiple bytes. + void ExpectLengthPrefixed(unsigned operands, WasmOpcode opcode) { + uint8_t prefix = (opcode >> 8) & 0xff; + DCHECK(WasmOpcodes::IsPrefixOpcode(static_cast<WasmOpcode>(prefix))); + uint8_t index = opcode & 0xff; + uint8_t encoded[2] = {0, 0}; + uint8_t* p = encoded; + unsigned len = static_cast<unsigned>(LEBHelper::sizeof_u32v(index)); + DCHECK_GE(2, len); + LEBHelper::write_u32v(&p, index); + // length of index, + number of operands + prefix bye + ExpectLength(len + operands + 1, prefix, encoded[0], encoded[1]); + } }; TEST_F(WasmOpcodeLengthTest, Statements) { @@ -3754,17 +3774,15 @@ TEST_F(WasmOpcodeLengthTest, SimpleExpressions) { } TEST_F(WasmOpcodeLengthTest, SimdExpressions) { -#define TEST_SIMD(name, opcode, sig) \ - ExpectLength(2, kSimdPrefix, static_cast<byte>(kExpr##name & 0xFF)); +#define TEST_SIMD(name, opcode, sig) ExpectLengthPrefixed(0, kExpr##name); FOREACH_SIMD_0_OPERAND_OPCODE(TEST_SIMD) #undef TEST_SIMD -#define TEST_SIMD(name, opcode, sig) \ - ExpectLength(3, kSimdPrefix, static_cast<byte>(kExpr##name & 0xFF)); +#define TEST_SIMD(name, opcode, sig) ExpectLengthPrefixed(1, kExpr##name); FOREACH_SIMD_1_OPERAND_OPCODE(TEST_SIMD) #undef TEST_SIMD - ExpectLength(18, kSimdPrefix, static_cast<byte>(kExprS8x16Shuffle & 0xFF)); - // test for bad simd opcode - ExpectLength(2, kSimdPrefix, 0xFF); + ExpectLengthPrefixed(16, kExprS8x16Shuffle); + // test for bad simd opcode, 0xFF is encoded in two bytes. + ExpectLength(3, kSimdPrefix, 0xFF, 0x1); } using TypesOfLocals = ZoneVector<ValueType>; |