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

Function test_single_timeout

test/timeout.c:238–290  ·  view source on GitHub ↗

* Test single timeout waking us up */

Source from the content-addressed store, hash-verified

236 * Test single timeout waking us up
237 */
238static 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);
288err:
289 return 1;
290}
291
292static int test_single_timeout_remove_notfound(struct io_uring *ring)
293{

Callers 1

mainFunction · 0.85

Calls 5

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

Tested by

no test coverage detected