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

Function memory_limit

tests/all/pooling_allocator.rs:24–98  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

22#[test]
23#[cfg_attr(miri, ignore)]
24fn 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 }

Callers

nothing calls this directly

Calls 11

OkFunction · 0.85
allocation_strategyMethod · 0.80
assert_containsMethod · 0.80
small_pool_configFunction · 0.70
newFunction · 0.50
max_memory_sizeMethod · 0.45
memory_guard_sizeMethod · 0.45
memory_reservationMethod · 0.45
wasm_multi_memoryMethod · 0.45
unwrapMethod · 0.45
get_memoryMethod · 0.45

Tested by

no test coverage detected