[LTP] [PATCH v5 2/5] mmapstress01: format comments

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


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

diff --git a/testcases/kernel/mem/mmapstress/mmapstress01.c b/testcases/kernel/mem/mmapstress/mmapstress01.c
index 83d3f387d..dee73de5e 100644
--- a/testcases/kernel/mem/mmapstress/mmapstress01.c
+++ b/testcases/kernel/mem/mmapstress/mmapstress01.c
@@ -5,19 +5,20 @@
  * 06/30/2001	Port to Linux	nsharoff@us.ibm.com
  * 10/03/2022	Refactor to LTP framework	edliaw@google.com
  */
-/*
- *  This test stresses mmaps, without dealing with fragments or anything!
- *  It forks a specified number of children,
- *  all of whom mmap the same file, make a given number of accesses
- *  to random pages in the map (reading & writing and comparing data).
- *  Then the child exits and the parent forks another to take its place.
- *  Each time a child is forked, it stats the file and maps the full
- *  length of the file.
+/*\
+ * [Description]
+ * This test stresses mmaps, without dealing with fragments or anything!
+ * It forks a specified number of children,
+ * all of whom mmap the same file, make a given number of accesses
+ * to random pages in the map (reading & writing and comparing data).
+ * Then the child exits and the parent forks another to take its place.
+ * Each time a child is forked, it stats the file and maps the full
+ * length of the file.
  *
- *  This program continues to run until it either receives a SIGINT,
- *  or times out (if a timeout value is specified).  When either of
- *  these things happens, it cleans up its kids, then checks the
- *  file to make sure it has the correct data.
+ * This program continues to run until it either receives a SIGINT,
+ * or times out (if a timeout value is specified).  When either of
+ * these things happens, it cleans up its kids, then checks the
+ * file to make sure it has the correct data.
  */
 
 #define _GNU_SOURCE 1
@@ -102,10 +103,9 @@ static void setup(void)
 		tst_brk(TBROK, "invalid number of mapping children '%s'",
 			opt_nprocs);
 
-	if (debug) {
+	if (debug)
 		tst_res(TINFO, "creating file <%s> with %lld bytes, pattern %d",
 			TEST_FILE, filesize, pattern);
-	}
 }
 
 static void cleanup(void)
@@ -115,11 +115,11 @@ static void cleanup(void)
 }
 
 /*
- *  Child process that reads/writes map.  The child stats the file
- *  to determine the size, maps the size of the file, then reads/writes
- *  its own locations on random pages of the map (its locations being
- *  determined based on nprocs & procno).  After a specific number of
- *  iterations, it exits.
+ * Child process that reads/writes map.  The child stats the file
+ * to determine the size, maps the size of the file, then reads/writes
+ * its own locations on random pages of the map (its locations being
+ * determined based on nprocs & procno).  After a specific number of
+ * iterations, it exits.
  */
 static void child_mapper(char *file, unsigned int procno, unsigned int nprocs)
 {
@@ -136,7 +136,7 @@ static void child_mapper(char *file, unsigned int procno, unsigned int nprocs)
 	unsigned int mappages;
 	unsigned int i;
 
-	seed = initrand();	/* initialize random seed */
+	seed = initrand();
 
 	SAFE_STAT(file, &statbuf);
 	filesize = statbuf.st_size;
@@ -167,9 +167,7 @@ static void child_mapper(char *file, unsigned int procno, unsigned int nprocs)
 			  offset);
 	SAFE_CLOSE(fd);
 
-	/*
-	 *  Now loop read/writing random pages.
-	 */
+	/* Loop read/writing random pages. */
 	for (loopcnt = 0; loopcnt < nloops; loopcnt++) {
 		randpage = lrand48() % mappages;
 		paddr = maddr + (randpage * pagesize);	/* page address */
@@ -187,16 +185,12 @@ static void child_mapper(char *file, unsigned int procno, unsigned int nprocs)
 					*((unsigned char *)(paddr + i)),
 					randpage, i, (procno + pattern) & 0xff);
 
