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

Function linear_memory_limits

tests/all/instance.rs:39–81  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

37#[cfg_attr(miri, ignore)]
38#[cfg(target_pointer_width = "64")]
39fn linear_memory_limits() -> Result<()> {
40 // this test will allocate 4GB of virtual memory space, and may not work in
41 // situations like CI QEMU emulation where it triggers SIGKILL.
42 if std::env::var("WASMTIME_TEST_NO_HOG_MEMORY").is_ok() {
43 return Ok(());
44 }
45 test(&Engine::default())?;
46 let mut pool = crate::small_pool_config();
47 pool.max_memory_size(1 << 32);
48 test(&Engine::new(Config::new().allocation_strategy(
49 InstanceAllocationStrategy::Pooling(pool),
50 ))?)?;
51 return Ok(());
52
53 fn test(engine: &Engine) -> Result<()> {
54 let wat = r#"
55 (module
56 (memory 65534)
57
58 (func (export "grow") (result i32)
59 i32.const 1
60 memory.grow)
61 (func (export "size") (result i32)
62 memory.size)
63 )
64 "#;
65 let module = Module::new(engine, wat)?;
66
67 let mut store = Store::new(engine, ());
68 let instance = Instance::new(&mut store, &module, &[])?;
69 let size = instance.get_typed_func::<(), i32>(&mut store, "size")?;
70 let grow = instance.get_typed_func::<(), i32>(&mut store, "grow")?;
71
72 assert_eq!(size.call(&mut store, ())?, 65534);
73 assert_eq!(grow.call(&mut store, ())?, 65534);
74 assert_eq!(size.call(&mut store, ())?, 65535);
75 assert_eq!(grow.call(&mut store, ())?, 65535);
76 assert_eq!(size.call(&mut store, ())?, 65536);
77 assert_eq!(grow.call(&mut store, ())?, -1);
78 assert_eq!(size.call(&mut store, ())?, 65536);
79 Ok(())
80 }
81}

Callers

nothing calls this directly

Calls 7

OkFunction · 0.85
is_okMethod · 0.80
allocation_strategyMethod · 0.80
testFunction · 0.70
small_pool_configFunction · 0.70
newFunction · 0.50
max_memory_sizeMethod · 0.45

Tested by

no test coverage detected