From 0fc0f2bd0e84c38d6b61bd77c09b85710353f32d Mon Sep 17 00:00:00 2001 From: Muminul Islam Date: Sat, 21 Mar 2026 16:36:41 -0700 Subject: [PATCH] tests: add basic_regular_guest macro and with_kernel Introduce a basic_regular_guest! macro in integration.rs to reduce boilerplate when creating regular (non-CVM) guest instances. Also add a with_kernel() builder method to Guest in test_infra, allowing fluent configuration of the kernel path. Signed-off-by: Muminul Islam --- cloud-hypervisor/tests/integration.rs | 11 +++++++++-- test_infra/src/lib.rs | 5 +++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/cloud-hypervisor/tests/integration.rs b/cloud-hypervisor/tests/integration.rs index 3af45c35c..04f61f59e 100644 --- a/cloud-hypervisor/tests/integration.rs +++ b/cloud-hypervisor/tests/integration.rs @@ -29,6 +29,13 @@ mod common; use common::tests_wrappers::*; use common::utils::*; +macro_rules! basic_regular_guest { + ($image_name:expr) => {{ + let disk_config = UbuntuDiskConfig::new($image_name.to_string()); + GuestFactory::new_regular_guest_factory().create_guest(Box::new(disk_config)) + }}; +} + mod common_parallel { use std::io::{self, SeekFrom}; use std::process::Command; @@ -41,8 +48,8 @@ mod common_parallel { #[cfg(target_arch = "x86_64")] fn test_focal_hypervisor_fw() { let disk_config = UbuntuDiskConfig::new(FOCAL_IMAGE_NAME.to_string()); - let mut guest = Guest::new(Box::new(disk_config)); - guest.kernel_path = Some(fw_path(FwType::RustHypervisorFirmware)); + let guest = basic_regular_guest!(FOCAL_IMAGE_NAME) + .with_kernel(fw_path(FwType::RustHypervisorFirmware)); _test_simple_launch(&guest); } diff --git a/test_infra/src/lib.rs b/test_infra/src/lib.rs index b6d7641f6..a299b2c49 100644 --- a/test_infra/src/lib.rs +++ b/test_infra/src/lib.rs @@ -1018,6 +1018,11 @@ impl Guest { self } + pub fn with_kernel(mut self, kernel: String) -> Self { + self.kernel_path = Some(kernel); + self + } + pub fn default_net_string(&self) -> String { format!( "tap=,mac={},ip={},mask=255.255.255.128",