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

Function host_memory_grow

tests/all/memory_creator.rs:154–192  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

152
153 #[test]
154 fn host_memory_grow() -> wasmtime::Result<()> {
155 let (mut store, mem_creator) = config();
156 let module = Module::new(
157 store.engine(),
158 r#"
159 (module
160 (func $f (drop (memory.grow (i32.const 1))))
161 (memory (export "memory") 1 2)
162 (start $f)
163 )
164 "#,
165 )?;
166
167 Instance::new(&mut store, &module, &[])?;
168 let instance2 = Instance::new(&mut store, &module, &[])?;
169
170 assert_eq!(*mem_creator.num_created_memories.lock().unwrap(), 2);
171
172 assert_eq!(
173 instance2
174 .get_memory(&mut store, "memory")
175 .unwrap()
176 .size(&store),
177 2
178 );
179
180 // we take the lock outside the assert, so it won't get poisoned on assert failure
181 let tot_pages = *mem_creator.num_total_bytes.lock().unwrap();
182 assert_eq!(
183 tot_pages,
184 (4 * wasmtime_environ::Memory::DEFAULT_PAGE_SIZE) as usize
185 );
186
187 drop(store);
188 let tot_pages = *mem_creator.num_total_bytes.lock().unwrap();
189 assert_eq!(tot_pages, 0);
190
191 Ok(())
192 }
193}

Callers

nothing calls this directly

Calls 7

OkFunction · 0.85
configFunction · 0.70
newFunction · 0.50
dropFunction · 0.50
engineMethod · 0.45
unwrapMethod · 0.45
lockMethod · 0.45

Tested by

no test coverage detected