tests: Refactor _test_power_button to accept Guest parameter

Remove the acpi bool parameter and internal guest and kernel
setup from _test_power_button. The function now accepts a Guest
reference and uses default_kernel_cmdline() instead of
hardcoded kernel paths.

Update test_power_button in common_parallel to create a regular
guest via GuestFactory. Update test_power_button_acpi in
aarch64_acpi to use with_kernel_path(edk2_path()) for ACPI
firmware support.

Add with_kernel_path() builder method on Guest in test_infra
to allow overriding the kernel path after guest creation.

Signed-off-by: Muminul Islam <muislam@microsoft.com>
This commit is contained in:
Muminul Islam
2026-03-05 17:20:38 -08:00
committed by Rob Bradford
parent 19fa512f02
commit e278e5e931
2 changed files with 16 additions and 17 deletions

View File

@@ -1052,25 +1052,13 @@ fn _test_guest_numa_nodes(acpi: bool) {
}
#[allow(unused_variables)]
fn _test_power_button(acpi: bool) {
let disk_config = UbuntuDiskConfig::new(JAMMY_IMAGE_NAME.to_string());
let guest = Guest::new(Box::new(disk_config));
let mut cmd = GuestCommand::new(&guest);
fn _test_power_button(guest: &Guest) {
let mut cmd = GuestCommand::new(guest);
let api_socket = temp_api_path(&guest.tmp_dir);
#[cfg(target_arch = "x86_64")]
let kernel_path = direct_kernel_boot_path();
#[cfg(target_arch = "aarch64")]
let kernel_path = if acpi {
edk2_path()
} else {
direct_kernel_boot_path()
};
cmd.default_cpus()
.default_memory()
.args(["--kernel", kernel_path.to_str().unwrap()])
.args(["--cmdline", DIRECT_KERNEL_BOOT_CMDLINE])
.default_kernel_cmdline()
.capture_output()
.default_disks()
.default_net()
@@ -2828,7 +2816,9 @@ mod common_parallel {
#[test]
fn test_power_button() {
_test_power_button(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_power_button(&guest);
}
#[test]
@@ -14533,7 +14523,11 @@ mod aarch64_acpi {
#[test]
fn test_power_button_acpi() {
_test_power_button(true);
let disk_config = UbuntuDiskConfig::new(JAMMY_IMAGE_NAME.to_string());
let guest = GuestFactory::new_regular_guest_factory()
.create_guest(Box::new(disk_config))
.with_kernel_path(edk2_path().to_str().unwrap());
_test_power_button(&guest);
}
#[test]

View File

@@ -1013,6 +1013,11 @@ impl Guest {
self
}
pub fn with_kernel_path(mut self, kernel_path: &str) -> Self {
self.kernel_path = Some(kernel_path.to_string());
self
}
pub fn default_net_string(&self) -> String {
format!(
"tap=,mac={},ip={},mask=255.255.255.128",