selftests: mptcp: join: skip check if MIB counter not supported (part 2)
authorMatthieu Baerts <matthieu.baerts@tessares.net>
Tue, 20 Jun 2023 16:30:20 +0000 (18:30 +0200)
committerJakub Kicinski <kuba@kernel.org>
Thu, 22 Jun 2023 05:45:58 +0000 (22:45 -0700)
Selftests are supposed to run on any kernels, including the old ones not
supporting all MPTCP features.

One of them is the MPTCP MIB counters introduced in commit fc518953bc9c
("mptcp: add and use MIB counter infrastructure") and more later. The
MPTCP Join selftest heavily relies on these counters.

If a counter is not supported by the kernel, it is not displayed when
using 'nstat -z'. We can then detect that and skip the verification. A
new helper (get_counter()) has been added recently in the -net tree to
do the required checks and return an error if the counter is not
available.

This commit is similar to the one with the same title applied in the
-net tree but it modifies code only present in net-next for the moment,
see the Fixes commit below.

While at it, we can also remove the use of ${extra_msg} variable which
is never assigned in chk_rm_tx_nr() function and use 'echo' without '-n'
parameter.

Link: https://github.com/multipath-tcp/mptcp_net-next/issues/368
Fixes: 0639fa230a21 ("selftests: mptcp: add explicit check for new mibs")
Signed-off-by: Matthieu Baerts <matthieu.baerts@tessares.net>
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
tools/testing/selftests/net/mptcp/mptcp_join.sh

index 1b68fe1..a7973d6 100755 (executable)
@@ -1683,12 +1683,12 @@ chk_add_tx_nr()
        timeout=$(ip netns exec $ns1 sysctl -n net.mptcp.add_addr_timeout)
 
        printf "%-${nr_blank}s %s" " " "add TX"
-       count=$(ip netns exec $ns1 nstat -as MPTcpExtAddAddrTx | grep MPTcpExtAddAddrTx | awk '{print $2}')
-       [ -z "$count" ] && count=0
-
+       count=$(get_counter ${ns1} "MPTcpExtAddAddrTx")
+       if [ -z "$count" ]; then
+               echo -n "[skip]"
        # if the test configured a short timeout tolerate greater then expected
        # add addrs options, due to retransmissions
-       if [ "$count" != "$add_tx_nr" ] && { [ "$timeout" -gt 1 ] || [ "$count" -lt "$add_tx_nr" ]; }; then
+       elif [ "$count" != "$add_tx_nr" ] && { [ "$timeout" -gt 1 ] || [ "$count" -lt "$add_tx_nr" ]; }; then
                echo "[fail] got $count ADD_ADDR[s] TX, expected $add_tx_nr"
                fail_test
        else
@@ -1696,9 +1696,10 @@ chk_add_tx_nr()
        fi
 
        echo -n " - echo TX "
-       count=$(ip netns exec $ns2 nstat -as MPTcpExtEchoAddTx | grep MPTcpExtEchoAddTx | awk '{print $2}')
-       [ -z "$count" ] && count=0
-       if [ "$count" != "$echo_tx_nr" ]; then
+       count=$(get_counter ${ns2} "MPTcpExtEchoAddTx")
+       if [ -z "$count" ]; then
+               echo "[skip]"
+       elif [ "$count" != "$echo_tx_nr" ]; then
                echo "[fail] got $count ADD_ADDR echo[s] TX, expected $echo_tx_nr"
                fail_test
        else
@@ -1734,9 +1735,10 @@ chk_rm_nr()
        fi
 
        printf "%-${nr_blank}s %s" " " "rm "
-       count=$(ip netns exec $addr_ns nstat -as MPTcpExtRmAddr | grep MPTcpExtRmAddr | awk '{print $2}')
-       [ -z "$count" ] && count=0
-       if [ "$count" != "$rm_addr_nr" ]; then
+       count=$(get_counter ${addr_ns} "MPTcpExtRmAddr")
+       if [ -z "$count" ]; then
+               echo -n "[skip]"
+       elif [ "$count" != "$rm_addr_nr" ]; then
                echo "[fail] got $count RM_ADDR[s] expected $rm_addr_nr"
                fail_test
        else
@@ -1778,16 +1780,15 @@ chk_rm_tx_nr()
        local rm_addr_tx_nr=$1
 
        printf "%-${nr_blank}s %s" " " "rm TX "
-       count=$(ip netns exec $ns2 nstat -as MPTcpExtRmAddrTx | grep MPTcpExtRmAddrTx | awk '{print $2}')
-       [ -z "$count" ] && count=0
-       if [ "$count" != "$rm_addr_tx_nr" ]; then
+       count=$(get_counter ${ns2} "MPTcpExtRmAddrTx")
+       if [ -z "$count" ]; then
+               echo "[skip]"
+       elif [ "$count" != "$rm_addr_tx_nr" ]; then
                echo "[fail] got $count RM_ADDR[s] expected $rm_addr_tx_nr"
                fail_test
        else
-               echo -n "[ ok ]"
+               echo "[ ok ]"
        fi
-
-       echo "$extra_msg"
 }
 
 chk_prio_nr()