Skip to content

Commit a38c2a4

Browse files
JBYoshiJonathanWoollett-Light
authored andcommitted
[Test code] ARM64: Add try_from()/unwrap() in test
Some places in the code don't allow us to re-type values to let the compiler verify that those conversions are safe, particularly with length values. Since these are for test code, I don't expect overflows to happen, so I've just inserted unwraps here. I've done this in a separate commit because my dev setup doesn't use ARM. In case something ARM-specific breaks in CI, I'd like to be able to keep those changes in their own commits so I can debug more easily. Signed-off-by: Jonathan Browne <[email protected]>
1 parent 970495a commit a38c2a4

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

src/vmm/src/arch/aarch64/fdt.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,7 @@ mod tests {
449449
}
450450
// The `load` function from the `device_tree` will mistakenly check the actual size
451451
// of the buffer with the allocated size. This works around that.
452-
fn set_size(buf: &mut [u8], pos: usize, val: usize) {
452+
fn set_size(buf: &mut [u8], pos: usize, val: u32) {
453453
buf[pos] = ((val >> 24) & 0xff) as u8;
454454
buf[pos + 1] = ((val >> 16) & 0xff) as u8;
455455
buf[pos + 2] = ((val >> 8) & 0xff) as u8;
@@ -541,7 +541,7 @@ mod tests {
541541
// }
542542

543543
let pos = 4;
544-
let val = layout::FDT_MAX_SIZE;
544+
let val = u32::try_from(layout::FDT_MAX_SIZE).unwrap();
545545
let mut buf = vec![];
546546
buf.extend_from_slice(saved_dtb_bytes);
547547

@@ -604,7 +604,7 @@ mod tests {
604604
// }
605605

606606
let pos = 4;
607-
let val = layout::FDT_MAX_SIZE;
607+
let val = u32::try_from(layout::FDT_MAX_SIZE).unwrap();
608608
let mut buf = vec![];
609609
buf.extend_from_slice(saved_dtb_bytes);
610610

src/vmm/src/arch/aarch64/regs.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -779,7 +779,7 @@ mod tests {
779779
let bytes = 69_u64.to_le_bytes();
780780
let reg_ref = Aarch64RegisterRef::new(KVM_REG_SIZE_U64, &bytes);
781781

782-
assert_eq!(reg_ref.size(), 8);
782+
assert_eq!(usize::from(reg_ref.size()), 8);
783783
assert_eq!(reg_ref.value::<u64, 8>(), 69);
784784
}
785785

@@ -808,7 +808,7 @@ mod tests {
808808
let mut bytes = 69_u64.to_le_bytes();
809809
let mut reg_ref = Aarch64RegisterRefMut::new(KVM_REG_SIZE_U64, &mut bytes);
810810

811-
assert_eq!(reg_ref.size(), 8);
811+
assert_eq!(usize::from(reg_ref.size()), 8);
812812
assert_eq!(reg_ref.value::<u64, 8>(), 69);
813813
reg_ref.set_value(reg_ref.value::<u64, 8>() + 1);
814814
assert_eq!(reg_ref.value::<u64, 8>(), 70);

0 commit comments

Comments
 (0)