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 @@ ...@@ -9,7 +9,6 @@
. "$(dirname "${0}")/mptcp_lib.sh" . "$(dirname "${0}")/mptcp_lib.sh"
ns="" ns=""
test_cnt=1
timeout_poll=30 timeout_poll=30
timeout_test=$((timeout_poll * 2 + 1)) timeout_test=$((timeout_poll * 2 + 1))
ret=0 ret=0
...@@ -55,21 +54,20 @@ __chk_nr() ...@@ -55,21 +54,20 @@ __chk_nr()
nr=$(eval $command) nr=$(eval $command)
printf "%-50s" "$msg" mptcp_lib_print_title "$msg"
if [ "$nr" != "$expected" ]; then if [ "$nr" != "$expected" ]; then
if [ "$nr" = "$skip" ] && ! mptcp_lib_expect_all_features; 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}" mptcp_lib_result_skip "${msg}"
else else
echo "[ fail ] expected $expected found $nr" mptcp_lib_pr_fail "expected $expected found $nr"
mptcp_lib_result_fail "${msg}" mptcp_lib_result_fail "${msg}"
ret=${KSFT_FAIL} ret=${KSFT_FAIL}
fi fi
else else
echo "[ ok ]" mptcp_lib_pr_ok
mptcp_lib_result_pass "${msg}" mptcp_lib_result_pass "${msg}"
fi fi
test_cnt=$((test_cnt+1))
} }
__chk_msk_nr() __chk_msk_nr()
...@@ -114,20 +112,19 @@ wait_msk_nr() ...@@ -114,20 +112,19 @@ wait_msk_nr()
sleep 1 sleep 1
done done
printf "%-50s" "$msg" mptcp_lib_print_title "$msg"
if [ $i -ge $timeout ]; then 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" mptcp_lib_result_fail "${msg} # timeout"
ret=${KSFT_FAIL} ret=${KSFT_FAIL}
elif [ $nr != $expected ]; then 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" mptcp_lib_result_fail "${msg} # unexpected result"
ret=${KSFT_FAIL} ret=${KSFT_FAIL}
else else
echo "[ ok ]" mptcp_lib_pr_ok
mptcp_lib_result_pass "${msg}" mptcp_lib_result_pass "${msg}"
fi fi
test_cnt=$((test_cnt+1))
} }
chk_msk_fallback_nr() chk_msk_fallback_nr()
......
...@@ -25,7 +25,6 @@ err="" ...@@ -25,7 +25,6 @@ err=""
capout="" capout=""
ns1="" ns1=""
ns2="" ns2=""
ksft_skip=4
iptables="iptables" iptables="iptables"
ip6tables="ip6tables" ip6tables="ip6tables"
timeout_poll=30 timeout_poll=30
...@@ -48,7 +47,7 @@ declare -A all_tests ...@@ -48,7 +47,7 @@ declare -A all_tests
declare -a only_tests_ids declare -a only_tests_ids
declare -a only_tests_names declare -a only_tests_names
declare -A failed_tests declare -A failed_tests
TEST_COUNT=0 MPTCP_LIB_TEST_FORMAT="%03u %s\n"
TEST_NAME="" TEST_NAME=""
nr_blank=6 nr_blank=6
...@@ -170,11 +169,6 @@ cleanup() ...@@ -170,11 +169,6 @@ cleanup()
cleanup_partial cleanup_partial
} }
print_title()
{
printf "%03u %s\n" "${TEST_COUNT}" "${TEST_NAME}"
}
print_check() print_check()
{ {
printf "%-${nr_blank}s%-36s" " " "${*}" printf "%-${nr_blank}s%-36s" " " "${*}"
...@@ -190,17 +184,17 @@ print_info() ...@@ -190,17 +184,17 @@ print_info()
print_ok() print_ok()
{ {
mptcp_lib_print_ok "[ ok ]${1:+ ${*}}" mptcp_lib_pr_ok "${@}"
} }
print_fail() print_fail()
{ {
mptcp_lib_print_err "[fail]${1:+ ${*}}" mptcp_lib_pr_fail "${@}"
} }
print_skip() print_skip()
{ {
mptcp_lib_print_warn "[skip]${1:+ ${*}}" mptcp_lib_pr_skip "${@}"
} }
# [ $1: fail msg ] # [ $1: fail msg ]
...@@ -233,7 +227,7 @@ skip_test() ...@@ -233,7 +227,7 @@ skip_test()
local i local i
for i in "${only_tests_ids[@]}"; do for i in "${only_tests_ids[@]}"; do
if [ "${TEST_COUNT}" -eq "${i}" ]; then if [ "$((MPTCP_LIB_TEST_COUNTER+1))" -eq "${i}" ]; then
return 1 return 1
fi fi
done done
...@@ -268,14 +262,13 @@ reset() ...@@ -268,14 +262,13 @@ reset()
TEST_NAME="${1}" TEST_NAME="${1}"
TEST_COUNT=$((TEST_COUNT+1))
if skip_test; then if skip_test; then
MPTCP_LIB_TEST_COUNTER=$((MPTCP_LIB_TEST_COUNTER+1))
last_test_ignored=1 last_test_ignored=1
return 1 return 1
fi fi
print_title mptcp_lib_print_title "${TEST_NAME}"
if [ "${init}" != "1" ]; then if [ "${init}" != "1" ]; then
init init
...@@ -398,15 +391,15 @@ setup_fail_rules() ...@@ -398,15 +391,15 @@ setup_fail_rules()
-p tcp \ -p tcp \
-m length --length 150:9999 \ -m length --length 150:9999 \
-m statistic --mode nth --packet 1 --every 99999 \ -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 \ tc -n $ns2 filter add dev ns2eth$i egress \
protocol ip prio 1000 \ protocol ip prio 1000 \
handle 42 fw \ handle 42 fw \
action pedit munge offset 148 u8 invert \ action pedit munge offset 148 u8 invert \
pipe csum tcp \ pipe csum tcp \
index 100 || return ${ksft_skip} index 100 || return ${KSFT_SKIP}
} }
reset_with_fail() reset_with_fail()
...@@ -420,7 +413,7 @@ reset_with_fail() ...@@ -420,7 +413,7 @@ reset_with_fail()
local rc=0 local rc=0
setup_fail_rules "${@}" || rc=$? 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" mark_as_skipped "unable to set the 'fail' rules"
return 1 return 1
fi fi
...@@ -456,13 +449,15 @@ reset_with_tcp_filter() ...@@ -456,13 +449,15 @@ reset_with_tcp_filter()
# $1: err msg # $1: err msg
fail_test() 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 # just in case a test is marked twice as failed
if [ ${last_test_failed} -eq 0 ]; then if [ ${last_test_failed} -eq 0 ]; then
failed_tests[${TEST_COUNT}]="${TEST_NAME}" failed_tests[${MPTCP_LIB_TEST_COUNTER}]="${TEST_NAME}"
dump_stats dump_stats
last_test_failed=1 last_test_failed=1
fi fi
...@@ -760,18 +755,18 @@ pm_nl_check_endpoint() ...@@ -760,18 +755,18 @@ pm_nl_check_endpoint()
line="${line% }" line="${line% }"
# the dump order is: address id flags port dev # the dump order is: address id flags port dev
[ -n "$addr" ] && expected_line="$addr" [ -n "$addr" ] && expected_line="$addr"
expected_line="$expected_line $id" expected_line+=" $id"
[ -n "$_flags" ] && expected_line="$expected_line ${_flags//","/" "}" [ -n "$_flags" ] && expected_line+=" ${_flags//","/" "}"
[ -n "$dev" ] && expected_line="$expected_line $dev" [ -n "$dev" ] && expected_line+=" $dev"
[ -n "$port" ] && expected_line="$expected_line $port" [ -n "$port" ] && expected_line+=" $port"
else else
line=$(ip netns exec $ns ./pm_nl_ctl get $_id) line=$(ip netns exec $ns ./pm_nl_ctl get $_id)
# the dump order is: id flags dev address port # the dump order is: id flags dev address port
expected_line="$id" expected_line="$id"
[ -n "$flags" ] && expected_line="$expected_line $flags" [ -n "$flags" ] && expected_line+=" $flags"
[ -n "$dev" ] && expected_line="$expected_line $dev" [ -n "$dev" ] && expected_line+=" $dev"
[ -n "$addr" ] && expected_line="$expected_line $addr" [ -n "$addr" ] && expected_line+=" $addr"
[ -n "$_port" ] && expected_line="$expected_line $_port" [ -n "$_port" ] && expected_line+=" $_port"
fi fi
if [ "$line" = "$expected_line" ]; then if [ "$line" = "$expected_line" ]; then
print_ok print_ok
...@@ -973,7 +968,7 @@ do_transfer() ...@@ -973,7 +968,7 @@ do_transfer()
local srv_proto="$4" local srv_proto="$4"
local connect_addr="$5" local connect_addr="$5"
local port=$((10000 + TEST_COUNT - 1)) local port=$((10000 + MPTCP_LIB_TEST_COUNTER - 1))
local cappid local cappid
local FAILING_LINKS=${FAILING_LINKS:-""} local FAILING_LINKS=${FAILING_LINKS:-""}
local fastclose=${fastclose:-""} local fastclose=${fastclose:-""}
...@@ -991,9 +986,9 @@ do_transfer() ...@@ -991,9 +986,9 @@ do_transfer()
capuser="-Z $SUDO_USER" capuser="-Z $SUDO_USER"
fi 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 & ip netns exec ${listener_ns} tcpdump -i any -s 65535 -B 32768 $capuser -w $capfile > "$capout" 2>&1 &
cappid=$! cappid=$!
...@@ -1222,7 +1217,7 @@ chk_csum_nr() ...@@ -1222,7 +1217,7 @@ chk_csum_nr()
print_check "sum" print_check "sum"
count=$(mptcp_lib_get_counter ${ns1} "MPTcpExtDataCsumErr") count=$(mptcp_lib_get_counter ${ns1} "MPTcpExtDataCsumErr")
if [ "$count" != "$csum_ns1" ]; then if [ "$count" != "$csum_ns1" ]; then
extra_msg="$extra_msg ns1=$count" extra_msg+=" ns1=$count"
fi fi
if [ -z "$count" ]; then if [ -z "$count" ]; then
print_skip print_skip
...@@ -1235,7 +1230,7 @@ chk_csum_nr() ...@@ -1235,7 +1230,7 @@ chk_csum_nr()
print_check "csum" print_check "csum"
count=$(mptcp_lib_get_counter ${ns2} "MPTcpExtDataCsumErr") count=$(mptcp_lib_get_counter ${ns2} "MPTcpExtDataCsumErr")
if [ "$count" != "$csum_ns2" ]; then if [ "$count" != "$csum_ns2" ]; then
extra_msg="$extra_msg ns2=$count" extra_msg+=" ns2=$count"
fi fi
if [ -z "$count" ]; then if [ -z "$count" ]; then
print_skip print_skip
...@@ -1279,7 +1274,7 @@ chk_fail_nr() ...@@ -1279,7 +1274,7 @@ chk_fail_nr()
print_check "ftx" print_check "ftx"
count=$(mptcp_lib_get_counter ${ns_tx} "MPTcpExtMPFailTx") count=$(mptcp_lib_get_counter ${ns_tx} "MPTcpExtMPFailTx")
if [ "$count" != "$fail_tx" ]; then if [ "$count" != "$fail_tx" ]; then
extra_msg="$extra_msg,tx=$count" extra_msg+=",tx=$count"
fi fi
if [ -z "$count" ]; then if [ -z "$count" ]; then
print_skip print_skip
...@@ -1293,7 +1288,7 @@ chk_fail_nr() ...@@ -1293,7 +1288,7 @@ chk_fail_nr()
print_check "failrx" print_check "failrx"
count=$(mptcp_lib_get_counter ${ns_rx} "MPTcpExtMPFailRx") count=$(mptcp_lib_get_counter ${ns_rx} "MPTcpExtMPFailRx")
if [ "$count" != "$fail_rx" ]; then if [ "$count" != "$fail_rx" ]; then
extra_msg="$extra_msg,rx=$count" extra_msg+=",rx=$count"
fi fi
if [ -z "$count" ]; then if [ -z "$count" ]; then
print_skip print_skip
...@@ -1328,7 +1323,7 @@ chk_fclose_nr() ...@@ -1328,7 +1323,7 @@ chk_fclose_nr()
if [ -z "$count" ]; then if [ -z "$count" ]; then
print_skip print_skip
elif [ "$count" != "$fclose_tx" ]; then 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" fail_test "got $count MP_FASTCLOSE[s] TX expected $fclose_tx"
else else
print_ok print_ok
...@@ -1339,7 +1334,7 @@ chk_fclose_nr() ...@@ -1339,7 +1334,7 @@ chk_fclose_nr()
if [ -z "$count" ]; then if [ -z "$count" ]; then
print_skip print_skip
elif [ "$count" != "$fclose_rx" ]; then 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" fail_test "got $count MP_FASTCLOSE[s] RX expected $fclose_rx"
else else
print_ok print_ok
...@@ -1708,7 +1703,7 @@ chk_rm_nr() ...@@ -1708,7 +1703,7 @@ chk_rm_nr()
count=$((count + cnt)) count=$((count + cnt))
if [ "$count" != "$rm_subflow_nr" ]; then if [ "$count" != "$rm_subflow_nr" ]; then
suffix="$count in [$rm_subflow_nr:$((rm_subflow_nr*2))]" suffix="$count in [$rm_subflow_nr:$((rm_subflow_nr*2))]"
extra_msg="$extra_msg simult" extra_msg+=" simult"
fi fi
if [ $count -ge "$rm_subflow_nr" ] && \ if [ $count -ge "$rm_subflow_nr" ] && \
[ "$count" -le "$((rm_subflow_nr *2 ))" ]; then [ "$count" -le "$((rm_subflow_nr *2 ))" ]; then
...@@ -2789,29 +2784,16 @@ backup_tests() ...@@ -2789,29 +2784,16 @@ backup_tests()
fi 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() verify_listener_events()
{ {
local evt=$1
local e_type=$2 local e_type=$2
local e_family=$3
local e_saddr=$4 local e_saddr=$4
local e_sport=$5 local e_sport=$5
local type
local family
local saddr
local sport
local name local name
if [ $e_type = $LISTENER_CREATED ]; then if [ $e_type = $MPTCP_LIB_EVENT_LISTENER_CREATED ]; then
name="LISTENER_CREATED" name="LISTENER_CREATED"
elif [ $e_type = $LISTENER_CLOSED ]; then elif [ $e_type = $MPTCP_LIB_EVENT_LISTENER_CLOSED ]; then
name="LISTENER_CLOSED " name="LISTENER_CLOSED "
else else
name="$e_type" name="$e_type"
...@@ -2824,23 +2806,11 @@ verify_listener_events() ...@@ -2824,23 +2806,11 @@ verify_listener_events()
return return
fi fi
type=$(mptcp_lib_evts_get_info type "$evt" "$e_type") if mptcp_lib_verify_listener_events "${@}"; then
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
print_ok print_ok
return 0 return 0
fi fi
fail_test "$e_type:$type $e_family:$family $e_saddr:$saddr $e_sport:$sport" fail_test
} }
add_addr_ports_tests() add_addr_ports_tests()
...@@ -2878,8 +2848,10 @@ add_addr_ports_tests() ...@@ -2878,8 +2848,10 @@ add_addr_ports_tests()
chk_add_nr 1 1 1 chk_add_nr 1 1 1
chk_rm_nr 1 1 invert 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 $MPTCP_LIB_EVENT_LISTENER_CREATED \
verify_listener_events $evts_ns1 $LISTENER_CLOSED $AF_INET 10.0.2.1 10100 $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 kill_events_pids
fi fi
...@@ -3485,11 +3457,11 @@ userspace_tests() ...@@ -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}" "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_chk_get_addr "${ns1}" "20" "id 20 flags signal 10.0.3.1"
userspace_pm_rm_addr $ns1 10 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}" \ userspace_pm_chk_dump_addr "${ns1}" \
"id 20 flags signal 10.0.3.1" "after rm_addr 10" "id 20 flags signal 10.0.3.1" "after rm_addr 10"
userspace_pm_rm_addr $ns1 20 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" userspace_pm_chk_dump_addr "${ns1}" "" "after rm_addr 20"
chk_rm_nr 2 2 invert chk_rm_nr 2 2 invert
chk_mptcp_info subflows 0 subflows 0 chk_mptcp_info subflows 0 subflows 0
...@@ -3516,7 +3488,7 @@ userspace_tests() ...@@ -3516,7 +3488,7 @@ userspace_tests()
"subflow" "subflow"
userspace_pm_chk_get_addr "${ns2}" "20" "id 20 flags subflow 10.0.3.2" userspace_pm_chk_get_addr "${ns2}" "20" "id 20 flags subflow 10.0.3.2"
userspace_pm_rm_addr $ns2 20 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}" \ userspace_pm_chk_dump_addr "${ns2}" \
"" \ "" \
"after rm_addr 20" "after rm_addr 20"
...@@ -3659,7 +3631,7 @@ usage() ...@@ -3659,7 +3631,7 @@ usage()
{ {
if [ -n "${1}" ]; then if [ -n "${1}" ]; then
echo "${1}" echo "${1}"
ret=1 ret=${KSFT_FAIL}
fi fi
echo "mptcp_join usage:" echo "mptcp_join usage:"
......
...@@ -8,8 +8,21 @@ readonly KSFT_SKIP=4 ...@@ -8,8 +8,21 @@ readonly KSFT_SKIP=4
# shellcheck disable=SC2155 # declare and assign separately # shellcheck disable=SC2155 # declare and assign separately
readonly KSFT_TEST="${MPTCP_LIB_KSFT_TEST:-$(basename "${0}" .sh)}" 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=()
MPTCP_LIB_SUBTESTS_DUPLICATED=0 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 # only if supported (or forced) and not disabled, see no-color.org
if { [ -t 1 ] || [ "${SELFTESTS_MPTCP_LIB_COLOR_FORCE:-}" = "1" ]; } && if { [ -t 1 ] || [ "${SELFTESTS_MPTCP_LIB_COLOR_FORCE:-}" = "1" ]; } &&
...@@ -48,6 +61,23 @@ mptcp_lib_print_err() { ...@@ -48,6 +61,23 @@ mptcp_lib_print_err() {
mptcp_lib_print_color "${MPTCP_LIB_COLOR_RED}${*}" 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 # 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 # features using the last version of the kernel and the selftests to make sure
# a test is not being skipped by mistake. # a test is not being skipped by mistake.
...@@ -78,14 +108,14 @@ mptcp_lib_has_file() { ...@@ -78,14 +108,14 @@ mptcp_lib_has_file() {
mptcp_lib_check_mptcp() { mptcp_lib_check_mptcp() {
if ! mptcp_lib_has_file "/proc/sys/net/mptcp/enabled"; then 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} exit ${KSFT_SKIP}
fi fi
} }
mptcp_lib_check_kallsyms() { mptcp_lib_check_kallsyms() {
if ! mptcp_lib_has_file "/proc/kallsyms"; then 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} exit ${KSFT_SKIP}
fi fi
} }
...@@ -292,7 +322,7 @@ mptcp_lib_check_transfer() { ...@@ -292,7 +322,7 @@ mptcp_lib_check_transfer() {
local what="${3}" local what="${3}"
if ! cmp "$in" "$out" > /dev/null 2>&1; then 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 "$in"
mptcp_lib_print_file_err "$out" mptcp_lib_print_file_err "$out"
...@@ -332,13 +362,13 @@ mptcp_lib_check_output() { ...@@ -332,13 +362,13 @@ mptcp_lib_check_output() {
fi fi
if [ ${cmd_ret} -ne 0 ]; then 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}" cat "${err}"
return 2 return 2
elif [ "${out}" = "${expected}" ]; then elif [ "${out}" = "${expected}" ]; then
return 0 return 0
else else
mptcp_lib_print_err "[FAIL] expected '${expected}' got '${out}'" mptcp_lib_pr_fail "expected '${expected}' got '${out}'"
return 1 return 1
fi fi
} }
...@@ -350,29 +380,30 @@ mptcp_lib_check_tools() { ...@@ -350,29 +380,30 @@ mptcp_lib_check_tools() {
case "${tool}" in case "${tool}" in
"ip") "ip")
if ! ip -Version &> /dev/null; then 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} exit ${KSFT_SKIP}
fi fi
;; ;;
"ss") "ss")
if ! ss -h | grep -q MPTCP; then 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} exit ${KSFT_SKIP}
fi fi
;; ;;
"iptables"* | "ip6tables"*) "iptables"* | "ip6tables"*)
if ! "${tool}" -V &> /dev/null; then 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} exit ${KSFT_SKIP}
fi fi
;; ;;
*) *)
mptcp_lib_print_err "Internal error: unsupported tool: ${tool}" mptcp_lib_pr_fail "Internal error: unsupported tool: ${tool}"
exit ${KSFT_FAIL} exit ${KSFT_FAIL}
;; ;;
esac esac
done done
} }
mptcp_lib_ns_init() { mptcp_lib_ns_init() {
local sec rndh local sec rndh
...@@ -410,3 +441,67 @@ mptcp_lib_events() { ...@@ -410,3 +441,67 @@ mptcp_lib_events() {
ip netns exec "${ns}" ./pm_nl_ctl events >> "${evts}" 2>&1 & ip netns exec "${ns}" ./pm_nl_ctl events >> "${evts}" 2>&1 &
pid=$! 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() ...@@ -103,8 +103,9 @@ check_mark()
local v local v
for v in $values; do for v in $values; do
if [ $v -ne 0 ]; then if [ $v -ne 0 ]; then
echo "FAIL: got $tables $values in ns $ns , not 0 - not all expected packets marked" 1>&2 mptcp_lib_pr_fail "got $tables $values in ns $ns," \
ret=1 "not 0 - not all expected packets marked"
ret=${KSFT_FAIL}
return 1 return 1
fi fi
done done
...@@ -112,6 +113,11 @@ check_mark() ...@@ -112,6 +113,11 @@ check_mark()
return 0 return 0
} }
print_title()
{
mptcp_lib_print_title "${@}"
}
do_transfer() do_transfer()
{ {
local listener_ns="$1" local listener_ns="$1"
...@@ -161,8 +167,9 @@ do_transfer() ...@@ -161,8 +167,9 @@ do_transfer()
wait $spid wait $spid
local rets=$? local rets=$?
print_title "Transfer ${ip:2}"
if [ ${rets} -ne 0 ] || [ ${retc} -ne 0 ]; then 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 echo -e "\nnetns ${listener_ns} socket stat for ${port}:" 1>&2
ip netns exec ${listener_ns} ss -Menita 1>&2 -o "sport = :$port" ip netns exec ${listener_ns} ss -Menita 1>&2 -o "sport = :$port"
...@@ -171,10 +178,17 @@ do_transfer() ...@@ -171,10 +178,17 @@ do_transfer()
mptcp_lib_result_fail "transfer ${ip}" mptcp_lib_result_fail "transfer ${ip}"
ret=1 ret=${KSFT_FAIL}
return 1 return 1
fi 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 if [ $local_addr = "::" ];then
check_mark $listener_ns 6 || retc=1 check_mark $listener_ns 6 || retc=1
check_mark $connector_ns 6 || retc=1 check_mark $connector_ns 6 || retc=1
...@@ -183,15 +197,13 @@ do_transfer() ...@@ -183,15 +197,13 @@ do_transfer()
check_mark $connector_ns 4 || retc=1 check_mark $connector_ns 4 || retc=1
fi fi
mptcp_lib_check_transfer $cin $sout "file received by server"
rets=$?
mptcp_lib_result_code "${retc}" "mark ${ip}" mptcp_lib_result_code "${retc}" "mark ${ip}"
mptcp_lib_result_code "${rets}" "transfer ${ip}"
if [ $retc -eq 0 ] && [ $rets -eq 0 ];then if [ $retc -eq 0 ] && [ $rets -eq 0 ];then
mptcp_lib_pr_ok
return 0 return 0
fi fi
mptcp_lib_pr_fail
return 1 return 1
} }
...@@ -212,7 +224,7 @@ do_mptcp_sockopt_tests() ...@@ -212,7 +224,7 @@ do_mptcp_sockopt_tests()
local lret=0 local lret=0
if ! mptcp_lib_kallsyms_has "mptcp_diag_fill_info$"; then 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" mptcp_lib_result_skip "sockopt"
return return
fi fi
...@@ -220,23 +232,27 @@ do_mptcp_sockopt_tests() ...@@ -220,23 +232,27 @@ do_mptcp_sockopt_tests()
ip netns exec "$ns_sbox" ./mptcp_sockopt ip netns exec "$ns_sbox" ./mptcp_sockopt
lret=$? lret=$?
print_title "SOL_MPTCP sockopt v4"
if [ $lret -ne 0 ]; then if [ $lret -ne 0 ]; then
echo "FAIL: SOL_MPTCP getsockopt" 1>&2 mptcp_lib_pr_fail
mptcp_lib_result_fail "sockopt v4" mptcp_lib_result_fail "sockopt v4"
ret=$lret ret=$lret
return return
fi fi
mptcp_lib_pr_ok
mptcp_lib_result_pass "sockopt v4" mptcp_lib_result_pass "sockopt v4"
ip netns exec "$ns_sbox" ./mptcp_sockopt -6 ip netns exec "$ns_sbox" ./mptcp_sockopt -6
lret=$? lret=$?
print_title "SOL_MPTCP sockopt v6"
if [ $lret -ne 0 ]; then if [ $lret -ne 0 ]; then
echo "FAIL: SOL_MPTCP getsockopt (ipv6)" 1>&2 mptcp_lib_pr_fail
mptcp_lib_result_fail "sockopt v6" mptcp_lib_result_fail "sockopt v6"
ret=$lret ret=$lret
return return
fi fi
mptcp_lib_pr_ok
mptcp_lib_result_pass "sockopt v6" mptcp_lib_result_pass "sockopt v6"
} }
...@@ -259,16 +275,17 @@ run_tests() ...@@ -259,16 +275,17 @@ run_tests()
do_tcpinq_test() do_tcpinq_test()
{ {
print_title "TCP_INQ cmsg/ioctl $*"
ip netns exec "$ns_sbox" ./mptcp_inq "$@" ip netns exec "$ns_sbox" ./mptcp_inq "$@"
local lret=$? local lret=$?
if [ $lret -ne 0 ];then if [ $lret -ne 0 ];then
ret=$lret ret=$lret
echo "FAIL: mptcp_inq $*" 1>&2 mptcp_lib_pr_fail
mptcp_lib_result_fail "TCP_INQ: $*" mptcp_lib_result_fail "TCP_INQ: $*"
return $lret return $lret
fi fi
echo "PASS: TCP_INQ cmsg/ioctl $*" mptcp_lib_pr_ok
mptcp_lib_result_pass "TCP_INQ: $*" mptcp_lib_result_pass "TCP_INQ: $*"
return $lret return $lret
} }
...@@ -278,7 +295,7 @@ do_tcpinq_tests() ...@@ -278,7 +295,7 @@ do_tcpinq_tests()
local lret=0 local lret=0
if ! mptcp_lib_kallsyms_has "mptcp_ioctl$"; then 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" mptcp_lib_result_skip "TCP_INQ"
return return
fi fi
...@@ -314,15 +331,7 @@ trap cleanup EXIT ...@@ -314,15 +331,7 @@ trap cleanup EXIT
run_tests $ns1 $ns2 10.0.1.1 run_tests $ns1 $ns2 10.0.1.1
run_tests $ns1 $ns2 dead:beef: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 do_mptcp_sockopt_tests
if [ $ret -eq 0 ];then
echo "PASS: SOL_MPTCP getsockopt has expected information"
fi
do_tcpinq_tests do_tcpinq_tests
mptcp_lib_result_print_all_tap mptcp_lib_result_print_all_tap
......
...@@ -19,11 +19,11 @@ while getopts "$optstring" option;do ...@@ -19,11 +19,11 @@ while getopts "$optstring" option;do
case "$option" in case "$option" in
"h") "h")
usage $0 usage $0
exit 0 exit ${KSFT_PASS}
;; ;;
"?") "?")
usage $0 usage $0
exit 1 exit ${KSFT_FAIL}
;; ;;
esac esac
done done
...@@ -53,17 +53,17 @@ check() ...@@ -53,17 +53,17 @@ check()
local msg="$3" local msg="$3"
local rc=0 local rc=0
printf "%-50s" "$msg" mptcp_lib_print_title "$msg"
mptcp_lib_check_output "${err}" "${cmd}" "${expected}" || rc=${?} mptcp_lib_check_output "${err}" "${cmd}" "${expected}" || rc=${?}
if [ ${rc} -eq 2 ]; then if [ ${rc} -eq 2 ]; then
mptcp_lib_result_fail "${msg} # error ${rc}" mptcp_lib_result_fail "${msg} # error ${rc}"
ret=1 ret=${KSFT_FAIL}
elif [ ${rc} -eq 0 ]; then elif [ ${rc} -eq 0 ]; then
mptcp_lib_print_ok "[ OK ]" mptcp_lib_print_ok "[ OK ]"
mptcp_lib_result_pass "${msg}" mptcp_lib_result_pass "${msg}"
elif [ ${rc} -eq 1 ]; then elif [ ${rc} -eq 1 ]; then
mptcp_lib_result_fail "${msg} # different output" mptcp_lib_result_fail "${msg} # different output"
ret=1 ret=${KSFT_FAIL}
fi fi
} }
...@@ -189,7 +189,8 @@ subflow,backup,fullmesh 10.0.1.1" " (backup,fullmesh)" ...@@ -189,7 +189,8 @@ subflow,backup,fullmesh 10.0.1.1" " (backup,fullmesh)"
else else
for st in fullmesh nofullmesh backup,fullmesh; do for st in fullmesh nofullmesh backup,fullmesh; do
st=" (${st})" st=" (${st})"
printf "%-50s%s\n" "${st}" "[SKIP]" mptcp_lib_print_title "${st}"
mptcp_lib_pr_skip
mptcp_lib_result_skip "${st}" mptcp_lib_result_skip "${st}"
done done
fi fi
......
...@@ -14,7 +14,8 @@ ns3="" ...@@ -14,7 +14,8 @@ ns3=""
capture=false capture=false
timeout_poll=30 timeout_poll=30
timeout_test=$((timeout_poll * 2 + 1)) 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 ret=0
bail=0 bail=0
slack=50 slack=50
...@@ -126,8 +127,7 @@ do_transfer() ...@@ -126,8 +127,7 @@ do_transfer()
local sin=$2 local sin=$2
local max_time=$3 local max_time=$3
local port local port
port=$((10000+test_cnt)) port=$((10000+MPTCP_LIB_TEST_COUNTER))
test_cnt=$((test_cnt+1))
:> "$cout" :> "$cout"
:> "$sout" :> "$sout"
...@@ -187,12 +187,12 @@ do_transfer() ...@@ -187,12 +187,12 @@ do_transfer()
printf "%-16s" " max $max_time " printf "%-16s" " max $max_time "
if [ $retc -eq 0 ] && [ $rets -eq 0 ] && \ if [ $retc -eq 0 ] && [ $rets -eq 0 ] && \
[ $cmpc -eq 0 ] && [ $cmps -eq 0 ]; then [ $cmpc -eq 0 ] && [ $cmps -eq 0 ]; then
echo "[ OK ]" mptcp_lib_pr_ok
cat "$capout" cat "$capout"
return 0 return 0
fi fi
echo " [ fail ]" mptcp_lib_pr_fail
echo "client exit code $retc, server $rets" 1>&2 echo "client exit code $retc, server $rets" 1>&2
echo -e "\nnetns ${ns3} socket stat for $port:" 1>&2 echo -e "\nnetns ${ns3} socket stat for $port:" 1>&2
ip netns exec ${ns3} ss -nita 1>&2 -o "sport = :$port" ip netns exec ${ns3} ss -nita 1>&2 -o "sport = :$port"
...@@ -239,7 +239,7 @@ run_test() ...@@ -239,7 +239,7 @@ run_test()
# completion (see mptcp_connect): 200ms on each side, add some slack # completion (see mptcp_connect): 200ms on each side, add some slack
time=$((time + 400 + slack)) time=$((time + 400 + slack))
printf "%-60s" "$msg" mptcp_lib_print_title "$msg"
do_transfer $small $large $time do_transfer $small $large $time
lret=$? lret=$?
mptcp_lib_result_code "${lret}" "${msg}" mptcp_lib_result_code "${lret}" "${msg}"
...@@ -249,7 +249,7 @@ run_test() ...@@ -249,7 +249,7 @@ run_test()
fi fi
msg+=" - reverse direction" msg+=" - reverse direction"
printf "%-60s" "${msg}" mptcp_lib_print_title "${msg}"
do_transfer $large $small $time do_transfer $large $small $time
lret=$? lret=$?
mptcp_lib_result_code "${lret}" "${msg}" mptcp_lib_result_code "${lret}" "${msg}"
...@@ -263,7 +263,7 @@ while getopts "bcdh" option;do ...@@ -263,7 +263,7 @@ while getopts "bcdh" option;do
case "$option" in case "$option" in
"h") "h")
usage $0 usage $0
exit 0 exit ${KSFT_PASS}
;; ;;
"b") "b")
bail=1 bail=1
...@@ -276,7 +276,7 @@ while getopts "bcdh" option;do ...@@ -276,7 +276,7 @@ while getopts "bcdh" option;do
;; ;;
"?") "?")
usage $0 usage $0
exit 1 exit ${KSFT_FAIL}
;; ;;
esac esac
done done
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
# code but we accept it. # code but we accept it.
#shellcheck disable=SC2086 #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 #shellcheck disable=SC2034
. "$(dirname "${0}")/mptcp_lib.sh" . "$(dirname "${0}")/mptcp_lib.sh"
...@@ -19,15 +19,15 @@ if ! mptcp_lib_has_file '/proc/sys/net/mptcp/pm_type'; then ...@@ -19,15 +19,15 @@ if ! mptcp_lib_has_file '/proc/sys/net/mptcp/pm_type'; then
fi fi
mptcp_lib_check_tools ip mptcp_lib_check_tools ip
ANNOUNCED=6 # MPTCP_EVENT_ANNOUNCED ANNOUNCED=${MPTCP_LIB_EVENT_ANNOUNCED}
REMOVED=7 # MPTCP_EVENT_REMOVED REMOVED=${MPTCP_LIB_EVENT_REMOVED}
SUB_ESTABLISHED=10 # MPTCP_EVENT_SUB_ESTABLISHED SUB_ESTABLISHED=${MPTCP_LIB_EVENT_SUB_ESTABLISHED}
SUB_CLOSED=11 # MPTCP_EVENT_SUB_CLOSED SUB_CLOSED=${MPTCP_LIB_EVENT_SUB_CLOSED}
LISTENER_CREATED=15 #MPTCP_EVENT_LISTENER_CREATED LISTENER_CREATED=${MPTCP_LIB_EVENT_LISTENER_CREATED}
LISTENER_CLOSED=16 #MPTCP_EVENT_LISTENER_CLOSED LISTENER_CLOSED=${MPTCP_LIB_EVENT_LISTENER_CLOSED}
AF_INET=2 AF_INET=${MPTCP_LIB_AF_INET}
AF_INET6=10 AF_INET6=${MPTCP_LIB_AF_INET6}
file="" file=""
server_evts="" server_evts=""
...@@ -54,14 +54,12 @@ ns1="" ...@@ -54,14 +54,12 @@ ns1=""
ns2="" ns2=""
ret=0 ret=0
test_name="" test_name=""
# a bit more space: because we have more to display
_printf() { MPTCP_LIB_TEST_FORMAT="%02u %-68s"
stdbuf -o0 -e0 printf "${@}"
}
print_title() print_title()
{ {
_printf "INFO: %s\n" "${1}" mptcp_lib_pr_info "${1}"
} }
# $1: test name # $1: test name
...@@ -69,36 +67,29 @@ print_test() ...@@ -69,36 +67,29 @@ print_test()
{ {
test_name="${1}" test_name="${1}"
_printf "%-68s" "${test_name}" mptcp_lib_print_title "${test_name}"
}
print_results()
{
_printf "[%s]\n" "${1}"
} }
test_pass() test_pass()
{ {
print_results " OK " mptcp_lib_pr_ok
mptcp_lib_result_pass "${test_name}" mptcp_lib_result_pass "${test_name}"
} }
test_skip() test_skip()
{ {
print_results "SKIP" mptcp_lib_pr_skip
mptcp_lib_result_skip "${test_name}" mptcp_lib_result_skip "${test_name}"
} }
# $1: msg # $1: msg
test_fail() test_fail()
{ {
print_results "FAIL" if [ ${#} -gt 0 ]
ret=1 then
mptcp_lib_pr_fail "${@}"
if [ -n "${1}" ]; then
_printf "\t%s\n" "${1}"
fi fi
ret=${KSFT_FAIL}
mptcp_lib_result_fail "${test_name}" mptcp_lib_result_fail "${test_name}"
} }
...@@ -120,7 +111,7 @@ cleanup() ...@@ -120,7 +111,7 @@ cleanup()
rm -rf $file $client_evts $server_evts rm -rf $file $client_evts $server_evts
_printf "Done\n" mptcp_lib_pr_info "Done"
} }
trap cleanup EXIT trap cleanup EXIT
...@@ -218,7 +209,7 @@ make_connection() ...@@ -218,7 +209,7 @@ make_connection()
else else
test_fail "Expected tokens (c:${client_token} - s:${server_token}) and server (c:${client_serverside} - s:${server_serverside})" test_fail "Expected tokens (c:${client_token} - s:${server_token}) and server (c:${client_serverside} - s:${server_serverside})"
mptcp_lib_result_print_all_tap mptcp_lib_result_print_all_tap
exit 1 exit ${KSFT_FAIL}
fi fi
if [ "$is_v6" = "v6" ] if [ "$is_v6" = "v6" ]
...@@ -237,45 +228,16 @@ make_connection() ...@@ -237,45 +228,16 @@ make_connection()
fi 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 # $@: all var names to check
check_expected() check_expected()
{ {
local rc=0 if mptcp_lib_check_expected "${@}"
local var
for var in "${@}"
do
check_expected_one "${var}" "${rc}" || rc=1
done
if [ ${rc} -eq 0 ]
then then
test_pass test_pass
return 0 return 0
fi fi
test_fail
return 1 return 1
} }
...@@ -425,7 +387,7 @@ test_remove() ...@@ -425,7 +387,7 @@ test_remove()
then then
test_pass test_pass
else else
test_fail test_fail "unexpected type: ${type}"
fi fi
# RM_ADDR using an invalid addr id should result in no action # RM_ADDR using an invalid addr id should result in no action
...@@ -438,7 +400,7 @@ test_remove() ...@@ -438,7 +400,7 @@ test_remove()
then then
test_pass test_pass
else else
test_fail test_fail "unexpected type: ${type}"
fi fi
# RM_ADDR from the client to server machine # RM_ADDR from the client to server machine
...@@ -873,32 +835,11 @@ test_prio() ...@@ -873,32 +835,11 @@ test_prio()
verify_listener_events() verify_listener_events()
{ {
local evt=$1 if mptcp_lib_verify_listener_events "${@}"; then
local e_type=$2 test_pass
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)
else else
saddr=$(mptcp_lib_evts_get_info saddr4 $evt $e_type) test_fail
fi fi
check_expected "type" "family" "saddr" "sport"
} }
test_listener() test_listener()
...@@ -920,6 +861,7 @@ test_listener() ...@@ -920,6 +861,7 @@ test_listener()
local listener_pid=$! local listener_pid=$!
sleep 0.5 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 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 # ADD_ADDR from client to server machine reusing the subflow port
...@@ -936,6 +878,7 @@ test_listener() ...@@ -936,6 +878,7 @@ test_listener()
mptcp_lib_kill_wait $listener_pid mptcp_lib_kill_wait $listener_pid
sleep 0.5 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 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