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 <muislam@microsoft.com>
This commit is contained in:
Muminul Islam
2026-02-22 22:06:51 -08:00
committed by Rob Bradford
parent 9fd9c24419
commit fdc51d923f
2 changed files with 57 additions and 46 deletions

View File

@@ -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<String>,
}
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<serde_json::Value> {
@@ -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::<Vec<_>>(),
&event_path
));

View File

@@ -883,6 +883,28 @@ pub fn kill_child(child: &mut Child) {
}
}
#[derive(Debug)]
pub struct MetaEvent {
pub event: String,
pub device_id: Option<String>,
}
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<MetaEvent> {
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)]