In this series from Geliang, there are various improvements in MPTCP selftests: sharing code, doing actions the same way, colours, etc.
Patch 1 prints all error messages to stdout: what was done in almost all other MPTCP selftests. This can be now easily changed later if needed.
Patch 2 makes sure the test counter is continuous in mptcp_connect.sh.
Patch 3 aligns the messages that are printed in mptcp_connect.sh.
Patch 4 prints each test results in mptcp_sockopt.sh, similar to what we have in the TAP output.
Patch 5 moves the different test counters to a single one in mptcp_lib.sh, to uniform how it is used.
Patch 6 moves how titles are printed from mptcp_join.sh to the lib, to be reused in patch 7 by all other MPTCP selftests.
Patch 8 uses the '+=' operator to append strings instead of repeating twice the variable name: that's shorter, easier to read.
Patch 9 adds colours for the [ OK ], [SKIP], [FAIL] and INFO keywords in all MPTCP selftests.
Patch 10 to 12 are some preparation patches for patch 13: patch 10 modifies how some 'test_fail' helpers, patch 11 moves a helper from userspace_pm.sh to the lib, and patch 12 changes where titles are printed in userspace_pm.sh. Patch 13 moves some duplicated helpers from mptcp_join.sh and userspace_pm.sh to mptcp_lib.sh.
Patch 14 moves duplicated read-only variables from mptcp_join.sh and userspace_pm.sh to mptcp_lib.sh as well.
Patch 15 uses explicit variables instead of hard-coded numbers for the exit status.
Signed-off-by: Matthieu Baerts (NGI0) matttbe@kernel.org --- Geliang Tang (15): selftests: mptcp: print all error messages to stdout selftests: mptcp: connect: add dedicated port counter selftests: mptcp: connect: fix misaligned output selftests: mptcp: sockopt: print every test result selftests: mptcp: export TEST_COUNTER variable selftests: mptcp: add print_title in mptcp_lib selftests: mptcp: print test results with counters selftests: mptcp: use += operator to append strings selftests: mptcp: print test results with colors selftests: mptcp: call test_fail without argument selftests: mptcp: extract mptcp_lib_check_expected selftests: mptcp: print_test out of verify_listener_events selftests: mptcp: add mptcp_lib_verify_listener_events selftests: mptcp: declare event macros in mptcp_lib selftests: mptcp: use KSFT_SKIP/KSFT_PASS/KSFT_FAIL
tools/testing/selftests/net/mptcp/diag.sh | 19 ++- tools/testing/selftests/net/mptcp/mptcp_connect.sh | 145 +++++++++++---------- tools/testing/selftests/net/mptcp/mptcp_join.sh | 120 +++++++---------- tools/testing/selftests/net/mptcp/mptcp_lib.sh | 113 ++++++++++++++-- tools/testing/selftests/net/mptcp/mptcp_sockopt.sh | 53 ++++---- tools/testing/selftests/net/mptcp/pm_netlink.sh | 13 +- tools/testing/selftests/net/mptcp/simult_flows.sh | 18 +-- tools/testing/selftests/net/mptcp/userspace_pm.sh | 117 +++++------------ 8 files changed, 312 insertions(+), 286 deletions(-) --- base-commit: 19cfdc0d57696c92523da8eb26c0f3e092400bee change-id: 20240308-upstream-net-next-20240308-selftests-mptcp-unification-6df178cc8f6a
Best regards,
From: Geliang Tang tanggeliang@kylinos.cn
Some error messages are printed to stderr while the others are printed to 'stdout'. As part of the unification, this patch drop "1>&2" to let all errors messages are printed to 'stdout'.
Signed-off-by: Geliang Tang tanggeliang@kylinos.cn Reviewed-by: Matthieu Baerts (NGI0) matttbe@kernel.org Signed-off-by: Matthieu Baerts (NGI0) matttbe@kernel.org --- tools/testing/selftests/net/mptcp/mptcp_connect.sh | 10 +++++----- tools/testing/selftests/net/mptcp/mptcp_sockopt.sh | 11 ++++++----- 2 files changed, 11 insertions(+), 10 deletions(-)
diff --git a/tools/testing/selftests/net/mptcp/mptcp_connect.sh b/tools/testing/selftests/net/mptcp/mptcp_connect.sh index 0ca2960c9099..679e366c8f6b 100755 --- a/tools/testing/selftests/net/mptcp/mptcp_connect.sh +++ b/tools/testing/selftests/net/mptcp/mptcp_connect.sh @@ -294,7 +294,7 @@ do_ping() ip netns exec ${connector_ns} ping ${ping_args} $connect_addr >/dev/null || rc=1
if [ $rc -ne 0 ] ; then - echo "$listener_ns -> $connect_addr connectivity [ FAIL ]" 1>&2 + echo "$listener_ns -> $connect_addr connectivity [ FAIL ]" ret=1
return 1 @@ -470,13 +470,13 @@ do_transfer()
if [ ${stat_synrx_now_l} -lt ${expect_synrx} ]; then printf "[ FAIL ] lower MPC SYN rx (%d) than expected (%d)\n" \ - "${stat_synrx_now_l}" "${expect_synrx}" 1>&2 + "${stat_synrx_now_l}" "${expect_synrx}" retc=1 fi if [ ${stat_ackrx_now_l} -lt ${expect_ackrx} ] && [ ${stat_ooo_now} -eq 0 ]; then if [ ${stat_ooo_now} -eq 0 ]; then printf "[ FAIL ] lower MPC ACK rx (%d) than expected (%d)\n" \ - "${stat_ackrx_now_l}" "${expect_ackrx}" 1>&2 + "${stat_ackrx_now_l}" "${expect_ackrx}" rets=1 else printf "[ Note ] fallback due to TCP OoO" @@ -721,7 +721,7 @@ EOF ip -net "$listener_ns" route del local $local_addr/0 dev lo table 100
if [ $lret -ne 0 ]; then - echo "FAIL: $msg, mptcp connection error" 1>&2 + echo "FAIL: $msg, mptcp connection error" ret=$lret return 1 fi @@ -810,7 +810,7 @@ log_if_error() local msg="$1"
if [ ${ret} -ne 0 ]; then - echo "FAIL: ${msg}" 1>&2 + echo "FAIL: ${msg}"
final_ret=${ret} ret=0 diff --git a/tools/testing/selftests/net/mptcp/mptcp_sockopt.sh b/tools/testing/selftests/net/mptcp/mptcp_sockopt.sh index 6ed4aa32222f..7c70b52e63c6 100755 --- a/tools/testing/selftests/net/mptcp/mptcp_sockopt.sh +++ b/tools/testing/selftests/net/mptcp/mptcp_sockopt.sh @@ -103,7 +103,8 @@ check_mark() local v for v in $values; do if [ $v -ne 0 ]; then - echo "FAIL: got $tables $values in ns $ns , not 0 - not all expected packets marked" 1>&2 + echo "FAIL: got $tables $values in ns $ns," \ + "not 0 - not all expected packets marked" ret=1 return 1 fi @@ -162,7 +163,7 @@ do_transfer() local rets=$?
if [ ${rets} -ne 0 ] || [ ${retc} -ne 0 ]; then - echo " client exit code $retc, server $rets" 1>&2 + echo " client exit code $retc, server $rets" echo -e "\nnetns ${listener_ns} socket stat for ${port}:" 1>&2 ip netns exec ${listener_ns} ss -Menita 1>&2 -o "sport = :$port"
@@ -221,7 +222,7 @@ do_mptcp_sockopt_tests() lret=$?
if [ $lret -ne 0 ]; then - echo "FAIL: SOL_MPTCP getsockopt" 1>&2 + echo "FAIL: SOL_MPTCP getsockopt" mptcp_lib_result_fail "sockopt v4" ret=$lret return @@ -232,7 +233,7 @@ do_mptcp_sockopt_tests() lret=$?
if [ $lret -ne 0 ]; then - echo "FAIL: SOL_MPTCP getsockopt (ipv6)" 1>&2 + echo "FAIL: SOL_MPTCP getsockopt (ipv6)" mptcp_lib_result_fail "sockopt v6" ret=$lret return @@ -263,7 +264,7 @@ do_tcpinq_test() local lret=$? if [ $lret -ne 0 ];then ret=$lret - echo "FAIL: mptcp_inq $*" 1>&2 + echo "FAIL: mptcp_inq $*" mptcp_lib_result_fail "TCP_INQ: $*" return $lret fi
From: Geliang Tang tanggeliang@kylinos.cn
This patch adds a new dedicated counter 'port' instead of TEST_COUNT to increase port numbers in mptcp_connect.sh.
This can avoid outputting discontinuous test counters.
Signed-off-by: Geliang Tang tanggeliang@kylinos.cn Reviewed-by: Matthieu Baerts (NGI0) matttbe@kernel.org Signed-off-by: Matthieu Baerts (NGI0) matttbe@kernel.org --- tools/testing/selftests/net/mptcp/mptcp_connect.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/tools/testing/selftests/net/mptcp/mptcp_connect.sh b/tools/testing/selftests/net/mptcp/mptcp_connect.sh index 679e366c8f6b..ab3f52434753 100755 --- a/tools/testing/selftests/net/mptcp/mptcp_connect.sh +++ b/tools/testing/selftests/net/mptcp/mptcp_connect.sh @@ -33,6 +33,7 @@ do_tcp=0 checksum=false filesize=0 connect_per_transfer=1 +port=$((10000 - 1))
if [ $tc_loss -eq 100 ];then tc_loss=1% @@ -313,8 +314,7 @@ do_transfer() local local_addr="$6" local extra_args="$7"
- local port - port=$((10000+TEST_COUNT)) + port=$((port + 1)) TEST_COUNT=$((TEST_COUNT+1))
if [ "$rcvbuf" -gt 0 ]; then @@ -710,7 +710,7 @@ EOF
echo "INFO: test $msg"
- TEST_COUNT=10000 + port=$((20000 - 1)) local extra_args="-o TRANSPARENT" do_transfer ${listener_ns} ${connector_ns} MPTCP MPTCP \ ${connect_addr} ${local_addr} "${extra_args}"
From: Geliang Tang tanggeliang@kylinos.cn
The first [ OK ] in the output of mptcp_connect.sh misaligns with the others:
New MPTCP socket can be blocked via sysctl [ OK ] INFO: validating network environment with pings INFO: Using loss of 0.85% delay 16 ms reorder 95% 70% with delay 4ms on ns1 MPTCP -> ns1 (10.0.1.1:10000 ) MPTCP (duration 184ms) [ OK ] ns1 MPTCP -> ns1 (10.0.1.1:10001 ) TCP (duration 50ms) [ OK ] ns1 TCP -> ns1 (10.0.1.1:10002 ) MPTCP (duration 55ms) [ OK ]
This patch aligns them by using 69 chars to display the first two lines, and 50 chars for the other. Since 19 chars are used to display duration time. Also print out a [ OK ] at the end of the 2nd line for consistency.
Signed-off-by: Geliang Tang tanggeliang@kylinos.cn Reviewed-by: Matthieu Baerts (NGI0) matttbe@kernel.org Signed-off-by: Matthieu Baerts (NGI0) matttbe@kernel.org --- tools/testing/selftests/net/mptcp/mptcp_connect.sh | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-)
diff --git a/tools/testing/selftests/net/mptcp/mptcp_connect.sh b/tools/testing/selftests/net/mptcp/mptcp_connect.sh index ab3f52434753..ce9342b241cd 100755 --- a/tools/testing/selftests/net/mptcp/mptcp_connect.sh +++ b/tools/testing/selftests/net/mptcp/mptcp_connect.sh @@ -248,11 +248,17 @@ else set_ethtool_flags "$ns4" ns4eth3 "$ethtool_args" fi
+print_larger_title() { + # here we don't have the time, a bit longer for the alignment + printf "%-69s" "${@}" +} + check_mptcp_disabled() { local disabled_ns mptcp_lib_ns_init disabled_ns
+ print_larger_title "New MPTCP socket can be blocked via sysctl" # net.mptcp.enabled should be enabled by default if [ "$(ip netns exec ${disabled_ns} sysctl net.mptcp.enabled | awk '{ print $3 }')" -ne 1 ]; then echo -e "net.mptcp.enabled sysctl is not 1 by default\t\t[ FAIL ]" @@ -274,7 +280,7 @@ check_mptcp_disabled() return 1 fi
- echo -e "New MPTCP socket can be blocked via sysctl\t\t[ OK ]" + echo "[ OK ]" mptcp_lib_result_pass "New MPTCP socket can be blocked via sysctl" return 0 } @@ -342,7 +348,7 @@ do_transfer() addr_port=$(printf "%s:%d" ${connect_addr} ${port}) local result_msg result_msg="$(printf "%.3s %-5s -> %.3s (%-20s) %-5s" ${connector_ns} ${cl_proto} ${listener_ns} ${addr_port} ${srv_proto})" - printf "%s\t" "${result_msg}" + printf "%-50s" "${result_msg}"
if $capture; then local capuser @@ -835,7 +841,7 @@ check_mptcp_disabled
stop_if_error "The kernel configuration is not valid for MPTCP"
-echo "INFO: validating network environment with pings" +print_larger_title "Validating network environment with pings" for sender in "$ns1" "$ns2" "$ns3" "$ns4";do do_ping "$ns1" $sender 10.0.1.1 do_ping "$ns1" $sender dead:beef:1::1 @@ -857,6 +863,7 @@ done mptcp_lib_result_code "${ret}" "ping tests"
stop_if_error "Could not even run ping tests" +echo "[ OK ]"
[ -n "$tc_loss" ] && tc -net "$ns2" qdisc add dev ns2eth3 root netem loss random $tc_loss delay ${tc_delay}ms echo -n "INFO: Using loss of $tc_loss "
From: Geliang Tang tanggeliang@kylinos.cn
Only total test results are printed out in mptcp_sockopt.sh:
PASS: all packets had packet mark set PASS: SOL_MPTCP getsockopt has expected information PASS: TCP_INQ cmsg/ioctl -t tcp PASS: TCP_INQ cmsg/ioctl -6 -t tcp PASS: TCP_INQ cmsg/ioctl -r tcp PASS: TCP_INQ cmsg/ioctl -6 -r tcp PASS: TCP_INQ cmsg/ioctl -r tcp -t tcp
They mismatch with the test results:
ok 1 - mptcp_sockopt: mark ipv4 ok 2 - mptcp_sockopt: transfer ipv4 ok 3 - mptcp_sockopt: mark ipv6 ok 4 - mptcp_sockopt: transfer ipv6 ok 5 - mptcp_sockopt: sockopt v4 ok 6 - mptcp_sockopt: sockopt v6 ok 7 - mptcp_sockopt: TCP_INQ: -t tcp ok 8 - mptcp_sockopt: TCP_INQ: -6 -t tcp ok 9 - mptcp_sockopt: TCP_INQ: -r tcp ok 10 - mptcp_sockopt: TCP_INQ: -6 -r tcp ok 11 - mptcp_sockopt: TCP_INQ: -r tcp -t tcp
'mptcp_sockopt.sh' now display more detailed results + why (what you had in a former patch from v6, merged here). It no longer displays 'PASS:', because it is duplicated info now that the detailed are displayed:
Transfer v4 [ OK ] Mark v4 [ OK ] Transfer v6 [ OK ] Mark v6 [ OK ] SOL_MPTCP sockopt v4 [ OK ] SOL_MPTCP sockopt v6 [ OK ] TCP_INQ cmsg/ioctl -t tcp [ OK ] TCP_INQ cmsg/ioctl -6 -t tcp [ OK ] TCP_INQ cmsg/ioctl -r tcp [ OK ] TCP_INQ cmsg/ioctl -6 -r tcp [ OK ] TCP_INQ cmsg/ioctl -r tcp -t tcp [ OK ]
Also fix the TAP output:
ok 1 - mptcp_sockopt: transfer ipv4 ok 2 - mptcp_sockopt: mark ipv4 ok 3 - mptcp_sockopt: transfer ipv6 ok 4 - mptcp_sockopt: mark ipv6 ok 5 - mptcp_sockopt: sockopt v4 ok 6 - mptcp_sockopt: sockopt v6 ok 7 - mptcp_sockopt: TCP_INQ: -t tcp ok 8 - mptcp_sockopt: TCP_INQ: -6 -t tcp ok 9 - mptcp_sockopt: TCP_INQ: -r tcp ok 10 - mptcp_sockopt: TCP_INQ: -6 -r tcp ok 11 - mptcp_sockopt: TCP_INQ: -r tcp -t tcp
Signed-off-by: Geliang Tang tanggeliang@kylinos.cn Reviewed-by: Matthieu Baerts (NGI0) matttbe@kernel.org Signed-off-by: Matthieu Baerts (NGI0) matttbe@kernel.org --- tools/testing/selftests/net/mptcp/mptcp_sockopt.sh | 42 +++++++++++++--------- 1 file changed, 25 insertions(+), 17 deletions(-)
diff --git a/tools/testing/selftests/net/mptcp/mptcp_sockopt.sh b/tools/testing/selftests/net/mptcp/mptcp_sockopt.sh index 7c70b52e63c6..17b36c1312f4 100755 --- a/tools/testing/selftests/net/mptcp/mptcp_sockopt.sh +++ b/tools/testing/selftests/net/mptcp/mptcp_sockopt.sh @@ -113,6 +113,11 @@ check_mark() return 0 }
+print_title() +{ + printf "%-50s" "${@}" +} + do_transfer() { local listener_ns="$1" @@ -162,8 +167,9 @@ do_transfer() wait $spid local rets=$?
+ print_title "Transfer ${ip:2}" if [ ${rets} -ne 0 ] || [ ${retc} -ne 0 ]; then - echo " client exit code $retc, server $rets" + echo "[FAIL] client exit code $retc, server $rets" echo -e "\nnetns ${listener_ns} socket stat for ${port}:" 1>&2 ip netns exec ${listener_ns} ss -Menita 1>&2 -o "sport = :$port"
@@ -175,7 +181,14 @@ do_transfer() ret=1 return 1 fi + if ! mptcp_lib_check_transfer $cin $sout "file received by server"; then + rets=1 + else + echo "[ OK ]" + fi + mptcp_lib_result_code "${rets}" "transfer ${ip}"
+ print_title "Mark ${ip:2}" if [ $local_addr = "::" ];then check_mark $listener_ns 6 || retc=1 check_mark $connector_ns 6 || retc=1 @@ -184,15 +197,13 @@ do_transfer() check_mark $connector_ns 4 || retc=1 fi
- mptcp_lib_check_transfer $cin $sout "file received by server" - rets=$? - mptcp_lib_result_code "${retc}" "mark ${ip}" - mptcp_lib_result_code "${rets}" "transfer ${ip}"
if [ $retc -eq 0 ] && [ $rets -eq 0 ];then + echo "[ OK ]" return 0 fi + echo "[FAIL]"
return 1 } @@ -221,23 +232,27 @@ do_mptcp_sockopt_tests() ip netns exec "$ns_sbox" ./mptcp_sockopt lret=$?
+ print_title "SOL_MPTCP sockopt v4" if [ $lret -ne 0 ]; then - echo "FAIL: SOL_MPTCP getsockopt" + echo "[FAIL]" mptcp_lib_result_fail "sockopt v4" ret=$lret return fi + echo "[ OK ]" mptcp_lib_result_pass "sockopt v4"
ip netns exec "$ns_sbox" ./mptcp_sockopt -6 lret=$?
+ print_title "SOL_MPTCP sockopt v6" if [ $lret -ne 0 ]; then - echo "FAIL: SOL_MPTCP getsockopt (ipv6)" + echo "[FAIL]" mptcp_lib_result_fail "sockopt v6" ret=$lret return fi + echo "[ OK ]" mptcp_lib_result_pass "sockopt v6" }
@@ -260,16 +275,17 @@ run_tests()
do_tcpinq_test() { + print_title "TCP_INQ cmsg/ioctl $*" ip netns exec "$ns_sbox" ./mptcp_inq "$@" local lret=$? if [ $lret -ne 0 ];then ret=$lret - echo "FAIL: mptcp_inq $*" + echo "[FAIL]" mptcp_lib_result_fail "TCP_INQ: $*" return $lret fi
- echo "PASS: TCP_INQ cmsg/ioctl $*" + echo "[ OK ]" mptcp_lib_result_pass "TCP_INQ: $*" return $lret } @@ -315,15 +331,7 @@ trap cleanup EXIT run_tests $ns1 $ns2 10.0.1.1 run_tests $ns1 $ns2 dead:beef:1::1
-if [ $ret -eq 0 ];then - echo "PASS: all packets had packet mark set" -fi - do_mptcp_sockopt_tests -if [ $ret -eq 0 ];then - echo "PASS: SOL_MPTCP getsockopt has expected information" -fi - do_tcpinq_tests
mptcp_lib_result_print_all_tap
From: Geliang Tang tanggeliang@kylinos.cn
Variable TEST_COUNT are used in mptcp_connect.sh and mptcp_join.sh as test counters, which are initialized to 0, while variable test_cnt are used in diag.sh and simult_flows.sh, which are initialized to 1. To maintain consistency, this patch renames them all as MPTCP_LIB_TEST_COUNTER, initializes it to 1, and exports it into mptcp_lib.sh.
Signed-off-by: Geliang Tang tanggeliang@kylinos.cn Reviewed-by: Matthieu Baerts (NGI0) matttbe@kernel.org Signed-off-by: Matthieu Baerts (NGI0) matttbe@kernel.org --- tools/testing/selftests/net/mptcp/diag.sh | 5 ++--- tools/testing/selftests/net/mptcp/mptcp_connect.sh | 3 +-- tools/testing/selftests/net/mptcp/mptcp_join.sh | 15 +++++++-------- tools/testing/selftests/net/mptcp/mptcp_lib.sh | 2 ++ tools/testing/selftests/net/mptcp/simult_flows.sh | 5 ++--- 5 files changed, 14 insertions(+), 16 deletions(-)
diff --git a/tools/testing/selftests/net/mptcp/diag.sh b/tools/testing/selftests/net/mptcp/diag.sh index afe862895946..b63510ce2327 100755 --- a/tools/testing/selftests/net/mptcp/diag.sh +++ b/tools/testing/selftests/net/mptcp/diag.sh @@ -9,7 +9,6 @@ . "$(dirname "${0}")/mptcp_lib.sh"
ns="" -test_cnt=1 timeout_poll=30 timeout_test=$((timeout_poll * 2 + 1)) ret=0 @@ -69,7 +68,7 @@ __chk_nr() echo "[ ok ]" mptcp_lib_result_pass "${msg}" fi - test_cnt=$((test_cnt+1)) + MPTCP_LIB_TEST_COUNTER=$((MPTCP_LIB_TEST_COUNTER+1)) }
__chk_msk_nr() @@ -127,7 +126,7 @@ wait_msk_nr() echo "[ ok ]" mptcp_lib_result_pass "${msg}" fi - test_cnt=$((test_cnt+1)) + MPTCP_LIB_TEST_COUNTER=$((MPTCP_LIB_TEST_COUNTER+1)) }
chk_msk_fallback_nr() diff --git a/tools/testing/selftests/net/mptcp/mptcp_connect.sh b/tools/testing/selftests/net/mptcp/mptcp_connect.sh index ce9342b241cd..915faee77e25 100755 --- a/tools/testing/selftests/net/mptcp/mptcp_connect.sh +++ b/tools/testing/selftests/net/mptcp/mptcp_connect.sh @@ -131,7 +131,6 @@ ns2="" ns3="" ns4=""
-TEST_COUNT=0 TEST_GROUP=""
# This function is used in the cleanup trap @@ -321,7 +320,7 @@ do_transfer() local extra_args="$7"
port=$((port + 1)) - TEST_COUNT=$((TEST_COUNT+1)) + MPTCP_LIB_TEST_COUNTER=$((MPTCP_LIB_TEST_COUNTER+1))
if [ "$rcvbuf" -gt 0 ]; then extra_args="$extra_args -R $rcvbuf" diff --git a/tools/testing/selftests/net/mptcp/mptcp_join.sh b/tools/testing/selftests/net/mptcp/mptcp_join.sh index 1df2d24979a0..4ef0d5ae9dae 100755 --- a/tools/testing/selftests/net/mptcp/mptcp_join.sh +++ b/tools/testing/selftests/net/mptcp/mptcp_join.sh @@ -48,7 +48,6 @@ declare -A all_tests declare -a only_tests_ids declare -a only_tests_names declare -A failed_tests -TEST_COUNT=0 TEST_NAME="" nr_blank=6
@@ -172,7 +171,7 @@ cleanup()
print_title() { - printf "%03u %s\n" "${TEST_COUNT}" "${TEST_NAME}" + printf "%03u %s\n" "${MPTCP_LIB_TEST_COUNTER}" "${TEST_NAME}" }
print_check() @@ -233,7 +232,7 @@ skip_test()
local i for i in "${only_tests_ids[@]}"; do - if [ "${TEST_COUNT}" -eq "${i}" ]; then + if [ "${MPTCP_LIB_TEST_COUNTER}" -eq "${i}" ]; then return 1 fi done @@ -268,7 +267,7 @@ reset()
TEST_NAME="${1}"
- TEST_COUNT=$((TEST_COUNT+1)) + MPTCP_LIB_TEST_COUNTER=$((MPTCP_LIB_TEST_COUNTER+1))
if skip_test; then last_test_ignored=1 @@ -462,7 +461,7 @@ fail_test()
# just in case a test is marked twice as failed if [ ${last_test_failed} -eq 0 ]; then - failed_tests[${TEST_COUNT}]="${TEST_NAME}" + failed_tests[${MPTCP_LIB_TEST_COUNTER}]="${TEST_NAME}" dump_stats last_test_failed=1 fi @@ -973,7 +972,7 @@ do_transfer() local srv_proto="$4" local connect_addr="$5"
- local port=$((10000 + TEST_COUNT - 1)) + local port=$((10000 + MPTCP_LIB_TEST_COUNTER - 1)) local cappid local FAILING_LINKS=${FAILING_LINKS:-""} local fastclose=${fastclose:-""} @@ -991,9 +990,9 @@ do_transfer() capuser="-Z $SUDO_USER" fi
- capfile=$(printf "mp_join-%02u-%s.pcap" "$TEST_COUNT" "${listener_ns}") + capfile=$(printf "mp_join-%02u-%s.pcap" "$MPTCP_LIB_TEST_COUNTER" "${listener_ns}")
- echo "Capturing traffic for test $TEST_COUNT into $capfile" + echo "Capturing traffic for test $MPTCP_LIB_TEST_COUNTER into $capfile" ip netns exec ${listener_ns} tcpdump -i any -s 65535 -B 32768 $capuser -w $capfile > "$capout" 2>&1 & cappid=$!
diff --git a/tools/testing/selftests/net/mptcp/mptcp_lib.sh b/tools/testing/selftests/net/mptcp/mptcp_lib.sh index 5d071b6eb780..63abf4431993 100644 --- a/tools/testing/selftests/net/mptcp/mptcp_lib.sh +++ b/tools/testing/selftests/net/mptcp/mptcp_lib.sh @@ -10,6 +10,8 @@ readonly KSFT_TEST="${MPTCP_LIB_KSFT_TEST:-$(basename "${0}" .sh)}"
MPTCP_LIB_SUBTESTS=() MPTCP_LIB_SUBTESTS_DUPLICATED=0 +# shellcheck disable=SC2034 # unused at this moment +MPTCP_LIB_TEST_COUNTER=0
# only if supported (or forced) and not disabled, see no-color.org if { [ -t 1 ] || [ "${SELFTESTS_MPTCP_LIB_COLOR_FORCE:-}" = "1" ]; } && diff --git a/tools/testing/selftests/net/mptcp/simult_flows.sh b/tools/testing/selftests/net/mptcp/simult_flows.sh index 365fb3d6ef55..3ad663e38c42 100755 --- a/tools/testing/selftests/net/mptcp/simult_flows.sh +++ b/tools/testing/selftests/net/mptcp/simult_flows.sh @@ -14,7 +14,6 @@ ns3="" capture=false timeout_poll=30 timeout_test=$((timeout_poll * 2 + 1)) -test_cnt=1 ret=0 bail=0 slack=50 @@ -126,8 +125,8 @@ do_transfer() local sin=$2 local max_time=$3 local port - port=$((10000+test_cnt)) - test_cnt=$((test_cnt+1)) + port=$((10000+MPTCP_LIB_TEST_COUNTER)) + MPTCP_LIB_TEST_COUNTER=$((MPTCP_LIB_TEST_COUNTER+1))
:> "$cout" :> "$sout"
From: Geliang Tang tanggeliang@kylinos.cn
This patch adds a new variable MPTCP_LIB_TEST_FORMAT as the test title printing format. Also add a helper mptcp_lib_print_title() to use this format to print the test title with test counters. They are used in mptcp_join.sh first.
Each MPTCP selftest is having subtests, and it helps to give them a number to quickly identify them. This can be managed by mptcp_lib.sh, reusing what has been done here. The following commit will use these new helpers in the other tests.
Signed-off-by: Geliang Tang tanggeliang@kylinos.cn Reviewed-by: Matthieu Baerts (NGI0) matttbe@kernel.org Signed-off-by: Matthieu Baerts (NGI0) matttbe@kernel.org --- tools/testing/selftests/net/mptcp/mptcp_join.sh | 13 ++++--------- tools/testing/selftests/net/mptcp/mptcp_lib.sh | 10 +++++++++- 2 files changed, 13 insertions(+), 10 deletions(-)
diff --git a/tools/testing/selftests/net/mptcp/mptcp_join.sh b/tools/testing/selftests/net/mptcp/mptcp_join.sh index 4ef0d5ae9dae..2f34e2b9a1c4 100755 --- a/tools/testing/selftests/net/mptcp/mptcp_join.sh +++ b/tools/testing/selftests/net/mptcp/mptcp_join.sh @@ -48,6 +48,7 @@ declare -A all_tests declare -a only_tests_ids declare -a only_tests_names declare -A failed_tests +MPTCP_LIB_TEST_FORMAT="%03u %s\n" TEST_NAME="" nr_blank=6
@@ -169,11 +170,6 @@ cleanup() cleanup_partial }
-print_title() -{ - printf "%03u %s\n" "${MPTCP_LIB_TEST_COUNTER}" "${TEST_NAME}" -} - print_check() { printf "%-${nr_blank}s%-36s" " " "${*}" @@ -232,7 +228,7 @@ skip_test()
local i for i in "${only_tests_ids[@]}"; do - if [ "${MPTCP_LIB_TEST_COUNTER}" -eq "${i}" ]; then + if [ "$((MPTCP_LIB_TEST_COUNTER+1))" -eq "${i}" ]; then return 1 fi done @@ -267,14 +263,13 @@ reset()
TEST_NAME="${1}"
- MPTCP_LIB_TEST_COUNTER=$((MPTCP_LIB_TEST_COUNTER+1)) - if skip_test; then + MPTCP_LIB_TEST_COUNTER=$((MPTCP_LIB_TEST_COUNTER+1)) last_test_ignored=1 return 1 fi
- print_title + mptcp_lib_print_title "${TEST_NAME}"
if [ "${init}" != "1" ]; then init diff --git a/tools/testing/selftests/net/mptcp/mptcp_lib.sh b/tools/testing/selftests/net/mptcp/mptcp_lib.sh index 63abf4431993..eb740a2f7898 100644 --- a/tools/testing/selftests/net/mptcp/mptcp_lib.sh +++ b/tools/testing/selftests/net/mptcp/mptcp_lib.sh @@ -10,8 +10,8 @@ readonly KSFT_TEST="${MPTCP_LIB_KSFT_TEST:-$(basename "${0}" .sh)}"
MPTCP_LIB_SUBTESTS=() MPTCP_LIB_SUBTESTS_DUPLICATED=0 -# shellcheck disable=SC2034 # unused at this moment MPTCP_LIB_TEST_COUNTER=0 +MPTCP_LIB_TEST_FORMAT="%02u %-50s"
# only if supported (or forced) and not disabled, see no-color.org if { [ -t 1 ] || [ "${SELFTESTS_MPTCP_LIB_COLOR_FORCE:-}" = "1" ]; } && @@ -412,3 +412,11 @@ mptcp_lib_events() { ip netns exec "${ns}" ./pm_nl_ctl events >> "${evts}" 2>&1 & pid=$! } + +mptcp_lib_print_title() { + : "${MPTCP_LIB_TEST_COUNTER:?}" + : "${MPTCP_LIB_TEST_FORMAT:?}" + + # shellcheck disable=SC2059 # the format is in a variable + printf "${MPTCP_LIB_TEST_FORMAT}" "$((++MPTCP_LIB_TEST_COUNTER))" "${*}" +}
From: Geliang Tang tanggeliang@kylinos.cn
This patch adds a new helper mptcp_lib_print_title(), a wrapper of mptcp_lib_inc_test_counter() and mptcp_lib_pr_title_counter(), to print out test counter in each test result and increase the counter. Use this helper to print out test counters for every tests in diag.sh, mptcp_connect.sh, mptcp_sockopt.sh, pm_netlink.sh, simult_flows.sh, and userspace_pm.sh.
diag.sh:
01 no msk on netns creation [ ok ] 02 listen match for dport 10000 [ ok ] 03 listen match for sport 10000 [ ok ] 04 listen match for saddr and sport [ ok ] 05 all listen sockets [ ok ]
mptcp_connect.sh:
01 New MPTCP socket can be blocked via sysctl [ OK ] 02 Validating network environment with pings [ OK ] INFO: Using loss of 0.85% delay 31 ms reorder .. with delay 7ms on ns3eth4 03 ns1 MPTCP -> ns1 (10.0.1.1:10000 ) MPTCP (duration 69ms) [ OK ] 04 ns1 MPTCP -> ns1 (10.0.1.1:10001 ) TCP (duration 20ms) [ OK ] 05 ns1 TCP -> ns1 (10.0.1.1:10002 ) MPTCP (duration 16ms) [ OK ]
mptcp_sockopt.sh:
01 Transfer v4 [ OK ] 02 Mark v4 [ OK ] 03 Transfer v6 [ OK ] 04 Mark v6 [ OK ] 05 SOL_MPTCP sockopt v4 [ OK ]
pm_netlink.sh:
01 defaults addr list [ OK ] 02 simple add/get addr [ OK ] 03 dump addrs [ OK ] 04 simple del addr [ OK ] 05 dump addrs after del [ OK ]
simult_flows.sh:
01 balanced bwidth 7391 max 8456 [ OK ] 02 balanced bwidth - reverse direction 7403 max 8456 [ OK ] 03 balanced bwidth with unbalanced delay 7429 max 8456 [ OK ] 04 balanced bwidth with unbalanced delay - reverse ... 7485 max 8456 [ OK ] 05 unbalanced bwidth 7549 max 8456 [ OK ]
userspace_pm.sh:
01 Created network namespaces ns1, ns2 [ OK ] INFO: Make connections 02 Established IPv4 MPTCP Connection ns2 => ns1 [ OK ] 03 Established IPv6 MPTCP Connection ns2 => ns1 [ OK ] INFO: Announce tests 04 ADD_ADDR 10.0.2.2 (ns2) => ns1, invalid token [ OK ] 05 ADD_ADDR id:67 10.0.2.2 (ns2) => ns1, reuse port [ OK ]
Having test counters helps to quickly identify issues when looking at a long list of output logs and results.
Signed-off-by: Geliang Tang tanggeliang@kylinos.cn Reviewed-by: Matthieu Baerts (NGI0) matttbe@kernel.org Signed-off-by: Matthieu Baerts (NGI0) matttbe@kernel.org --- tools/testing/selftests/net/mptcp/diag.sh | 6 ++---- tools/testing/selftests/net/mptcp/mptcp_connect.sh | 6 +++--- tools/testing/selftests/net/mptcp/mptcp_sockopt.sh | 2 +- tools/testing/selftests/net/mptcp/pm_netlink.sh | 5 +++-- tools/testing/selftests/net/mptcp/simult_flows.sh | 7 ++++--- tools/testing/selftests/net/mptcp/userspace_pm.sh | 4 +++- 6 files changed, 16 insertions(+), 14 deletions(-)
diff --git a/tools/testing/selftests/net/mptcp/diag.sh b/tools/testing/selftests/net/mptcp/diag.sh index b63510ce2327..4ffdd415e670 100755 --- a/tools/testing/selftests/net/mptcp/diag.sh +++ b/tools/testing/selftests/net/mptcp/diag.sh @@ -54,7 +54,7 @@ __chk_nr()
nr=$(eval $command)
- printf "%-50s" "$msg" + mptcp_lib_print_title "$msg" if [ "$nr" != "$expected" ]; then if [ "$nr" = "$skip" ] && ! mptcp_lib_expect_all_features; then echo "[ skip ] Feature probably not supported" @@ -68,7 +68,6 @@ __chk_nr() echo "[ ok ]" mptcp_lib_result_pass "${msg}" fi - MPTCP_LIB_TEST_COUNTER=$((MPTCP_LIB_TEST_COUNTER+1)) }
__chk_msk_nr() @@ -113,7 +112,7 @@ wait_msk_nr() sleep 1 done
- printf "%-50s" "$msg" + mptcp_lib_print_title "$msg" if [ $i -ge $timeout ]; then echo "[ fail ] timeout while expecting $expected max $max last $nr" mptcp_lib_result_fail "${msg} # timeout" @@ -126,7 +125,6 @@ wait_msk_nr() echo "[ ok ]" mptcp_lib_result_pass "${msg}" fi - MPTCP_LIB_TEST_COUNTER=$((MPTCP_LIB_TEST_COUNTER+1)) }
chk_msk_fallback_nr() diff --git a/tools/testing/selftests/net/mptcp/mptcp_connect.sh b/tools/testing/selftests/net/mptcp/mptcp_connect.sh index 915faee77e25..bbda37d6514f 100755 --- a/tools/testing/selftests/net/mptcp/mptcp_connect.sh +++ b/tools/testing/selftests/net/mptcp/mptcp_connect.sh @@ -249,7 +249,8 @@ fi
print_larger_title() { # here we don't have the time, a bit longer for the alignment - printf "%-69s" "${@}" + MPTCP_LIB_TEST_FORMAT="%02u %-69s" \ + mptcp_lib_print_title "${@}" }
check_mptcp_disabled() @@ -320,7 +321,6 @@ do_transfer() local extra_args="$7"
port=$((port + 1)) - MPTCP_LIB_TEST_COUNTER=$((MPTCP_LIB_TEST_COUNTER+1))
if [ "$rcvbuf" -gt 0 ]; then extra_args="$extra_args -R $rcvbuf" @@ -347,7 +347,7 @@ do_transfer() addr_port=$(printf "%s:%d" ${connect_addr} ${port}) local result_msg result_msg="$(printf "%.3s %-5s -> %.3s (%-20s) %-5s" ${connector_ns} ${cl_proto} ${listener_ns} ${addr_port} ${srv_proto})" - printf "%-50s" "${result_msg}" + mptcp_lib_print_title "${result_msg}"
if $capture; then local capuser diff --git a/tools/testing/selftests/net/mptcp/mptcp_sockopt.sh b/tools/testing/selftests/net/mptcp/mptcp_sockopt.sh index 17b36c1312f4..19d0ac31b6a9 100755 --- a/tools/testing/selftests/net/mptcp/mptcp_sockopt.sh +++ b/tools/testing/selftests/net/mptcp/mptcp_sockopt.sh @@ -115,7 +115,7 @@ check_mark()
print_title() { - printf "%-50s" "${@}" + mptcp_lib_print_title "${@}" }
do_transfer() diff --git a/tools/testing/selftests/net/mptcp/pm_netlink.sh b/tools/testing/selftests/net/mptcp/pm_netlink.sh index 427fc5c70b3c..5b9bc25dfef4 100755 --- a/tools/testing/selftests/net/mptcp/pm_netlink.sh +++ b/tools/testing/selftests/net/mptcp/pm_netlink.sh @@ -53,7 +53,7 @@ check() local msg="$3" local rc=0
- printf "%-50s" "$msg" + mptcp_lib_print_title "$msg" mptcp_lib_check_output "${err}" "${cmd}" "${expected}" || rc=${?} if [ ${rc} -eq 2 ]; then mptcp_lib_result_fail "${msg} # error ${rc}" @@ -189,7 +189,8 @@ subflow,backup,fullmesh 10.0.1.1" " (backup,fullmesh)" else for st in fullmesh nofullmesh backup,fullmesh; do st=" (${st})" - printf "%-50s%s\n" "${st}" "[SKIP]" + mptcp_lib_print_title "${st}" + echo "[SKIP]" mptcp_lib_result_skip "${st}" done fi diff --git a/tools/testing/selftests/net/mptcp/simult_flows.sh b/tools/testing/selftests/net/mptcp/simult_flows.sh index 3ad663e38c42..b7549d9364d6 100755 --- a/tools/testing/selftests/net/mptcp/simult_flows.sh +++ b/tools/testing/selftests/net/mptcp/simult_flows.sh @@ -14,6 +14,8 @@ ns3="" capture=false timeout_poll=30 timeout_test=$((timeout_poll * 2 + 1)) +# a bit more space: because we have more to display +MPTCP_LIB_TEST_FORMAT="%02u %-60s" ret=0 bail=0 slack=50 @@ -126,7 +128,6 @@ do_transfer() local max_time=$3 local port port=$((10000+MPTCP_LIB_TEST_COUNTER)) - MPTCP_LIB_TEST_COUNTER=$((MPTCP_LIB_TEST_COUNTER+1))
:> "$cout" :> "$sout" @@ -238,7 +239,7 @@ run_test() # completion (see mptcp_connect): 200ms on each side, add some slack time=$((time + 400 + slack))
- printf "%-60s" "$msg" + mptcp_lib_print_title "$msg" do_transfer $small $large $time lret=$? mptcp_lib_result_code "${lret}" "${msg}" @@ -248,7 +249,7 @@ run_test() fi
msg+=" - reverse direction" - printf "%-60s" "${msg}" + mptcp_lib_print_title "${msg}" do_transfer $large $small $time lret=$? mptcp_lib_result_code "${lret}" "${msg}" diff --git a/tools/testing/selftests/net/mptcp/userspace_pm.sh b/tools/testing/selftests/net/mptcp/userspace_pm.sh index b0cce8f065d8..ca238592baee 100755 --- a/tools/testing/selftests/net/mptcp/userspace_pm.sh +++ b/tools/testing/selftests/net/mptcp/userspace_pm.sh @@ -54,6 +54,8 @@ ns1="" ns2="" ret=0 test_name="" +# a bit more space: because we have more to display +MPTCP_LIB_TEST_FORMAT="%02u %-68s"
_printf() { stdbuf -o0 -e0 printf "${@}" @@ -69,7 +71,7 @@ print_test() { test_name="${1}"
- _printf "%-68s" "${test_name}" + mptcp_lib_print_title "${test_name}" }
print_results()
From: Geliang Tang tanggeliang@kylinos.cn
This patch uses addition assignment operator (+=) to append strings instead of duplicating the variable name in mptcp_connect.sh and mptcp_join.sh.
This can make the statements shorter.
Note: in mptcp_connect.sh, add a local variable extra in do_transfer to save the various extra warning logs, using += to append it. And add a new variable tc_info to save various tc info, also using += to append it. This can make the code more readable and prepare for the next commit.
Signed-off-by: Geliang Tang tanggeliang@kylinos.cn Reviewed-by: Matthieu Baerts (NGI0) matttbe@kernel.org Signed-off-by: Matthieu Baerts (NGI0) matttbe@kernel.org --- tools/testing/selftests/net/mptcp/mptcp_connect.sh | 53 ++++++++++++---------- tools/testing/selftests/net/mptcp/mptcp_join.sh | 30 ++++++------ 2 files changed, 43 insertions(+), 40 deletions(-)
diff --git a/tools/testing/selftests/net/mptcp/mptcp_connect.sh b/tools/testing/selftests/net/mptcp/mptcp_connect.sh index bbda37d6514f..78098546ddd3 100755 --- a/tools/testing/selftests/net/mptcp/mptcp_connect.sh +++ b/tools/testing/selftests/net/mptcp/mptcp_connect.sh @@ -323,15 +323,15 @@ do_transfer() port=$((port + 1))
if [ "$rcvbuf" -gt 0 ]; then - extra_args="$extra_args -R $rcvbuf" + extra_args+=" -R $rcvbuf" fi
if [ "$sndbuf" -gt 0 ]; then - extra_args="$extra_args -S $sndbuf" + extra_args+=" -S $sndbuf" fi
if [ -n "$testmode" ]; then - extra_args="$extra_args -m $testmode" + extra_args+=" -m $testmode" fi
if [ -n "$extra_args" ] && $options_log; then @@ -451,6 +451,7 @@ do_transfer() mptcp_lib_check_transfer $cin $sout "file received by server" rets=$?
+ local extra="" local stat_synrx_now_l local stat_ackrx_now_l local stat_cookietx_now @@ -484,7 +485,7 @@ do_transfer() "${stat_ackrx_now_l}" "${expect_ackrx}" rets=1 else - printf "[ Note ] fallback due to TCP OoO" + extra+=" [ Note ] fallback due to TCP OoO" fi fi
@@ -507,39 +508,41 @@ do_transfer() fi fi
- if [ $retc -eq 0 ] && [ $rets -eq 0 ]; then - printf "[ OK ]" - mptcp_lib_result_pass "${TEST_GROUP}: ${result_msg}" - else - mptcp_lib_result_fail "${TEST_GROUP}: ${result_msg}" - fi - if [ $cookies -eq 2 ];then if [ $stat_cookietx_last -ge $stat_cookietx_now ] ;then - printf " WARN: CookieSent: did not advance" + extra+=" WARN: CookieSent: did not advance" fi if [ $stat_cookierx_last -ge $stat_cookierx_now ] ;then - printf " WARN: CookieRecv: did not advance" + extra+=" WARN: CookieRecv: did not advance" fi else if [ $stat_cookietx_last -ne $stat_cookietx_now ] ;then - printf " WARN: CookieSent: changed" + extra+=" WARN: CookieSent: changed" fi if [ $stat_cookierx_last -ne $stat_cookierx_now ] ;then - printf " WARN: CookieRecv: changed" + extra+=" WARN: CookieRecv: changed" fi fi
if [ ${stat_synrx_now_l} -gt ${expect_synrx} ]; then - printf " WARN: SYNRX: expect %d, got %d (probably retransmissions)" \ - "${expect_synrx}" "${stat_synrx_now_l}" + extra+=" WARN: SYNRX: expect ${expect_synrx}," + extra+=" got ${stat_synrx_now_l} (probably retransmissions)" fi if [ ${stat_ackrx_now_l} -gt ${expect_ackrx} ]; then - printf " WARN: ACKRX: expect %d, got %d (probably retransmissions)" \ - "${expect_ackrx}" "${stat_ackrx_now_l}" + extra+=" WARN: ACKRX: expect ${expect_ackrx}," + extra+=" got ${stat_ackrx_now_l} (probably retransmissions)" + fi + + if [ $retc -eq 0 ] && [ $rets -eq 0 ]; then + printf "[ OK ]%s\n" "${extra:1}" + mptcp_lib_result_pass "${TEST_GROUP}: ${result_msg}" + else + if [ -n "${extra}" ]; then + printf "%s\n" "${extra:1}" + fi + mptcp_lib_result_fail "${TEST_GROUP}: ${result_msg}" fi
- echo cat "$capout" [ $retc -eq 0 ] && [ $rets -eq 0 ] } @@ -865,8 +868,8 @@ stop_if_error "Could not even run ping tests" echo "[ OK ]"
[ -n "$tc_loss" ] && tc -net "$ns2" qdisc add dev ns2eth3 root netem loss random $tc_loss delay ${tc_delay}ms -echo -n "INFO: Using loss of $tc_loss " -test "$tc_delay" -gt 0 && echo -n "delay $tc_delay ms " +tc_info="loss of $tc_loss " +test "$tc_delay" -gt 0 && tc_info+="delay $tc_delay ms "
reorder_delay=$((tc_delay / 4))
@@ -877,17 +880,17 @@ if [ -z "${tc_reorder}" ]; then
if [ $reorder_delay -gt 0 ] && [ $reorder1 -lt 100 ] && [ $reorder2 -gt 0 ]; then tc_reorder="reorder ${reorder1}% ${reorder2}%" - echo -n "$tc_reorder with delay ${reorder_delay}ms " + tc_info+="$tc_reorder with delay ${reorder_delay}ms " fi elif [ "$tc_reorder" = "0" ];then tc_reorder="" elif [ "$reorder_delay" -gt 0 ];then # reordering requires some delay tc_reorder="reorder $tc_reorder" - echo -n "$tc_reorder with delay ${reorder_delay}ms " + tc_info+="$tc_reorder with delay ${reorder_delay}ms " fi
-echo "on ns3eth4" +echo "INFO: Using ${tc_info}on ns3eth4"
tc -net "$ns3" qdisc add dev ns3eth4 root netem delay ${reorder_delay}ms $tc_reorder
diff --git a/tools/testing/selftests/net/mptcp/mptcp_join.sh b/tools/testing/selftests/net/mptcp/mptcp_join.sh index 2f34e2b9a1c4..d2969eec36d5 100755 --- a/tools/testing/selftests/net/mptcp/mptcp_join.sh +++ b/tools/testing/selftests/net/mptcp/mptcp_join.sh @@ -754,18 +754,18 @@ pm_nl_check_endpoint() line="${line% }" # the dump order is: address id flags port dev [ -n "$addr" ] && expected_line="$addr" - expected_line="$expected_line $id" - [ -n "$_flags" ] && expected_line="$expected_line ${_flags//","/" "}" - [ -n "$dev" ] && expected_line="$expected_line $dev" - [ -n "$port" ] && expected_line="$expected_line $port" + expected_line+=" $id" + [ -n "$_flags" ] && expected_line+=" ${_flags//","/" "}" + [ -n "$dev" ] && expected_line+=" $dev" + [ -n "$port" ] && expected_line+=" $port" else line=$(ip netns exec $ns ./pm_nl_ctl get $_id) # the dump order is: id flags dev address port expected_line="$id" - [ -n "$flags" ] && expected_line="$expected_line $flags" - [ -n "$dev" ] && expected_line="$expected_line $dev" - [ -n "$addr" ] && expected_line="$expected_line $addr" - [ -n "$_port" ] && expected_line="$expected_line $_port" + [ -n "$flags" ] && expected_line+=" $flags" + [ -n "$dev" ] && expected_line+=" $dev" + [ -n "$addr" ] && expected_line+=" $addr" + [ -n "$_port" ] && expected_line+=" $_port" fi if [ "$line" = "$expected_line" ]; then print_ok @@ -1216,7 +1216,7 @@ chk_csum_nr() print_check "sum" count=$(mptcp_lib_get_counter ${ns1} "MPTcpExtDataCsumErr") if [ "$count" != "$csum_ns1" ]; then - extra_msg="$extra_msg ns1=$count" + extra_msg+=" ns1=$count" fi if [ -z "$count" ]; then print_skip @@ -1229,7 +1229,7 @@ chk_csum_nr() print_check "csum" count=$(mptcp_lib_get_counter ${ns2} "MPTcpExtDataCsumErr") if [ "$count" != "$csum_ns2" ]; then - extra_msg="$extra_msg ns2=$count" + extra_msg+=" ns2=$count" fi if [ -z "$count" ]; then print_skip @@ -1273,7 +1273,7 @@ chk_fail_nr() print_check "ftx" count=$(mptcp_lib_get_counter ${ns_tx} "MPTcpExtMPFailTx") if [ "$count" != "$fail_tx" ]; then - extra_msg="$extra_msg,tx=$count" + extra_msg+=",tx=$count" fi if [ -z "$count" ]; then print_skip @@ -1287,7 +1287,7 @@ chk_fail_nr() print_check "failrx" count=$(mptcp_lib_get_counter ${ns_rx} "MPTcpExtMPFailRx") if [ "$count" != "$fail_rx" ]; then - extra_msg="$extra_msg,rx=$count" + extra_msg+=",rx=$count" fi if [ -z "$count" ]; then print_skip @@ -1322,7 +1322,7 @@ chk_fclose_nr() if [ -z "$count" ]; then print_skip elif [ "$count" != "$fclose_tx" ]; then - extra_msg="$extra_msg,tx=$count" + extra_msg+=",tx=$count" fail_test "got $count MP_FASTCLOSE[s] TX expected $fclose_tx" else print_ok @@ -1333,7 +1333,7 @@ chk_fclose_nr() if [ -z "$count" ]; then print_skip elif [ "$count" != "$fclose_rx" ]; then - extra_msg="$extra_msg,rx=$count" + extra_msg+=",rx=$count" fail_test "got $count MP_FASTCLOSE[s] RX expected $fclose_rx" else print_ok @@ -1702,7 +1702,7 @@ chk_rm_nr() count=$((count + cnt)) if [ "$count" != "$rm_subflow_nr" ]; then suffix="$count in [$rm_subflow_nr:$((rm_subflow_nr*2))]" - extra_msg="$extra_msg simult" + extra_msg+=" simult" fi if [ $count -ge "$rm_subflow_nr" ] && \ [ "$count" -le "$((rm_subflow_nr *2 ))" ]; then
From: Geliang Tang tanggeliang@kylinos.cn
To unify the output formats of all test scripts, this patch adds four more helpers:
mptcp_lib_pr_ok() mptcp_lib_pr_skip() mptcp_lib_pr_fail() mptcp_lib_pr_info()
to print out [ OK ], [SKIP], [FAIL] and 'INFO: ' with colors. Use them in all scripts to print the "ok/skip/fail/info' using the same 'format'.
Having colors helps to quickly identify issues when looking at a long list of output logs and results.
Note that now all print the same keywords, which was not the case before, but it is good to uniform that.
Signed-off-by: Geliang Tang tanggeliang@kylinos.cn Reviewed-by: Matthieu Baerts (NGI0) matttbe@kernel.org Signed-off-by: Matthieu Baerts (NGI0) matttbe@kernel.org --- tools/testing/selftests/net/mptcp/diag.sh | 12 ++--- tools/testing/selftests/net/mptcp/mptcp_connect.sh | 62 +++++++++++----------- tools/testing/selftests/net/mptcp/mptcp_join.sh | 6 +-- tools/testing/selftests/net/mptcp/mptcp_lib.sh | 36 +++++++++---- tools/testing/selftests/net/mptcp/mptcp_sockopt.sh | 28 +++++----- tools/testing/selftests/net/mptcp/pm_netlink.sh | 2 +- tools/testing/selftests/net/mptcp/simult_flows.sh | 4 +- tools/testing/selftests/net/mptcp/userspace_pm.sh | 27 +++------- 8 files changed, 90 insertions(+), 87 deletions(-)
diff --git a/tools/testing/selftests/net/mptcp/diag.sh b/tools/testing/selftests/net/mptcp/diag.sh index 4ffdd415e670..bc97ab33a00e 100755 --- a/tools/testing/selftests/net/mptcp/diag.sh +++ b/tools/testing/selftests/net/mptcp/diag.sh @@ -57,15 +57,15 @@ __chk_nr() mptcp_lib_print_title "$msg" if [ "$nr" != "$expected" ]; then if [ "$nr" = "$skip" ] && ! mptcp_lib_expect_all_features; then - echo "[ skip ] Feature probably not supported" + mptcp_lib_pr_skip "Feature probably not supported" mptcp_lib_result_skip "${msg}" else - echo "[ fail ] expected $expected found $nr" + mptcp_lib_pr_fail "expected $expected found $nr" mptcp_lib_result_fail "${msg}" ret=${KSFT_FAIL} fi else - echo "[ ok ]" + mptcp_lib_pr_ok mptcp_lib_result_pass "${msg}" fi } @@ -114,15 +114,15 @@ wait_msk_nr()
mptcp_lib_print_title "$msg" if [ $i -ge $timeout ]; then - echo "[ fail ] timeout while expecting $expected max $max last $nr" + mptcp_lib_pr_fail "timeout while expecting $expected max $max last $nr" mptcp_lib_result_fail "${msg} # timeout" ret=${KSFT_FAIL} elif [ $nr != $expected ]; then - echo "[ fail ] expected $expected found $nr" + mptcp_lib_pr_fail "expected $expected found $nr" mptcp_lib_result_fail "${msg} # unexpected result" ret=${KSFT_FAIL} else - echo "[ ok ]" + mptcp_lib_pr_ok mptcp_lib_result_pass "${msg}" fi } diff --git a/tools/testing/selftests/net/mptcp/mptcp_connect.sh b/tools/testing/selftests/net/mptcp/mptcp_connect.sh index 78098546ddd3..cb1837f2761a 100755 --- a/tools/testing/selftests/net/mptcp/mptcp_connect.sh +++ b/tools/testing/selftests/net/mptcp/mptcp_connect.sh @@ -218,7 +218,7 @@ set_ethtool_flags() { local flags="$3"
if ip netns exec $ns ethtool -K $dev $flags 2>/dev/null; then - echo "INFO: set $ns dev $dev: ethtool -K $flags" + mptcp_lib_pr_info "set $ns dev $dev: ethtool -K $flags" fi }
@@ -261,7 +261,7 @@ check_mptcp_disabled() print_larger_title "New MPTCP socket can be blocked via sysctl" # net.mptcp.enabled should be enabled by default if [ "$(ip netns exec ${disabled_ns} sysctl net.mptcp.enabled | awk '{ print $3 }')" -ne 1 ]; then - echo -e "net.mptcp.enabled sysctl is not 1 by default\t\t[ FAIL ]" + mptcp_lib_pr_fail "net.mptcp.enabled sysctl is not 1 by default" mptcp_lib_result_fail "net.mptcp.enabled sysctl is not 1 by default" ret=1 return 1 @@ -274,13 +274,13 @@ check_mptcp_disabled() mptcp_lib_ns_exit "${disabled_ns}"
if [ ${err} -eq 0 ]; then - echo -e "New MPTCP socket cannot be blocked via sysctl\t\t[ FAIL ]" + mptcp_lib_pr_fail "New MPTCP socket cannot be blocked via sysctl" mptcp_lib_result_fail "New MPTCP socket cannot be blocked via sysctl" ret=1 return 1 fi
- echo "[ OK ]" + mptcp_lib_pr_ok mptcp_lib_result_pass "New MPTCP socket can be blocked via sysctl" return 0 } @@ -301,7 +301,7 @@ do_ping() ip netns exec ${connector_ns} ping ${ping_args} $connect_addr >/dev/null || rc=1
if [ $rc -ne 0 ] ; then - echo "$listener_ns -> $connect_addr connectivity [ FAIL ]" + mptcp_lib_pr_fail "$listener_ns -> $connect_addr connectivity" ret=1
return 1 @@ -335,7 +335,7 @@ do_transfer() fi
if [ -n "$extra_args" ] && $options_log; then - echo "INFO: extra options: $extra_args" + mptcp_lib_pr_info "extra options: $extra_args" fi options_log=false
@@ -432,7 +432,7 @@ do_transfer() result_msg+=" # time=${duration}ms" printf "(duration %05sms) " "${duration}" if [ ${rets} -ne 0 ] || [ ${retc} -ne 0 ]; then - echo "[ FAIL ] client exit code $retc, server $rets" 1>&2 + mptcp_lib_pr_fail "client exit code $retc, server $rets" echo -e "\nnetns ${listener_ns} socket stat for ${port}:" 1>&2 ip netns exec ${listener_ns} ss -Menita 1>&2 -o "sport = :$port" cat /tmp/${listener_ns}.out @@ -475,14 +475,14 @@ do_transfer() fi
if [ ${stat_synrx_now_l} -lt ${expect_synrx} ]; then - printf "[ FAIL ] lower MPC SYN rx (%d) than expected (%d)\n" \ - "${stat_synrx_now_l}" "${expect_synrx}" + mptcp_lib_pr_fail "lower MPC SYN rx (${stat_synrx_now_l})" \ + "than expected (${expect_synrx})" retc=1 fi if [ ${stat_ackrx_now_l} -lt ${expect_ackrx} ] && [ ${stat_ooo_now} -eq 0 ]; then if [ ${stat_ooo_now} -eq 0 ]; then - printf "[ FAIL ] lower MPC ACK rx (%d) than expected (%d)\n" \ - "${stat_ackrx_now_l}" "${expect_ackrx}" + mptcp_lib_pr_fail "lower MPC ACK rx (${stat_ackrx_now_l})" \ + "than expected (${expect_ackrx})" rets=1 else extra+=" [ Note ] fallback due to TCP OoO" @@ -497,13 +497,13 @@ do_transfer()
local csum_err_s_nr=$((csum_err_s - stat_csum_err_s)) if [ $csum_err_s_nr -gt 0 ]; then - printf "[ FAIL ]\nserver got %d data checksum error[s]" ${csum_err_s_nr} + mptcp_lib_pr_fail "server got ${csum_err_s_nr} data checksum error[s]" rets=1 fi
local csum_err_c_nr=$((csum_err_c - stat_csum_err_c)) if [ $csum_err_c_nr -gt 0 ]; then - printf "[ FAIL ]\nclient got %d data checksum error[s]" ${csum_err_c_nr} + mptcp_lib_pr_fail "client got ${csum_err_c_nr} data checksum error[s]" retc=1 fi fi @@ -534,11 +534,11 @@ do_transfer() fi
if [ $retc -eq 0 ] && [ $rets -eq 0 ]; then - printf "[ OK ]%s\n" "${extra:1}" + mptcp_lib_pr_ok "${extra:1}" mptcp_lib_result_pass "${TEST_GROUP}: ${result_msg}" else if [ -n "${extra}" ]; then - printf "%s\n" "${extra:1}" + mptcp_lib_print_warn "${extra:1}" fi mptcp_lib_result_fail "${TEST_GROUP}: ${result_msg}" fi @@ -668,7 +668,7 @@ run_test_transparent() # following function has been exported (T). Not great but better than # checking for a specific kernel version. if ! mptcp_lib_kallsyms_has "T __ip_sock_set_tos$"; then - echo "INFO: ${msg} not supported by the kernel: SKIP" + mptcp_lib_pr_skip "${msg} not supported by the kernel" mptcp_lib_result_skip "${TEST_GROUP}" return fi @@ -685,7 +685,7 @@ table inet mangle { } EOF then - echo "SKIP: $msg, could not load nft ruleset" + mptcp_lib_pr_skip "$msg, could not load nft ruleset" mptcp_lib_fail_if_expected_feature "nft rules" mptcp_lib_result_skip "${TEST_GROUP}" return @@ -701,7 +701,7 @@ EOF
if ! ip -net "$listener_ns" $r6flag rule add fwmark 1 lookup 100; then ip netns exec "$listener_ns" nft flush ruleset - echo "SKIP: $msg, ip $r6flag rule failed" + mptcp_lib_pr_skip "$msg, ip $r6flag rule failed" mptcp_lib_fail_if_expected_feature "ip rule" mptcp_lib_result_skip "${TEST_GROUP}" return @@ -710,13 +710,13 @@ EOF if ! ip -net "$listener_ns" route add local $local_addr/0 dev lo table 100; then ip netns exec "$listener_ns" nft flush ruleset ip -net "$listener_ns" $r6flag rule del fwmark 1 lookup 100 - echo "SKIP: $msg, ip route add local $local_addr failed" + mptcp_lib_pr_skip "$msg, ip route add local $local_addr failed" mptcp_lib_fail_if_expected_feature "ip route" mptcp_lib_result_skip "${TEST_GROUP}" return fi
- echo "INFO: test $msg" + mptcp_lib_pr_info "test $msg"
port=$((20000 - 1)) local extra_args="-o TRANSPARENT" @@ -729,12 +729,12 @@ EOF ip -net "$listener_ns" route del local $local_addr/0 dev lo table 100
if [ $lret -ne 0 ]; then - echo "FAIL: $msg, mptcp connection error" + mptcp_lib_pr_fail "$msg, mptcp connection error" ret=$lret return 1 fi
- echo "PASS: $msg" + mptcp_lib_pr_info "$msg pass" return 0 }
@@ -743,7 +743,7 @@ run_tests_peekmode() local peekmode="$1"
TEST_GROUP="peek mode: ${peekmode}" - echo "INFO: with peek mode: ${peekmode}" + mptcp_lib_pr_info "with peek mode: ${peekmode}" run_tests_lo "$ns1" "$ns1" 10.0.1.1 1 "-P ${peekmode}" run_tests_lo "$ns1" "$ns1" dead:beef:1::1 1 "-P ${peekmode}" } @@ -753,12 +753,12 @@ run_tests_mptfo() TEST_GROUP="MPTFO"
if ! mptcp_lib_kallsyms_has "mptcp_fastopen_"; then - echo "INFO: TFO not supported by the kernel: SKIP" + mptcp_lib_pr_skip "TFO not supported by the kernel" mptcp_lib_result_skip "${TEST_GROUP}" return fi
- echo "INFO: with MPTFO start" + mptcp_lib_pr_info "with MPTFO start" ip netns exec "$ns1" sysctl -q net.ipv4.tcp_fastopen=2 ip netns exec "$ns2" sysctl -q net.ipv4.tcp_fastopen=1
@@ -770,7 +770,7 @@ run_tests_mptfo()
ip netns exec "$ns1" sysctl -q net.ipv4.tcp_fastopen=0 ip netns exec "$ns2" sysctl -q net.ipv4.tcp_fastopen=0 - echo "INFO: with MPTFO end" + mptcp_lib_pr_info "with MPTFO end" }
run_tests_disconnect() @@ -781,7 +781,7 @@ run_tests_disconnect() TEST_GROUP="full disconnect"
if ! mptcp_lib_kallsyms_has "mptcp_pm_data_reset$"; then - echo "INFO: Full disconnect not supported: SKIP" + mptcp_lib_pr_skip "Full disconnect not supported" mptcp_lib_result_skip "${TEST_GROUP}" return fi @@ -794,7 +794,7 @@ run_tests_disconnect() cin_disconnect="$old_cin" connect_per_transfer=3
- echo "INFO: disconnect" + mptcp_lib_pr_info "disconnect" run_tests_lo "$ns1" "$ns1" 10.0.1.1 1 "-I 3 -i $old_cin" run_tests_lo "$ns1" "$ns1" dead:beef:1::1 1 "-I 3 -i $old_cin"
@@ -818,7 +818,7 @@ log_if_error() local msg="$1"
if [ ${ret} -ne 0 ]; then - echo "FAIL: ${msg}" + mptcp_lib_pr_fail "${msg}"
final_ret=${ret} ret=0 @@ -865,7 +865,7 @@ done mptcp_lib_result_code "${ret}" "ping tests"
stop_if_error "Could not even run ping tests" -echo "[ OK ]" +mptcp_lib_pr_ok
[ -n "$tc_loss" ] && tc -net "$ns2" qdisc add dev ns2eth3 root netem loss random $tc_loss delay ${tc_delay}ms tc_info="loss of $tc_loss " @@ -890,7 +890,7 @@ elif [ "$reorder_delay" -gt 0 ];then tc_info+="$tc_reorder with delay ${reorder_delay}ms " fi
-echo "INFO: Using ${tc_info}on ns3eth4" +mptcp_lib_pr_info "Using ${tc_info}on ns3eth4"
tc -net "$ns3" qdisc add dev ns3eth4 root netem delay ${reorder_delay}ms $tc_reorder
diff --git a/tools/testing/selftests/net/mptcp/mptcp_join.sh b/tools/testing/selftests/net/mptcp/mptcp_join.sh index d2969eec36d5..9f67b9ba97d8 100755 --- a/tools/testing/selftests/net/mptcp/mptcp_join.sh +++ b/tools/testing/selftests/net/mptcp/mptcp_join.sh @@ -185,17 +185,17 @@ print_info()
print_ok() { - mptcp_lib_print_ok "[ ok ]${1:+ ${*}}" + mptcp_lib_pr_ok "${@}" }
print_fail() { - mptcp_lib_print_err "[fail]${1:+ ${*}}" + mptcp_lib_pr_fail "${@}" }
print_skip() { - mptcp_lib_print_warn "[skip]${1:+ ${*}}" + mptcp_lib_pr_skip "${@}" }
# [ $1: fail msg ] diff --git a/tools/testing/selftests/net/mptcp/mptcp_lib.sh b/tools/testing/selftests/net/mptcp/mptcp_lib.sh index eb740a2f7898..ea39392c68e7 100644 --- a/tools/testing/selftests/net/mptcp/mptcp_lib.sh +++ b/tools/testing/selftests/net/mptcp/mptcp_lib.sh @@ -50,6 +50,23 @@ mptcp_lib_print_err() { mptcp_lib_print_color "${MPTCP_LIB_COLOR_RED}${*}" }
+# shellcheck disable=SC2120 # parameters are optional +mptcp_lib_pr_ok() { + mptcp_lib_print_ok "[ OK ]${1:+ ${*}}" +} + +mptcp_lib_pr_skip() { + mptcp_lib_print_warn "[SKIP]${1:+ ${*}}" +} + +mptcp_lib_pr_fail() { + mptcp_lib_print_err "[FAIL]${1:+ ${*}}" +} + +mptcp_lib_pr_info() { + mptcp_lib_print_info "INFO: ${*}" +} + # SELFTESTS_MPTCP_LIB_EXPECT_ALL_FEATURES env var can be set when validating all # features using the last version of the kernel and the selftests to make sure # a test is not being skipped by mistake. @@ -80,14 +97,14 @@ mptcp_lib_has_file() {
mptcp_lib_check_mptcp() { if ! mptcp_lib_has_file "/proc/sys/net/mptcp/enabled"; then - echo "SKIP: MPTCP support is not available" + mptcp_lib_pr_skip "MPTCP support is not available" exit ${KSFT_SKIP} fi }
mptcp_lib_check_kallsyms() { if ! mptcp_lib_has_file "/proc/kallsyms"; then - echo "SKIP: CONFIG_KALLSYMS is missing" + mptcp_lib_pr_skip "CONFIG_KALLSYMS is missing" exit ${KSFT_SKIP} fi } @@ -294,7 +311,7 @@ mptcp_lib_check_transfer() { local what="${3}"
if ! cmp "$in" "$out" > /dev/null 2>&1; then - echo "[ FAIL ] $what does not match (in, out):" + mptcp_lib_pr_fail "$what does not match (in, out):" mptcp_lib_print_file_err "$in" mptcp_lib_print_file_err "$out"
@@ -334,13 +351,13 @@ mptcp_lib_check_output() { fi
if [ ${cmd_ret} -ne 0 ]; then - mptcp_lib_print_err "[FAIL] command execution '${cmd}' stderr" + mptcp_lib_pr_fail "command execution '${cmd}' stderr" cat "${err}" return 2 elif [ "${out}" = "${expected}" ]; then return 0 else - mptcp_lib_print_err "[FAIL] expected '${expected}' got '${out}'" + mptcp_lib_pr_fail "expected '${expected}' got '${out}'" return 1 fi } @@ -352,29 +369,30 @@ mptcp_lib_check_tools() { case "${tool}" in "ip") if ! ip -Version &> /dev/null; then - mptcp_lib_print_warn "SKIP: Could not run test without ip tool" + mptcp_lib_pr_skip "Could not run test without ip tool" exit ${KSFT_SKIP} fi ;; "ss") if ! ss -h | grep -q MPTCP; then - mptcp_lib_print_warn "SKIP: ss tool does not support MPTCP" + mptcp_lib_pr_skip "ss tool does not support MPTCP" exit ${KSFT_SKIP} fi ;; "iptables"* | "ip6tables"*) if ! "${tool}" -V &> /dev/null; then - mptcp_lib_print_warn "SKIP: Could not run all tests without ${tool}" + mptcp_lib_pr_skip "Could not run all tests without ${tool}" exit ${KSFT_SKIP} fi ;; *) - mptcp_lib_print_err "Internal error: unsupported tool: ${tool}" + mptcp_lib_pr_fail "Internal error: unsupported tool: ${tool}" exit ${KSFT_FAIL} ;; esac done } + mptcp_lib_ns_init() { local sec rndh
diff --git a/tools/testing/selftests/net/mptcp/mptcp_sockopt.sh b/tools/testing/selftests/net/mptcp/mptcp_sockopt.sh index 19d0ac31b6a9..96aa8f71bbb0 100755 --- a/tools/testing/selftests/net/mptcp/mptcp_sockopt.sh +++ b/tools/testing/selftests/net/mptcp/mptcp_sockopt.sh @@ -103,8 +103,8 @@ check_mark() local v for v in $values; do if [ $v -ne 0 ]; then - echo "FAIL: got $tables $values in ns $ns," \ - "not 0 - not all expected packets marked" + mptcp_lib_pr_fail "got $tables $values in ns $ns," \ + "not 0 - not all expected packets marked" ret=1 return 1 fi @@ -169,7 +169,7 @@ do_transfer()
print_title "Transfer ${ip:2}" if [ ${rets} -ne 0 ] || [ ${retc} -ne 0 ]; then - echo "[FAIL] client exit code $retc, server $rets" + mptcp_lib_pr_fail "client exit code $retc, server $rets" echo -e "\nnetns ${listener_ns} socket stat for ${port}:" 1>&2 ip netns exec ${listener_ns} ss -Menita 1>&2 -o "sport = :$port"
@@ -184,7 +184,7 @@ do_transfer() if ! mptcp_lib_check_transfer $cin $sout "file received by server"; then rets=1 else - echo "[ OK ]" + mptcp_lib_pr_ok fi mptcp_lib_result_code "${rets}" "transfer ${ip}"
@@ -200,10 +200,10 @@ do_transfer() mptcp_lib_result_code "${retc}" "mark ${ip}"
if [ $retc -eq 0 ] && [ $rets -eq 0 ];then - echo "[ OK ]" + mptcp_lib_pr_ok return 0 fi - echo "[FAIL]" + mptcp_lib_pr_fail
return 1 } @@ -224,7 +224,7 @@ do_mptcp_sockopt_tests() local lret=0
if ! mptcp_lib_kallsyms_has "mptcp_diag_fill_info$"; then - echo "INFO: MPTCP sockopt not supported: SKIP" + mptcp_lib_pr_skip "MPTCP sockopt not supported" mptcp_lib_result_skip "sockopt" return fi @@ -234,12 +234,12 @@ do_mptcp_sockopt_tests()
print_title "SOL_MPTCP sockopt v4" if [ $lret -ne 0 ]; then - echo "[FAIL]" + mptcp_lib_pr_fail mptcp_lib_result_fail "sockopt v4" ret=$lret return fi - echo "[ OK ]" + mptcp_lib_pr_ok mptcp_lib_result_pass "sockopt v4"
ip netns exec "$ns_sbox" ./mptcp_sockopt -6 @@ -247,12 +247,12 @@ do_mptcp_sockopt_tests()
print_title "SOL_MPTCP sockopt v6" if [ $lret -ne 0 ]; then - echo "[FAIL]" + mptcp_lib_pr_fail mptcp_lib_result_fail "sockopt v6" ret=$lret return fi - echo "[ OK ]" + mptcp_lib_pr_ok mptcp_lib_result_pass "sockopt v6" }
@@ -280,12 +280,12 @@ do_tcpinq_test() local lret=$? if [ $lret -ne 0 ];then ret=$lret - echo "[FAIL]" + mptcp_lib_pr_fail mptcp_lib_result_fail "TCP_INQ: $*" return $lret fi
- echo "[ OK ]" + mptcp_lib_pr_ok mptcp_lib_result_pass "TCP_INQ: $*" return $lret } @@ -295,7 +295,7 @@ do_tcpinq_tests() local lret=0
if ! mptcp_lib_kallsyms_has "mptcp_ioctl$"; then - echo "INFO: TCP_INQ not supported: SKIP" + mptcp_lib_pr_skip "TCP_INQ not supported" mptcp_lib_result_skip "TCP_INQ" return fi diff --git a/tools/testing/selftests/net/mptcp/pm_netlink.sh b/tools/testing/selftests/net/mptcp/pm_netlink.sh index 5b9bc25dfef4..69ffff8b076b 100755 --- a/tools/testing/selftests/net/mptcp/pm_netlink.sh +++ b/tools/testing/selftests/net/mptcp/pm_netlink.sh @@ -190,7 +190,7 @@ else for st in fullmesh nofullmesh backup,fullmesh; do st=" (${st})" mptcp_lib_print_title "${st}" - echo "[SKIP]" + mptcp_lib_pr_skip mptcp_lib_result_skip "${st}" done fi diff --git a/tools/testing/selftests/net/mptcp/simult_flows.sh b/tools/testing/selftests/net/mptcp/simult_flows.sh index b7549d9364d6..e62052c3206d 100755 --- a/tools/testing/selftests/net/mptcp/simult_flows.sh +++ b/tools/testing/selftests/net/mptcp/simult_flows.sh @@ -187,12 +187,12 @@ do_transfer() printf "%-16s" " max $max_time " if [ $retc -eq 0 ] && [ $rets -eq 0 ] && \ [ $cmpc -eq 0 ] && [ $cmps -eq 0 ]; then - echo "[ OK ]" + mptcp_lib_pr_ok cat "$capout" return 0 fi
- echo " [ fail ]" + mptcp_lib_pr_fail echo "client exit code $retc, server $rets" 1>&2 echo -e "\nnetns ${ns3} socket stat for $port:" 1>&2 ip netns exec ${ns3} ss -nita 1>&2 -o "sport = :$port" diff --git a/tools/testing/selftests/net/mptcp/userspace_pm.sh b/tools/testing/selftests/net/mptcp/userspace_pm.sh index ca238592baee..4e29aa9c2529 100755 --- a/tools/testing/selftests/net/mptcp/userspace_pm.sh +++ b/tools/testing/selftests/net/mptcp/userspace_pm.sh @@ -57,13 +57,9 @@ test_name="" # a bit more space: because we have more to display MPTCP_LIB_TEST_FORMAT="%02u %-68s"
-_printf() { - stdbuf -o0 -e0 printf "${@}" -} - print_title() { - _printf "INFO: %s\n" "${1}" + mptcp_lib_pr_info "${1}" }
# $1: test name @@ -74,33 +70,23 @@ print_test() mptcp_lib_print_title "${test_name}" }
-print_results() -{ - _printf "[%s]\n" "${1}" -} - test_pass() { - print_results " OK " + mptcp_lib_pr_ok mptcp_lib_result_pass "${test_name}" }
test_skip() { - print_results "SKIP" + mptcp_lib_pr_skip mptcp_lib_result_skip "${test_name}" }
# $1: msg test_fail() { - print_results "FAIL" + mptcp_lib_pr_fail "${@}" ret=1 - - if [ -n "${1}" ]; then - _printf "\t%s\n" "${1}" - fi - mptcp_lib_result_fail "${test_name}" }
@@ -122,7 +108,7 @@ cleanup()
rm -rf $file $client_evts $server_evts
- _printf "Done\n" + mptcp_lib_pr_info "Done" }
trap cleanup EXIT @@ -256,8 +242,7 @@ check_expected_one() test_fail fi
- _printf "\tExpected value for '%s': '%s', got '%s'.\n" \ - "${var}" "${!exp}" "${!var}" + mptcp_lib_print_err "\tExpected value for '${var}': '${!exp}', got '${!var}'." return 1 }
From: Geliang Tang tanggeliang@kylinos.cn
This patch modifies test_fail() to call mptcp_lib_pr_fail() only if there are arguments (if [ ${#} -gt 0 ]) in userspace_pm.sh, add arguments "unexpected type: ${type}" when calling test_fail() from test_remove(). Then mptcp_lib_pr_fail() can be used in check_expected_one() instead of test_fail().
The same in mptcp_join.sh, calling fail_test() without argument, and adapt this helper not to call print_fail() in this case.
Signed-off-by: Geliang Tang tanggeliang@kylinos.cn Reviewed-by: Matthieu Baerts (NGI0) matttbe@kernel.org Signed-off-by: Matthieu Baerts (NGI0) matttbe@kernel.org --- tools/testing/selftests/net/mptcp/mptcp_join.sh | 7 +++++-- tools/testing/selftests/net/mptcp/userspace_pm.sh | 12 ++++++++---- 2 files changed, 13 insertions(+), 6 deletions(-)
diff --git a/tools/testing/selftests/net/mptcp/mptcp_join.sh b/tools/testing/selftests/net/mptcp/mptcp_join.sh index 9f67b9ba97d8..041175ec1304 100755 --- a/tools/testing/selftests/net/mptcp/mptcp_join.sh +++ b/tools/testing/selftests/net/mptcp/mptcp_join.sh @@ -452,7 +452,9 @@ fail_test() { ret=1
- print_fail "${@}" + if [ ${#} -gt 0 ]; then + print_fail "${@}" + fi
# just in case a test is marked twice as failed if [ ${last_test_failed} -eq 0 ]; then @@ -2834,7 +2836,8 @@ verify_listener_events() print_ok return 0 fi - fail_test "$e_type:$type $e_family:$family $e_saddr:$saddr $e_sport:$sport" + print_fail "$e_type:$type $e_family:$family $e_saddr:$saddr $e_sport:$sport" + fail_test }
add_addr_ports_tests() diff --git a/tools/testing/selftests/net/mptcp/userspace_pm.sh b/tools/testing/selftests/net/mptcp/userspace_pm.sh index 4e29aa9c2529..bc2f0184b1eb 100755 --- a/tools/testing/selftests/net/mptcp/userspace_pm.sh +++ b/tools/testing/selftests/net/mptcp/userspace_pm.sh @@ -85,7 +85,10 @@ test_skip() # $1: msg test_fail() { - mptcp_lib_pr_fail "${@}" + if [ ${#} -gt 0 ] + then + mptcp_lib_pr_fail "${@}" + fi ret=1 mptcp_lib_result_fail "${test_name}" } @@ -239,7 +242,7 @@ check_expected_one()
if [ "${prev_ret}" = "0" ] then - test_fail + mptcp_lib_pr_fail fi
mptcp_lib_print_err "\tExpected value for '${var}': '${!exp}', got '${!var}'." @@ -263,6 +266,7 @@ check_expected() return 0 fi
+ test_fail return 1 }
@@ -412,7 +416,7 @@ test_remove() then test_pass else - test_fail + test_fail "unexpected type: ${type}" fi
# RM_ADDR using an invalid addr id should result in no action @@ -425,7 +429,7 @@ test_remove() then test_pass else - test_fail + test_fail "unexpected type: ${type}" fi
# RM_ADDR from the client to server machine
From: Geliang Tang tanggeliang@kylinos.cn
Extract the main part of check_expected() in userspace_pm.sh to a new function mptcp_lib_check_expected() in mptcp_lib.sh. It will be used in both mptcp_john.sh and userspace_pm.sh. check_expected_one() is moved into mptcp_lib.sh too as mptcp_lib_check_expected_one().
Signed-off-by: Geliang Tang tanggeliang@kylinos.cn Reviewed-by: Matthieu Baerts (NGI0) matttbe@kernel.org Signed-off-by: Matthieu Baerts (NGI0) matttbe@kernel.org --- tools/testing/selftests/net/mptcp/mptcp_lib.sh | 30 +++++++++++++++++++++ tools/testing/selftests/net/mptcp/userspace_pm.sh | 33 ++--------------------- 2 files changed, 32 insertions(+), 31 deletions(-)
diff --git a/tools/testing/selftests/net/mptcp/mptcp_lib.sh b/tools/testing/selftests/net/mptcp/mptcp_lib.sh index ea39392c68e7..44491f18ed17 100644 --- a/tools/testing/selftests/net/mptcp/mptcp_lib.sh +++ b/tools/testing/selftests/net/mptcp/mptcp_lib.sh @@ -438,3 +438,33 @@ mptcp_lib_print_title() { # shellcheck disable=SC2059 # the format is in a variable printf "${MPTCP_LIB_TEST_FORMAT}" "$((++MPTCP_LIB_TEST_COUNTER))" "${*}" } + +# $1: var name ; $2: prev ret +mptcp_lib_check_expected_one() { + local var="${1}" + local exp="e_${var}" + local prev_ret="${2}" + + if [ "${!var}" = "${!exp}" ]; then + return 0 + fi + + if [ "${prev_ret}" = "0" ]; then + mptcp_lib_pr_fail + fi + + mptcp_lib_print_err "Expected value for '${var}': '${!exp}', got '${!var}'." + return 1 +} + +# $@: all var names to check +mptcp_lib_check_expected() { + local rc=0 + local var + + for var in "${@}"; do + mptcp_lib_check_expected_one "${var}" "${rc}" || rc=1 + done + + return "${rc}" +} diff --git a/tools/testing/selftests/net/mptcp/userspace_pm.sh b/tools/testing/selftests/net/mptcp/userspace_pm.sh index bc2f0184b1eb..6d0862a1b68d 100755 --- a/tools/testing/selftests/net/mptcp/userspace_pm.sh +++ b/tools/testing/selftests/net/mptcp/userspace_pm.sh @@ -5,7 +5,7 @@ # code but we accept it. #shellcheck disable=SC2086
-# Some variables are used below but indirectly, see check_expected_one() +# Some variables are used below but indirectly, see verify_*_event() #shellcheck disable=SC2034
. "$(dirname "${0}")/mptcp_lib.sh" @@ -228,39 +228,10 @@ make_connection() fi }
-# $1: var name ; $2: prev ret -check_expected_one() -{ - local var="${1}" - local exp="e_${var}" - local prev_ret="${2}" - - if [ "${!var}" = "${!exp}" ] - then - return 0 - fi - - if [ "${prev_ret}" = "0" ] - then - mptcp_lib_pr_fail - fi - - mptcp_lib_print_err "\tExpected value for '${var}': '${!exp}', got '${!var}'." - return 1 -} - # $@: all var names to check check_expected() { - local rc=0 - local var - - for var in "${@}" - do - check_expected_one "${var}" "${rc}" || rc=1 - done - - if [ ${rc} -eq 0 ] + if mptcp_lib_check_expected "${@}" then test_pass return 0
From: Geliang Tang tanggeliang@kylinos.cn
verify_listener_events() helper will be exported into mptcp_lib.sh as a public function, but print_test() is invoked in it, which is a private function in userspace_pm.sh only. So this patch moves print_test() out of verify_listener_events().
Signed-off-by: Geliang Tang tanggeliang@kylinos.cn Reviewed-by: Matthieu Baerts (NGI0) matttbe@kernel.org Signed-off-by: Matthieu Baerts (NGI0) matttbe@kernel.org --- tools/testing/selftests/net/mptcp/userspace_pm.sh | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-)
diff --git a/tools/testing/selftests/net/mptcp/userspace_pm.sh b/tools/testing/selftests/net/mptcp/userspace_pm.sh index 6d0862a1b68d..e9aea44edee5 100755 --- a/tools/testing/selftests/net/mptcp/userspace_pm.sh +++ b/tools/testing/selftests/net/mptcp/userspace_pm.sh @@ -845,12 +845,6 @@ verify_listener_events() local saddr local sport
- if [ $e_type = $LISTENER_CREATED ]; then - print_test "CREATE_LISTENER $e_saddr:$e_sport" - elif [ $e_type = $LISTENER_CLOSED ]; then - print_test "CLOSE_LISTENER $e_saddr:$e_sport" - fi - type=$(mptcp_lib_evts_get_info type $evt $e_type) family=$(mptcp_lib_evts_get_info family $evt $e_type) sport=$(mptcp_lib_evts_get_info sport $evt $e_type) @@ -882,6 +876,7 @@ test_listener() local listener_pid=$!
sleep 0.5 + print_test "CREATE_LISTENER 10.0.2.2:$client4_port" verify_listener_events $client_evts $LISTENER_CREATED $AF_INET 10.0.2.2 $client4_port
# ADD_ADDR from client to server machine reusing the subflow port @@ -898,6 +893,7 @@ test_listener() mptcp_lib_kill_wait $listener_pid
sleep 0.5 + print_test "CLOSE_LISTENER 10.0.2.2:$client4_port" verify_listener_events $client_evts $LISTENER_CLOSED $AF_INET 10.0.2.2 $client4_port }
From: Geliang Tang tanggeliang@kylinos.cn
To avoid duplicated code in different MPTCP selftests, we can add and use helpers defined in mptcp_lib.sh.
The helper verify_listener_events() is defined both in mptcp_join.sh and userspace_pm.sh, export it into mptcp_lib.sh and rename it with mptcp_lib_ prefix. Use this new helper in both scripts.
Signed-off-by: Geliang Tang tanggeliang@kylinos.cn Reviewed-by: Matthieu Baerts (NGI0) matttbe@kernel.org Signed-off-by: Matthieu Baerts (NGI0) matttbe@kernel.org --- tools/testing/selftests/net/mptcp/mptcp_join.sh | 21 +----------------- tools/testing/selftests/net/mptcp/mptcp_lib.sh | 26 +++++++++++++++++++++++ tools/testing/selftests/net/mptcp/userspace_pm.sh | 21 +++--------------- 3 files changed, 30 insertions(+), 38 deletions(-)
diff --git a/tools/testing/selftests/net/mptcp/mptcp_join.sh b/tools/testing/selftests/net/mptcp/mptcp_join.sh index 041175ec1304..9b538a7071e7 100755 --- a/tools/testing/selftests/net/mptcp/mptcp_join.sh +++ b/tools/testing/selftests/net/mptcp/mptcp_join.sh @@ -2794,15 +2794,9 @@ AF_INET6=10
verify_listener_events() { - local evt=$1 local e_type=$2 - local e_family=$3 local e_saddr=$4 local e_sport=$5 - local type - local family - local saddr - local sport local name
if [ $e_type = $LISTENER_CREATED ]; then @@ -2820,23 +2814,10 @@ verify_listener_events() return fi
- type=$(mptcp_lib_evts_get_info type "$evt" "$e_type") - family=$(mptcp_lib_evts_get_info family "$evt" "$e_type") - sport=$(mptcp_lib_evts_get_info sport "$evt" "$e_type") - if [ $family ] && [ $family = $AF_INET6 ]; then - saddr=$(mptcp_lib_evts_get_info saddr6 "$evt" "$e_type") - else - saddr=$(mptcp_lib_evts_get_info saddr4 "$evt" "$e_type") - fi - - if [ $type ] && [ $type = $e_type ] && - [ $family ] && [ $family = $e_family ] && - [ $saddr ] && [ $saddr = $e_saddr ] && - [ $sport ] && [ $sport = $e_sport ]; then + if mptcp_lib_verify_listener_events "${@}"; then print_ok return 0 fi - print_fail "$e_type:$type $e_family:$family $e_saddr:$saddr $e_sport:$sport" fail_test }
diff --git a/tools/testing/selftests/net/mptcp/mptcp_lib.sh b/tools/testing/selftests/net/mptcp/mptcp_lib.sh index 44491f18ed17..a977a722fb3d 100644 --- a/tools/testing/selftests/net/mptcp/mptcp_lib.sh +++ b/tools/testing/selftests/net/mptcp/mptcp_lib.sh @@ -468,3 +468,29 @@ mptcp_lib_check_expected() {
return "${rc}" } + +# shellcheck disable=SC2034 # Some variables are used below but indirectly +mptcp_lib_verify_listener_events() { + local evt=${1} + local e_type=${2} + local e_family=${3} + local e_saddr=${4} + local e_sport=${5} + local type + local family + local saddr + local sport + local rc=0 + + type=$(mptcp_lib_evts_get_info type "${evt}" "${e_type}") + family=$(mptcp_lib_evts_get_info family "${evt}" "${e_type}") + if [ "${family}" ] && [ "${family}" = "${AF_INET6}" ]; then + saddr=$(mptcp_lib_evts_get_info saddr6 "${evt}" "${e_type}") + else + saddr=$(mptcp_lib_evts_get_info saddr4 "${evt}" "${e_type}") + fi + sport=$(mptcp_lib_evts_get_info sport "${evt}" "${e_type}") + + mptcp_lib_check_expected "type" "family" "saddr" "sport" || rc="${?}" + return "${rc}" +} diff --git a/tools/testing/selftests/net/mptcp/userspace_pm.sh b/tools/testing/selftests/net/mptcp/userspace_pm.sh index e9aea44edee5..1e0b39e5525c 100755 --- a/tools/testing/selftests/net/mptcp/userspace_pm.sh +++ b/tools/testing/selftests/net/mptcp/userspace_pm.sh @@ -835,26 +835,11 @@ test_prio()
verify_listener_events() { - local evt=$1 - local e_type=$2 - local e_family=$3 - local e_saddr=$4 - local e_sport=$5 - local type - local family - local saddr - local sport - - type=$(mptcp_lib_evts_get_info type $evt $e_type) - family=$(mptcp_lib_evts_get_info family $evt $e_type) - sport=$(mptcp_lib_evts_get_info sport $evt $e_type) - if [ $family ] && [ $family = $AF_INET6 ]; then - saddr=$(mptcp_lib_evts_get_info saddr6 $evt $e_type) + if mptcp_lib_verify_listener_events "${@}"; then + test_pass else - saddr=$(mptcp_lib_evts_get_info saddr4 $evt $e_type) + test_fail fi - - check_expected "type" "family" "saddr" "sport" }
test_listener()
From: Geliang Tang tanggeliang@kylinos.cn
MPTCP event macros (SUB_ESTABLISHED, LISTENER_CREATED, LISTENER_CLOSED), and the protocol family macros (AF_INET, AF_INET6) are defined in both mptcp_join.sh and userspace_pm.sh. In order not to duplicate code, this patch declares them all in mptcp_lib.sh with MPTCP_LIB_ prefixs.
Signed-off-by: Geliang Tang tanggeliang@kylinos.cn Reviewed-by: Matthieu Baerts (NGI0) matttbe@kernel.org Signed-off-by: Matthieu Baerts (NGI0) matttbe@kernel.org --- tools/testing/selftests/net/mptcp/mptcp_join.sh | 23 +++++++++-------------- tools/testing/selftests/net/mptcp/mptcp_lib.sh | 11 +++++++++++ tools/testing/selftests/net/mptcp/userspace_pm.sh | 16 ++++++++-------- 3 files changed, 28 insertions(+), 22 deletions(-)
diff --git a/tools/testing/selftests/net/mptcp/mptcp_join.sh b/tools/testing/selftests/net/mptcp/mptcp_join.sh index 9b538a7071e7..728575fd86ea 100755 --- a/tools/testing/selftests/net/mptcp/mptcp_join.sh +++ b/tools/testing/selftests/net/mptcp/mptcp_join.sh @@ -2785,13 +2785,6 @@ backup_tests() fi }
-SUB_ESTABLISHED=10 # MPTCP_EVENT_SUB_ESTABLISHED -LISTENER_CREATED=15 #MPTCP_EVENT_LISTENER_CREATED -LISTENER_CLOSED=16 #MPTCP_EVENT_LISTENER_CLOSED - -AF_INET=2 -AF_INET6=10 - verify_listener_events() { local e_type=$2 @@ -2799,9 +2792,9 @@ verify_listener_events() local e_sport=$5 local name
- if [ $e_type = $LISTENER_CREATED ]; then + if [ $e_type = $MPTCP_LIB_EVENT_LISTENER_CREATED ]; then name="LISTENER_CREATED" - elif [ $e_type = $LISTENER_CLOSED ]; then + elif [ $e_type = $MPTCP_LIB_EVENT_LISTENER_CLOSED ]; then name="LISTENER_CLOSED " else name="$e_type" @@ -2856,8 +2849,10 @@ add_addr_ports_tests() chk_add_nr 1 1 1 chk_rm_nr 1 1 invert
- verify_listener_events $evts_ns1 $LISTENER_CREATED $AF_INET 10.0.2.1 10100 - verify_listener_events $evts_ns1 $LISTENER_CLOSED $AF_INET 10.0.2.1 10100 + verify_listener_events $evts_ns1 $MPTCP_LIB_EVENT_LISTENER_CREATED \ + $MPTCP_LIB_AF_INET 10.0.2.1 10100 + verify_listener_events $evts_ns1 $MPTCP_LIB_EVENT_LISTENER_CLOSED \ + $MPTCP_LIB_AF_INET 10.0.2.1 10100 kill_events_pids fi
@@ -3463,11 +3458,11 @@ userspace_tests() userspace_pm_chk_get_addr "${ns1}" "10" "id 10 flags signal 10.0.2.1" userspace_pm_chk_get_addr "${ns1}" "20" "id 20 flags signal 10.0.3.1" userspace_pm_rm_addr $ns1 10 - userspace_pm_rm_sf $ns1 "::ffff:10.0.2.1" $SUB_ESTABLISHED + userspace_pm_rm_sf $ns1 "::ffff:10.0.2.1" $MPTCP_LIB_EVENT_SUB_ESTABLISHED userspace_pm_chk_dump_addr "${ns1}" \ "id 20 flags signal 10.0.3.1" "after rm_addr 10" userspace_pm_rm_addr $ns1 20 - userspace_pm_rm_sf $ns1 10.0.3.1 $SUB_ESTABLISHED + userspace_pm_rm_sf $ns1 10.0.3.1 $MPTCP_LIB_EVENT_SUB_ESTABLISHED userspace_pm_chk_dump_addr "${ns1}" "" "after rm_addr 20" chk_rm_nr 2 2 invert chk_mptcp_info subflows 0 subflows 0 @@ -3494,7 +3489,7 @@ userspace_tests() "subflow" userspace_pm_chk_get_addr "${ns2}" "20" "id 20 flags subflow 10.0.3.2" userspace_pm_rm_addr $ns2 20 - userspace_pm_rm_sf $ns2 10.0.3.2 $SUB_ESTABLISHED + userspace_pm_rm_sf $ns2 10.0.3.2 $MPTCP_LIB_EVENT_SUB_ESTABLISHED userspace_pm_chk_dump_addr "${ns2}" \ "" \ "after rm_addr 20" diff --git a/tools/testing/selftests/net/mptcp/mptcp_lib.sh b/tools/testing/selftests/net/mptcp/mptcp_lib.sh index a977a722fb3d..d529b4b37af8 100644 --- a/tools/testing/selftests/net/mptcp/mptcp_lib.sh +++ b/tools/testing/selftests/net/mptcp/mptcp_lib.sh @@ -8,6 +8,17 @@ readonly KSFT_SKIP=4 # shellcheck disable=SC2155 # declare and assign separately readonly KSFT_TEST="${MPTCP_LIB_KSFT_TEST:-$(basename "${0}" .sh)}"
+# These variables are used in some selftests, read-only +declare -rx MPTCP_LIB_EVENT_ANNOUNCED=6 # MPTCP_EVENT_ANNOUNCED +declare -rx MPTCP_LIB_EVENT_REMOVED=7 # MPTCP_EVENT_REMOVED +declare -rx MPTCP_LIB_EVENT_SUB_ESTABLISHED=10 # MPTCP_EVENT_SUB_ESTABLISHED +declare -rx MPTCP_LIB_EVENT_SUB_CLOSED=11 # MPTCP_EVENT_SUB_CLOSED +declare -rx MPTCP_LIB_EVENT_LISTENER_CREATED=15 # MPTCP_EVENT_LISTENER_CREATED +declare -rx MPTCP_LIB_EVENT_LISTENER_CLOSED=16 # MPTCP_EVENT_LISTENER_CLOSED + +declare -rx MPTCP_LIB_AF_INET=2 +declare -rx MPTCP_LIB_AF_INET6=10 + MPTCP_LIB_SUBTESTS=() MPTCP_LIB_SUBTESTS_DUPLICATED=0 MPTCP_LIB_TEST_COUNTER=0 diff --git a/tools/testing/selftests/net/mptcp/userspace_pm.sh b/tools/testing/selftests/net/mptcp/userspace_pm.sh index 1e0b39e5525c..72dca742280f 100755 --- a/tools/testing/selftests/net/mptcp/userspace_pm.sh +++ b/tools/testing/selftests/net/mptcp/userspace_pm.sh @@ -19,15 +19,15 @@ if ! mptcp_lib_has_file '/proc/sys/net/mptcp/pm_type'; then fi mptcp_lib_check_tools ip
-ANNOUNCED=6 # MPTCP_EVENT_ANNOUNCED -REMOVED=7 # MPTCP_EVENT_REMOVED -SUB_ESTABLISHED=10 # MPTCP_EVENT_SUB_ESTABLISHED -SUB_CLOSED=11 # MPTCP_EVENT_SUB_CLOSED -LISTENER_CREATED=15 #MPTCP_EVENT_LISTENER_CREATED -LISTENER_CLOSED=16 #MPTCP_EVENT_LISTENER_CLOSED +ANNOUNCED=${MPTCP_LIB_EVENT_ANNOUNCED} +REMOVED=${MPTCP_LIB_EVENT_REMOVED} +SUB_ESTABLISHED=${MPTCP_LIB_EVENT_SUB_ESTABLISHED} +SUB_CLOSED=${MPTCP_LIB_EVENT_SUB_CLOSED} +LISTENER_CREATED=${MPTCP_LIB_EVENT_LISTENER_CREATED} +LISTENER_CLOSED=${MPTCP_LIB_EVENT_LISTENER_CLOSED}
-AF_INET=2 -AF_INET6=10 +AF_INET=${MPTCP_LIB_AF_INET} +AF_INET6=${MPTCP_LIB_AF_INET6}
file="" server_evts=""
From: Geliang Tang tanggeliang@kylinos.cn
This patch uses the public var KSFT_SKIP in mptcp_lib.sh instead of ksft_skip, and drop 'ksft_skip=4' in mptcp_join.sh.
Use KSFT_PASS and KSFT_FAIL macros instead of 0 and 1 after 'exit ' and 'ret=' in all scripts:
exit 0 -> exit ${KSFT_PASS} exit 1 -> exit ${KSFT_FAIL} ret=0 -> ret=${KSFT_PASS} ret=1 -> ret=${KSFT_FAIL}
Signed-off-by: Geliang Tang tanggeliang@kylinos.cn Reviewed-by: Matthieu Baerts (NGI0) matttbe@kernel.org Signed-off-by: Matthieu Baerts (NGI0) matttbe@kernel.org --- tools/testing/selftests/net/mptcp/mptcp_connect.sh | 18 +++++++++--------- tools/testing/selftests/net/mptcp/mptcp_join.sh | 13 ++++++------- tools/testing/selftests/net/mptcp/mptcp_sockopt.sh | 4 ++-- tools/testing/selftests/net/mptcp/pm_netlink.sh | 8 ++++---- tools/testing/selftests/net/mptcp/simult_flows.sh | 4 ++-- tools/testing/selftests/net/mptcp/userspace_pm.sh | 4 ++-- 6 files changed, 25 insertions(+), 26 deletions(-)
diff --git a/tools/testing/selftests/net/mptcp/mptcp_connect.sh b/tools/testing/selftests/net/mptcp/mptcp_connect.sh index cb1837f2761a..4c4248554826 100755 --- a/tools/testing/selftests/net/mptcp/mptcp_connect.sh +++ b/tools/testing/selftests/net/mptcp/mptcp_connect.sh @@ -65,14 +65,14 @@ while getopts "$optstring" option;do case "$option" in "h") usage $0 - exit 0 + exit ${KSFT_PASS} ;; "d") if [ $OPTARG -ge 0 ];then tc_delay="$OPTARG" else echo "-d requires numeric argument, got "$OPTARG"" 1>&2 - exit 1 + exit ${KSFT_FAIL} fi ;; "e") @@ -96,7 +96,7 @@ while getopts "$optstring" option;do sndbuf="$OPTARG" else echo "-S requires numeric argument, got "$OPTARG"" 1>&2 - exit 1 + exit ${KSFT_FAIL} fi ;; "R") @@ -104,7 +104,7 @@ while getopts "$optstring" option;do rcvbuf="$OPTARG" else echo "-R requires numeric argument, got "$OPTARG"" 1>&2 - exit 1 + exit ${KSFT_FAIL} fi ;; "m") @@ -121,7 +121,7 @@ while getopts "$optstring" option;do ;; "?") usage $0 - exit 1 + exit ${KSFT_FAIL} ;; esac done @@ -263,7 +263,7 @@ check_mptcp_disabled() if [ "$(ip netns exec ${disabled_ns} sysctl net.mptcp.enabled | awk '{ print $3 }')" -ne 1 ]; then mptcp_lib_pr_fail "net.mptcp.enabled sysctl is not 1 by default" mptcp_lib_result_fail "net.mptcp.enabled sysctl is not 1 by default" - ret=1 + ret=${KSFT_FAIL} return 1 fi ip netns exec ${disabled_ns} sysctl -q net.mptcp.enabled=0 @@ -276,7 +276,7 @@ check_mptcp_disabled() if [ ${err} -eq 0 ]; then mptcp_lib_pr_fail "New MPTCP socket cannot be blocked via sysctl" mptcp_lib_result_fail "New MPTCP socket cannot be blocked via sysctl" - ret=1 + ret=${KSFT_FAIL} return 1 fi
@@ -302,7 +302,7 @@ do_ping()
if [ $rc -ne 0 ] ; then mptcp_lib_pr_fail "$listener_ns -> $connect_addr connectivity" - ret=1 + ret=${KSFT_FAIL}
return 1 fi @@ -821,7 +821,7 @@ log_if_error() mptcp_lib_pr_fail "${msg}"
final_ret=${ret} - ret=0 + ret=${KSFT_PASS}
return ${final_ret} fi diff --git a/tools/testing/selftests/net/mptcp/mptcp_join.sh b/tools/testing/selftests/net/mptcp/mptcp_join.sh index 728575fd86ea..5e9211e89825 100755 --- a/tools/testing/selftests/net/mptcp/mptcp_join.sh +++ b/tools/testing/selftests/net/mptcp/mptcp_join.sh @@ -25,7 +25,6 @@ err="" capout="" ns1="" ns2="" -ksft_skip=4 iptables="iptables" ip6tables="ip6tables" timeout_poll=30 @@ -392,15 +391,15 @@ setup_fail_rules() -p tcp \ -m length --length 150:9999 \ -m statistic --mode nth --packet 1 --every 99999 \ - -j MARK --set-mark 42 || return ${ksft_skip} + -j MARK --set-mark 42 || return ${KSFT_SKIP}
- tc -n $ns2 qdisc add dev ns2eth$i clsact || return ${ksft_skip} + tc -n $ns2 qdisc add dev ns2eth$i clsact || return ${KSFT_SKIP} tc -n $ns2 filter add dev ns2eth$i egress \ protocol ip prio 1000 \ handle 42 fw \ action pedit munge offset 148 u8 invert \ pipe csum tcp \ - index 100 || return ${ksft_skip} + index 100 || return ${KSFT_SKIP} }
reset_with_fail() @@ -414,7 +413,7 @@ reset_with_fail() local rc=0 setup_fail_rules "${@}" || rc=$?
- if [ ${rc} -eq ${ksft_skip} ]; then + if [ ${rc} -eq ${KSFT_SKIP} ]; then mark_as_skipped "unable to set the 'fail' rules" return 1 fi @@ -450,7 +449,7 @@ reset_with_tcp_filter() # $1: err msg fail_test() { - ret=1 + ret=${KSFT_FAIL}
if [ ${#} -gt 0 ]; then print_fail "${@}" @@ -3632,7 +3631,7 @@ usage() { if [ -n "${1}" ]; then echo "${1}" - ret=1 + ret=${KSFT_FAIL} fi
echo "mptcp_join usage:" diff --git a/tools/testing/selftests/net/mptcp/mptcp_sockopt.sh b/tools/testing/selftests/net/mptcp/mptcp_sockopt.sh index 96aa8f71bbb0..e2d70c18786e 100755 --- a/tools/testing/selftests/net/mptcp/mptcp_sockopt.sh +++ b/tools/testing/selftests/net/mptcp/mptcp_sockopt.sh @@ -105,7 +105,7 @@ check_mark() if [ $v -ne 0 ]; then mptcp_lib_pr_fail "got $tables $values in ns $ns," \ "not 0 - not all expected packets marked" - ret=1 + ret=${KSFT_FAIL} return 1 fi done @@ -178,7 +178,7 @@ do_transfer()
mptcp_lib_result_fail "transfer ${ip}"
- ret=1 + ret=${KSFT_FAIL} return 1 fi if ! mptcp_lib_check_transfer $cin $sout "file received by server"; then diff --git a/tools/testing/selftests/net/mptcp/pm_netlink.sh b/tools/testing/selftests/net/mptcp/pm_netlink.sh index 69ffff8b076b..6ab8c5d36340 100755 --- a/tools/testing/selftests/net/mptcp/pm_netlink.sh +++ b/tools/testing/selftests/net/mptcp/pm_netlink.sh @@ -19,11 +19,11 @@ while getopts "$optstring" option;do case "$option" in "h") usage $0 - exit 0 + exit ${KSFT_PASS} ;; "?") usage $0 - exit 1 + exit ${KSFT_FAIL} ;; esac done @@ -57,13 +57,13 @@ check() mptcp_lib_check_output "${err}" "${cmd}" "${expected}" || rc=${?} if [ ${rc} -eq 2 ]; then mptcp_lib_result_fail "${msg} # error ${rc}" - ret=1 + ret=${KSFT_FAIL} elif [ ${rc} -eq 0 ]; then mptcp_lib_print_ok "[ OK ]" mptcp_lib_result_pass "${msg}" elif [ ${rc} -eq 1 ]; then mptcp_lib_result_fail "${msg} # different output" - ret=1 + ret=${KSFT_FAIL} fi }
diff --git a/tools/testing/selftests/net/mptcp/simult_flows.sh b/tools/testing/selftests/net/mptcp/simult_flows.sh index e62052c3206d..1b2366220388 100755 --- a/tools/testing/selftests/net/mptcp/simult_flows.sh +++ b/tools/testing/selftests/net/mptcp/simult_flows.sh @@ -263,7 +263,7 @@ while getopts "bcdh" option;do case "$option" in "h") usage $0 - exit 0 + exit ${KSFT_PASS} ;; "b") bail=1 @@ -276,7 +276,7 @@ while getopts "bcdh" option;do ;; "?") usage $0 - exit 1 + exit ${KSFT_FAIL} ;; esac done diff --git a/tools/testing/selftests/net/mptcp/userspace_pm.sh b/tools/testing/selftests/net/mptcp/userspace_pm.sh index 72dca742280f..9e2981f2d7f5 100755 --- a/tools/testing/selftests/net/mptcp/userspace_pm.sh +++ b/tools/testing/selftests/net/mptcp/userspace_pm.sh @@ -89,7 +89,7 @@ test_fail() then mptcp_lib_pr_fail "${@}" fi - ret=1 + ret=${KSFT_FAIL} mptcp_lib_result_fail "${test_name}" }
@@ -209,7 +209,7 @@ make_connection() else test_fail "Expected tokens (c:${client_token} - s:${server_token}) and server (c:${client_serverside} - s:${server_serverside})" mptcp_lib_result_print_all_tap - exit 1 + exit ${KSFT_FAIL} fi
if [ "$is_v6" = "v6" ]
Hello:
This series was applied to netdev/net-next.git (main) by Jakub Kicinski kuba@kernel.org:
On Fri, 08 Mar 2024 23:10:07 +0100 you wrote:
In this series from Geliang, there are various improvements in MPTCP selftests: sharing code, doing actions the same way, colours, etc.
Patch 1 prints all error messages to stdout: what was done in almost all other MPTCP selftests. This can be now easily changed later if needed.
Patch 2 makes sure the test counter is continuous in mptcp_connect.sh.
[...]
Here is the summary with links: - [net-next,01/15] selftests: mptcp: print all error messages to stdout https://git.kernel.org/netdev/net-next/c/6215df11b945 - [net-next,02/15] selftests: mptcp: connect: add dedicated port counter https://git.kernel.org/netdev/net-next/c/01ed9838107f - [net-next,03/15] selftests: mptcp: connect: fix misaligned output https://git.kernel.org/netdev/net-next/c/c9161a0f8ff9 - [net-next,04/15] selftests: mptcp: sockopt: print every test result https://git.kernel.org/netdev/net-next/c/fd959262c1bb - [net-next,05/15] selftests: mptcp: export TEST_COUNTER variable https://git.kernel.org/netdev/net-next/c/9e6a39ecb9a1 - [net-next,06/15] selftests: mptcp: add print_title in mptcp_lib https://git.kernel.org/netdev/net-next/c/3382bb09701b - [net-next,07/15] selftests: mptcp: print test results with counters https://git.kernel.org/netdev/net-next/c/aa7694766f14 - [net-next,08/15] selftests: mptcp: use += operator to append strings https://git.kernel.org/netdev/net-next/c/e7c42bf4d320 - [net-next,09/15] selftests: mptcp: print test results with colors https://git.kernel.org/netdev/net-next/c/747ba8783a33 - [net-next,10/15] selftests: mptcp: call test_fail without argument https://git.kernel.org/netdev/net-next/c/339c225e2e03 - [net-next,11/15] selftests: mptcp: extract mptcp_lib_check_expected https://git.kernel.org/netdev/net-next/c/663260e14668 - [net-next,12/15] selftests: mptcp: print_test out of verify_listener_events https://git.kernel.org/netdev/net-next/c/8ebb44196585 - [net-next,13/15] selftests: mptcp: add mptcp_lib_verify_listener_events https://git.kernel.org/netdev/net-next/c/7f0782ca1ce9 - [net-next,14/15] selftests: mptcp: declare event macros in mptcp_lib https://git.kernel.org/netdev/net-next/c/23a0485d1c04 - [net-next,15/15] selftests: mptcp: use KSFT_SKIP/KSFT_PASS/KSFT_FAIL https://git.kernel.org/netdev/net-next/c/8f7a69a8e7dc
You are awesome, thank you!
linux-kselftest-mirror@lists.linaro.org