[LTP] [PATCH v5 4/5] mmapstress01: remove unnecessary pidarray

Edward Liaw edliaw@google.com
Wed Oct 12 16:48:22 CEST 2022


Signed-off-by: Edward Liaw <edliaw@google.com>
---
 .../kernel/mem/mmapstress/mmapstress01.c      | 25 ++++---------------
 1 file changed, 5 insertions(+), 20 deletions(-)

diff --git a/testcases/kernel/mem/mmapstress/mmapstress01.c b/testcases/kernel/mem/mmapstress/mmapstress01.c
index ea818ffcd..de7da5b99 100644
--- a/testcases/kernel/mem/mmapstress/mmapstress01.c
+++ b/testcases/kernel/mem/mmapstress/mmapstress01.c
@@ -62,7 +62,7 @@ static char *opt_sparseoffset;
 static char *randloops;
 
 static int fd;
-static int finished;
+static volatile int finished;
 static int nprocs = 20;
 static long long filesize = 4096;
 static long long sparseoffset;
@@ -273,7 +273,6 @@ static void run(void)
 	int wait_stat;
 	off_t bytes_left;
 	pid_t pid;
-	pid_t *pidarray = NULL;
 	sigset_t set_mask;
 	size_t write_cnt;
 	struct sigaction sa;
@@ -289,6 +288,7 @@ static void run(void)
 	 * Plan for death by signal or alarm.
 	 * Also catch and cleanup with SIGINT.
 	 */
+	finished = 0;
 	sa.sa_handler = sighandler;
 	sa.sa_flags = 0;
 	SAFE_SIGEMPTYSET(&sa.sa_mask);
@@ -302,10 +302,6 @@ static void run(void)
 	fd = SAFE_OPEN(TEST_FILE, O_CREAT | O_TRUNC | O_RDWR, 0664);
 
 	buf = SAFE_MALLOC(pagesize);
-	pidarray = SAFE_MALLOC(nprocs * sizeof(pid_t));
-
-	for (i = 0; i < nprocs; i++)
-		*(pidarray + i) = 0;
 
 	for (i = 0, data = 0; i < (int)pagesize; i++) {
 		*(buf + i) = (data + pattern) & 0xff;
@@ -321,13 +317,11 @@ static void run(void)
 
 	/* Fork off mmap children. */
 	for (procno = 0; procno < nprocs; procno++) {
-		switch (pid = SAFE_FORK()) {
-		case 0:
+		pid = SAFE_FORK();
+
+		if (pid == 0) {
 			child_mapper(TEST_FILE, (unsigned int)procno, (unsigned int)nprocs);
 			exit(0);
-
-		default:
-			pidarray[procno] = pid;
 		}
 	}
 
@@ -353,19 +347,10 @@ static void run(void)
 			    || WEXITSTATUS(wait_stat) != 0)
 				tst_brk(TBROK, "child exit with err <x%x>",
 					wait_stat);
-			for (i = 0; i < nprocs; i++)
-				if (pid == pidarray[i])
-					break;
-			if (i == nprocs)
-				tst_brk(TBROK, "unknown child pid %d, <x%x>",
-					pid, wait_stat);
-
 			pid = SAFE_FORK();
 			if (pid == 0) {	/* child */
 				child_mapper(TEST_FILE, (unsigned int)i, (unsigned int)nprocs);
 				exit(0);
-			} else {
-				pidarray[i] = pid;
 			}
 		} else {
 			/*
-- 
2.38.0.rc1.362.ged0d419d3c-goog



More information about the ltp mailing list