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

Function test_limits_table_only

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

Source from the content-addressed store, hash-verified

269
270#[test]
271fn test_limits_table_only() -> Result<()> {
272 let engine = Engine::default();
273 let module = Module::new(
274 &engine,
275 r#"(module (memory (export "m") 0) (table (export "t") 0 funcref))"#,
276 )?;
277
278 let mut store = Store::new(&engine, StoreLimitsBuilder::new().table_elements(5).build());
279 store.limiter(|s| s as &mut dyn ResourceLimiter);
280
281 let instance = Instance::new(&mut store, &module, &[])?;
282
283 // Test instance exports and host objects *not* hitting the limit
284 for memory in IntoIterator::into_iter([
285 instance.get_memory(&mut store, "m").unwrap(),
286 Memory::new(&mut store, MemoryType::new(0, None))?,
287 ]) {
288 memory.grow(&mut store, 3)?;
289 memory.grow(&mut store, 5)?;
290 memory.grow(&mut store, 2)?;
291 memory.grow(&mut store, 1)?;
292 }
293
294 // Test instance exports and host objects hitting the limit
295 for table in IntoIterator::into_iter([
296 instance.get_table(&mut store, "t").unwrap(),
297 Table::new(
298 &mut store,
299 TableType::new(RefType::FUNCREF, 0, None),
300 Ref::Func(None),
301 )?,
302 ]) {
303 table.grow(&mut store, 2, Ref::Func(None))?;
304 table.grow(&mut store, 1, Ref::Func(None))?;
305 table.grow(&mut store, 2, Ref::Func(None))?;
306
307 assert_eq!(
308 table
309 .grow(&mut store, 1, Ref::Func(None))
310 .map_err(|e| e.to_string())
311 .unwrap_err(),
312 "failed to grow table by `1`"
313 );
314 }
315
316 Ok(())
317}
318
319#[test]
320fn test_initial_table_limits_exceeded() -> Result<()> {

Callers

nothing calls this directly

Calls 11

into_iterFunction · 0.85
OkFunction · 0.85
newFunction · 0.50
FuncEnum · 0.50
buildMethod · 0.45
table_elementsMethod · 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