Skip to content

Commit c49e72e

Browse files
authored
Fix broken test_udp_recvmsg_multishot_trunc test (#284)
* Fix broken test_udp_recvmsg_multishot_trunc test Signed-off-by: Alex Saveau <[email protected]> * Add some hacks Signed-off-by: Alex Saveau <[email protected]> --------- Signed-off-by: Alex Saveau <[email protected]>
1 parent b29e815 commit c49e72e

File tree

1 file changed

+18
-17
lines changed

1 file changed

+18
-17
lines changed

io-uring-test/src/tests/net.rs

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1447,7 +1447,6 @@ pub fn test_udp_recvmsg_multishot_trunc<S: squeue::EntryMarker, C: cqueue::Entry
14471447
test.probe.is_supported(opcode::RecvMsgMulti::CODE);
14481448
test.probe.is_supported(opcode::ProvideBuffers::CODE);
14491449
test.probe.is_supported(opcode::SendMsg::CODE);
1450-
test.check_kernel_version("6.6.0" /* 6.2 is totally broken and returns nonsense upon truncation */);
14511450
);
14521451

14531452
println!("test udp_recvmsg_multishot_trunc");
@@ -1459,15 +1458,10 @@ pub fn test_udp_recvmsg_multishot_trunc<S: squeue::EntryMarker, C: cqueue::Entry
14591458
const DATA: &[u8] = b"testfooo for me";
14601459
let mut buf1 = [0u8; 20]; // 20 = size_of::<io_uring_recvmsg_out>() + msghdr.msg_namelen
14611460
let mut buf2 = [0u8; 20 + DATA.len()];
1462-
let mut buf3 = [0u8; 20 + DATA.len()];
1463-
let mut buffers = [
1464-
buf1.as_mut_slice(),
1465-
buf2.as_mut_slice(),
1466-
buf3.as_mut_slice(),
1467-
];
1461+
let mut buffers = [buf1.as_mut_slice(), buf2.as_mut_slice()];
14681462

14691463
for (index, buf) in buffers.iter_mut().enumerate() {
1470-
let provide_bufs_e = io_uring::opcode::ProvideBuffers::new(
1464+
let provide_bufs_e = opcode::ProvideBuffers::new(
14711465
(**buf).as_mut_ptr(),
14721466
buf.len() as i32,
14731467
1,
@@ -1479,7 +1473,7 @@ pub fn test_udp_recvmsg_multishot_trunc<S: squeue::EntryMarker, C: cqueue::Entry
14791473
.into();
14801474
unsafe { ring.submission().push(&provide_bufs_e)? };
14811475
ring.submitter().submit_and_wait(1)?;
1482-
let cqes: Vec<io_uring::cqueue::Entry> = ring.completion().map(Into::into).collect();
1476+
let cqes: Vec<cqueue::Entry> = ring.completion().map(Into::into).collect();
14831477
assert_eq!(cqes.len(), 1);
14841478
assert_eq!(cqes[0].user_data(), 11);
14851479
assert_eq!(cqes[0].result(), 0);
@@ -1488,7 +1482,7 @@ pub fn test_udp_recvmsg_multishot_trunc<S: squeue::EntryMarker, C: cqueue::Entry
14881482

14891483
// This structure is actually only used for input arguments to the kernel
14901484
// (and only name length and control length are actually relevant).
1491-
let mut msghdr: libc::msghdr = unsafe { std::mem::zeroed() };
1485+
let mut msghdr: libc::msghdr = unsafe { mem::zeroed() };
14921486
msghdr.msg_namelen = 4;
14931487

14941488
let recvmsg_e = opcode::RecvMsgMulti::new(
@@ -1524,11 +1518,12 @@ pub fn test_udp_recvmsg_multishot_trunc<S: squeue::EntryMarker, C: cqueue::Entry
15241518
ring.submitter().submit().unwrap();
15251519

15261520
ring.submitter().submit_and_wait(4).unwrap();
1527-
let cqes: Vec<io_uring::cqueue::Entry> = ring.completion().map(Into::into).collect();
1528-
assert_eq!(cqes.len(), 4);
1529-
let mut i = 0;
1521+
let cqes: Vec<cqueue::Entry> = ring.completion().map(Into::into).collect();
1522+
assert!([4, 5].contains(&cqes.len()));
1523+
1524+
let mut processed_responses = 0;
15301525
for cqe in cqes {
1531-
let is_more = io_uring::cqueue::more(cqe.flags());
1526+
let is_more = cqueue::more(cqe.flags());
15321527
match cqe.user_data() {
15331528
// send notifications
15341529
55 => {
@@ -1537,13 +1532,18 @@ pub fn test_udp_recvmsg_multishot_trunc<S: squeue::EntryMarker, C: cqueue::Entry
15371532
}
15381533
// RecvMsgMulti
15391534
77 => {
1535+
if cqe.result() == -105 {
1536+
// Ran out of buffers
1537+
continue;
1538+
}
1539+
15401540
assert!(cqe.result() > 0);
15411541
assert!(is_more);
1542-
let buf_id = io_uring::cqueue::buffer_select(cqe.flags()).unwrap();
1542+
let buf_id = cqueue::buffer_select(cqe.flags()).unwrap() % buffers.len() as u16;
15431543
let tmp_buf = &buffers[buf_id as usize];
15441544
let msg = types::RecvMsgOut::parse(tmp_buf, &msghdr);
15451545

1546-
match i {
1546+
match buf_id {
15471547
0 => {
15481548
let msg = msg.unwrap();
15491549
assert!(msg.is_payload_truncated());
@@ -1564,13 +1564,14 @@ pub fn test_udp_recvmsg_multishot_trunc<S: squeue::EntryMarker, C: cqueue::Entry
15641564
}
15651565
_ => unreachable!(),
15661566
}
1567-
i += 1;
1567+
processed_responses += 1;
15681568
}
15691569
_ => {
15701570
unreachable!()
15711571
}
15721572
}
15731573
}
1574+
assert_eq!(processed_responses, 2);
15741575

15751576
Ok(())
15761577
}

0 commit comments

Comments
 (0)