[LTP] [PATCH v2] Check for maximum available pids in dio_sparse.c

Andrea Cervesato andrea.cervesato@suse.de
Tue Feb 1 10:39:54 CET 2022


Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.de>
---
In v2 setup message for children has been moved from TCONF to TINFO.
And other small fixes.

 testcases/kernel/io/ltp-aiodio/dio_sparse.c | 26 +++++++++++++++++----
 1 file changed, 21 insertions(+), 5 deletions(-)

diff --git a/testcases/kernel/io/ltp-aiodio/dio_sparse.c b/testcases/kernel/io/ltp-aiodio/dio_sparse.c
index 0039daa8d..1da1ae37f 100644
--- a/testcases/kernel/io/ltp-aiodio/dio_sparse.c
+++ b/testcases/kernel/io/ltp-aiodio/dio_sparse.c
@@ -54,14 +54,29 @@ static void dio_sparse(int fd, int align, long long fs, int ws, long long off)
 		w = SAFE_WRITE(0, fd, bufptr, ws);
 		i += w;
 	}
+
+	free(bufptr);
 }
 
 static void setup(void)
 {
 	struct stat sb;
+	int max_pids;
+
+	if (tst_parse_int(str_numchildren, &numchildren, 1, INT_MAX)) {
+		tst_brk(TBROK, "Invalid number of children '%s'",
+			str_numchildren);
+	}
 
-	if (tst_parse_int(str_numchildren, &numchildren, 1, INT_MAX))
-		tst_brk(TBROK, "Invalid number of children '%s'", str_numchildren);
+	max_pids = tst_get_free_pids();
+	if (numchildren > max_pids) {
+		numchildren = max_pids;
+
+		tst_res(TINFO,
+			"Number of children reduced to %d due to system "
+			"limitations",
+			numchildren);
+	}
 
 	if (tst_parse_filesize(str_writesize, &writesize, 1, LLONG_MAX))
 		tst_brk(TBROK, "Invalid write blocks size '%s'", str_writesize);
@@ -75,7 +90,8 @@ static void setup(void)
 	SAFE_STAT(".", &sb);
 	alignment = sb.st_blksize;
 
-	run_child = SAFE_MMAP(NULL, sizeof(int), PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANONYMOUS, -1, 0);
+	run_child = SAFE_MMAP(NULL, sizeof(int), PROT_READ | PROT_WRITE,
+			      MAP_SHARED | MAP_ANONYMOUS, -1, 0);
 
 	tst_res(TINFO, "Dirtying free blocks");
 	dirty_freeblocks(100 * 1024 * 1024);
@@ -91,7 +107,7 @@ static void cleanup(void)
 
 static void run(void)
 {
-	char *filename = "dio_sparse";
+	char *filename = "file.bin";
 	int status;
 	int fd;
 	int i;
@@ -129,7 +145,7 @@ static struct tst_test test = {
 		{"w:", &str_writesize, "Size of writing blocks (default 1K)"},
 		{"s:", &str_filesize, "Size of file (default 100M)"},
 		{"o:", &str_offset, "File offset (default 0)"},
-		{}
+		{},
 	},
 	.skip_filesystems = (const char *[]) {
 		"tmpfs",
-- 
2.34.1



More information about the ltp mailing list