* Test linked timeout with timeout (timeoutception) */
| 165 | * Test linked timeout with timeout (timeoutception) |
| 166 | */ |
| 167 | static int test_single_link_timeout_ception(struct io_uring *ring) |
| 168 | { |
| 169 | struct __kernel_timespec ts1, ts2; |
| 170 | struct io_uring_cqe *cqe; |
| 171 | struct io_uring_sqe *sqe; |
| 172 | int ret, i; |
| 173 | |
| 174 | sqe = io_uring_get_sqe(ring); |
| 175 | if (!sqe) { |
| 176 | printf("get sqe failed\n"); |
| 177 | goto err; |
| 178 | } |
| 179 | |
| 180 | ts1.tv_sec = 1; |
| 181 | ts1.tv_nsec = 0; |
| 182 | io_uring_prep_timeout(sqe, &ts1, -1U, 0); |
| 183 | sqe->flags |= IOSQE_IO_LINK; |
| 184 | sqe->user_data = 1; |
| 185 | |
| 186 | sqe = io_uring_get_sqe(ring); |
| 187 | if (!sqe) { |
| 188 | printf("get sqe failed\n"); |
| 189 | goto err; |
| 190 | } |
| 191 | |
| 192 | ts2.tv_sec = 2; |
| 193 | ts2.tv_nsec = 0; |
| 194 | io_uring_prep_link_timeout(sqe, &ts2, 0); |
| 195 | sqe->user_data = 2; |
| 196 | |
| 197 | ret = io_uring_submit(ring); |
| 198 | if (ret != 2) { |
| 199 | printf("sqe submit failed: %d\n", ret); |
| 200 | goto err; |
| 201 | } |
| 202 | |
| 203 | for (i = 0; i < 2; i++) { |
| 204 | ret = io_uring_wait_cqe(ring, &cqe); |
| 205 | if (ret < 0) { |
| 206 | printf("wait completion %d\n", ret); |
| 207 | goto err; |
| 208 | } |
| 209 | switch (cqe->user_data) { |
| 210 | case 1: |
| 211 | /* newer kernels allow timeout links */ |
| 212 | if (cqe->res != -EINVAL && cqe->res != -ETIME) { |
| 213 | fprintf(stderr, "Timeout got %d, wanted " |
| 214 | "-EINVAL or -ETIME\n", cqe->res); |
| 215 | goto err; |
| 216 | } |
| 217 | break; |
| 218 | case 2: |
| 219 | if (cqe->res != -ECANCELED) { |
| 220 | fprintf(stderr, "Link timeout got %d, wanted -ECANCELED\n", cqe->res); |
| 221 | goto err; |
| 222 | } |
| 223 | break; |
| 224 | } |
no test coverage detected