* Test numbered trigger of timeout */
| 110 | * Test numbered trigger of timeout |
| 111 | */ |
| 112 | static int test_single_timeout_nr(struct io_uring *ring, int nr) |
| 113 | { |
| 114 | struct io_uring_cqe *cqe; |
| 115 | struct io_uring_sqe *sqe; |
| 116 | struct __kernel_timespec ts; |
| 117 | int i, ret; |
| 118 | |
| 119 | sqe = io_uring_get_sqe(ring); |
| 120 | if (!sqe) { |
| 121 | fprintf(stderr, "%s: get sqe failed\n", __FUNCTION__); |
| 122 | goto err; |
| 123 | } |
| 124 | |
| 125 | msec_to_ts(&ts, TIMEOUT_MSEC); |
| 126 | io_uring_prep_timeout(sqe, &ts, nr, 0); |
| 127 | |
| 128 | sqe = io_uring_get_sqe(ring); |
| 129 | io_uring_prep_nop(sqe); |
| 130 | io_uring_sqe_set_data(sqe, (void *) 1); |
| 131 | sqe = io_uring_get_sqe(ring); |
| 132 | io_uring_prep_nop(sqe); |
| 133 | io_uring_sqe_set_data(sqe, (void *) 1); |
| 134 | |
| 135 | ret = io_uring_submit_and_wait(ring, 3); |
| 136 | if (ret <= 0) { |
| 137 | fprintf(stderr, "%s: sqe submit failed: %d\n", __FUNCTION__, ret); |
| 138 | goto err; |
| 139 | } |
| 140 | |
| 141 | i = 0; |
| 142 | while (i < 3) { |
| 143 | ret = io_uring_wait_cqe(ring, &cqe); |
| 144 | if (ret < 0) { |
| 145 | fprintf(stderr, "%s: wait completion %d\n", __FUNCTION__, ret); |
| 146 | goto err; |
| 147 | } |
| 148 | |
| 149 | ret = cqe->res; |
| 150 | |
| 151 | /* |
| 152 | * NOP commands have user_data as 1. Check that we get the |
| 153 | * at least 'nr' NOPs first, then the successfully removed timeout. |
| 154 | */ |
| 155 | if (io_uring_cqe_get_data(cqe) == NULL) { |
| 156 | if (i < nr) { |
| 157 | fprintf(stderr, "%s: timeout received too early\n", __FUNCTION__); |
| 158 | goto err; |
| 159 | } |
| 160 | if (ret) { |
| 161 | fprintf(stderr, "%s: timeout triggered by passage of" |
| 162 | " time, not by events completed\n", __FUNCTION__); |
| 163 | goto err; |
| 164 | } |
| 165 | } |
| 166 | |
| 167 | io_uring_cqe_seen(ring, cqe); |
| 168 | if (ret) { |
| 169 | fprintf(stderr, "res: %d\n", ret); |
no test coverage detected