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

Function test_wasm_backtrace_max_frames

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

Source from the content-addressed store, hash-verified

1835
1836#[test]
1837fn test_wasm_backtrace_max_frames() -> Result<()> {
1838 fn run(max_frames: Option<NonZeroUsize>) -> wasmtime::Error {
1839 let wat = r#"
1840 (module
1841 (func $f1 (export "f1") (call $f2))
1842 (func $f2 (call $f3))
1843 (func $f3 (call $f4))
1844 (func $f4 (call $f5))
1845 (func $f5 (call $f6))
1846 (func $f6 (call $f7))
1847 (func $f7 (call $f8))
1848 (func $f8 (call $f9))
1849 (func $f9 (call $f10))
1850 (func $f10 (unreachable))
1851 )
1852 "#;
1853
1854 let mut config = Config::new();
1855 config.wasm_backtrace_max_frames(max_frames);
1856 let engine = Engine::new(&config).unwrap();
1857 let module = Module::new(&engine, wat).unwrap();
1858 let mut store = Store::new(&engine, ());
1859 let instance = Instance::new(&mut store, &module, &[]).unwrap();
1860 let f1 = instance.get_typed_func::<(), ()>(&mut store, "f1").unwrap();
1861 f1.call(&mut store, ()).unwrap_err()
1862 }
1863
1864 // Capturing more than 10 frames should get them all.
1865 let err = run(NonZeroUsize::new(20));
1866 let bt = err.downcast_ref::<WasmBacktrace>().unwrap();
1867 assert_eq!(bt.frames().len(), 10);
1868
1869 // Limit to 5 frames gets the top 5.
1870 let err = run(NonZeroUsize::new(5));
1871 let bt = err.downcast_ref::<WasmBacktrace>().unwrap();
1872 assert_eq!(bt.frames().len(), 5);
1873
1874 // Limit of None means no frames collected
1875 let err = run(None);
1876 assert!(err.downcast_ref::<WasmBacktrace>().is_none());
1877
1878 Ok(())
1879}

Callers

nothing calls this directly

Calls 4

OkFunction · 0.85
runFunction · 0.70
newFunction · 0.50
unwrapMethod · 0.45

Tested by

no test coverage detected