summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJens Axboe <axboe@kernel.dk>2019-09-17 13:38:27 -0600
committerJens Axboe <axboe@kernel.dk>2019-09-17 13:39:47 -0600
commitefb39e105afdb4dd5c0f1e964720cfa3cdcceb18 (patch)
treef33b5c938964be3d5a16a2575e0123e7284a1ee5
parente4269d2c10586c03786df24d6382da99a956f03c (diff)
downloadliburing-efb39e105afdb4dd5c0f1e964720cfa3cdcceb18.tar.gz
liburing-efb39e105afdb4dd5c0f1e964720cfa3cdcceb18.tar.bz2
test/timeout: check if we always get a wakeup from timeout
We need a wakeup even if we don't hit the desired number of available commands if a timeout has triggered. Add a test case for that. Signed-off-by: Jens Axboe <axboe@kernel.dk>
-rw-r--r--test/timeout.c69
1 files changed, 68 insertions, 1 deletions
diff --git a/test/timeout.c b/test/timeout.c
index 960d85d..8e40ea8 100644
--- a/test/timeout.c
+++ b/test/timeout.c
@@ -12,6 +12,8 @@
#include "liburing.h"
+#define TIMEOUT_MSEC 1000
+
static unsigned long long mtime_since(const struct timeval *s,
const struct timeval *e)
{
@@ -37,6 +39,66 @@ static unsigned long long mtime_since_now(struct timeval *tv)
return mtime_since(tv, &end);
}
+/*
+ * Test that we return to userspace if a timeout triggers, even if we
+ * don't satisfy the number of events asked for.
+ */
+static int test_single_timeout_many(struct io_uring *ring)
+{
+ struct io_uring_cqe *cqe;
+ struct io_uring_sqe *sqe;
+ unsigned long long exp;
+ struct timespec ts;
+ struct timeval tv;
+ int ret;
+
+ sqe = io_uring_get_sqe(ring);
+ if (!sqe) {
+ printf("get sqe failed\n");
+ goto err;
+ }
+
+ ts.tv_sec = TIMEOUT_MSEC / 1000;
+ ts.tv_nsec = 0;
+ io_uring_prep_timeout(sqe, &ts);
+
+ ret = io_uring_submit(ring);
+ if (ret <= 0) {
+ printf("sqe submit failed: %d\n", ret);
+ goto err;
+ }
+
+ gettimeofday(&tv, NULL);
+ ret = io_uring_enter(ring->ring_fd, 0, 4, IORING_ENTER_GETEVENTS, NULL);
+ if (ret < 0) {
+ printf("io_uring_enter %d\n", ret);
+ goto err;
+ }
+
+ ret = io_uring_wait_cqe(ring, &cqe);
+ if (ret < 0) {
+ printf("wait completion %d\n", ret);
+ goto err;
+ }
+ if (cqe->res == -EINVAL)
+ printf("Timeout not supported, ignored\n");
+ else if (cqe->res != 0) {
+ printf("Timeout: %s\n", strerror(-cqe->res));
+ goto err;
+ }
+ io_uring_cqe_seen(ring, cqe);
+
+ 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 single timeout waking us up
+ */
static int test_single_timeout(struct io_uring *ring)
{
struct io_uring_cqe *cqe;
@@ -51,7 +113,6 @@ static int test_single_timeout(struct io_uring *ring)
printf("get sqe failed\n");
goto err;
}
-#define TIMEOUT_MSEC 1000
ts.tv_sec = TIMEOUT_MSEC / 1000;
ts.tv_nsec = 0;
@@ -103,5 +164,11 @@ int main(int argc, char *argv[])
return ret;
}
+ ret = test_single_timeout_many(&ring);
+ if (ret) {
+ printf("test_single_timeout_many failed\n");
+ return ret;
+ }
+
return 0;
}