From 1bf083bf005a4d7a077784cfc7de739ac1e1e7e0 Mon Sep 17 00:00:00 2001 From: Henry Wang Date: Thu, 2 Sep 2021 00:59:11 -0400 Subject: [PATCH] tests: Add a test case for Arm64 ACPI power button Signed-off-by: Henry Wang --- tests/integration.rs | 66 +++++++++++++++++++++++++++++--------------- 1 file changed, 43 insertions(+), 23 deletions(-) diff --git a/tests/integration.rs b/tests/integration.rs index 15e6e8d4d..0dd00e2ba 100644 --- a/tests/integration.rs +++ b/tests/integration.rs @@ -1061,6 +1061,43 @@ mod tests { handle_child_output(r, &output); } + #[allow(unused_variables)] + fn _test_power_button(acpi: bool) { + let focal = UbuntuDiskConfig::new(FOCAL_IMAGE_NAME.to_string()); + let guest = Guest::new(Box::new(focal)); + 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.args(&["--cpus", "boot=1"]) + .args(&["--memory", "size=512M"]) + .args(&["--kernel", kernel_path.to_str().unwrap()]) + .args(&["--cmdline", DIRECT_KERNEL_BOOT_CMDLINE]) + .capture_output() + .default_disks() + .default_net() + .args(&["--api-socket", &api_socket]); + + let child = cmd.spawn().unwrap(); + + let r = std::panic::catch_unwind(|| { + guest.wait_vm_boot(None).unwrap(); + assert!(remote_command(&api_socket, "power-button", None)); + }); + + let output = child.wait_with_output().unwrap(); + assert!(output.status.success()); + handle_child_output(r, &output); + } + type PrepareNetDaemon = dyn Fn(&TempDir, &str, Option<&str>, usize, bool) -> (std::process::Command, String); @@ -2289,30 +2326,13 @@ mod tests { #[test] fn test_power_button() { - let focal = UbuntuDiskConfig::new(FOCAL_IMAGE_NAME.to_string()); - let guest = Guest::new(Box::new(focal)); - let mut cmd = GuestCommand::new(&guest); - let api_socket = temp_api_path(&guest.tmp_dir); + _test_power_button(false); + } - cmd.args(&["--cpus", "boot=1"]) - .args(&["--memory", "size=512M"]) - .args(&["--kernel", direct_kernel_boot_path().to_str().unwrap()]) - .args(&["--cmdline", DIRECT_KERNEL_BOOT_CMDLINE]) - .capture_output() - .default_disks() - .default_net() - .args(&["--api-socket", &api_socket]); - - let child = cmd.spawn().unwrap(); - - let r = std::panic::catch_unwind(|| { - guest.wait_vm_boot(None).unwrap(); - assert!(remote_command(&api_socket, "power-button", None)); - }); - - let output = child.wait_with_output().unwrap(); - assert!(output.status.success()); - handle_child_output(r, &output); + #[test] + #[cfg(all(target_arch = "aarch64", feature = "acpi"))] + fn test_power_button_acpi_aarch64() { + _test_power_button(true); } #[test]