From fdc51d923f3a389202a625a288bccbb7cd3ded9b Mon Sep 17 00:00:00 2001 From: Muminul Islam Date: Sun, 22 Feb 2026 22:06:51 -0800 Subject: [PATCH] tests: refactor event sequencing expectations for simple launch Move MetaEvent from the integration test into shared test infrastructure and expose it for reuse. Add a Guest helper that returns the expected sequential events for simple launch, and update the integration test to consume this helper instead of maintaining a local event list. Adjust expected behavior for confidential VMs by omitting the disk reset event, which is not guaranteed to be emitted in that mode. Preserve the existing expected sequence for non-confidential VMs. Signed-off-by: Muminul Islam --- cloud-hypervisor/tests/integration.rs | 50 ++----------------------- test_infra/src/lib.rs | 53 +++++++++++++++++++++++++++ 2 files changed, 57 insertions(+), 46 deletions(-) diff --git a/cloud-hypervisor/tests/integration.rs b/cloud-hypervisor/tests/integration.rs index 99a22f273..c836f631d 100644 --- a/cloud-hypervisor/tests/integration.rs +++ b/cloud-hypervisor/tests/integration.rs @@ -889,28 +889,6 @@ fn fw_path(_fw_type: FwType) -> String { fw_path.to_str().unwrap().to_string() } -#[derive(Debug)] -struct MetaEvent { - event: String, - device_id: Option, -} - -impl MetaEvent { - pub fn match_with_json_event(&self, v: &serde_json::Value) -> bool { - let mut matched = false; - if v["event"].as_str().unwrap() == self.event { - if let Some(device_id) = &self.device_id { - if v["properties"]["id"].as_str().unwrap() == device_id { - matched = true; - } - } else { - matched = true; - } - } - matched - } -} - // Parse the event_monitor file based on the format that each event // is followed by a double newline fn parse_event_file(event_file: &str) -> Vec { @@ -2584,31 +2562,11 @@ fn _test_simple_launch(guest: &Guest) { assert_eq!(guest.get_cpu_count().unwrap_or_default(), 1); assert!(guest.get_total_memory().unwrap_or_default() > 480_000); assert_eq!(guest.get_pci_bridge_class().unwrap_or_default(), "0x060000"); - - let expected_sequential_events = [ - &MetaEvent { - event: "starting".to_string(), - device_id: None, - }, - &MetaEvent { - event: "booting".to_string(), - device_id: None, - }, - &MetaEvent { - event: "booted".to_string(), - device_id: None, - }, - &MetaEvent { - event: "activated".to_string(), - device_id: Some("_disk0".to_string()), - }, - &MetaEvent { - event: "reset".to_string(), - device_id: Some("_disk0".to_string()), - }, - ]; assert!(check_sequential_events( - &expected_sequential_events, + &guest + .get_expected_seq_events_for_simple_launch() + .iter() + .collect::>(), &event_path )); diff --git a/test_infra/src/lib.rs b/test_infra/src/lib.rs index 2848a130e..cab400082 100644 --- a/test_infra/src/lib.rs +++ b/test_infra/src/lib.rs @@ -883,6 +883,28 @@ pub fn kill_child(child: &mut Child) { } } +#[derive(Debug)] +pub struct MetaEvent { + pub event: String, + pub device_id: Option, +} + +impl MetaEvent { + pub fn match_with_json_event(&self, v: &serde_json::Value) -> bool { + let mut matched = false; + if v["event"].as_str().unwrap() == self.event { + if let Some(device_id) = &self.device_id { + if v["properties"]["id"].as_str().unwrap() == device_id { + matched = true; + } + } else { + matched = true; + } + } + matched + } +} + pub const PIPE_SIZE: i32 = 32 << 20; pub struct Guest { @@ -1320,6 +1342,37 @@ impl Guest { assert_eq!(self.ssh_command("sudo umount /mnt").unwrap(), ""); } } + + pub fn get_expected_seq_events_for_simple_launch(&self) -> Vec { + let mut out_evt = vec![ + MetaEvent { + event: "starting".to_string(), + device_id: None, + }, + MetaEvent { + event: "booting".to_string(), + device_id: None, + }, + MetaEvent { + event: "booted".to_string(), + device_id: None, + }, + MetaEvent { + event: "activated".to_string(), + device_id: Some("_disk0".to_string()), + }, + ]; + // For confidential VM, reset of the device does not trigger a VMM exit, or + // It is handled in the PSP + // so we won't receive the "reset" event for disk0. + if self.vm_type != GuestVmType::Confidential { + out_evt.push(MetaEvent { + event: "reset".to_string(), + device_id: Some("_disk0".to_string()), + }); + } + out_evt + } } #[derive(Default)]