diff options
author | Jens Axboe <axboe@kernel.dk> | 2019-10-15 16:49:19 -0600 |
---|---|---|
committer | Jens Axboe <axboe@kernel.dk> | 2019-10-15 16:52:44 -0600 |
commit | f303986495386cf00a37ee7ae69809387e099a1a (patch) | |
tree | cbb839ff56ad90438a5cf6218b9205d6c1ef3c21 | |
parent | 19ca53282d86edd42261076c4a7433fbd5dc1e20 (diff) | |
download | liburing-f303986495386cf00a37ee7ae69809387e099a1a.tar.gz liburing-f303986495386cf00a37ee7ae69809387e099a1a.tar.bz2 |
Add test case for absolute timeouts
Signed-off-by: Jens Axboe <axboe@kernel.dk>
-rw-r--r-- | src/include/liburing/io_uring.h | 5 | ||||
-rw-r--r-- | test/timeout.c | 61 |
2 files changed, 66 insertions, 0 deletions
diff --git a/src/include/liburing/io_uring.h b/src/include/liburing/io_uring.h index e0137ea..b402dfe 100644 --- a/src/include/liburing/io_uring.h +++ b/src/include/liburing/io_uring.h @@ -71,6 +71,11 @@ struct io_uring_sqe { #define IORING_FSYNC_DATASYNC (1U << 0) /* + * sqe->timeout_flags + */ +#define IORING_TIMEOUT_ABS (1U << 0) + +/* * IO completion data structure (Completion Queue Entry) */ struct io_uring_cqe { diff --git a/test/timeout.c b/test/timeout.c index c759789..66056ae 100644 --- a/test/timeout.c +++ b/test/timeout.c @@ -275,6 +275,61 @@ err: } /* + * Test single absolute timeout waking us up + */ +static int test_single_timeout_abs(struct io_uring *ring) +{ + struct io_uring_cqe *cqe; + struct io_uring_sqe *sqe; + unsigned long long exp; + struct __kernel_timespec ts; + struct timespec abs_ts; + struct timeval tv; + int ret; + + sqe = io_uring_get_sqe(ring); + if (!sqe) { + printf("get sqe failed\n"); + goto err; + } + + clock_gettime(CLOCK_MONOTONIC, &abs_ts); + ts.tv_sec = abs_ts.tv_sec + 1; + ts.tv_nsec = abs_ts.tv_nsec; + io_uring_prep_timeout(sqe, &ts, 0); + sqe->timeout_flags |= IORING_TIMEOUT_ABS; + + ret = io_uring_submit(ring); + if (ret <= 0) { + printf("sqe submit failed: %d\n", ret); + goto err; + } + + gettimeofday(&tv, NULL); + ret = io_uring_wait_cqe(ring, &cqe); + if (ret < 0) { + printf("wait completion %d\n", ret); + goto err; + } + if (cqe->res == -EINVAL) { + printf("Absolute timeouts not supported, ignored\n"); + io_uring_cqe_seen(ring, cqe); + return 0; + } else if (cqe->res != -ETIME) { + printf("Timeout: %s\n", strerror(-cqe->res)); + io_uring_cqe_seen(ring, cqe); + goto err; + } + + exp = mtime_since_now(&tv); + if (exp >= TIMEOUT_MSEC / 2 && exp <= (TIMEOUT_MSEC * 3) / 2) + return 0; + printf("Timeout seems wonky (got %llu)\n", exp); +err: + return 1; +} + +/* * Test that timeout is canceled on exit */ static int test_single_timeout_exit(struct io_uring *ring) @@ -326,6 +381,12 @@ int main(int argc, char *argv[]) if (not_supported) return 0; + ret = test_single_timeout_abs(&ring); + if (ret) { + printf("test_single_timeout_abs failed\n"); + return ret; + } + ret = test_single_timeout_many(&ring); if (ret) { printf("test_single_timeout_many failed\n"); |