| 66 | |
| 67 | |
| 68 | static int test_eventfd(void) |
| 69 | { |
| 70 | struct io_uring ring; |
| 71 | int ret; |
| 72 | int fda, fdb; |
| 73 | struct io_uring_cqe *cqe; |
| 74 | |
| 75 | ret = io_uring_queue_init(8, &ring, IORING_SETUP_SINGLE_ISSUER | |
| 76 | IORING_SETUP_DEFER_TASKRUN); |
| 77 | if (ret) |
| 78 | return ret; |
| 79 | |
| 80 | fda = eventfd(0, EFD_NONBLOCK); |
| 81 | fdb = eventfd(0, EFD_NONBLOCK); |
| 82 | |
| 83 | CHECK(fda >= 0 && fdb >= 0); |
| 84 | |
| 85 | ret = io_uring_register_eventfd(&ring, fda); |
| 86 | if (ret) |
| 87 | return ret; |
| 88 | |
| 89 | CHECK(!can_read(fda)); |
| 90 | CHECK(!can_read(fdb)); |
| 91 | |
| 92 | io_uring_prep_poll_add(io_uring_get_sqe(&ring), fdb, POLLIN); |
| 93 | io_uring_submit(&ring); |
| 94 | CHECK(!can_read(fda)); /* poll should not have completed */ |
| 95 | |
| 96 | io_uring_prep_nop(io_uring_get_sqe(&ring)); |
| 97 | io_uring_submit(&ring); |
| 98 | CHECK(can_read(fda)); /* nop should have */ |
| 99 | |
| 100 | CHECK(io_uring_peek_cqe(&ring, &cqe) == 0); |
| 101 | CHECK(cqe->res == 0); |
| 102 | io_uring_cqe_seen(&ring, cqe); |
| 103 | eventfd_clear(fda); |
| 104 | |
| 105 | eventfd_trigger(fdb); |
| 106 | /* can take time due to rcu_call */ |
| 107 | CHECK(can_read_t(fda, 1000)); |
| 108 | |
| 109 | /* should not have processed the cqe yet */ |
| 110 | CHECK(io_uring_cq_ready(&ring) == 0); |
| 111 | |
| 112 | io_uring_get_events(&ring); |
| 113 | CHECK(io_uring_cq_ready(&ring) == 1); |
| 114 | |
| 115 | |
| 116 | io_uring_queue_exit(&ring); |
| 117 | return 0; |
| 118 | } |
| 119 | |
| 120 | struct thread_data { |
| 121 | struct io_uring ring; |
no test coverage detected