]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
selftests: mptcp: get stats just before timing out
authorMatthieu Baerts (NGI0) <matttbe@kernel.org>
Fri, 14 Nov 2025 18:12:12 +0000 (19:12 +0100)
committerJakub Kicinski <kuba@kernel.org>
Tue, 18 Nov 2025 03:27:47 +0000 (19:27 -0800)
Recently, some debugging happened around a test that was timing out. The
stats were showing connections being closed which was confusing because
the closing state was caused by the timeout stopping the transfer.

To avoid such confusion, the timeout is no longer done per mptcp_connect
process, but separately. In case of timeout, the stats are now printed,
then the apps are killed.

The stats will still be printed after the kill, but that's fine, and
this might even be useful, just in case. Timeout should be exceptional.

Reviewed-by: Geliang Tang <geliang@kernel.org>
Signed-off-by: Matthieu Baerts (NGI0) <matttbe@kernel.org>
Link: https://patch.msgid.link/20251114-net-next-mptcp-sft-count-cache-stats-timeout-v1-8-863cb04e1b7b@kernel.org
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
tools/testing/selftests/net/mptcp/mptcp_connect.sh
tools/testing/selftests/net/mptcp/mptcp_join.sh
tools/testing/selftests/net/mptcp/mptcp_lib.sh
tools/testing/selftests/net/mptcp/mptcp_sockopt.sh
tools/testing/selftests/net/mptcp/simult_flows.sh

index e0bfd9b4730cd21da8342e5b85630af4ace3ea60..a6447f7a31fe53563b74ea4c84ceb76d56f95144 100755 (executable)
@@ -393,27 +393,35 @@ do_transfer()
                mptcp_lib_nstat_init "${connector_ns}"
        fi
 
-       timeout ${timeout_test} \
-               ip netns exec ${listener_ns} \
-                       ./mptcp_connect -t ${timeout_poll} -l -p $port -s ${srv_proto} \
-                               $extra_args $local_addr < "$sin" > "$sout" &
+       ip netns exec ${listener_ns} \
+               ./mptcp_connect -t ${timeout_poll} -l -p $port -s ${srv_proto} \
+                       $extra_args $local_addr < "$sin" > "$sout" &
        local spid=$!
 
        mptcp_lib_wait_local_port_listen "${listener_ns}" "${port}"
 
        local start
        start=$(date +%s%3N)
-       timeout ${timeout_test} \
-               ip netns exec ${connector_ns} \
-                       ./mptcp_connect -t ${timeout_poll} -p $port -s ${cl_proto} \
-                               $extra_args $connect_addr < "$cin" > "$cout" &
+       ip netns exec ${connector_ns} \
+               ./mptcp_connect -t ${timeout_poll} -p $port -s ${cl_proto} \
+                       $extra_args $connect_addr < "$cin" > "$cout" &
        local cpid=$!
 
+       mptcp_lib_wait_timeout "${timeout_test}" "${listener_ns}" \
+               "${connector_ns}" "${port}" "${cpid}" "${spid}" &
+       local timeout_pid=$!
+
        wait $cpid
        local retc=$?
        wait $spid
        local rets=$?
 
+       if kill -0 $timeout_pid; then
+               # Finished before the timeout: kill the background job
+               mptcp_lib_kill_group_wait $timeout_pid
+               timeout_pid=0
+       fi
+
        local stop
        stop=$(date +%s%3N)
 
@@ -433,7 +441,7 @@ do_transfer()
        local duration
        duration=$((stop-start))
        printf "(duration %05sms) " "${duration}"
-       if [ ${rets} -ne 0 ] || [ ${retc} -ne 0 ]; then
+       if [ ${rets} -ne 0 ] || [ ${retc} -ne 0 ] || [ ${timeout_pid} -ne 0 ]; then
                mptcp_lib_pr_fail "client exit code $retc, server $rets"
                mptcp_lib_pr_err_stats "${listener_ns}" "${connector_ns}" "${port}"
 
index 54bac074f18465996844e36cc1a647e26d250d0e..be61612f68fe51985dd889888ea03f48ef51d5ef 100755 (executable)
@@ -1024,38 +1024,38 @@ do_transfer()
        if [ "$test_linkfail" -gt 1 ];then
                listener_in="${sinfail}"
        fi
