From 92f3f86669672c0799a89b4483d482d77f7cb555 Mon Sep 17 00:00:00 2001 From: Rob Bradford Date: Wed, 13 Jan 2021 10:20:03 +0000 Subject: [PATCH] tests: Add integration test for power button Signed-off-by: Rob Bradford --- tests/integration.rs | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/tests/integration.rs b/tests/integration.rs index 461d20cb0..512b77da5 100644 --- a/tests/integration.rs +++ b/tests/integration.rs @@ -2574,6 +2574,38 @@ mod tests { handle_child_output(r, &output); } + #[test] + #[cfg(target_arch = "x86_64")] + fn test_power_button() { + let mut focal = UbuntuDiskConfig::new(FOCAL_IMAGE_NAME.to_string()); + let guest = Guest::new(&mut focal); + let mut cmd = GuestCommand::new(&guest); + let api_socket = temp_api_path(&guest.tmp_dir); + + cmd.args(&["--cpus", "boot=1"]) + .args(&["--memory", "size=512M"]) + .args(&[ + "--kernel", + direct_kernel_boot_path().unwrap().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(target_arch = "x86_64")] fn test_user_defined_memory_regions() {