Skip to contentSkip to conversation

tst_net.sh: Print help ASAP

PATCH In review Petr Vorel 2 participants 3 messages Jan 26, 2022 – Jan 27, 2022

lore
Share & tools
lore

Petr Vorel

author
#0 lore raw

PATCH 1/1 tst_net.sh: Print help ASAP

This also allows not requiring printing help with root when using TST_USE_NETNS:

    $ PATH="/opt/ltp/testcases/bin:$PATH" gre02.sh -h
    gre02 1 TCONF: Must be super/root for this test!

And with root setup was unnecessary things done just to print help:

    # PATH="/opt/ltp/testcases/bin:$PATH" gre02.sh -h
    gre02 1 TINFO: initialize 'lhost' 'ltp_ns_veth2' interface
    gre02 1 TINFO: add local addr 10.0.0.2/24
    gre02 1 TINFO: add local addr fd00:1:1:1::2/64
    gre02 1 TINFO: initialize 'rhost' 'ltp_ns_veth1' interface
    gre02 1 TINFO: add remote addr 10.0.0.1/24
    gre02 1 TINFO: add remote addr fd00:1:1:1::1/64
    gre02 1 TINFO: Network config (local -- remote):
    gre02 1 TINFO: ltp_ns_veth2 -- ltp_ns_veth1
    gre02 1 TINFO: 10.0.0.2/24 -- 10.0.0.1/24
    gre02 1 TINFO: fd00:1:1:1::2/64 -- fd00:1:1:1::1/64
    Usage: /opt/ltp/testcases/bin/gre02.sh [-6]
    OPTIONS
    -6      IPv6 tests
    -h      Prints this help
    -i n    Execute test n times

Now just help is printed, work for unprivileged user:

    $ PATH="/opt/ltp/testcases/bin:$PATH" gre02.sh -h
    Usage: /opt/ltp/testcases/bin/gre02.sh [-6]
    OPTIONS
    -6      IPv6 tests
    -h      Prints this help
    -i n    Execute test n times
---
 testcases/lib/tst_net.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
testcases/lib/tst_net.sh +1 -1
index 4dc0fca926..047686dc39 100644
@@ -937,7 +937,7 @@ tst_default_max_pkt()
 	echo "$((mtu + mtu / 10))"
 }
 
-[ -n "$TST_NET_SKIP_VARIABLE_INIT" ] && return 0
+[ -n "$TST_PRINT_HELP" -o -n "$TST_NET_SKIP_VARIABLE_INIT" ] && return 0
 
 # Management Link
 [ -z "$RHOST" ] && TST_USE_NETNS="yes"
Signature · 5 lines
2.34.1


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
Acked-by on v1 1/1
#1 lore raw

Hi Petr,

Quoted 44 lines · Petr Vorel

This also allows not requiring printing help with root when using TST_USE_NETNS:

    $ PATH="/opt/ltp/testcases/bin:$PATH" gre02.sh -h
    gre02 1 TCONF: Must be super/root for this test!

And with root setup was unnecessary things done just to print help:

    # PATH="/opt/ltp/testcases/bin:$PATH" gre02.sh -h
    gre02 1 TINFO: initialize 'lhost' 'ltp_ns_veth2' interface
    gre02 1 TINFO: add local addr 10.0.0.2/24
    gre02 1 TINFO: add local addr fd00:1:1:1::2/64
    gre02 1 TINFO: initialize 'rhost' 'ltp_ns_veth1' interface
    gre02 1 TINFO: add remote addr 10.0.0.1/24
    gre02 1 TINFO: add remote addr fd00:1:1:1::1/64
    gre02 1 TINFO: Network config (local -- remote):
    gre02 1 TINFO: ltp_ns_veth2 -- ltp_ns_veth1
    gre02 1 TINFO: 10.0.0.2/24 -- 10.0.0.1/24
    gre02 1 TINFO: fd00:1:1:1::2/64 -- fd00:1:1:1::1/64
    Usage: /opt/ltp/testcases/bin/gre02.sh [-6]
    OPTIONS
    -6      IPv6 tests
    -h      Prints this help
    -i n    Execute test n times

Now just help is printed, work for unprivileged user:

    $ PATH="/opt/ltp/testcases/bin:$PATH" gre02.sh -h
    Usage: /opt/ltp/testcases/bin/gre02.sh [-6]
    OPTIONS
    -6      IPv6 tests
    -h      Prints this help
    -i n    Execute test n times
---
 testcases/lib/tst_net.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
testcases/lib/tst_net.sh +0 -0
index 4dc0fca926..047686dc39 100644

testcases/lib/tst_net.sh tst_default_max_pkt() · line 943

Quoted 8 lines
testcases/lib/tst_net.sh +1 -1
@@ -937,7 +937,7 @@ tst_default_max_pkt()
 	echo "$((mtu + mtu / 10))"
 }
 
-[ -n "$TST_NET_SKIP_VARIABLE_INIT" ] && return 0
+[ -n "$TST_PRINT_HELP" -o -n "$TST_NET_SKIP_VARIABLE_INIT" ] && return 0
 
 # Management Link
 [ -z "$RHOST" ] && TST_USE_NETNS="yes"
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
author
#2 lore raw

Hi Alexey,

thanks for you review, merged.

Kind regards,
Petr

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp