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

Function test_trapping_unknown_import

tests/all/linker.rs:375–410  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

373#[test]
374#[cfg_attr(miri, ignore)]
375fn test_trapping_unknown_import() -> Result<()> {
376 const WAT: &str = r#"
377 (module
378 (type $t0 (func))
379 (import "" "imp" (func $.imp (type $t0)))
380 (func $run call $.imp)
381 (func $other)
382 (export "run" (func $run))
383 (export "other" (func $other))
384 )
385 "#;
386
387 let mut store = Store::<()>::default();
388 let module = Module::new(store.engine(), WAT).expect("failed to create module");
389 let mut linker = Linker::new(store.engine());
390
391 linker.define_unknown_imports_as_traps(&module)?;
392 let instance = linker.instantiate(&mut store, &module)?;
393
394 // "run" calls an import function which will not be defined, so it should trap
395 let run_func = instance
396 .get_func(&mut store, "run")
397 .expect("expected a run func in the module");
398
399 let err = run_func.call(&mut store, &[], &mut []).unwrap_err();
400 assert!(err.is::<UnknownImportError>());
401
402 // "other" does not call the import function, so it should not trap
403 let other_func = instance
404 .get_func(&mut store, "other")
405 .expect("expected an other func in the module");
406
407 other_func.call(&mut store, &[], &mut [])?;
408
409 Ok(())
410}
411
412#[test]
413#[cfg_attr(miri, ignore)]

Callers

nothing calls this directly

Calls 8

OkFunction · 0.85
newFunction · 0.50
expectMethod · 0.45
engineMethod · 0.45
instantiateMethod · 0.45
get_funcMethod · 0.45
callMethod · 0.45

Tested by

no test coverage detected