Skip to content

Commit f4ff166

Browse files
matttbegregkh
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: [email protected] Fixes: 04b57c9 ("selftests: mptcp: join: stop transfer when check is done (part 2)") Signed-off-by: Matthieu Baerts (NGI0) <[email protected]> Link: https://patch.msgid.link/20251110-net-mptcp-sft-join-unstable-v1-6-a4332c714e10@kernel.org Signed-off-by: Jakub Kicinski <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent acc03eb commit f4ff166

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
@@ -3645,7 +3645,7 @@ userspace_tests()
36453645
chk_mptcp_info subflows 0 subflows 0
36463646
chk_subflows_total 1 1
36473647
kill_events_pids
3648-
mptcp_lib_kill_wait $tests_pid
3648+
mptcp_lib_kill_group_wait $tests_pid
36493649
fi
36503650

36513651
# userspace pm create destroy subflow
@@ -3673,7 +3673,7 @@ userspace_tests()
36733673
chk_mptcp_info subflows 0 subflows 0
36743674
chk_subflows_total 1 1
36753675
kill_events_pids
3676-
mptcp_lib_kill_wait $tests_pid
3676+
mptcp_lib_kill_group_wait $tests_pid
36773677
fi
36783678

36793679
# userspace pm create id 0 subflow
@@ -3694,7 +3694,7 @@ userspace_tests()
36943694
chk_mptcp_info subflows 1 subflows 1
36953695
chk_subflows_total 2 2
36963696
kill_events_pids
3697-
mptcp_lib_kill_wait $tests_pid
3697+
mptcp_lib_kill_group_wait $tests_pid
36983698
fi
36993699

37003700
# userspace pm remove initial subflow
@@ -3718,7 +3718,7 @@ userspace_tests()
37183718
chk_mptcp_info subflows 1 subflows 1
37193719
chk_subflows_total 1 1
37203720
kill_events_pids
3721-
mptcp_lib_kill_wait $tests_pid
3721+
mptcp_lib_kill_group_wait $tests_pid
37223722
fi
37233723

37243724
# userspace pm send RM_ADDR for ID 0
@@ -3744,7 +3744,7 @@ userspace_tests()
37443744
chk_mptcp_info subflows 1 subflows 1
37453745
chk_subflows_total 1 1
37463746
kill_events_pids
3747-
mptcp_lib_kill_wait $tests_pid
3747+
mptcp_lib_kill_group_wait $tests_pid
37483748
fi
37493749
}
37503750

@@ -3774,7 +3774,7 @@ endpoint_tests()
37743774
pm_nl_add_endpoint $ns2 10.0.2.2 flags signal
37753775
pm_nl_check_endpoint "modif is allowed" \
37763776
$ns2 10.0.2.2 id 1 flags signal
3777-
mptcp_lib_kill_wait $tests_pid
3777+
mptcp_lib_kill_group_wait $tests_pid
37783778
fi
37793779

37803780
if reset_with_tcp_filter "delete and re-add" ns2 10.0.3.2 REJECT OUTPUT &&
@@ -3829,7 +3829,7 @@ endpoint_tests()
38293829
chk_mptcp_info subflows 3 subflows 3
38303830
done
38313831

3832-
mptcp_lib_kill_wait $tests_pid
3832+
mptcp_lib_kill_group_wait $tests_pid
38333833

38343834
kill_events_pids
38353835
chk_evt_nr ns1 MPTCP_LIB_EVENT_LISTENER_CREATED 1
@@ -3903,7 +3903,7 @@ endpoint_tests()
39033903
wait_mpj $ns2
39043904
chk_subflow_nr "after re-re-add ID 0" 3
39053905
chk_mptcp_info subflows 3 subflows 3
3906-
mptcp_lib_kill_wait $tests_pid
3906+
mptcp_lib_kill_group_wait $tests_pid
39073907

39083908
kill_events_pids
39093909
chk_evt_nr ns1 MPTCP_LIB_EVENT_LISTENER_CREATED 1
@@ -3951,7 +3951,7 @@ endpoint_tests()
39513951
wait_mpj $ns2
39523952
pm_nl_add_endpoint $ns1 10.0.3.1 id 2 flags signal
39533953
wait_mpj $ns2
3954-
mptcp_lib_kill_wait $tests_pid
3954+
mptcp_lib_kill_group_wait $tests_pid
39553955

39563956
join_syn_tx=3 join_connect_err=1 \
39573957
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)