Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix broken test_udp_recvmsg_multishot_trunc test #284

Merged
merged 2 commits into from
May 9, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 18 additions & 17 deletions io-uring-test/src/tests/net.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1447,7 +1447,6 @@ pub fn test_udp_recvmsg_multishot_trunc<S: squeue::EntryMarker, C: cqueue::Entry
test.probe.is_supported(opcode::RecvMsgMulti::CODE);
test.probe.is_supported(opcode::ProvideBuffers::CODE);
test.probe.is_supported(opcode::SendMsg::CODE);
test.check_kernel_version("6.6.0" /* 6.2 is totally broken and returns nonsense upon truncation */);
);

println!("test udp_recvmsg_multishot_trunc");
Expand All @@ -1459,15 +1458,10 @@ pub fn test_udp_recvmsg_multishot_trunc<S: squeue::EntryMarker, C: cqueue::Entry
const DATA: &[u8] = b"testfooo for me";
let mut buf1 = [0u8; 20]; // 20 = size_of::<io_uring_recvmsg_out>() + msghdr.msg_namelen
let mut buf2 = [0u8; 20 + DATA.len()];
let mut buf3 = [0u8; 20 + DATA.len()];
let mut buffers = [
buf1.as_mut_slice(),
buf2.as_mut_slice(),
buf3.as_mut_slice(),
];
let mut buffers = [buf1.as_mut_slice(), buf2.as_mut_slice()];

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

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

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

ring.submitter().submit_and_wait(4).unwrap();
let cqes: Vec<io_uring::cqueue::Entry> = ring.completion().map(Into::into).collect();
assert_eq!(cqes.len(), 4);
let mut i = 0;
let cqes: Vec<cqueue::Entry> = ring.completion().map(Into::into).collect();
assert!([4, 5].contains(&cqes.len()));

let mut processed_responses = 0;
for cqe in cqes {
let is_more = io_uring::cqueue::more(cqe.flags());
let is_more = cqueue::more(cqe.flags());
match cqe.user_data() {
// send notifications
55 => {
Expand All @@ -1537,13 +1532,18 @@ pub fn test_udp_recvmsg_multishot_trunc<S: squeue::EntryMarker, C: cqueue::Entry
}
// RecvMsgMulti
77 => {
if cqe.result() == -105 {
// Ran out of buffers
continue;
}

assert!(cqe.result() > 0);
assert!(is_more);
let buf_id = io_uring::cqueue::buffer_select(cqe.flags()).unwrap();
let buf_id = cqueue::buffer_select(cqe.flags()).unwrap() % buffers.len() as u16;
let tmp_buf = &buffers[buf_id as usize];
let msg = types::RecvMsgOut::parse(tmp_buf, &msghdr);

match i {
match buf_id {
0 => {
let msg = msg.unwrap();
assert!(msg.is_payload_truncated());
Expand All @@ -1564,13 +1564,14 @@ pub fn test_udp_recvmsg_multishot_trunc<S: squeue::EntryMarker, C: cqueue::Entry
}
_ => unreachable!(),
}
i += 1;
processed_responses += 1;
}
_ => {
unreachable!()
}
}
}
assert_eq!(processed_responses, 2);

Ok(())
}
Expand Down
Loading