public inbox for io-uring@vger.kernel.org
 help / color / mirror / Atom feed
From: Pavel Begunkov <asml.silence@gmail.com>
To: io-uring@vger.kernel.org
Cc: asml.silence@gmail.com
Subject: [PATCH liburing 5/6] tests: add helper for iov data verification
Date: Thu, 11 Sep 2025 12:26:30 +0100	[thread overview]
Message-ID: <85ec39ae2040270bec7ac991e7689fbafb36a259.1757589613.git.asml.silence@gmail.com> (raw)
In-Reply-To: <cover.1757589613.git.asml.silence@gmail.com>

Signed-off-by: Pavel Begunkov <asml.silence@gmail.com>
---
 test/helpers.c | 44 ++++++++++++++++++++++++++++++++++++++++++++
 test/helpers.h |  3 +++
 2 files changed, 47 insertions(+)

diff --git a/test/helpers.c b/test/helpers.c
index 15ceb17a..83a128e3 100644
--- a/test/helpers.c
+++ b/test/helpers.c
@@ -536,3 +536,47 @@ size_t t_iovec_data_length(struct iovec *iov, unsigned iov_len)
 		sz += iov[i].iov_len;
 	return sz;
 }
+
+#define t_min(a, b) ((a) < (b) ? (a) : (b))
+
+unsigned long t_compare_data_iovec(struct iovec *iov_src, unsigned nr_src,
+				   struct iovec *iov_dst, unsigned nr_dst)
+{
+	size_t src_len = t_iovec_data_length(iov_src, nr_src);
+	size_t dst_len = t_iovec_data_length(iov_dst, nr_dst);
+	size_t len_left = t_min(src_len, dst_len);
+	unsigned long src_off = 0, dst_off = 0;
+	unsigned long offset = 0;
+
+	while (offset != len_left) {
+		size_t len = len_left - offset;
+		unsigned long i;
+
+		len = t_min(len, iov_src->iov_len - src_off);
+		len = t_min(len, iov_dst->iov_len - dst_off);
+
+		for (i = 0; i < len; i++) {
+			char csrc = ((char *)iov_src->iov_base)[src_off + i];
+			char cdst = ((char *)iov_dst->iov_base)[dst_off + i];
+
+			if (csrc != cdst) {
+				fprintf(stderr, "data mismatch, %i vs %i\n",
+					csrc, cdst);
+				return -EINVAL;
+			}
+		}
+
+		src_off += len;
+		dst_off += len;
+		if (src_off == iov_src->iov_len) {
+			src_off = 0;
+			iov_src++;
+		}
+		if (dst_off == iov_dst->iov_len) {
+			dst_off = 0;
+			iov_dst++;
+		}
+		offset += len;
+	}
+	return 0;
+}
diff --git a/test/helpers.h b/test/helpers.h
index 7dafeb17..cfada945 100644
--- a/test/helpers.h
+++ b/test/helpers.h
@@ -126,6 +126,9 @@ int t_submit_and_wait_single(struct io_uring *ring, struct io_uring_cqe **cqe);
 
 size_t t_iovec_data_length(struct iovec *iov, unsigned iov_len);
 
+unsigned long t_compare_data_iovec(struct iovec *iov_src, unsigned nr_src,
+				   struct iovec *iov_dst, unsigned nr_dst);
+
 static inline void t_sqe_prep_cmd(struct io_uring_sqe *sqe,
 				  int fd, unsigned cmd_op)
 {
-- 
2.49.0


  parent reply	other threads:[~2025-09-11 11:25 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-09-11 11:26 [PATCH liburing 0/6] Add query and mock tests Pavel Begunkov
2025-09-11 11:26 ` [PATCH liburing 1/6] tests: test the query interface Pavel Begunkov
2025-09-19 14:11   ` Pavel Begunkov
2025-09-11 11:26 ` [PATCH liburing 2/6] tests: add t_submit_and_wait_single helper Pavel Begunkov
2025-09-11 11:26 ` [PATCH liburing 3/6] tests: introduce t_iovec_data_length helper Pavel Begunkov
2025-09-11 11:26 ` [PATCH liburing 4/6] tests: add t_sqe_prep_cmd helper Pavel Begunkov
2025-09-11 11:26 ` Pavel Begunkov [this message]
2025-09-11 11:26 ` [PATCH liburing 6/6] tests: add mock file based tests Pavel Begunkov
2025-09-19 13:15 ` [PATCH liburing 0/6] Add query and mock tests Jens Axboe
2025-09-19 16:56   ` Jens Axboe
2025-09-22  7:55     ` Pavel Begunkov
2025-09-22 12:00       ` 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=85ec39ae2040270bec7ac991e7689fbafb36a259.1757589613.git.asml.silence@gmail.com \
    --to=asml.silence@gmail.com \
    --cc=io-uring@vger.kernel.org \
    /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