Skip to contentSkip to conversation

Use LTP_TIMEOUT_MUL in TST_RETRY_FN()

PATCH New Clemens Famulla-Conrad 4 participants 27 messages Sep 11, 2019 – Oct 18, 2019 Library code

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Use LTP_TIMEOUT_MUL in TST_RETRY_FN()

We discovered timeout problems for well known candidates. Most of the time we already use LTP_TIMEOUT_MUL in other cases to globally increase timeout value. So doing it for this function as well.

---
 testcases/lib/tst_test.sh | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
testcases/lib/tst_test.sh +3 -1
index e0b24c6b9..80b8871cb 100644
@@ -162,9 +162,11 @@ EXPECT_FAIL()
 
 TST_RETRY_FN_EXP_BACKOFF()
 {
+	LTP_TIMEOUT_MUL=${LTP_TIMEOUT_MUL:-1}
+
 	local tst_fun="$1"
 	local tst_exp=$2
-	local tst_sec=$(expr $3 \* 1000000)
+	local tst_sec=$(expr $3 \* 1000000 \* $LTP_TIMEOUT_MUL)
 	local tst_delay=1
 
 	if [ $# -ne 3 ]; then
Signature · 1 line
2.16.4
#1 lore raw

PATCH 1/1 Use LTP_TIMEOUT_MUL in TST_RETRY_FN()

Hi Clemens,

Quoted 14 lines

We discovered timeout problems for well known candidates. Most of the time we already use LTP_TIMEOUT_MUL in other cases to globally increase timeout value. So doing it for this function as well.

---
 testcases/lib/tst_test.sh | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
testcases/lib/tst_test.sh +0 -0
index e0b24c6b9..80b8871cb 100644

testcases/lib/tst_test.sh EXPECT_FAIL() · line 170

Quoted 10 lines
testcases/lib/tst_test.sh +3 -1
@@ -162,9 +162,11 @@ EXPECT_FAIL()
 
 TST_RETRY_FN_EXP_BACKOFF()
 {
+	LTP_TIMEOUT_MUL=${LTP_TIMEOUT_MUL:-1}
+
 	local tst_fun="$1"
 	local tst_exp=$2
-	local tst_sec=$(expr $3 \* 1000000)
+	local tst_sec=$(expr $3 \* 1000000 \* $LTP_TIMEOUT_MUL)
 	local tst_delay=1

I'm for it, but that will diverge from C API. Shouldn't we add it also to tst_common.h?

Kind regards,
Petr

#2 lore raw

PATCH 1/1 Use LTP_TIMEOUT_MUL in TST_RETRY_FN()

Quoted 20 lines · Petr Vorel

Hi Clemens,

Quoted 18 lines

We discovered timeout problems for well known candidates. Most of the time we already use LTP_TIMEOUT_MUL in other cases to globally increase timeout value. So doing it for this function as well.

---
 testcases/lib/tst_test.sh | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
testcases/lib/tst_test.sh +2 -0
index e0b24c6b9..80b8871cb 100644
@@ -162,9 +162,11 @@ EXPECT_FAIL()
 TST_RETRY_FN_EXP_BACKOFF()
 {
+	LTP_TIMEOUT_MUL=${LTP_TIMEOUT_MUL:-1}
+
 	local tst_fun="$1"
Quoted 8 lines

testcases/lib/tst_test.sh EXPECT_FAIL() · line 170

Quoted 4 lines
testcases/lib/tst_test.sh +1 -1
 	local tst_exp=$2
-	local tst_sec=$(expr $3 \* 1000000)
+	local tst_sec=$(expr $3 \* 1000000 \* $LTP_TIMEOUT_MUL)
 	local tst_delay=1

I'm for it, but that will diverge from C API. Shouldn't we add it also
to tst_common.h?

Agree, let me add it. Thx for the hint.

Quoted 3 lines

Kind regards,
Petr

#3 lore raw

PATCH v2 1/3 tst_test.sh: Use LTP_TIMEOUT_MUL in TST_RETRY_FN()

In reply to Clemens Famulla-Conrad

Because of timeout problems when using TST_RETRY_FN() we do now use LTP_TIMEOUT_MUL to adopt the timeout value.

Introduced tst_adjut_timeout function to have a generic place to adopt timeout values.

---
 testcases/lib/tst_test.sh | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)
testcases/lib/tst_test.sh +8 -4
index e0b24c6b9..03692e503 100644
@@ -164,7 +164,7 @@ TST_RETRY_FN_EXP_BACKOFF()
 {
 	local tst_fun="$1"
 	local tst_exp=$2
-	local tst_sec=$(expr $3 \* 1000000)
+	local tst_sec=$(tst_adjust_timeout $(expr $3 \* 1000000))
 	local tst_delay=1
 
 	if [ $# -ne 3 ]; then
@@ -371,12 +371,16 @@ _tst_rescmp()
 	fi
 }
 
-
-_tst_setup_timer()
+tst_adjust_timeout()
 {
 	LTP_TIMEOUT_MUL=${LTP_TIMEOUT_MUL:-1}
+	local timeout=$1
+	echo $(( timeout * LTP_TIMEOUT_MUL))
+}
 
-	local sec=$((300 * LTP_TIMEOUT_MUL))
+_tst_setup_timer()
+{
+	local sec=$(tst_adjust_timeout 300)
 	local h=$((sec / 3600))
 	local m=$((sec / 60 % 60))
 	local s=$((sec % 60))
Signature · 1 line
2.16.4
#4 lore raw

PATCH v2 2/3 tst_test.c: Add tst_adjust_timeout()

This function is used to adjust timeout values with environment variables like LTP_TIMEOUT_MUL.

---
 include/tst_test.h |  1 +
 lib/tst_test.c     | 32 ++++++++++++++++++++------------
 2 files changed, 21 insertions(+), 12 deletions(-)
include/tst_test.h +1 -0
index cdeaf6ad0..908015846 100644
@@ -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);
 
 
lib/tst_test.c +20 -12
index d2cf92608..1283dba1a 100644
@@ -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,
Signature · 1 line
2.16.4
#5 lore raw

PATCH v2 3/3 tst_common.h: Use tst_adjust_timeout in TST_RETRY_FN()

In reply to Clemens Famulla-Conrad

Because of timeout problems when using TST_RETRY_FN() we want a LTP_TIMEOUT_MUL adopted timeout value here as well.

---
 include/tst_common.h | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
include/tst_common.h +4 -2
index c21505450..ca8f06d01 100644
@@ -50,12 +50,14 @@
 	TST_RETRY_FN_EXP_BACKOFF(FUNC, ERET, 1)
 
 #define TST_RETRY_FN_EXP_BACKOFF(FUNC, ERET, MAX_DELAY)	\
-({	int tst_delay_ = 1;						\
+({	unsigned int tst_delay_, tst_max_delay_;			\
+	tst_delay_ = 1;							\
+	tst_max_delay_ = tst_adjust_timeout(MAX_DELAY * 1000000);	\
 	for (;;) {							\
 		typeof(FUNC) tst_ret_ = FUNC;				\
 		if (tst_ret_ == ERET)					\
 			break;						\
-		if (tst_delay_ < MAX_DELAY * 1000000) {			\
+		if (tst_delay_ < tst_max_delay_) {			\
 			usleep(tst_delay_);				\
 			tst_delay_ *= 2;				\
 		} else {						\
Signature · 1 line
2.16.4
#6 lore raw

PATCH v2 1/3 tst_test.sh: Use LTP_TIMEOUT_MUL in TST_RETRY_FN()

In reply to Clemens Famulla-Conrad
Quoted 6 lines · Clemens Famulla-Conrad

Because of timeout problems when using TST_RETRY_FN() we do now use LTP_TIMEOUT_MUL to adopt the timeout value.

Introduced tst_adjut_timeout function to have a generic place to adopt timeout values.

What about using tst_multipy_timeout as the function name? Since it only raises the timeout value with a multiplier.

Quoted 21 lines
---
 testcases/lib/tst_test.sh | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)
testcases/lib/tst_test.sh +1 -1
index e0b24c6b9..03692e503 100644
@@ -164,7 +164,7 @@ TST_RETRY_FN_EXP_BACKOFF()
 {
        local tst_fun="$1"
        local tst_exp=$2
-       local tst_sec=$(expr $3 \* 1000000)
+       local tst_sec=$(tst_adjust_timeout $(expr $3 \* 1000000))
        local tst_delay=1
 
        if [ $# -ne 3 ]; then
@@ -371,12 +371,16 @@ _tst_rescmp()
        fi

testcases/lib/tst_test.sh _tst_rescmp() · line 379

Quoted 10 lines
testcases/lib/tst_test.sh +3 -2
 }
 
-
-_tst_setup_timer()
+tst_adjust_timeout()
 {
        LTP_TIMEOUT_MUL=${LTP_TIMEOUT_MUL:-1}
+       local timeout=$1
+       echo $(( timeout * LTP_TIMEOUT_MUL))
 

Shouldn't we check the LTP_TIMEOUT_MUL > 1 before using it?

Signature · 5 lines
Regards,
Li Wang
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.linux.it/pipermail/ltp/attachments/20190912/d28e6372/attachment.htm>
#7 lore raw

PATCH v2 1/3 tst_test.sh: Use LTP_TIMEOUT_MUL in TST_RETRY_FN()

Quoted 6 lines · Li Wang
Quoted 3 lines · Clemens Famulla-Conrad

Because of timeout problems when using TST_RETRY_FN() we do now use LTP_TIMEOUT_MUL to adopt the timeout value.

Quoted 7 lines
Quoted 3 lines

Introduced tst_adjut_timeout function to have a generic place to adopt timeout values.

What about using tst_multipy_timeout as the function name? Since it only
raises the timeout value with a multiplier.

I had a this patchset [1] in my mind.
Maybe we will also apply a minimum. But we would still just multiply :) so Sure we can name it tst_multiply_timeout().

[1]https://patchwork.ozlabs.org/patch/1155460

Quoted 24 lines
Quoted 24 lines
---
 testcases/lib/tst_test.sh | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)
testcases/lib/tst_test.sh +1 -1
index e0b24c6b9..03692e503 100644
@@ -164,7 +164,7 @@ TST_RETRY_FN_EXP_BACKOFF()
 {
        local tst_fun="$1"
        local tst_exp=$2
-       local tst_sec=$(expr $3 \* 1000000)
+       local tst_sec=$(tst_adjust_timeout $(expr $3 \* 1000000))
        local tst_delay=1
 
        if [ $# -ne 3 ]; then
@@ -371,12 +371,16 @@ _tst_rescmp()
        fi
 }
 
Quoted 10 lines

testcases/lib/tst_test.sh _tst_rescmp() · line 380

Quoted 8 lines
testcases/lib/tst_test.sh +3 -2
-
-_tst_setup_timer()
+tst_adjust_timeout()
 {
        LTP_TIMEOUT_MUL=${LTP_TIMEOUT_MUL:-1}
+       local timeout=$1
+       echo $(( timeout * LTP_TIMEOUT_MUL))
 

Shouldn't we check the LTP_TIMEOUT_MUL > 1 before using it?

Yes, thx for the hint.

#8 lore raw

PATCH v2 1/3 tst_test.sh: Use LTP_TIMEOUT_MUL in TST_RETRY_FN()

Hi Clemens,

Quoted 7 lines · Li Wang
Quoted 5 lines
Quoted 2 lines · Clemens Famulla-Conrad

Because of timeout problems when using TST_RETRY_FN() we do now use LTP_TIMEOUT_MUL to adopt the timeout value.

Quoted 7 lines
Quoted 7 lines
Quoted 2 lines

Introduced tst_adjut_timeout function to have a generic place to adopt timeout values.

What about using tst_multipy_timeout as the function name? Since it only
raises the timeout value with a multiplier.

+1.

Quoted 4 lines

I had a this patchset [1] in my mind.
Maybe we will also apply a minimum. But we would still just multiply :) so Sure we can name it tst_multiply_timeout().

Quoted 35 lines

[1]https://patchwork.ozlabs.org/patch/1155460

Quoted 31 lines
Quoted 19 lines
---
 testcases/lib/tst_test.sh | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)
testcases/lib/tst_test.sh +1 -1
index e0b24c6b9..03692e503 100644
@@ -164,7 +164,7 @@ TST_RETRY_FN_EXP_BACKOFF()
 {
        local tst_fun="$1"
        local tst_exp=$2
-       local tst_sec=$(expr $3 \* 1000000)
+       local tst_sec=$(tst_adjust_timeout $(expr $3 \* 1000000))
        local tst_delay=1
 
        if [ $# -ne 3 ]; then

testcases/lib/tst_test.sh _tst_rescmp() · line 378

Quoted 10 lines
testcases/lib/tst_test.sh +3 -2
@@ -371,12 +371,16 @@ _tst_rescmp()
        fi
 }
 
-
-_tst_setup_timer()
+tst_adjust_timeout()
 {
        LTP_TIMEOUT_MUL=${LTP_TIMEOUT_MUL:-1}
+       local timeout=$1
+       echo $(( timeout * LTP_TIMEOUT_MUL))

Shouldn't we check the LTP_TIMEOUT_MUL > 1 before using it?

Also timeout should be checked.
I'd tst_brk TBROK if either of them is < 0.

Quoted 1 line

Yes, thx for the hint.

BTW: I haven't finish patchset doing the same [1]. Feel free to include docs from [2].

I'll also sent tonight LTP_TIMEOUT_MUL_MIN (as part of v2 for [3]).
But it should be trivial to rebase changes of the later commit (whoever gets merged first).

Kind regards,
Petr

[1] https://patchwork.ozlabs.org/project/ltp/list/?series=120151&state=*
[2] https://patchwork.ozlabs.org/patch/1133627/
[3] https://patchwork.ozlabs.org/patch/1155460/

#9 lore raw

PATCH v2 1/3 tst_test.sh: Use LTP_TIMEOUT_MUL in TST_RETRY_FN()

Quoted 58 lines · Petr Vorel

Hi Clemens,

Quoted 11 lines · Li Wang
Quoted 8 lines
Quoted 6 lines · Clemens Famulla-Conrad

Because of timeout problems when using TST_RETRY_FN() we do now use
LTP_TIMEOUT_MUL to adopt the timeout value. Introduced tst_adjut_timeout function to have a generic place to
adopt timeout values.

Quoted 4 lines
Quoted 4 lines

What about using tst_multipy_timeout as the function name? Since it
only
raises the timeout value with a multiplier.

+1.

Quoted 37 lines

I had a this patchset [1] in my mind.
Maybe we will also apply a minimum. But we would still just multiply :)
so Sure we can name it tst_multiply_timeout(). [1]https://patchwork.ozlabs.org/patch/1155460

Quoted 29 lines
Quoted 19 lines
---
 testcases/lib/tst_test.sh | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)
testcases/lib/tst_test.sh +1 -1
index e0b24c6b9..03692e503 100644
@@ -164,7 +164,7 @@ TST_RETRY_FN_EXP_BACKOFF()
 {
        local tst_fun="$1"
        local tst_exp=$2
-       local tst_sec=$(expr $3 \* 1000000)
+       local tst_sec=$(tst_adjust_timeout $(expr $3 \*
 1000000))
        local tst_delay=1
        if [ $# -ne 3 ]; then

testcases/lib/tst_test.sh _tst_rescmp() · line 377

Quoted 9 lines
testcases/lib/tst_test.sh +3 -2
@@ -371,12 +371,16 @@ _tst_rescmp()
        fi
 }
-
-_tst_setup_timer()
+tst_adjust_timeout()
 {
        LTP_TIMEOUT_MUL=${LTP_TIMEOUT_MUL:-1}
+       local timeout=$1
+       echo $(( timeout * LTP_TIMEOUT_MUL))

Shouldn't we check the LTP_TIMEOUT_MUL > 1 before using it?

Quoted 8 lines

Also timeout should be checked.
I'd tst_brk TBROK if either of them is < 0.

Quoted 1 line

Yes, thx for the hint.

BTW: I haven't finish patchset doing the same [1]. Feel free to include docs
from [2].

Thx for that hint, was aware of that patchset [1].

Quoted 12 lines

I'll also sent tonight LTP_TIMEOUT_MUL_MIN (as part of v2 for [3]). But it should be trivial to rebase changes of the later commit (whoever gets merged first).

Kind regards,
Petr

[1] https://patchwork.ozlabs.org/project/ltp/list/?series=120151&stat
e=*
[2] https://patchwork.ozlabs.org/patch/1133627/
[3] https://patchwork.ozlabs.org/patch/1155460/

#10 lore raw

PATCH v2 1/3 tst_test.sh: Use LTP_TIMEOUT_MUL in TST_RETRY_FN()

Quoted 7 lines · Clemens Famulla-Conrad
Quoted 4 lines · Petr Vorel

BTW: I haven't finish patchset doing the same [1]. Feel free to include docs
from [2].

Thx for that hint, was aware of that patchset [1].

^
not (important detail :)

#11 lore raw

PATCH v2 1/3 tst_test.sh: Use LTP_TIMEOUT_MUL in TST_RETRY_FN()

In reply to Clemens Famulla-Conrad

Hi Clemens,

...

testcases/lib/tst_test.sh TST_RETRY_FN_EXP_BACKOFF() · line 167

Quoted 2 lines
testcases/lib/tst_test.sh +1 -1
-	local tst_sec=$(expr $3 \* 1000000)
+	local tst_sec=$(tst_adjust_timeout $(expr $3 \* 1000000))

Just a style comment: instead of using $(expr ), I'd switch to $(( )).

Kind regards,
Petr

#12 lore raw

PATCH v2 1/3 tst_test.sh: Use LTP_TIMEOUT_MUL in TST_RETRY_FN()

In reply to Clemens Famulla-Conrad

Hi Clemens,

Quoted 5 lines

Because of timeout problems when using TST_RETRY_FN() we do now use LTP_TIMEOUT_MUL to adopt the timeout value.

Introduced tst_adjut_timeout function to have a generic place to adopt timeout values.

@Li, Cyril, Jan acking this?

for whole patchset, with suggestion to use $(( )) instead of $(expr ) [1]. (was used originaly, but when you're touching the code, could you please change it?)

I'm for merging this patchset, but I'd rather merge my "v5 shell: Introduce TST_TIMEOUT variable" [2] [3] patchset first.
I can rebase this patchset before merge.

Kind regards,
Petr

[1] https://patchwork.ozlabs.org/patch/1161157/#2258600
[2] https://patchwork.ozlabs.org/patch/1175082/
[3] https://patchwork.ozlabs.org/project/ltp/list/?series=135548&state=*

#13 lore raw

PATCH v2 1/3 tst_test.sh: Use LTP_TIMEOUT_MUL in TST_RETRY_FN()

Hi!

Quoted 3 lines

I'm for merging this patchset, but I'd rather merge my "v5 shell: Introduce TST_TIMEOUT variable" [2] [3] patchset first.
I can rebase this patchset before merge.

Well, we still need to ceil the LTP_TIMEOUT_MUL in the shell version of the TST_RETRY_FN_EXP_BACKOFF. So I would say that your patch has to go first, then we need to export the part that ceils the timeout multiplier as a function and finally use it in the first patch of this patchset.

Signature · 2 lines
Cyril Hrubis
[email protected]
#14 lore raw

PATCH v2 1/3 tst_test.sh: Use LTP_TIMEOUT_MUL in TST_RETRY_FN()

Quoted 11 lines · Cyril Hrubis

Hi!

Quoted 1 line

I'm for merging this patchset, but I'd rather merge my "v5 shell:

Introduce

Quoted 2 lines

TST_TIMEOUT variable" [2] [3] patchset first.
I can rebase this patchset before merge.

Well, we still need to ceil the LTP_TIMEOUT_MUL in the shell version of the TST_RETRY_FN_EXP_BACKOFF. So I would say that your patch has to go first, then we need to export the part that ceils the timeout multiplier as a function and finally use it in the first patch of this patchset.

Agreed.

@Petr, I have no more comments, feel free to merge this with the changing as we discussed.

Signature · 5 lines
Regards,
Li Wang
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.linux.it/pipermail/ltp/attachments/20191012/13570177/attachment.htm>
#15 lore raw

PATCH v2 1/3 tst_test.sh: Use LTP_TIMEOUT_MUL in TST_RETRY_FN()

On Sat, 2019-10-12 at 10:46 +0800, Li Wang wrote:
<snip>

Quoted 6 lines

Agreed.

@Petr, I have no more comments, feel free to merge this with the changing
as we discussed.

@Petr, I have v3 almost ready. Will send it soon.

#16 lore raw

PATCH v3 1/4 tst_test.sh: Use LTP_TIMEOUT_MUL in TST_RETRY_FN()

Because of timeout problems when using TST_RETRY_FN() we do now use LTP_TIMEOUT_MUL to adopt the timeout value.

Introduced tst_multiply_timeout function to have a generic place to adopt timeout values.

---
 testcases/lib/tst_test.sh | 35 +++++++++++++++++++++++++----------
 1 file changed, 25 insertions(+), 10 deletions(-)
testcases/lib/tst_test.sh +25 -10
index d8071cb10..ee220ac19 100644
@@ -164,9 +164,11 @@ TST_RETRY_FN_EXP_BACKOFF()
 {
 	local tst_fun="$1"
 	local tst_exp=$2
-	local tst_sec=$(expr $3 \* 1000000)
+	local tst_sec=$(( $3 * 1000000 ))
 	local tst_delay=1
 
+	tst_multiply_timeout tst_sec
+
 	if [ $# -ne 3 ]; then
 		tst_brk TBROK "TST_RETRY_FN_EXP_BACKOFF expects 3 parameters"
 	fi
@@ -376,16 +378,13 @@ _tst_rescmp()
 	fi
 }
 
-
-_tst_setup_timer()
+tst_multiply_timeout()
 {
-	TST_TIMEOUT=${TST_TIMEOUT:-300}
-	LTP_TIMEOUT_MUL=${LTP_TIMEOUT_MUL:-1}
+	# first parameter is used as return value
+	local timeout="${!1}"
+	[ $# -gt 1 ] && timeout="$2"
 
-	if [ "$TST_TIMEOUT" = -1 ]; then
-		tst_res TINFO "Timeout per run is disabled"
-		return
-	fi
+	LTP_TIMEOUT_MUL=${LTP_TIMEOUT_MUL:-1}
 
 	local err="LTP_TIMEOUT_MUL must be number >= 1!"
 
@@ -396,13 +395,29 @@ _tst_setup_timer()
 		LTP_TIMEOUT_MUL=$((LTP_TIMEOUT_MUL+1))
 		tst_res TINFO "ceiling LTP_TIMEOUT_MUL to $LTP_TIMEOUT_MUL"
 	fi
+
 	[ "$LTP_TIMEOUT_MUL" -ge 1 ] || tst_brk TBROK "$err ($LTP_TIMEOUT_MUL)"
+	[ "$timeout" -ge 1 ] || tst_brk TBROK "timeout need to be >= 1 ($timeout)"
+
+	eval "$1='$(( timeout * LTP_TIMEOUT_MUL))'"
+	return 0
+}
+
+_tst_setup_timer()
+{
+	TST_TIMEOUT=${TST_TIMEOUT:-300}
+
+	if [ "$TST_TIMEOUT" = -1 ]; then
+		tst_res TINFO "Timeout per run is disabled"
+		return
+	fi
 
 	if ! tst_is_int "$TST_TIMEOUT" || [ "$TST_TIMEOUT" -lt 1 ]; then
 		tst_brk TBROK "TST_TIMEOUT must be int >= 1! ($TST_TIMEOUT)"
 	fi
 
-	local sec=$((TST_TIMEOUT * LTP_TIMEOUT_MUL))
+	local sec=$TST_TIMEOUT
+	tst_multiply_timeout sec
 	local h=$((sec / 3600))
 	local m=$((sec / 60 % 60))
 	local s=$((sec % 60))
Signature · 1 line
2.16.4
#17 lore raw

PATCH v3 2/4 tst_test.c: Add tst_multiply_timeout()

This function is used to adjust timeout values with environment variables like LTP_TIMEOUT_MUL.

---
 include/tst_test.h |  1 +
 lib/tst_test.c     | 41 ++++++++++++++++++++++++++++++-----------
 2 files changed, 31 insertions(+), 11 deletions(-)
include/tst_test.h +1 -0
index 84acf2c59..aaea128ba 100644
@@ -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);
 
 
lib/tst_test.c +30 -11

61 lines not on this page · raw message

Signature · 1 line
2.16.4
#18 lore raw

PATCH v3 2/4 tst_test.c: Add tst_multiply_timeout()

Hi Clemens,

Quoted 4 lines

This function is used to adjust timeout values with environment variables like LTP_TIMEOUT_MUL.

LGTM, minor formatting/wording bellow.

...

lib/tst_test.c unsigned int tst_timeout_remaining(void) · line 1102

Quoted 8 lines
lib/tst_test.c +5 -2
-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){

Please add space before { (on more places + unnecessary { }). linux/scripts/checkpatch.pl --terse --no-tree -f lib/tst_test.c would tell you :)
([1] but we don't follow it fully - common sense is applied, but we try).

Quoted 6 lines
lib/tst_test.c +6 -0
+		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);

lib/tst_test.c unsigned int tst_timeout_remaining(void) · line 1118

Quoted 10 lines
lib/tst_test.c +10 -0
+			}
+		} 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);

nit: need => maybe must/needs ?

Kind regards,
Petr
[1] https://github.com/linux-test-project/ltp/wiki/Test-Writing-Guidelines#131-c-coding-style

#19 lore raw

PATCH v3 3/4 tst_common.h: Use tst_multiply_timeout in TST_RETRY_FN()

In reply to Clemens Famulla-Conrad

Because of timeout problems when using TST_RETRY_FN() we want a LTP_TIMEOUT_MUL adopted timeout value here as well.

---
 include/tst_common.h | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
include/tst_common.h +4 -2
index c21505450..b901273b0 100644
@@ -50,12 +50,14 @@
 	TST_RETRY_FN_EXP_BACKOFF(FUNC, ERET, 1)
 
 #define TST_RETRY_FN_EXP_BACKOFF(FUNC, ERET, MAX_DELAY)	\
-({	int tst_delay_ = 1;						\
+({	unsigned int tst_delay_, tst_max_delay_;			\
+	tst_delay_ = 1;							\
+	tst_max_delay_ = tst_multiply_timeout(MAX_DELAY * 1000000);	\
 	for (;;) {							\
 		typeof(FUNC) tst_ret_ = FUNC;				\
 		if (tst_ret_ == ERET)					\
 			break;						\
-		if (tst_delay_ < MAX_DELAY * 1000000) {			\
+		if (tst_delay_ < tst_max_delay_) {			\
 			usleep(tst_delay_);				\
 			tst_delay_ *= 2;				\
 		} else {						\
Signature · 1 line
2.16.4
#21 lore raw

PATCH v3 4/4 Add newlib shell test for tst_multiply_timeout()

In reply to Clemens Famulla-Conrad

Simple test for different kinds of calls from tst_multiply_timeout()

---
 lib/newlib_tests/shell/test_timeout_mul.sh | 54 ++++++++++++++++++++++++++++++
 1 file changed, 54 insertions(+)
 create mode 100755 lib/newlib_tests/shell/test_timeout_mul.sh
lib/newlib_tests/shell/test_timeout_mul.sh new file +54 -0
new file mode 100755
index 000000000..8397df25c
@@ -0,0 +1,54 @@
+#!/bin/bash
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (c) 2019 Clemens Famulla-Conrad <[email protected]>
+
+TST_TESTFUNC=do_test
+. tst_test.sh
+
+
+call_it()
+{
+	local SAVE_MUL=${LTP_TIMEOUT_MUL}
+	$1
+	if [ "${!2}" -ne "$3" ]; then
+		tst_brk TBROK "LTP_TIMEOUT_MUL=$SAVE_MUL $1 (${!2} != $3)"
+	else
+		tst_res TPASS "LTP_TIMEOUT_MUL=$SAVE_MUL $1 (${!2} == $3)"
+	fi
+}
+
+do_test()
+{
+	LTP_TIMEOUT_MUL=2
+	local sec=1
+
+        call_it 'tst_multiply_timeout sec' 'sec' 2
+        call_it 'tst_multiply_timeout foo 1000' 'foo' 2000
+
+	sec=1
+        call_it 'tst_multiply_timeout sec 500' 'sec' 1000
+
+	sec=1
+	LTP_TIMEOUT_MUL="1.5"
+        call_it 'tst_multiply_timeout sec' 'sec' 2
+
+	sec=1
+	LTP_TIMEOUT_MUL=0.5
+        call_it 'tst_multiply_timeout sec' 'sec' 1
+
+	sec=1
+	LTP_TIMEOUT_MUL=1.5
+        call_it 'tst_multiply_timeout sec 5' 'sec' 10
+
+	sec=1
+	LTP_TIMEOUT_MUL=0.5
+        call_it 'tst_multiply_timeout sec 5' 'sec' 5
+
+	sec=1
+	LTP_TIMEOUT_MUL=2
+        call_it 'tst_multiply_timeout sec' 'sec' 2
+        call_it 'tst_multiply_timeout sec' 'sec' 4
+        call_it 'tst_multiply_timeout sec' 'sec' 8
+}
+
+tst_run;
Signature · 1 line
2.16.4
#22 lore raw

PATCH v3 4/4 Add newlib shell test for tst_multiply_timeout()

Hi Clemens,

lib/newlib_tests/shell/test_timeout_mul.sh line 1

Quoted 13 lines

Simple test for different kinds of calls from tst_multiply_timeout()

---
 lib/newlib_tests/shell/test_timeout_mul.sh | 54 ++++++++++++++++++++++++++++++
 1 file changed, 54 insertions(+)
 create mode 100755 lib/newlib_tests/shell/test_timeout_mul.sh
lib/newlib_tests/shell/test_timeout_mul.sh new file +1 -0
new file mode 100755
index 000000000..8397df25c
@@ -0,0 +1,54 @@
+#!/bin/bash

This is library test, which will run on developer box, where bash is for sure. But I'd still prefer to have /bin/sh with posix shell syntax. Mainly because if you have /bin/bash in sources people will write tests with bashisms (even if you document that bash is only allowed for these library tests).

But we should have a discussion on that and document it ([1]).

lib/newlib_tests/shell/test_timeout_mul.sh line 6

Quoted 5 lines
lib/newlib_tests/shell/test_timeout_mul.sh new file +5 -0
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (c) 2019 Clemens Famulla-Conrad <[email protected]>
+
+TST_TESTFUNC=do_test
+. tst_test.sh

This expect PATH to be set correctly. Which is probably better approach, than mine (I put PATH for tst_test.sh into lib/newlib_tests/shell/test_timeout_mul.sh; best would be to have 'make check', which would set it; my patch [2] does not set it).

Quoted 12 lines
lib/newlib_tests/shell/test_timeout_mul.sh new file +12 -0
+
+
+call_it()
+{
+	local SAVE_MUL=${LTP_TIMEOUT_MUL}
+	$1
+	if [ "${!2}" -ne "$3" ]; then
+		tst_brk TBROK "LTP_TIMEOUT_MUL=$SAVE_MUL $1 (${!2} != $3)"
+	else
+		tst_res TPASS "LTP_TIMEOUT_MUL=$SAVE_MUL $1 (${!2} == $3)"
+	fi
+}

lib/newlib_tests/shell/test_timeout_mul.sh line 28

Quoted 10 lines
lib/newlib_tests/shell/test_timeout_mul.sh new file +10 -0
+
+do_test()
+{
+	LTP_TIMEOUT_MUL=2
+	local sec=1
+
+        call_it 'tst_multiply_timeout sec' 'sec' 2
+        call_it 'tst_multiply_timeout foo 1000' 'foo' 2000
+
+	sec=1

You mix tabs and spaces.

Quoted 16 lines
lib/newlib_tests/shell/test_timeout_mul.sh new file +16 -0
+        call_it 'tst_multiply_timeout sec 500' 'sec' 1000
+
+	sec=1
+	LTP_TIMEOUT_MUL="1.5"
+        call_it 'tst_multiply_timeout sec' 'sec' 2
+
+	sec=1
+	LTP_TIMEOUT_MUL=0.5
+        call_it 'tst_multiply_timeout sec' 'sec' 1
+
+	sec=1
+	LTP_TIMEOUT_MUL=1.5
+        call_it 'tst_multiply_timeout sec 5' 'sec' 10
+
+	sec=1
+	LTP_TIMEOUT_MUL=0.5

lib/newlib_tests/shell/test_timeout_mul.sh line 54

Quoted 10 lines
lib/newlib_tests/shell/test_timeout_mul.sh new file +10 -0
+        call_it 'tst_multiply_timeout sec 5' 'sec' 5
+
+	sec=1
+	LTP_TIMEOUT_MUL=2
+        call_it 'tst_multiply_timeout sec' 'sec' 2
+        call_it 'tst_multiply_timeout sec' 'sec' 4
+        call_it 'tst_multiply_timeout sec' 'sec' 8
+}
+
+tst_run;

Unnecessary ;

Kind regards,
Petr

[1] https://patchwork.ozlabs.org/patch/1166786/
[2] https://patchwork.ozlabs.org/patch/1166785/

#23 lore raw

PATCH v3 1/4 tst_test.sh: Use LTP_TIMEOUT_MUL in TST_RETRY_FN()

In reply to Clemens Famulla-Conrad

Hi Clemens,

...

testcases/lib/tst_test.sh _tst_rescmp() · line 381

Quoted 2 lines
testcases/lib/tst_test.sh +1 -1
-_tst_setup_timer()
+tst_multiply_timeout()

Private function, it should have underscore prefix.

testcases/lib/tst_test.sh _tst_rescmp() · line 384

Quoted 5 lines

{

testcases/lib/tst_test.sh +2 -2
-	TST_TIMEOUT=${TST_TIMEOUT:-300}
-	LTP_TIMEOUT_MUL=${LTP_TIMEOUT_MUL:-1}
+	# first parameter is used as return value
+	local timeout="${!1}"

Bashism, this will not work on dash, busybox shell ('busybox sh'), etc.

checkbashisms.pl is your friend :).
https://salsa.debian.org/debian/devscripts/raw/master/scripts/checkbashisms.pl
https://github.com/linux-test-project/ltp/wiki/Test-Writing-Guidelines#132-shell-coding-style

Variable variable is possible to do portable way with eval. eval timeout=\$$1

Quoted 10 lines
testcases/lib/tst_test.sh +2 -4
+	[ $# -gt 1 ] && timeout="$2"
-	if [ "$TST_TIMEOUT" = -1 ]; then
-		tst_res TINFO "Timeout per run is disabled"
-		return
-	fi
+	LTP_TIMEOUT_MUL=${LTP_TIMEOUT_MUL:-1}
 
 	local err="LTP_TIMEOUT_MUL must be number >= 1!"

testcases/lib/tst_test.sh _tst_setup_timer() · line 402

Quoted 8 lines
testcases/lib/tst_test.sh +4 -0
@@ -396,13 +395,29 @@ _tst_setup_timer()
 		LTP_TIMEOUT_MUL=$((LTP_TIMEOUT_MUL+1))
 		tst_res TINFO "ceiling LTP_TIMEOUT_MUL to $LTP_TIMEOUT_MUL"
 	fi
+
 	[ "$LTP_TIMEOUT_MUL" -ge 1 ] || tst_brk TBROK "$err ($LTP_TIMEOUT_MUL)"
+	[ "$timeout" -ge 1 ] || tst_brk TBROK "timeout need to be >= 1 ($timeout)"
+
+	eval "$1='$(( timeout * LTP_TIMEOUT_MUL))'"

Eval on input, eval on output :).

testcases/lib/tst_test.sh _tst_setup_timer() · line 403

Quoted 1 line
testcases/lib/tst_test.sh +1 -0
+	return 0

You don't use return value anywhere. + There is no return 1.

testcases/lib/tst_test.sh _tst_setup_timer() · line 404

Quoted 1 line
testcases/lib/tst_test.sh +1 -0
+}

Passing timeout variable name and optionally timeout value works and allows TBROK messages not to be mangled/hidden (which would be if function echo the result, which is then read the usual way: timeout=$(tst_multiply_timeout 100) ), but I'm not sure if all this is worth of just error handling. Having 2x eval, $2 optionally used (but only in tests) makes code a bit complex.

How about just simply save the result into global variable $TST_TIMEOUT?

Kind regards,
Petr

#24 lore raw

PATCH v3 1/4 tst_test.sh: Use LTP_TIMEOUT_MUL in TST_RETRY_FN()

Quoted 16 lines · Petr Vorel

Hi Clemens,

...

testcases/lib/tst_test.sh _tst_rescmp() · line 381

Quoted 2 lines
testcases/lib/tst_test.sh +1 -1
-_tst_setup_timer()
+tst_multiply_timeout()

Private function, it should have underscore prefix.

testcases/lib/tst_test.sh _tst_rescmp() · line 384

Quoted 5 lines

{

testcases/lib/tst_test.sh +2 -2
-	TST_TIMEOUT=${TST_TIMEOUT:-300}
-	LTP_TIMEOUT_MUL=${LTP_TIMEOUT_MUL:-1}
+	# first parameter is used as return value
+	local timeout="${!1}"

Bashism, this will not work on dash, busybox shell ('busybox sh'), etc.

Quoted 8 lines

checkbashisms.pl is your friend :).
https://salsa.debian.org/debian/devscripts/raw/master/scripts/checkba
shisms.pl
https://github.com/linux-test-project/ltp/wiki/Test-Writing-Guideline
s#132-shell-coding-style

Variable variable is possible to do portable way with eval. eval timeout=\$$1

Ok, I will take bashisms into acount. Thx for pointing me to that script.

Quoted 28 lines
Quoted 18 lines
testcases/lib/tst_test.sh +2 -4
+	[ $# -gt 1 ] && timeout="$2"
-	if [ "$TST_TIMEOUT" = -1 ]; then
-		tst_res TINFO "Timeout per run is disabled"
-		return
-	fi
+	LTP_TIMEOUT_MUL=${LTP_TIMEOUT_MUL:-1}
 	local err="LTP_TIMEOUT_MUL must be number >= 1!"
@@ -396,13 +395,29 @@ _tst_setup_timer()
 		LTP_TIMEOUT_MUL=$((LTP_TIMEOUT_MUL+1))
 		tst_res TINFO "ceiling LTP_TIMEOUT_MUL to

$LTP_TIMEOUT_MUL"

testcases/lib/tst_test.sh +1 -0
 	fi
+
 	[ "$LTP_TIMEOUT_MUL" -ge 1 ] || tst_brk TBROK "$err

($LTP_TIMEOUT_MUL)"

(quoted diff) +1 -0
+	[ "$timeout" -ge 1 ] || tst_brk TBROK "timeout need to be
Quoted 1 line

= 1 ($timeout)"

Review

Quoted 2 lines
(quoted diff) +2 -0
+
+	eval "$1='$(( timeout * LTP_TIMEOUT_MUL))'"

Eval on input, eval on output :).

testcases/lib/tst_test.sh _tst_setup_timer() · line 403

Quoted 1 line
testcases/lib/tst_test.sh +1 -0
+	return 0

You don't use return value anywhere. + There is no return 1.

Quoted 1 line

+}

Quoted 9 lines

Passing timeout variable name and optionally timeout value works and allows
TBROK messages not to be mangled/hidden (which would be if function echo the
result, which is then read the usual way:
timeout=$(tst_multiply_timeout 100) ),
but I'm not sure if all this is worth of just error handling. Having 2x eval, $2 optionally used (but only in tests) makes code a bit complex.

In the end, I never called the function with the optional second parameter. So we could remove it and with it, the first eval. Would you be ok with just one eval ?

Quoted 2 lines

How about just simply save the result into global variable $TST_TIMEOUT?

Will not work, as this function is also used in TST_RETRY_FN_EXP_BACKOFF() where we do not use TST_TIMEOUT.

thanks
Clemens

#25 lore raw

PATCH v3 1/4 tst_test.sh: Use LTP_TIMEOUT_MUL in TST_RETRY_FN()

Hi Clemens,

Quoted 5 lines
Quoted 2 lines

Variable variable is possible to do portable way with eval. eval timeout=\$$1

Ok, I will take bashisms into acount. Thx for pointing me to that script.

Thanks!

Quoted 14 lines
Quoted 9 lines

Passing timeout variable name and optionally timeout value works and allows
TBROK messages not to be mangled/hidden (which would be if function echo the
result, which is then read the usual way:
timeout=$(tst_multiply_timeout 100) ),
but I'm not sure if all this is worth of just error handling. Having 2x eval, $2 optionally used (but only in tests) makes code a bit complex.

In the end, I never called the function with the optional second parameter. So we could remove it and with it, the first eval. Would you be ok with just one eval ?

Quoted 5 lines
Quoted 2 lines

How about just simply save the result into global variable $TST_TIMEOUT?

Will not work, as this function is also used in TST_RETRY_FN_EXP_BACKOFF() where we do not use TST_TIMEOUT.

OK.

Previously I was thinking to echo result or error message and handle error outside, depending on return value:

	timeout_or_error=$(tst_multiply_timeout 100) || tst_brk TBROK "$timeout_or_error"

but that's not nice solution either.

Your solution (with removed second parameter) is ok, it just looks unusual for me (passing variable name to be changed, something like "shell way of passing a pointer" is not really common), but as I don't see any other solution, I'm ok with that. But I'd like to get somebody else opinion, maybe we just don't see other obvious solution.

Kind regards,
Petr