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 <muislam@microsoft.com>
This commit is contained in:
Muminul Islam
2026-02-22 22:25:32 -08:00
committed by Rob Bradford
parent 45a5c7a04e
commit 05aeef06e5
2 changed files with 11 additions and 1 deletions

View File

@@ -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()

View File

@@ -918,6 +918,7 @@ pub struct Guest {
pub console_type: Option<String>,
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<u32>) {
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