tests: Refactor test_pci_msi into reusable helper

Extract PCI MSI interrupt test logic from test_pci_msi into a
standalone _test_pci_msi helper that accepts a Guest reference.
The helper boots a VM, waits for boot, and asserts that 12 MSI
interrupts are present in /proc/interrupts.

Replace hardcoded kernel and cmdline arguments with
default_kernel_cmdline(). Update the test call site in
common_parallel to use GuestFactory and delegate to the new
helper, enabling reuse with different guest types.

Signed-off-by: Muminul Islam <muislam@microsoft.com>
This commit is contained in:
Muminul Islam
2026-03-05 22:31:34 -08:00
committed by Rob Bradford
parent bad5da622e
commit acec5b00d6

View File

@@ -2590,6 +2590,39 @@ fn _test_virtio_queue_affinity(guest: &Guest) {
handle_child_output(r, &output);
}
fn _test_pci_msi(guest: &Guest) {
let mut cmd = GuestCommand::new(guest);
cmd.default_cpus()
.default_memory()
.default_kernel_cmdline()
.capture_output()
.default_disks()
.default_net();
let mut child = cmd.spawn().unwrap();
guest.wait_vm_boot().unwrap();
let grep_cmd = format!("grep -c {} /proc/interrupts", get_msi_interrupt_pattern());
let r = std::panic::catch_unwind(|| {
assert_eq!(
guest
.ssh_command(&grep_cmd)
.unwrap()
.trim()
.parse::<u32>()
.unwrap_or_default(),
12
);
});
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};
@@ -2972,38 +3005,8 @@ mod common_parallel {
#[test]
fn test_pci_msi() {
let disk_config = UbuntuDiskConfig::new(JAMMY_IMAGE_NAME.to_string());
let guest = Guest::new(Box::new(disk_config));
let mut cmd = GuestCommand::new(&guest);
cmd.default_cpus()
.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();
guest.wait_vm_boot().unwrap();
let grep_cmd = format!("grep -c {} /proc/interrupts", get_msi_interrupt_pattern());
let r = std::panic::catch_unwind(|| {
assert_eq!(
guest
.ssh_command(&grep_cmd)
.unwrap()
.trim()
.parse::<u32>()
.unwrap_or_default(),
12
);
});
kill_child(&mut child);
let output = child.wait_with_output().unwrap();
handle_child_output(r, &output);
let guest = GuestFactory::new_regular_guest_factory().create_guest(Box::new(disk_config));
_test_pci_msi(&guest);
}
#[test]