From 18ed8e61d201cc1de0cba0b523e5ed4a9853629e Mon Sep 17 00:00:00 2001 From: Muminul Islam Date: Thu, 5 Mar 2026 18:38:10 -0800 Subject: [PATCH] tests: Refactor test_multi_cpu into reusable helper Extract the multi-CPU test logic from the test_multi_cpu test into a standalone _test_multi_cpu helper that accepts a Guest reference as a parameter. Update the test_multi_cpu call site in common_parallel to create the guest via GuestFactory::new_regular_guest_factory() and delegate to the new helper. This enables reuse of the test logic with different guest types such as confidential VMs. Signed-off-by: Muminul Islam --- cloud-hypervisor/tests/integration.rs | 69 +++++++++++++-------------- 1 file changed, 34 insertions(+), 35 deletions(-) diff --git a/cloud-hypervisor/tests/integration.rs b/cloud-hypervisor/tests/integration.rs index 47c3c1f04..ccc874bad 100644 --- a/cloud-hypervisor/tests/integration.rs +++ b/cloud-hypervisor/tests/integration.rs @@ -2471,6 +2471,37 @@ fn _test_simple_launch(guest: &Guest) { handle_child_output(r, &output); } +fn _test_multi_cpu(guest: &Guest) { + let mut cmd = GuestCommand::new(guest); + cmd.args(["--cpus", "boot=2,max=4"]) + .default_memory() + .default_kernel_cmdline() + .capture_output() + .default_disks() + .default_net(); + + let mut child = cmd.spawn().unwrap(); + + let r = std::panic::catch_unwind(|| { + guest.wait_vm_boot().unwrap(); + + assert_eq!(guest.get_cpu_count().unwrap_or_default(), 2); + + assert_eq!( + guest + .ssh_command(r#"sudo dmesg | grep "smp: Brought up" | sed "s/\[\ *[0-9.]*\] //""#) + .unwrap() + .trim(), + "smp: Brought up 1 node, 2 CPUs" + ); + }); + + kill_child(&mut child); + let output = child.wait_with_output().unwrap(); + + handle_child_output(r, &output); +} + mod common_parallel { use std::cmp; use std::fs::{File, OpenOptions, copy}; @@ -2502,41 +2533,9 @@ mod common_parallel { #[test] fn test_multi_cpu() { - let jammy_image = JAMMY_IMAGE_NAME.to_string(); - let disk_config = UbuntuDiskConfig::new(jammy_image); - let guest = Guest::new(Box::new(disk_config)); - - let mut cmd = GuestCommand::new(&guest); - cmd.args(["--cpus", "boot=2,max=4"]) - .default_memory() - .args(["--kernel", direct_kernel_boot_path().to_str().unwrap()]) - .args(["--cmdline", DIRECT_KERNEL_BOOT_CMDLINE]) - .capture_output() - .default_disks() - .default_net(); - - let mut child = cmd.spawn().unwrap(); - - let r = std::panic::catch_unwind(|| { - guest.wait_vm_boot().unwrap(); - - assert_eq!(guest.get_cpu_count().unwrap_or_default(), 2); - - assert_eq!( - guest - .ssh_command( - r#"sudo dmesg | grep "smp: Brought up" | sed "s/\[\ *[0-9.]*\] //""# - ) - .unwrap() - .trim(), - "smp: Brought up 1 node, 2 CPUs" - ); - }); - - kill_child(&mut child); - let output = child.wait_with_output().unwrap(); - - handle_child_output(r, &output); + let disk_config = UbuntuDiskConfig::new(JAMMY_IMAGE_NAME.to_string()); + let guest = GuestFactory::new_regular_guest_factory().create_guest(Box::new(disk_config)); + _test_multi_cpu(&guest); } #[test]