-       timeout ${timeout_test} \
-               ip netns exec ${listener_ns} \
-                       ./mptcp_connect -t ${timeout_poll} -l -p ${port} -s ${srv_proto} \
-                               ${extra_srv_args} "${bind_addr}" < "${listener_in}" > "${sout}" &
+       ip netns exec ${listener_ns} \
+               ./mptcp_connect -t ${timeout_poll} -l -p ${port} -s ${srv_proto} \
+                       ${extra_srv_args} "${bind_addr}" < "${listener_in}" > "${sout}" &
        local spid=$!
 
        mptcp_lib_wait_local_port_listen "${listener_ns}" "${port}"
 
        extra_cl_args="$extra_args $extra_cl_args"
        if [ "$test_linkfail" -eq 0 ];then
-               timeout ${timeout_test} \
-                       ip netns exec ${connector_ns} \
-                               ./mptcp_connect -t ${timeout_poll} -p $port -s ${cl_proto} \
-                                       $extra_cl_args $connect_addr < "$cin" > "$cout" &
+               ip netns exec ${connector_ns} \
+                       ./mptcp_connect -t ${timeout_poll} -p $port -s ${cl_proto} \
+                               $extra_cl_args $connect_addr < "$cin" > "$cout" &
        elif [ "$test_linkfail" -eq 1 ] || [ "$test_linkfail" -eq 2 ];then
                connector_in="${cinsent}"
                ( cat "$cinfail" ; sleep 2; link_failure $listener_ns ; cat "$cinfail" ) | \
                        tee "$cinsent" | \
-                       timeout ${timeout_test} \
                                ip netns exec ${connector_ns} \
                                        ./mptcp_connect -t ${timeout_poll} -p $port -s ${cl_proto} \
                                                $extra_cl_args $connect_addr > "$cout" &
        else
                connector_in="${cinsent}"
                tee "$cinsent" < "$cinfail" | \
-                       timeout ${timeout_test} \
-                               ip netns exec ${connector_ns} \
-                                       ./mptcp_connect -t ${timeout_poll} -p $port -s ${cl_proto} \
-                                               $extra_cl_args $connect_addr > "$cout" &
+                       ip netns exec ${connector_ns} \
+                               ./mptcp_connect -t ${timeout_poll} -p $port -s ${cl_proto} \
+                                       $extra_cl_args $connect_addr > "$cout" &
        fi
        local cpid=$!
 
+       mptcp_lib_wait_timeout "${timeout_test}" "${listener_ns}" \
+               "${connector_ns}" "${port}" "${cpid}" "${spid}" &
+       local timeout_pid=$!
+
        pm_nl_set_endpoint $listener_ns $connector_ns $connect_addr
        check_cestab $listener_ns $connector_ns
 
@@ -1064,12 +1064,18 @@ do_transfer()
        wait $spid
        local rets=$?
 
+       if kill -0 $timeout_pid; then
+               # Finished before the timeout: kill the background job
+               mptcp_lib_kill_group_wait $timeout_pid
+               timeout_pid=0
+       fi
+
        cond_stop_capture
 
        mptcp_lib_nstat_get "${listener_ns}"
        mptcp_lib_nstat_get "${connector_ns}"
 
-       if [ ${rets} -ne 0 ] || [ ${retc} -ne 0 ]; then
+       if [ ${rets} -ne 0 ] || [ ${retc} -ne 0 ] || [ ${timeout_pid} -ne 0 ]; then
                fail_test "client exit code $retc, server $rets"
                mptcp_lib_pr_err_stats "${listener_ns}" "${connector_ns}" "${port}"
                return 1
index 91ec75ddcb96074cffc02bc71db3a86932c1363a..5fea7e7df628c80d5dcd23541f23b4b4ed226dac 100644 (file)
@@ -350,6 +350,19 @@ mptcp_lib_evts_get_info() {
                mptcp_lib_get_info_value "${1}" "^type:${3:-1},"
 }
 
