public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
From: Clemens Famulla-Conrad <cfamullaconrad@suse.de>
To: ltp@lists.linux.it
Subject: [LTP] [PATCH v3 2/4] tst_test.c: Add tst_multiply_timeout()
Date: Wed, 16 Oct 2019 18:15:17 +0200	[thread overview]
Message-ID: <20191016161519.11256-2-cfamullaconrad@suse.de> (raw)
In-Reply-To: <20191016161519.11256-1-cfamullaconrad@suse.de>

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     | 41 ++++++++++++++++++++++++++++++-----------
 2 files changed, 31 insertions(+), 11 deletions(-)

diff --git a/include/tst_test.h b/include/tst_test.h
index 84acf2c59..aaea128ba 100644
--- a/include/tst_test.h
+++ b/include/tst_test.h
@@ -267,6 +267,7 @@ const char *tst_strsig(int sig);
 const char *tst_strstatus(int status);
 
 unsigned int tst_timeout_remaining(void);
+unsigned int tst_multiply_timeout(unsigned int timeout);
 void tst_set_timeout(int timeout);
 
 
diff --git a/lib/tst_test.c b/lib/tst_test.c
index 6239acf89..6d92d8775 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 int timeout_mul = -1;
 static pid_t main_pid, lib_pid;
 static int mntpoint_mounted;
 static int ovl_mounted;
@@ -1093,25 +1094,43 @@ unsigned int tst_timeout_remaining(void)
 	return 0;
 }
 
-void tst_set_timeout(int timeout)
+unsigned int tst_multiply_timeout(unsigned int timeout)
 {
-	char *mul = getenv("LTP_TIMEOUT_MUL");
+	char *mul;
+	float mul_float;
+
+	if (timeout_mul == -1){
+		mul = getenv("LTP_TIMEOUT_MUL");
+		if (mul) {
+			timeout_mul = mul_float = atof(mul);
+			if (timeout_mul != mul_float){
+				timeout_mul++;
+				tst_res(TINFO, "ceiling LTP_TIMEOUT_MUL to %d", timeout_mul);
+			}
+		} else {
+			timeout_mul = 1;
+		}
+	}
+	if (timeout_mul < 1)
+		tst_brk(TBROK, "LTP_TIMEOUT_MUL need to be int >= 1! (%d)", timeout_mul);
+
+	if (timeout < 1)
+		tst_brk(TBROK, "timeout need to be >= 1! (%d)", timeout);
+
+	return timeout * timeout_mul;
+}
 
+void tst_set_timeout(int timeout)
+{
 	if (timeout == -1) {
 		tst_res(TINFO, "Timeout per run is disabled");
 		return;
 	}
 
-	results->timeout = timeout;
+	if (timeout < 1)
+		tst_brk(TBROK, "timeout need to be >= 1! (%d)", 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_multiply_timeout(timeout);
 
 	tst_res(TINFO, "Timeout per run is %uh %02um %02us",
 		results->timeout/3600, (results->timeout%3600)/60,
-- 
2.16.4


  reply	other threads:[~2019-10-16 16:15 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-09-11  8:55 [LTP] [PATCH] Use LTP_TIMEOUT_MUL in TST_RETRY_FN() Clemens Famulla-Conrad
2019-09-11  9:12 ` Petr Vorel
2019-09-11  9:17   ` Clemens Famulla-Conrad
2019-09-11 16:52 ` [LTP] [PATCH v2 1/3] tst_test.sh: " Clemens Famulla-Conrad
2019-09-11 16:52   ` [LTP] [PATCH v2 2/3] tst_test.c: Add tst_adjust_timeout() Clemens Famulla-Conrad
2019-09-11 16:52   ` [LTP] [PATCH v2 3/3] tst_common.h: Use tst_adjust_timeout in TST_RETRY_FN() Clemens Famulla-Conrad
2019-09-12  5:42   ` [LTP] [PATCH v2 1/3] tst_test.sh: Use LTP_TIMEOUT_MUL " Li Wang
2019-09-12  8:52     ` Clemens Famulla-Conrad
2019-09-12 14:55       ` Petr Vorel
2019-09-12 16:49         ` Clemens Famulla-Conrad
2019-09-12 19:46           ` Clemens Famulla-Conrad
2019-09-12 21:51   ` Petr Vorel
2019-10-11 12:02   ` Petr Vorel
2019-10-11 12:53     ` Cyril Hrubis
2019-10-12  2:46       ` Li Wang
2019-10-16 11:25         ` Clemens Famulla-Conrad
2019-10-16 16:15           ` [LTP] [PATCH v3 1/4] " Clemens Famulla-Conrad
2019-10-16 16:15             ` Clemens Famulla-Conrad [this message]
2019-10-17  8:47               ` [LTP] [PATCH v3 2/4] tst_test.c: Add tst_multiply_timeout() Petr Vorel
2019-10-16 16:15             ` [LTP] [PATCH v3 3/4] tst_common.h: Use tst_multiply_timeout in TST_RETRY_FN() Clemens Famulla-Conrad
2019-10-17  8:48               ` Petr Vorel
2019-10-16 16:15             ` [LTP] [PATCH v3 4/4] Add newlib shell test for tst_multiply_timeout() Clemens Famulla-Conrad
2019-10-17  9:00               ` Petr Vorel
2019-10-17  8:39             ` [LTP] [PATCH v3 1/4] tst_test.sh: Use LTP_TIMEOUT_MUL in TST_RETRY_FN() Petr Vorel
2019-10-17 12:23               ` Clemens Famulla-Conrad
2019-10-18  7:46                 ` Petr Vorel
2019-10-18  8:29                 ` Petr Vorel

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20191016161519.11256-2-cfamullaconrad@suse.de \
    --to=cfamullaconrad@suse.de \
    --cc=ltp@lists.linux.it \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox