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

Function TEST

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

Source from the content-addressed store, hash-verified

5using namespace wasmtime;
6
7TEST(Linker, Smoke) {
8 Engine engine;
9 Linker linker(engine);
10 Store store(engine);
11 linker.allow_shadowing(false);
12 Global g =
13 Global::create(store, GlobalType(ValType::i32(), false), 1).unwrap();
14 linker.define(store, "a", "g", g).unwrap();
15 linker.define_wasi().unwrap();
16 linker
17 .func_new("a", "f", FuncType({}, {}),
18 [](auto caller, auto params, auto results) -> auto {
19 return std::monostate();
20 })
21 .unwrap();
22 linker.func_wrap("a", "f2", []() {}).unwrap();
23 linker.func_wrap("a", "f3", [](Caller arg) {}).unwrap();
24 linker.func_wrap("a", "f4", [](Caller arg, int32_t a) {}).unwrap();
25 Module mod = Module::compile(engine, "(module)").unwrap();
26 Instance i = Instance::create(store, mod, {}).unwrap();
27 linker.define_instance(store, "x", i).unwrap();
28 linker.instantiate(store, mod).unwrap();
29 linker.module(store, "y", mod).unwrap();
30 EXPECT_TRUE(linker.get(store, "a", "g"));
31 linker.get_default(store, "g").unwrap();
32 EXPECT_TRUE(linker.get(store, "a", "f"));
33 EXPECT_TRUE(std::holds_alternative<Func>(*linker.get(store, "a", "f")));
34}
35
36TEST(Linker, CallableMove) {
37 Engine engine;

Callers

nothing calls this directly

Calls 15

define_wasiMethod · 0.80
define_instanceMethod · 0.80
createFunction · 0.50
GlobalTypeClass · 0.50
FuncTypeClass · 0.50
compileFunction · 0.50
allow_shadowingMethod · 0.45
unwrapMethod · 0.45
defineMethod · 0.45
func_newMethod · 0.45
func_wrapMethod · 0.45
instantiateMethod · 0.45

Tested by

no test coverage detected