MCPcopy Create free account
hub / github.com/bytecodealliance/wasmtime / TEST

Function TEST

crates/c-api/tests/instance.cc:7–49  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

5using namespace wasmtime;
6
7TEST(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
51TEST(Instance, NewClearsTrapPointer) {
52 Engine engine;

Callers

nothing calls this directly

Calls 12

wasmtime_instance_newFunction · 0.85
createFunction · 0.50
MemoryTypeClass · 0.50
GlobalTypeClass · 0.50
TableTypeClass · 0.50
FuncTypeClass · 0.50
compileFunction · 0.50
unwrapMethod · 0.45
errMethod · 0.45
getMethod · 0.45
contextMethod · 0.45
capiMethod · 0.45

Tested by

no test coverage detected