From 3b56ec240a32af6456456e30fdfb99050d4ca1d3 Mon Sep 17 00:00:00 2001 From: Muminul Islam Date: Sat, 7 Mar 2026 15:55:24 -0800 Subject: [PATCH] tests: Refactor test_direct_kernel_boot into reusable helper Extract direct kernel boot test logic into a standalone _test_direct_kernel_boot helper that accepts a Guest reference. The helper boots a VM, validates CPU count and memory using generic validate_cpu_count and validate_memory methods, and asserts 12 MSI interrupts 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 | 74 +++++++++++++-------------- 1 file changed, 37 insertions(+), 37 deletions(-) diff --git a/cloud-hypervisor/tests/integration.rs b/cloud-hypervisor/tests/integration.rs index a064a5bbb..2fc61ef51 100644 --- a/cloud-hypervisor/tests/integration.rs +++ b/cloud-hypervisor/tests/integration.rs @@ -2768,6 +2768,41 @@ fn _test_pci_multiple_segments( handle_child_output(r, &output); } +fn _test_direct_kernel_boot(guest: &Guest) { + let mut child = GuestCommand::new(guest) + .default_cpus() + .default_memory() + .default_kernel_cmdline() + .default_disks() + .default_net() + .capture_output() + .spawn() + .unwrap(); + + let r = std::panic::catch_unwind(|| { + guest.wait_vm_boot().unwrap(); + + guest.validate_cpu_count(None); + guest.validate_memory(None); + + let grep_cmd = format!("grep -c {} /proc/interrupts", get_msi_interrupt_pattern()); + 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}; @@ -3250,43 +3285,8 @@ mod common_parallel { #[test] fn test_direct_kernel_boot() { let disk_config = UbuntuDiskConfig::new(JAMMY_IMAGE_NAME.to_string()); - let guest = Guest::new(Box::new(disk_config)); - - let kernel_path = direct_kernel_boot_path(); - - let mut child = GuestCommand::new(&guest) - .default_cpus() - .default_memory() - .args(["--kernel", kernel_path.to_str().unwrap()]) - .args(["--cmdline", DIRECT_KERNEL_BOOT_CMDLINE]) - .default_disks() - .default_net() - .capture_output() - .spawn() - .unwrap(); - - let r = std::panic::catch_unwind(|| { - guest.wait_vm_boot().unwrap(); - - assert_eq!(guest.get_cpu_count().unwrap_or_default(), 1); - assert!(guest.get_total_memory().unwrap_or_default() > 480_000); - - let grep_cmd = format!("grep -c {} /proc/interrupts", get_msi_interrupt_pattern()); - 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_direct_kernel_boot(&guest); } #[test]