+mptcp_lib_wait_timeout() {
+       local timeout_test="${1}"
+       local listener_ns="${2}"
+       local connector_ns="${3}"
+       local port="${4}"
+       shift 4 # rest are PIDs
+
+       sleep "${timeout_test}"
+       mptcp_lib_print_err "timeout"
+       mptcp_lib_pr_err_stats "${listener_ns}" "${connector_ns}" "${port}"
+       kill "${@}" 2>/dev/null
+}
+
 # $1: PID
 mptcp_lib_kill_wait() {
        [ "${1}" -eq 0 ] && return 0
index 6cde7429104b95b5b7f51c68f484403967a3a925..ab8bce06b2626c79debea88f7a73b7f2bf690de4 100755 (executable)
@@ -172,31 +172,39 @@ do_transfer()
        mptcp_lib_nstat_init "${listener_ns}"
        mptcp_lib_nstat_init "${connector_ns}"
 
-       timeout ${timeout_test} \
-               ip netns exec ${listener_ns} \
-                       $mptcp_connect -t ${timeout_poll} -l -M 1 -p $port -s ${srv_proto} -c "${cmsg}" \
-                               ${local_addr} < "$sin" > "$sout" &
+       ip netns exec ${listener_ns} \
+               $mptcp_connect -t ${timeout_poll} -l -M 1 -p $port -s ${srv_proto} -c "${cmsg}" \
+                       ${local_addr} < "$sin" > "$sout" &
        local spid=$!
 
        mptcp_lib_wait_local_port_listen "${listener_ns}" "${port}"
 
-       timeout ${timeout_test} \
-               ip netns exec ${connector_ns} \
-                       $mptcp_connect -t ${timeout_poll} -M 2 -p $port -s ${cl_proto} -c "${cmsg}" \
-                               $connect_addr < "$cin" > "$cout" &
+       ip netns exec ${connector_ns} \
+               $mptcp_connect -t ${timeout_poll} -M 2 -p $port -s ${cl_proto} -c "${cmsg}" \
+                       $connect_addr < "$cin" > "$cout" &
 
        local cpid=$!
 
+       mptcp_lib_wait_timeout "${timeout_test}" "${listener_ns}" \
+               "${connector_ns}" "${port}" "${cpid}" "${spid}" &
+       local timeout_pid=$!
+
        wait $cpid
        local retc=$?
        wait $spid
        local rets=$?
 
+       if kill -0 $timeout_pid; then
+               # Finished before the timeout: kill the background job
+               mptcp_lib_kill_group_wait $timeout_pid
+               timeout_pid=0
+       fi
+
        mptcp_lib_nstat_get "${listener_ns}"
        mptcp_lib_nstat_get "${connector_ns}"
 
        print_title "Transfer ${ip:2}"
-       if [ ${rets} -ne 0 ] || [ ${retc} -ne 0 ]; then
+       if [ ${rets} -ne 0 ] || [ ${retc} -ne 0 ] || [ ${timeout_pid} -ne 0 ]; then
                mptcp_lib_pr_fail "client exit code $retc, server $rets"
                mptcp_lib_pr_err_stats "${listener_ns}" "${connector_ns}" "${port}"
 
index 503cb59571a4cfffc43a5c1f0214dcce1d6ca634..806aaa7d2d61dc2b18d823c8bf86ce044fd3969e 100755 (executable)
@@ -158,25 +158,33 @@ do_transfer()
        mptcp_lib_nstat_init "${ns3}"
        mptcp_lib_nstat_init "${ns1}"
 
-       timeout ${timeout_test} \
-               ip netns exec ${ns3} \
-                       ./mptcp_connect -jt ${timeout_poll} -l -p $port -T $max_time \
-                               0.0.0.0 < "$sin" > "$sout" &
+       ip netns exec ${ns3} \
+               ./mptcp_connect -jt ${timeout_poll} -l -p $port -T $max_time \
+                       0.0.0.0 < "$sin" > "$sout" &
        local spid=$!
 
        mptcp_lib_wait_local_port_listen "${ns3}" "${port}"
 
-       timeout ${timeout_test} \
-               ip netns exec ${ns1} \
-                       ./mptcp_connect -jt ${timeout_poll} -p $port -T $max_time \
-                               10.0.3.3 < "$cin" > "$cout" &
+       ip netns exec ${ns1} \
+               ./mptcp_connect -jt ${timeout_poll} -p $port -T $max_time \
+                       10.0.3.3 < "$cin" > "$cout" &
        local cpid=$!
 
+       mptcp_lib_wait_timeout "${timeout_test}" "${ns3}" "${ns1}" "${port}" \
+               "${cpid}" "${spid}" &
+       local timeout_pid=$!
+
        wait $cpid
        local retc=$?
        wait $spid
        local rets=$?
 
+       if kill -0 $timeout_pid; then
+               # Finished before the timeout: kill the background job
+               mptcp_lib_kill_group_wait $timeout_pid
+               timeout_pid=0
+       fi
+
        if $capture; then
                sleep 1
                kill ${cappid_listener}
@@ -191,8 +199,9 @@ do_transfer()
        cmp $cin $sout > /dev/null 2>&1
        local cmpc=$?
 
-       if [ $retc -eq 0 ] && [ $rets -eq 0 ] && \
-          [ $cmpc -eq 0 ] && [ $cmps -eq 0 ]; then
+       if [ $retc -eq 0 ] && [ $rets -eq 0 ] &&
+          [ $cmpc -eq 0 ] && [ $cmps -eq 0 ] &&
+          [ $timeout_pid -eq 0 ]; then
                printf "%-16s" " max $max_time "
                mptcp_lib_pr_ok
                cat "$capout"