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

Function test_trap_trace

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

Source from the content-addressed store, hash-verified

114
115#[test]
116fn test_trap_trace() -> Result<()> {
117 let mut store = Store::<()>::default();
118 let wat = r#"
119 (module $hello_mod
120 (func (export "run") (call $hello))
121 (func $hello (unreachable))
122 )
123 "#;
124
125 let module = Module::new(store.engine(), wat)?;
126 let instance = Instance::new(&mut store, &module, &[])?;
127 let run_func = instance.get_typed_func::<(), ()>(&mut store, "run")?;
128
129 let e = run_func.call(&mut store, ()).unwrap_err();
130
131 let trace = e.downcast_ref::<WasmBacktrace>().unwrap().frames();
132 assert_eq!(trace.len(), 2);
133 assert_eq!(trace[0].module().name().unwrap(), "hello_mod");
134 assert_eq!(trace[0].func_index(), 1);
135 assert_eq!(trace[0].func_name(), Some("hello"));
136 assert_eq!(trace[0].func_offset(), Some(1));
137 assert_eq!(trace[0].module_offset(), Some(0x26));
138 assert_eq!(trace[1].module().name().unwrap(), "hello_mod");
139 assert_eq!(trace[1].func_index(), 0);
140 assert_eq!(trace[1].func_name(), None);
141 assert_eq!(trace[1].func_offset(), Some(1));
142 assert_eq!(trace[1].module_offset(), Some(0x21));
143 assert_eq!(e.downcast::<Trap>()?, Trap::UnreachableCodeReached);
144
145 Ok(())
146}
147
148#[test]
149fn test_trap_through_host() -> Result<()> {

Callers

nothing calls this directly

Calls 6

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

Tested by

no test coverage detected