public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
From: Petr Vorel <pvorel@suse.cz>
To: ltp@lists.linux.it
Subject: [LTP] [PATCH] lib/tst_test.sh: don't call _tst_do_exit() recursively with tst_brk()
Date: Tue, 27 Nov 2018 10:04:39 +0100	[thread overview]
Message-ID: <20181127090439.GA23733@dell5510> (raw)
In-Reply-To: <1542729786-4097-1-git-send-email-alexey.kodanev@oracle.com>

Hi Alexey,

> With this patch, "safe" functions such as "ROD" and "tst_rhost_run -s"
> can be used in a test cleanup function, i.e. in case of an error, "safe"
> command won't recursively call the cleanup function again but will only
> print the warning message about the failure.

> This behavior is consistent with the LTP C library.

> Signed-off-by: Alexey Kodanev <alexey.kodanev@oracle.com>
Reviewed-by: Petr Vorel <pvorel@suse.cz>
> ---
>  testcases/lib/tst_test.sh |    6 ++++++
>  1 files changed, 6 insertions(+), 0 deletions(-)

> diff --git a/testcases/lib/tst_test.sh b/testcases/lib/tst_test.sh
> index 16081fa..e84cf7f 100644
> --- a/testcases/lib/tst_test.sh
> +++ b/testcases/lib/tst_test.sh
> @@ -41,6 +41,7 @@ trap "tst_brk TBROK 'test interrupted'" INT
>  _tst_do_exit()
>  {
>  	local ret=0
> +	TST_DO_EXIT=1

>  	if [ -n "$TST_SETUP_STARTED" -a -n "$TST_CLEANUP" -a \
>  	     -z "$TST_NO_CLEANUP" ]; then
> @@ -123,6 +124,11 @@ tst_brk()
>  	local res=$1
>  	shift

> +	if [ "$TST_DO_EXIT" = 1 ]; then
> +		tst_res TWARN "$@"
> +		return
> +	fi
> +
>  	tst_res "$res" "$@"
>  	_tst_do_exit
>  }

Shouldn't we return explicitly after any tst_brk_ call in tst_rhost_run()?
Without that we get warning twice, when called from cleanup.
test 2 TWARN: tst_rhost_run: command not defined
test 2 TWARN: tst_rhost_run: command not defined

This should fix it:

diff --git testcases/lib/tst_net.sh testcases/lib/tst_net.sh
index d1206e285..385e3bf5c 100644
--- testcases/lib/tst_net.sh
+++ testcases/lib/tst_net.sh
@@ -140,8 +140,11 @@ tst_rhost_run()
 	local user="root"
 	local cmd=
 	local safe=0
+	local ttype=TWARN
 	local bg=
 
+	[ "$safe" -eq 1 ] && ttype=TWARN
+
 	OPTIND=0
 
 	while getopts :bBsc:u: opt; do
@@ -161,9 +164,7 @@ tst_rhost_run()
 	OPTIND=0
 
 	if [ -z "$cmd" ]; then
-		[ "$safe" -eq 1 ] && \
-			tst_brk_ TBROK "tst_rhost_run: command not defined"
-		tst_res_ TWARN "tst_rhost_run: command not defined"
+		tst_brk_ $ttype "tst_rhost_run: command not defined"
 		return 1
 	fi
 
@@ -182,8 +183,10 @@ tst_rhost_run()
 	echo "$output" | grep -q 'RTERR$' && ret=1
 	if [ $ret -eq 1 ]; then
 		output=$(echo "$output" | sed 's/RTERR//')
-		[ "$safe" -eq 1 ] && \
+		if [ "$safe" -eq 1 ]; then
 			tst_brk_ TBROK "'$cmd' failed on '$RHOST': '$output'"
+			return 1
+		fi
 	fi
 
 	[ -z "$out" -a -n "$output" ] && echo "$output"


Other option is really run $TST_CLEANUP function only once, but that's
inconsistent with C library :-(. Code would be simple:

diff --git testcases/lib/tst_test.sh testcases/lib/tst_test.sh
index adfaea47e..beb1275ba 100644
--- testcases/lib/tst_test.sh
+++ testcases/lib/tst_test.sh
@@ -44,6 +44,7 @@ _tst_do_exit()
 
 	if [ -n "$TST_SETUP_STARTED" -a -n "$TST_CLEANUP" -a \
 	     -z "$TST_NO_CLEANUP" ]; then
+		TST_NO_CLEANUP=1
 		$TST_CLEANUP
 	fi
 
And we should update doc.

Kind regards,
Petr

  reply	other threads:[~2018-11-27  9:04 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-11-20 16:03 [LTP] [PATCH] lib/tst_test.sh: don't call _tst_do_exit() recursively with tst_brk() Alexey Kodanev
2018-11-27  9:04 ` Petr Vorel [this message]
2018-11-27 13:42   ` Alexey Kodanev
2018-11-27 15:01     ` Petr Vorel
2018-11-27 15:09     ` Petr Vorel
2018-11-30 18:18       ` [LTP] WIKI updates via git Petr Vorel
2018-12-04 11:47         ` Alexey Kodanev

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=20181127090439.GA23733@dell5510 \
    --to=pvorel@suse.cz \
    --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