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