[LTP] [PATCH 1/1] tst_test.sh: Print help ASAP

Petr Vorel pvorel@suse.cz
Tue Nov 23 19:26:54 CET 2021


Hi,

[ Cc Alexey ]

> There is no need to run setup before printing help.

This is wrong approach (=> reject status), it should be fixed in tst_net.sh,
which should probably run netns initialization:
[ -n "$TST_USE_NETNS" -a "$TST_INIT_NETNS" != "no" ] && init_ltp_netspace

as part of the setup function (tst_net_setup).

Because 1) running help immediately breaks redefining help in nfs07.sh [1]:

. nfs_lib.sh

TST_USAGE="show_usage"

(yes, having help for tst_net.sh, nfs_lib.sh and for some of the tests
which use it is maybe complicated flow, but it should work).

2) code works as expected for tests which use just tst_test.sh (or other
libraries which does *not* use tst_net.sh).

Sorry for the noise.

Kind regards,
Petr

[1] https://lore.kernel.org/ltp/20211123151537.14913-3-mdoucha@suse.cz/T/#u

> Before this change root was required for network tests also for -h:

>     $ PATH="$lb:$PATH" nfs01 -h
>     nfs01 1 TCONF: Must be super/root for this test!

> And with root setup was run:

> 	# PATH="$lb:$PATH" nfs07.sh -h
> 	nfs07 1 TINFO: initialize 'lhost' 'ltp_ns_veth2' interface
> 	nfs07 1 TINFO: add local addr 10.0.0.2/24
> 	nfs07 1 TINFO: add local addr fd00:1:1:1::2/64
> 	nfs07 1 TINFO: initialize 'rhost' 'ltp_ns_veth1' interface
> 	nfs07 1 TINFO: add remote addr 10.0.0.1/24
> 	nfs07 1 TINFO: add remote addr fd00:1:1:1::1/64
> 	nfs07 1 TINFO: Network config (local -- remote):
> 	nfs07 1 TINFO: ltp_ns_veth2 -- ltp_ns_veth1
> 	nfs07 1 TINFO: 10.0.0.2/24 -- 10.0.0.1/24
> 	nfs07 1 TINFO: fd00:1:1:1::2/64 -- fd00:1:1:1::1/64
> 	-t x    Socket type, tcp or udp, default is udp
> 	-v x    NFS version, default is '3'
> 	-n x    Create x files and x directories, default is 5000
> 	-h      Prints this help
> 	-i n    Execute test n times

> Now help is simply printed:

>     $ PATH="$lb:$PATH" nfs01 -h
>     -t x    Socket type, tcp or udp, default is udp
>     -v x    NFS version, default is '3'
>     -6      IPv6 tests
>     -h      Prints this help
>     -i n    Execute test n times

> Signed-off-by: Petr Vorel <pvorel@suse.cz>
> ---
>  testcases/lib/tst_test.sh | 6 +++++-
>  1 file changed, 5 insertions(+), 1 deletion(-)

> diff --git a/testcases/lib/tst_test.sh b/testcases/lib/tst_test.sh
> index 2556b28f5..3cf94adac 100644
> --- a/testcases/lib/tst_test.sh
> +++ b/testcases/lib/tst_test.sh
> @@ -606,7 +606,6 @@ tst_run()

>  	while getopts ":hi:$TST_OPTS" _tst_name $TST_ARGS; do
>  		case $_tst_name in
> -		'h') tst_usage; exit 0;;
>  		'i') TST_ITERATIONS=$OPTARG;;
>  		'?') tst_usage; exit 2;;
>  		*) $TST_PARSE_ARGS "$_tst_name" "$OPTARG";;
> @@ -789,4 +788,9 @@ if [ -z "$TST_NO_DEFAULT_RUN" ]; then
>  			tst_brk TBROK "Unexpected positional arguments '$@'"
>  		fi
>  	fi
> +
> +	if [ "$TST_PRINT_HELP" = 1 ]; then
> +		tst_usage
> +		exit 0
> +	fi
>  fi


More information about the ltp mailing list