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

Function memory_init

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

Source from the content-addressed store, hash-verified

100#[test]
101#[cfg_attr(miri, ignore)]
102fn memory_init() -> Result<()> {
103 let mut pool = crate::small_pool_config();
104 pool.max_memory_size(2 << 16).table_elements(0);
105 let mut config = Config::new();
106 config.allocation_strategy(pool);
107
108 let engine = Engine::new(&config)?;
109
110 let module = Module::new(
111 &engine,
112 r#"
113 (module
114 (memory (export "m") 2)
115 (data (i32.const 65530) "this data spans multiple pages")
116 (data (i32.const 10) "hello world")
117 )
118 "#,
119 )?;
120
121 let mut store = Store::new(&engine, ());
122 let instance = Instance::new(&mut store, &module, &[])?;
123 let memory = instance.get_memory(&mut store, "m").unwrap();
124
125 assert_eq!(
126 &memory.data(&store)[65530..65560],
127 b"this data spans multiple pages"
128 );
129 assert_eq!(&memory.data(&store)[10..21], b"hello world");
130
131 Ok(())
132}
133
134#[test]
135#[cfg_attr(miri, ignore)]

Callers

nothing calls this directly

Calls 8

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

Tested by

no test coverage detected