Commit cd617a58 authored by Matthias Liedtke's avatar Matthias Liedtke Committed by V8 LUCI CQ

[test][wasm] Increase coverage for value types in signature

Change-Id: I19105432a71b5850264624c23d7bb732193100f3
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3791046Reviewed-by: 's avatarJakob Kummerow <jkummerow@chromium.org>
Auto-Submit: Matthias Liedtke <mliedtke@chromium.org>
Commit-Queue: Matthias Liedtke <mliedtke@chromium.org>
Cr-Commit-Position: refs/heads/main@{#82071}
parent 781a5b5a
......@@ -207,11 +207,11 @@ size_t ModuleDecoder::IdentifyUnknownSection(ModuleDecoder* decoder,
bool ModuleDecoder::ok() { return impl_->ok(); }
const FunctionSig* DecodeWasmSignatureForTesting(const WasmFeatures& enabled,
Zone* zone, const byte* start,
const byte* end) {
Result<const FunctionSig*> DecodeWasmSignatureForTesting(
const WasmFeatures& enabled, Zone* zone, const byte* start,
const byte* end) {
ModuleDecoderImpl decoder(enabled, start, end, kWasmOrigin);
return decoder.DecodeFunctionSignature(zone, start);
return decoder.toResult(decoder.DecodeFunctionSignature(zone, start));
}
ConstantExpression DecodeWasmInitExprForTesting(const WasmFeatures& enabled,
......
......@@ -97,8 +97,8 @@ V8_EXPORT_PRIVATE ModuleResult DecodeWasmModuleForDisassembler(
AccountingAllocator* allocator);
// Exposed for testing. Decodes a single function signature, allocating it
// in the given zone. Returns {nullptr} upon failure.
V8_EXPORT_PRIVATE const FunctionSig* DecodeWasmSignatureForTesting(
// in the given zone.
V8_EXPORT_PRIVATE Result<const FunctionSig*> DecodeWasmSignatureForTesting(
const WasmFeatures& enabled, Zone* zone, const byte* start,
const byte* end);
......
......@@ -182,13 +182,23 @@ struct ValueTypePair {
uint8_t code;
ValueType type;
} kValueTypes[] = {
// TODO(mliedtke): Cover other value types as well.
{kI32Code, kWasmI32}, // --
{kI64Code, kWasmI64}, // --
{kF32Code, kWasmF32}, // --
{kF64Code, kWasmF64}, // --
{kFuncRefCode, kWasmFuncRef}, // --
{kExternRefCode, kWasmExternRef}, // --
{kI32Code, kWasmI32}, // --
{kI64Code, kWasmI64}, // --
{kF32Code, kWasmF32}, // --
{kF64Code, kWasmF64}, // --
{kFuncRefCode, kWasmFuncRef}, // --
{kExternRefCode, kWasmExternRef}, // --
{kAnyRefCode, kWasmAnyRef}, // --
{kS128Code, kWasmS128}, // --
{kEqRefCode, kWasmEqRef}, // --
{kI31RefCode, kWasmI31Ref}, // --
{kDataRefCode, kWasmDataRef}, // --
{kArrayRefCode, kWasmArrayRef}, // --
{kNoneCode, kWasmNullRef}, // --
{kStringRefCode, kWasmStringRef}, // --
{kStringViewWtf8Code, kWasmStringViewWtf8}, // --
{kStringViewWtf16Code, kWasmStringViewWtf16}, // --
{kStringViewIterCode, kWasmStringViewIter}, // --
};
class WasmModuleVerifyTest : public TestWithIsolateAndZone {
......@@ -2215,7 +2225,20 @@ class WasmSignatureDecodeTest : public TestWithZone {
WasmFeatures enabled_features_ = WasmFeatures::None();
const FunctionSig* DecodeSig(const byte* start, const byte* end) {
return DecodeWasmSignatureForTesting(enabled_features_, zone(), start, end);
Result<const FunctionSig*> res =
DecodeWasmSignatureForTesting(enabled_features_, zone(), start, end);
EXPECT_TRUE(res.ok()) << res.error().message() << " at offset "
<< res.error().offset();
return res.ok() ? res.value() : nullptr;
}
testing::AssertionResult DecodeSigError(const byte* start, const byte* end) {
Result<const FunctionSig*> res =
DecodeWasmSignatureForTesting(enabled_features_, zone(), start, end);
if (res.ok()) {
return testing::AssertionFailure() << "unexpected valid signature";
}
return testing::AssertionSuccess();
}
};
......@@ -2231,6 +2254,10 @@ TEST_F(WasmSignatureDecodeTest, Ok_v_v) {
}
TEST_F(WasmSignatureDecodeTest, Ok_t_v) {
WASM_FEATURE_SCOPE(gc);
WASM_FEATURE_SCOPE(simd);
WASM_FEATURE_SCOPE(typed_funcref);
WASM_FEATURE_SCOPE(stringref);
for (size_t i = 0; i < arraysize(kValueTypes); i++) {
ValueTypePair ret_type = kValueTypes[i];
const byte data[] = {SIG_ENTRY_x(ret_type.code)};
......@@ -2245,6 +2272,10 @@ TEST_F(WasmSignatureDecodeTest, Ok_t_v) {
}
TEST_F(WasmSignatureDecodeTest, Ok_v_t) {
WASM_FEATURE_SCOPE(gc);
WASM_FEATURE_SCOPE(simd);
WASM_FEATURE_SCOPE(typed_funcref);
WASM_FEATURE_SCOPE(stringref);
for (size_t i = 0; i < arraysize(kValueTypes); i++) {
ValueTypePair param_type = kValueTypes[i];
const byte data[] = {SIG_ENTRY_v_x(param_type.code)};
......@@ -2259,6 +2290,10 @@ TEST_F(WasmSignatureDecodeTest, Ok_v_t) {
}
TEST_F(WasmSignatureDecodeTest, Ok_t_t) {
WASM_FEATURE_SCOPE(gc);
WASM_FEATURE_SCOPE(simd);
WASM_FEATURE_SCOPE(typed_funcref);
WASM_FEATURE_SCOPE(stringref);
for (size_t i = 0; i < arraysize(kValueTypes); i++) {
ValueTypePair ret_type = kValueTypes[i];
for (size_t j = 0; j < arraysize(kValueTypes); j++) {
......@@ -2277,6 +2312,10 @@ TEST_F(WasmSignatureDecodeTest, Ok_t_t) {
}
TEST_F(WasmSignatureDecodeTest, Ok_i_tt) {
WASM_FEATURE_SCOPE(gc);
WASM_FEATURE_SCOPE(simd);
WASM_FEATURE_SCOPE(typed_funcref);
WASM_FEATURE_SCOPE(stringref);
for (size_t i = 0; i < arraysize(kValueTypes); i++) {
ValueTypePair p0_type = kValueTypes[i];
for (size_t j = 0; j < arraysize(kValueTypes); j++) {
......@@ -2297,6 +2336,10 @@ TEST_F(WasmSignatureDecodeTest, Ok_i_tt) {
}
TEST_F(WasmSignatureDecodeTest, Ok_tt_tt) {
WASM_FEATURE_SCOPE(gc);
WASM_FEATURE_SCOPE(simd);
WASM_FEATURE_SCOPE(typed_funcref);
WASM_FEATURE_SCOPE(stringref);
for (size_t i = 0; i < arraysize(kValueTypes); i++) {
ValueTypePair p0_type = kValueTypes[i];
for (size_t j = 0; j < arraysize(kValueTypes); j++) {
......@@ -2322,16 +2365,14 @@ TEST_F(WasmSignatureDecodeTest, TooManyParams) {
static const byte data[] = {kWasmFunctionTypeCode,
WASM_I32V_3(kV8MaxWasmFunctionParams + 1),
kI32Code, 0};
const FunctionSig* sig = DecodeSig(data, data + sizeof(data));
EXPECT_FALSE(sig != nullptr);
EXPECT_TRUE(DecodeSigError(data, data + sizeof(data)));
}
TEST_F(WasmSignatureDecodeTest, TooManyReturns) {
for (int i = 0; i < 2; i++) {
byte data[] = {kWasmFunctionTypeCode, 0,
WASM_I32V_3(kV8MaxWasmFunctionReturns + 1), kI32Code};
const FunctionSig* sig = DecodeSig(data, data + sizeof(data));
EXPECT_EQ(nullptr, sig);
EXPECT_TRUE(DecodeSigError(data, data + sizeof(data)));
}
}
......@@ -2343,8 +2384,7 @@ TEST_F(WasmSignatureDecodeTest, Fail_off_end) {
for (int i = 0; i < p + 1; i++) {
// Should fall off the end for all signatures.
const FunctionSig* sig = DecodeSig(data, data + i);
EXPECT_EQ(nullptr, sig);
EXPECT_TRUE(DecodeSigError(data, data + sizeof(data)));
}
}
}
......@@ -2355,27 +2395,23 @@ TEST_F(WasmSignatureDecodeTest, Fail_invalid_type) {
byte data[] = {SIG_ENTRY_x_xx(kI32Code, kI32Code, kI32Code)};
if (i >= arraysize(data)) break;
data[i] = kInvalidType;
const FunctionSig* sig = DecodeSig(data, data + sizeof(data));
EXPECT_EQ(nullptr, sig);
EXPECT_TRUE(DecodeSigError(data, data + sizeof(data)));
}
}
TEST_F(WasmSignatureDecodeTest, Fail_invalid_ret_type1) {
static const byte data[] = {SIG_ENTRY_x_x(kVoidCode, kI32Code)};
const FunctionSig* sig = DecodeSig(data, data + sizeof(data));
EXPECT_EQ(nullptr, sig);
EXPECT_TRUE(DecodeSigError(data, data + sizeof(data)));
}
TEST_F(WasmSignatureDecodeTest, Fail_invalid_param_type1) {
static const byte data[] = {SIG_ENTRY_x_x(kI32Code, kVoidCode)};
const FunctionSig* sig = DecodeSig(data, data + sizeof(data));
EXPECT_EQ(nullptr, sig);
EXPECT_TRUE(DecodeSigError(data, data + sizeof(data)));
}
TEST_F(WasmSignatureDecodeTest, Fail_invalid_param_type2) {
static const byte data[] = {SIG_ENTRY_x_xx(kI32Code, kI32Code, kVoidCode)};
const FunctionSig* sig = DecodeSig(data, data + sizeof(data));
EXPECT_EQ(nullptr, sig);
EXPECT_TRUE(DecodeSigError(data, data + sizeof(data)));
}
class WasmFunctionVerifyTest : public TestWithIsolateAndZone {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment