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

Function static_api_test

crates/fuzzing/src/oracles/component_api.rs:234–333  ·  view source on GitHub ↗

Generate zero or more sets of arbitrary argument and result values and execute the test using those values, asserting that they flow from host-to-guest and guest-to-host unchanged.

(
    input: &mut Unstructured<'a>,
    declarations: &Declarations,
)

Source from the content-addressed store, hash-verified

232/// Generate zero or more sets of arbitrary argument and result values and execute the test using those
233/// values, asserting that they flow from host-to-guest and guest-to-host unchanged.
234pub fn static_api_test<'a, P, R>(
235 input: &mut Unstructured<'a>,
236 declarations: &Declarations,
237) -> arbitrary::Result<()>
238where
239 P: ComponentNamedList
240 + Lift
241 + Lower
242 + Clone
243 + PartialEq
244 + Debug
245 + Arbitrary<'a>
246 + Send
247 + Sync
248 + 'static,
249 R: ComponentNamedList
250 + Lift
251 + Lower
252 + Clone
253 + PartialEq
254 + Debug
255 + Arbitrary<'a>
256 + Send
257 + Sync
258 + 'static,
259{
260 crate::init_fuzzing();
261
262 let mut store = store::<Box<dyn Any + Send>>(input, Box::new(()))?;
263 let engine = store.engine();
264 let wat = declarations.make_component();
265 let wat = wat.as_bytes();
266 crate::oracles::log_wasm(wat);
267 let component = Component::new(&engine, wat).unwrap();
268 let mut linker = Linker::new(&engine);
269
270 fn host_function<P, R>(
271 cx: StoreContextMut<'_, Box<dyn Any + Send>>,
272 params: P,
273 ) -> wasmtime::Result<R>
274 where
275 P: Debug + PartialEq + 'static,
276 R: Debug + Clone + 'static,
277 {
278 log::trace!("received parameters {params:?}");
279 let data: &(P, R) = cx.data().downcast_ref().unwrap();
280 let (expected_params, result) = data;
281 assert_eq!(params, *expected_params);
282 log::trace!("returning result {result:?}");
283 Ok(result.clone())
284 }
285
286 if declarations.options.host_async {
287 linker
288 .root()
289 .func_wrap_concurrent(IMPORT_FUNCTION, |a, params| {
290 Box::pin(async move {
291 a.with(|mut cx| host_function::<P, R>(cx.as_context_mut(), params))

Callers

nothing calls this directly

Calls 15

init_fuzzingFunction · 0.85
log_wasmFunction · 0.85
OkFunction · 0.85
make_componentMethod · 0.80
as_bytesMethod · 0.80
run_concurrentMethod · 0.80
call_concurrentMethod · 0.80
newFunction · 0.50
block_onFunction · 0.50
engineMethod · 0.45
unwrapMethod · 0.45
func_wrap_concurrentMethod · 0.45

Tested by

no test coverage detected