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

Petr Vorel pvorel@suse.cz
Tue Nov 23 19:07:11 CET 2021


There is no need to run setup before printing help.

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
-- 
2.33.1



More information about the ltp mailing list