summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorJens Axboe <axboe@kernel.dk>2019-09-23 11:02:14 -0600
committerJens Axboe <axboe@kernel.dk>2019-09-23 11:02:14 -0600
commit556960942eaa69fd53544932f00db3fa9f196e00 (patch)
tree16c2f9b850410453c3df7c1d286660c6eb590e17 /test
parent1cff0db7bc315c02774e3345243a21763d73dada (diff)
downloadliburing-556960942eaa69fd53544932f00db3fa9f196e00.tar.gz
liburing-556960942eaa69fd53544932f00db3fa9f196e00.tar.bz2
Add STDOUT write test
This will fail if we don't support non ->write_iter() fops. Signed-off-by: Jens Axboe <axboe@kernel.dk>
Diffstat (limited to 'test')
-rw-r--r--test/Makefile4
-rw-r--r--test/stdout.c78
2 files changed, 80 insertions, 2 deletions
diff --git a/test/Makefile b/test/Makefile
index 2b77dfe..54052a7 100644
--- a/test/Makefile
+++ b/test/Makefile
@@ -6,7 +6,7 @@ all_targets += poll poll-cancel ring-leak fsync io_uring_setup io_uring_register
io_uring_enter nop sq-full cq-full 35fa71a030ca-test \
917257daa0fe-test b19062a56726-test eeed8b54e0df-test link \
send_recvmsg a4c0b3decb33-test 500f9fbadef8-test timeout \
- sq-space_left
+ sq-space_left stdout
include ../Makefile.quiet
@@ -19,7 +19,7 @@ test_srcs := poll.c poll-cancel.c ring-leak.c fsync.c io_uring_setup.c \
io_uring_register.c io_uring_enter.c nop.c sq-full.c cq-full.c \
35fa71a030ca-test.c 917257daa0fe-test.c b19062a56726-test.c \
eeed8b54e0df-test.c link.c send_recvmsg.c a4c0b3decb33-test.c \
- 500f9fbadef8-test.c timeout.c sq-space_left.c
+ 500f9fbadef8-test.c timeout.c sq-space_left.c stdout.c
test_objs := $(patsubst %.c,%.ol,$(test_srcs))
diff --git a/test/stdout.c b/test/stdout.c
new file mode 100644
index 0000000..7b64c8c
--- /dev/null
+++ b/test/stdout.c
@@ -0,0 +1,78 @@
+/*
+ * Description: check that STDOUT write works
+ */
+#include <errno.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <string.h>
+#include <fcntl.h>
+
+#include "liburing.h"
+
+static int test_pipe_io(struct io_uring *ring)
+{
+ struct io_uring_cqe *cqe;
+ struct io_uring_sqe *sqe;
+ struct iovec vecs;
+ int ret;
+
+ vecs.iov_base = "This is a pipe test\n";
+ vecs.iov_len = strlen(vecs.iov_base);
+
+ sqe = io_uring_get_sqe(ring);
+ if (!sqe) {
+ printf("get sqe failed\n");
+ goto err;
+ }
+ io_uring_prep_writev(sqe, STDOUT_FILENO, &vecs, 1, 0);
+
+ ret = io_uring_submit(ring);
+ if (ret < 1) {
+ printf("Submitted only %d\n", ret);
+ goto err;
+ } else if (ret < 0) {
+ printf("sqe submit failed: %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 < 0) {
+ printf("STDOUT write error: %s\n", strerror(-cqe->res));
+ goto err;
+ }
+ if (cqe->res != vecs.iov_len) {
+ printf("Got %d write, wanted %d\n", cqe->res, (int)vecs.iov_len);
+ goto err;
+ }
+ io_uring_cqe_seen(ring, cqe);
+
+ return 0;
+err:
+ return 1;
+}
+
+int main(int argc, char *argv[])
+{
+ struct io_uring ring;
+ int ret;
+
+ ret = io_uring_queue_init(8, &ring, 0);
+ if (ret) {
+ printf("ring setup failed\n");
+ return 1;
+
+ }
+
+ ret = test_pipe_io(&ring);
+ if (ret) {
+ printf("test_pipe_io failed\n");
+ return ret;
+ }
+
+ return 0;
+}