From e7d394e286e2c156abd38031edd7535c2ebeeb38 Mon Sep 17 00:00:00 2001 From: Anatol Belski Date: Sat, 16 May 2026 15:47:07 +0200 Subject: [PATCH] virtio-devices: Test cap_len of VIRTIO_PCI_CAP_PCI_CFG Regression test for the cap_len fix. The emitted VirtioPciCfgCap must report cap_len 20, covering the trailing pci_cfg_data window per virtio 1.2 section 4.1.4.9. Signed-off-by: Anatol Belski --- virtio-devices/src/transport/pci_device.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/virtio-devices/src/transport/pci_device.rs b/virtio-devices/src/transport/pci_device.rs index c01955c38..a41a935d6 100644 --- a/virtio-devices/src/transport/pci_device.rs +++ b/virtio-devices/src/transport/pci_device.rs @@ -1443,4 +1443,12 @@ mod unit_tests { intr.trigger(VirtioInterruptType::Queue(0)).unwrap(); assert!(!intr.config_changed.load(Ordering::Acquire)); } + + #[test] + fn pci_cfg_cap_len_includes_data_window() { + let cap = VirtioPciCfgCap::new(); + let expected = (size_of::() as u8) + VIRTIO_PCI_CAP_LEN_OFFSET; + assert_eq!(cap.cap.cap_len, expected); + assert_eq!(cap.cap.cap_len, 20); + } }