tests: Refactor _test_virtio_vsock to accept Guest parameter

Extract guest and kernel setup out of _test_virtio_vsock and
pass a Guest reference as a parameter instead. Replace explicit
kernel and cmdline arguments with default_kernel_cmdline().

Move guest creation to the test call sites using
GuestFactory::new_regular_guest_factory(), enabling reuse of
the helper 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 17:50:10 -08:00
committed by Rob Bradford
parent b6d8df772d
commit dacc92a08f

View File

@@ -1781,28 +1781,15 @@ fn get_fd_count(pid: u32) -> usize {
fs::read_dir(format!("/proc/{pid}/fd")).unwrap().count()
}
fn _test_virtio_vsock(hotplug: bool) {
let disk_config = UbuntuDiskConfig::new(JAMMY_IMAGE_NAME.to_string());
let guest = Guest::new(Box::new(disk_config));
#[cfg(target_arch = "x86_64")]
let kernel_path = direct_kernel_boot_path();
#[cfg(target_arch = "aarch64")]
let kernel_path = if hotplug {
edk2_path()
} else {
direct_kernel_boot_path()
};
fn _test_virtio_vsock(guest: &Guest, hotplug: bool) {
let socket = temp_vsock_path(&guest.tmp_dir);
let api_socket = temp_api_path(&guest.tmp_dir);
let mut cmd = GuestCommand::new(&guest);
let mut cmd = GuestCommand::new(guest);
cmd.args(["--api-socket", &api_socket]);
cmd.default_cpus();
cmd.default_memory();
cmd.args(["--kernel", kernel_path.to_str().unwrap()]);
cmd.args(["--cmdline", DIRECT_KERNEL_BOOT_CMDLINE]);
cmd.default_kernel_cmdline();
cmd.default_disks();
cmd.default_net();
@@ -5965,12 +5952,21 @@ mod common_parallel {
#[test]
fn test_virtio_vsock() {
_test_virtio_vsock(false);
let disk_config = UbuntuDiskConfig::new(JAMMY_IMAGE_NAME.to_string());
let guest = GuestFactory::new_regular_guest_factory().create_guest(Box::new(disk_config));
_test_virtio_vsock(&guest, false);
}
#[test]
fn test_virtio_vsock_hotplug() {
_test_virtio_vsock(true);
let disk_config = UbuntuDiskConfig::new(JAMMY_IMAGE_NAME.to_string());
#[cfg(target_arch = "x86_64")]
let guest = GuestFactory::new_regular_guest_factory().create_guest(Box::new(disk_config));
#[cfg(target_arch = "aarch64")]
let guest = GuestFactory::new_regular_guest_factory()
.create_guest(Box::new(disk_config))
.with_kernel_path(edk2_path().to_str().unwrap());
_test_virtio_vsock(&guest, true);
}
#[test]