From 67945b31e5fff04571c2d961c39d2bfefef952b8 Mon Sep 17 00:00:00 2001 From: Rob Bradford Date: Wed, 4 Mar 2026 02:22:14 -0800 Subject: [PATCH] tests: Add integration test for nested virtualization Since we run integration tests on Intel & AMD this should test the behaviour of `--cpus nested={on|off}` correctly. Signed-off-by: Rob Bradford --- cloud-hypervisor/tests/integration.rs | 45 +++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/cloud-hypervisor/tests/integration.rs b/cloud-hypervisor/tests/integration.rs index d9874d2e7..96963bc4e 100644 --- a/cloud-hypervisor/tests/integration.rs +++ b/cloud-hypervisor/tests/integration.rs @@ -2616,6 +2616,51 @@ mod common_parallel { handle_child_output(r, &output); } + fn _test_nested_virtualization(nested: bool) { + let disk_config = UbuntuDiskConfig::new(JAMMY_IMAGE_NAME.to_string()); + let guest = Guest::new(Box::new(disk_config)).with_nested(nested); + let mut child = GuestCommand::new(&guest) + .default_cpus() + .default_memory() + .args(["--kernel", direct_kernel_boot_path().to_str().unwrap()]) + .args(["--cmdline", DIRECT_KERNEL_BOOT_CMDLINE]) + .default_disks() + .default_net() + .capture_output() + .spawn() + .unwrap(); + + let r = std::panic::catch_unwind(|| { + guest.wait_vm_boot().unwrap(); + + let expected = if nested { "yes" } else { "no" }; + assert_eq!( + guest + .ssh_command("test -c /dev/kvm && echo yes || echo no") + .unwrap() + .trim(), + expected + ); + }); + + kill_child(&mut child); + let output = child.wait_with_output().unwrap(); + + handle_child_output(r, &output); + } + + #[test] + #[cfg(target_arch = "x86_64")] + fn test_nested_virtualization_on() { + _test_nested_virtualization(true); + } + + #[test] + #[cfg(target_arch = "x86_64")] + fn test_nested_virtualization_off() { + _test_nested_virtualization(false); + } + #[test] fn test_cpu_affinity() { let disk_config = UbuntuDiskConfig::new(JAMMY_IMAGE_NAME.to_string());