selftests: mptcp: userspace: print error details if any
authorMatthieu Baerts <matthieu.baerts@tessares.net>
Wed, 25 Jan 2023 10:47:27 +0000 (11:47 +0100)
committerPaolo Abeni <pabeni@redhat.com>
Thu, 26 Jan 2023 12:33:30 +0000 (13:33 +0100)
Before, only '[FAIL]' was printed in case of error during the validation
phase.

Now, in case of failure, the variable name, its value and expected one
are displayed to help understand what was wrong.

Reviewed-by: Mat Martineau <mathew.j.martineau@linux.intel.com>
Signed-off-by: Matthieu Baerts <matthieu.baerts@tessares.net>
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
tools/testing/selftests/net/mptcp/userspace_pm.sh

index 2f2a85a212b085fa52b1bc3d9a13228e8049b27c..259382ad552c3019c279d4aeeaedb751eb2af9e2 100755 (executable)
@@ -201,11 +201,16 @@ make_connection()
        server_serverside=$(grep "type:1," "$server_evts" |
                            sed --unbuffered -n 's/.*\(server_side:\)\([[:digit:]]*\).*$/\2/p;q')
 
        server_serverside=$(grep "type:1," "$server_evts" |
                            sed --unbuffered -n 's/.*\(server_side:\)\([[:digit:]]*\).*$/\2/p;q')
 
+       stdbuf -o0 -e0 printf "Established IP%s MPTCP Connection ns2 => ns1    \t\t" $is_v6
        if [ "$client_token" != "" ] && [ "$server_token" != "" ] && [ "$client_serverside" = 0 ] &&
                   [ "$server_serverside" = 1 ]
        then
        if [ "$client_token" != "" ] && [ "$server_token" != "" ] && [ "$client_serverside" = 0 ] &&
                   [ "$server_serverside" = 1 ]
        then
-               stdbuf -o0 -e0 printf "Established IP%s MPTCP Connection ns2 => ns1    \t\t[OK]\n" $is_v6
+               stdbuf -o0 -e0 printf "[OK]\n"
        else
        else
+               stdbuf -o0 -e0 printf "[FAIL]\n"
+               stdbuf -o0 -e0 printf "\tExpected tokens (c:%s - s:%s) and server (c:%d - s:%d)\n" \
+                       "${client_token}" "${server_token}" \
+                       "${client_serverside}" "${server_serverside}"
                exit 1
        fi
 
                exit 1
        fi
 
@@ -225,13 +230,26 @@ make_connection()
        fi
 }
 
        fi
 }
 
-# $1: var name
+# $1: var name ; $2: prev ret
 check_expected_one()
 {
        local var="${1}"
        local exp="e_${var}"
 check_expected_one()
 {
        local var="${1}"
        local exp="e_${var}"
+       local prev_ret="${2}"
 
 
-       [ "${!var}" = "${!exp}" ]
+       if [ "${!var}" = "${!exp}" ]
+       then
+               return 0
+       fi
+
+       if [ "${prev_ret}" = "0" ]
+       then
+               stdbuf -o0 -e0 printf "[FAIL]\n"
+       fi
+
+       stdbuf -o0 -e0 printf "\tExpected value for '%s': '%s', got '%s'.\n" \
+               "${var}" "${!var}" "${!exp}"
+       return 1
 }
 
 # $@: all var names to check
 }
 
 # $@: all var names to check
@@ -242,7 +260,7 @@ check_expected()
 
        for var in "${@}"
        do
 
        for var in "${@}"
        do
-               check_expected_one "${var}" || ret=1
+               check_expected_one "${var}" "${ret}" || ret=1
        done
 
        if [ ${ret} -eq 0 ]
        done
 
        if [ ${ret} -eq 0 ]
@@ -251,7 +269,6 @@ check_expected()
                return 0
        fi
 
                return 0
        fi
 
-       stdbuf -o0 -e0 printf "[FAIL]\n"
        exit 1
 }
 
        exit 1
 }
 
@@ -303,7 +320,7 @@ test_announce()
        then
                stdbuf -o0 -e0 printf "[OK]\n"
        else
        then
                stdbuf -o0 -e0 printf "[OK]\n"
        else
-               stdbuf -o0 -e0 printf "[FAIL]\n"
+               stdbuf -o0 -e0 printf "[FAIL]\n\ttype defined: %s\n" "${type}"
                exit 1
        fi
 
                exit 1
        fi
 
@@ -837,7 +854,7 @@ test_prio()
        count=$(ip netns exec "$ns2" nstat -as | grep MPTcpExtMPPrioTx | awk '{print $2}')
        [ -z "$count" ] && count=0
        if [ $count != 1 ]; then
        count=$(ip netns exec "$ns2" nstat -as | grep MPTcpExtMPPrioTx | awk '{print $2}')
        [ -z "$count" ] && count=0
        if [ $count != 1 ]; then
-               stdbuf -o0 -e0 printf "[FAIL]\n"
+               stdbuf -o0 -e0 printf "[FAIL]\n\tCount != 1: %d\n" "${count}"
                exit 1
        else
                stdbuf -o0 -e0 printf "[OK]\n"
                exit 1
        else
                stdbuf -o0 -e0 printf "[OK]\n"
@@ -848,7 +865,7 @@ test_prio()
        count=$(ip netns exec "$ns1" nstat -as | grep MPTcpExtMPPrioRx | awk '{print $2}')
        [ -z "$count" ] && count=0
        if [ $count != 1 ]; then
        count=$(ip netns exec "$ns1" nstat -as | grep MPTcpExtMPPrioRx | awk '{print $2}')
        [ -z "$count" ] && count=0
        if [ $count != 1 ]; then
-               stdbuf -o0 -e0 printf "[FAIL]\n"
+               stdbuf -o0 -e0 printf "[FAIL]\n\tCount != 1: %d\n" "${count}"
                exit 1
        else
                stdbuf -o0 -e0 printf "[OK]\n"
                exit 1
        else
                stdbuf -o0 -e0 printf "[OK]\n"