| 54 | } |
| 55 | |
| 56 | TEST(serializeTypeTest, SerializeFunctionType) { |
| 57 | WasmEdge::Configure ConfWASM1; |
| 58 | ConfWASM1.setWASMStandard(WasmEdge::Standard::WASM_1); |
| 59 | WasmEdge::Loader::Serializer SerWASM1(ConfWASM1); |
| 60 | |
| 61 | std::vector<uint8_t> Expected; |
| 62 | std::vector<uint8_t> Output; |
| 63 | |
| 64 | // 1. Test serialize function type. |
| 65 | // |
| 66 | // 1. Serialize void parameter and result function type. |
| 67 | // 2. Serialize non-void parameter function type. |
| 68 | // 3. Serialize non-void result function type. |
| 69 | // 4. Serialize function type with parameters and result. |
| 70 | // 5. Serialize invalid parameters with ExternRef without Ref-Types |
| 71 | // proposal. |
| 72 | // 6. Serialize invalid results with ExternRef without Ref-Types proposal. |
| 73 | // 7. Serialize invalid function type with multi-value returns without |
| 74 | // Multi-Value proposal. |
| 75 | |
| 76 | WasmEdge::AST::FunctionType FuncType; |
| 77 | |
| 78 | Output = {}; |
| 79 | EXPECT_TRUE(Ser.serializeSection(createTypeSec(FuncType), Output)); |
| 80 | Expected = { |
| 81 | 0x01U, // Type section |
| 82 | 0x04U, // Content size = 4 |
| 83 | 0x01U, // Vector length = 1 |
| 84 | 0x60U, // Function type header |
| 85 | 0x00U, // Parameter length = 0 |
| 86 | 0x00U // Result length = 0 |
| 87 | }; |
| 88 | EXPECT_EQ(Output, Expected); |
| 89 | |
| 90 | FuncType.getParamTypes() = {WasmEdge::TypeCode::F64, WasmEdge::TypeCode::F32, |
| 91 | WasmEdge::TypeCode::I64, WasmEdge::TypeCode::I32}; |
| 92 | Output = {}; |
| 93 | EXPECT_TRUE(Ser.serializeSection(createTypeSec(FuncType), Output)); |
| 94 | Expected = { |
| 95 | 0x01U, // Type section |
| 96 | 0x08U, // Content size = 8 |
| 97 | 0x01U, // Vector length = 1 |
| 98 | 0x60U, // Function type header |
| 99 | 0x04U, // Parameter length = 4 |
| 100 | 0x7CU, 0x7DU, 0x7EU, 0x7FU, // Parameter list |
| 101 | 0x00U // Result length = 0 |
| 102 | }; |
| 103 | EXPECT_EQ(Output, Expected); |
| 104 | |
| 105 | FuncType.getParamTypes() = {}; |
| 106 | FuncType.getReturnTypes() = {WasmEdge::TypeCode::F64}; |
| 107 | Output = {}; |
| 108 | EXPECT_TRUE(Ser.serializeSection(createTypeSec(FuncType), Output)); |
| 109 | Expected = { |
| 110 | 0x01U, // Type section |
| 111 | 0x05U, // Content size = 5 |
| 112 | 0x01U, // Vector length = 1 |
| 113 | 0x60U, // Function type header |
nothing calls this directly
no test coverage detected