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

Function custom_limiter_detect_grow_failure

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

Source from the content-addressed store, hash-verified

744
745#[test]
746fn custom_limiter_detect_grow_failure() -> Result<()> {
747 if std::env::var("WASMTIME_TEST_NO_HOG_MEMORY").is_ok() {
748 return Ok(());
749 }
750 let mut pool = crate::small_pool_config();
751 pool.max_memory_size(10 << 16).table_elements(10);
752 let mut config = Config::new();
753 config.allocation_strategy(InstanceAllocationStrategy::Pooling(pool));
754 let engine = Engine::new(&config).unwrap();
755 let linker = Linker::new(&engine);
756
757 let module = Module::new(
758 &engine,
759 r#"(module (memory (export "m") 0) (table (export "t") 0 funcref))"#,
760 )?;
761
762 let context = FailureDetector::default();
763
764 let mut store = Store::new(&engine, context);
765 store.limiter(|s| s as &mut dyn ResourceLimiter);
766 let instance = linker.instantiate(&mut store, &module)?;
767 let memory = instance.get_memory(&mut store, "m").unwrap();
768
769 // Grow the memory by 640 KiB (10 pages)
770 memory.grow(&mut store, 10)?;
771
772 assert!(store.data().memory_error.is_none());
773 assert_eq!(store.data().memory_current, 0);
774 assert_eq!(store.data().memory_desired, 10 * 64 * 1024);
775
776 // Grow past the static limit set by ModuleLimits.
777 // The ResourceLimiter will permit this, but the grow will fail.
778 assert_eq!(
779 memory.grow(&mut store, 1).unwrap_err().to_string(),
780 "failed to grow memory by `1`"
781 );
782
783 assert_eq!(store.data().memory_current, 10 * 64 * 1024);
784 assert_eq!(store.data().memory_desired, 11 * 64 * 1024);
785 assert_eq!(
786 store.data().memory_error.as_ref().unwrap(),
787 "Memory maximum size exceeded"
788 );
789
790 let table = instance.get_table(&mut store, "t").unwrap();
791 // Grow the table 10 elements
792 table.grow(&mut store, 10, Ref::Func(None))?;
793
794 assert!(store.data().table_error.is_none());
795 assert_eq!(store.data().table_current, 0);
796 assert_eq!(store.data().table_desired, 10);
797
798 // Grow past the static limit set by ModuleLimits.
799 // The ResourceLimiter will permit this, but the grow will fail.
800 assert_eq!(
801 table
802 .grow(&mut store, 1, Ref::Func(None))
803 .unwrap_err()

Callers

nothing calls this directly

Calls 15

OkFunction · 0.85
is_okMethod · 0.80
allocation_strategyMethod · 0.80
small_pool_configFunction · 0.70
newFunction · 0.50
FuncEnum · 0.50
dropFunction · 0.50
table_elementsMethod · 0.45
max_memory_sizeMethod · 0.45
unwrapMethod · 0.45
limiterMethod · 0.45
instantiateMethod · 0.45

Tested by

no test coverage detected