public inbox for [email protected]
 help / color / mirror / Atom feed
From: Bart Van Assche <[email protected]>
To: Jens Axboe <[email protected]>
Cc: [email protected], Bart Van Assche <[email protected]>
Subject: [PATCH liburing 4/7] Add a C++ unit test
Date: Sun, 28 Jun 2020 12:58:20 -0700	[thread overview]
Message-ID: <[email protected]> (raw)
In-Reply-To: <[email protected]>

Since the liburing header files support C++ compilers, add a C++ unit test.
This helps to verify C++ compatibility of the liburing header files.

Signed-off-by: Bart Van Assche <[email protected]>
---
 test/Makefile       | 12 ++++++++++++
 test/sq-full-cpp.cc | 45 +++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 57 insertions(+)
 create mode 100644 test/sq-full-cpp.cc

diff --git a/test/Makefile b/test/Makefile
index e103296fabdd..c80ad421a938 100644
--- a/test/Makefile
+++ b/test/Makefile
@@ -8,6 +8,7 @@ XCFLAGS =
 override CFLAGS += -Wall -Wextra -Wno-unused-parameter -Wno-sign-compare\
 	-D_GNU_SOURCE -D__SANE_USERSPACE_TYPES__ -L../src/ \
 	-I../src/include/ -include ../config-host.h
+CXXFLAGS += $(CFLAGS) -std=c++11
 
 all_targets += poll poll-cancel ring-leak fsync io_uring_setup io_uring_register \
 	       io_uring_enter nop sq-full cq-full 35fa71a030ca-test \
@@ -36,11 +37,18 @@ ifdef CONFIG_HAVE_STATX
 all_targets += statx
 endif
 
+ifdef CONFIG_HAVE_CXX
+all_targets += sq-full-cpp
+endif
+
 all: $(all_targets)
 
 %: %.c
 	$(QUIET_CC)$(CC) $(CFLAGS) -o $@ $< -luring $(XCFLAGS)
 
+%: %.cc
+	$(QUIET_CC)$(CXX) $(CXXFLAGS) -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 \
 	35fa71a030ca-test.c 917257daa0fe-test.c b19062a56726-test.c \
@@ -63,6 +71,10 @@ ifdef CONFIG_HAVE_STATX
 test_srcs += statx.c
 endif
 
+ifdef CONFIG_HAVE_CXX
+test_srcs += sq-full-cpp
+endif
+
 test_objs := $(patsubst %.c,%.ol,$(test_srcs))
 
 35fa71a030ca-test: XCFLAGS = -lpthread
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 <errno.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <string.h>
+#include <fcntl.h>
+
+#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;
+}

  parent reply	other threads:[~2020-06-28 19:58 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-06-28 19:58 [PATCH liburing 0/7] C++ and Travis patches Bart Van Assche
2020-06-28 19:58 ` [PATCH liburing 1/7] src/Makefile: Only specify -shared at link time Bart Van Assche
2020-06-28 19:58 ` [PATCH liburing 2/7] src/include/liburing/barrier.h: Restore clang compatibility Bart Van Assche
2020-06-28 19:58 ` [PATCH liburing 3/7] Make the liburing header files again compatible with C++ Bart Van Assche
2020-06-28 19:58 ` Bart Van Assche [this message]
2020-06-28 19:58 ` [PATCH liburing 5/7] configure: Use $CC and $CXX as default compilers if set Bart Van Assche
2020-06-28 19:58 ` [PATCH liburing 6/7] .travis.yml: Change the language from C to C++ Bart Van Assche
2020-06-28 19:58 ` [PATCH liburing 7/7] .travis.yml: Run tests as root and ignore test results Bart Van Assche
2020-06-28 20:04 ` [PATCH liburing 0/7] C++ and Travis patches Jens Axboe

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    [email protected] \
    [email protected] \
    [email protected] \
    [email protected] \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox