Skip to contentSkip to conversation

tst_test.sh: Print help ASAP

PATCH In review Petr Vorel 1 participant 2 messages Nov 23, 2021

lore
Share & tools
lore

Petr Vorel

author
#0 lore raw

PATCH 1/1 tst_test.sh: Print help ASAP

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
---
 testcases/lib/tst_test.sh | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
testcases/lib/tst_test.sh +5 -1
index 2556b28f5..3cf94adac 100644
@@ -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
Signature · 5 lines
2.33.1


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
author
#1 lore raw

Hi,

[ Cc Alexey ]

Quoted 1 line

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/[email protected]/T/#u

Quoted 60 lines

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
---
 testcases/lib/tst_test.sh | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
testcases/lib/tst_test.sh +5 -1
index 2556b28f5..3cf94adac 100644
@@ -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
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp