tests: centralize memory validation in test helpers

Replace the hard-coded memory threshold check in the simple launch
integration test with Guest::validate_memory(None).

Add Guest::get_expected_memory() to derive thresholds from mem_size_str
and vm_type, and reuse this through validate_memory().

Signed-off-by: Muminul Islam <muislam@microsoft.com>
This commit is contained in:
Muminul Islam
2026-02-22 22:39:10 -08:00
committed by Rob Bradford
parent 05aeef06e5
commit 32edcf39a6
2 changed files with 35 additions and 1 deletions

View File

@@ -2560,7 +2560,7 @@ fn _test_simple_launch(guest: &Guest) {
guest.wait_vm_boot().unwrap();
guest.validate_cpu_count(None);
assert!(guest.get_total_memory().unwrap_or_default() > 480_000);
guest.validate_memory(None);
assert_eq!(guest.get_pci_bridge_class().unwrap_or_default(), "0x060000");
assert!(check_sequential_events(
&guest

View File

@@ -1399,6 +1399,40 @@ impl Guest {
};
assert_eq!(self.get_cpu_count().unwrap_or_default(), cpu);
}
fn get_expected_memory(&self) -> Option<u32> {
// For confidential VMs, the memory available to the guest is less than
// the memory assigned to the VM, as some of it is reserved for the PSP
// and bounce buffers.
// So we return the expected available memory for confidential VMs here.
let memory = match self.mem_size_str.as_str() {
"512M" => {
if self.vm_type == GuestVmType::Confidential {
407_000
} else {
480_000
}
}
"1G" => {
if self.vm_type == GuestVmType::Confidential {
920_000
} else {
960_000
}
}
// More to be added if more memory sizes are used in the tests
_ => panic!("Unsupported memory size: {}", self.mem_size_str),
};
Some(memory)
}
pub fn validate_memory(&self, expected_memory: Option<u32>) {
let memory = expected_memory
.or_else(|| self.get_expected_memory())
.unwrap_or_default();
assert!(self.get_total_memory().unwrap_or_default() > memory);
}
}
#[derive(Default)]