From 5a3d54fa1945b8c45122e1af33382c7337d869f0 Mon Sep 17 00:00:00 2001 From: Sebastien Boeuf Date: Tue, 15 Sep 2020 10:20:29 +0200 Subject: [PATCH] ci: Extend virtio-mem integration test with reboot Now that virtio-mem supports reboot, we extend the existing integration tests to validate the amount of RAM after reboot is the same as before the reboot, but also that we can still resize down the VM or the memory zone after the reboot. Signed-off-by: Sebastien Boeuf --- tests/integration.rs | 49 +++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 46 insertions(+), 3 deletions(-) diff --git a/tests/integration.rs b/tests/integration.rs index ae078cb62..acd8ec2d9 100644 --- a/tests/integration.rs +++ b/tests/integration.rs @@ -2323,7 +2323,7 @@ mod tests { } #[cfg(target_arch = "x86_64")] - #[test] + #[cfg_attr(not(feature = "mmio"), test)] fn test_user_defined_memory_regions() { let mut focal = UbuntuDiskConfig::new(FOCAL_IMAGE_NAME.to_string()); let guest = Guest::new(&mut focal); @@ -2376,6 +2376,28 @@ mod tests { resize_zone_command(&api_socket, "mem2", "2G"); thread::sleep(std::time::Duration::new(5, 0)); assert!(guest.get_total_memory().unwrap_or_default() > 4_800_000); + + guest.ssh_command("sudo reboot").unwrap(); + thread::sleep(std::time::Duration::new(30, 0)); + let reboot_count = guest + .ssh_command("sudo journalctl | grep -c -- \"-- Reboot --\"") + .unwrap_or_default() + .trim() + .parse::() + .unwrap_or_default(); + assert_eq!(reboot_count, 1); + + // Check the amount of RAM after reboot + assert!(guest.get_total_memory().unwrap_or_default() > 4_800_000); + assert!(guest.get_total_memory().unwrap_or_default() < 5_760_000); + + // Check if we can still resize down to the initial 'boot'size + resize_zone_command(&api_socket, "mem0", "1G"); + thread::sleep(std::time::Duration::new(5, 0)); + assert!(guest.get_total_memory().unwrap_or_default() < 4_800_000); + resize_zone_command(&api_socket, "mem2", "1G"); + thread::sleep(std::time::Duration::new(5, 0)); + assert!(guest.get_total_memory().unwrap_or_default() < 3_840_000); }); let _ = child.kill(); @@ -4416,8 +4438,8 @@ mod tests { handle_child_output(r, &output); } - #[test] #[cfg(target_arch = "x86_64")] + #[cfg_attr(not(feature = "mmio"), test)] fn test_virtio_mem() { let mut focal = UbuntuDiskConfig::new(FOCAL_IMAGE_NAME.to_string()); let guest = Guest::new(&mut focal); @@ -4467,13 +4489,34 @@ mod tests { thread::sleep(std::time::Duration::new(10, 0)); assert!(guest.get_total_memory().unwrap_or_default() > 1_920_000); - // Remove RAM to the VM + // Remove RAM from the VM let desired_ram = 1024 << 20; resize_command(&api_socket, None, Some(desired_ram), None); thread::sleep(std::time::Duration::new(10, 0)); assert!(guest.get_total_memory().unwrap_or_default() > 960_000); assert!(guest.get_total_memory().unwrap_or_default() < 1_920_000); + + guest.ssh_command("sudo reboot").unwrap(); + thread::sleep(std::time::Duration::new(30, 0)); + let reboot_count = guest + .ssh_command("sudo journalctl | grep -c -- \"-- Reboot --\"") + .unwrap_or_default() + .trim() + .parse::() + .unwrap_or_default(); + assert_eq!(reboot_count, 1); + + // Check the amount of memory after reboot is 1GiB + assert!(guest.get_total_memory().unwrap_or_default() > 960_000); + assert!(guest.get_total_memory().unwrap_or_default() < 1_920_000); + + // Check we can still resize to 512MiB + let desired_ram = 512 << 20; + resize_command(&api_socket, None, Some(desired_ram), None); + thread::sleep(std::time::Duration::new(10, 0)); + assert!(guest.get_total_memory().unwrap_or_default() > 480_000); + assert!(guest.get_total_memory().unwrap_or_default() < 960_000); }); let _ = child.kill();