Execute a series of exception-related operations.
(mut fuzz_config: generators::Config, mut ops: ExceptionOps)
| 951 | |
| 952 | /// Execute a series of exception-related operations. |
| 953 | pub fn exception_ops(mut fuzz_config: generators::Config, mut ops: ExceptionOps) -> Result<()> { |
| 954 | match fuzz_config.wasmtime.compiler_strategy { |
| 955 | // Winch doesn't support exceptions; force to Cranelift. |
| 956 | CompilerStrategy::Winch => { |
| 957 | fuzz_config.wasmtime.compiler_strategy = CompilerStrategy::CraneliftNative; |
| 958 | } |
| 959 | CompilerStrategy::CraneliftNative | CompilerStrategy::CraneliftPulley => {} |
| 960 | } |
| 961 | |
| 962 | let module_cfg = &mut fuzz_config.module_config.config; |
| 963 | // Force exceptions + GC on (exceptions require GC). |
| 964 | module_cfg.gc_enabled = true; |
| 965 | module_cfg.exceptions_enabled = true; |
| 966 | module_cfg.reference_types_enabled = true; |
| 967 | |
| 968 | let expected = ops.expected_result(); |
| 969 | |
| 970 | let wasm = ops.to_wasm_binary(); |
| 971 | log_wasm(&wasm); |
| 972 | |
| 973 | let mut store = fuzz_config.to_store(); |
| 974 | |
| 975 | let module = compile_module(store.engine(), &wasm, KnownValid::No, &fuzz_config) |
| 976 | .ok_or_else(|| wasmtime::format_err!("Compilation failed"))?; |
| 977 | let mut linker = Linker::new(store.engine()); |
| 978 | |
| 979 | let check_ty = FuncType::new(store.engine(), [ValType::I32, ValType::I32], []); |
| 980 | let check_func = Func::new(&mut store, check_ty, |_caller, params, _results| { |
| 981 | let actual = params[0].unwrap_i32(); |
| 982 | let expected = params[1].unwrap_i32(); |
| 983 | assert_eq!(actual, expected, "check_i32 mismatch"); |
| 984 | Ok(()) |
| 985 | }); |
| 986 | linker.define(&store, "", "check_i32", check_func).unwrap(); |
| 987 | |
| 988 | let instance = linker.instantiate(&mut store, &module).unwrap(); |
| 989 | let run = instance.get_func(&mut store, "run").unwrap(); |
| 990 | |
| 991 | let mut results = [Val::I32(0)]; |
| 992 | match run.call(&mut store, &[], &mut results) { |
| 993 | Ok(()) => { |
| 994 | let actual = results[0].unwrap_i32(); |
| 995 | assert_eq!( |
| 996 | actual, expected, |
| 997 | "exception_ops: run returned {actual}, expected {expected} \ |
| 998 | (one catch per scenario)" |
| 999 | ); |
| 1000 | } |
| 1001 | Err(e) => { |
| 1002 | // AllocationTooLarge / GcHeapOutOfMemory are acceptable resource-limit traps. |
| 1003 | if let Some(trap) = e.downcast_ref::<Trap>() { |
| 1004 | match trap { |
| 1005 | Trap::AllocationTooLarge => return Ok(()), |
| 1006 | _ => {} |
| 1007 | } |
| 1008 | } |
| 1009 | if e.is::<GcHeapOutOfMemory<()>>() { |
| 1010 | return Ok(()); |
nothing calls this directly
no test coverage detected