From 365b94702317c1a67e4fa8dd01e93a7dd2876f87 Mon Sep 17 00:00:00 2001 From: Bo Chen Date: Wed, 2 Sep 2020 18:44:27 -0700 Subject: [PATCH] tests: Port test_simple_launch to the new methodology This is the last test to be ported to the new methodology. Signed-off-by: Bo Chen --- tests/integration.rs | 67 ++++++++++++++++++++------------------------ 1 file changed, 31 insertions(+), 36 deletions(-) diff --git a/tests/integration.rs b/tests/integration.rs index 2e03984b7..4b6c8faf0 100644 --- a/tests/integration.rs +++ b/tests/integration.rs @@ -5,9 +5,6 @@ #[cfg(test)] #[cfg(feature = "integration_tests")] -#[macro_use] -extern crate credibility; - #[cfg(test)] #[cfg(feature = "integration_tests")] #[macro_use] @@ -2153,44 +2150,42 @@ mod tests { #[cfg_attr(not(feature = "mmio"), test)] #[cfg(target_arch = "x86_64")] fn test_simple_launch() { - 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)); - aver_eq!(tb, guest.get_cpu_count().unwrap_or_default(), 1); - aver_eq!(tb, guest.get_initial_apicid().unwrap_or(1), 0); - aver!(tb, guest.get_total_memory().unwrap_or_default() > 480_000); - aver!(tb, guest.get_entropy().unwrap_or_default() >= 900); - aver_eq!( - tb, - guest.get_pci_bridge_class().unwrap_or_default(), - "0x060000" - ); - - let _ = child.kill(); - let _ = child.wait(); + let r = std::panic::catch_unwind(|| { + assert_eq!(guest.get_cpu_count().unwrap_or_default(), 1); + assert_eq!(guest.get_initial_apicid().unwrap_or(1), 0); + assert!(guest.get_total_memory().unwrap_or_default() > 480_000); + assert!(guest.get_entropy().unwrap_or_default() >= 900); + assert_eq!(guest.get_pci_bridge_class().unwrap_or_default(), "0x060000"); }); - Ok(()) + + let _ = child.kill(); + let output = child.wait_with_output().unwrap(); + + handle_child_output(r, &output); }); }