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

Function table_limit

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

Source from the content-addressed store, hash-verified

237#[test]
238#[cfg_attr(miri, ignore)]
239fn table_limit() -> Result<()> {
240 const TABLE_ELEMENTS: usize = 10;
241 let mut pool = crate::small_pool_config();
242 pool.table_elements(TABLE_ELEMENTS);
243 let mut config = Config::new();
244 config.allocation_strategy(pool);
245 config.memory_guard_size(0);
246 config.memory_reservation(1 << 16);
247
248 let engine = Engine::new(&config)?;
249
250 // Module should fail to instantiate because it has too many tables
251 match Module::new(&engine, r#"(module (table 1 funcref) (table 1 funcref))"#) {
252 Ok(_) => panic!("module compilation should fail"),
253 Err(e) => {
254 e.assert_contains("defined tables count of 2 exceeds the per-instance limit of 1")
255 }
256 }
257
258 // Module should fail to instantiate because the minimum is greater than
259 // the configured limit
260 match Module::new(&engine, r#"(module (table 31 funcref))"#) {
261 Ok(_) => panic!("module compilation should fail"),
262 Err(e) => e.assert_contains(
263 "table index 0 has a minimum element size of 31 which exceeds the limit of 10",
264 ),
265 }
266
267 let module = Module::new(
268 &engine,
269 r#"(module (table (export "t") 0 funcref) (func (export "f") (result i32) (table.grow (ref.null func) (i32.const 1))))"#,
270 )?;
271
272 // Instantiate the module and grow the table via the `f` function
273 {
274 let mut store = Store::new(&engine, ());
275 let instance = Instance::new(&mut store, &module, &[])?;
276 let f = instance.get_typed_func::<(), i32>(&mut store, "f")?;
277
278 for i in 0..TABLE_ELEMENTS {
279 assert_eq!(
280 f.call(&mut store, ()).expect("function should not trap"),
281 i as i32
282 );
283 }
284
285 assert_eq!(
286 f.call(&mut store, ()).expect("function should not trap"),
287 -1
288 );
289 assert_eq!(
290 f.call(&mut store, ()).expect("function should not trap"),
291 -1
292 );
293 }
294
295 // Instantiate the module and grow the table via the Wasmtime API
296 let mut store = Store::new(&engine, ());

Callers

nothing calls this directly

Calls 10

OkFunction · 0.85
allocation_strategyMethod · 0.80
assert_containsMethod · 0.80
small_pool_configFunction · 0.70
newFunction · 0.50
table_elementsMethod · 0.45
memory_guard_sizeMethod · 0.45
memory_reservationMethod · 0.45
unwrapMethod · 0.45
get_tableMethod · 0.45

Tested by

no test coverage detected