diff mbox series

[v2,2/2] tst_test.sh: Convert only TBROK/TCONF to TWARN in cleanup

Message ID 20250211205734.1932275-2-pvorel@suse.cz
State Changes Requested
Headers show
Series [v2,1/2] tst_test.sh: Fix TBROK => TWARN evaluation in tst_brk() | expand

Commit Message

Petr Vorel Feb. 11, 2025, 8:57 p.m. UTC
Second attempt to convert only TBROK/TCONF to TWARN in cleanup().

Also print original message to help find function call with wrong
parameter.

Fixes: 55bfa08e17 ("tst_test.sh/tst_brk(): Convert only TBROK to TWARN in cleanup")
Signed-off-by: Petr Vorel <pvorel@suse.cz>
---
New in v2.

 testcases/lib/tst_test.sh | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)

Comments

Andrea Cervesato Dec. 18, 2025, 12:43 p.m. UTC | #1
Hi!

On Tue Feb 11, 2025 at 9:57 PM CET, Petr Vorel wrote:
> Second attempt to convert only TBROK/TCONF to TWARN in cleanup().
>
> Also print original message to help find function call with wrong
> parameter.
>
> Fixes: 55bfa08e17 ("tst_test.sh/tst_brk(): Convert only TBROK to TWARN in cleanup")
> Signed-off-by: Petr Vorel <pvorel@suse.cz>
> ---
> New in v2.
>
>  testcases/lib/tst_test.sh | 14 ++++++++++----
>  1 file changed, 10 insertions(+), 4 deletions(-)
>
> diff --git a/testcases/lib/tst_test.sh b/testcases/lib/tst_test.sh
> index 5a6e34473f..0747f7aaf4 100644
> --- a/testcases/lib/tst_test.sh
> +++ b/testcases/lib/tst_test.sh
> @@ -126,11 +126,17 @@ tst_brk()
>  	local res=$1
>  	shift
>  
> -	if [ "$res" != TBROK -a "$res" != TCONF ]; then
> -		tst_res TBROK "tst_brk can be called only with TBROK or TCONF ($res)"
> -	elif [ "$TST_TBROK_TO_TWARN" = 1 ]; then
> -		tst_res TWARN "$@"
> +	if [ "$TST_TBROK_TO_TWARN" = 1 ]; then
> +		if [ "$res" != TBROK -a "$res" != TCONF ]; then
> +			tst_res TWARN "tst_brk can be called only with TBROK or TCONF ($res, msg: '$@')"
> +		else
> +			tst_res TWARN "$@"
> +		fi
>  		return
> +	fi
> +
> +	if [ "$res" != TBROK -a "$res" != TCONF ]; then
> +		tst_res TBROK "tst_brk can be called only with TBROK or TCONF ($res, msg: '$@')"
>  	else
>  		tst_res "$res" "$@"
>  	fi

Here there's a bit of code duplication. For instance, we can save the
message inside a variable, as well as the T-flag, the use it accordingly
to TST_TBROK_TO_TWARN.
Petr Vorel Jan. 5, 2026, 2:24 p.m. UTC | #2
Hi Andrea,

...
> > +	if [ "$TST_TBROK_TO_TWARN" = 1 ]; then
> > +		if [ "$res" != TBROK -a "$res" != TCONF ]; then
> > +			tst_res TWARN "tst_brk can be called only with TBROK or TCONF ($res, msg: '$@')"
> > +		else
> > +			tst_res TWARN "$@"
> > +		fi
> >  		return
> > +	fi
> > +
> > +	if [ "$res" != TBROK -a "$res" != TCONF ]; then
> > +		tst_res TBROK "tst_brk can be called only with TBROK or TCONF ($res, msg: '$@')"
> >  	else
> >  		tst_res "$res" "$@"
> >  	fi

> Here there's a bit of code duplication. For instance, we can save the
> message inside a variable, as well as the T-flag, the use it accordingly
> to TST_TBROK_TO_TWARN.

Sure, this could be done, but as for other tst_test.sh modifications: unless
it's an important fix I'd not touch it as we now have a shell loader. Again,
I'm sorry to waste your time for the review.

Kind regards,
Petr
diff mbox series

Patch

diff --git a/testcases/lib/tst_test.sh b/testcases/lib/tst_test.sh
index 5a6e34473f..0747f7aaf4 100644
--- a/testcases/lib/tst_test.sh
+++ b/testcases/lib/tst_test.sh
@@ -126,11 +126,17 @@  tst_brk()
 	local res=$1
 	shift
 
-	if [ "$res" != TBROK -a "$res" != TCONF ]; then
-		tst_res TBROK "tst_brk can be called only with TBROK or TCONF ($res)"
-	elif [ "$TST_TBROK_TO_TWARN" = 1 ]; then
-		tst_res TWARN "$@"
+	if [ "$TST_TBROK_TO_TWARN" = 1 ]; then
+		if [ "$res" != TBROK -a "$res" != TCONF ]; then
+			tst_res TWARN "tst_brk can be called only with TBROK or TCONF ($res, msg: '$@')"
+		else
+			tst_res TWARN "$@"
+		fi
 		return
+	fi
+
+	if [ "$res" != TBROK -a "$res" != TCONF ]; then
+		tst_res TBROK "tst_brk can be called only with TBROK or TCONF ($res, msg: '$@')"
 	else
 		tst_res "$res" "$@"
 	fi