From cb2f11724aadf24f3320b5c298745dab11669f14 Mon Sep 17 00:00:00 2001 From: Bo Chen Date: Wed, 2 Sep 2020 17:04:01 -0700 Subject: [PATCH] tests: Port test_reboot to the new methodology Signed-off-by: Bo Chen --- tests/integration.rs | 66 ++++++++++++++++++++++++-------------------- 1 file changed, 36 insertions(+), 30 deletions(-) diff --git a/tests/integration.rs b/tests/integration.rs index 145570068..2e03984b7 100644 --- a/tests/integration.rs +++ b/tests/integration.rs @@ -3775,30 +3775,31 @@ mod tests { #[cfg_attr(not(feature = "mmio"), test)] #[cfg(target_arch = "x86_64")] fn test_reboot() { - test_block!(tb, "", { - let mut bionic = UbuntuDiskConfig::new(BIONIC_IMAGE_NAME.to_string()); - let mut focal = UbuntuDiskConfig::new(FOCAL_IMAGE_NAME.to_string()); + let mut bionic = UbuntuDiskConfig::new(BIONIC_IMAGE_NAME.to_string()); + let mut focal = UbuntuDiskConfig::new(FOCAL_IMAGE_NAME.to_string()); - vec![ - &mut bionic as &mut dyn DiskConfig, - &mut focal as &mut dyn DiskConfig, - ] - .iter_mut() - .for_each(|disk_config| { - let guest = Guest::new(*disk_config); + vec![ + &mut bionic as &mut dyn DiskConfig, + &mut focal as &mut dyn DiskConfig, + ] + .iter_mut() + .for_each(|disk_config| { + let guest = Guest::new(*disk_config); - let mut child = GuestCommand::new(&guest) - .args(&["--cpus", "boot=1"]) - .args(&["--memory", "size=512M"]) - .args(&["--kernel", guest.fw_path.as_str()]) - .default_raw_disks() - .default_net() - .args(&["--serial", "tty", "--console", "off"]) - .spawn() - .unwrap(); + let mut child = GuestCommand::new(&guest) + .args(&["--cpus", "boot=1"]) + .args(&["--memory", "size=512M"]) + .args(&["--kernel", guest.fw_path.as_str()]) + .default_raw_disks() + .default_net() + .args(&["--serial", "tty", "--console", "off"]) + .capture_output() + .spawn() + .unwrap(); - thread::sleep(std::time::Duration::new(20, 0)); + thread::sleep(std::time::Duration::new(20, 0)); + let r = std::panic::catch_unwind(|| { let reboot_count = guest .ssh_command("sudo journalctl | grep -c -- \"-- Reboot --\"") .unwrap_or_default() @@ -3807,7 +3808,7 @@ mod tests { .unwrap_or(1); let fd_count_1 = get_fd_count(child.id()); - aver_eq!(tb, reboot_count, 0); + assert_eq!(reboot_count, 0); guest.ssh_command("sudo reboot").unwrap_or_default(); thread::sleep(std::time::Duration::new(20, 0)); @@ -3818,20 +3819,25 @@ mod tests { .parse::() .unwrap_or_default(); let fd_count_2 = get_fd_count(child.id()); - aver_eq!(tb, reboot_count, 1); - aver_eq!(tb, fd_count_1, fd_count_2); + assert_eq!(reboot_count, 1); + assert_eq!(fd_count_1, fd_count_2); guest .ssh_command("sudo shutdown -h now") .unwrap_or_default(); - - // Check that the cloud-hypervisor binary actually terminated - if let Ok(status) = child.wait() { - aver_eq!(tb, status.success(), true); - } - let _ = child.wait(); + thread::sleep(std::time::Duration::new(20, 0)); }); - Ok(()) + + let _ = child.kill(); + let output = child.wait_with_output().unwrap(); + handle_child_output(r, &output); + + let r = std::panic::catch_unwind(|| { + // Check that the cloud-hypervisor binary actually terminated + assert_eq!(output.status.success(), true); + }); + + handle_child_output(r, &output); }); }