1 /* SPDX-License-Identifier: MIT */
2 /*
3 * Description: test IORING_SETUP_SUBMIT_ALL
4 *
5 */
6 #include <errno.h>
7 #include <stdio.h>
8 #include <unistd.h>
9 #include <stdlib.h>
10
11 #include "liburing.h"
12 #include "helpers.h"
13
test(struct io_uring * ring,int expect_drops)14 static int test(struct io_uring *ring, int expect_drops)
15 {
16 struct io_uring_sqe *sqe;
17 char buf[32];
18 int ret, i;
19
20 for (i = 0; i < 4; i++) {
21 sqe = io_uring_get_sqe(ring);
22 if (!sqe) {
23 fprintf(stderr, "get sqe failed\n");
24 goto err;
25 }
26
27 io_uring_prep_nop(sqe);
28 }
29
30 /* prep two invalid reads, these will fail */
31 for (i = 0; i < 2; i++) {
32 sqe = io_uring_get_sqe(ring);
33 if (!sqe) {
34 fprintf(stderr, "get sqe failed\n");
35 goto err;
36 }
37
38 io_uring_prep_read(sqe, 128, buf, sizeof(buf), 0);
39 sqe->ioprio = (short) -1;
40 }
41
42
43 ret = io_uring_submit(ring);
44 if (expect_drops) {
45 if (ret != 5) {
46 fprintf(stderr, "drops submit failed: %d\n", ret);
47 goto err;
48 }
49 } else {
50 if (ret != 6) {
51 fprintf(stderr, "no drops submit failed: %d\n", ret);
52 goto err;
53 }
54 }
55
56 return 0;
57 err:
58 return 1;
59 }
60
main(int argc,char * argv[])61 int main(int argc, char *argv[])
62 {
63 struct io_uring ring;
64 int ret;
65
66 if (argc > 1)
67 return T_EXIT_SKIP;
68
69 ret = io_uring_queue_init(8, &ring, IORING_SETUP_SUBMIT_ALL);
70 if (ret)
71 return 0;
72
73 ret = test(&ring, 0);
74 if (ret) {
75 fprintf(stderr, "test no drops failed\n");
76 return ret;
77 }
78
79 io_uring_queue_exit(&ring);
80
81 ret = io_uring_queue_init(8, &ring, 0);
82 if (ret) {
83 fprintf(stderr, "ring setup failed\n");
84 return T_EXIT_FAIL;
85 }
86
87 ret = test(&ring, 1);
88 if (ret) {
89 fprintf(stderr, "test drops failed\n");
90 return ret;
91 }
92
93 return T_EXIT_PASS;
94 }
95