Commit eea2f448 authored by Matthieu Baerts (NGI0)'s avatar Matthieu Baerts (NGI0) Committed by Jakub Kicinski
Browse files

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: default avatarGeliang Tang <geliang@kernel.org>
Signed-off-by: default avatarMatthieu 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: default avatarJakub Kicinski <kuba@kernel.org>
parent 39348f5f
Loading
Loading
Loading
Loading
+17 −9
Original line number Diff line number Diff line
@@ -393,7 +393,6 @@ 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" &
@@ -403,17 +402,26 @@ do_transfer()

	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" &
	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}"

+20 −14
Original line number Diff line number Diff line
@@ -1024,7 +1024,6 @@ 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}" &
@@ -1034,7 +1033,6 @@ do_transfer()

	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" &
@@ -1042,20 +1040,22 @@ do_transfer()
		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" &
	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
+13 −0
Original line number Diff line number Diff line
@@ -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
+17 −9
Original line number Diff line number Diff line
@@ -172,7 +172,6 @@ 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" &
@@ -180,23 +179,32 @@ do_transfer()

	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" &

	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}"

+19 −10
Original line number Diff line number Diff line
@@ -158,7 +158,6 @@ 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" &
@@ -166,17 +165,26 @@ do_transfer()

	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" &
	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"