From acec5b00d64f1268cfc69703a287029a3eb261f9 Mon Sep 17 00:00:00 2001 From: Muminul Islam Date: Thu, 5 Mar 2026 22:31:34 -0800 Subject: [PATCH] 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 --- cloud-hypervisor/tests/integration.rs | 67 ++++++++++++++------------- 1 file changed, 35 insertions(+), 32 deletions(-) diff --git a/cloud-hypervisor/tests/integration.rs b/cloud-hypervisor/tests/integration.rs index cd5118642..4e919884b 100644 --- a/cloud-hypervisor/tests/integration.rs +++ b/cloud-hypervisor/tests/integration.rs @@ -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::() + .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::() - .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]