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

Function test_trap_trace_cb

tests/all/traps.rs:235–263  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

233
234#[test]
235fn test_trap_trace_cb() -> Result<()> {
236 let mut store = Store::<()>::default();
237 let wat = r#"
238 (module $hello_mod
239 (import "" "throw" (func $throw))
240 (func (export "run") (call $hello))
241 (func $hello (call $throw))
242 )
243 "#;
244
245 let fn_type = FuncType::new(store.engine(), None, None);
246 let fn_func = Func::new(&mut store, fn_type, |_, _, _| bail!("cb throw"));
247
248 let module = Module::new(store.engine(), wat)?;
249 let instance = Instance::new(&mut store, &module, &[fn_func.into()])?;
250 let run_func = instance.get_typed_func::<(), ()>(&mut store, "run")?;
251
252 let e = run_func.call(&mut store, ()).unwrap_err();
253
254 let trace = e.downcast_ref::<WasmBacktrace>().unwrap().frames();
255 assert_eq!(trace.len(), 2);
256 assert_eq!(trace[0].module().name().unwrap(), "hello_mod");
257 assert_eq!(trace[0].func_index(), 2);
258 assert_eq!(trace[1].module().name().unwrap(), "hello_mod");
259 assert_eq!(trace[1].func_index(), 1);
260 e.assert_contains("cb throw");
261
262 Ok(())
263}
264
265#[test]
266fn test_trap_stack_overflow() -> Result<()> {

Callers

nothing calls this directly

Calls 7

OkFunction · 0.85
assert_containsMethod · 0.80
newFunction · 0.50
engineMethod · 0.45
callMethod · 0.45
framesMethod · 0.45
unwrapMethod · 0.45

Tested by

no test coverage detected