From: Geliang Tang <tanggeliang@kylinos.cn>
The helper mptcp_lib_verify_listener_events() will be added latter in
mptcp_lib.sh, and be used by mptcp_join.sh and userspace_pm.sh. The
former prints colored output while the latter is not. It makes sense
to unify them.
This patch uses mptcp_lib_print_ok(), _warn(), _err() and _info() helpers
in scripts diag.sh, mptcp_connect.sh, mptcp_sockopt.sh, pm_netlink.sh,
simult_flows.sh and userspace_pm.sh to print test results with colors.
Having colors helps to quickly identify issues when looking at a long
list of output logs and results.
Signed-off-by: Geliang Tang <tanggeliang@kylinos.cn>
---
tools/testing/selftests/net/mptcp/diag.sh | 12 ++++----
.../selftests/net/mptcp/mptcp_connect.sh | 28 ++++++++++---------
.../selftests/net/mptcp/mptcp_sockopt.sh | 16 +++++------
.../testing/selftests/net/mptcp/pm_netlink.sh | 3 +-
.../selftests/net/mptcp/simult_flows.sh | 4 +--
.../selftests/net/mptcp/userspace_pm.sh | 13 +++------
6 files changed, 37 insertions(+), 39 deletions(-)
diff --git a/tools/testing/selftests/net/mptcp/diag.sh b/tools/testing/selftests/net/mptcp/diag.sh
index aa3fb808fc6d..f9f62a8f41e3 100755
--- a/tools/testing/selftests/net/mptcp/diag.sh
+++ b/tools/testing/selftests/net/mptcp/diag.sh
@@ -58,15 +58,15 @@ __chk_nr()
printf "%-50s" "$msg"
if [ "$nr" != "$expected" ]; then
if [ "$nr" = "$skip" ] && ! mptcp_lib_expect_all_features; then
- echo "[SKIP] Feature probably not supported"
+ mptcp_lib_print_warn "[SKIP] Feature probably not supported"
mptcp_lib_result_skip "${msg}"
else
- echo "[FAIL] expected $expected found $nr"
+ mptcp_lib_print_err "[FAIL] expected $expected found $nr"
mptcp_lib_result_fail "${msg}"
ret=$test_cnt
fi
else
- echo "[ OK ]"
+ mptcp_lib_print_ok "[ OK ]"
mptcp_lib_result_pass "${msg}"
fi
test_cnt=$((test_cnt+1))
@@ -116,15 +116,15 @@ wait_msk_nr()
printf "%-50s" "$msg"
if [ $i -ge $timeout ]; then
- echo "[FAIL] timeout while expecting $expected max $max last $nr"
+ mptcp_lib_print_err "[FAIL] timeout while expecting $expected max $max last $nr"
mptcp_lib_result_fail "${msg} # timeout"
ret=$test_cnt
elif [ $nr != $expected ]; then
- echo "[FAIL] expected $expected found $nr"
+ mptcp_lib_print_err "[FAIL] expected $expected found $nr"
mptcp_lib_result_fail "${msg} # unexpected result"
ret=$test_cnt
else
- echo "[ OK ]"
+ mptcp_lib_print_ok "[ OK ]"
mptcp_lib_result_pass "${msg}"
fi
test_cnt=$((test_cnt+1))
diff --git a/tools/testing/selftests/net/mptcp/mptcp_connect.sh b/tools/testing/selftests/net/mptcp/mptcp_connect.sh
index 72be905bab1f..c7483902026b 100755
--- a/tools/testing/selftests/net/mptcp/mptcp_connect.sh
+++ b/tools/testing/selftests/net/mptcp/mptcp_connect.sh
@@ -254,7 +254,8 @@ check_mptcp_disabled()
# 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\t [FAIL]"
+ echo -n -e "net.mptcp.enabled sysctl is not 1 by default"
+ mptcp_lib_print_err "\t\t\t [FAIL]"
mptcp_lib_result_fail "net.mptcp.enabled sysctl is not 1 by default"
ret=1
return 1
@@ -267,13 +268,15 @@ 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\t [FAIL]"
+ echo -n -e "New MPTCP socket cannot be blocked via sysctl"
+ mptcp_lib_print_err "\t\t\t [FAIL]"
mptcp_lib_result_fail "New MPTCP socket cannot be blocked via sysctl"
ret=1
return 1
fi
- echo -e "New MPTCP socket can be blocked via sysctl\t\t\t [ OK ]"
+ echo -n -e "New MPTCP socket can be blocked via sysctl"
+ mptcp_lib_print_ok "\t\t\t [ OK ]"
mptcp_lib_result_pass "New MPTCP socket can be blocked via sysctl"
return 0
}
@@ -503,7 +506,7 @@ do_transfer()
fi
if [ $retc -eq 0 ] && [ $rets -eq 0 ]; then
- printf "[ OK ]"
+ mptcp_lib_print_ok "[ OK ]"
mptcp_lib_result_pass "${TEST_GROUP}: ${result_msg}"
else
mptcp_lib_result_fail "${TEST_GROUP}: ${result_msg}"
@@ -534,7 +537,6 @@ do_transfer()
"${expect_ackrx}" "${stat_ackrx_now_l}"
fi
- echo
cat "$capout"
[ $retc -eq 0 ] && [ $rets -eq 0 ]
}
@@ -708,7 +710,7 @@ EOF
return
fi
- echo "INFO: test $msg"
+ mptcp_lib_print_info "INFO: test $msg"
TEST_COUNT=10000
local extra_args="-o TRANSPARENT"
@@ -721,12 +723,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" 1>&2
+ mptcp_lib_print_err "FAIL: $msg, mptcp connection error" 1>&2
ret=$lret
return 1
fi
- echo "PASS: $msg"
+ mptcp_lib_print_ok "PASS: $msg"
return 0
}
@@ -735,7 +737,7 @@ run_tests_peekmode()
local peekmode="$1"
TEST_GROUP="peek mode: ${peekmode}"
- echo "INFO: with peek mode: ${peekmode}"
+ mptcp_lib_print_info "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}"
}
@@ -750,7 +752,7 @@ run_tests_mptfo()
return
fi
- echo "INFO: with MPTFO start"
+ mptcp_lib_print_info "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
@@ -762,7 +764,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_print_info "INFO: with MPTFO end"
}
run_tests_disconnect()
@@ -786,7 +788,7 @@ run_tests_disconnect()
cin_disconnect="$old_cin"
connect_per_transfer=3
- echo "INFO: disconnect"
+ mptcp_lib_print_info "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"
@@ -835,7 +837,7 @@ check_mptcp_disabled
stop_if_error "The kernel configuration is not valid for MPTCP"
-echo "INFO: validating network environment with pings"
+mptcp_lib_print_info "INFO: 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
diff --git a/tools/testing/selftests/net/mptcp/mptcp_sockopt.sh b/tools/testing/selftests/net/mptcp/mptcp_sockopt.sh
index f84185b5dc9f..cfa0cfb918f4 100755
--- a/tools/testing/selftests/net/mptcp/mptcp_sockopt.sh
+++ b/tools/testing/selftests/net/mptcp/mptcp_sockopt.sh
@@ -218,7 +218,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_print_warn "INFO: MPTCP sockopt not supported: SKIP"
mptcp_lib_result_skip "sockopt"
return
fi
@@ -228,7 +228,7 @@ do_mptcp_sockopt_tests()
printf "%-50s" "sockopt v4"
if [ $lret -ne 0 ]; then
- echo "FAIL: SOL_MPTCP getsockopt" 1>&2
+ mptcp_lib_print_err "FAIL: SOL_MPTCP getsockopt"
mptcp_lib_result_fail "sockopt v4"
ret=$lret
return
@@ -241,7 +241,7 @@ do_mptcp_sockopt_tests()
printf "%-50s" "sockopt v6"
if [ $lret -ne 0 ]; then
- echo "FAIL: SOL_MPTCP getsockopt (ipv6)" 1>&2
+ mptcp_lib_print_err "FAIL: SOL_MPTCP getsockopt (ipv6)"
mptcp_lib_result_fail "sockopt v6"
ret=$lret
return
@@ -274,13 +274,13 @@ do_tcpinq_test()
local lret=$?
if [ $lret -ne 0 ];then
ret=$lret
- echo "FAIL: mptcp_inq $*" 1>&2
+ mptcp_lib_print_err "FAIL: mptcp_inq $*" 1>&2
mptcp_lib_result_fail "TCP_INQ: $*"
return $lret
fi
mptcp_lib_print_ok "[ OK ]"
- echo "PASS: TCP_INQ cmsg/ioctl $*"
+ mptcp_lib_print_info "PASS: TCP_INQ cmsg/ioctl $*"
mptcp_lib_result_pass "TCP_INQ: $*"
return $lret
}
@@ -290,7 +290,7 @@ do_tcpinq_tests()
local lret=0
if ! mptcp_lib_kallsyms_has "mptcp_ioctl$"; then
- echo "INFO: TCP_INQ not supported: SKIP"
+ mptcp_lib_print_warn "INFO: TCP_INQ not supported: SKIP"
mptcp_lib_result_skip "TCP_INQ"
return
fi
@@ -327,12 +327,12 @@ 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"
+ mptcp_lib_print_info "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"
+ mptcp_lib_print_info "PASS: SOL_MPTCP getsockopt has expected information"
fi
do_tcpinq_tests
diff --git a/tools/testing/selftests/net/mptcp/pm_netlink.sh b/tools/testing/selftests/net/mptcp/pm_netlink.sh
index 427fc5c70b3c..68fad278ac59 100755
--- a/tools/testing/selftests/net/mptcp/pm_netlink.sh
+++ b/tools/testing/selftests/net/mptcp/pm_netlink.sh
@@ -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]"
+ printf "%-50s" "${st}"
+ mptcp_lib_print_warn "[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 58cfdaf1db25..79cb377ee0bd 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_print_ok "[ OK ]"
cat "$capout"
return 0
fi
- echo " [FAIL]"
+ mptcp_lib_print_err " [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 b0cce8f065d8..33bbb0d5807f 100755
--- a/tools/testing/selftests/net/mptcp/userspace_pm.sh
+++ b/tools/testing/selftests/net/mptcp/userspace_pm.sh
@@ -61,7 +61,7 @@ _printf() {
print_title()
{
- _printf "INFO: %s\n" "${1}"
+ mptcp_lib_print_info "INFO: ${1}"
}
# $1: test name
@@ -72,27 +72,22 @@ print_test()
_printf "%-68s" "${test_name}"
}
-print_results()
-{
- _printf "[%s]\n" "${1}"
-}
-
test_pass()
{
- print_results " OK "
+ mptcp_lib_print_ok "[ OK ]"
mptcp_lib_result_pass "${test_name}"
}
test_skip()
{
- print_results "SKIP"
+ mptcp_lib_print_warn "[SKIP]"
mptcp_lib_result_skip "${test_name}"
}
# $1: msg
test_fail()
{
- print_results "FAIL"
+ mptcp_lib_print_err "[FAIL]${1:+ ${*}}"
ret=1
if [ -n "${1}" ]; then
--
2.40.1