virtio-devices: Test cap_len of sibling compound virtio PCI caps

Assert VirtioPciNotifyCap and VirtioPciCap64 size cap_len from
their own type. Catches a future regression of the same shape as
the VirtioPciCfgCap one in any of the sibling capabilities.

Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
This commit is contained in:
Anatol Belski
2026-05-16 15:48:55 +02:00
committed by Rob Bradford
parent b776c6d317
commit 2c86362674

View File

@@ -1458,4 +1458,19 @@ mod unit_tests {
assert_eq!(cap.cap.cfg_type, PciCapabilityType::Pci as u8);
assert_eq!(cap.cap.cfg_type, 5);
}
#[test]
fn compound_caps_size_cap_len_from_own_type() {
let notify = VirtioPciNotifyCap::new(PciCapabilityType::Notify, 0, 0, 0, Le32::from(0));
assert_eq!(
notify.cap.cap_len,
(size_of::<VirtioPciNotifyCap>() as u8) + VIRTIO_PCI_CAP_LEN_OFFSET
);
let cap64 = VirtioPciCap64::new(PciCapabilityType::SharedMemory, 0, 0, 0, 0);
assert_eq!(
cap64.cap.cap_len,
(size_of::<VirtioPciCap64>() as u8) + VIRTIO_PCI_CAP_LEN_OFFSET
);
}
}