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

Function memory_zeroed

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

Source from the content-addressed store, hash-verified

197
198#[test]
199fn memory_zeroed() -> Result<()> {
200 if skip_pooling_allocator_tests() {
201 return Ok(());
202 }
203
204 let mut pool = crate::small_pool_config();
205 pool.max_memory_size(1 << 16).table_elements(0);
206 let mut config = Config::new();
207 config.allocation_strategy(pool);
208 config.memory_guard_size(0);
209 config.memory_reservation(1 << 16);
210
211 let engine = Engine::new(&config)?;
212
213 let module = Module::new(&engine, r#"(module (memory (export "m") 1))"#)?;
214
215 // Instantiate the module repeatedly after writing data to the entire memory
216 for _ in 0..10 {
217 let mut store = Store::new(&engine, ());
218 let instance = Instance::new(&mut store, &module, &[])?;
219 let memory = instance.get_memory(&mut store, "m").unwrap();
220
221 assert_eq!(memory.size(&store,), 1);
222 assert_eq!(memory.data_size(&store), 65536);
223
224 let ptr = memory.data_mut(&mut store).as_mut_ptr();
225
226 unsafe {
227 for i in 0..8192 {
228 assert_eq!(*ptr.cast::<u64>().offset(i), 0);
229 }
230 std::ptr::write_bytes(ptr, 0xFE, memory.data_size(&store));
231 }
232 }
233
234 Ok(())
235}
236
237#[test]
238#[cfg_attr(miri, ignore)]

Callers

nothing calls this directly

Calls 15

OkFunction · 0.85
write_bytesFunction · 0.85
allocation_strategyMethod · 0.80
small_pool_configFunction · 0.70
newFunction · 0.50
table_elementsMethod · 0.45
max_memory_sizeMethod · 0.45
memory_guard_sizeMethod · 0.45
memory_reservationMethod · 0.45
unwrapMethod · 0.45
get_memoryMethod · 0.45

Tested by

no test coverage detected