* Test single timeout waking us up */
| 236 | * Test single timeout waking us up |
| 237 | */ |
| 238 | static int test_single_timeout(struct io_uring *ring, bool immediate) |
| 239 | { |
| 240 | struct io_uring_cqe *cqe; |
| 241 | struct io_uring_sqe *sqe; |
| 242 | unsigned long long exp; |
| 243 | struct __kernel_timespec ts; |
| 244 | struct timeval tv; |
| 245 | int ret; |
| 246 | |
| 247 | sqe = io_uring_get_sqe(ring); |
| 248 | if (!sqe) { |
| 249 | fprintf(stderr, "%s: get sqe failed\n", __FUNCTION__); |
| 250 | goto err; |
| 251 | } |
| 252 | |
| 253 | msec_to_ts(&ts, TIMEOUT_MSEC); |
| 254 | t_prep_timeout(sqe, &ts, 0, immediate); |
| 255 | |
| 256 | ret = io_uring_submit(ring); |
| 257 | if (ret <= 0) { |
| 258 | fprintf(stderr, "%s: sqe submit failed: %d\n", __FUNCTION__, ret); |
| 259 | goto err; |
| 260 | } |
| 261 | |
| 262 | gettimeofday(&tv, NULL); |
| 263 | ret = io_uring_wait_cqe(ring, &cqe); |
| 264 | if (ret < 0) { |
| 265 | fprintf(stderr, "%s: wait completion %d\n", __FUNCTION__, ret); |
| 266 | goto err; |
| 267 | } |
| 268 | ret = cqe->res; |
| 269 | io_uring_cqe_seen(ring, cqe); |
| 270 | if (ret == -EINVAL) { |
| 271 | if (immediate) { |
| 272 | no_immediate = true; |
| 273 | fprintf(stdout, "%s: Timeout (imm) not supported, ignored\n", __FUNCTION__); |
| 274 | return 0; |
| 275 | } |
| 276 | fprintf(stdout, "%s: Timeout not supported, ignored\n", __FUNCTION__); |
| 277 | not_supported = 1; |
| 278 | return 0; |
| 279 | } else if (ret != -ETIME) { |
| 280 | fprintf(stderr, "%s: Timeout: %s\n", __FUNCTION__, strerror(-ret)); |
| 281 | goto err; |
| 282 | } |
| 283 | |
| 284 | exp = mtime_since_now(&tv); |
| 285 | if (exp >= TIMEOUT_MSEC / 2 && exp <= (TIMEOUT_MSEC * 3) / 2) |
| 286 | return 0; |
| 287 | fprintf(stderr, "%s: Timeout seems wonky (got %llu)\n", __FUNCTION__, exp); |
| 288 | err: |
| 289 | return 1; |
| 290 | } |
| 291 | |
| 292 | static int test_single_timeout_remove_notfound(struct io_uring *ring) |
| 293 | { |
no test coverage detected