Skip to content

Commit f7758da

Browse files
committed
Add unit test cases and benchmark for push_command()
Add unit test cases and benchmark for push_command(). Signed-off-by: Liu Jiang <[email protected]>
1 parent 6be9264 commit f7758da

File tree

3 files changed

+57
-1
lines changed

3 files changed

+57
-1
lines changed

io-uring-bench/src/nop.rs

+29-1
Original file line numberDiff line numberDiff line change
@@ -41,5 +41,33 @@ fn bench_normal(c: &mut Criterion) {
4141
});
4242
}
4343

44-
criterion_group!(squeue, bench_normal);
44+
fn bench_prepare(c: &mut Criterion) {
45+
let mut io_uring = IoUring::new(16).unwrap();
46+
47+
c.bench_function("prepare", |b| {
48+
b.iter(|| {
49+
let mut queue = TaskQueue(128);
50+
let nop = black_box(opcode::Nop::new());
51+
52+
while queue.want() {
53+
{
54+
let mut sq = io_uring.submission();
55+
while queue.want() {
56+
unsafe {
57+
match sq.push_command(&nop, None) {
58+
Ok(_) => queue.pop(),
59+
Err(_) => break,
60+
}
61+
}
62+
}
63+
}
64+
65+
io_uring.submit_and_wait(16).unwrap();
66+
67+
io_uring.completion().map(black_box).for_each(drop);
68+
}
69+
});
70+
});
71+
}
72+
criterion_group!(squeue, bench_normal, bench_prepare);
4573
criterion_main!(squeue);

io-uring-test/src/main.rs

+1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ fn main() -> anyhow::Result<()> {
2727
};
2828

2929
tests::queue::test_nop(&mut ring, &test)?;
30+
tests::queue::test_nop_prepare(&mut ring, &test)?;
3031
tests::queue::test_queue_split(&mut ring, &test)?;
3132

3233
#[cfg(feature = "unstable")]

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

+27
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use crate::Test;
2+
use io_uring::squeue::OptionValues;
23
use io_uring::{opcode, IoUring};
34

45
pub fn test_nop(ring: &mut IoUring, test: &Test) -> anyhow::Result<()> {
@@ -26,6 +27,32 @@ pub fn test_nop(ring: &mut IoUring, test: &Test) -> anyhow::Result<()> {
2627
Ok(())
2728
}
2829

30+
pub fn test_nop_prepare(ring: &mut IoUring, test: &Test) -> anyhow::Result<()> {
31+
require! {
32+
test;
33+
}
34+
35+
println!("test nop with prepare");
36+
37+
let nop = opcode::Nop::new();
38+
let opt = OptionValues::default().user_data(0x42);
39+
40+
unsafe {
41+
let mut queue = ring.submission();
42+
queue.push_command(&nop, Some(&opt)).expect("queue is full");
43+
}
44+
45+
ring.submit_and_wait(1)?;
46+
47+
let cqes = ring.completion().collect::<Vec<_>>();
48+
49+
assert_eq!(cqes.len(), 1);
50+
assert_eq!(cqes[0].user_data(), 0x42);
51+
assert_eq!(cqes[0].result(), 0);
52+
53+
Ok(())
54+
}
55+
2956
#[cfg(feature = "unstable")]
3057
pub fn test_batch(ring: &mut IoUring, test: &Test) -> anyhow::Result<()> {
3158
use std::mem::MaybeUninit;

0 commit comments

Comments
 (0)