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

Function test_limits

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

Source from the content-addressed store, hash-verified

5#[test]
6#[cfg_attr(miri, ignore)]
7fn test_limits() -> Result<()> {
8 let engine = Engine::default();
9 let module = Module::new(
10 &engine,
11 r#"(module
12 (memory $m (export "m") 0)
13 (table (export "t") 0 funcref)
14 (func (export "grow") (param i32) (result i32)
15 (memory.grow $m (local.get 0)))
16 )"#,
17 )?;
18
19 let mut store = Store::new(
20 &engine,
21 StoreLimitsBuilder::new()
22 .memory_size(10 * WASM_PAGE_SIZE)
23 .table_elements(5)
24 .build(),
25 );
26 store.limiter(|s| s as &mut dyn ResourceLimiter);
27
28 let instance = Instance::new(&mut store, &module, &[])?;
29
30 // Test instance exports and host objects hitting the limit
31 for memory in IntoIterator::into_iter([
32 instance.get_memory(&mut store, "m").unwrap(),
33 Memory::new(&mut store, MemoryType::new(0, None))?,
34 ]) {
35 memory.grow(&mut store, 3)?;
36 memory.grow(&mut store, 5)?;
37 memory.grow(&mut store, 2)?;
38
39 assert_eq!(
40 memory
41 .grow(&mut store, 1)
42 .map_err(|e| e.to_string())
43 .unwrap_err(),
44 "failed to grow memory by `1`"
45 );
46 }
47
48 // Test instance exports and host objects hitting the limit
49 for table in IntoIterator::into_iter([
50 instance.get_table(&mut store, "t").unwrap(),
51 Table::new(
52 &mut store,
53 TableType::new(RefType::FUNCREF, 0, None),
54 Ref::Func(None),
55 )?,
56 ]) {
57 table.grow(&mut store, 2, Ref::Func(None))?;
58 table.grow(&mut store, 1, Ref::Func(None))?;
59 table.grow(&mut store, 2, Ref::Func(None))?;
60
61 assert_eq!(
62 table
63 .grow(&mut store, 1, Ref::Func(None))
64 .map_err(|e| e.to_string())

Callers

nothing calls this directly

Calls 14

into_iterFunction · 0.85
OkFunction · 0.85
memory_sizeMethod · 0.80
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