* Test multi timeouts waking us up */
| 523 | * Test multi timeouts waking us up |
| 524 | */ |
| 525 | static int test_multi_timeout(struct io_uring *ring) |
| 526 | { |
| 527 | struct io_uring_sqe *sqe; |
| 528 | struct io_uring_cqe *cqe; |
| 529 | struct __kernel_timespec ts[2]; |
| 530 | unsigned int timeout[2]; |
| 531 | unsigned long long exp; |
| 532 | struct timeval tv; |
| 533 | int ret, i; |
| 534 | |
| 535 | /* req_1: timeout req, count = 1, time = (TIMEOUT_MSEC * 2) */ |
| 536 | timeout[0] = TIMEOUT_MSEC * 2; |
| 537 | msec_to_ts(&ts[0], timeout[0]); |
| 538 | sqe = io_uring_get_sqe(ring); |
| 539 | if (!sqe) { |
| 540 | fprintf(stderr, "%s: get sqe failed\n", __FUNCTION__); |
| 541 | goto err; |
| 542 | } |
| 543 | io_uring_prep_timeout(sqe, &ts[0], 1, 0); |
| 544 | sqe->user_data = 1; |
| 545 | |
| 546 | /* req_2: timeout req, count = 1, time = TIMEOUT_MSEC */ |
| 547 | timeout[1] = TIMEOUT_MSEC; |
| 548 | msec_to_ts(&ts[1], timeout[1]); |
| 549 | sqe = io_uring_get_sqe(ring); |
| 550 | if (!sqe) { |
| 551 | fprintf(stderr, "%s: get sqe failed\n", __FUNCTION__); |
| 552 | goto err; |
| 553 | } |
| 554 | io_uring_prep_timeout(sqe, &ts[1], 1, 0); |
| 555 | sqe->user_data = 2; |
| 556 | |
| 557 | ret = io_uring_submit(ring); |
| 558 | if (ret <= 0) { |
| 559 | fprintf(stderr, "%s: sqe submit failed: %d\n", __FUNCTION__, ret); |
| 560 | goto err; |
| 561 | } |
| 562 | |
| 563 | gettimeofday(&tv, NULL); |
| 564 | for (i = 0; i < 2; i++) { |
| 565 | unsigned int time = 0; |
| 566 | __u64 user_data = 0; |
| 567 | |
| 568 | ret = io_uring_wait_cqe(ring, &cqe); |
| 569 | if (ret < 0) { |
| 570 | fprintf(stderr, "%s: wait completion %d\n", __FUNCTION__, ret); |
| 571 | goto err; |
| 572 | } |
| 573 | |
| 574 | /* |
| 575 | * Both of these two reqs should timeout, but req_2 should |
| 576 | * return before req_1. |
| 577 | */ |
| 578 | switch (i) { |
| 579 | case 0: |
| 580 | user_data = 2; |
| 581 | time = timeout[1]; |
| 582 | break; |
no test coverage detected