public inbox for io-uring@vger.kernel.org
 help / color / mirror / Atom feed
From: Nitesh Shetty <nj.shetty@samsung.com>
To: io-uring@vger.kernel.org
Cc: gost.dev@samsung.com, nitheshshetty@gmail.com,
	Nitesh Shetty <nj.shetty@samsung.com>
Subject: [PATCH liburing 2/3] test/fixed-seg: verify the data read
Date: Wed, 23 Apr 2025 18:57:51 +0530	[thread overview]
Message-ID: <20250423132752.15622-3-nj.shetty@samsung.com> (raw)
In-Reply-To: <20250423132752.15622-1-nj.shetty@samsung.com>

Write before reading the data. This written data
will be used for comparision later to verification.
To avoid running test on block device in use by system (e.g, mounted),
O_EXCL is added while opening file.

Signed-off-by: Nitesh Shetty <nj.shetty@samsung.com>
---
 test/fixed-seg.c | 34 +++++++++++++++++++++++++++++++---
 1 file changed, 31 insertions(+), 3 deletions(-)

diff --git a/test/fixed-seg.c b/test/fixed-seg.c
index 83e4b13..ab1d359 100644
--- a/test/fixed-seg.c
+++ b/test/fixed-seg.c
@@ -12,7 +12,7 @@
 #include "liburing.h"
 #include "helpers.h"
 
-static struct iovec rvec;
+static struct iovec rvec, wvec;
 
 static int read_it(struct io_uring *ring, int fd, int len, int off)
 {
@@ -40,6 +40,12 @@ static int read_it(struct io_uring *ring, int fd, int len, int off)
 		return 1;
 	}
 	io_uring_cqe_seen(ring, cqe);
+
+	if (memcmp(wvec.iov_base, rvec.iov_base + off, len)) {
+		fprintf(stderr, "%d %d verify failed\n", len, off);
+		return 1;
+	}
+
 	return 0;
 }
 
@@ -81,7 +87,7 @@ int main(int argc, char *argv[])
 	struct io_uring ring;
 	const char *fname;
 	char buf[256];
-	int fd, ret;
+	int fd, rnd_fd, ret;
 
 	if (argc > 1) {
 		fname = argv[1];
@@ -93,12 +99,34 @@ int main(int argc, char *argv[])
 		t_create_file(fname, 128*1024);
 	}
 
-	fd = open(fname, O_RDONLY | O_DIRECT);
+	fd = open(fname, O_RDWR | O_DIRECT | O_EXCL);
 	if (fd < 0) {
 		perror("open");
 		return 1;
 	}
 
+	rnd_fd = open("/dev/urandom", O_RDONLY);
+	if (fd < 0) {
+		perror("urandom: open");
+		goto err;
+	}
+
+	if (posix_memalign(&wvec.iov_base, 4096, 512*1024))
+		goto err;
+	wvec.iov_len = 512*1024;
+
+	ret = read(rnd_fd, wvec.iov_base, wvec.iov_len);
+	if (ret != wvec.iov_len) {
+		fprintf(stderr, "Precondition, urandom read failed, ret: %d\n", ret);
+		goto err;
+	}
+
+	ret = write(fd, wvec.iov_base, wvec.iov_len);
+	if (ret != wvec.iov_len) {
+		fprintf(stderr, "Precondition, write failed, ret: %d\n", ret);
+		goto err;
+	}
+
 	if (posix_memalign(&rvec.iov_base, 4096, 512*1024))
 		goto err;
 	rvec.iov_len = 512*1024;
-- 
2.43.0


  parent reply	other threads:[~2025-04-23 16:55 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <CGME20250423133628epcas5p2b4752a672a64bd2f1392f663a284f9f2@epcas5p2.samsung.com>
2025-04-23 13:27 ` [PATCH liburing 0/3] test/fixed-seg: Add data verification and Nitesh Shetty
     [not found]   ` <CGME20250423133638epcas5p34a9cf20f13387f7f604d9c2e2bf6976a@epcas5p3.samsung.com>
2025-04-23 13:27     ` [PATCH liburing 1/3] test/fixed-seg: Prep patch, rename the vec to rvec Nitesh Shetty
     [not found]   ` <CGME20250423133642epcas5p1bef7e3af23bd8561f359ccc16fdaf980@epcas5p1.samsung.com>
2025-04-23 13:27     ` Nitesh Shetty [this message]
     [not found]   ` <CGME20250423133646epcas5p2e67808b13c6c85444b8a9f28995fe70b@epcas5p2.samsung.com>
2025-04-23 13:27     ` [PATCH liburing 3/3] test/fixed-seg: Support non 512 LBA format devices Nitesh Shetty
2025-04-23 19:05       ` Anuj gupta
2025-04-23 20:02         ` Jens Axboe
2025-04-23 20:04   ` [PATCH liburing 0/3] test/fixed-seg: Add data verification and 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=20250423132752.15622-3-nj.shetty@samsung.com \
    --to=nj.shetty@samsung.com \
    --cc=gost.dev@samsung.com \
    --cc=io-uring@vger.kernel.org \
    --cc=nitheshshetty@gmail.com \
    /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