| 5 | using namespace wasmtime; |
| 6 | |
| 7 | TEST(Instance, Smoke) { |
| 8 | Engine engine; |
| 9 | Store store(engine); |
| 10 | Memory m = Memory::create(store, MemoryType(1)).unwrap(); |
| 11 | Global g = |
| 12 | Global::create(store, GlobalType(ValType::i32(), false), 1).unwrap(); |
| 13 | Table t = Table::create(store, TableType(ValType::funcref(), 1), |
| 14 | std::optional<Func>()) |
| 15 | .unwrap(); |
| 16 | Func f(store, FuncType({}, {}), |
| 17 | [](auto caller, auto params, auto results) -> auto { |
| 18 | return std::monostate(); |
| 19 | }); |
| 20 | |
| 21 | Module mod = |
| 22 | Module::compile(engine, "(module" |
| 23 | "(import \"\" \"\" (func))" |
| 24 | "(import \"\" \"\" (global i32))" |
| 25 | "(import \"\" \"\" (table 1 funcref))" |
| 26 | "(import \"\" \"\" (memory 1))" |
| 27 | |
| 28 | "(func (export \"f\"))" |
| 29 | "(global (export \"g\") i32 (i32.const 0))" |
| 30 | "(export \"m\" (memory 0))" |
| 31 | "(export \"t\" (table 0))" |
| 32 | ")") |
| 33 | .unwrap(); |
| 34 | Instance::create(store, mod, {}).err(); |
| 35 | Instance i = Instance::create(store, mod, {f, g, t, m}).unwrap(); |
| 36 | EXPECT_FALSE(i.get(store, "not-present")); |
| 37 | f = std::get<Func>(*i.get(store, "f")); |
| 38 | m = std::get<Memory>(*i.get(store, "m")); |
| 39 | t = std::get<Table>(*i.get(store, "t")); |
| 40 | g = std::get<Global>(*i.get(store, "g")); |
| 41 | |
| 42 | EXPECT_TRUE(i.get(store, 0)); |
| 43 | EXPECT_TRUE(i.get(store, 1)); |
| 44 | EXPECT_TRUE(i.get(store, 2)); |
| 45 | EXPECT_TRUE(i.get(store, 3)); |
| 46 | EXPECT_FALSE(i.get(store, 4)); |
| 47 | auto [name, func] = *i.get(store, 0); |
| 48 | EXPECT_EQ(name, "f"); |
| 49 | } |
| 50 | |
| 51 | TEST(Instance, NewClearsTrapPointer) { |
| 52 | Engine engine; |
nothing calls this directly
no test coverage detected