[LTP] [PATCH v4 4/4] mmapstress01: use max_runtime

Edward Liaw edliaw@google.com
Thu Oct 6 20:42:28 CEST 2022


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

diff --git a/testcases/kernel/mem/mmapstress/mmapstress01.c b/testcases/kernel/mem/mmapstress/mmapstress01.c
index 9a18587cf..83d3f387d 100644
--- a/testcases/kernel/mem/mmapstress/mmapstress01.c
+++ b/testcases/kernel/mem/mmapstress/mmapstress01.c
@@ -48,7 +48,6 @@ static unsigned int initrand(void);
 static char *debug;
 static char *do_sync;
 static char *do_offset;
-static char *opt_alarmtime;
 static char *opt_filesize;
 static char *opt_nprocs;
 static char *opt_sparseoffset;
@@ -57,7 +56,6 @@ static char *randloops;
 static int fd;
 static int finished;
 static int nprocs = 20;
-static float alarmtime;
 static long long filesize = 4096;
 static long long sparseoffset;
 static size_t pagesize;
@@ -77,7 +75,6 @@ static struct tst_option options[] = {
 	 "When non-zero, causes the sparse area to be left before the data, "
 	 "so that the actual initial filesize is sparseoffset + filesize "
 	 "(default 0)"},
-	{"t:", &opt_alarmtime, "Number of minutes to run (default 0)"},
 	{},
 };
 
@@ -105,18 +102,10 @@ static void setup(void)
 		tst_brk(TBROK, "invalid number of mapping children '%s'",
 			opt_nprocs);
 
-	if (tst_parse_float(opt_alarmtime, &alarmtime, 0, FLT_MAX / 60))
-		tst_brk(TBROK, "invalid minutes to run '%s'", opt_alarmtime);
-
 	if (debug) {
 		tst_res(TINFO, "creating file <%s> with %lld bytes, pattern %d",
 			TEST_FILE, filesize, pattern);
-		if (alarmtime)
-			tst_res(TINFO, "running for %f minutes", alarmtime);
-		else
-			tst_res(TINFO, "running with no time limit");
 	}
-	alarmtime *= 60;
 }
 
 static void cleanup(void)
@@ -312,8 +301,7 @@ static void run(void)
 	pattern = seed & 0xff;
 
 	/*
-	 *  Plan for death by signal.  User may have specified
-	 *  a time limit, in which set an alarm and catch SIGALRM.
+	 *  Plan for death by signal or alarm.
 	 *  Also catch and cleanup with SIGINT.
 	 */
 	sa.sa_handler = sighandler;
@@ -323,10 +311,9 @@ static void run(void)
 	SAFE_SIGACTION(SIGQUIT, &sa, 0);
 	SAFE_SIGACTION(SIGTERM, &sa, 0);
 
-	if (alarmtime) {
-		SAFE_SIGACTION(SIGALRM, &sa, 0);
-		(void)alarm(alarmtime);
-	}
+	SAFE_SIGACTION(SIGALRM, &sa, 0);
+	alarm(tst_remaining_runtime());
+
 	fd = SAFE_OPEN(TEST_FILE, O_CREAT | O_TRUNC | O_RDWR, 0664);
 
 	buf = SAFE_MALLOC(pagesize);
@@ -415,7 +402,7 @@ static void run(void)
 	SAFE_SIGEMPTYSET(&set_mask);
 	SAFE_SIGADDSET(&set_mask, SIGALRM);
 	SAFE_SIGPROCMASK(SIG_BLOCK, &set_mask, NULL);
-	(void)alarm(0);
+	alarm(0);
 
 	/*
 	 *  Finished!  Check the file for sanity.
@@ -429,6 +416,7 @@ static struct tst_test test = {
 	.setup = setup,
 	.options = options,
 	.cleanup = cleanup,
+	.max_runtime = 12,
 	.needs_tmpdir = 1,
 	.forks_child = 1,
 };
-- 
2.38.0.rc1.362.ged0d419d3c-goog



More information about the ltp mailing list