Skip to content

Commit

Permalink
selftests: mptcp: print test results with colors
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
Geliang Tang authored and intel-lab-lkp committed Mar 6, 2024
1 parent 404f2b8 commit 90072e8
Show file tree
Hide file tree
Showing 8 changed files with 87 additions and 83 deletions.
12 changes: 6 additions & 6 deletions tools/testing/selftests/net/mptcp/diag.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
Expand Down
62 changes: 31 additions & 31 deletions tools/testing/selftests/net/mptcp/mptcp_connect.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -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
Expand All @@ -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
}
Expand All @@ -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
Expand Down Expand Up @@ -336,7 +336,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

Expand Down Expand Up @@ -433,7 +433,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
Expand Down Expand Up @@ -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
printf "[ Note ] fallback due to TCP OoO"
Expand All @@ -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
Expand Down Expand Up @@ -536,11 +536,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
Expand Down Expand Up @@ -670,7 +670,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
Expand All @@ -687,7 +687,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
Expand All @@ -703,7 +703,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
Expand All @@ -712,13 +712,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_base=20000
local extra_args="-o TRANSPARENT"
Expand All @@ -731,12 +731,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
}

Expand All @@ -745,7 +745,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}"
}
Expand All @@ -755,12 +755,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

Expand All @@ -772,7 +772,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()
Expand All @@ -783,7 +783,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
Expand All @@ -796,7 +796,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"

Expand All @@ -820,7 +820,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
Expand Down Expand Up @@ -867,7 +867,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 "
Expand All @@ -892,7 +892,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

Expand Down
6 changes: 3 additions & 3 deletions tools/testing/selftests/net/mptcp/mptcp_join.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 ]
Expand Down
32 changes: 25 additions & 7 deletions tools/testing/selftests/net/mptcp/mptcp_lib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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"

Expand Down Expand Up @@ -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

Expand Down
Loading

0 comments on commit 90072e8

Please sign in to comment.