summaryrefslogtreecommitdiff
path: root/test/timeout.c
diff options
context:
space:
mode:
authorJens Axboe <axboe@kernel.dk>2019-09-20 22:15:38 -0600
committerJens Axboe <axboe@kernel.dk>2019-09-20 22:15:38 -0600
commit095bafc04ef9b72ebfcf61c5665ca1267542381f (patch)
tree4ef14f48a26cf17cd04ac8802e986db27f03120d /test/timeout.c
parentd5bb23be626387b11edc35d36b2571c34e7013f4 (diff)
downloadliburing-095bafc04ef9b72ebfcf61c5665ca1267542381f.tar.gz
liburing-095bafc04ef9b72ebfcf61c5665ca1267542381f.tar.bz2
Test support for timed waittimeout
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Diffstat (limited to 'test/timeout.c')
-rw-r--r--test/timeout.c57
1 files changed, 57 insertions, 0 deletions
diff --git a/test/timeout.c b/test/timeout.c
index 641f4ac..00581e0 100644
--- a/test/timeout.c
+++ b/test/timeout.c
@@ -177,6 +177,57 @@ err:
return 1;
}
+static int test_single_timeout_wait(struct io_uring *ring)
+{
+ struct io_uring_cqe *cqe;
+ struct io_uring_sqe *sqe;
+ struct timespec ts;
+ int i, ret;
+
+ sqe = io_uring_get_sqe(ring);
+ io_uring_prep_nop(sqe);
+ io_uring_sqe_set_data(sqe, (void *) 1);
+
+ sqe = io_uring_get_sqe(ring);
+ io_uring_prep_nop(sqe);
+ io_uring_sqe_set_data(sqe, (void *) 1);
+
+ ret = io_uring_submit(ring);
+ if (ret <= 0) {
+ printf("sqe submit failed: %d\n", ret);
+ goto err;
+ }
+
+ ts.tv_sec = 1;
+ ts.tv_nsec = 0;
+
+ i = 0;
+ do {
+ ret = io_uring_wait_cqe_timeout(ring, &cqe, &ts);
+ if (ret == -ETIME)
+ break;
+ if (ret < 0) {
+ printf("wait timeout failed: %d\n", ret);
+ goto err;
+ }
+
+ if (cqe->res < 0) {
+ printf("res: %d\n", cqe->res);
+ goto err;
+ }
+ io_uring_cqe_seen(ring, cqe);
+ i++;
+ } while (1);
+
+ if (i != 2) {
+ printf("got %d completions\n", i);
+ goto err;
+ }
+ return 0;
+err:
+ return 1;
+}
+
/*
* Test single timeout waking us up
*/
@@ -293,6 +344,12 @@ int main(int argc, char *argv[])
return ret;
}
+ ret = test_single_timeout_wait(&ring);
+ if (ret) {
+ printf("test_single_timeout_wait failed\n");
+ return ret;
+ }
+
/*
* this test must go last, it kills the ring
*/