From 99353856efe010023f1055314201e9ed8f8e7de9 Mon Sep 17 00:00:00 2001 From: Yi Wang Date: Thu, 15 Jun 2023 21:00:57 +0800 Subject: [PATCH] tests: Add integration test for pvpanic Add integration test for pvpanic, by two methods: - the vendor id and device id of pci device in guest - triggering a guest panic and check event-monitor. Also, to support pvpanic-pci driver, add pvpanic config in resources. Signed-off-by: Yi Wang Signed-off-by: Rob Bradford --- resources/linux-config-aarch64 | 3 +- resources/linux-config-x86_64 | 3 +- tests/integration.rs | 58 ++++++++++++++++++++++++++++++++++ 3 files changed, 62 insertions(+), 2 deletions(-) diff --git a/resources/linux-config-aarch64 b/resources/linux-config-aarch64 index 91a3ed295..6ae6d96e2 100644 --- a/resources/linux-config-aarch64 +++ b/resources/linux-config-aarch64 @@ -1402,7 +1402,8 @@ CONFIG_NVME_MULTIPATH=y # CONFIG_MISC_RTSX_PCI is not set # CONFIG_HABANA_AI is not set # CONFIG_UACCE is not set -# CONFIG_PVPANIC is not set +CONFIG_PVPANIC=y +CONFIG_PVPANIC_PCI=y # CONFIG_GP_PCI1XXXX is not set # end of Misc devices diff --git a/resources/linux-config-x86_64 b/resources/linux-config-x86_64 index 9d4d066c3..fe2fa93b8 100644 --- a/resources/linux-config-x86_64 +++ b/resources/linux-config-x86_64 @@ -1378,7 +1378,8 @@ CONFIG_NVME_MULTIPATH=y # CONFIG_MISC_RTSX_PCI is not set # CONFIG_HABANA_AI is not set # CONFIG_UACCE is not set -# CONFIG_PVPANIC is not set +CONFIG_PVPANIC=y +CONFIG_PVPANIC_PCI=y # CONFIG_GP_PCI1XXXX is not set # end of Misc devices diff --git a/tests/integration.rs b/tests/integration.rs index a180acbf7..18ead1135 100644 --- a/tests/integration.rs +++ b/tests/integration.rs @@ -2225,6 +2225,16 @@ fn enable_guest_watchdog(guest: &Guest, watchdog_sec: u32) { .unwrap(); } +fn make_guest_panic(guest: &Guest) { + // Check for pvpanic device + assert!(guest + .does_device_vendor_pair_match("0x0011", "0x1b36") + .unwrap_or_default()); + + // Trigger guest a panic + guest.ssh_command("screen -dmS reboot sh -c \"sleep 5; echo s | tee /proc/sysrq-trigger; echo c | sudo tee /proc/sysrq-trigger\"").unwrap(); +} + mod common_parallel { use std::{fs::OpenOptions, io::SeekFrom}; @@ -6131,6 +6141,54 @@ mod common_parallel { handle_child_output(r, &output); } + #[test] + fn test_pvpanic() { + let jammy = UbuntuDiskConfig::new(JAMMY_IMAGE_NAME.to_string()); + let guest = Guest::new(Box::new(jammy)); + let api_socket = temp_api_path(&guest.tmp_dir); + let event_path = temp_event_monitor_path(&guest.tmp_dir); + + let kernel_path = direct_kernel_boot_path(); + + let mut cmd = GuestCommand::new(&guest); + cmd.args(["--cpus", "boot=1"]) + .args(["--memory", "size=512M"]) + .args(["--kernel", kernel_path.to_str().unwrap()]) + .args(["--cmdline", DIRECT_KERNEL_BOOT_CMDLINE]) + .default_disks() + .args(["--net", guest.default_net_string().as_str()]) + .args(["--pvpanic"]) + .args(["--api-socket", &api_socket]) + .args(["--event-monitor", format!("path={event_path}").as_str()]) + .capture_output(); + + let mut child = cmd.spawn().unwrap(); + + let r = std::panic::catch_unwind(|| { + guest.wait_vm_boot(None).unwrap(); + + // Trigger guest a panic + make_guest_panic(&guest); + + // Wait a while for guest + thread::sleep(std::time::Duration::new(10, 0)); + + let expected_sequential_events = [&MetaEvent { + event: "panic".to_string(), + device_id: None, + }]; + assert!(check_latest_events_exact( + &expected_sequential_events, + &event_path + )); + }); + + let _ = child.kill(); + let output = child.wait_with_output().unwrap(); + + handle_child_output(r, &output); + } + #[test] fn test_tap_from_fd() { let focal = UbuntuDiskConfig::new(FOCAL_IMAGE_NAME.to_string());