MCPcopy Create free account
hub / github.com/cloud-hypervisor/cloud-hypervisor / test_virtio_mem

Function test_virtio_mem

cloud-hypervisor/tests/integration.rs:2858–2931  ·  view source on GitHub ↗

See #7456

()

Source from the content-addressed store, hash-verified

2856 #[test]
2857 #[cfg(not(feature = "mshv"))] // See #7456
2858 fn test_virtio_mem() {
2859 let disk_config = UbuntuDiskConfig::new(JAMMY_IMAGE_NAME.to_string());
2860 let guest = Guest::new(Box::new(disk_config));
2861 let api_socket = temp_api_path(&guest.tmp_dir);
2862
2863 let kernel_path = direct_kernel_boot_path();
2864
2865 let mut child = GuestCommand::new(&guest)
2866 .args(["--cpus", "boot=2,max=4"])
2867 .args([
2868 "--memory",
2869 "size=512M,hotplug_method=virtio-mem,hotplug_size=8192M",
2870 ])
2871 .args(["--kernel", kernel_path.to_str().unwrap()])
2872 .args(["--cmdline", DIRECT_KERNEL_BOOT_CMDLINE])
2873 .default_disks()
2874 .default_net()
2875 .args(["--api-socket", &api_socket])
2876 .capture_output()
2877 .spawn()
2878 .unwrap();
2879
2880 let r = std::panic::catch_unwind(|| {
2881 guest.wait_vm_boot().unwrap();
2882
2883 assert!(guest.get_total_memory().unwrap_or_default() > 480_000);
2884
2885 guest.enable_memory_hotplug();
2886
2887 // Add RAM to the VM
2888 let desired_ram = 1024 << 20;
2889 resize_command(&api_socket, None, Some(desired_ram), None, None);
2890
2891 assert!(wait_until(Duration::from_secs(10), || {
2892 guest.get_total_memory().unwrap_or_default() > 960_000
2893 }));
2894
2895 // Add RAM to the VM
2896 let desired_ram = 2048 << 20;
2897 resize_command(&api_socket, None, Some(desired_ram), None, None);
2898
2899 assert!(wait_until(Duration::from_secs(10), || {
2900 guest.get_total_memory().unwrap_or_default() > 1_920_000
2901 }));
2902
2903 // Remove RAM from the VM
2904 let desired_ram = 1024 << 20;
2905 resize_command(&api_socket, None, Some(desired_ram), None, None);
2906
2907 assert!(wait_until(Duration::from_secs(10), || {
2908 let total_memory = guest.get_total_memory().unwrap_or_default();
2909 total_memory > 960_000 && total_memory < 1_920_000
2910 }));
2911
2912 guest.reboot_linux(0);
2913
2914 // Check the amount of memory after reboot is 1GiB
2915 assert!(guest.get_total_memory().unwrap_or_default() > 960_000);

Callers

nothing calls this directly

Calls 14

newFunction · 0.85
temp_api_pathFunction · 0.85
direct_kernel_boot_pathFunction · 0.85
resize_commandFunction · 0.85
kill_childFunction · 0.85
handle_child_outputFunction · 0.85
spawnMethod · 0.80
capture_outputMethod · 0.80
argsMethod · 0.80
default_netMethod · 0.80
default_disksMethod · 0.80
wait_vm_bootMethod · 0.80

Tested by

no test coverage detected