mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2026-08-05 02:19:16 +00:00
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:
committed by
Rob Bradford
parent
28aa81e66b
commit
d0634d18d9
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user