selftests: mptcp: add mptcp_lib_kill_wait

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

Export kill_wait() helper in userspace_pm.sh into mptcp_lib.sh and
rename it as mptcp_lib_kill_wait(). It can be used to instead of
kill_wait() in mptcp_join.sh. Use the new helper in both scripts.

Reviewed-by: Matthieu Baerts <matttbe@kernel.org>
Signed-off-by: Geliang Tang <geliang.tang@suse.com>
Signed-off-by: Mat Martineau <martineau@kernel.org>
Link: https://lore.kernel.org/r/20231128-send-net-next-2023107-v4-9-8d6b94150f6b@kernel.org
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
This commit is contained in:
Geliang Tang 2023-11-28 15:18:53 -08:00 committed by Jakub Kicinski
parent b9fb176081
commit bdbef0a6ff
3 changed files with 22 additions and 28 deletions

View file

@ -682,16 +682,10 @@ wait_mpj()
done
}
kill_wait()
{
kill $1 > /dev/null 2>&1
wait $1 2>/dev/null
}
kill_events_pids()
{
kill_wait $evts_ns1_pid
kill_wait $evts_ns2_pid
mptcp_lib_kill_wait $evts_ns1_pid
mptcp_lib_kill_wait $evts_ns2_pid
}
kill_tests_wait()

View file

@ -217,3 +217,12 @@ mptcp_lib_get_info_value() {
mptcp_lib_evts_get_info() {
mptcp_lib_get_info_value "${1}" "^type:${3:-1}," < "${2}"
}
# $1: PID
mptcp_lib_kill_wait() {
[ "${1}" -eq 0 ] && return 0
kill -SIGUSR1 "${1}" > /dev/null 2>&1
kill "${1}" > /dev/null 2>&1
wait "${1}" 2>/dev/null
}

View file

@ -108,15 +108,6 @@ test_fail()
mptcp_lib_result_fail "${test_name}"
}
kill_wait()
{
[ $1 -eq 0 ] && return 0
kill -SIGUSR1 $1 > /dev/null 2>&1
kill $1 > /dev/null 2>&1
wait $1 2>/dev/null
}
# This function is used in the cleanup trap
#shellcheck disable=SC2317
cleanup()
@ -128,7 +119,7 @@ cleanup()
for pid in $client4_pid $server4_pid $client6_pid $server6_pid\
$server_evts_pid $client_evts_pid
do
kill_wait $pid
mptcp_lib_kill_wait $pid
done
local netns
@ -210,7 +201,7 @@ make_connection()
fi
:>"$client_evts"
if [ $client_evts_pid -ne 0 ]; then
kill_wait $client_evts_pid
mptcp_lib_kill_wait $client_evts_pid
fi
ip netns exec "$ns2" ./pm_nl_ctl events >> "$client_evts" 2>&1 &
client_evts_pid=$!
@ -219,7 +210,7 @@ make_connection()
fi
:>"$server_evts"
if [ $server_evts_pid -ne 0 ]; then
kill_wait $server_evts_pid
mptcp_lib_kill_wait $server_evts_pid
fi
ip netns exec "$ns1" ./pm_nl_ctl events >> "$server_evts" 2>&1 &
server_evts_pid=$!
@ -624,7 +615,7 @@ test_subflows()
"10.0.2.2" "$client4_port" "23" "$client_addr_id" "ns1" "ns2"
# Delete the listener from the client ns, if one was created
kill_wait $listener_pid
mptcp_lib_kill_wait $listener_pid
local sport
sport=$(mptcp_lib_evts_get_info sport "$server_evts" $SUB_ESTABLISHED)
@ -663,7 +654,7 @@ test_subflows()
"$client_addr_id" "ns1" "ns2"
# Delete the listener from the client ns, if one was created
kill_wait $listener_pid
mptcp_lib_kill_wait $listener_pid
sport=$(mptcp_lib_evts_get_info sport "$server_evts" $SUB_ESTABLISHED)
@ -702,7 +693,7 @@ test_subflows()
"$client_addr_id" "ns1" "ns2"
# Delete the listener from the client ns, if one was created
kill_wait $listener_pid
mptcp_lib_kill_wait $listener_pid
sport=$(mptcp_lib_evts_get_info sport "$server_evts" $SUB_ESTABLISHED)
@ -740,7 +731,7 @@ test_subflows()
"10.0.2.1" "$app4_port" "23" "$server_addr_id" "ns2" "ns1"
# Delete the listener from the server ns, if one was created
kill_wait $listener_pid
mptcp_lib_kill_wait $listener_pid
sport=$(mptcp_lib_evts_get_info sport "$client_evts" $SUB_ESTABLISHED)
@ -779,7 +770,7 @@ test_subflows()
"$server_addr_id" "ns2" "ns1"
# Delete the listener from the server ns, if one was created
kill_wait $listener_pid
mptcp_lib_kill_wait $listener_pid
sport=$(mptcp_lib_evts_get_info sport "$client_evts" $SUB_ESTABLISHED)
@ -816,7 +807,7 @@ test_subflows()
"10.0.2.2" "10.0.2.1" "$new4_port" "23" "$server_addr_id" "ns2" "ns1"
# Delete the listener from the server ns, if one was created
kill_wait $listener_pid
mptcp_lib_kill_wait $listener_pid
sport=$(mptcp_lib_evts_get_info sport "$client_evts" $SUB_ESTABLISHED)
@ -862,7 +853,7 @@ test_subflows_v4_v6_mix()
"$server_addr_id" "ns2" "ns1"
# Delete the listener from the server ns, if one was created
kill_wait $listener_pid
mptcp_lib_kill_wait $listener_pid
sport=$(mptcp_lib_evts_get_info sport "$client_evts" $SUB_ESTABLISHED)
@ -974,7 +965,7 @@ test_listener()
sleep 0.5
# Delete the listener from the client ns, if one was created
kill_wait $listener_pid
mptcp_lib_kill_wait $listener_pid
sleep 0.5
verify_listener_events $client_evts $LISTENER_CLOSED $AF_INET 10.0.2.2 $client4_port