Skip to content

Commit fd5662b

Browse files
JBYoshiJonathanWoollett-Light
authored andcommitted
[Test code] Update types for (in)equality checks
For equalities and inequalities, we can change the types on each side to always convert to the larger type, which ensures all conversions are safe. Signed-off-by: Jonathan Browne <[email protected]>
1 parent 9296de5 commit fd5662b

File tree

3 files changed

+21
-16
lines changed

3 files changed

+21
-16
lines changed

src/snapshot-editor/src/edit_memory.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,8 @@ mod tests {
114114

115115
fn check_file_content(file: &File, expected_content: &[u8]) {
116116
assert_eq!(
117-
file.metadata().unwrap().len() as usize,
118-
expected_content.len()
117+
file.metadata().unwrap().len(),
118+
expected_content.len() as u64
119119
);
120120
let mut buf = vec![0u8; expected_content.len()];
121121
file.read_exact_at(buf.as_mut_slice(), 0).unwrap();

src/vmm/src/devices/virtio/block/device.rs

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -836,8 +836,8 @@ mod tests {
836836
let status_addr = GuestAddress(vq.dtable[2].addr.get());
837837
assert_eq!(used.len, 1);
838838
assert_eq!(
839-
mem.read_obj::<u8>(status_addr).unwrap(),
840-
VIRTIO_BLK_S_IOERR as u8
839+
u32::from(mem.read_obj::<u8>(status_addr).unwrap()),
840+
VIRTIO_BLK_S_IOERR
841841
);
842842
}
843843

@@ -861,8 +861,8 @@ mod tests {
861861
let status_addr = GuestAddress(vq.dtable[2].addr.get());
862862
assert_eq!(used.len, 1);
863863
assert_eq!(
864-
mem.read_obj::<u8>(status_addr).unwrap(),
865-
VIRTIO_BLK_S_IOERR as u8
864+
u32::from(mem.read_obj::<u8>(status_addr).unwrap()),
865+
VIRTIO_BLK_S_IOERR
866866
);
867867
}
868868
}
@@ -1048,8 +1048,8 @@ mod tests {
10481048

10491049
let status_addr = GuestAddress(vq.dtable[2].addr.get());
10501050
assert_eq!(
1051-
mem.read_obj::<u8>(status_addr).unwrap(),
1052-
VIRTIO_BLK_S_IOERR as u8
1051+
u32::from(mem.read_obj::<u8>(status_addr).unwrap()),
1052+
VIRTIO_BLK_S_IOERR
10531053
);
10541054
}
10551055

@@ -1270,8 +1270,8 @@ mod tests {
12701270

12711271
let status_addr = GuestAddress(vq.dtable[2].addr.get());
12721272
assert_eq!(
1273-
mem.read_obj::<u8>(status_addr).unwrap(),
1274-
VIRTIO_BLK_S_IOERR as u8
1273+
u32::from(mem.read_obj::<u8>(status_addr).unwrap()),
1274+
VIRTIO_BLK_S_IOERR
12751275
);
12761276
}
12771277
}
@@ -1431,10 +1431,12 @@ mod tests {
14311431
let status_addr = vq.dtable[used.id as usize + 1].addr.get();
14321432
assert_eq!(used.len, 1);
14331433
assert_eq!(
1434-
vq.memory()
1435-
.read_obj::<u8>(GuestAddress(status_addr))
1436-
.unwrap(),
1437-
VIRTIO_BLK_S_OK as u8
1434+
u32::from(
1435+
vq.memory()
1436+
.read_obj::<u8>(GuestAddress(status_addr))
1437+
.unwrap(),
1438+
),
1439+
VIRTIO_BLK_S_OK
14381440
);
14391441
}
14401442
}

src/vmm/src/devices/virtio/vsock/csm/connection.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1171,7 +1171,10 @@ mod tests {
11711171
assert!(ctx.conn.has_pending_rx());
11721172
ctx.recv();
11731173
assert_eq!(ctx.pkt.op(), uapi::VSOCK_OP_CREDIT_UPDATE);
1174-
assert_eq!(ctx.pkt.fwd_cnt(), initial_fwd_cnt + data.len() as u32 * 2);
1174+
assert_eq!(
1175+
ctx.pkt.fwd_cnt() as usize,
1176+
initial_fwd_cnt as usize + data.len() * 2,
1177+
);
11751178
assert_eq!(ctx.conn.fwd_cnt, ctx.conn.last_fwd_cnt_to_peer);
11761179
}
11771180

@@ -1264,7 +1267,7 @@ mod tests {
12641267
// Fill up the TX buffer.
12651268
let data = vec![0u8; ctx.pkt.buf_size()];
12661269
ctx.init_data_pkt(data.as_slice());
1267-
for _i in 0..(csm_defs::CONN_TX_BUF_SIZE / data.len() as u32) {
1270+
for _i in 0..(csm_defs::CONN_TX_BUF_SIZE as usize / data.len()) {
12681271
ctx.send();
12691272
}
12701273

0 commit comments

Comments
 (0)