Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

selftests: mptcp: get stats just before timing out

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>

authored by

Matthieu Baerts (NGI0) and committed by
Jakub Kicinski
eea2f448 39348f5f

+86 -42
+17 -9
tools/testing/selftests/net/mptcp/mptcp_connect.sh
··· 393 393 mptcp_lib_nstat_init "${connector_ns}" 394 394 fi 395 395 396 - timeout ${timeout_test} \ 397 - ip netns exec ${listener_ns} \ 398 - ./mptcp_connect -t ${timeout_poll} -l -p $port -s ${srv_proto} \ 399 - $extra_args $local_addr < "$sin" > "$sout" & 396 + ip netns exec ${listener_ns} \ 397 + ./mptcp_connect -t ${timeout_poll} -l -p $port -s ${srv_proto} \ 398 + $extra_args $local_addr < "$sin" > "$sout" & 400 399 local spid=$! 401 400 402 401 mptcp_lib_wait_local_port_listen "${listener_ns}" "${port}" 403 402 404 403 local start 405 404 start=$(date +%s%3N) 406 - timeout ${timeout_test} \ 407 - ip netns exec ${connector_ns} \ 408 - ./mptcp_connect -t ${timeout_poll} -p $port -s ${cl_proto} \ 409 - $extra_args $connect_addr < "$cin" > "$cout" & 405 + ip netns exec ${connector_ns} \ 406 + ./mptcp_connect -t ${timeout_poll} -p $port -s ${cl_proto} \ 407 + $extra_args $connect_addr < "$cin" > "$cout" & 410 408 local cpid=$! 409 + 410 + mptcp_lib_wait_timeout "${timeout_test}" "${listener_ns}" \ 411 + "${connector_ns}" "${port}" "${cpid}" "${spid}" & 412 + local timeout_pid=$! 411 413 412 414 wait $cpid 413 415 local retc=$? 414 416 wait $spid 415 417 local rets=$? 418 + 419 + if kill -0 $timeout_pid; then 420 + # Finished before the timeout: kill the background job 421 + mptcp_lib_kill_group_wait $timeout_pid 422 + timeout_pid=0 423 + fi 416 424 417 425 local stop 418 426 stop=$(date +%s%3N) ··· 441 433 local duration 442 434 duration=$((stop-start)) 443 435 printf "(duration %05sms) " "${duration}" 444 - if [ ${rets} -ne 0 ] || [ ${retc} -ne 0 ]; then 436 + if [ ${rets} -ne 0 ] || [ ${retc} -ne 0 ] || [ ${timeout_pid} -ne 0 ]; then 445 437 mptcp_lib_pr_fail "client exit code $retc, server $rets" 446 438 mptcp_lib_pr_err_stats "${listener_ns}" "${connector_ns}" "${port}" 447 439
+20 -14
tools/testing/selftests/net/mptcp/mptcp_join.sh
··· 1024 1024 if [ "$test_linkfail" -gt 1 ];then 1025 1025 listener_in="${sinfail}" 1026 1026 fi 1027 - timeout ${timeout_test} \ 1028 - ip netns exec ${listener_ns} \ 1029 - ./mptcp_connect -t ${timeout_poll} -l -p ${port} -s ${srv_proto} \ 1030 - ${extra_srv_args} "${bind_addr}" < "${listener_in}" > "${sout}" & 1027 + ip netns exec ${listener_ns} \ 1028 + ./mptcp_connect -t ${timeout_poll} -l -p ${port} -s ${srv_proto} \ 1029 + ${extra_srv_args} "${bind_addr}" < "${listener_in}" > "${sout}" & 1031 1030 local spid=$! 1032 1031 1033 1032 mptcp_lib_wait_local_port_listen "${listener_ns}" "${port}" 1034 1033 1035 1034 extra_cl_args="$extra_args $extra_cl_args" 1036 1035 if [ "$test_linkfail" -eq 0 ];then 1037 - timeout ${timeout_test} \ 1038 - ip netns exec ${connector_ns} \ 1039 - ./mptcp_connect -t ${timeout_poll} -p $port -s ${cl_proto} \ 1040 - $extra_cl_args $connect_addr < "$cin" > "$cout" & 1036 + ip netns exec ${connector_ns} \ 1037 + ./mptcp_connect -t ${timeout_poll} -p $port -s ${cl_proto} \ 1038 + $extra_cl_args $connect_addr < "$cin" > "$cout" & 1041 1039 elif [ "$test_linkfail" -eq 1 ] || [ "$test_linkfail" -eq 2 ];then 1042 1040 connector_in="${cinsent}" 1043 1041 ( cat "$cinfail" ; sleep 2; link_failure $listener_ns ; cat "$cinfail" ) | \ 1044 1042 tee "$cinsent" | \ 1045 - timeout ${timeout_test} \ 1046 1043 ip netns exec ${connector_ns} \ 1047 1044 ./mptcp_connect -t ${timeout_poll} -p $port -s ${cl_proto} \ 1048 1045 $extra_cl_args $connect_addr > "$cout" & 1049 1046 else 1050 1047 connector_in="${cinsent}" 1051 1048 tee "$cinsent" < "$cinfail" | \ 1052 - timeout ${timeout_test} \ 1053 - ip netns exec ${connector_ns} \ 1054 - ./mptcp_connect -t ${timeout_poll} -p $port -s ${cl_proto} \ 1055 - $extra_cl_args $connect_addr > "$cout" & 1049 + ip netns exec ${connector_ns} \ 1050 + ./mptcp_connect -t ${timeout_poll} -p $port -s ${cl_proto} \ 1051 + $extra_cl_args $connect_addr > "$cout" & 1056 1052 fi 1057 1053 local cpid=$! 1054 + 1055 + mptcp_lib_wait_timeout "${timeout_test}" "${listener_ns}" \ 1056 + "${connector_ns}" "${port}" "${cpid}" "${spid}" & 1057 + local timeout_pid=$! 1058 1058 1059 1059 pm_nl_set_endpoint $listener_ns $connector_ns $connect_addr 1060 1060 check_cestab $listener_ns $connector_ns ··· 1064 1064 wait $spid 1065 1065 local rets=$? 1066 1066 1067 + if kill -0 $timeout_pid; then 1068 + # Finished before the timeout: kill the background job 1069 + mptcp_lib_kill_group_wait $timeout_pid 1070 + timeout_pid=0 1071 + fi 1072 + 1067 1073 cond_stop_capture 1068 1074 1069 1075 mptcp_lib_nstat_get "${listener_ns}" 1070 1076 mptcp_lib_nstat_get "${connector_ns}" 1071 1077 1072 - if [ ${rets} -ne 0 ] || [ ${retc} -ne 0 ]; then 1078 + if [ ${rets} -ne 0 ] || [ ${retc} -ne 0 ] || [ ${timeout_pid} -ne 0 ]; then 1073 1079 fail_test "client exit code $retc, server $rets" 1074 1080 mptcp_lib_pr_err_stats "${listener_ns}" "${connector_ns}" "${port}" 1075 1081 return 1
+13
tools/testing/selftests/net/mptcp/mptcp_lib.sh
··· 350 350 mptcp_lib_get_info_value "${1}" "^type:${3:-1}," 351 351 } 352 352 353 + mptcp_lib_wait_timeout() { 354 + local timeout_test="${1}" 355 + local listener_ns="${2}" 356 + local connector_ns="${3}" 357 + local port="${4}" 358 + shift 4 # rest are PIDs 359 + 360 + sleep "${timeout_test}" 361 + mptcp_lib_print_err "timeout" 362 + mptcp_lib_pr_err_stats "${listener_ns}" "${connector_ns}" "${port}" 363 + kill "${@}" 2>/dev/null 364 + } 365 + 353 366 # $1: PID 354 367 mptcp_lib_kill_wait() { 355 368 [ "${1}" -eq 0 ] && return 0
+17 -9
tools/testing/selftests/net/mptcp/mptcp_sockopt.sh
··· 172 172 mptcp_lib_nstat_init "${listener_ns}" 173 173 mptcp_lib_nstat_init "${connector_ns}" 174 174 175 - timeout ${timeout_test} \ 176 - ip netns exec ${listener_ns} \ 177 - $mptcp_connect -t ${timeout_poll} -l -M 1 -p $port -s ${srv_proto} -c "${cmsg}" \ 178 - ${local_addr} < "$sin" > "$sout" & 175 + ip netns exec ${listener_ns} \ 176 + $mptcp_connect -t ${timeout_poll} -l -M 1 -p $port -s ${srv_proto} -c "${cmsg}" \ 177 + ${local_addr} < "$sin" > "$sout" & 179 178 local spid=$! 180 179 181 180 mptcp_lib_wait_local_port_listen "${listener_ns}" "${port}" 182 181 183 - timeout ${timeout_test} \ 184 - ip netns exec ${connector_ns} \ 185 - $mptcp_connect -t ${timeout_poll} -M 2 -p $port -s ${cl_proto} -c "${cmsg}" \ 186 - $connect_addr < "$cin" > "$cout" & 182 + ip netns exec ${connector_ns} \ 183 + $mptcp_connect -t ${timeout_poll} -M 2 -p $port -s ${cl_proto} -c "${cmsg}" \ 184 + $connect_addr < "$cin" > "$cout" & 187 185 188 186 local cpid=$! 187 + 188 + mptcp_lib_wait_timeout "${timeout_test}" "${listener_ns}" \ 189 + "${connector_ns}" "${port}" "${cpid}" "${spid}" & 190 + local timeout_pid=$! 189 191 190 192 wait $cpid 191 193 local retc=$? 192 194 wait $spid 193 195 local rets=$? 194 196 197 + if kill -0 $timeout_pid; then 198 + # Finished before the timeout: kill the background job 199 + mptcp_lib_kill_group_wait $timeout_pid 200 + timeout_pid=0 201 + fi 202 + 195 203 mptcp_lib_nstat_get "${listener_ns}" 196 204 mptcp_lib_nstat_get "${connector_ns}" 197 205 198 206 print_title "Transfer ${ip:2}" 199 - if [ ${rets} -ne 0 ] || [ ${retc} -ne 0 ]; then 207 + if [ ${rets} -ne 0 ] || [ ${retc} -ne 0 ] || [ ${timeout_pid} -ne 0 ]; then 200 208 mptcp_lib_pr_fail "client exit code $retc, server $rets" 201 209 mptcp_lib_pr_err_stats "${listener_ns}" "${connector_ns}" "${port}" 202 210
+19 -10
tools/testing/selftests/net/mptcp/simult_flows.sh
··· 158 158 mptcp_lib_nstat_init "${ns3}" 159 159 mptcp_lib_nstat_init "${ns1}" 160 160 161 - timeout ${timeout_test} \ 162 - ip netns exec ${ns3} \ 163 - ./mptcp_connect -jt ${timeout_poll} -l -p $port -T $max_time \ 164 - 0.0.0.0 < "$sin" > "$sout" & 161 + ip netns exec ${ns3} \ 162 + ./mptcp_connect -jt ${timeout_poll} -l -p $port -T $max_time \ 163 + 0.0.0.0 < "$sin" > "$sout" & 165 164 local spid=$! 166 165 167 166 mptcp_lib_wait_local_port_listen "${ns3}" "${port}" 168 167 169 - timeout ${timeout_test} \ 170 - ip netns exec ${ns1} \ 171 - ./mptcp_connect -jt ${timeout_poll} -p $port -T $max_time \ 172 - 10.0.3.3 < "$cin" > "$cout" & 168 + ip netns exec ${ns1} \ 169 + ./mptcp_connect -jt ${timeout_poll} -p $port -T $max_time \ 170 + 10.0.3.3 < "$cin" > "$cout" & 173 171 local cpid=$! 172 + 173 + mptcp_lib_wait_timeout "${timeout_test}" "${ns3}" "${ns1}" "${port}" \ 174 + "${cpid}" "${spid}" & 175 + local timeout_pid=$! 174 176 175 177 wait $cpid 176 178 local retc=$? 177 179 wait $spid 178 180 local rets=$? 181 + 182 + if kill -0 $timeout_pid; then 183 + # Finished before the timeout: kill the background job 184 + mptcp_lib_kill_group_wait $timeout_pid 185 + timeout_pid=0 186 + fi 179 187 180 188 if $capture; then 181 189 sleep 1 ··· 199 191 cmp $cin $sout > /dev/null 2>&1 200 192 local cmpc=$? 201 193 202 - if [ $retc -eq 0 ] && [ $rets -eq 0 ] && \ 203 - [ $cmpc -eq 0 ] && [ $cmps -eq 0 ]; then 194 + if [ $retc -eq 0 ] && [ $rets -eq 0 ] && 195 + [ $cmpc -eq 0 ] && [ $cmps -eq 0 ] && 196 + [ $timeout_pid -eq 0 ]; then 204 197 printf "%-16s" " max $max_time " 205 198 mptcp_lib_pr_ok 206 199 cat "$capout"