diff --git a/cloud-hypervisor/tests/integration.rs b/cloud-hypervisor/tests/integration.rs index 7250e8d9f..804784507 100644 --- a/cloud-hypervisor/tests/integration.rs +++ b/cloud-hypervisor/tests/integration.rs @@ -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 diff --git a/test_infra/src/lib.rs b/test_infra/src/lib.rs index 0293249ff..60bf4ece0 100644 --- a/test_infra/src/lib.rs +++ b/test_infra/src/lib.rs @@ -1399,6 +1399,40 @@ impl Guest { }; assert_eq!(self.get_cpu_count().unwrap_or_default(), cpu); } + + fn get_expected_memory(&self) -> Option { + // 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) { + let memory = expected_memory + .or_else(|| self.get_expected_memory()) + .unwrap_or_default(); + + assert!(self.get_total_memory().unwrap_or_default() > memory); + } } #[derive(Default)]