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

Function hostcall_trap_events

tests/all/debug.rs:700–740  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

698#[tokio::test]
699#[cfg_attr(miri, ignore)]
700async fn hostcall_trap_events() -> wasmtime::Result<()> {
701 let _ = env_logger::try_init();
702
703 let (module, mut store) = get_module_and_store(
704 |config| {
705 config.wasm_exceptions(true);
706 },
707 r#"
708 (module
709 (func (export "main") (result i32)
710 i32.const 0
711 i32.const 0
712 i32.div_u
713 drop
714 i32.const 42))
715 "#,
716 )?;
717
718 debug_event_checker!(
719 D, store,
720 { 0 ;
721 wasmtime::DebugEvent::Trap(wasmtime_environ::Trap::IntegerDivisionByZero) => {
722 let frame = store.debug_exit_frames().next().unwrap();
723 let (_func, pc) = frame.wasm_function_index_and_pc(&mut store).unwrap().unwrap();
724 assert_eq!(pc.raw(), 0x26);
725 }
726 }
727 );
728
729 let (handler, counter) = D::new_and_counter();
730 store.set_debug_handler(handler);
731
732 let instance = Instance::new_async(&mut store, &module, &[]).await?;
733 let func = instance.get_func(&mut store, "main").unwrap();
734 let mut results = [Val::I32(0)];
735 let result = func.call_async(&mut store, &[], &mut results).await;
736 assert!(result.is_err()); // Uncaught trap.
737 assert_eq!(counter.load(Ordering::Relaxed), 1);
738
739 Ok(())
740}
741
742#[tokio::test]
743#[cfg_attr(miri, ignore)]

Callers

nothing calls this directly

Calls 7

get_module_and_storeFunction · 0.85
OkFunction · 0.85
set_debug_handlerMethod · 0.80
wasm_exceptionsMethod · 0.45
unwrapMethod · 0.45
get_funcMethod · 0.45
call_asyncMethod · 0.45

Tested by

no test coverage detected