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

Function test_limits_memory_only

tests/all/limits.rs:185–236  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

183
184#[test]
185fn test_limits_memory_only() -> Result<()> {
186 let engine = Engine::default();
187 let module = Module::new(
188 &engine,
189 r#"(module (memory (export "m") 0) (table (export "t") 0 funcref))"#,
190 )?;
191
192 let mut store = Store::new(
193 &engine,
194 StoreLimitsBuilder::new()
195 .memory_size(10 * WASM_PAGE_SIZE)
196 .build(),
197 );
198 store.limiter(|s| s as &mut dyn ResourceLimiter);
199
200 let instance = Instance::new(&mut store, &module, &[])?;
201
202 // Test instance exports and host objects hitting the limit
203 for memory in IntoIterator::into_iter([
204 instance.get_memory(&mut store, "m").unwrap(),
205 Memory::new(&mut store, MemoryType::new(0, None))?,
206 ]) {
207 memory.grow(&mut store, 3)?;
208 memory.grow(&mut store, 5)?;
209 memory.grow(&mut store, 2)?;
210
211 assert_eq!(
212 memory
213 .grow(&mut store, 1)
214 .map_err(|e| e.to_string())
215 .unwrap_err(),
216 "failed to grow memory by `1`"
217 );
218 }
219
220 // Test instance exports and host objects *not* hitting the limit
221 for table in IntoIterator::into_iter([
222 instance.get_table(&mut store, "t").unwrap(),
223 Table::new(
224 &mut store,
225 TableType::new(RefType::FUNCREF, 0, None),
226 Ref::Func(None),
227 )?,
228 ]) {
229 table.grow(&mut store, 2, Ref::Func(None))?;
230 table.grow(&mut store, 1, Ref::Func(None))?;
231 table.grow(&mut store, 2, Ref::Func(None))?;
232 table.grow(&mut store, 1, Ref::Func(None))?;
233 }
234
235 Ok(())
236}
237
238#[test]
239fn test_initial_memory_limits_exceeded() -> Result<()> {

Callers

nothing calls this directly

Calls 11

into_iterFunction · 0.85
OkFunction · 0.85
memory_sizeMethod · 0.80
newFunction · 0.50
FuncEnum · 0.50
buildMethod · 0.45
limiterMethod · 0.45
unwrapMethod · 0.45
get_memoryMethod · 0.45
growMethod · 0.45
get_tableMethod · 0.45

Tested by

no test coverage detected