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

Function purge_module_with_mpk

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

Source from the content-addressed store, hash-verified

1521
1522#[test]
1523fn purge_module_with_mpk() -> Result<()> {
1524 if !wasmtime::PoolingAllocationConfig::are_memory_protection_keys_available() {
1525 println!("skipping test; mpk is not supported");
1526 return Ok(());
1527 }
1528
1529 let mut pool = crate::small_pool_config();
1530 pool.total_memories(2)
1531 .memory_protection_keys(Enabled::Yes)
1532 .max_memory_protection_keys(2);
1533 let mut config = Config::new();
1534 config.allocation_strategy(InstanceAllocationStrategy::Pooling(pool));
1535 let engine = Engine::new(&config)?;
1536
1537 // Create a module and instantiate it in stripe 0.
1538 let m1 = Module::new(&engine, "(module (memory 1))")?;
1539 let mut store = Store::new(&engine, ());
1540 Instance::new(&mut store, &m1, &[])?;
1541
1542 // Create and instantiate a module in stripe 1. Note that the store is
1543 // immediately destroyed here after instantiation. That should leave the
1544 // linear memory slot available for re-instantiation.
1545 {
1546 let m2 = Module::new(&engine, "(module (memory 1))")?;
1547 Instance::new(&mut Store::new(&engine, ()), &m2, &[])?;
1548
1549 // ... drop `m2` here which will purge it and should remove the warm
1550 // slot left for the module. Nothing should get corrupted...
1551 }
1552
1553 // Drop the outer store here which will clean up the rest of the
1554 // instance/etc.
1555 drop(store);
1556
1557 Ok(())
1558}

Callers

nothing calls this directly

Calls 8

OkFunction · 0.85
allocation_strategyMethod · 0.80
small_pool_configFunction · 0.70
newFunction · 0.50
dropFunction · 0.50
total_memoriesMethod · 0.45

Tested by

no test coverage detected