summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJens Axboe <axboe@kernel.dk>2019-09-17 12:18:07 -0600
committerJens Axboe <axboe@kernel.dk>2019-09-17 12:18:07 -0600
commite4269d2c10586c03786df24d6382da99a956f03c (patch)
treea1afda823c6d92b3c4d12a913bae2e58a66639f0
parent4652762d5be96e08a0ff8194de1e6f6d8127cee5 (diff)
downloadliburing-e4269d2c10586c03786df24d6382da99a956f03c.tar.gz
liburing-e4269d2c10586c03786df24d6382da99a956f03c.tar.bz2
test/timeout: include some notion of verifying length of timeout
In my testing, we're always right on 1000 msec, but allow some slack and just judge it good if we're within +- 50%. Signed-off-by: Jens Axboe <axboe@kernel.dk>
-rw-r--r--test/timeout.c39
1 files changed, 36 insertions, 3 deletions
diff --git a/test/timeout.c b/test/timeout.c
index 0d9e447..960d85d 100644
--- a/test/timeout.c
+++ b/test/timeout.c
@@ -8,14 +8,42 @@
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
+#include <sys/time.h>
#include "liburing.h"
+static unsigned long long mtime_since(const struct timeval *s,
+ const struct timeval *e)
+{
+ long long sec, usec;
+
+ sec = e->tv_sec - s->tv_sec;
+ usec = (e->tv_usec - s->tv_usec);
+ if (sec > 0 && usec < 0) {
+ sec--;
+ usec += 1000000;
+ }
+
+ sec *= 1000;
+ usec /= 1000;
+ return sec + usec;
+}
+
+static unsigned long long mtime_since_now(struct timeval *tv)
+{
+ struct timeval end;
+
+ gettimeofday(&end, NULL);
+ return mtime_since(tv, &end);
+}
+
static int test_single_timeout(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);
@@ -23,8 +51,9 @@ static int test_single_timeout(struct io_uring *ring)
printf("get sqe failed\n");
goto err;
}
+#define TIMEOUT_MSEC 1000
- ts.tv_sec = 1;
+ ts.tv_sec = TIMEOUT_MSEC / 1000;
ts.tv_nsec = 0;
io_uring_prep_timeout(sqe, &ts);
@@ -34,6 +63,7 @@ static int test_single_timeout(struct io_uring *ring)
goto err;
}
+ gettimeofday(&tv, NULL);
ret = io_uring_wait_cqe(ring, &cqe);
if (ret < 0) {
printf("wait completion %d\n", ret);
@@ -45,9 +75,12 @@ static int test_single_timeout(struct io_uring *ring)
printf("Timeout: %s\n", strerror(-cqe->res));
goto err;
}
-
io_uring_cqe_seen(ring, cqe);
- return 0;
+
+ 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;
}