MCPcopy Create free account
hub / github.com/axboe/liburing / test

Function test

test/poll-mshot-wake.c:22–118  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

20#define NR_LOOPS 2
21
22static int test(void)
23{
24 struct __kernel_timespec ts;
25 struct io_uring_cqe *cqe;
26 struct io_uring_sqe *sqe;
27 struct io_uring ring;
28 int ret, evfd, i;
29 uint64_t val;
30
31 evfd = eventfd(0, EFD_NONBLOCK);
32 if (evfd < 0) {
33 perror("eventfd");
34 return T_EXIT_FAIL;
35 }
36
37 ret = io_uring_queue_init(8, &ring, 0);
38 if (ret) {
39 fprintf(stderr, "queue_init: %d\n", ret);
40 close(evfd);
41 return T_EXIT_FAIL;
42 }
43
44 ret = io_uring_register_eventfd(&ring, evfd);
45 if (ret) {
46 fprintf(stderr, "register_eventfd: %d\n", ret);
47 close(evfd);
48 io_uring_queue_exit(&ring);
49 return T_EXIT_FAIL;
50 }
51
52 sqe = io_uring_get_sqe(&ring);
53 io_uring_prep_poll_multishot(sqe, evfd, POLLIN);
54 sqe->user_data = 1;
55
56 ret = io_uring_submit(&ring);
57 if (ret != 1) {
58 fprintf(stderr, "submit: %d\n", ret);
59 goto err;
60 }
61
62 for (i = 0; i < NR_LOOPS; i++) {
63 val = 1;
64 ret = write(evfd, &val, sizeof(val));
65 if (ret != sizeof(val)) {
66 perror("write");
67 goto err;
68 }
69 ret = read(evfd, &val, sizeof(val));
70 if (ret != sizeof(val)) {
71 perror("read");
72 goto err;
73 }
74
75 ts.tv_sec = 1;
76 ts.tv_nsec = 0;
77 ret = io_uring_wait_cqe_timeout(&ring, &cqe, &ts);
78 if (ret == -ETIME) {
79 fprintf(stderr, "poll stuck: no CQE after iteration %d\n", i);

Callers 1

mainFunction · 0.70

Calls 6

io_uring_queue_initFunction · 0.85
io_uring_queue_exitFunction · 0.85
io_uring_submitFunction · 0.85
io_uring_get_sqeFunction · 0.50

Tested by

no test coverage detected