summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJens Axboe <axboe@kernel.dk>2019-05-14 19:08:37 -0600
committerJens Axboe <axboe@kernel.dk>2019-05-14 19:08:37 -0600
commit1982bfd44dc3b4b6dad7885fbf708d2bf1dc7ebf (patch)
tree26354cbe073f753ad58f45c6126054dd5bb0bbbc
parent0ba9503f793647bfd967da8083a2adf56621307c (diff)
Add chain failure handling test case
Signed-off-by: Jens Axboe <axboe@kernel.dk>
-rw-r--r--examples/link-cp.c3
-rw-r--r--test/link.c79
2 files changed, 78 insertions, 4 deletions
diff --git a/examples/link-cp.c b/examples/link-cp.c
index c747966..993d3a6 100644
--- a/examples/link-cp.c
+++ b/examples/link-cp.c
@@ -82,6 +82,9 @@ static void handle_cqe(struct io_uring_cqe *cqe)
{
struct io_data *data;
+ if (cqe->res < 0)
+ printf("cqe error: %s\n", strerror(cqe->res));
+
data = io_uring_cqe_get_data(cqe);
if (!data)
return;
diff --git a/test/link.c b/test/link.c
index b656bb2..e7ca3e3 100644
--- a/test/link.c
+++ b/test/link.c
@@ -12,6 +12,64 @@
#include "../src/liburing.h"
/*
+ * Test failing head of chain, and dependent getting -ECANCELED
+ */
+static int test_single_link_fail(struct io_uring *ring)
+{
+ 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 = io_uring_get_sqe(ring);
+ if (!sqe) {
+ printf("get sqe failed\n");
+ goto err;
+ }
+
+ io_uring_prep_nop(sqe);
+
+ ret = io_uring_submit(ring);
+ if (ret <= 0) {
+ printf("sqe submit failed: %d\n", ret);
+ goto err;
+ }
+
+ for (i = 0; i < 2; i++) {
+ ret = io_uring_peek_cqe(ring, &cqe);
+ if (ret < 0) {
+ printf("wait completion %d\n", ret);
+ goto err;
+ }
+ if (!cqe) {
+ printf("failed to get cqe\n");
+ goto err;
+ }
+ if (i == 0 && cqe->res != -EINVAL) {
+ printf("sqe0 failed with %d, wanted -EINVAL\n", cqe->res);
+ goto err;
+ }
+ if (i == 1 && cqe->res != -ECANCELED) {
+ printf("sqe0 failed with %d, wanted -ECANCELED\n", cqe->res);
+ goto err;
+ }
+ io_uring_cqe_seen(ring, cqe);
+ }
+
+ return 0;
+err:
+ return 1;
+}
+
+/*
* Test two independent chains
*/
static int test_double_chain(struct io_uring *ring)
@@ -53,7 +111,7 @@ static int test_double_chain(struct io_uring *ring)
}
io_uring_prep_nop(sqe);
-
+
ret = io_uring_submit(ring);
if (ret <= 0) {
printf("sqe submit failed: %d\n", ret);
@@ -108,7 +166,7 @@ static int test_double_link(struct io_uring *ring)
}
io_uring_prep_nop(sqe);
-
+
ret = io_uring_submit(ring);
if (ret <= 0) {
printf("sqe submit failed: %d\n", ret);
@@ -154,7 +212,7 @@ static int test_single_link(struct io_uring *ring)
}
io_uring_prep_nop(sqe);
-
+
ret = io_uring_submit(ring);
if (ret <= 0) {
printf("sqe submit failed: %d\n", ret);
@@ -177,7 +235,7 @@ err:
int main(int argc, char *argv[])
{
- struct io_uring ring;
+ struct io_uring ring, poll_ring;
int ret;
ret = io_uring_queue_init(8, &ring, 0);
@@ -187,6 +245,13 @@ int main(int argc, char *argv[])
}
+ ret = io_uring_queue_init(8, &poll_ring, IORING_SETUP_IOPOLL);
+ if (ret) {
+ printf("poll_ring setup failed\n");
+ return 1;
+
+ }
+
ret = test_single_link(&ring);
if (ret) {
printf("test_single_link failed\n");
@@ -205,5 +270,11 @@ int main(int argc, char *argv[])
return ret;
}
+ ret = test_single_link_fail(&poll_ring);
+ if (ret) {
+ printf("test_single_link_fail failed\n");
+ return ret;
+ }
+
return 0;
}