| 478 | #[wasmtime_test] |
| 479 | #[cfg_attr(miri, ignore)] |
| 480 | fn host_function_consumes_all(config: &mut Config) -> Result<()> { |
| 481 | const FUEL: u64 = 10_000; |
| 482 | config.consume_fuel(true); |
| 483 | let engine = Engine::new(&config)?; |
| 484 | let module = Module::new( |
| 485 | &engine, |
| 486 | r#" |
| 487 | (module |
| 488 | (import "" "" (func)) |
| 489 | (func (export "") |
| 490 | call 0 |
| 491 | call $other) |
| 492 | (func $other)) |
| 493 | "#, |
| 494 | ) |
| 495 | .unwrap(); |
| 496 | let mut store = Store::new(&engine, ()); |
| 497 | store.set_fuel(FUEL).unwrap(); |
| 498 | let func = Func::wrap(&mut store, |mut caller: Caller<'_, ()>| { |
| 499 | let remaining = caller.get_fuel().unwrap(); |
| 500 | assert_eq!(remaining, FUEL - 2); |
| 501 | assert!(caller.set_fuel(1).is_ok()); |
| 502 | }); |
| 503 | |
| 504 | let instance = Instance::new(&mut store, &module, &[func.into()]).unwrap(); |
| 505 | let export = instance.get_typed_func::<(), ()>(&mut store, "").unwrap(); |
| 506 | let trap = export.call(&mut store, ()).unwrap_err(); |
| 507 | assert_eq!(trap.downcast::<Trap>().unwrap(), Trap::OutOfFuel); |
| 508 | Ok(()) |
| 509 | } |
| 510 | |
| 511 | #[wasmtime_test] |
| 512 | fn manual_edge_cases(config: &mut Config) -> Result<()> { |