summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJens Axboe <axboe@kernel.dk>2019-11-20 08:33:52 -0700
committerJens Axboe <axboe@kernel.dk>2019-11-20 08:33:52 -0700
commit9f9929ef445bab5299a83d48f08038dfc95028b0 (patch)
treef5805807529c6bc2f5cfa3f413a8c6dd1f515592
parent2e7d74490387c62eb2f20e536acb9f5ab761d1aa (diff)
downloadliburing-9f9929ef445bab5299a83d48f08038dfc95028b0.tar.gz
liburing-9f9929ef445bab5299a83d48f08038dfc95028b0.tar.bz2
test/link-timeout: add a few more test cases
Signed-off-by: Jens Axboe <axboe@kernel.dk>
-rw-r--r--test/link-timeout.c201
1 files changed, 191 insertions, 10 deletions
diff --git a/test/link-timeout.c b/test/link-timeout.c
index 46d8e93..c6445d0 100644
--- a/test/link-timeout.c
+++ b/test/link-timeout.c
@@ -588,7 +588,7 @@ static int test_timeout_link_chain1(struct io_uring *ring)
}
switch (cqe->user_data) {
case 1:
- if (cqe->res != -EINTR) {
+ if (cqe->res != -EINTR && cqe->res != -ECANCELED) {
fprintf(stderr, "Req %llu got %d\n", cqe->user_data,
cqe->res);
goto err;
@@ -682,10 +682,22 @@ static int test_timeout_link_chain2(struct io_uring *ring)
switch (cqe->user_data) {
/* poll cancel really should return -ECANCEL... */
case 1:
+ if (cqe->res != -ECANCELED) {
+ fprintf(stderr, "Req %llu got %d\n", cqe->user_data,
+ cqe->res);
+ goto err;
+ }
+ break;
case 2:
+ if (cqe->res != -ETIME) {
+ fprintf(stderr, "Req %llu got %d\n", cqe->user_data,
+ cqe->res);
+ goto err;
+ }
+ break;
case 3:
case 4:
- if (cqe->res) {
+ if (cqe->res != -ECANCELED) {
fprintf(stderr, "Req %llu got %d\n", cqe->user_data,
cqe->res);
goto err;
@@ -726,8 +738,8 @@ static int test_timeout_link_chain3(struct io_uring *ring)
printf("get sqe failed\n");
goto err;
}
- ts.tv_sec = 1;
- ts.tv_nsec = 0;//1000000;
+ ts.tv_sec = 0;
+ ts.tv_nsec = 1000000;
io_uring_prep_link_timeout(sqe, &ts, 0);
sqe->flags |= IOSQE_IO_LINK;
sqe->user_data = 2;
@@ -757,8 +769,8 @@ static int test_timeout_link_chain3(struct io_uring *ring)
printf("get sqe failed\n");
goto err;
}
- ts.tv_sec = 1;
- ts.tv_nsec = 0;//1000000;
+ ts.tv_sec = 0;
+ ts.tv_nsec = 1000000;
io_uring_prep_link_timeout(sqe, &ts, 0);
sqe->user_data = 5;
@@ -787,13 +799,14 @@ static int test_timeout_link_chain3(struct io_uring *ring)
goto err;
}
switch (cqe->user_data) {
- case 1:
- if (cqe->res != -ENOLINK) {
- fprintf(stderr, "Read got %d\n", cqe->res);
+ case 2:
+ if (cqe->res != -ETIME) {
+ fprintf(stderr, "Req %llu got %d\n", cqe->user_data,
+ cqe->res);
goto err;
}
break;
- case 2:
+ case 1:
case 3:
case 4:
case 5:
@@ -819,6 +832,162 @@ err:
return 1;
}
+static int test_timeout_link_chain4(struct io_uring *ring)
+{
+ struct __kernel_timespec ts;
+ struct io_uring_cqe *cqe;
+ struct io_uring_sqe *sqe;
+ int fds[2], ret, i;
+
+ if (pipe(fds)) {
+ perror("pipe");
+ return 1;
+ }
+
+ sqe = io_uring_get_sqe(ring);
+ if (!sqe) {
+ printf("get sqe failed\n");
+ goto err;
+ }
+ io_uring_prep_nop(sqe);
+ sqe->flags |= IOSQE_IO_LINK;
+ sqe->user_data = 1;
+
+ sqe = io_uring_get_sqe(ring);
+ if (!sqe) {
+ printf("get sqe failed\n");
+ goto err;
+ }
+ io_uring_prep_poll_add(sqe, fds[0], POLLIN);
+ sqe->flags |= IOSQE_IO_LINK;
+ sqe->user_data = 2;
+
+ sqe = io_uring_get_sqe(ring);
+ if (!sqe) {
+ printf("get sqe failed\n");
+ goto err;
+ }
+ ts.tv_sec = 0;
+ ts.tv_nsec = 1000000;
+ io_uring_prep_link_timeout(sqe, &ts, 0);
+ sqe->user_data = 3;
+
+ ret = io_uring_submit(ring);
+ if (ret != 3) {
+ printf("sqe submit failed: %d\n", ret);
+ goto err;
+ }
+
+ for (i = 0; i < 3; i++) {
+ ret = io_uring_wait_cqe(ring, &cqe);
+ if (ret < 0) {
+ printf("wait completion %d\n", ret);
+ goto err;
+ }
+ switch (cqe->user_data) {
+ /* poll cancel really should return -ECANCEL... */
+ case 1:
+ if (cqe->res) {
+ fprintf(stderr, "Req %llu got %d\n", cqe->user_data,
+ cqe->res);
+ goto err;
+ }
+ break;
+ case 2:
+ if (cqe->res != -ECANCELED) {
+ fprintf(stderr, "Req %llu got %d\n", cqe->user_data,
+ cqe->res);
+ goto err;
+ }
+ break;
+ case 3:
+ if (cqe->res != -ETIME) {
+ fprintf(stderr, "Req %llu got %d\n", cqe->user_data,
+ cqe->res);
+ goto err;
+ }
+ break;
+ }
+ io_uring_cqe_seen(ring, cqe);
+ }
+
+ return 0;
+err:
+ return 1;
+}
+
+static int test_timeout_link_chain5(struct io_uring *ring)
+{
+ struct __kernel_timespec ts1, ts2;
+ struct io_uring_cqe *cqe;
+ struct io_uring_sqe *sqe;
+ int ret, i;
+
+ sqe = io_uring_get_sqe(ring);
+ if (!sqe) {
+ printf("get sqe failed\n");
+ goto err;
+ }
+ io_uring_prep_nop(sqe);
+ sqe->flags |= IOSQE_IO_LINK;
+ sqe->user_data = 1;
+
+ sqe = io_uring_get_sqe(ring);
+ if (!sqe) {
+ printf("get sqe failed\n");
+ goto err;
+ }
+ ts1.tv_sec = 1;
+ ts1.tv_nsec = 0;
+ io_uring_prep_link_timeout(sqe, &ts1, 0);
+ sqe->flags |= IOSQE_IO_LINK;
+ sqe->user_data = 2;
+
+ sqe = io_uring_get_sqe(ring);
+ if (!sqe) {
+ printf("get sqe failed\n");
+ goto err;
+ }
+ ts2.tv_sec = 2;
+ ts2.tv_nsec = 0;
+ io_uring_prep_link_timeout(sqe, &ts2, 0);
+ sqe->user_data = 3;
+
+ ret = io_uring_submit(ring);
+ if (ret != 3) {
+ printf("sqe submit failed: %d\n", ret);
+ goto err;
+ }
+
+ for (i = 0; i < 3; i++) {
+ ret = io_uring_wait_cqe(ring, &cqe);
+ if (ret < 0) {
+ printf("wait completion %d\n", ret);
+ goto err;
+ }
+ switch (cqe->user_data) {
+ case 1:
+ if (cqe->res) {
+ fprintf(stderr, "Timeout got %d, wanted -EINVAL\n",
+ cqe->res);
+ goto err;
+ }
+ break;
+ case 2:
+ if (cqe->res != -ECANCELED) {
+ fprintf(stderr, "Link timeout got %d, wanted -ECANCELED\n", cqe->res);
+ goto err;
+ }
+ break;
+ }
+ io_uring_cqe_seen(ring, cqe);
+ }
+
+ return 0;
+err:
+ return 1;
+}
+
int main(int argc, char *argv[])
{
struct io_uring ring;
@@ -848,6 +1017,18 @@ int main(int argc, char *argv[])
return ret;
}
+ ret = test_timeout_link_chain4(&ring);
+ if (ret) {
+ printf("test_single_link_chain4 failed\n");
+ return ret;
+ }
+
+ ret = test_timeout_link_chain5(&ring);
+ if (ret) {
+ printf("test_single_link_chain5 failed\n");
+ return ret;
+ }
+
ret = test_single_link_timeout(&ring, 10);
if (ret) {
printf("test_single_link_timeout 10 failed\n");