Skip to content

Commit 7f0782c

Browse files
Geliang Tangkuba-moo
authored andcommitted
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: Geliang Tang <[email protected]> Reviewed-by: Matthieu Baerts (NGI0) <[email protected]> Signed-off-by: Matthieu Baerts (NGI0) <[email protected]> Link: https://lore.kernel.org/r/20240308-upstream-net-next-20240308-selftests-mptcp-unification-v1-13-4f42c347b653@kernel.org Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 8ebb441 commit 7f0782c

File tree

3 files changed

+30
-38
lines changed

3 files changed

+30
-38
lines changed

tools/testing/selftests/net/mptcp/mptcp_join.sh

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2794,15 +2794,9 @@ AF_INET6=10
27942794

27952795
verify_listener_events()
27962796
{
2797-
local evt=$1
27982797
local e_type=$2
2799-
local e_family=$3
28002798
local e_saddr=$4
28012799
local e_sport=$5
2802-
local type
2803-
local family
2804-
local saddr
2805-
local sport
28062800
local name
28072801

28082802
if [ $e_type = $LISTENER_CREATED ]; then
@@ -2820,23 +2814,10 @@ verify_listener_events()
28202814
return
28212815
fi
28222816

2823-
type=$(mptcp_lib_evts_get_info type "$evt" "$e_type")
2824-
family=$(mptcp_lib_evts_get_info family "$evt" "$e_type")
2825-
sport=$(mptcp_lib_evts_get_info sport "$evt" "$e_type")
2826-
if [ $family ] && [ $family = $AF_INET6 ]; then
2827-
saddr=$(mptcp_lib_evts_get_info saddr6 "$evt" "$e_type")
2828-
else
2829-
saddr=$(mptcp_lib_evts_get_info saddr4 "$evt" "$e_type")
2830-
fi
2831-
2832-
if [ $type ] && [ $type = $e_type ] &&
2833-
[ $family ] && [ $family = $e_family ] &&
2834-
[ $saddr ] && [ $saddr = $e_saddr ] &&
2835-
[ $sport ] && [ $sport = $e_sport ]; then
2817+
if mptcp_lib_verify_listener_events "${@}"; then
28362818
print_ok
28372819
return 0
28382820
fi
2839-
print_fail "$e_type:$type $e_family:$family $e_saddr:$saddr $e_sport:$sport"
28402821
fail_test
28412822
}
28422823

tools/testing/selftests/net/mptcp/mptcp_lib.sh

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -468,3 +468,29 @@ mptcp_lib_check_expected() {
468468

469469
return "${rc}"
470470
}
471+
472+
# shellcheck disable=SC2034 # Some variables are used below but indirectly
473+
mptcp_lib_verify_listener_events() {
474+
local evt=${1}
475+
local e_type=${2}
476+
local e_family=${3}
477+
local e_saddr=${4}
478+
local e_sport=${5}
479+
local type
480+
local family
481+
local saddr
482+
local sport
483+
local rc=0
484+
485+
type=$(mptcp_lib_evts_get_info type "${evt}" "${e_type}")
486+
family=$(mptcp_lib_evts_get_info family "${evt}" "${e_type}")
487+
if [ "${family}" ] && [ "${family}" = "${AF_INET6}" ]; then
488+
saddr=$(mptcp_lib_evts_get_info saddr6 "${evt}" "${e_type}")
489+
else
490+
saddr=$(mptcp_lib_evts_get_info saddr4 "${evt}" "${e_type}")
491+
fi
492+
sport=$(mptcp_lib_evts_get_info sport "${evt}" "${e_type}")
493+
494+
mptcp_lib_check_expected "type" "family" "saddr" "sport" || rc="${?}"
495+
return "${rc}"
496+
}

tools/testing/selftests/net/mptcp/userspace_pm.sh

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -835,26 +835,11 @@ test_prio()
835835

836836
verify_listener_events()
837837
{
838-
local evt=$1
839-
local e_type=$2
840-
local e_family=$3
841-
local e_saddr=$4
842-
local e_sport=$5
843-
local type
844-
local family
845-
local saddr
846-
local sport
847-
848-
type=$(mptcp_lib_evts_get_info type $evt $e_type)
849-
family=$(mptcp_lib_evts_get_info family $evt $e_type)
850-
sport=$(mptcp_lib_evts_get_info sport $evt $e_type)
851-
if [ $family ] && [ $family = $AF_INET6 ]; then
852-
saddr=$(mptcp_lib_evts_get_info saddr6 $evt $e_type)
838+
if mptcp_lib_verify_listener_events "${@}"; then
839+
test_pass
853840
else
854-
saddr=$(mptcp_lib_evts_get_info saddr4 $evt $e_type)
841+
test_fail
855842
fi
856-
857-
check_expected "type" "family" "saddr" "sport"
858843
}
859844

860845
test_listener()

0 commit comments

Comments
 (0)