selftests: mptcp: add mptcp_lib_events helper

commit 35bc143a8514ee72b2e9d6b8b385468608b93a53 upstream.

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

This patch unifies "pm_nl_ctl events" related code in userspace_pm.sh
and mptcp_join.sh into a helper mptcp_lib_events(). Define it in
mptcp_lib.sh and use it in both scripts.

Note that mptcp_lib_kill_wait is now call before starting 'events' for
mptcp_join.sh as well, but that's fine: each test is started from a new
netns, so there will not be any existing pid there, and nothing is done
when mptcp_lib_kill_wait is called with 0.

Signed-off-by: Geliang Tang <tanggeliang@kylinos.cn>
Reviewed-by: Matthieu Baerts (NGI0) <matttbe@kernel.org>
Signed-off-by: Matthieu Baerts (NGI0) <matttbe@kernel.org>
Link: https://lore.kernel.org/r/20240306-upstream-net-next-20240304-selftests-mptcp-shared-code-shellcheck-v2-6-bc79e6e5e6a0@kernel.org
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Stable-dep-of: 20ccc7c5f7a3 ("selftests: mptcp: join: validate event numbers")
[ Conflicts in mptcp_lib.sh, because the context is different at the end
  of the file, where the new helper is supposed to go. The new helper
  has simply be added at the end. ]
Signed-off-by: Matthieu Baerts (NGI0) <matttbe@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
Geliang Tang 2024-09-03 12:23:49 +02:00 committed by Greg Kroah-Hartman
parent 0a37a0ec0d
commit b66609e9aa
3 changed files with 18 additions and 18 deletions

View File

@ -468,12 +468,8 @@ reset_with_events()
{
reset "${1}" || return 1
:> "$evts_ns1"
:> "$evts_ns2"
ip netns exec $ns1 ./pm_nl_ctl events >> "$evts_ns1" 2>&1 &
evts_ns1_pid=$!
ip netns exec $ns2 ./pm_nl_ctl events >> "$evts_ns2" 2>&1 &
evts_ns2_pid=$!
mptcp_lib_events "${ns1}" "${evts_ns1}" evts_ns1_pid
mptcp_lib_events "${ns2}" "${evts_ns2}" evts_ns2_pid
}
reset_with_tcp_filter()
@ -672,7 +668,9 @@ wait_mpj()
kill_events_pids()
{
mptcp_lib_kill_wait $evts_ns1_pid
evts_ns1_pid=0
mptcp_lib_kill_wait $evts_ns2_pid
evts_ns2_pid=0
}
pm_nl_set_limits()

View File

@ -258,3 +258,15 @@ mptcp_lib_get_counter() {
echo "${count}"
}
mptcp_lib_events() {
local ns="${1}"
local evts="${2}"
declare -n pid="${3}"
:>"${evts}"
mptcp_lib_kill_wait "${pid:-0}"
ip netns exec "${ns}" ./pm_nl_ctl events >> "${evts}" 2>&1 &
pid=$!
}

View File

@ -201,21 +201,11 @@ make_connection()
if [ -z "$client_evts" ]; then
client_evts=$(mktemp)
fi
:>"$client_evts"
if [ $client_evts_pid -ne 0 ]; then
mptcp_lib_kill_wait $client_evts_pid
fi
ip netns exec "$ns2" ./pm_nl_ctl events >> "$client_evts" 2>&1 &
client_evts_pid=$!
mptcp_lib_events "${ns2}" "${client_evts}" client_evts_pid
if [ -z "$server_evts" ]; then
server_evts=$(mktemp)
fi
:>"$server_evts"
if [ $server_evts_pid -ne 0 ]; then
mptcp_lib_kill_wait $server_evts_pid
fi
ip netns exec "$ns1" ./pm_nl_ctl events >> "$server_evts" 2>&1 &
server_evts_pid=$!
mptcp_lib_events "${ns1}" "${server_evts}" server_evts_pid
sleep 0.5
# Run the server