public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
From: Cyril Hrubis <chrubis@suse.cz>
To: Andrea Cervesato <acervesato@suse.de>
Cc: ltp@lists.linux.it
Subject: Re: [LTP] [PATCH v5] dio_truncate.c test refactory with LTP API
Date: Fri, 19 Nov 2021 13:28:35 +0100	[thread overview]
Message-ID: <YZeYc1dgffw8em7j@yuki> (raw)
In-Reply-To: <20211119104130.26480-1-acervesato@suse.de>

Hi!
Pushed with minor changes, thanks.

Apart from simple formatting fixes the most complicated change was
removal of the loop that waits the children at the end of the run().
Since if any of the children returns prematurely the waitpid() for the
pid will fail and the test will exit with TBROK. The easiest solution
was simply to remove the loop since the children exit with 0 now the
library will collect them for us just fine.

Full diff:

diff --git a/testcases/kernel/io/ltp-aiodio/dio_truncate.c b/testcases/kernel/io/ltp-aiodio/dio_truncate.c
index 3681c9bdb..68c10ac7a 100644
--- a/testcases/kernel/io/ltp-aiodio/dio_truncate.c
+++ b/testcases/kernel/io/ltp-aiodio/dio_truncate.c
@@ -10,13 +10,17 @@
  *
  * This test is mixing direct I/O and truncate operations checking if they can
  * be used together at the same time. Multiple children are spawned to read a
- * file that is edited using DIO write/read operations. Algorithm:
+ * file that is written to using direct I/O and truncated in a loop.
+ *
+ * [Algorithm]
+ *
  * - Spawn multiple children which start to read on 'file'
  * - Parent start to fill and truncate 'file' many times with zero char when
  *   children are reading
  * - Parent start to fill and truncate a junk file many times with non-zero char
+ *
  * If no issues occur on direct IO/truncate operations and the file always
- * contains non-zero characters, test PASS. Otherwise, test will FAIL.
+ * contains zero characters, test PASS. Otherwise, test will FAIL.
  */
 
 #define _GNU_SOURCE
@@ -53,7 +57,8 @@ static char *check_zero(char *buf, int size)
 		buf++;
 		size--;
 	}
-	return 0; /* all zeros */
+
+	return 0;
 }
 
 static void dio_read(const char *filename, size_t bs)
@@ -67,19 +72,19 @@ static void dio_read(const char *filename, size_t bs)
 	while ((fd = open(filename, O_RDONLY | O_DIRECT, 0666)) < 0)
 		usleep(100);
 
-	tst_res(TINFO, "child reading file");
+	tst_res(TINFO, "child %i reading file", getpid());
 	while (*run_child) {
 		off_t offset;
 		char *bufoff;
 
-		/* read the file, checking for zeros */
 		offset = SAFE_LSEEK(fd, SEEK_SET, 0);
 		do {
 			r = read(fd, bufptr, 64 * 1024);
 			if (r > 0) {
 				bufoff = check_zero(bufptr, r);
 				if (bufoff) {
-					tst_res(TINFO, "non-zero read at offset %p", offset + bufoff);
+					tst_res(TINFO, "non-zero read at offset %zu",
+						offset + (bufoff - bufptr));
 					free(bufptr);
 					SAFE_CLOSE(fd);
 					return;
@@ -91,8 +96,6 @@ static void dio_read(const char *filename, size_t bs)
 
 	free(bufptr);
 	SAFE_CLOSE(fd);
-
-	tst_res(TPASS, "zero buffer only after truncate");
 }
 
 static void dio_append(const char *path, char pattern, size_t bs, size_t bcount)
@@ -128,7 +131,6 @@ static void run(void)
 	char *filename = "file";
 	int filesize = FILE_SIZE;
 	int num_children = NUM_CHILDREN;
-	int pid[NUM_CHILDREN];
 	int status;
 	int i;
 	int fail = 0;
@@ -136,13 +138,14 @@ static void run(void)
 	*run_child = 1;
 
 	for (i = 0; i < num_children; i++) {
-		pid[i] = SAFE_FORK();
-		if (pid[i] == 0) {
+		if (!SAFE_FORK()) {
 			dio_read(filename, filesize);
 			return;
 		}
 	}
 
+	tst_res(TINFO, "parent writes/truncates the file");
+
 	for (i = 0; i < 100; i++) {
 		dio_append(filename, 0, filesize, 100);
 		SAFE_TRUNCATE(filename, 0);
@@ -161,9 +164,6 @@ static void run(void)
 		tst_res(TPASS, "All bytes read were zeroed");
 
 	*run_child = 0;
-
-	for (i = 0; i < num_children; i++)
-		SAFE_WAITPID(pid[i], &status, 0);
 }
 
 static struct tst_test test = {

-- 
Cyril Hrubis
chrubis@suse.cz

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

      reply	other threads:[~2021-11-19 12:27 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-19 10:41 [LTP] [PATCH v5] dio_truncate.c test refactory with LTP API Andrea Cervesato
2021-11-19 12:28 ` Cyril Hrubis [this message]

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=YZeYc1dgffw8em7j@yuki \
    --to=chrubis@suse.cz \
    --cc=acervesato@suse.de \
    --cc=ltp@lists.linux.it \
    /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