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 <anbelski@linux.microsoft.com>
This commit is contained in:
Anatol Belski
2026-05-16 15:47:07 +02:00
committed by Rob Bradford
parent b4dea599a3
commit e7d394e286

View File

@@ -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::<VirtioPciCfgCap>() as u8) + VIRTIO_PCI_CAP_LEN_OFFSET;
assert_eq!(cap.cap.cap_len, expected);
assert_eq!(cap.cap.cap_len, 20);
}
}