From 60c6242bde142ae2c8e88bfa9f14ebdbff9e78c4 Mon Sep 17 00:00:00 2001 From: Muminul Islam Date: Sun, 22 Feb 2026 22:13:57 -0800 Subject: [PATCH] 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 --- cloud-hypervisor/tests/integration.rs | 2 +- test_infra/src/lib.rs | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/cloud-hypervisor/tests/integration.rs b/cloud-hypervisor/tests/integration.rs index c836f631d..9838e1497 100644 --- a/cloud-hypervisor/tests/integration.rs +++ b/cloud-hypervisor/tests/integration.rs @@ -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() diff --git a/test_infra/src/lib.rs b/test_infra/src/lib.rs index cab400082..f45ed3e70 100644 --- a/test_infra/src/lib.rs +++ b/test_infra/src/lib.rs @@ -916,6 +916,8 @@ pub struct Guest { pub kernel_path: Option, pub kernel_cmdline: Option, pub console_type: Option, + 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