()
| 22 | #[test] |
| 23 | #[cfg_attr(miri, ignore)] |
| 24 | fn memory_limit() -> Result<()> { |
| 25 | let mut pool = crate::small_pool_config(); |
| 26 | pool.max_memory_size(3 << 16); |
| 27 | let mut config = Config::new(); |
| 28 | config.allocation_strategy(pool); |
| 29 | config.memory_guard_size(1 << 16); |
| 30 | config.memory_reservation(3 << 16); |
| 31 | config.wasm_multi_memory(true); |
| 32 | |
| 33 | let engine = Engine::new(&config)?; |
| 34 | |
| 35 | // Module should fail to instantiate because it has too many memories |
| 36 | match Module::new(&engine, r#"(module (memory 1) (memory 1))"#) { |
| 37 | Ok(_) => panic!("module instantiation should fail"), |
| 38 | Err(e) => { |
| 39 | e.assert_contains("defined memories count of 2 exceeds the per-instance limit of 1") |
| 40 | } |
| 41 | } |
| 42 | |
| 43 | // Module should fail to instantiate because the minimum is greater than |
| 44 | // the configured limit |
| 45 | match Module::new(&engine, r#"(module (memory 4))"#) { |
| 46 | Ok(_) => panic!("module instantiation should fail"), |
| 47 | Err(e) => { |
| 48 | e.assert_contains( |
| 49 | "memory index 0 is unsupported in this pooling allocator \ |
| 50 | configuration", |
| 51 | ); |
| 52 | e.assert_contains( |
| 53 | "memory has a minimum byte size of 262144 which exceeds \ |
| 54 | the limit of 0x30000 bytes", |
| 55 | ); |
| 56 | } |
| 57 | } |
| 58 | |
| 59 | let module = Module::new( |
| 60 | &engine, |
| 61 | r#"(module (memory (export "m") 0) (func (export "f") (result i32) (memory.grow (i32.const 1))))"#, |
| 62 | )?; |
| 63 | |
| 64 | // Instantiate the module and grow the memory via the `f` function |
| 65 | { |
| 66 | let mut store = Store::new(&engine, ()); |
| 67 | let instance = Instance::new(&mut store, &module, &[])?; |
| 68 | let f = instance.get_typed_func::<(), i32>(&mut store, "f")?; |
| 69 | |
| 70 | assert_eq!(f.call(&mut store, ()).expect("function should not trap"), 0); |
| 71 | assert_eq!(f.call(&mut store, ()).expect("function should not trap"), 1); |
| 72 | assert_eq!(f.call(&mut store, ()).expect("function should not trap"), 2); |
| 73 | assert_eq!( |
| 74 | f.call(&mut store, ()).expect("function should not trap"), |
| 75 | -1 |
| 76 | ); |
| 77 | assert_eq!( |
| 78 | f.call(&mut store, ()).expect("function should not trap"), |
| 79 | -1 |
| 80 | ); |
| 81 | } |
nothing calls this directly
no test coverage detected