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

Function TEST

crates/c-api/tests/async.cc:9–42  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

7using namespace wasmtime;
8
9TEST(async, call_func_async) {
10 Engine engine;
11 Store store(engine);
12 auto context = store.context();
13
14 Module m = Module::compile(
15 engine, "(module"
16 " (func (export \"f\") (param i32 i32) (result i32)"
17 " local.get 0"
18 " local.get 1"
19 " i32.add))")
20 .unwrap();
21
22 Instance instance = Instance::create(store, m, {}).unwrap();
23 auto f = std::get<Func>(*instance.get(store, "f"));
24
25 wasmtime_val_t params[2] = {{.kind = WASMTIME_I32, .of = {.i32 = 34}},
26 {.kind = WASMTIME_I32, .of = {.i32 = 35}}};
27 wasmtime_val_t results[1] = {};
28 wasm_trap_t *trap = nullptr;
29 wasmtime_error_t *error = nullptr;
30
31 auto *future = wasmtime_func_call_async(context.capi(), &f.capi(), params, 2,
32 results, 1, &trap, &error);
33
34 while (!wasmtime_call_future_poll(future)) {
35 }
36 wasmtime_call_future_delete(future);
37
38 EXPECT_EQ(trap, nullptr);
39 EXPECT_EQ(error, nullptr);
40 EXPECT_EQ(results[0].kind, WASMTIME_I32);
41 EXPECT_EQ(results[0].of.i32, 69);
42}
43
44TEST(async, instantiate_async) {
45 Engine engine;

Callers

nothing calls this directly

Calls 10

wasmtime_func_call_asyncFunction · 0.85
compileFunction · 0.50
createFunction · 0.50
contextMethod · 0.45
unwrapMethod · 0.45
getMethod · 0.45
capiMethod · 0.45

Tested by

no test coverage detected