summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorJames Rouzier <rouzier@gmail.com>2019-09-25 15:35:06 -0400
committerJames Rouzier <rouzier@gmail.com>2019-09-25 20:11:50 -0400
commit0b88d72b1a4bbf0a90da2067f489fbb788dc1e92 (patch)
treed877b5fe9c8093771105d23e0b042de8b632338a /test
parent46850c3a617e361c133c4da3d6e3069807ebe2b7 (diff)
downloadliburing-0b88d72b1a4bbf0a90da2067f489fbb788dc1e92.tar.gz
liburing-0b88d72b1a4bbf0a90da2067f489fbb788dc1e92.tar.bz2
Add io_uring_peek_batch_cqe()
io_uring_peek_batch_cqe(), get multiple cqe from the queue at once. Returns the number of cqe gotten. test/cq-peek-batch.c: tests io_uring_peek_batch_cqe() Signed-off-by: James Rouzier <rouzier@gmail.com>
Diffstat (limited to 'test')
-rw-r--r--test/Makefile5
-rw-r--r--test/cq-peek-batch.c96
2 files changed, 99 insertions, 2 deletions
diff --git a/test/Makefile b/test/Makefile
index 65dbb8c..4710b30 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 stdout cq-ready
+ sq-space_left stdout cq-ready cq-peek-batch
include ../Makefile.quiet
@@ -19,7 +19,8 @@ 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 stdout.c cq-ready.c
+ 500f9fbadef8-test.c timeout.c sq-space_left.c stdout.c cq-ready.c\
+ cq-peek-batch.c
test_objs := $(patsubst %.c,%.ol,$(test_srcs))
diff --git a/test/cq-peek-batch.c b/test/cq-peek-batch.c
new file mode 100644
index 0000000..e0a765e
--- /dev/null
+++ b/test/cq-peek-batch.c
@@ -0,0 +1,96 @@
+/*
+ * Description: test CQ peek-batch
+ *
+ */
+#include <errno.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <string.h>
+#include <fcntl.h>
+
+#include "liburing.h"
+
+static int queue_n_nops(struct io_uring *ring, int n, int offset)
+{
+ struct io_uring_sqe *sqe;
+ int i, ret;
+
+ for (i = 0; i < n; i++) {
+ sqe = io_uring_get_sqe(ring);
+ if (!sqe) {
+ printf("get sqe failed\n");
+ goto err;
+ }
+
+ io_uring_prep_nop(sqe);
+ sqe->user_data = i + offset;
+ }
+
+ ret = io_uring_submit(ring);
+ if (ret < n) {
+ printf("Submitted only %d\n", ret);
+ goto err;
+ } else if (ret < 0) {
+ printf("sqe submit failed: %d\n", ret);
+ goto err;
+ }
+
+ return 0;
+err:
+ return 1;
+}
+
+#define CHECK_BATCH(ring, got, cqes, count, expected) do {\
+ got = io_uring_peek_batch_cqe((ring), cqes, count);\
+ if (got != expected) {\
+ printf("Got %d CQs, expected %d\n", got, expected);\
+ goto err;\
+ }\
+} while(0)
+
+int main(int argc, char *argv[])
+{
+ struct io_uring_cqe *cqes[8];
+ struct io_uring ring;
+ int ret, i;
+ unsigned got;
+
+ ret = io_uring_queue_init(4, &ring, 0);
+ if (ret) {
+ printf("ring setup failed\n");
+ return 1;
+
+ }
+
+ CHECK_BATCH(&ring, got, cqes, 4, 0);
+ if (queue_n_nops(&ring, 4, 0))
+ goto err;
+
+ CHECK_BATCH(&ring, got, cqes, 4, 4);
+ for (i=0;i<4;i++) {
+ if (i != cqes[i]->user_data) {
+ printf("Got user_data %lld, expected %d\n", cqes[i]->user_data, i);
+ goto err;
+ }
+ }
+
+ if (queue_n_nops(&ring, 4, 4))
+ goto err;
+
+ io_uring_cq_advance(&ring, 4);
+ CHECK_BATCH(&ring, got, cqes, 4, 4);
+ for (i=0;i<4;i++) {
+ if (i + 4 != cqes[i]->user_data) {
+ printf("Got user_data %lld, expected %d\n", cqes[i]->user_data, i + 4);
+ goto err;
+ }
+ }
+
+ io_uring_cq_advance(&ring, 8);
+ io_uring_queue_exit(&ring);
+ return 0;
+err:
+ io_uring_queue_exit(&ring);
+ return 1;
+}