-			/*
-			 *  Now write it.
-			 */
+			/* Now write it. */
 			*(paddr + i) = (procno + pattern) & 0xff;
 		}
 	}
 	if (do_sync) {
-		/*
-		 * Exercise msync() as well!
-		 */
+		/* Exercise msync() as well! */
 		randpage = lrand48() % mappages;
 		paddr = maddr + (randpage * pagesize);	/* page address */
 		if (msync(paddr, (mappages - randpage) * pagesize,
@@ -207,9 +201,7 @@ static void child_mapper(char *file, unsigned int procno, unsigned int nprocs)
 	exit(0);
 }
 
-/*
- *  Make sure file has all the correct data.
- */
+/* Make sure file has all the correct data. */
 static void fileokay(char *file, unsigned char *expbuf)
 {
 	int cnt;
@@ -234,16 +226,12 @@ static void fileokay(char *file, unsigned char *expbuf)
 	for (i = 0; i < mappages; i++) {
 		cnt = SAFE_READ(0, fd, readbuf, pagesize);
 		if ((unsigned int)cnt != pagesize) {
-			/*
-			 *  Okay if at last page in file...
-			 */
+			/* Okay if at last page in file... */
 			if ((i * pagesize) + cnt != mapsize)
 				tst_brk(TFAIL, "missing data: read %d of %ld bytes",
 					(i * pagesize) + cnt, (long)mapsize);
 		}
-		/*
-		 *  Compare read bytes of data.
-		 */
+		/* Compare read bytes of data. */
 		for (j = 0; j < (unsigned int)cnt; j++) {
 			if (expbuf[j] != readbuf[j])
 				tst_brk(TFAIL,
@@ -265,12 +253,10 @@ static unsigned int initrand(void)
 	unsigned int seed;
 
 	/*
-	 *  Initialize random seed...  Got this from a test written
-	 *  by scooter:
-	 *      Use srand/rand to diffuse the information from the
-	 *      time and pid.  If you start several processes, then
-	 *      the time and pid information don't provide much
-	 *      variation.
+	 * Use srand/rand to diffuse the information from the
+	 * time and pid.  If you start several processes, then
+	 * the time and pid information don't provide much
+	 * variation.
 	 */
 	srand((unsigned int)getpid());
 	seed = rand();
@@ -301,8 +287,8 @@ static void run(void)
 	pattern = seed & 0xff;
 
 	/*
-	 *  Plan for death by signal or alarm.
-	 *  Also catch and cleanup with SIGINT.
+	 * Plan for death by signal or alarm.
+	 * Also catch and cleanup with SIGINT.
 	 */
 	sa.sa_handler = sighandler;
 	sa.sa_flags = 0;
@@ -334,9 +320,7 @@ static void run(void)
 	}
 	SAFE_CLOSE(fd);
 
-	/*
-	 *  Fork off mmap children.
-	 */
+	/* Fork off mmap children. */
 	for (procno = 0; procno < nprocs; procno++) {
 		switch (pid = SAFE_FORK()) {
 		case 0:
@@ -348,9 +332,7 @@ static void run(void)
 		}
 	}
 
-	/*
-	 *  Now wait for children and refork them as needed.
-	 */
+	/* Now wait for children and refork them as needed. */
 
 	SAFE_SIGEMPTYSET(&set_mask);
 	SAFE_SIGADDSET(&set_mask, SIGALRM);
@@ -358,15 +340,15 @@ static void run(void)
 	while (!finished) {
 		pid = wait(&wait_stat);
 		/*
-		 *  Block signals while processing child exit.
+		 * Block signals while processing child exit.
 		 */
 
 		SAFE_SIGPROCMASK(SIG_BLOCK, &set_mask, NULL);
 
 		if (pid != -1) {
 			/*
-			 *  Check exit status, then refork with the
-			 *  appropriate procno.
+			 * Check exit status, then refork with the
+			 * appropriate procno.
 			 */
 			if (!WIFEXITED(wait_stat)
 			    || WEXITSTATUS(wait_stat) != 0)
@@ -388,9 +370,9 @@ static void run(void)
 			}
 		} else {
 			/*
-			 *  wait returned an error.  If EINTR, then
-			 *  normal finish, else it's an unexpected
-			 *  error...
+			 * wait returned an error.  If EINTR, then
+			 * normal finish, else it's an unexpected
+			 * error...
 			 */
 			if (errno != EINTR || !finished)
 				tst_brk(TBROK | TERRNO,
@@ -404,9 +386,7 @@ static void run(void)
 	SAFE_SIGPROCMASK(SIG_BLOCK, &set_mask, NULL);
 	alarm(0);
 
-	/*
-	 *  Finished!  Check the file for sanity.
-	 */
+	/* Finished!  Check the file for sanity. */
 	fileokay(TEST_FILE, buf);
 	tst_res(TPASS, "file has expected data");
 }
-- 
2.38.0.rc1.362.ged0d419d3c-goog



More information about the ltp mailing list