]> www.infradead.org Git - users/hch/misc.git/commitdiff
selftests: mptcp: join: allow running -cCi
authorMatthieu Baerts <matthieu.baerts@tessares.net>
Mon, 7 Mar 2022 20:44:33 +0000 (12:44 -0800)
committerJakub Kicinski <kuba@kernel.org>
Wed, 9 Mar 2022 06:06:11 +0000 (22:06 -0800)
Without this patch, no tests would be ran when launching:

  mptcp_join.sh -cCi

In any order or a combination with 2 of these letters.

The recommended way with getopt is first parse all options and then act.

This allows to do some actions in priority, e.g. display the help menu
and stop.

But also some global variables changing the behaviour of this selftests
 -- like the ones behind -cCi options -- can be set before running the
different tests. By doing that, we can also avoid long and unreadable
regex.

Signed-off-by: Matthieu Baerts <matthieu.baerts@tessares.net>
Signed-off-by: Mat Martineau <mathew.j.martineau@linux.intel.com>
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
tools/testing/selftests/net/mptcp/mptcp_join.sh

index 45c6e5f069164026ee603a85df223e70077928f8..309d06781ae780727fed764ca94e2c380fda852d 100755 (executable)
@@ -16,7 +16,6 @@ capture=0
 checksum=0
 ip_mptcp=0
 check_invert=0
-do_all_tests=1
 init=0
 
 TEST_COUNT=0
@@ -2293,84 +2292,66 @@ usage()
        exit ${ret}
 }
 
-for arg in "$@"; do
-       # check for "capture/checksum" args before launching tests
-       if [[ "${arg}" =~ ^"-"[0-9a-zA-Z]*"c"[0-9a-zA-Z]*$ ]]; then
-               capture=1
-       fi
-       if [[ "${arg}" =~ ^"-"[0-9a-zA-Z]*"C"[0-9a-zA-Z]*$ ]]; then
-               checksum=1
-       fi
-       if [[ "${arg}" =~ ^"-"[0-9a-zA-Z]*"i"[0-9a-zA-Z]*$ ]]; then
-               ip_mptcp=1
-       fi
-
-       # exception for the capture/checksum/ip_mptcp options, the rest means: a part of the tests
-       if [ "${arg}" != "-c" ] && [ "${arg}" != "-C" ] && [ "${arg}" != "-i" ]; then
-               do_all_tests=0
-       fi
-done
-
-if [ $do_all_tests -eq 1 ]; then
-       all_tests
-       exit $ret
-fi
 
+tests=()
 while getopts 'fesltra64bpkdmchzCSi' opt; do
        case $opt in
                f)
-                       subflows_tests
+                       tests+=(subflows_tests)
                        ;;
                e)
-                       subflows_error_tests
+                       tests+=(subflows_error_tests)
                        ;;
                s)
-                       signal_address_tests
+                       tests+=(signal_address_tests)
                        ;;
                l)
-                       link_failure_tests
+                       tests+=(link_failure_tests)
                        ;;
                t)
-                       add_addr_timeout_tests
+                       tests+=(add_addr_timeout_tests)
                        ;;
                r)
-                       remove_tests
+                       tests+=(remove_tests)
                        ;;
                a)
-                       add_tests
+                       tests+=(add_tests)
                        ;;
                6)
-                       ipv6_tests
+                       tests+=(ipv6_tests)
                        ;;
                4)
-                       v4mapped_tests
+                       tests+=(v4mapped_tests)
                        ;;
                b)
-                       backup_tests
+                       tests+=(backup_tests)
                        ;;
                p)
-                       add_addr_ports_tests
+                       tests+=(add_addr_ports_tests)
                        ;;
                k)
-                       syncookies_tests
+                       tests+=(syncookies_tests)
                        ;;
                S)
-                       checksum_tests
+                       tests+=(checksum_tests)
                        ;;
                d)
-                       deny_join_id0_tests
+                       tests+=(deny_join_id0_tests)
                        ;;
                m)
-                       fullmesh_tests
+                       tests+=(fullmesh_tests)
                        ;;
                z)
-                       fastclose_tests
+                       tests+=(fastclose_tests)
                        ;;
                c)
+                       capture=1
                        ;;
                C)
+                       checksum=1
                        ;;
                i)
+                       ip_mptcp=1
                        ;;
                h)
                        usage
@@ -2381,4 +2362,12 @@ while getopts 'fesltra64bpkdmchzCSi' opt; do
        esac
 done
 
+if [ ${#tests[@]} -eq 0 ]; then
+       all_tests
+else
+       for subtests in "${tests[@]}"; do
+               "${subtests}"
+       done
+fi
+
 exit $ret