* Test single absolute timeout waking us up */
| 438 | * Test single absolute timeout waking us up |
| 439 | */ |
| 440 | static int test_single_timeout_abs(struct io_uring *ring, bool immediate) |
| 441 | { |
| 442 | struct io_uring_cqe *cqe; |
| 443 | struct io_uring_sqe *sqe; |
| 444 | unsigned long long exp; |
| 445 | struct __kernel_timespec ts; |
| 446 | struct timespec abs_ts; |
| 447 | struct timeval tv; |
| 448 | int ret; |
| 449 | |
| 450 | sqe = io_uring_get_sqe(ring); |
| 451 | if (!sqe) { |
| 452 | fprintf(stderr, "%s: get sqe failed\n", __FUNCTION__); |
| 453 | goto err; |
| 454 | } |
| 455 | |
| 456 | clock_gettime(CLOCK_MONOTONIC, &abs_ts); |
| 457 | ts.tv_sec = abs_ts.tv_sec + 1; |
| 458 | ts.tv_nsec = abs_ts.tv_nsec; |
| 459 | t_prep_timeout(sqe, &ts, IORING_TIMEOUT_ABS, immediate); |
| 460 | |
| 461 | ret = io_uring_submit(ring); |
| 462 | if (ret <= 0) { |
| 463 | fprintf(stderr, "%s: sqe submit failed: %d\n", __FUNCTION__, ret); |
| 464 | goto err; |
| 465 | } |
| 466 | |
| 467 | gettimeofday(&tv, NULL); |
| 468 | ret = io_uring_wait_cqe(ring, &cqe); |
| 469 | if (ret < 0) { |
| 470 | fprintf(stderr, "%s: wait completion %d\n", __FUNCTION__, ret); |
| 471 | goto err; |
| 472 | } |
| 473 | ret = cqe->res; |
| 474 | io_uring_cqe_seen(ring, cqe); |
| 475 | if (ret == -EINVAL) { |
| 476 | fprintf(stdout, "Absolute timeouts not supported, ignored\n"); |
| 477 | return 0; |
| 478 | } else if (ret != -ETIME) { |
| 479 | fprintf(stderr, "Timeout: %s\n", strerror(-ret)); |
| 480 | goto err; |
| 481 | } |
| 482 | |
| 483 | exp = mtime_since_now(&tv); |
| 484 | if (exp >= 1000 / 2 && exp <= (1000 * 3) / 2) |
| 485 | return 0; |
| 486 | fprintf(stderr, "%s: Timeout seems wonky (got %llu)\n", __FUNCTION__, exp); |
| 487 | err: |
| 488 | return 1; |
| 489 | } |
| 490 | |
| 491 | /* |
| 492 | * Test that timeout is canceled on exit |
no test coverage detected