• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* SPDX-License-Identifier: MIT */
2 /*
3  * Description: test CQ ring sizing
4  */
5 #include <errno.h>
6 #include <stdio.h>
7 #include <unistd.h>
8 #include <stdlib.h>
9 #include <string.h>
10 #include <fcntl.h>
11 
12 #include "liburing.h"
13 #include "helpers.h"
14 
main(int argc,char * argv[])15 int main(int argc, char *argv[])
16 {
17 	struct io_uring_params p;
18 	struct io_uring ring;
19 	int ret;
20 
21 	if (argc > 1)
22 		return T_EXIT_SKIP;
23 
24 	memset(&p, 0, sizeof(p));
25 	p.flags = IORING_SETUP_CQSIZE;
26 	p.cq_entries = 64;
27 
28 	ret = io_uring_queue_init_params(4, &ring, &p);
29 	if (ret) {
30 		if (ret == -EINVAL) {
31 			printf("Skipped, not supported on this kernel\n");
32 			goto done;
33 		}
34 		printf("ring setup failed\n");
35 		return T_EXIT_FAIL;
36 	}
37 
38 	if (p.cq_entries < 64) {
39 		printf("cq entries invalid (%d)\n", p.cq_entries);
40 		goto err;
41 	}
42 	io_uring_queue_exit(&ring);
43 
44 	memset(&p, 0, sizeof(p));
45 	p.flags = IORING_SETUP_CQSIZE;
46 	p.cq_entries = 0;
47 
48 	ret = io_uring_queue_init_params(4, &ring, &p);
49 	if (ret >= 0) {
50 		printf("zero sized cq ring succeeded\n");
51 		io_uring_queue_exit(&ring);
52 		goto err;
53 	}
54 
55 	if (ret != -EINVAL) {
56 		printf("io_uring_queue_init_params failed, but not with -EINVAL"
57 		       ", returned error %d (%s)\n", ret, strerror(-ret));
58 		goto err;
59 	}
60 
61 done:
62 	return T_EXIT_PASS;
63 err:
64 	return T_EXIT_FAIL;
65 }
66