From 05aeef06e504dbc3fc063c5abc652329c194f014 Mon Sep 17 00:00:00 2001 From: Muminul Islam Date: Sun, 22 Feb 2026 22:25:32 -0800 Subject: [PATCH] tests: centralize default memory args in helpers Replace hard-coded --memory args in simple launch tests with GuestCommand defaults driven by Guest state. Add Guest.mem_size_str with a default of 512M and introduce default_memory_string() and GuestCommand::default_memory(). Signed-off-by: Muminul Islam --- cloud-hypervisor/tests/integration.rs | 2 +- test_infra/src/lib.rs | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/cloud-hypervisor/tests/integration.rs b/cloud-hypervisor/tests/integration.rs index 6b1859173..7250e8d9f 100644 --- a/cloud-hypervisor/tests/integration.rs +++ b/cloud-hypervisor/tests/integration.rs @@ -2546,7 +2546,7 @@ fn _test_simple_launch(guest: &Guest) { let mut child = GuestCommand::new(guest) .default_cpus() - .args(["--memory", "size=512M"]) + .default_memory() .default_kernel_cmdline() .default_disks() .default_net() diff --git a/test_infra/src/lib.rs b/test_infra/src/lib.rs index d5349b43e..0293249ff 100644 --- a/test_infra/src/lib.rs +++ b/test_infra/src/lib.rs @@ -918,6 +918,7 @@ pub struct Guest { pub console_type: Option, pub num_cpu: u32, pub nested: bool, + pub mem_size_str: String, } // Return the next id that can be used for this guest. This is stored in a @@ -989,6 +990,7 @@ impl Guest { console_type: None, num_cpu: 1u32, nested: true, + mem_size_str: "512M".to_string(), } } @@ -1386,6 +1388,10 @@ impl Guest { ) } + pub fn default_memory_string(&self) -> String { + format!("size={}", self.mem_size_str) + } + pub fn validate_cpu_count(&self, expected_cpu_count: Option) { let cpu = match expected_cpu_count { Some(count) => count, @@ -1579,6 +1585,10 @@ impl<'a> GuestCommand<'a> { pub fn default_cpus(&mut self) -> &mut Self { self.args(["--cpus", self.guest.default_cpus_string().as_str()]) } + + pub fn default_memory(&mut self) -> &mut Self { + self.args(["--memory", self.guest.default_memory_string().as_str()]) + } } /// Returns the absolute path into the workspaces target directory to locate the desired