MCPcopy Create free account
hub / github.com/WasmEdge/WasmEdge / TEST

Function TEST

test/loader/segmentTest.cpp:36–128  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

34}
35
36TEST(SegmentTest, LoadTableSegment) {
37 std::vector<uint8_t> Vec;
38
39 Conf.setWASMStandard(WasmEdge::Standard::WASM_2);
40 WasmEdge::Loader::Loader LdrWASM2(Conf);
41
42 // 1. Test load table segment.
43 //
44 // 1. Load invalid empty table segment.
45 // 2. Load a table segment that contains only table type.
46 // 3. Load a table segment that contains an initialization expression
47 // with or without the typed function reference proposal.
48 // 4. Load a table segment with an unexpected end of checking byte.
49 // 5. Load a table segment with a wrong checking byte.
50 // 6. Load a table segment with an unexpected end of table type.
51 // 7. Load a table segment with an unexpected end of initialization
52 // expression.
53
54 Vec = {
55 0x04U, // Table section
56 0x01U, // Content size = 1
57 0x01U, // Vector length = 1
58 };
59 EXPECT_FALSE(Ldr.parseModule(prefixedVec(Vec)));
60
61 Vec = {
62 0x04U, // Table section
63 0x0DU, // Content size = 13
64 0x01U, // Vector length = 1
65 0x70U, // Reference type
66 0x01U, // Has min and max
67 0xF1U, 0xFFU, 0xFFU, 0xFFU, 0x0FU, // Min = 4294967281
68 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0x0FU // Max = 4294967295
69 };
70 EXPECT_TRUE(Ldr.parseModule(prefixedVec(Vec)));
71
72 Vec = {
73 0x04U, // Table section
74 0x13U, // Content size = 19
75 0x01U, // Vector length = 1
76 0x40U, 0x00U, // Table segment with init
77 0x70U, // Reference type
78 0x01U, // Has min and max
79 0xF1U, 0xFFU, 0xFFU, 0xFFU, 0x0FU, // Min = 4294967281
80 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0x0FU, // Max = 4294967295
81 0x45U, 0x46U, 0x47U, 0x0BU // Expression
82 };
83 EXPECT_FALSE(LdrWASM2.parseModule(prefixedVec(Vec)));
84 EXPECT_TRUE(Ldr.parseModule(prefixedVec(Vec)));
85
86 Vec = {
87 0x04U, // Table section
88 0x02U, // Content size = 2
89 0x01U, // Vector length = 1
90 0x40U // Table segment with init
91 // 0x00U Missing checking byte
92 // Missing table type and initialization expression
93 };

Callers

nothing calls this directly

Calls 3

setWASMStandardMethod · 0.80
parseModuleMethod · 0.80
prefixedVecFunction · 0.70

Tested by

no test coverage detected