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 <muislam@microsoft.com>
This commit is contained in:
Muminul Islam
2026-03-05 18:38:10 -08:00
committed by Rob Bradford
parent c44b7679cf
commit 18ed8e61d2

View File

@@ -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]