[LTP] [PATCH 4/6] syscalls/gettimeofday02: Convert to tst_remaining_runtime()

Cyril Hrubis chrubis@suse.cz
Mon Oct 25 18:01:32 CEST 2021


Signed-off-by: Cyril Hrubis <chrubis@suse.cz>
---
 .../syscalls/gettimeofday/gettimeofday02.c    | 35 ++-----------------
 1 file changed, 3 insertions(+), 32 deletions(-)

diff --git a/testcases/kernel/syscalls/gettimeofday/gettimeofday02.c b/testcases/kernel/syscalls/gettimeofday/gettimeofday02.c
index c0e56ed34..cdd5984b7 100644
--- a/testcases/kernel/syscalls/gettimeofday/gettimeofday02.c
+++ b/testcases/kernel/syscalls/gettimeofday/gettimeofday02.c
@@ -24,28 +24,15 @@
 #include "tst_timer.h"
 #include "lapi/syscalls.h"
 
-static volatile sig_atomic_t done;
-static char *str_rtime;
-static int rtime = 10;
-
-static void breakout(int sig)
-{
-	done = sig;
-}
-
 static void verify_gettimeofday(void)
 {
 	struct __kernel_old_timeval tv1, tv2;
 	unsigned long long cnt = 0;
 
-	done = 0;
-
-	alarm(rtime);
-
 	if (tst_syscall(__NR_gettimeofday, &tv1, NULL))
 		tst_brk(TFAIL | TERRNO, "gettimeofday() failed");
 
-	while (!done) {
+	while (tst_remaining_runtime()) {
 		if (tst_syscall(__NR_gettimeofday, &tv2, NULL))
 			tst_brk(TFAIL | TERRNO, "gettimeofday() failed");
 
@@ -63,26 +50,10 @@ static void verify_gettimeofday(void)
 	}
 
 	tst_res(TINFO, "gettimeofday() called %llu times", cnt);
-	tst_res(TPASS, "gettimeofday() monotonous in %i seconds", rtime);
-}
-
-static void setup(void)
-{
-	if (str_rtime) {
-		rtime = atoi(str_rtime);
-		if (rtime <= 0)
-			tst_brk(TBROK, "Invalid runtime '%s'", str_rtime);
-		tst_set_timeout(rtime + 60);
-	}
-
-	SAFE_SIGNAL(SIGALRM, breakout);
+	tst_res(TPASS, "gettimeofday() monotonous in %i seconds", test.max_runtime);
 }
 
 static struct tst_test test = {
-	.setup = setup,
-	.options = (struct tst_option[]) {
-		{"T:", &str_rtime, "-T len   Test iteration runtime in seconds"},
-		{},
-	},
+	.max_runtime = 10,
 	.test_all = verify_gettimeofday,
 };
-- 
2.32.0



More information about the ltp mailing list