Commit d9c822ff authored by Jakub Kicinski's avatar Jakub Kicinski

Merge branch 'selftests-mptcp-various-improvements'

Matthieu Baerts says:

====================
selftests: mptcp: various improvements

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.
====================

Link: https://lore.kernel.org/r/20240308-upstream-net-next-20240308-selftests-mptcp-unification-v1-0-4f42c347b653@kernel.orgSigned-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parents 0d1a7a8f 8f7a69a8
......@@ -9,7 +9,6 @@
. "$(dirname "${0}")/mptcp_lib.sh"
ns=""
test_cnt=1
timeout_poll=30
timeout_test=$((timeout_poll * 2 + 1))
ret=0
......@@ -55,21 +54,20 @@ __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"
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
test_cnt=$((test_cnt+1))
}
__chk_msk_nr()
......@@ -114,20 +112,19 @@ 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_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
test_cnt=$((test_cnt+1))
}
chk_msk_fallback_nr()
......
......@@ -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%
......@@ -64,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")
......@@ -95,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")
......@@ -103,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")
......@@ -120,7 +121,7 @@ while getopts "$optstring" option;do
;;
"?")
usage $0
exit 1
exit ${KSFT_FAIL}
;;
esac
done
......@@ -130,7 +131,6 @@ ns2=""
ns3=""
ns4=""
TEST_COUNT=0
TEST_GROUP=""
# This function is used in the cleanup trap
......@@ -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
}
......@@ -247,16 +247,23 @@ 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
MPTCP_LIB_TEST_FORMAT="%02u %-69s" \
mptcp_lib_print_title "${@}"
}
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 ]"
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
......@@ -267,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
ret=${KSFT_FAIL}
return 1
fi
echo -e "New MPTCP socket can be blocked via sysctl\t\t[ OK ]"
mptcp_lib_pr_ok
mptcp_lib_result_pass "New MPTCP socket can be blocked via sysctl"
return 0
}
......@@ -294,8 +301,8 @@ 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
ret=1
mptcp_lib_pr_fail "$listener_ns -> $connect_addr connectivity"
ret=${KSFT_FAIL}
return 1
fi
......@@ -313,24 +320,22 @@ do_transfer()
local local_addr="$6"
local extra_args="$7"
local port
port=$((10000+TEST_COUNT))
TEST_COUNT=$((TEST_COUNT+1))
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
echo "INFO: extra options: $extra_args"
mptcp_lib_pr_info "extra options: $extra_args"
fi
options_log=false
......@@ -342,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 "%s\t" "${result_msg}"
mptcp_lib_print_title "${result_msg}"
if $capture; then
local capuser
......@@ -427,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
......@@ -446,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
......@@ -469,17 +475,17 @@ 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}" 1>&2
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}" 1>&2
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"
extra+=" [ Note ] fallback due to TCP OoO"
fi
fi
......@@ -491,50 +497,52 @@ 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
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
mptcp_lib_pr_ok "${extra:1}"
mptcp_lib_result_pass "${TEST_GROUP}: ${result_msg}"
else
if [ -n "${extra}" ]; then
mptcp_lib_print_warn "${extra:1}"
fi
mptcp_lib_result_fail "${TEST_GROUP}: ${result_msg}"
fi
echo
cat "$capout"
[ $retc -eq 0 ] && [ $rets -eq 0 ]
}
......@@ -660,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
......@@ -677,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
......@@ -693,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
......@@ -702,15 +710,15 @@ 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"
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}"
......@@ -721,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" 1>&2
mptcp_lib_pr_fail "$msg, mptcp connection error"
ret=$lret
return 1
fi
echo "PASS: $msg"
mptcp_lib_pr_info "$msg pass"
return 0
}
......@@ -735,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}"
}
......@@ -745,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
......@@ -762,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()
......@@ -773,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
......@@ -786,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"
......@@ -810,10 +818,10 @@ log_if_error()
local msg="$1"
if [ ${ret} -ne 0 ]; then
echo "FAIL: ${msg}" 1>&2
mptcp_lib_pr_fail "${msg}"
final_ret=${ret}
ret=0
ret=${KSFT_PASS}
return ${final_ret}
fi
......@@ -835,7 +843,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,10 +865,11 @@ done
mptcp_lib_result_code "${ret}" "ping tests"
stop_if_error "Could not even run ping tests"
mptcp_lib_pr_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))
......@@ -871,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"
mptcp_lib_pr_info "Using ${tc_info}on ns3eth4"
tc -net "$ns3" qdisc add dev ns3eth4 root netem delay ${reorder_delay}ms $tc_reorder
......
......@@ -25,7 +25,6 @@ err=""
capout=""
ns1=""
ns2=""
ksft_skip=4
iptables="iptables"
ip6tables="ip6tables"
timeout_poll=30
......@@ -48,7 +47,7 @@ declare -A all_tests
declare -a only_tests_ids
declare -a only_tests_names
declare -A failed_tests
TEST_COUNT=0
MPTCP_LIB_TEST_FORMAT="%03u %s\n"
TEST_NAME=""
nr_blank=6
......@@ -170,11 +169,6 @@ cleanup()
cleanup_partial
}
print_title()
{
printf "%03u %s\n" "${TEST_COUNT}" "${TEST_NAME}"
}
print_check()
{
printf "%-${nr_blank}s%-36s" " " "${*}"
......@@ -190,17 +184,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 ]
......@@ -233,7 +227,7 @@ skip_test()
local i
for i in "${only_tests_ids[@]}"; do
if [ "${TEST_COUNT}" -eq "${i}" ]; then
if [ "$((MPTCP_LIB_TEST_COUNTER+1))" -eq "${i}" ]; then
return 1
fi
done
......@@ -268,14 +262,13 @@ reset()
TEST_NAME="${1}"
TEST_COUNT=$((TEST_COUNT+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
......@@ -398,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()
......@@ -420,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
......@@ -456,13 +449,15 @@ reset_with_tcp_filter()
# $1: err msg
fail_test()
{
ret=1
ret=${KSFT_FAIL}
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
failed_tests[${TEST_COUNT}]="${TEST_NAME}"
failed_tests[${MPTCP_LIB_TEST_COUNTER}]="${TEST_NAME}"
dump_stats
last_test_failed=1
fi
......@@ -760,18 +755,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
......@@ -973,7 +968,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 +986,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=$!
......@@ -1222,7 +1217,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
......@@ -1235,7 +1230,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
......@@ -1279,7 +1274,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
......@@ -1293,7 +1288,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
......@@ -1328,7 +1323,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
......@@ -1339,7 +1334,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
......@@ -1708,7 +1703,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
......@@ -2789,29 +2784,16 @@ 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 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
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"
......@@ -2824,23 +2806,11 @@ 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
fail_test "$e_type:$type $e_family:$family $e_saddr:$saddr $e_sport:$sport"
fail_test
}
add_addr_ports_tests()
......@@ -2878,8 +2848,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
......@@ -3485,11 +3457,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
......@@ -3516,7 +3488,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"
......@@ -3659,7 +3631,7 @@ usage()
{
if [ -n "${1}" ]; then
echo "${1}"
ret=1
ret=${KSFT_FAIL}
fi
echo "mptcp_join usage:"
......
......@@ -8,8 +8,21 @@ 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
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" ]; } &&
......@@ -48,6 +61,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.
......@@ -78,14 +108,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
}
......@@ -292,7 +322,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"
......@@ -332,13 +362,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
}
......@@ -350,29 +380,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
......@@ -410,3 +441,67 @@ 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))" "${*}"
}
# $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}"
}
# 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}"
}
......@@ -103,8 +103,9 @@ 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
ret=1
mptcp_lib_pr_fail "got $tables $values in ns $ns," \
"not 0 - not all expected packets marked"
ret=${KSFT_FAIL}
return 1
fi
done
......@@ -112,6 +113,11 @@ check_mark()
return 0
}
print_title()
{
mptcp_lib_print_title "${@}"
}
do_transfer()
{
local listener_ns="$1"
......@@ -161,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" 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"
......@@ -171,10 +178,17 @@ 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
rets=1
else
mptcp_lib_pr_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
......@@ -183,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
mptcp_lib_pr_ok
return 0
fi
mptcp_lib_pr_fail
return 1
}
......@@ -212,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
......@@ -220,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" 1>&2
mptcp_lib_pr_fail
mptcp_lib_result_fail "sockopt v4"
ret=$lret
return
fi
mptcp_lib_pr_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)" 1>&2
mptcp_lib_pr_fail
mptcp_lib_result_fail "sockopt v6"
ret=$lret
return
fi
mptcp_lib_pr_ok
mptcp_lib_result_pass "sockopt v6"
}
......@@ -259,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 $*" 1>&2
mptcp_lib_pr_fail
mptcp_lib_result_fail "TCP_INQ: $*"
return $lret
fi
echo "PASS: TCP_INQ cmsg/ioctl $*"
mptcp_lib_pr_ok
mptcp_lib_result_pass "TCP_INQ: $*"
return $lret
}
......@@ -278,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
......@@ -314,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
......
......@@ -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
......@@ -53,17 +53,17 @@ 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}"
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
}
......@@ -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}"
mptcp_lib_pr_skip
mptcp_lib_result_skip "${st}"
done
fi
......
......@@ -14,7 +14,8 @@ ns3=""
capture=false
timeout_poll=30
timeout_test=$((timeout_poll * 2 + 1))
test_cnt=1
# a bit more space: because we have more to display
MPTCP_LIB_TEST_FORMAT="%02u %-60s"
ret=0
bail=0
slack=50
......@@ -126,8 +127,7 @@ 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))
:> "$cout"
:> "$sout"
......@@ -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"
......@@ -239,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}"
......@@ -249,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}"
......@@ -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
......
......@@ -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"
......@@ -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=""
......@@ -54,14 +54,12 @@ ns1=""
ns2=""
ret=0
test_name=""
_printf() {
stdbuf -o0 -e0 printf "${@}"
}
# a bit more space: because we have more to display
MPTCP_LIB_TEST_FORMAT="%02u %-68s"
print_title()
{
_printf "INFO: %s\n" "${1}"
mptcp_lib_pr_info "${1}"
}
# $1: test name
......@@ -69,36 +67,29 @@ print_test()
{
test_name="${1}"
_printf "%-68s" "${test_name}"
}
print_results()
{
_printf "[%s]\n" "${1}"
mptcp_lib_print_title "${test_name}"
}
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"
ret=1
if [ -n "${1}" ]; then
_printf "\t%s\n" "${1}"
if [ ${#} -gt 0 ]
then
mptcp_lib_pr_fail "${@}"
fi
ret=${KSFT_FAIL}
mptcp_lib_result_fail "${test_name}"
}
......@@ -120,7 +111,7 @@ cleanup()
rm -rf $file $client_evts $server_evts
_printf "Done\n"
mptcp_lib_pr_info "Done"
}
trap cleanup EXIT
......@@ -218,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" ]
......@@ -237,45 +228,16 @@ 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
test_fail
fi
_printf "\tExpected value for '%s': '%s', got '%s'.\n" \
"${var}" "${!exp}" "${!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
fi
test_fail
return 1
}
......@@ -425,7 +387,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
......@@ -438,7 +400,7 @@ test_remove()
then
test_pass
else
test_fail
test_fail "unexpected type: ${type}"
fi
# RM_ADDR from the client to server machine
......@@ -873,32 +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
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)
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()
......@@ -920,6 +861,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
......@@ -936,6 +878,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
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment