Skip to content

Commit 2af5611

Browse files
matttbejfvogel
authored andcommitted
selftests: mptcp: join: properly kill background tasks
commit 852b644acbce1529307a4bb283752c4e77b5cda7 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> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> (cherry picked from commit ab9d10109ad0891ccf8b7401d9acbd0657a876d6) Signed-off-by: Jack Vogel <jack.vogel@oracle.com>
1 parent e2b0d01 commit 2af5611

File tree

2 files changed

+30
-9
lines changed

2 files changed

+30
-9
lines changed

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

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3616,7 +3616,7 @@ userspace_tests()
36163616
chk_mptcp_info subflows 0 subflows 0
36173617
chk_subflows_total 1 1
36183618
kill_events_pids
3619-
mptcp_lib_kill_wait $tests_pid
3619+
mptcp_lib_kill_group_wait $tests_pid
36203620
fi
36213621

36223622
# userspace pm create destroy subflow
@@ -3644,7 +3644,7 @@ userspace_tests()
36443644
chk_mptcp_info subflows 0 subflows 0
36453645
chk_subflows_total 1 1
36463646
kill_events_pids
3647-
mptcp_lib_kill_wait $tests_pid
3647+
mptcp_lib_kill_group_wait $tests_pid
36483648
fi
36493649

36503650
# userspace pm create id 0 subflow
@@ -3665,7 +3665,7 @@ userspace_tests()
36653665
chk_mptcp_info subflows 1 subflows 1
36663666
chk_subflows_total 2 2
36673667
kill_events_pids
3668-
mptcp_lib_kill_wait $tests_pid
3668+
mptcp_lib_kill_group_wait $tests_pid
36693669
fi
36703670

36713671
# userspace pm remove initial subflow
@@ -3689,7 +3689,7 @@ userspace_tests()
36893689
chk_mptcp_info subflows 1 subflows 1
36903690
chk_subflows_total 1 1
36913691
kill_events_pids
3692-
mptcp_lib_kill_wait $tests_pid
3692+
mptcp_lib_kill_group_wait $tests_pid
36933693
fi
36943694

36953695
# userspace pm send RM_ADDR for ID 0
@@ -3715,7 +3715,7 @@ userspace_tests()
37153715
chk_mptcp_info subflows 1 subflows 1
37163716
chk_subflows_total 1 1
37173717
kill_events_pids
3718-
mptcp_lib_kill_wait $tests_pid
3718+
mptcp_lib_kill_group_wait $tests_pid
37193719
fi
37203720
}
37213721

@@ -3745,7 +3745,7 @@ endpoint_tests()
37453745
pm_nl_add_endpoint $ns2 10.0.2.2 flags signal
37463746
pm_nl_check_endpoint "modif is allowed" \
37473747
$ns2 10.0.2.2 id 1 flags signal
3748-
mptcp_lib_kill_wait $tests_pid
3748+
mptcp_lib_kill_group_wait $tests_pid
37493749
fi
37503750

37513751
if reset_with_tcp_filter "delete and re-add" ns2 10.0.3.2 REJECT OUTPUT &&
@@ -3800,7 +3800,7 @@ endpoint_tests()
38003800
chk_mptcp_info subflows 3 subflows 3
38013801
done
38023802

3803-
mptcp_lib_kill_wait $tests_pid
3803+
mptcp_lib_kill_group_wait $tests_pid
38043804

38053805
kill_events_pids
38063806
chk_evt_nr ns1 MPTCP_LIB_EVENT_LISTENER_CREATED 1
@@ -3874,7 +3874,7 @@ endpoint_tests()
38743874
wait_mpj $ns2
38753875
chk_subflow_nr "after re-re-add ID 0" 3
38763876
chk_mptcp_info subflows 3 subflows 3
3877-
mptcp_lib_kill_wait $tests_pid
3877+
mptcp_lib_kill_group_wait $tests_pid
38783878

38793879
kill_events_pids
38803880
chk_evt_nr ns1 MPTCP_LIB_EVENT_LISTENER_CREATED 1
@@ -3922,7 +3922,7 @@ endpoint_tests()
39223922
wait_mpj $ns2
39233923
pm_nl_add_endpoint $ns1 10.0.3.1 id 2 flags signal
39243924
wait_mpj $ns2
3925-
mptcp_lib_kill_wait $tests_pid
3925+
mptcp_lib_kill_group_wait $tests_pid
39263926

39273927
join_syn_tx=3 join_connect_err=1 \
39283928
chk_join_nr 2 2 2

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

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

330+
# $1: PID
331+
mptcp_lib_pid_list_children() {
332+
local curr="${1}"
333+
# evoke 'ps' only once
334+
local pids="${2:-"$(ps o pid,ppid)"}"
335+
336+
echo "${curr}"
337+
338+
local pid
339+
for pid in $(echo "${pids}" | awk "\$2 == ${curr} { print \$1 }"); do
340+
mptcp_lib_pid_list_children "${pid}" "${pids}"
341+
done
342+
}
343+
344+
# $1: PID
345+
mptcp_lib_kill_group_wait() {
346+
# Some users might not have procps-ng: cannot use "kill -- -PID"
347+
mptcp_lib_pid_list_children "${1}" | xargs -r kill &>/dev/null
348+
wait "${1}" 2>/dev/null
349+
}
350+
330351
# $1: IP address
331352
mptcp_lib_is_v6() {
332353
[ -z "${1##*:*}" ]

0 commit comments

Comments
 (0)