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 <rbradford@meta.com>
This commit is contained in:
Rob Bradford
2026-03-04 02:22:14 -08:00
parent f57b7c5b86
commit 67945b31e5

View File

@@ -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());