| 13 | WasmEdge::Loader::Serializer Ser(Conf); |
| 14 | |
| 15 | TEST(SerializeSegmentTest, SerializeGlobalSegment) { |
| 16 | std::vector<uint8_t> Expected; |
| 17 | std::vector<uint8_t> Output; |
| 18 | |
| 19 | // 1. Test serialize global segment. |
| 20 | // |
| 21 | // 1. Serialize global segment with expression of only End operation. |
| 22 | // 2. Serialize global segment with non-empty expression. |
| 23 | |
| 24 | WasmEdge::AST::GlobalSection GlobalSec; |
| 25 | WasmEdge::AST::GlobalSegment GlobalSeg; |
| 26 | |
| 27 | GlobalSeg.getGlobalType() = WasmEdge::AST::GlobalType( |
| 28 | WasmEdge::TypeCode::I32, WasmEdge::ValMut::Const); |
| 29 | GlobalSeg.getExpr().getInstrs() = { |
| 30 | WasmEdge::AST::Instruction(WasmEdge::OpCode::End)}; |
| 31 | GlobalSec.getContent() = {GlobalSeg}; |
| 32 | |
| 33 | Output = {}; |
| 34 | EXPECT_TRUE(Ser.serializeSection(GlobalSec, Output)); |
| 35 | Expected = { |
| 36 | 0x06U, // Global section |
| 37 | 0x04U, // Content size = 4 |
| 38 | 0x01U, // Vector length = 1 |
| 39 | 0x7FU, 0x00, // Global type |
| 40 | 0x0BU // Expression |
| 41 | }; |
| 42 | EXPECT_EQ(Output, Expected); |
| 43 | |
| 44 | GlobalSeg.getGlobalType() = WasmEdge::AST::GlobalType( |
| 45 | WasmEdge::TypeCode::I32, WasmEdge::ValMut::Const); |
| 46 | GlobalSeg.getExpr().getInstrs() = { |
| 47 | WasmEdge::AST::Instruction(WasmEdge::OpCode::I32__eqz), |
| 48 | WasmEdge::AST::Instruction(WasmEdge::OpCode::I32__eq), |
| 49 | WasmEdge::AST::Instruction(WasmEdge::OpCode::I32__ne), |
| 50 | WasmEdge::AST::Instruction(WasmEdge::OpCode::End)}; |
| 51 | GlobalSec.getContent() = {GlobalSeg}; |
| 52 | |
| 53 | Output = {}; |
| 54 | EXPECT_TRUE(Ser.serializeSection(GlobalSec, Output)); |
| 55 | Expected = { |
| 56 | 0x06U, // Global section |
| 57 | 0x07U, // Content size = 7 |
| 58 | 0x01U, // Vector length = 1 |
| 59 | 0x7FU, 0x00U, // Global type |
| 60 | 0x45U, 0x46U, 0x47U, 0x0BU // Expression |
| 61 | }; |
| 62 | EXPECT_EQ(Output, Expected); |
| 63 | } |
| 64 | |
| 65 | TEST(SerializeSegmentTest, SerializeElementSegment) { |
| 66 | WasmEdge::Configure ConfWASM1; |
nothing calls this directly
no test coverage detected