| 24 | } |
| 25 | |
| 26 | TEST(SerializeInstructionTest, SerializeBlockControlInstruction) { |
| 27 | std::vector<uint8_t> Expected; |
| 28 | std::vector<uint8_t> Output; |
| 29 | std::vector<WasmEdge::AST::Instruction> Instructions; |
| 30 | |
| 31 | // 1. Test block control instructions. |
| 32 | // |
| 33 | // 1. Serialize block with only end operation. |
| 34 | // 2. Serialize loop with only end operation. |
| 35 | // 3. Serialize block with instructions. |
| 36 | // 4. Serialize loop with instructions. |
| 37 | |
| 38 | WasmEdge::AST::Instruction Block(WasmEdge::OpCode::Block); |
| 39 | WasmEdge::AST::Instruction Loop(WasmEdge::OpCode::Loop); |
| 40 | WasmEdge::AST::Instruction End(WasmEdge::OpCode::End); |
| 41 | WasmEdge::AST::Instruction I32Eqz(WasmEdge::OpCode::I32__eqz); |
| 42 | WasmEdge::AST::Instruction I32Eq(WasmEdge::OpCode::I32__eq); |
| 43 | WasmEdge::AST::Instruction I32Ne(WasmEdge::OpCode::I32__ne); |
| 44 | |
| 45 | Block.getBlockType().setEmpty(); |
| 46 | Instructions = {Block, End, End}; |
| 47 | Output = {}; |
| 48 | EXPECT_TRUE(Ser.serializeSection(createCodeSec(Instructions), Output)); |
| 49 | Expected = { |
| 50 | 0x0AU, // Code section |
| 51 | 0x07U, // Content size = 7 |
| 52 | 0x01U, // Vector length = 1 |
| 53 | 0x05U, // Code segment size = 5 |
| 54 | 0x00U, // Local vec(0) |
| 55 | 0x02U, // OpCode Block. |
| 56 | 0x40U, // Block type. |
| 57 | 0x0BU, // OpCode End. |
| 58 | 0x0BU // Expression End. |
| 59 | }; |
| 60 | EXPECT_EQ(Output, Expected); |
| 61 | |
| 62 | Loop.getBlockType().setEmpty(); |
| 63 | Instructions = {Loop, End, End}; |
| 64 | Output = {}; |
| 65 | EXPECT_TRUE(Ser.serializeSection(createCodeSec(Instructions), Output)); |
| 66 | Expected = { |
| 67 | 0x0AU, // Code section |
| 68 | 0x07U, // Content size = 7 |
| 69 | 0x01U, // Vector length = 1 |
| 70 | 0x05U, // Code segment size = 5 |
| 71 | 0x00U, // Local vec(0) |
| 72 | 0x03U, // OpCode Loop. |
| 73 | 0x40U, // Block type. |
| 74 | 0x0BU, // OpCode End. |
| 75 | 0x0BU // Expression End. |
| 76 | }; |
| 77 | EXPECT_EQ(Output, Expected); |
| 78 | |
| 79 | Loop.getBlockType().setEmpty(); |
| 80 | Instructions = {Block, I32Eqz, I32Eq, I32Ne, End, End}; |
| 81 | Output = {}; |
| 82 | EXPECT_TRUE(Ser.serializeSection(createCodeSec(Instructions), Output)); |
| 83 | Expected = { |
nothing calls this directly
no test coverage detected