Commit b7512d34 authored by Manos Koukoutos's avatar Manos Koukoutos Committed by Commit Bot

[wasm-gc] Move verification tests to correct file, write macros for them

Bug: v8:7748
Change-Id: I70ecda5e43e188835166b34a42620a477a5e7997
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2282600
Commit-Queue: Manos Koukoutos <manoskouk@chromium.org>
Reviewed-by: 's avatarJakob Kummerow <jkummerow@chromium.org>
Cr-Commit-Position: refs/heads/master@{#68708}
parent fea8e3bb
......@@ -942,162 +942,6 @@ TEST(MemoryWithOOBEmptyDataSegment) {
Cleanup();
}
TEST(GcStructIdsPass) {
{
EXPERIMENTAL_FLAG_SCOPE(gc);
EXPERIMENTAL_FLAG_SCOPE(typed_funcref);
EXPERIMENTAL_FLAG_SCOPE(reftypes);
Isolate* isolate = CcTest::InitIsolateOnce();
HandleScope scope(isolate);
testing::SetupIsolateForWasmModule(isolate);
ErrorThrower thrower(isolate, "GcStructIdsPass");
const byte data[] = {
WASM_MODULE_HEADER, // --
kTypeSectionCode, // --
U32V_1(23), // Section size
U32V_1(3), // type count
kWasmStructTypeCode, // index 0 = struct(i32, type(0), type(1))
U32V_1(3), // field count
kLocalI32, // field 0
U32V_1(1), // mutability
kLocalOptRef, // field 1
U32V_1(0), // --
U32V_1(1), // mutability
kLocalOptRef, // field 2
U32V_1(1), // --
U32V_1(1), // mutability
kWasmStructTypeCode, // index 1 = struct(type(0), type(2))
U32V_1(2), // field count
kLocalOptRef, // field 0
U32V_1(0), // --
U32V_1(1), // mutability
kLocalOptRef, // field 1
U32V_1(2), // --
U32V_1(1), // mutability
kWasmArrayTypeCode, // index 2 = array(type(0))
kLocalOptRef, // element type
U32V_1(0), // --
U32V_1(1) // mutability
};
CompileAndInstantiateForTesting(
isolate, &thrower, ModuleWireBytes(data, data + arraysize(data)));
// This module is valid.
if (thrower.error()) {
FATAL("%s", thrower.error_msg());
}
}
Cleanup();
}
TEST(GcTypeIdsUndefinedIndex) {
{
EXPERIMENTAL_FLAG_SCOPE(gc);
EXPERIMENTAL_FLAG_SCOPE(typed_funcref);
EXPERIMENTAL_FLAG_SCOPE(reftypes);
Isolate* isolate = CcTest::InitIsolateOnce();
HandleScope scope(isolate);
testing::SetupIsolateForWasmModule(isolate);
ErrorThrower thrower(isolate, "GcTypeIdsUndefinedIndex");
const byte data[] = {
WASM_MODULE_HEADER, // --
kTypeSectionCode, // --
U32V_1(6), // Section size
U32V_1(1), // type count
kWasmStructTypeCode, // index 0 = struct(type(1))
U32V_1(1), // field count
kLocalOptRef, // field 0
U32V_1(1), // --
U32V_1(1) // mutability
};
CompileAndInstantiateForTesting(
isolate, &thrower, ModuleWireBytes(data, data + arraysize(data)));
// There should be an error reflecting an undeclared index.
CHECK(thrower.error());
CHECK_NE(std::string(thrower.error_msg())
.find("reference to undeclared struct/array"),
std::string::npos);
}
Cleanup();
}
TEST(GcTypeIdsIllegalIndex) {
{
EXPERIMENTAL_FLAG_SCOPE(gc);
EXPERIMENTAL_FLAG_SCOPE(typed_funcref);
EXPERIMENTAL_FLAG_SCOPE(reftypes);
Isolate* isolate = CcTest::InitIsolateOnce();
HandleScope scope(isolate);
testing::SetupIsolateForWasmModule(isolate);
ErrorThrower thrower(isolate, "GcTypeIdsIllegalIndex");
const byte data[] = {
WASM_MODULE_HEADER, // --
kTypeSectionCode, // --
U32V_1(11), // Section size
U32V_1(2), // type count
kWasmStructTypeCode, // index 0 = struct(type(1))
U32V_1(1), // field count
kLocalOptRef, // field 0
U32V_1(1), // --
U32V_1(1), // mutability
kWasmFunctionTypeCode, // index 1 = int32 -> int32
U32V_1(1), // param count
kLocalI32, // param 0
U32V_1(1), // returns count
kLocalI32 // return 0
};
CompileAndInstantiateForTesting(
isolate, &thrower, ModuleWireBytes(data, data + arraysize(data)));
// There should be an error reflecting an invalid index.
CHECK(thrower.error());
CHECK_NE(std::string(thrower.error_msg())
.find("cannot build reference to function type index"),
std::string::npos);
}
Cleanup();
}
TEST(GcTypeIdsFunSigIllegalIndex) {
{
EXPERIMENTAL_FLAG_SCOPE(gc);
EXPERIMENTAL_FLAG_SCOPE(typed_funcref);
EXPERIMENTAL_FLAG_SCOPE(reftypes);
Isolate* isolate = CcTest::InitIsolateOnce();
HandleScope scope(isolate);
testing::SetupIsolateForWasmModule(isolate);
ErrorThrower thrower(isolate, "GcTypeIdsFumSigIllegalIndex");
const byte data[] = {
WASM_MODULE_HEADER, // --
kTypeSectionCode, // --
U32V_1(7), // Section size
U32V_1(1), // type count
kWasmFunctionTypeCode, // index 0 = int32 -> (ref null 0)
U32V_1(1), // param count
kLocalI32, // param 0
U32V_1(1), // returns count
kLocalOptRef, // return 0
U32V_1(0) // --
};
CompileAndInstantiateForTesting(
isolate, &thrower, ModuleWireBytes(data, data + arraysize(data)));
// There should be an error reflecting an invalid index.
CHECK(thrower.error());
CHECK_NE(std::string(thrower.error_msg())
.find("cannot build reference to function type index"),
std::string::npos);
}
Cleanup();
}
#undef EMIT_CODE_WITH_END
} // namespace test_run_wasm_module
......
......@@ -117,6 +117,15 @@ struct CheckLEB1 : std::integral_constant<size_t, num> {
#define EXCEPTION_ENTRY(sig_index) U32V_1(kExceptionAttribute), sig_index
#define FIELD_COUNT(count) U32V_1(count)
#define STRUCT_FIELD(type, mutability) type, (mutability ? 1 : 0)
#define WASM_REF(index) kLocalRef, index
#define WASM_OPT_REF(index) kLocalOptRef, index
#define WASM_STRUCT_DEF(...) kWasmStructTypeCode, __VA_ARGS__
#define WASM_ARRAY_DEF(type, mutability) \
kWasmArrayTypeCode, type, (mutability ? 1 : 0)
#define WASM_FUNCTION_DEF(...) kWasmFunctionTypeCode, __VA_ARGS__
#define EXPECT_VERIFIES(data) \
do { \
ModuleResult result = DecodeModule(data, data + sizeof(data)); \
......@@ -2659,6 +2668,61 @@ TEST_F(WasmModuleVerifyTest, DataCountSegmentCount_omitted) {
EXPECT_NOT_OK(result, "data segments count 0 mismatch (1 expected)");
}
TEST_F(WasmModuleVerifyTest, GcStructIdsPass) {
WASM_FEATURE_SCOPE(gc);
WASM_FEATURE_SCOPE(typed_funcref);
WASM_FEATURE_SCOPE(reftypes);
static const byte data[] = {SECTION(
Type, ENTRY_COUNT(3),
WASM_STRUCT_DEF(FIELD_COUNT(3), STRUCT_FIELD(kLocalI32, true),
STRUCT_FIELD(WASM_OPT_REF(0), true),
STRUCT_FIELD(WASM_OPT_REF(1), true)),
WASM_STRUCT_DEF(FIELD_COUNT(2), STRUCT_FIELD(WASM_OPT_REF(0), true),
STRUCT_FIELD(WASM_OPT_REF(2), true)),
WASM_ARRAY_DEF(WASM_OPT_REF(0), true))};
ModuleResult result = DecodeModule(data, data + sizeof(data));
EXPECT_OK(result);
}
TEST_F(WasmModuleVerifyTest, GcTypeIdsUndefinedIndex) {
WASM_FEATURE_SCOPE(gc);
WASM_FEATURE_SCOPE(typed_funcref);
WASM_FEATURE_SCOPE(reftypes);
static const byte data[] = {SECTION(
Type, ENTRY_COUNT(1),
WASM_STRUCT_DEF(FIELD_COUNT(1), STRUCT_FIELD(WASM_OPT_REF(1), true)))};
ModuleResult result = DecodeModule(data, data + sizeof(data));
EXPECT_NOT_OK(result, "reference to undeclared struct/array");
}
TEST_F(WasmModuleVerifyTest, GcTypeIdsIllegalIndex) {
WASM_FEATURE_SCOPE(gc);
WASM_FEATURE_SCOPE(typed_funcref);
WASM_FEATURE_SCOPE(reftypes);
static const byte data[] = {SECTION(
Type, ENTRY_COUNT(2),
WASM_STRUCT_DEF(FIELD_COUNT(1), STRUCT_FIELD(WASM_OPT_REF(1), true)),
WASM_FUNCTION_DEF(ENTRY_COUNT(1), kLocalI32, ENTRY_COUNT(1), kLocalI32))};
ModuleResult result = DecodeModule(data, data + sizeof(data));
EXPECT_NOT_OK(result, "cannot build reference to function type index");
}
TEST_F(WasmModuleVerifyTest, GcTypeIdsFunSigIllegalIndex) {
WASM_FEATURE_SCOPE(gc);
WASM_FEATURE_SCOPE(typed_funcref);
WASM_FEATURE_SCOPE(reftypes);
static const byte data[] = {SECTION(
Type, ENTRY_COUNT(1),
WASM_FUNCTION_DEF(U32V_1(1), kLocalI32, U32V_1(1), WASM_OPT_REF(0)))};
ModuleResult result = DecodeModule(data, data + sizeof(data));
EXPECT_NOT_OK(result, "cannot build reference to function type index");
}
#undef EXPECT_INIT_EXPR
#undef EXPECT_INIT_EXPR_FAIL
#undef WASM_INIT_EXPR_I32V_1
......@@ -2709,6 +2773,14 @@ TEST_F(WasmModuleVerifyTest, DataCountSegmentCount_omitted) {
#undef FOUR_EMPTY_BODIES
#undef SIGNATURES_SECTION_VOID_VOID
#undef LINEAR_MEMORY_INDEX_0
#undef FIELD_COUNT
#undef STRUCT_FIELD
#undef WASM_REF
#undef WASM_OPT_REF
#undef WASM_STRUCT_DEF
#undef WASM_ARRAY_DEF
#undef WASM_FUNCTION_DEF
#undef EXCEPTION_ENTRY
#undef EXPECT_VERIFIES
#undef EXPECT_FAILURE_LEN
......
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