From 2c8636267452dc9278be32bb454fe174860aed0e Mon Sep 17 00:00:00 2001 From: Anatol Belski Date: Sat, 16 May 2026 15:48:55 +0200 Subject: [PATCH] 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 --- virtio-devices/src/transport/pci_device.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/virtio-devices/src/transport/pci_device.rs b/virtio-devices/src/transport/pci_device.rs index 4b8fe3dbf..87b2a9d9f 100644 --- a/virtio-devices/src/transport/pci_device.rs +++ b/virtio-devices/src/transport/pci_device.rs @@ -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::() 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::() as u8) + VIRTIO_PCI_CAP_LEN_OFFSET + ); + } }