aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/libs/liburing/test/b5837bd5311d.c
blob: 1c332078eadd2686dfa5c59f8ea7b33b07b5f01f (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
67
68
69
70
71
72
73
74
75
76
77
78
79
#include "../config-host.h"
/* SPDX-License-Identifier: MIT */
/*
 * Description: Check to see if wait_nr is being honored.
 */
#include <stdio.h>
#include "liburing.h"
#include "helpers.h"

int main(int argc, char *argv[])
{
	struct io_uring_sqe *sqe;
	struct io_uring_cqe *cqe;
	struct io_uring ring;
	int ret;
	struct __kernel_timespec ts = {
		.tv_sec = 0,
		.tv_nsec = 10000000
	};

	if (argc > 1)
		return T_EXIT_SKIP;

	if (io_uring_queue_init(4, &ring, 0) != 0) {
		fprintf(stderr, "ring setup failed\n");
		return T_EXIT_FAIL;
	}

	/*
	 * First, submit the timeout sqe so we can actually finish the test
	 * if everything is in working order.
	 */
	sqe = io_uring_get_sqe(&ring);
	if (!sqe) {
		fprintf(stderr, "get sqe failed\n");
		return T_EXIT_FAIL;
	}
	io_uring_prep_timeout(sqe, &ts, (unsigned)-1, 0);

	ret = io_uring_submit(&ring);
	if (ret != 1) {
		fprintf(stderr, "Got submit %d, expected 1\n", ret);
		return T_EXIT_FAIL;
	}

	/*
	 * Next, submit a nop and wait for two events. If everything is working
	 * as it should, we should be waiting for more than a millisecond and we
	 * should see two cqes. Otherwise, execution continues immediately
	 * and we see only one cqe.
	 */
	sqe = io_uring_get_sqe(&ring);
	if (!sqe) {
		fprintf(stderr, "get sqe failed\n");
		return T_EXIT_FAIL;
	}
	io_uring_prep_nop(sqe);

	ret = io_uring_submit_and_wait(&ring, 2);
	if (ret != 1) {
		fprintf(stderr, "Got submit %d, expected 1\n", ret);
		return T_EXIT_FAIL;
	}

	if (io_uring_peek_cqe(&ring, &cqe) != 0) {
		fprintf(stderr, "Unable to peek cqe!\n");
		return T_EXIT_FAIL;
	}

	io_uring_cqe_seen(&ring, cqe);

	if (io_uring_peek_cqe(&ring, &cqe) != 0) {
		fprintf(stderr, "Unable to peek cqe!\n");
		return T_EXIT_FAIL;
	}

	io_uring_queue_exit(&ring);
	return T_EXIT_PASS;
}