From: Pavel Begunkov <[email protected]>
To: [email protected]
Cc: Jens Axboe <[email protected]>, [email protected]
Subject: [PATCH liburing v2 2/2] tests: test IORING_SETUP_SINGLE_ISSUER
Date: Fri, 22 Jul 2022 11:37:06 +0100 [thread overview]
Message-ID: <54af31b0b34fea289dc82ac228ec0cabed408cb6.1658484803.git.asml.silence@gmail.com> (raw)
In-Reply-To: <[email protected]>
Signed-off-by: Pavel Begunkov <[email protected]>
---
test/Makefile | 1 +
test/single-issuer.c | 153 +++++++++++++++++++++++++++++++++++++++++++
2 files changed, 154 insertions(+)
create mode 100644 test/single-issuer.c
diff --git a/test/Makefile b/test/Makefile
index e958a35..8945368 100644
--- a/test/Makefile
+++ b/test/Makefile
@@ -174,6 +174,7 @@ test_srcs := \
wakeup-hang.c \
xattr.c \
skip-cqe.c \
+ single-issuer.c \
# EOL
all_targets :=
diff --git a/test/single-issuer.c b/test/single-issuer.c
new file mode 100644
index 0000000..3bbc6c4
--- /dev/null
+++ b/test/single-issuer.c
@@ -0,0 +1,153 @@
+/* SPDX-License-Identifier: MIT */
+#include <errno.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <string.h>
+#include <fcntl.h>
+#include <error.h>
+#include <sys/types.h>
+#include <sys/wait.h>
+
+#include "liburing.h"
+#include "test.h"
+#include "helpers.h"
+
+static pid_t pid;
+
+static pid_t fork_t(void)
+{
+ pid = fork();
+ if (pid == -1) {
+ fprintf(stderr, "fork failed\n");
+ exit(T_EXIT_FAIL);
+ }
+ return pid;
+}
+
+static void wait_child_t(void)
+{
+ int wstatus;
+
+ if (waitpid(pid, &wstatus, 0) == (pid_t)-1) {
+ perror("waitpid()");
+ exit(T_EXIT_FAIL);
+ }
+ if (!WIFEXITED(wstatus)) {
+ fprintf(stderr, "child failed %i\n", WEXITSTATUS(wstatus));
+ exit(T_EXIT_FAIL);
+ }
+ if (WEXITSTATUS(wstatus))
+ exit(T_EXIT_FAIL);
+}
+
+static int try_submit(struct io_uring *ring)
+{
+ struct io_uring_cqe *cqe;
+ struct io_uring_sqe *sqe;
+ int ret;
+
+ sqe = io_uring_get_sqe(ring);
+ io_uring_prep_nop(sqe);
+ sqe->user_data = 42;
+
+ ret = io_uring_submit(ring);
+ if (ret < 0)
+ return ret;
+
+ if (ret != 1)
+ error(1, ret, "submit %i", ret);
+ ret = io_uring_wait_cqe(ring, &cqe);
+ if (ret)
+ error(1, ret, "wait fail %i", ret);
+
+ if (cqe->res || cqe->user_data != 42)
+ error(1, ret, "invalid cqe");
+
+ io_uring_cqe_seen(ring, cqe);
+ return 0;
+}
+
+int main(int argc, char *argv[])
+{
+ struct io_uring ring;
+ int ret;
+
+ if (argc > 1)
+ return T_EXIT_SKIP;
+
+ ret = io_uring_queue_init(8, &ring, IORING_SETUP_SINGLE_ISSUER);
+ if (ret == -EINVAL) {
+ fprintf(stderr, "SETUP_SINGLE_ISSUER is not supported, skip\n");
+ return T_EXIT_SKIP;
+ } else if (ret) {
+ fprintf(stderr, "io_uring_queue_init() failed %i\n", ret);
+ return T_EXIT_FAIL;
+ }
+
+ /* test that the creator iw allowed to submit */
+ ret = try_submit(&ring);
+ if (ret) {
+ fprintf(stderr, "the creater can't submit %i\n", ret);
+ return T_EXIT_FAIL;
+ }
+
+ /* test that a second submitter doesn't succeed */
+ if (!fork_t()) {
+ ret = try_submit(&ring);
+ if (ret != -EEXIST)
+ fprintf(stderr, "not owner child could submit %i\n", ret);
+ return ret != -EEXIST;
+ }
+ wait_child_t();
+ io_uring_queue_exit(&ring);
+
+ /* test that the first submitter but not creator can submit */
+ ret = io_uring_queue_init(8, &ring, IORING_SETUP_SINGLE_ISSUER);
+ if (ret)
+ error(1, ret, "ring init (2) %i", ret);
+
+ if (!fork_t()) {
+ ret = try_submit(&ring);
+ if (ret)
+ fprintf(stderr, "not owner child could submit %i\n", ret);
+ return !!ret;
+ }
+ wait_child_t();
+ io_uring_queue_exit(&ring);
+
+ /* test that anyone can submit to a SQPOLL|SINGLE_ISSUER ring */
+ ret = io_uring_queue_init(8, &ring, IORING_SETUP_SINGLE_ISSUER|IORING_SETUP_SQPOLL);
+ if (ret)
+ error(1, ret, "ring init (3) %i", ret);
+
+ ret = try_submit(&ring);
+ if (ret) {
+ fprintf(stderr, "SQPOLL submit failed (creator) %i\n", ret);
+ return T_EXIT_FAIL;
+ }
+
+ if (!fork_t()) {
+ ret = try_submit(&ring);
+ if (ret)
+ fprintf(stderr, "SQPOLL submit failed (child) %i\n", ret);
+ return !!ret;
+ }
+ wait_child_t();
+ io_uring_queue_exit(&ring);
+
+ /* test that IORING_ENTER_REGISTERED_RING doesn't break anything */
+ ret = io_uring_queue_init(8, &ring, IORING_SETUP_SINGLE_ISSUER);
+ if (ret)
+ error(1, ret, "ring init (4) %i", ret);
+
+ if (!fork_t()) {
+ ret = try_submit(&ring);
+ if (ret)
+ fprintf(stderr, "not owner child could submit %i\n", ret);
+ return !!ret;
+ }
+ wait_child_t();
+ io_uring_queue_exit(&ring);
+ return T_EXIT_PASS;
+}
--
2.37.0
next prev parent reply other threads:[~2022-07-22 10:38 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-07-22 10:37 [PATCH liburing v2 0/2] single issuer tests and poll bench Pavel Begunkov
2022-07-22 10:37 ` [PATCH liburing v2 1/2] examples: add a simple single-shot poll benchmark Pavel Begunkov
2022-07-22 10:37 ` Pavel Begunkov [this message]
2022-07-22 15:21 ` [PATCH liburing v2 0/2] single issuer tests and poll bench 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 \
--in-reply-to=54af31b0b34fea289dc82ac228ec0cabed408cb6.1658484803.git.asml.silence@gmail.com \
[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