(config: &mut Config)
| 650 | #[wasmtime_test] |
| 651 | #[cfg_attr(miri, ignore)] |
| 652 | fn custom_operator_cost(config: &mut Config) -> Result<()> { |
| 653 | config.consume_fuel(true); |
| 654 | let op_cost = OperatorCost { |
| 655 | I32Const: 12, |
| 656 | I32Add: 23, |
| 657 | I64Const: 64, |
| 658 | I64Add: 128, |
| 659 | Drop: 5, |
| 660 | ..Default::default() |
| 661 | }; |
| 662 | config.operator_cost(op_cost.clone()); |
| 663 | let engine = Engine::new(config)?; |
| 664 | let module = Module::new( |
| 665 | &engine, |
| 666 | r#" |
| 667 | (module |
| 668 | (func (export "main") |
| 669 | ;; i32: 1 + 2 |
| 670 | (drop (i32.add (i32.const 1) (i32.const 2))) |
| 671 | |
| 672 | ;; i64: 3 + 4 |
| 673 | (drop (i64.add (i64.const 3) (i64.const 4))) |
| 674 | ) |
| 675 | ) |
| 676 | "#, |
| 677 | )?; |
| 678 | let mut store = Store::new(&engine, ()); |
| 679 | store.set_fuel(10_000)?; |
| 680 | |
| 681 | let instance = Instance::new(&mut store, &module, &[])?; |
| 682 | let main = instance.get_typed_func::<(), ()>(&mut store, "main")?; |
| 683 | |
| 684 | let initial_fuel = store.get_fuel()?; |
| 685 | main.call(&mut store, ())?; |
| 686 | let cost_of_execution = u64::from(op_cost.I32Add) |
| 687 | + u64::from(op_cost.I64Add) |
| 688 | + u64::from(op_cost.I32Const) * 2 |
| 689 | + u64::from(op_cost.I64Const) * 2 |
| 690 | + u64::from(op_cost.Drop) * 2 |
| 691 | + 1; |
| 692 | assert_eq!(store.get_fuel()?, initial_fuel - cost_of_execution); |
| 693 | |
| 694 | Ok(()) |
| 695 | } |
nothing calls this directly
no test coverage detected