[LTP] [PATCH v4 3/4] tst_test.sh: Fix _tst_cleanup_timer() on set -e

Petr Vorel pvorel@suse.cz
Wed Aug 10 18:29:59 CEST 2022


Hi Martin,

> Hi,
> a comment explaining why this is needed would be nice, otherwise looks
> good. For patches 2 and 3:

> Reviewed-by: Martin Doucha <mdoucha@suse.cz>

> On 08. 08. 22 13:37, Petr Vorel wrote:
> > If test exits on time (i.e. no timeout) kill in _tst_cleanup_timer()
> > have nothing to kill therefore following wait exits 143.
I thought this is the explanation. Or would you prefer anything else to add?

Kind regards,
Petr

> > set -e (or #!/bin/sh -e or set -o errexit) quits on any non-zero exit code,
> > fix hardens _tst_cleanup_timer() to be able to be used on scripts with it.

> > Signed-off-by: Petr Vorel <pvorel@suse.cz>
> > ---
> > I can use 'if ...; then ; fi' if you prefer:

> > 	if [ "$LTP_COLORIZE_OUTPUT" = "n" -o "$LTP_COLORIZE_OUTPUT" = "0" ]; then
> > 		return 0
> > 	fi

> > 	if [ "$LTP_COLORIZE_OUTPUT" = "y" ] || [ "$LTP_COLORIZE_OUTPUT" = "1" ]; then
> > 		return 1
> > 	fi

> > ...
> > 	if [ "$color" = 1 ]; then
> > 		tst_flag2color "$1"
> > 	fi
> > 	printf "$2"
> > 	if [ "$color" = 1 ]; then
> > 		printf '\033[0m'
> > 	fi


> > Kind regards,
> > Petr

> >  testcases/lib/tst_test.sh | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)

> > diff --git a/testcases/lib/tst_test.sh b/testcases/lib/tst_test.sh
> > index 356af0106..1d2bf06cc 100644
> > --- a/testcases/lib/tst_test.sh
> > +++ b/testcases/lib/tst_test.sh
> > @@ -518,7 +518,7 @@ _tst_cleanup_timer()
> >  {
> >  	if [ -n "$_tst_setup_timer_pid" ]; then
> >  		kill -TERM $_tst_setup_timer_pid 2>/dev/null
> > -		wait $_tst_setup_timer_pid 2>/dev/null
> > +		wait $_tst_setup_timer_pid 2>/dev/null || true
> >  	fi
> >  }


More information about the ltp mailing list