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

Function smoke_func_wrap

tests/all/component_model/async.rs:52–91  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

50#[tokio::test]
51#[cfg_attr(miri, ignore)]
52async fn smoke_func_wrap() -> Result<()> {
53 let component = r#"
54 (component
55 (type $f (func))
56 (import "i" (func $f))
57
58 (core module $m
59 (import "imports" "i" (func $i))
60 (func (export "thunk") call $i)
61 )
62
63 (core func $f (canon lower (func $f)))
64 (core instance $i (instantiate $m
65 (with "imports" (instance
66 (export "i" (func $f))
67 ))
68 ))
69 (func (export "thunk")
70 (canon lift (core func $i "thunk"))
71 )
72 )
73 "#;
74
75 let engine = super::async_engine();
76 let component = Component::new(&engine, component)?;
77 let mut store = Store::new(&engine, ());
78 let mut linker = Linker::new(&engine);
79 let mut root = linker.root();
80 root.func_wrap_async("i", |_: StoreContextMut<()>, _: ()| {
81 Box::new(async { Ok(()) })
82 })?;
83
84 let instance = linker.instantiate_async(&mut store, &component).await?;
85
86 let thunk = instance.get_typed_func::<(), ()>(&mut store, "thunk")?;
87
88 thunk.call_async(&mut store, ()).await?;
89
90 Ok(())
91}
92
93// This test stresses TLS management in combination with the `realloc` option
94// for imported functions. This will create an async computation which invokes a

Callers

nothing calls this directly

Calls 7

async_engineFunction · 0.85
OkFunction · 0.85
newFunction · 0.50
rootMethod · 0.45
func_wrap_asyncMethod · 0.45
instantiate_asyncMethod · 0.45
call_asyncMethod · 0.45

Tested by

no test coverage detected