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

Function test_trap_stack_overflow

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

Source from the content-addressed store, hash-verified

264
265#[test]
266fn test_trap_stack_overflow() -> Result<()> {
267 let max_frames = NonZeroUsize::new(32).unwrap();
268 let wat = r#"
269 (module $rec_mod
270 (func $run (export "run") (call $run))
271 )
272 "#;
273
274 let mut config = Config::new();
275 config.wasm_backtrace_max_frames(Some(max_frames));
276 let engine = Engine::new(&config).unwrap();
277 let module = Module::new(&engine, wat).unwrap();
278 let mut store = Store::new(&engine, ());
279 let instance = Instance::new(&mut store, &module, &[]).unwrap();
280 let run_func = instance.get_typed_func::<(), ()>(&mut store, "run")?;
281
282 let e = run_func.call(&mut store, ()).unwrap_err();
283
284 let trace = e.downcast_ref::<WasmBacktrace>().unwrap().frames();
285 assert_eq!(trace.len(), max_frames.get());
286 for i in 0..trace.len() {
287 assert_eq!(trace[i].module().name().unwrap(), "rec_mod");
288 assert_eq!(trace[i].func_index(), 0);
289 assert_eq!(trace[i].func_name(), Some("run"));
290 }
291 assert_eq!(e.downcast::<Trap>()?, Trap::StackOverflow);
292
293 Ok(())
294}
295
296#[test]
297fn trap_display_pretty() -> Result<()> {

Callers

nothing calls this directly

Calls 7

OkFunction · 0.85
newFunction · 0.50
unwrapMethod · 0.45
callMethod · 0.45
framesMethod · 0.45
lenMethod · 0.45

Tested by

no test coverage detected