virtio-devices: Test PCI CFG data_len as access bound

Verify that bar_access_params uses data_len when it is smaller than
cap.length.

Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
This commit is contained in:
Anatol Belski
2026-05-23 16:10:13 +02:00
committed by Rob Bradford
parent 28aa81e66b
commit d0634d18d9

View File

@@ -1501,4 +1501,18 @@ mod unit_tests {
assert_eq!(bar_offset, 0x14);
assert_eq!(access_len, 1);
}
#[test]
fn bar_access_params_uses_data_len_when_smaller() {
let mut cap = VirtioPciCfgCap::new();
let slice = cap.as_mut_slice();
// cap.length = 4, but caller provides only 2 bytes
slice[6..10].copy_from_slice(&0x00u32.to_le_bytes());
slice[10..14].copy_from_slice(&4u32.to_le_bytes());
let (bar_offset, access_len) = cap.bar_access_params(2);
assert_eq!(bar_offset, 0);
assert_eq!(access_len, 2);
}
}