summaryrefslogtreecommitdiff
path: root/test/d77a67ed5f27-test.c
blob: e56fdcd4069d4633fd886449e8c8b84e1c522875 (plain)
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
/* SPDX-License-Identifier: MIT */
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <signal.h>
#include <stdlib.h>
#include "liburing.h"
#include "helpers.h"

static void sig_alrm(int sig)
{
	fprintf(stderr, "Timed out!\n");
	exit(1);
}

int main(int argc, char *argv[])
{
	struct io_uring_sqe *sqe;
	struct io_uring_cqe *cqe;
	struct io_uring_params p;
	struct io_uring ring;
	int ret, data;

	if (argc > 1)
		return 0;

	signal(SIGALRM, sig_alrm);

	memset(&p, 0, sizeof(p));
	p.sq_thread_idle = 100;
	p.flags = IORING_SETUP_SQPOLL;
	ret = t_create_ring_params(4, &ring, &p);
	if (ret == T_SETUP_SKIP)
		return 0;
	else if (ret < 0)
		return 1;

	/* make sure sq thread is sleeping at this point */
	usleep(150000);
	alarm(1);

	sqe = io_uring_get_sqe(&ring);
	if (!sqe) {
		fprintf(stderr, "sqe get failed\n");
		return 1;
	}

	io_uring_prep_nop(sqe);
	io_uring_sqe_set_data(sqe, (void *) (unsigned long) 42);
	io_uring_submit_and_wait(&ring, 1);

	ret = io_uring_peek_cqe(&ring, &cqe);
	if (ret) {
		fprintf(stderr, "cqe get failed\n");
		return 1;
	}

	data = (unsigned long) io_uring_cqe_get_data(cqe);
	if (data != 42) {
		fprintf(stderr, "invalid data: %d\n", data);
		return 1;
	}

	return 0;
}