From 0b896d7bf992caadde8f0c4d57478800b2261507 Mon Sep 17 00:00:00 2001 From: Bart Van Assche Date: Sat, 27 Jun 2020 09:09:59 -0700 Subject: [PATCH liburing 2/2] Add a C++ unit test Since the liburing header files support C++ compilers, add a C++ unit test. Signed-off-by: Bart Van Assche --- test/Makefile | 9 +++++++-- test/sq-full-cpp.cc | 45 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+), 2 deletions(-) create mode 100644 test/sq-full-cpp.cc diff --git a/test/Makefile b/test/Makefile index e103296fabdd..8b81d2d5f67c 100644 --- a/test/Makefile +++ b/test/Makefile @@ -10,7 +10,8 @@ override CFLAGS += -Wall -Wextra -Wno-unused-parameter -Wno-sign-compare\ -I../src/include/ -include ../config-host.h all_targets += poll poll-cancel ring-leak fsync io_uring_setup io_uring_register \ - io_uring_enter nop sq-full cq-full 35fa71a030ca-test \ + io_uring_enter nop sq-full sq-full-cpp cq-full \ + 35fa71a030ca-test \ 917257daa0fe-test b19062a56726-test eeed8b54e0df-test link \ send_recvmsg a4c0b3decb33-test 500f9fbadef8-test timeout \ sq-space_left stdout cq-ready cq-peek-batch file-register \ @@ -41,8 +42,12 @@ all: $(all_targets) %: %.c $(QUIET_CC)$(CC) $(CFLAGS) -o $@ $< -luring $(XCFLAGS) +%: %.cc + $(QUIET_CC)$(CXX) $(CFLAGS) -o $@ $< -luring $(XCFLAGS) + 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 \ + io_uring_register.c io_uring_enter.c nop.c sq-full.c sq-full-cpp.cc \ + 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\ diff --git a/test/sq-full-cpp.cc b/test/sq-full-cpp.cc new file mode 100644 index 000000000000..ba400996e615 --- /dev/null +++ b/test/sq-full-cpp.cc @@ -0,0 +1,45 @@ +/* SPDX-License-Identifier: MIT */ +/* + * Description: test SQ queue full condition + * + */ +#include +#include +#include +#include +#include +#include + +#include "liburing.h" + +int main(int argc, char *argv[]) +{ + struct io_uring_sqe *sqe; + struct io_uring ring; + int ret, i; + + if (argc > 1) + return 0; + + ret = io_uring_queue_init(8, &ring, 0); + if (ret) { + fprintf(stderr, "ring setup failed: %d\n", ret); + return 1; + + } + + i = 0; + while ((sqe = io_uring_get_sqe(&ring)) != NULL) + i++; + + if (i != 8) { + fprintf(stderr, "Got %d SQEs, wanted 8\n", i); + goto err; + } + + io_uring_queue_exit(&ring); + return 0; +err: + io_uring_queue_exit(&ring); + return 1; +}