Skip to content

Commit

Permalink
Test
Browse files Browse the repository at this point in the history
Signed-off-by: Alex Saveau <[email protected]>
  • Loading branch information
SUPERCILEX committed May 6, 2024
1 parent 1585421 commit 2f23531
Showing 1 changed file with 17 additions and 13 deletions.
30 changes: 17 additions & 13 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 @@ -1461,17 +1460,12 @@ pub fn test_udp_recvmsg_multishot_trunc<S: squeue::EntryMarker, C: cqueue::Entry
let mut buf2 = [0u8; 20 + DATA.len()];
let mut buffers = [buf1.as_mut_slice(), buf2.as_mut_slice()];

for (index, buf) in buffers.iter_mut().enumerate() {
let provide_bufs_e = opcode::ProvideBuffers::new(
(**buf).as_mut_ptr(),
buf.len() as i32,
1,
BUF_GROUP,
index as u16,
)
.build()
.user_data(11)
.into();
for buf in &mut buffers {
let provide_bufs_e =
opcode::ProvideBuffers::new((**buf).as_mut_ptr(), buf.len() as i32, 1, BUF_GROUP, 0)
.build()
.user_data(11)
.into();
unsafe { ring.submission().push(&provide_bufs_e)? };
ring.submitter().submit_and_wait(1)?;
let cqes: Vec<cqueue::Entry> = ring.completion().map(Into::into).collect();
Expand Down Expand Up @@ -1520,7 +1514,10 @@ pub fn test_udp_recvmsg_multishot_trunc<S: squeue::EntryMarker, C: cqueue::Entry

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

dbg!(&cqes);
let mut processed_responses = 0;
for cqe in cqes {
let is_more = cqueue::more(cqe.flags());
match cqe.user_data() {
Expand All @@ -1539,6 +1536,11 @@ pub fn test_udp_recvmsg_multishot_trunc<S: squeue::EntryMarker, C: cqueue::Entry
assert!(cqe.result() > 0);
assert!(is_more);
let buf_id = cqueue::buffer_select(cqe.flags()).unwrap();
if usize::from(buf_id) >= buffers.len() {
// A different way for the kernel to indicate it ran out of buffers.
continue;
}

let tmp_buf = &buffers[buf_id as usize];
let msg = types::RecvMsgOut::parse(tmp_buf, &msghdr);

Expand All @@ -1563,12 +1565,14 @@ pub fn test_udp_recvmsg_multishot_trunc<S: squeue::EntryMarker, C: cqueue::Entry
}
_ => unreachable!(),
}
processed_responses += 1;
}
_ => {
unreachable!()
}
}
}
assert_eq!(processed_responses, 2);

Ok(())
}
Expand Down

0 comments on commit 2f23531

Please sign in to comment.