aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/libs/liburing/test/cq-size.c
blob: 08aa58783030ba5ad05d8cb1cdc23e89a3eeb081 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#include "../config-host.h"
/* SPDX-License-Identifier: MIT */
/*
 * Description: test CQ ring sizing
 */
#include <errno.h>
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>

#include "liburing.h"
#include "helpers.h"

int main(int argc, char *argv[])
{
	struct io_uring_params p;
	struct io_uring ring;
	int ret;

	if (argc > 1)
		return T_EXIT_SKIP;

	memset(&p, 0, sizeof(p));
	p.flags = IORING_SETUP_CQSIZE;
	p.cq_entries = 64;

	ret = io_uring_queue_init_params(4, &ring, &p);
	if (ret) {
		if (ret == -EINVAL) {
			printf("Skipped, not supported on this kernel\n");
			goto done;
		}
		printf("ring setup failed\n");
		return T_EXIT_FAIL;
	}

	if (p.cq_entries < 64) {
		printf("cq entries invalid (%d)\n", p.cq_entries);
		goto err;
	}
	io_uring_queue_exit(&ring);

	memset(&p, 0, sizeof(p));
	p.flags = IORING_SETUP_CQSIZE;
	p.cq_entries = 0;

	ret = io_uring_queue_init_params(4, &ring, &p);
	if (ret >= 0) {
		printf("zero sized cq ring succeeded\n");
		io_uring_queue_exit(&ring);
		goto err;
	}

	if (ret != -EINVAL) {
		printf("io_uring_queue_init_params failed, but not with -EINVAL"
		       ", returned error %d (%s)\n", ret, strerror(-ret));
		goto err;
	}

done:
	return T_EXIT_PASS;
err:
	return T_EXIT_FAIL;
}