MCPcopy Create free account
hub / github.com/axboe/liburing / test_single_timeout_many

Function test_single_timeout_many

test/timeout.c:53–107  ·  view source on GitHub ↗

* Test that we return to userspace if a timeout triggers, even if we * don't satisfy the number of events asked for. */

Source from the content-addressed store, hash-verified

51 * don't satisfy the number of events asked for.
52 */
53static int test_single_timeout_many(struct io_uring *ring, bool immediate)
54{
55 struct io_uring_cqe *cqe;
56 struct io_uring_sqe *sqe;
57 unsigned long long exp;
58 struct __kernel_timespec ts;
59 struct timeval tv;
60 int ret;
61
62 sqe = io_uring_get_sqe(ring);
63 if (!sqe) {
64 fprintf(stderr, "%s: get sqe failed\n", __FUNCTION__);
65 goto err;
66 }
67
68 msec_to_ts(&ts, TIMEOUT_MSEC);
69 t_prep_timeout(sqe, &ts, 0, immediate);
70
71 ret = io_uring_submit(ring);
72 if (ret <= 0) {
73 fprintf(stderr, "%s: sqe submit failed: %d\n", __FUNCTION__, ret);
74 goto err;
75 }
76
77 gettimeofday(&tv, NULL);
78 ret = __sys_io_uring_enter(ring->ring_fd, 0, 4, IORING_ENTER_GETEVENTS,
79 NULL);
80 if (ret < 0) {
81 fprintf(stderr, "%s: io_uring_enter %d\n", __FUNCTION__, ret);
82 goto err;
83 }
84
85 ret = io_uring_wait_cqe(ring, &cqe);
86 if (ret < 0) {
87 fprintf(stderr, "%s: wait completion %d\n", __FUNCTION__, ret);
88 goto err;
89 }
90 ret = cqe->res;
91 io_uring_cqe_seen(ring, cqe);
92 if (ret == -EINVAL) {
93 fprintf(stdout, "Timeout not supported, ignored\n");
94 not_supported = 1;
95 return 0;
96 } else if (ret != -ETIME) {
97 fprintf(stderr, "Timeout: %s\n", strerror(-ret));
98 goto err;
99 }
100
101 exp = mtime_since_now(&tv);
102 if (exp >= TIMEOUT_MSEC / 2 && exp <= (TIMEOUT_MSEC * 3) / 2)
103 return 0;
104 fprintf(stderr, "%s: Timeout seems wonky (got %llu)\n", __FUNCTION__, exp);
105err:
106 return 1;
107}
108
109/*
110 * Test numbered trigger of timeout

Callers 1

mainFunction · 0.85

Calls 6

t_prep_timeoutFunction · 0.85
io_uring_submitFunction · 0.85
msec_to_tsFunction · 0.70
mtime_since_nowFunction · 0.70
io_uring_get_sqeFunction · 0.50
__sys_io_uring_enterFunction · 0.50

Tested by

no test coverage detected