| 11 | using namespace std::literals; |
| 12 | |
| 13 | TEST(Component, LoadAndValidate_TestWasm) { |
| 14 | Configure Conf; |
| 15 | Conf.addProposal(Proposal::Component); |
| 16 | VM::VM VM(Conf); |
| 17 | |
| 18 | std::vector<uint8_t> Vec = { |
| 19 | 0x00, 0x61, 0x73, 0x6d, 0x0d, 0x00, 0x01, 0x00, // WASM preamble |
| 20 | |
| 21 | 0x07, 0x12, 0x01, // Type section: size 0x12, vector size 1 |
| 22 | 0x42, 0x02, // TypeSec[0]: instance type, vector size 2 |
| 23 | 0x01, 0x40, 0x00, 0x01, 0x00, // InstType[0]: type: functype {}->{} |
| 24 | 0x04, // InstType[1]: exportdecl |
| 25 | 0x00, 0x05, 0x68, 0x65, 0x6c, 0x6c, 0x6f, // exportdecl: name "hello" |
| 26 | 0x01, 0x00, // exportdecl: externdesc: func[0] |
| 27 | |
| 28 | 0x0a, 0x11, 0x01, // Import section: size 0x11, vector size 1 |
| 29 | 0x00, 0x0c, // ImportSec[0]: import name "my:demo/host" |
| 30 | 0x6d, 0x79, 0x3a, 0x64, 0x65, 0x6d, 0x6f, 0x2f, 0x68, 0x6f, 0x73, 0x74, |
| 31 | 0x05, 0x00, // import externdesc: instance[0] |
| 32 | |
| 33 | 0x01, 0x57, // CoreModule section: size 0x57 |
| 34 | 0x00, 0x61, 0x73, 0x6d, 0x01, 0x00, 0x00, 0x00, // WASM header |
| 35 | 0x01, 0x04, 0x01, 0x60, 0x00, 0x00, // Type section: {func{}->{}} |
| 36 | 0x02, 0x16, 0x01, 0x0c, // Import section: vector size 1 |
| 37 | 0x6d, 0x79, 0x3a, 0x64, 0x65, 0x6d, 0x6f, 0x2f, 0x68, 0x6f, 0x73, 0x74, |
| 38 | 0x05, 0x68, 0x65, 0x6c, 0x6c, 0x6f, // "my:demo/host" "hello" |
| 39 | 0x00, 0x00, // import func[0] |
| 40 | 0x00, 0x2f, 0x09, 0x70, 0x72, 0x6f, 0x64, 0x75, 0x63, 0x65, 0x72, 0x73, |
| 41 | 0x01, 0x0c, 0x70, 0x72, 0x6f, 0x63, 0x65, 0x73, 0x73, 0x65, 0x64, 0x2d, |
| 42 | 0x62, 0x79, 0x01, 0x0d, 0x77, 0x69, 0x74, 0x2d, 0x63, 0x6f, 0x6d, 0x70, |
| 43 | 0x6f, 0x6e, 0x65, 0x6e, 0x74, 0x07, 0x30, 0x2e, 0x32, 0x32, 0x37, 0x2e, |
| 44 | 0x31, // Custom section |
| 45 | |
| 46 | 0x06, 0x0a, 0x01, // Alias section: size 0x0a, vector size 1 |
| 47 | 0x01, // sort: func |
| 48 | 0x00, 0x00, // target: instance[0] |
| 49 | 0x05, 0x68, 0x65, 0x6c, 0x6c, 0x6f, // target: name "hello" |
| 50 | |
| 51 | 0x08, 0x05, 0x01, // Canon section: size 0x05, vector size 1 |
| 52 | 0x01, 0x00, 0x00, 0x00, // canon lower func[0] |
| 53 | |
| 54 | 0x02, 0x1d, 0x02, // CoreInstance section: size 0x1d, vector size 2 |
| 55 | 0x01, 0x01, // CoreInstSec[0]: inlineexport |
| 56 | 0x05, 0x68, 0x65, 0x6c, 0x6c, 0x6f, // export name "hello" |
| 57 | 0x00, 0x00, // export sort func[0] |
| 58 | 0x00, 0x00, // CoreInstSec[1]: instantiate module[0] |
| 59 | 0x01, 0x0c, 0x6d, 0x79, 0x3a, 0x64, 0x65, 0x6d, 0x6f, 0x2f, 0x68, 0x6f, |
| 60 | 0x73, 0x74, // module name "my:demo/host" |
| 61 | 0x12, 0x00, // instance index 0 |
| 62 | |
| 63 | 0x00, 0x2f, 0x09, 0x70, 0x72, 0x6f, 0x64, 0x75, 0x63, 0x65, 0x72, 0x73, |
| 64 | 0x01, 0x0c, 0x70, 0x72, 0x6f, 0x63, 0x65, 0x73, 0x73, 0x65, 0x64, 0x2d, |
| 65 | 0x62, 0x79, 0x01, 0x0d, 0x77, 0x69, 0x74, 0x2d, 0x63, 0x6f, 0x6d, 0x70, |
| 66 | 0x6f, 0x6e, 0x65, 0x6e, 0x74, 0x07, 0x30, 0x2e, 0x32, 0x32, 0x37, 0x2e, |
| 67 | 0x31, // Custom section |
| 68 | }; |
| 69 | |
| 70 | ASSERT_TRUE(VM.loadWasm(Vec)); |
nothing calls this directly
no test coverage detected