aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPavel Begunkov <asml.silence@gmail.com>2024-04-08 17:38:10 +0100
committerJens Axboe <axboe@kernel.dk>2024-04-08 21:45:15 -0600
commita305179d22f982f08a38162c13fe1f6fc8e99ab3 (patch)
treec3adcf7d7bfda42ed50dcbbf82c639439649a046
parente4cfc721761a85ea6a257c77572546292d04bf79 (diff)
downloadliburing-a305179d22f982f08a38162c13fe1f6fc8e99ab3.tar.gz
test: handle test_send_faults()'s cases one by one
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 <asml.silence@gmail.com> Link: https://lore.kernel.org/r/d9b3f41c15dbe993f7bec1d058c480375f6d852e.1712594147.git.asml.silence@gmail.com Signed-off-by: Jens Axboe <axboe@kernel.dk>
-rw-r--r--test/send-zerocopy.c105
1 files changed, 71 insertions, 34 deletions
diff --git a/test/send-zerocopy.c b/test/send-zerocopy.c
index 1b6dd774..78ec3d76 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;
}