Skip to content

Commit b77075c

Browse files
matttbegregkh
authored andcommitted
selftests: mptcp: join: properly kill background tasks
commit 852b644 upstream. The 'run_tests' function is executed in the background, but killing its associated PID would not kill the children tasks running in the background. To properly kill all background tasks, 'kill -- -PID' could be used, but this requires kill from procps-ng. Instead, all children tasks are listed using 'ps', and 'kill' is called with all PIDs of this group. Fixes: 31ee4ad ("selftests: mptcp: join: stop transfer when check is done (part 1)") Cc: stable@vger.kernel.org Fixes: 04b57c9 ("selftests: mptcp: join: stop transfer when check is done (part 2)") Signed-off-by: Matthieu Baerts (NGI0) <matttbe@kernel.org> Link: https://patch.msgid.link/20251110-net-mptcp-sft-join-unstable-v1-6-a4332c714e10@kernel.org Signed-off-by: Jakub Kicinski <kuba@kernel.org> [ Conflicts in mptcp_join.sh, because commit e3b47e4 ("selftests: mptcp: userspace pm remove initial subflow") and commit b9fb176 ("selftests: mptcp: userspace pm send RM_ADDR for ID 0") are not in this version. They introduced new subtests that got modified by this patch. That's OK, no need to modify them if they are not there: the conflicts can be dropped. ] Signed-off-by: Matthieu Baerts (NGI0) <matttbe@kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent f12f4c6 commit b77075c

2 files changed

Lines changed: 28 additions & 7 deletions

File tree

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3679,7 +3679,7 @@ userspace_tests()
36793679
chk_mptcp_info subflows 0 subflows 0
36803680
chk_subflows_total 1 1
36813681
kill_events_pids
3682-
mptcp_lib_kill_wait $tests_pid
3682+
mptcp_lib_kill_group_wait $tests_pid
36833683
fi
36843684

36853685
# userspace pm create destroy subflow
@@ -3707,7 +3707,7 @@ userspace_tests()
37073707
chk_mptcp_info subflows 0 subflows 0
37083708
chk_subflows_total 1 1
37093709
kill_events_pids
3710-
mptcp_lib_kill_wait $tests_pid
3710+
mptcp_lib_kill_group_wait $tests_pid
37113711
fi
37123712

37133713
# userspace pm create id 0 subflow
@@ -3728,7 +3728,7 @@ userspace_tests()
37283728
chk_mptcp_info subflows 1 subflows 1
37293729
chk_subflows_total 2 2
37303730
kill_events_pids
3731-
mptcp_lib_kill_wait $tests_pid
3731+
mptcp_lib_kill_group_wait $tests_pid
37323732
fi
37333733
}
37343734

@@ -3758,7 +3758,7 @@ endpoint_tests()
37583758
pm_nl_add_endpoint $ns2 10.0.2.2 flags signal
37593759
pm_nl_check_endpoint "modif is allowed" \
37603760
$ns2 10.0.2.2 id 1 flags signal
3761-
mptcp_lib_kill_wait $tests_pid
3761+
mptcp_lib_kill_group_wait $tests_pid
37623762
fi
37633763

37643764
if reset_with_tcp_filter "delete and re-add" ns2 10.0.3.2 REJECT OUTPUT &&
@@ -3813,7 +3813,7 @@ endpoint_tests()
38133813
chk_mptcp_info subflows 3 subflows 3
38143814
done
38153815

3816-
mptcp_lib_kill_wait $tests_pid
3816+
mptcp_lib_kill_group_wait $tests_pid
38173817

38183818
kill_events_pids
38193819
chk_evt_nr ns1 MPTCP_LIB_EVENT_LISTENER_CREATED 1
@@ -3886,7 +3886,7 @@ endpoint_tests()
38863886
wait_mpj $ns2
38873887
chk_subflow_nr "after re-re-add ID 0" 3
38883888
chk_mptcp_info subflows 3 subflows 3
3889-
mptcp_lib_kill_wait $tests_pid
3889+
mptcp_lib_kill_group_wait $tests_pid
38903890

38913891
kill_events_pids
38923892
chk_evt_nr ns1 MPTCP_LIB_EVENT_LISTENER_CREATED 1
@@ -3933,7 +3933,7 @@ endpoint_tests()
39333933
wait_mpj $ns2
39343934
pm_nl_add_endpoint $ns1 10.0.3.1 id 2 flags signal
39353935
wait_mpj $ns2
3936-
mptcp_lib_kill_wait $tests_pid
3936+
mptcp_lib_kill_group_wait $tests_pid
39373937

39383938
chk_join_nr 2 2 2
39393939
chk_add_nr 2 2

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,27 @@ mptcp_lib_kill_wait() {
242242
wait "${1}" 2>/dev/null
243243
}
244244

245+
# $1: PID
246+
mptcp_lib_pid_list_children() {
247+
local curr="${1}"
248+
# evoke 'ps' only once
249+
local pids="${2:-"$(ps o pid,ppid)"}"
250+
251+
echo "${curr}"
252+
253+
local pid
254+
for pid in $(echo "${pids}" | awk "\$2 == ${curr} { print \$1 }"); do
255+
mptcp_lib_pid_list_children "${pid}" "${pids}"
256+
done
257+
}
258+
259+
# $1: PID
260+
mptcp_lib_kill_group_wait() {
261+
# Some users might not have procps-ng: cannot use "kill -- -PID"
262+
mptcp_lib_pid_list_children "${1}" | xargs -r kill &>/dev/null
263+
wait "${1}" 2>/dev/null
264+
}
265+
245266
# $1: IP address
246267
mptcp_lib_is_v6() {
247268
[ -z "${1##*:*}" ]

0 commit comments

Comments
 (0)