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

Function custom_limiter_async_detect_grow_failure

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

Source from the content-addressed store, hash-verified

855#[tokio::test]
856#[cfg_attr(miri, ignore)]
857async fn custom_limiter_async_detect_grow_failure() -> Result<()> {
858 if std::env::var("WASMTIME_TEST_NO_HOG_MEMORY").is_ok() {
859 return Ok(());
860 }
861 let mut pool = crate::small_pool_config();
862 pool.max_memory_size(10 << 16).table_elements(10);
863 let mut config = Config::new();
864 config.allocation_strategy(InstanceAllocationStrategy::Pooling(pool));
865 let engine = Engine::new(&config).unwrap();
866 let linker = Linker::<FailureDetector>::new(&engine);
867
868 let module = Module::new(
869 &engine,
870 r#"(module (memory (export "m") 0) (table (export "t") 0 funcref))"#,
871 )?;
872
873 let context = FailureDetector::default();
874
875 let mut store = Store::new(&engine, context);
876 store.limiter_async(|s| s as &mut dyn ResourceLimiterAsync);
877 let instance = linker.instantiate_async(&mut store, &module).await?;
878 let memory = instance.get_memory(&mut store, "m").unwrap();
879
880 // Grow the memory by 640 KiB (10 pages)
881 memory.grow_async(&mut store, 10).await?;
882
883 assert!(store.data().memory_error.is_none());
884 assert_eq!(store.data().memory_current, 0);
885 assert_eq!(store.data().memory_desired, 10 * 64 * 1024);
886
887 // Grow past the static limit set by ModuleLimits.
888 // The ResourcLimiterAsync will permit this, but the grow will fail.
889 assert_eq!(
890 memory
891 .grow_async(&mut store, 1)
892 .await
893 .unwrap_err()
894 .to_string(),
895 "failed to grow memory by `1`"
896 );
897
898 assert_eq!(store.data().memory_current, 10 * 64 * 1024);
899 assert_eq!(store.data().memory_desired, 11 * 64 * 1024);
900 assert_eq!(
901 store.data().memory_error.as_ref().unwrap(),
902 "Memory maximum size exceeded"
903 );
904
905 let table = instance.get_table(&mut store, "t").unwrap();
906 // Grow the table 10 elements
907 table.grow_async(&mut store, 10, Ref::Func(None)).await?;
908
909 assert!(store.data().table_error.is_none());
910 assert_eq!(store.data().table_current, 0);
911 assert_eq!(store.data().table_desired, 10);
912
913 // Grow past the static limit set by ModuleLimits.
914 // The ResourceLimiter will permit this, but the grow will fail.

Callers

nothing calls this directly

Calls 15

OkFunction · 0.85
is_okMethod · 0.80
allocation_strategyMethod · 0.80
limiter_asyncMethod · 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
instantiate_asyncMethod · 0.45

Tested by

no test coverage detected