1 /* SPDX-License-Identifier: MIT */
2 /*
3 * Description: Check to see if wait_nr is being honored.
4 */
5 #include <stdio.h>
6 #include "liburing.h"
7
main(int argc,char * argv[])8 int main(int argc, char *argv[])
9 {
10 struct io_uring_sqe *sqe;
11 struct io_uring_cqe *cqe;
12 struct io_uring ring;
13 int ret;
14 struct __kernel_timespec ts = {
15 .tv_sec = 0,
16 .tv_nsec = 10000000
17 };
18
19 if (argc > 1)
20 return 0;
21
22 if (io_uring_queue_init(4, &ring, 0) != 0) {
23 fprintf(stderr, "ring setup failed\n");
24 return 1;
25 }
26
27 /*
28 * First, submit the timeout sqe so we can actually finish the test
29 * if everything is in working order.
30 */
31 sqe = io_uring_get_sqe(&ring);
32 if (!sqe) {
33 fprintf(stderr, "get sqe failed\n");
34 return 1;
35 }
36 io_uring_prep_timeout(sqe, &ts, (unsigned)-1, 0);
37
38 ret = io_uring_submit(&ring);
39 if (ret != 1) {
40 fprintf(stderr, "Got submit %d, expected 1\n", ret);
41 return 1;
42 }
43
44 /*
45 * Next, submit a nop and wait for two events. If everything is working
46 * as it should, we should be waiting for more than a millisecond and we
47 * should see two cqes. Otherwise, execution continues immediately
48 * and we see only one cqe.
49 */
50 sqe = io_uring_get_sqe(&ring);
51 if (!sqe) {
52 fprintf(stderr, "get sqe failed\n");
53 return 1;
54 }
55 io_uring_prep_nop(sqe);
56
57 ret = io_uring_submit_and_wait(&ring, 2);
58 if (ret != 1) {
59 fprintf(stderr, "Got submit %d, expected 1\n", ret);
60 return 1;
61 }
62
63 if (io_uring_peek_cqe(&ring, &cqe) != 0) {
64 fprintf(stderr, "Unable to peek cqe!\n");
65 return 1;
66 }
67
68 io_uring_cqe_seen(&ring, cqe);
69
70 if (io_uring_peek_cqe(&ring, &cqe) != 0) {
71 fprintf(stderr, "Unable to peek cqe!\n");
72 return 1;
73 }
74
75 io_uring_queue_exit(&ring);
76 return 0;
77 }
78