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

Function test_custom_table_limiter

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

Source from the content-addressed store, hash-verified

657
658#[test]
659fn test_custom_table_limiter() -> Result<()> {
660 let engine = Engine::default();
661 let linker = Linker::new(&engine);
662
663 let module = Module::new(&engine, r#"(module (table (export "t") 0 funcref))"#)?;
664
665 let context = TableContext {
666 elements_used: 0,
667 element_limit: 10,
668 limit_exceeded: false,
669 };
670
671 let mut store = Store::new(&engine, context);
672 store.limiter(|s| s as &mut dyn ResourceLimiter);
673 let instance = linker.instantiate(&mut store, &module)?;
674 let table = instance.get_table(&mut store, "t").unwrap();
675
676 // Grow the table by 10 elements
677 table.grow(&mut store, 3, Ref::Func(None))?;
678 table.grow(&mut store, 5, Ref::Func(None))?;
679 table.grow(&mut store, 2, Ref::Func(None))?;
680
681 assert!(!store.data().limit_exceeded);
682
683 // Table is at the maximum, but the limit hasn't been exceeded
684 assert!(!store.data().limit_exceeded);
685
686 // Try to grow the memory again
687 assert_eq!(
688 table
689 .grow(&mut store, 1, Ref::Func(None))
690 .map_err(|e| e.to_string())
691 .unwrap_err(),
692 "failed to grow table by `1`"
693 );
694
695 assert!(store.data().limit_exceeded);
696
697 Ok(())
698}
699
700#[derive(Default)]
701struct FailureDetector {

Callers

nothing calls this directly

Calls 8

OkFunction · 0.85
newFunction · 0.50
FuncEnum · 0.50
limiterMethod · 0.45
instantiateMethod · 0.45
unwrapMethod · 0.45
get_tableMethod · 0.45
growMethod · 0.45

Tested by

no test coverage detected