[v2,2/3] tst_test.c: Add tst_adjust_timeout()
diff mbox series

Message ID 20190911165225.2122-2-cfamullaconrad@suse.de
State New
Headers show
Series
  • [v2,1/3] tst_test.sh: Use LTP_TIMEOUT_MUL in TST_RETRY_FN()
Related show

Commit Message

Clemens Famulla-Conrad Sept. 11, 2019, 4:52 p.m. UTC
This function is used to adjust timeout values with environment
variables like LTP_TIMEOUT_MUL.

Signed-off-by: Clemens Famulla-Conrad <cfamullaconrad@suse.de>
---
 include/tst_test.h |  1 +
 lib/tst_test.c     | 32 ++++++++++++++++++++------------
 2 files changed, 21 insertions(+), 12 deletions(-)

Patch
diff mbox series

diff --git a/include/tst_test.h b/include/tst_test.h
index cdeaf6ad0..908015846 100644
--- a/include/tst_test.h
+++ b/include/tst_test.h
@@ -261,6 +261,7 @@  const char *tst_strsig(int sig);
 const char *tst_strstatus(int status);
 
 unsigned int tst_timeout_remaining(void);
+unsigned int tst_adjust_timeout(unsigned int timeout);
 void tst_set_timeout(int timeout);
 
 
diff --git a/lib/tst_test.c b/lib/tst_test.c
index d2cf92608..1283dba1a 100644
--- a/lib/tst_test.c
+++ b/lib/tst_test.c
@@ -36,6 +36,7 @@  struct tst_test *tst_test;
 static const char *tid;
 static int iterations = 1;
 static float duration = -1;
+static float timeout_mul = -1;
 static pid_t main_pid, lib_pid;
 static int mntpoint_mounted;
 static int ovl_mounted;
@@ -1087,25 +1088,32 @@  unsigned int tst_timeout_remaining(void)
 	return 0;
 }
 
-void tst_set_timeout(int timeout)
+unsigned int tst_adjust_timeout(unsigned int timeout)
 {
-	char *mul = getenv("LTP_TIMEOUT_MUL");
+	char *mul;
+	if (timeout_mul == -1){
+		mul = getenv("LTP_TIMEOUT_MUL");
+		if (mul) {
+			timeout_mul = atof(mul);
+			if (timeout_mul < 1)
+				tst_brk(TBROK,
+					"Invalid timeout multiplier '%s'",
+					mul);
+		} else {
+			timeout_mul = 1;
+		}
+	}
+	return timeout * timeout_mul + 0.5;
+}
 
+void tst_set_timeout(int timeout)
+{
 	if (timeout == -1) {
 		tst_res(TINFO, "Timeout per run is disabled");
 		return;
 	}
 
-	results->timeout = timeout;
-
-	if (mul) {
-		float m = atof(mul);
-
-		if (m < 1)
-			tst_brk(TBROK, "Invalid timeout multiplier '%s'", mul);
-
-		results->timeout = results->timeout * m + 0.5;
-	}
+	results->timeout = tst_adjust_timeout(timeout);
 
 	tst_res(TINFO, "Timeout per run is %uh %02um %02us",
 		results->timeout/3600, (results->timeout%3600)/60,