From: Pavel Begunkov <[email protected]>
To: [email protected]
Cc: Jens Axboe <[email protected]>, [email protected]
Subject: [PATCH liburing 1/3] test: handle test_send_faults()'s cases one by one
Date: Mon, 8 Apr 2024 15:24:20 +0100 [thread overview]
Message-ID: <d9b3f41c15dbe993f7bec1d058c480375f6d852e.1712585927.git.asml.silence@gmail.com> (raw)
In-Reply-To: <[email protected]>
There are 3 different cases tested by test_send_faults(), requests for
which are sent together. That's not too convenient, complicates CQEs
checking and opens some space for error. Do them one at a time.
Signed-off-by: Pavel Begunkov <[email protected]>
---
test/send-zerocopy.c | 105 +++++++++++++++++++++++++++++--------------
1 file changed, 71 insertions(+), 34 deletions(-)
diff --git a/test/send-zerocopy.c b/test/send-zerocopy.c
index 1b6dd77..78ec3d7 100644
--- a/test/send-zerocopy.c
+++ b/test/send-zerocopy.c
@@ -122,17 +122,60 @@ static int test_basic_send(struct io_uring *ring, int sock_tx, int sock_rx)
return T_EXIT_PASS;
}
+static int test_send_faults_check(struct io_uring *ring, int expected)
+{
+ struct io_uring_cqe *cqe;
+ int ret, nr_cqes = 0;
+ bool more = true;
+
+ while (more) {
+ nr_cqes++;
+ ret = io_uring_wait_cqe(ring, &cqe);
+ assert(!ret);
+ assert(cqe->user_data == 1);
+
+ if (nr_cqes == 1 && (cqe->flags & IORING_CQE_F_NOTIF)) {
+ fprintf(stderr, "test_send_faults_check notif came first\n");
+ return -1;
+ }
+
+ if (!(cqe->flags & IORING_CQE_F_NOTIF)) {
+ if (cqe->res != expected) {
+ fprintf(stderr, "invalid cqe res %i vs expected %i, "
+ "user_data %i\n",
+ cqe->res, expected, (int)cqe->user_data);
+ return -1;
+ }
+ } else {
+ if (cqe->res != 0 || cqe->flags != IORING_CQE_F_NOTIF) {
+ fprintf(stderr, "invalid notif cqe %i %i\n",
+ cqe->res, cqe->flags);
+ return -1;
+ }
+ }
+
+ more = cqe->flags & IORING_CQE_F_MORE;
+ io_uring_cqe_seen(ring, cqe);
+ }
+
+ if (nr_cqes > 2) {
+ fprintf(stderr, "test_send_faults_check() too many CQEs %i\n",
+ nr_cqes);
+ return -1;
+ }
+ assert(check_cq_empty(ring));
+ return 0;
+}
+
static int test_send_faults(int sock_tx, int sock_rx)
{
struct io_uring_sqe *sqe;
- struct io_uring_cqe *cqe;
int msg_flags = 0;
unsigned zc_flags = 0;
- int payload_size = 100;
- int ret, i, nr_cqes, nr_reqs = 3;
+ int ret, payload_size = 100;
struct io_uring ring;
- ret = io_uring_queue_init(32, &ring, IORING_SETUP_SUBMIT_ALL);
+ ret = io_uring_queue_init(32, &ring, 0);
if (ret) {
fprintf(stderr, "queue init failed: %d\n", ret);
return -1;
@@ -143,6 +186,14 @@ static int test_send_faults(int sock_tx, int sock_rx)
io_uring_prep_send_zc(sqe, sock_tx, (void *)1UL, payload_size,
msg_flags, zc_flags);
sqe->user_data = 1;
+ ret = io_uring_submit(&ring);
+ assert(ret == 1);
+
+ ret = test_send_faults_check(&ring, -EFAULT);
+ if (ret) {
+ fprintf(stderr, "test_send_faults with invalid buf failed\n");
+ return -1;
+ }
/* invalid address */
sqe = io_uring_get_sqe(&ring);
@@ -150,44 +201,30 @@ static int test_send_faults(int sock_tx, int sock_rx)
msg_flags, zc_flags);
io_uring_prep_send_set_addr(sqe, (const struct sockaddr *)1UL,
sizeof(struct sockaddr_in6));
- sqe->user_data = 2;
+ sqe->user_data = 1;
+ ret = io_uring_submit(&ring);
+ assert(ret == 1);
+
+ ret = test_send_faults_check(&ring, -EFAULT);
+ if (ret) {
+ fprintf(stderr, "test_send_faults with invalid addr failed\n");
+ return -1;
+ }
/* invalid send/recv flags */
sqe = io_uring_get_sqe(&ring);
io_uring_prep_send_zc(sqe, sock_tx, tx_buffer, payload_size,
msg_flags, ~0U);
- sqe->user_data = 3;
-
+ sqe->user_data = 1;
ret = io_uring_submit(&ring);
- assert(ret == nr_reqs);
-
- nr_cqes = nr_reqs;
- for (i = 0; i < nr_cqes; i++) {
- ret = io_uring_wait_cqe(&ring, &cqe);
- assert(!ret);
- assert(cqe->user_data <= nr_reqs);
-
- if (!(cqe->flags & IORING_CQE_F_NOTIF)) {
- int expected = (cqe->user_data == 3) ? -EINVAL : -EFAULT;
+ assert(ret == 1);
- if (cqe->res != expected) {
- fprintf(stderr, "invalid cqe res %i vs expected %i, "
- "user_data %i\n",
- cqe->res, expected, (int)cqe->user_data);
- return -1;
- }
- if (cqe->flags & IORING_CQE_F_MORE)
- nr_cqes++;
- } else {
- if (cqe->res != 0 || cqe->flags != IORING_CQE_F_NOTIF) {
- fprintf(stderr, "invalid notif cqe %i %i\n",
- cqe->res, cqe->flags);
- return -1;
- }
- }
- io_uring_cqe_seen(&ring, cqe);
+ ret = test_send_faults_check(&ring, -EINVAL);
+ if (ret) {
+ fprintf(stderr, "test_send_faults with invalid flags failed\n");
+ return -1;
}
- assert(check_cq_empty(&ring));
+
return T_EXIT_PASS;
}
--
2.44.0
next prev parent reply other threads:[~2024-04-08 14:24 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-04-08 14:24 [PATCH liburing 0/3] improve sendzc tests Pavel Begunkov
2024-04-08 14:24 ` Pavel Begunkov [this message]
2024-04-08 14:24 ` [PATCH liburing 2/3] test/sendzc: improve zc support probing Pavel Begunkov
2024-04-08 14:24 ` [PATCH liburing 3/3] io_uring/sendzc: add DEFER_TASKRUN testing Pavel Begunkov
2024-04-08 15:23 ` Pavel Begunkov
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=d9b3f41c15dbe993f7bec1d058c480375f6d852e.1712585927.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