From: Pavel Begunkov <[email protected]>
To: [email protected]
Cc: Jens Axboe <[email protected]>, [email protected]
Subject: [PATCH liburing 5/5] tests/msg_ring: remote submit to a deferred tw ring
Date: Tue, 24 Jan 2023 01:21:49 +0000 [thread overview]
Message-ID: <6aabba6058e0029104174379c4c3135d6af835f5.1674523156.git.asml.silence@gmail.com> (raw)
In-Reply-To: <[email protected]>
Test sending messages to a deferred ring from another task
Signed-off-by: Pavel Begunkov <[email protected]>
---
test/msg-ring.c | 80 ++++++++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 79 insertions(+), 1 deletion(-)
diff --git a/test/msg-ring.c b/test/msg-ring.c
index 495c127..cb6687f 100644
--- a/test/msg-ring.c
+++ b/test/msg-ring.c
@@ -146,6 +146,79 @@ err:
return 1;
}
+static void *remote_submit_fn(void *data)
+{
+ struct io_uring_sqe *sqe;
+ struct io_uring_cqe *cqe;
+ struct io_uring *target = data;
+ struct io_uring ring;
+ int ret;
+
+ ret = io_uring_queue_init(8, &ring, 0);
+ if (ret) {
+ fprintf(stderr, "thread ring setup failed: %d\n", ret);
+ goto err;
+ }
+ sqe = io_uring_get_sqe(&ring);
+ if (!sqe) {
+ fprintf(stderr, "get sqe failed\n");
+ goto err;
+ }
+
+ io_uring_prep_msg_ring(sqe, target->ring_fd, 0x20, 0x5aa5, 0);
+ sqe->user_data = 1;
+
+ ret = io_uring_submit(&ring);
+ if (ret <= 0) {
+ fprintf(stderr, "sqe submit failed: %d\n", ret);
+ goto err;
+ }
+
+ ret = io_uring_wait_cqe(&ring, &cqe);
+ if (ret < 0) {
+ fprintf(stderr, "wait completion %d\n", ret);
+ goto err;
+ }
+ if (cqe->res != 0 || cqe->user_data != 1) {
+ fprintf(stderr, "invalid cqe\n");
+ goto err;
+ }
+ io_uring_cqe_seen(&ring, cqe);
+ io_uring_queue_exit(&ring);
+ return NULL;
+err:
+ return (void *) (unsigned long) 1;
+}
+
+static int test_remote_submit(struct io_uring *target)
+{
+ struct io_uring_cqe *cqe;
+ pthread_t thread;
+ void *tret;
+ int ret;
+
+ pthread_create(&thread, NULL, remote_submit_fn, target);
+
+ ret = io_uring_wait_cqe(target, &cqe);
+ if (ret < 0) {
+ fprintf(stderr, "wait completion %d\n", ret);
+ goto err;
+ }
+ if (cqe->res != 0x20) {
+ fprintf(stderr, "cqe res %d\n", cqe->res);
+ return -1;
+ }
+ if (cqe->user_data != 0x5aa5) {
+ fprintf(stderr, "user_data %llx\n", (long long) cqe->user_data);
+ return -1;
+ }
+ io_uring_cqe_seen(target, cqe);
+ pthread_join(thread, &tret);
+ return 0;
+err:
+ return 1;
+}
+
static int test_invalid(struct io_uring *ring, bool fixed)
{
struct io_uring_cqe *cqe;
@@ -322,6 +395,12 @@ int main(int argc, char *argv[])
return T_EXIT_FAIL;
}
}
+
+ ret = test_remote_submit(&ring);
+ if (ret) {
+ fprintf(stderr, "test_remote_submit failed\n");
+ return T_EXIT_FAIL;
+ }
io_uring_queue_exit(&ring);
if (test_disabled_ring(&ring2, 0)) {
@@ -334,7 +413,6 @@ int main(int argc, char *argv[])
fprintf(stderr, "test_disabled_ring defer failed\n");
return T_EXIT_FAIL;
}
-
}
io_uring_queue_exit(&ring2);
--
2.38.1
next prev parent reply other threads:[~2023-01-24 1:24 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-01-24 1:21 [PATCH liburing 0/5] deferred tw msg_ring tests Pavel Begunkov
2023-01-24 1:21 ` [PATCH liburing 1/5] tests/msg_ring: use correct exit codes Pavel Begunkov
2023-01-24 1:21 ` [PATCH liburing 2/5] tests/msg_ring: test msg_ring with deferred tw Pavel Begunkov
2023-01-24 1:21 ` [PATCH liburing 3/5] test/msg_ring: test msg_ring to a disabled ring Pavel Begunkov
2023-01-24 1:21 ` [PATCH liburing 4/5] tests/msg_ring: refactor test_remote Pavel Begunkov
2023-01-24 1:21 ` Pavel Begunkov [this message]
2023-01-24 2:31 ` [PATCH liburing 0/5] deferred tw msg_ring tests 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=6aabba6058e0029104174379c4c3135d6af835f5.1674523156.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