Commit 7f0782ca authored by Geliang Tang's avatar Geliang Tang Committed by Jakub Kicinski

selftests: mptcp: add mptcp_lib_verify_listener_events

To avoid duplicated code in different MPTCP selftests, we can add and use
helpers defined in mptcp_lib.sh.

The helper verify_listener_events() is defined both in mptcp_join.sh and
userspace_pm.sh, export it into mptcp_lib.sh and rename it with mptcp_lib_
prefix. Use this new helper in both scripts.
Signed-off-by: default avatarGeliang Tang <tanggeliang@kylinos.cn>
Reviewed-by: default avatarMatthieu Baerts (NGI0) <matttbe@kernel.org>
Signed-off-by: default avatarMatthieu Baerts (NGI0) <matttbe@kernel.org>
Link: https://lore.kernel.org/r/20240308-upstream-net-next-20240308-selftests-mptcp-unification-v1-13-4f42c347b653@kernel.orgSigned-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parent 8ebb4419
......@@ -2794,15 +2794,9 @@ AF_INET6=10
verify_listener_events()
{
local evt=$1
local e_type=$2
local e_family=$3
local e_saddr=$4
local e_sport=$5
local type
local family
local saddr
local sport
local name
if [ $e_type = $LISTENER_CREATED ]; then
......@@ -2820,23 +2814,10 @@ verify_listener_events()
return
fi
type=$(mptcp_lib_evts_get_info type "$evt" "$e_type")
family=$(mptcp_lib_evts_get_info family "$evt" "$e_type")
sport=$(mptcp_lib_evts_get_info sport "$evt" "$e_type")
if [ $family ] && [ $family = $AF_INET6 ]; then
saddr=$(mptcp_lib_evts_get_info saddr6 "$evt" "$e_type")
else
saddr=$(mptcp_lib_evts_get_info saddr4 "$evt" "$e_type")
fi
if [ $type ] && [ $type = $e_type ] &&
[ $family ] && [ $family = $e_family ] &&
[ $saddr ] && [ $saddr = $e_saddr ] &&
[ $sport ] && [ $sport = $e_sport ]; then
if mptcp_lib_verify_listener_events "${@}"; then
print_ok
return 0
fi
print_fail "$e_type:$type $e_family:$family $e_saddr:$saddr $e_sport:$sport"
fail_test
}
......
......@@ -468,3 +468,29 @@ mptcp_lib_check_expected() {
return "${rc}"
}
# shellcheck disable=SC2034 # Some variables are used below but indirectly
mptcp_lib_verify_listener_events() {
local evt=${1}
local e_type=${2}
local e_family=${3}
local e_saddr=${4}
local e_sport=${5}
local type
local family
local saddr
local sport
local rc=0
type=$(mptcp_lib_evts_get_info type "${evt}" "${e_type}")
family=$(mptcp_lib_evts_get_info family "${evt}" "${e_type}")
if [ "${family}" ] && [ "${family}" = "${AF_INET6}" ]; then
saddr=$(mptcp_lib_evts_get_info saddr6 "${evt}" "${e_type}")
else
saddr=$(mptcp_lib_evts_get_info saddr4 "${evt}" "${e_type}")
fi
sport=$(mptcp_lib_evts_get_info sport "${evt}" "${e_type}")
mptcp_lib_check_expected "type" "family" "saddr" "sport" || rc="${?}"
return "${rc}"
}
......@@ -835,26 +835,11 @@ test_prio()
verify_listener_events()
{
local evt=$1
local e_type=$2
local e_family=$3
local e_saddr=$4
local e_sport=$5
local type
local family
local saddr
local sport
type=$(mptcp_lib_evts_get_info type $evt $e_type)
family=$(mptcp_lib_evts_get_info family $evt $e_type)
sport=$(mptcp_lib_evts_get_info sport $evt $e_type)
if [ $family ] && [ $family = $AF_INET6 ]; then
saddr=$(mptcp_lib_evts_get_info saddr6 $evt $e_type)
if mptcp_lib_verify_listener_events "${@}"; then
test_pass
else
saddr=$(mptcp_lib_evts_get_info saddr4 $evt $e_type)
test_fail
fi
check_expected "type" "family" "saddr" "sport"
}
test_listener()
......
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