Skip to content

Commit 852b644

Browse files
matttbekuba-moo
authored andcommitted
selftests: mptcp: join: properly kill background tasks
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>
1 parent ee79980 commit 852b644

2 files changed

Lines changed: 30 additions & 9 deletions

File tree

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

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3831,7 +3831,7 @@ userspace_tests()
38313831
chk_mptcp_info subflows 0 subflows 0
38323832
chk_subflows_total 1 1
38333833
kill_events_pids
3834-
mptcp_lib_kill_wait $tests_pid
3834+
mptcp_lib_kill_group_wait $tests_pid
38353835
fi
38363836

38373837
# userspace pm create destroy subflow
@@ -3859,7 +3859,7 @@ userspace_tests()
38593859
chk_mptcp_info subflows 0 subflows 0
38603860
chk_subflows_total 1 1
38613861
kill_events_pids
3862-
mptcp_lib_kill_wait $tests_pid
3862+
mptcp_lib_kill_group_wait $tests_pid
38633863
fi
38643864

38653865
# userspace pm create id 0 subflow
@@ -3880,7 +3880,7 @@ userspace_tests()
38803880
chk_mptcp_info subflows 1 subflows 1
38813881
chk_subflows_total 2 2
38823882
kill_events_pids
3883-
mptcp_lib_kill_wait $tests_pid
3883+
mptcp_lib_kill_group_wait $tests_pid
38843884
fi
38853885

38863886
# userspace pm remove initial subflow
@@ -3904,7 +3904,7 @@ userspace_tests()
39043904
chk_mptcp_info subflows 1 subflows 1
39053905
chk_subflows_total 1 1
39063906
kill_events_pids
3907-
mptcp_lib_kill_wait $tests_pid
3907+
mptcp_lib_kill_group_wait $tests_pid
39083908
fi
39093909

39103910
# userspace pm send RM_ADDR for ID 0
@@ -3930,7 +3930,7 @@ userspace_tests()
39303930
chk_mptcp_info subflows 1 subflows 1
39313931
chk_subflows_total 1 1
39323932
kill_events_pids
3933-
mptcp_lib_kill_wait $tests_pid
3933+
mptcp_lib_kill_group_wait $tests_pid
39343934
fi
39353935
}
39363936

@@ -3960,7 +3960,7 @@ endpoint_tests()
39603960
pm_nl_add_endpoint $ns2 10.0.2.2 flags signal
39613961
pm_nl_check_endpoint "modif is allowed" \
39623962
$ns2 10.0.2.2 id 1 flags signal
3963-
mptcp_lib_kill_wait $tests_pid
3963+
mptcp_lib_kill_group_wait $tests_pid
39643964
fi
39653965

39663966
if reset_with_tcp_filter "delete and re-add" ns2 10.0.3.2 REJECT OUTPUT &&
@@ -4015,7 +4015,7 @@ endpoint_tests()
40154015
chk_mptcp_info subflows 3 subflows 3
40164016
done
40174017

4018-
mptcp_lib_kill_wait $tests_pid
4018+
mptcp_lib_kill_group_wait $tests_pid
40194019

40204020
kill_events_pids
40214021
chk_evt_nr ns1 MPTCP_LIB_EVENT_LISTENER_CREATED 1
@@ -4089,7 +4089,7 @@ endpoint_tests()
40894089
wait_mpj $ns2
40904090
chk_subflow_nr "after re-re-add ID 0" 3
40914091
chk_mptcp_info subflows 3 subflows 3
4092-
mptcp_lib_kill_wait $tests_pid
4092+
mptcp_lib_kill_group_wait $tests_pid
40934093

40944094
kill_events_pids
40954095
chk_evt_nr ns1 MPTCP_LIB_EVENT_LISTENER_CREATED 1
@@ -4137,7 +4137,7 @@ endpoint_tests()
41374137
wait_mpj $ns2
41384138
pm_nl_add_endpoint $ns1 10.0.3.1 id 2 flags signal
41394139
wait_mpj $ns2
4140-
mptcp_lib_kill_wait $tests_pid
4140+
mptcp_lib_kill_group_wait $tests_pid
41414141

41424142
join_syn_tx=3 join_connect_err=1 \
41434143
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
@@ -350,6 +350,27 @@ mptcp_lib_kill_wait() {
350350
wait "${1}" 2>/dev/null
351351
}
352352

353+
# $1: PID
354+
mptcp_lib_pid_list_children() {
355+
local curr="${1}"
356+
# evoke 'ps' only once
357+
local pids="${2:-"$(ps o pid,ppid)"}"
358+
359+
echo "${curr}"
360+
361+
local pid
362+
for pid in $(echo "${pids}" | awk "\$2 == ${curr} { print \$1 }"); do
363+
mptcp_lib_pid_list_children "${pid}" "${pids}"
364+
done
365+
}
366+
367+
# $1: PID
368+
mptcp_lib_kill_group_wait() {
369+
# Some users might not have procps-ng: cannot use "kill -- -PID"
370+
mptcp_lib_pid_list_children "${1}" | xargs -r kill &>/dev/null
371+
wait "${1}" 2>/dev/null
372+
}
373+
353374
# $1: IP address
354375
mptcp_lib_is_v6() {
355376
[ -z "${1##*:*}" ]

0 commit comments

Comments
 (0)