tests: centralize default CPU arguments in test infrastructure

Replace the hard-coded  .args(["--cpus", "boot=1"]) in the simple
launch integration test with a shared helper (default_cpus) from test
infrastructure.

Extend Guest with explicit CPU-related defaults (num_cpu, nested)
and add default_cpus_string() so CPU configuration is derived from
guest state instead of being duplicated at call sites.

This refactor improves consistency and makes CPU defaults easier to
maintain across integration tests.

Signed-off-by: Muminul Islam <muislam@microsoft.com>
This commit is contained in:
Muminul Islam
2026-02-22 22:13:57 -08:00
committed by Rob Bradford
parent fdc51d923f
commit 60c6242bde
2 changed files with 17 additions and 1 deletions

View File

@@ -2545,7 +2545,7 @@ fn _test_simple_launch(guest: &Guest) {
let event_path = temp_event_monitor_path(&guest.tmp_dir);
let mut child = GuestCommand::new(guest)
.args(["--cpus", "boot=1"])
.default_cpus()
.args(["--memory", "size=512M"])
.default_kernel_cmdline()
.default_disks()

View File

@@ -916,6 +916,8 @@ pub struct Guest {
pub kernel_path: Option<String>,
pub kernel_cmdline: Option<String>,
pub console_type: Option<String>,
pub num_cpu: u32,
pub nested: bool,
}
// Return the next id that can be used for this guest. This is stored in a
@@ -985,6 +987,8 @@ impl Guest {
kernel_path: None,
kernel_cmdline: None,
console_type: None,
num_cpu: 1u32,
nested: true,
}
}
@@ -1373,6 +1377,14 @@ impl Guest {
}
out_evt
}
pub fn default_cpus_string(&self) -> String {
format!(
"boot={}{}",
self.num_cpu,
if self.nested { "" } else { ",nested=off" }
)
}
}
#[derive(Default)]
@@ -1555,6 +1567,10 @@ impl<'a> GuestCommand<'a> {
self
}
pub fn default_cpus(&mut self) -> &mut Self {
self.args(["--cpus", self.guest.default_cpus_string().as_str()])
}
}
/// Returns the absolute path into the workspaces target directory to locate the desired