Skip to content

Commit 3f68117

Browse files
committed
Add test for SubmitArgs::min_wait_usec
1 parent 9bd94a4 commit 3f68117

File tree

2 files changed

+53
-0
lines changed

2 files changed

+53
-0
lines changed

io-uring-test/src/main.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ fn test<S: squeue::EntryMarker, C: cqueue::EntryMarker>(
115115
tests::timeout::test_timeout_cancel(&mut ring, &test)?;
116116
tests::timeout::test_timeout_abs(&mut ring, &test)?;
117117
tests::timeout::test_timeout_submit_args(&mut ring, &test)?;
118+
tests::timeout::test_timeout_submit_args_min_wait(&mut ring, &test)?;
118119

119120
// net
120121
tests::net::test_tcp_write_read(&mut ring, &test)?;

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

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,3 +381,55 @@ pub fn test_timeout_submit_args<S: squeue::EntryMarker, C: cqueue::EntryMarker>(
381381

382382
Ok(())
383383
}
384+
385+
pub fn test_timeout_submit_args_min_wait<S: squeue::EntryMarker, C: cqueue::EntryMarker>(
386+
ring: &mut IoUring<S, C>,
387+
test: &Test,
388+
) -> anyhow::Result<()> {
389+
require! {
390+
test;
391+
ring.params().is_feature_ext_arg();
392+
ring.params().is_feature_min_timeout();
393+
};
394+
395+
println!("test timeout_submit_args_min_wait");
396+
397+
let ts = types::Timespec::new().sec(2);
398+
let args = types::SubmitArgs::new()
399+
.timespec(&ts)
400+
.min_wait_usec(1_000_000);
401+
402+
// timeout
403+
404+
let start = Instant::now();
405+
match ring.submitter().submit_with_args(2, &args) {
406+
Ok(_) => panic!(),
407+
Err(ref err) if err.raw_os_error() == Some(libc::ETIME) => (),
408+
Err(err) => return Err(err.into()),
409+
}
410+
assert_eq!(start.elapsed().as_secs(), 2);
411+
412+
assert!(ring.completion().next().is_none());
413+
414+
// no timeout
415+
416+
let nop_e = opcode::Nop::new();
417+
418+
unsafe {
419+
ring.submission()
420+
.push(&nop_e.build().user_data(0x1d).into())
421+
.expect("queue is full");
422+
}
423+
424+
let start = Instant::now();
425+
ring.submitter().submit_with_args(2, &args)?;
426+
assert_eq!(start.elapsed().as_secs(), 1);
427+
428+
let cqes: Vec<cqueue::Entry> = ring.completion().map(Into::into).collect();
429+
430+
assert_eq!(cqes.len(), 1);
431+
assert_eq!(cqes[0].user_data(), 0x1d);
432+
assert_eq!(cqes[0].result(), 0);
433+
434+
Ok(())
435+
}

0 commit comments

Comments
 (0)