diff mbox series

[net-next,v2,11/15] selftests: mptcp: add mptcp_lib_get_counter

Message ID 20231114-send-net-next-2023107-v2-11-b650a477362c@kernel.org (mailing list archive)
State Superseded
Delegated to: Netdev Maintainers
Headers show
Series mptcp: More selftest coverage and code cleanup for net-next | expand

Checks

Context Check Description
netdev/series_format success Posting correctly formatted
netdev/tree_selection success Clearly marked for net-next
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 8 this patch: 8
netdev/cc_maintainers warning 2 maintainers not CCed: linux-kselftest@vger.kernel.org shuah@kernel.org
netdev/build_clang success Errors and warnings before: 8 this patch: 8
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success net selftest script(s) already in Makefile
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 8 this patch: 8
netdev/checkpatch warning WARNING: line length of 81 exceeds 80 columns WARNING: line length of 82 exceeds 80 columns WARNING: line length of 88 exceeds 80 columns WARNING: line length of 93 exceeds 80 columns WARNING: line length of 94 exceeds 80 columns WARNING: line length of 96 exceeds 80 columns WARNING: line length of 97 exceeds 80 columns WARNING: line length of 98 exceeds 80 columns
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Mat Martineau Nov. 14, 2023, 7:56 p.m. UTC
From: Geliang Tang <geliang.tang@suse.com>

To avoid duplicated code in different MPTCP selftests, we can add
and use helpers defined in mptcp_lib.sh.

The helper get_counter() in mptcp_join.sh and get_mib_counter() in
mptcp_connect.sh have the same functionality, export get_counter() into
mptcp_lib.sh and rename it as mptcp_lib_get_counter(). Use this new
helper instead of get_counter() and get_mib_counter().

Reviewed-by: Matthieu Baerts <matttbe@kernel.org>
Signed-off-by: Geliang Tang <geliang.tang@suse.com>
Signed-off-by: Mat Martineau <martineau@kernel.org>
---
 tools/testing/selftests/net/mptcp/mptcp_connect.sh | 41 ++++------
 tools/testing/selftests/net/mptcp/mptcp_join.sh    | 88 +++++++++-------------
 tools/testing/selftests/net/mptcp/mptcp_lib.sh     | 16 ++++
 3 files changed, 65 insertions(+), 80 deletions(-)

Comments

Geliang Tang Nov. 14, 2023, 10:03 p.m. UTC | #1
On Tue, Nov 14, 2023 at 11:56:53AM -0800, Mat Martineau wrote:
> From: Geliang Tang <geliang.tang@suse.com>
> 
> To avoid duplicated code in different MPTCP selftests, we can add
> and use helpers defined in mptcp_lib.sh.
> 
> The helper get_counter() in mptcp_join.sh and get_mib_counter() in
> mptcp_connect.sh have the same functionality, export get_counter() into
> mptcp_lib.sh and rename it as mptcp_lib_get_counter(). Use this new
> helper instead of get_counter() and get_mib_counter().
> 
> Reviewed-by: Matthieu Baerts <matttbe@kernel.org>
> Signed-off-by: Geliang Tang <geliang.tang@suse.com>
> Signed-off-by: Mat Martineau <martineau@kernel.org>
> ---
>  tools/testing/selftests/net/mptcp/mptcp_connect.sh | 41 ++++------
>  tools/testing/selftests/net/mptcp/mptcp_join.sh    | 88 +++++++++-------------
>  tools/testing/selftests/net/mptcp/mptcp_lib.sh     | 16 ++++
>  3 files changed, 65 insertions(+), 80 deletions(-)

Sorry Mat, this patch needs to be updated. A squash-to patch [1] has been
merged into it last week.

Thanks,
-Geliang

[1] https://patchwork.kernel.org/project/mptcp/patch/a345cc5ff04729307b7b5b3a26f81e4e653dbefb.1699408002.git.geliang.tang@suse.com/

> 
> diff --git a/tools/testing/selftests/net/mptcp/mptcp_connect.sh b/tools/testing/selftests/net/mptcp/mptcp_connect.sh
> index 4cf62b2b0480..3b971d1617d8 100755
> --- a/tools/testing/selftests/net/mptcp/mptcp_connect.sh
> +++ b/tools/testing/selftests/net/mptcp/mptcp_connect.sh
> @@ -335,21 +335,6 @@ do_ping()
>  	return 0
>  }
>  
> -# $1: ns, $2: MIB counter
> -get_mib_counter()
> -{
> -	local listener_ns="${1}"
> -	local mib="${2}"
> -
> -	# strip the header
> -	ip netns exec "${listener_ns}" \
> -		nstat -z -a "${mib}" | \
> -			tail -n+2 | \
> -			while read a count c rest; do
> -				echo $count
> -			done
> -}
> -
>  # $1: ns, $2: port
>  wait_local_port_listen()
>  {
> @@ -435,12 +420,12 @@ do_transfer()
>  			nstat -n
>  	fi
>  
> -	local stat_synrx_last_l=$(get_mib_counter "${listener_ns}" "MPTcpExtMPCapableSYNRX")
> -	local stat_ackrx_last_l=$(get_mib_counter "${listener_ns}" "MPTcpExtMPCapableACKRX")
> -	local stat_cookietx_last=$(get_mib_counter "${listener_ns}" "TcpExtSyncookiesSent")
> -	local stat_cookierx_last=$(get_mib_counter "${listener_ns}" "TcpExtSyncookiesRecv")
> -	local stat_csum_err_s=$(get_mib_counter "${listener_ns}" "MPTcpExtDataCsumErr")
> -	local stat_csum_err_c=$(get_mib_counter "${connector_ns}" "MPTcpExtDataCsumErr")
> +	local stat_synrx_last_l=$(mptcp_lib_get_counter "${listener_ns}" "MPTcpExtMPCapableSYNRX")
> +	local stat_ackrx_last_l=$(mptcp_lib_get_counter "${listener_ns}" "MPTcpExtMPCapableACKRX")
> +	local stat_cookietx_last=$(mptcp_lib_get_counter "${listener_ns}" "TcpExtSyncookiesSent")
> +	local stat_cookierx_last=$(mptcp_lib_get_counter "${listener_ns}" "TcpExtSyncookiesRecv")
> +	local stat_csum_err_s=$(mptcp_lib_get_counter "${listener_ns}" "MPTcpExtDataCsumErr")
> +	local stat_csum_err_c=$(mptcp_lib_get_counter "${connector_ns}" "MPTcpExtDataCsumErr")
>  
>  	timeout ${timeout_test} \
>  		ip netns exec ${listener_ns} \
> @@ -503,11 +488,11 @@ do_transfer()
>  	check_transfer $cin $sout "file received by server"
>  	rets=$?
>  
> -	local stat_synrx_now_l=$(get_mib_counter "${listener_ns}" "MPTcpExtMPCapableSYNRX")
> -	local stat_ackrx_now_l=$(get_mib_counter "${listener_ns}" "MPTcpExtMPCapableACKRX")
> -	local stat_cookietx_now=$(get_mib_counter "${listener_ns}" "TcpExtSyncookiesSent")
> -	local stat_cookierx_now=$(get_mib_counter "${listener_ns}" "TcpExtSyncookiesRecv")
> -	local stat_ooo_now=$(get_mib_counter "${listener_ns}" "TcpExtTCPOFOQueue")
> +	local stat_synrx_now_l=$(mptcp_lib_get_counter "${listener_ns}" "MPTcpExtMPCapableSYNRX")
> +	local stat_ackrx_now_l=$(mptcp_lib_get_counter "${listener_ns}" "MPTcpExtMPCapableACKRX")
> +	local stat_cookietx_now=$(mptcp_lib_get_counter "${listener_ns}" "TcpExtSyncookiesSent")
> +	local stat_cookierx_now=$(mptcp_lib_get_counter "${listener_ns}" "TcpExtSyncookiesRecv")
> +	local stat_ooo_now=$(mptcp_lib_get_counter "${listener_ns}" "TcpExtTCPOFOQueue")
>  
>  	expect_synrx=$((stat_synrx_last_l))
>  	expect_ackrx=$((stat_ackrx_last_l))
> @@ -536,8 +521,8 @@ do_transfer()
>  	fi
>  
>  	if $checksum; then
> -		local csum_err_s=$(get_mib_counter "${listener_ns}" "MPTcpExtDataCsumErr")
> -		local csum_err_c=$(get_mib_counter "${connector_ns}" "MPTcpExtDataCsumErr")
> +		local csum_err_s=$(mptcp_lib_get_counter "${listener_ns}" "MPTcpExtDataCsumErr")
> +		local csum_err_c=$(mptcp_lib_get_counter "${connector_ns}" "MPTcpExtDataCsumErr")
>  
>  		local csum_err_s_nr=$((csum_err_s - stat_csum_err_s))
>  		if [ $csum_err_s_nr -gt 0 ]; then
> diff --git a/tools/testing/selftests/net/mptcp/mptcp_join.sh b/tools/testing/selftests/net/mptcp/mptcp_join.sh
> index 1f0a6c09e605..4cb6ca72f164 100755
> --- a/tools/testing/selftests/net/mptcp/mptcp_join.sh
> +++ b/tools/testing/selftests/net/mptcp/mptcp_join.sh
> @@ -605,25 +605,9 @@ wait_local_port_listen()
>  	done
>  }
>  
> -# $1: ns ; $2: counter
> -get_counter()
> -{
> -	local ns="${1}"
> -	local counter="${2}"
> -	local count
> -
> -	count=$(ip netns exec ${ns} nstat -asz "${counter}" | awk 'NR==1 {next} {print $2}')
> -	if [ -z "${count}" ]; then
> -		mptcp_lib_fail_if_expected_feature "${counter} counter"
> -		return 1
> -	fi
> -
> -	echo "${count}"
> -}
> -
>  rm_addr_count()
>  {
> -	get_counter "${1}" "MPTcpExtRmAddr"
> +	mptcp_lib_get_counter "${1}" "MPTcpExtRmAddr"
>  }
>  
>  # $1: ns, $2: old rm_addr counter in $ns
> @@ -643,7 +627,7 @@ wait_rm_addr()
>  
>  rm_sf_count()
>  {
> -	get_counter "${1}" "MPTcpExtRmSubflow"
> +	mptcp_lib_get_counter "${1}" "MPTcpExtRmSubflow"
>  }
>  
>  # $1: ns, $2: old rm_sf counter in $ns
> @@ -666,11 +650,11 @@ wait_mpj()
>  	local ns="${1}"
>  	local cnt old_cnt
>  
> -	old_cnt=$(get_counter ${ns} "MPTcpExtMPJoinAckRx")
> +	old_cnt=$(mptcp_lib_get_counter ${ns} "MPTcpExtMPJoinAckRx")
>  
>  	local i
>  	for i in $(seq 10); do
> -		cnt=$(get_counter ${ns} "MPTcpExtMPJoinAckRx")
> +		cnt=$(mptcp_lib_get_counter ${ns} "MPTcpExtMPJoinAckRx")
>  		[ "$cnt" = "${old_cnt}" ] || break
>  		sleep 0.1
>  	done
> @@ -1272,7 +1256,7 @@ chk_csum_nr()
>  	fi
>  
>  	print_check "sum"
> -	count=$(get_counter ${ns1} "MPTcpExtDataCsumErr")
> +	count=$(mptcp_lib_get_counter ${ns1} "MPTcpExtDataCsumErr")
>  	if [ "$count" != "$csum_ns1" ]; then
>  		extra_msg="$extra_msg ns1=$count"
>  	fi
> @@ -1285,7 +1269,7 @@ chk_csum_nr()
>  		print_ok
>  	fi
>  	print_check "csum"
> -	count=$(get_counter ${ns2} "MPTcpExtDataCsumErr")
> +	count=$(mptcp_lib_get_counter ${ns2} "MPTcpExtDataCsumErr")
>  	if [ "$count" != "$csum_ns2" ]; then
>  		extra_msg="$extra_msg ns2=$count"
>  	fi
> @@ -1329,7 +1313,7 @@ chk_fail_nr()
>  	fi
>  
>  	print_check "ftx"
> -	count=$(get_counter ${ns_tx} "MPTcpExtMPFailTx")
> +	count=$(mptcp_lib_get_counter ${ns_tx} "MPTcpExtMPFailTx")
>  	if [ "$count" != "$fail_tx" ]; then
>  		extra_msg="$extra_msg,tx=$count"
>  	fi
> @@ -1343,7 +1327,7 @@ chk_fail_nr()
>  	fi
>  
>  	print_check "failrx"
> -	count=$(get_counter ${ns_rx} "MPTcpExtMPFailRx")
> +	count=$(mptcp_lib_get_counter ${ns_rx} "MPTcpExtMPFailRx")
>  	if [ "$count" != "$fail_rx" ]; then
>  		extra_msg="$extra_msg,rx=$count"
>  	fi
> @@ -1376,7 +1360,7 @@ chk_fclose_nr()
>  	fi
>  
>  	print_check "ctx"
> -	count=$(get_counter ${ns_tx} "MPTcpExtMPFastcloseTx")
> +	count=$(mptcp_lib_get_counter ${ns_tx} "MPTcpExtMPFastcloseTx")
>  	if [ -z "$count" ]; then
>  		print_skip
>  	elif [ "$count" != "$fclose_tx" ]; then
> @@ -1387,7 +1371,7 @@ chk_fclose_nr()
>  	fi
>  
>  	print_check "fclzrx"
> -	count=$(get_counter ${ns_rx} "MPTcpExtMPFastcloseRx")
> +	count=$(mptcp_lib_get_counter ${ns_rx} "MPTcpExtMPFastcloseRx")
>  	if [ -z "$count" ]; then
>  		print_skip
>  	elif [ "$count" != "$fclose_rx" ]; then
> @@ -1417,7 +1401,7 @@ chk_rst_nr()
>  	fi
>  
>  	print_check "rtx"
> -	count=$(get_counter ${ns_tx} "MPTcpExtMPRstTx")
> +	count=$(mptcp_lib_get_counter ${ns_tx} "MPTcpExtMPRstTx")
>  	if [ -z "$count" ]; then
>  		print_skip
>  	# accept more rst than expected except if we don't expect any
> @@ -1429,7 +1413,7 @@ chk_rst_nr()
>  	fi
>  
>  	print_check "rstrx"
> -	count=$(get_counter ${ns_rx} "MPTcpExtMPRstRx")
> +	count=$(mptcp_lib_get_counter ${ns_rx} "MPTcpExtMPRstRx")
>  	if [ -z "$count" ]; then
>  		print_skip
>  	# accept more rst than expected except if we don't expect any
> @@ -1450,7 +1434,7 @@ chk_infi_nr()
>  	local count
>  
>  	print_check "itx"
> -	count=$(get_counter ${ns2} "MPTcpExtInfiniteMapTx")
> +	count=$(mptcp_lib_get_counter ${ns2} "MPTcpExtInfiniteMapTx")
>  	if [ -z "$count" ]; then
>  		print_skip
>  	elif [ "$count" != "$infi_tx" ]; then
> @@ -1460,7 +1444,7 @@ chk_infi_nr()
>  	fi
>  
>  	print_check "infirx"
> -	count=$(get_counter ${ns1} "MPTcpExtInfiniteMapRx")
> +	count=$(mptcp_lib_get_counter ${ns1} "MPTcpExtInfiniteMapRx")
>  	if [ -z "$count" ]; then
>  		print_skip
>  	elif [ "$count" != "$infi_rx" ]; then
> @@ -1489,7 +1473,7 @@ chk_join_nr()
>  	fi
>  
>  	print_check "syn"
> -	count=$(get_counter ${ns1} "MPTcpExtMPJoinSynRx")
> +	count=$(mptcp_lib_get_counter ${ns1} "MPTcpExtMPJoinSynRx")
>  	if [ -z "$count" ]; then
>  		print_skip
>  	elif [ "$count" != "$syn_nr" ]; then
> @@ -1500,7 +1484,7 @@ chk_join_nr()
>  
>  	print_check "synack"
>  	with_cookie=$(ip netns exec $ns2 sysctl -n net.ipv4.tcp_syncookies)
> -	count=$(get_counter ${ns2} "MPTcpExtMPJoinSynAckRx")
> +	count=$(mptcp_lib_get_counter ${ns2} "MPTcpExtMPJoinSynAckRx")
>  	if [ -z "$count" ]; then
>  		print_skip
>  	elif [ "$count" != "$syn_ack_nr" ]; then
> @@ -1517,7 +1501,7 @@ chk_join_nr()
>  	fi
>  
>  	print_check "ack"
> -	count=$(get_counter ${ns1} "MPTcpExtMPJoinAckRx")
> +	count=$(mptcp_lib_get_counter ${ns1} "MPTcpExtMPJoinAckRx")
>  	if [ -z "$count" ]; then
>  		print_skip
>  	elif [ "$count" != "$ack_nr" ]; then
> @@ -1550,8 +1534,8 @@ chk_stale_nr()
>  
>  	print_check "stale"
>  
> -	stale_nr=$(get_counter ${ns} "MPTcpExtSubflowStale")
> -	recover_nr=$(get_counter ${ns} "MPTcpExtSubflowRecover")
> +	stale_nr=$(mptcp_lib_get_counter ${ns} "MPTcpExtSubflowStale")
> +	recover_nr=$(mptcp_lib_get_counter ${ns} "MPTcpExtSubflowRecover")
>  	if [ -z "$stale_nr" ] || [ -z "$recover_nr" ]; then
>  		print_skip
>  	elif [ $stale_nr -lt $stale_min ] ||
> @@ -1588,7 +1572,7 @@ chk_add_nr()
>  	timeout=$(ip netns exec $ns1 sysctl -n net.mptcp.add_addr_timeout)
>  
>  	print_check "add"
> -	count=$(get_counter ${ns2} "MPTcpExtAddAddr")
> +	count=$(mptcp_lib_get_counter ${ns2} "MPTcpExtAddAddr")
>  	if [ -z "$count" ]; then
>  		print_skip
>  	# if the test configured a short timeout tolerate greater then expected
> @@ -1600,7 +1584,7 @@ chk_add_nr()
>  	fi
>  
>  	print_check "echo"
> -	count=$(get_counter ${ns1} "MPTcpExtEchoAdd")
> +	count=$(mptcp_lib_get_counter ${ns1} "MPTcpExtEchoAdd")
>  	if [ -z "$count" ]; then
>  		print_skip
>  	elif [ "$count" != "$echo_nr" ]; then
> @@ -1611,7 +1595,7 @@ chk_add_nr()
>  
>  	if [ $port_nr -gt 0 ]; then
>  		print_check "pt"
> -		count=$(get_counter ${ns2} "MPTcpExtPortAdd")
> +		count=$(mptcp_lib_get_counter ${ns2} "MPTcpExtPortAdd")
>  		if [ -z "$count" ]; then
>  			print_skip
>  		elif [ "$count" != "$port_nr" ]; then
> @@ -1621,7 +1605,7 @@ chk_add_nr()
>  		fi
>  
>  		print_check "syn"
> -		count=$(get_counter ${ns1} "MPTcpExtMPJoinPortSynRx")
> +		count=$(mptcp_lib_get_counter ${ns1} "MPTcpExtMPJoinPortSynRx")
>  		if [ -z "$count" ]; then
>  			print_skip
>  		elif [ "$count" != "$syn_nr" ]; then
> @@ -1632,7 +1616,7 @@ chk_add_nr()
>  		fi
>  
>  		print_check "synack"
> -		count=$(get_counter ${ns2} "MPTcpExtMPJoinPortSynAckRx")
> +		count=$(mptcp_lib_get_counter ${ns2} "MPTcpExtMPJoinPortSynAckRx")
>  		if [ -z "$count" ]; then
>  			print_skip
>  		elif [ "$count" != "$syn_ack_nr" ]; then
> @@ -1643,7 +1627,7 @@ chk_add_nr()
>  		fi
>  
>  		print_check "ack"
> -		count=$(get_counter ${ns1} "MPTcpExtMPJoinPortAckRx")
> +		count=$(mptcp_lib_get_counter ${ns1} "MPTcpExtMPJoinPortAckRx")
>  		if [ -z "$count" ]; then
>  			print_skip
>  		elif [ "$count" != "$ack_nr" ]; then
> @@ -1654,7 +1638,7 @@ chk_add_nr()
>  		fi
>  
>  		print_check "syn"
> -		count=$(get_counter ${ns1} "MPTcpExtMismatchPortSynRx")
> +		count=$(mptcp_lib_get_counter ${ns1} "MPTcpExtMismatchPortSynRx")
>  		if [ -z "$count" ]; then
>  			print_skip
>  		elif [ "$count" != "$mis_syn_nr" ]; then
> @@ -1665,7 +1649,7 @@ chk_add_nr()
>  		fi
>  
>  		print_check "ack"
> -		count=$(get_counter ${ns1} "MPTcpExtMismatchPortAckRx")
> +		count=$(mptcp_lib_get_counter ${ns1} "MPTcpExtMismatchPortAckRx")
>  		if [ -z "$count" ]; then
>  			print_skip
>  		elif [ "$count" != "$mis_ack_nr" ]; then
> @@ -1687,7 +1671,7 @@ chk_add_tx_nr()
>  	timeout=$(ip netns exec $ns1 sysctl -n net.mptcp.add_addr_timeout)
>  
>  	print_check "add TX"
> -	count=$(get_counter ${ns1} "MPTcpExtAddAddrTx")
> +	count=$(mptcp_lib_get_counter ${ns1} "MPTcpExtAddAddrTx")
>  	if [ -z "$count" ]; then
>  		print_skip
>  	# if the test configured a short timeout tolerate greater then expected
> @@ -1699,7 +1683,7 @@ chk_add_tx_nr()
>  	fi
>  
>  	print_check "echo TX"
> -	count=$(get_counter ${ns2} "MPTcpExtEchoAddTx")
> +	count=$(mptcp_lib_get_counter ${ns2} "MPTcpExtEchoAddTx")
>  	if [ -z "$count" ]; then
>  		print_skip
>  	elif [ "$count" != "$echo_tx_nr" ]; then
> @@ -1737,7 +1721,7 @@ chk_rm_nr()
>  	fi
>  
>  	print_check "rm"
> -	count=$(get_counter ${addr_ns} "MPTcpExtRmAddr")
> +	count=$(mptcp_lib_get_counter ${addr_ns} "MPTcpExtRmAddr")
>  	if [ -z "$count" ]; then
>  		print_skip
>  	elif [ "$count" != "$rm_addr_nr" ]; then
> @@ -1747,13 +1731,13 @@ chk_rm_nr()
>  	fi
>  
>  	print_check "rmsf"
> -	count=$(get_counter ${subflow_ns} "MPTcpExtRmSubflow")
> +	count=$(mptcp_lib_get_counter ${subflow_ns} "MPTcpExtRmSubflow")
>  	if [ -z "$count" ]; then
>  		print_skip
>  	elif [ -n "$simult" ]; then
>  		local cnt suffix
>  
> -		cnt=$(get_counter ${addr_ns} "MPTcpExtRmSubflow")
> +		cnt=$(mptcp_lib_get_counter ${addr_ns} "MPTcpExtRmSubflow")
>  
>  		# in case of simult flush, the subflow removal count on each side is
>  		# unreliable
> @@ -1782,7 +1766,7 @@ chk_rm_tx_nr()
>  	local rm_addr_tx_nr=$1
>  
>  	print_check "rm TX"
> -	count=$(get_counter ${ns2} "MPTcpExtRmAddrTx")
> +	count=$(mptcp_lib_get_counter ${ns2} "MPTcpExtRmAddrTx")
>  	if [ -z "$count" ]; then
>  		print_skip
>  	elif [ "$count" != "$rm_addr_tx_nr" ]; then
> @@ -1799,7 +1783,7 @@ chk_prio_nr()
>  	local count
>  
>  	print_check "ptx"
> -	count=$(get_counter ${ns1} "MPTcpExtMPPrioTx")
> +	count=$(mptcp_lib_get_counter ${ns1} "MPTcpExtMPPrioTx")
>  	if [ -z "$count" ]; then
>  		print_skip
>  	elif [ "$count" != "$mp_prio_nr_tx" ]; then
> @@ -1809,7 +1793,7 @@ chk_prio_nr()
>  	fi
>  
>  	print_check "prx"
> -	count=$(get_counter ${ns1} "MPTcpExtMPPrioRx")
> +	count=$(mptcp_lib_get_counter ${ns1} "MPTcpExtMPPrioRx")
>  	if [ -z "$count" ]; then
>  		print_skip
>  	elif [ "$count" != "$mp_prio_nr_rx" ]; then
> @@ -1942,7 +1926,7 @@ wait_attempt_fail()
>  	while [ $time -lt $timeout_ms ]; do
>  		local cnt
>  
> -		cnt=$(get_counter ${ns} "TcpAttemptFails")
> +		cnt=$(mptcp_lib_get_counter ${ns} "TcpAttemptFails")
>  
>  		[ "$cnt" = 1 ] && return 1
>  		time=$((time + 100))
> diff --git a/tools/testing/selftests/net/mptcp/mptcp_lib.sh b/tools/testing/selftests/net/mptcp/mptcp_lib.sh
> index 447292cad33c..718c79dda2b3 100644
> --- a/tools/testing/selftests/net/mptcp/mptcp_lib.sh
> +++ b/tools/testing/selftests/net/mptcp/mptcp_lib.sh
> @@ -231,3 +231,19 @@ mptcp_lib_kill_wait() {
>  mptcp_lib_is_v6() {
>  	[ -z "${1##*:*}" ]
>  }
> +
> +# $1: ns, $2: MIB counter
> +mptcp_lib_get_counter() {
> +	local ns="${1}"
> +	local counter="${2}"
> +	local count
> +
> +	count=$(ip netns exec "${ns}" nstat -asz "${counter}" |
> +		awk 'NR==1 {next} {print $2}')
> +	if [ -z "${count}" ]; then
> +		mptcp_lib_fail_if_expected_feature "${counter} counter"
> +		return 1
> +	fi
> +
> +	echo "${count}"
> +}
> 
> -- 
> 2.41.0
>
diff mbox series

Patch

diff --git a/tools/testing/selftests/net/mptcp/mptcp_connect.sh b/tools/testing/selftests/net/mptcp/mptcp_connect.sh
index 4cf62b2b0480..3b971d1617d8 100755
--- a/tools/testing/selftests/net/mptcp/mptcp_connect.sh
+++ b/tools/testing/selftests/net/mptcp/mptcp_connect.sh
@@ -335,21 +335,6 @@  do_ping()
 	return 0
 }
 
-# $1: ns, $2: MIB counter
-get_mib_counter()
-{
-	local listener_ns="${1}"
-	local mib="${2}"
-
-	# strip the header
-	ip netns exec "${listener_ns}" \
-		nstat -z -a "${mib}" | \
-			tail -n+2 | \
-			while read a count c rest; do
-				echo $count
-			done
-}
-
 # $1: ns, $2: port
 wait_local_port_listen()
 {
@@ -435,12 +420,12 @@  do_transfer()
 			nstat -n
 	fi
 
-	local stat_synrx_last_l=$(get_mib_counter "${listener_ns}" "MPTcpExtMPCapableSYNRX")
-	local stat_ackrx_last_l=$(get_mib_counter "${listener_ns}" "MPTcpExtMPCapableACKRX")
-	local stat_cookietx_last=$(get_mib_counter "${listener_ns}" "TcpExtSyncookiesSent")
-	local stat_cookierx_last=$(get_mib_counter "${listener_ns}" "TcpExtSyncookiesRecv")
-	local stat_csum_err_s=$(get_mib_counter "${listener_ns}" "MPTcpExtDataCsumErr")
-	local stat_csum_err_c=$(get_mib_counter "${connector_ns}" "MPTcpExtDataCsumErr")
+	local stat_synrx_last_l=$(mptcp_lib_get_counter "${listener_ns}" "MPTcpExtMPCapableSYNRX")
+	local stat_ackrx_last_l=$(mptcp_lib_get_counter "${listener_ns}" "MPTcpExtMPCapableACKRX")
+	local stat_cookietx_last=$(mptcp_lib_get_counter "${listener_ns}" "TcpExtSyncookiesSent")
+	local stat_cookierx_last=$(mptcp_lib_get_counter "${listener_ns}" "TcpExtSyncookiesRecv")
+	local stat_csum_err_s=$(mptcp_lib_get_counter "${listener_ns}" "MPTcpExtDataCsumErr")
+	local stat_csum_err_c=$(mptcp_lib_get_counter "${connector_ns}" "MPTcpExtDataCsumErr")
 
 	timeout ${timeout_test} \
 		ip netns exec ${listener_ns} \
@@ -503,11 +488,11 @@  do_transfer()
 	check_transfer $cin $sout "file received by server"
 	rets=$?
 
-	local stat_synrx_now_l=$(get_mib_counter "${listener_ns}" "MPTcpExtMPCapableSYNRX")
-	local stat_ackrx_now_l=$(get_mib_counter "${listener_ns}" "MPTcpExtMPCapableACKRX")
-	local stat_cookietx_now=$(get_mib_counter "${listener_ns}" "TcpExtSyncookiesSent")
-	local stat_cookierx_now=$(get_mib_counter "${listener_ns}" "TcpExtSyncookiesRecv")
-	local stat_ooo_now=$(get_mib_counter "${listener_ns}" "TcpExtTCPOFOQueue")
+	local stat_synrx_now_l=$(mptcp_lib_get_counter "${listener_ns}" "MPTcpExtMPCapableSYNRX")
+	local stat_ackrx_now_l=$(mptcp_lib_get_counter "${listener_ns}" "MPTcpExtMPCapableACKRX")
+	local stat_cookietx_now=$(mptcp_lib_get_counter "${listener_ns}" "TcpExtSyncookiesSent")
+	local stat_cookierx_now=$(mptcp_lib_get_counter "${listener_ns}" "TcpExtSyncookiesRecv")
+	local stat_ooo_now=$(mptcp_lib_get_counter "${listener_ns}" "TcpExtTCPOFOQueue")
 
 	expect_synrx=$((stat_synrx_last_l))
 	expect_ackrx=$((stat_ackrx_last_l))
@@ -536,8 +521,8 @@  do_transfer()
 	fi
 
 	if $checksum; then
-		local csum_err_s=$(get_mib_counter "${listener_ns}" "MPTcpExtDataCsumErr")
-		local csum_err_c=$(get_mib_counter "${connector_ns}" "MPTcpExtDataCsumErr")
+		local csum_err_s=$(mptcp_lib_get_counter "${listener_ns}" "MPTcpExtDataCsumErr")
+		local csum_err_c=$(mptcp_lib_get_counter "${connector_ns}" "MPTcpExtDataCsumErr")
 
 		local csum_err_s_nr=$((csum_err_s - stat_csum_err_s))
 		if [ $csum_err_s_nr -gt 0 ]; then
diff --git a/tools/testing/selftests/net/mptcp/mptcp_join.sh b/tools/testing/selftests/net/mptcp/mptcp_join.sh
index 1f0a6c09e605..4cb6ca72f164 100755
--- a/tools/testing/selftests/net/mptcp/mptcp_join.sh
+++ b/tools/testing/selftests/net/mptcp/mptcp_join.sh
@@ -605,25 +605,9 @@  wait_local_port_listen()
 	done
 }
 
-# $1: ns ; $2: counter
-get_counter()
-{
-	local ns="${1}"
-	local counter="${2}"
-	local count
-
-	count=$(ip netns exec ${ns} nstat -asz "${counter}" | awk 'NR==1 {next} {print $2}')
-	if [ -z "${count}" ]; then
-		mptcp_lib_fail_if_expected_feature "${counter} counter"
-		return 1
-	fi
-
-	echo "${count}"
-}
-
 rm_addr_count()
 {
-	get_counter "${1}" "MPTcpExtRmAddr"
+	mptcp_lib_get_counter "${1}" "MPTcpExtRmAddr"
 }
 
 # $1: ns, $2: old rm_addr counter in $ns
@@ -643,7 +627,7 @@  wait_rm_addr()
 
 rm_sf_count()
 {
-	get_counter "${1}" "MPTcpExtRmSubflow"
+	mptcp_lib_get_counter "${1}" "MPTcpExtRmSubflow"
 }
 
 # $1: ns, $2: old rm_sf counter in $ns
@@ -666,11 +650,11 @@  wait_mpj()
 	local ns="${1}"
 	local cnt old_cnt
 
-	old_cnt=$(get_counter ${ns} "MPTcpExtMPJoinAckRx")
+	old_cnt=$(mptcp_lib_get_counter ${ns} "MPTcpExtMPJoinAckRx")
 
 	local i
 	for i in $(seq 10); do
-		cnt=$(get_counter ${ns} "MPTcpExtMPJoinAckRx")
+		cnt=$(mptcp_lib_get_counter ${ns} "MPTcpExtMPJoinAckRx")
 		[ "$cnt" = "${old_cnt}" ] || break
 		sleep 0.1
 	done
@@ -1272,7 +1256,7 @@  chk_csum_nr()
 	fi
 
 	print_check "sum"
-	count=$(get_counter ${ns1} "MPTcpExtDataCsumErr")
+	count=$(mptcp_lib_get_counter ${ns1} "MPTcpExtDataCsumErr")
 	if [ "$count" != "$csum_ns1" ]; then
 		extra_msg="$extra_msg ns1=$count"
 	fi
@@ -1285,7 +1269,7 @@  chk_csum_nr()
 		print_ok
 	fi
 	print_check "csum"
-	count=$(get_counter ${ns2} "MPTcpExtDataCsumErr")
+	count=$(mptcp_lib_get_counter ${ns2} "MPTcpExtDataCsumErr")
 	if [ "$count" != "$csum_ns2" ]; then
 		extra_msg="$extra_msg ns2=$count"
 	fi
@@ -1329,7 +1313,7 @@  chk_fail_nr()
 	fi
 
 	print_check "ftx"
-	count=$(get_counter ${ns_tx} "MPTcpExtMPFailTx")
+	count=$(mptcp_lib_get_counter ${ns_tx} "MPTcpExtMPFailTx")
 	if [ "$count" != "$fail_tx" ]; then
 		extra_msg="$extra_msg,tx=$count"
 	fi
@@ -1343,7 +1327,7 @@  chk_fail_nr()
 	fi
 
 	print_check "failrx"
-	count=$(get_counter ${ns_rx} "MPTcpExtMPFailRx")
+	count=$(mptcp_lib_get_counter ${ns_rx} "MPTcpExtMPFailRx")
 	if [ "$count" != "$fail_rx" ]; then
 		extra_msg="$extra_msg,rx=$count"
 	fi
@@ -1376,7 +1360,7 @@  chk_fclose_nr()
 	fi
 
 	print_check "ctx"
-	count=$(get_counter ${ns_tx} "MPTcpExtMPFastcloseTx")
+	count=$(mptcp_lib_get_counter ${ns_tx} "MPTcpExtMPFastcloseTx")
 	if [ -z "$count" ]; then
 		print_skip
 	elif [ "$count" != "$fclose_tx" ]; then
@@ -1387,7 +1371,7 @@  chk_fclose_nr()
 	fi
 
 	print_check "fclzrx"
-	count=$(get_counter ${ns_rx} "MPTcpExtMPFastcloseRx")
+	count=$(mptcp_lib_get_counter ${ns_rx} "MPTcpExtMPFastcloseRx")
 	if [ -z "$count" ]; then
 		print_skip
 	elif [ "$count" != "$fclose_rx" ]; then
@@ -1417,7 +1401,7 @@  chk_rst_nr()
 	fi
 
 	print_check "rtx"
-	count=$(get_counter ${ns_tx} "MPTcpExtMPRstTx")
+	count=$(mptcp_lib_get_counter ${ns_tx} "MPTcpExtMPRstTx")
 	if [ -z "$count" ]; then
 		print_skip
 	# accept more rst than expected except if we don't expect any
@@ -1429,7 +1413,7 @@  chk_rst_nr()
 	fi
 
 	print_check "rstrx"
-	count=$(get_counter ${ns_rx} "MPTcpExtMPRstRx")
+	count=$(mptcp_lib_get_counter ${ns_rx} "MPTcpExtMPRstRx")
 	if [ -z "$count" ]; then
 		print_skip
 	# accept more rst than expected except if we don't expect any
@@ -1450,7 +1434,7 @@  chk_infi_nr()
 	local count
 
 	print_check "itx"
-	count=$(get_counter ${ns2} "MPTcpExtInfiniteMapTx")
+	count=$(mptcp_lib_get_counter ${ns2} "MPTcpExtInfiniteMapTx")
 	if [ -z "$count" ]; then
 		print_skip
 	elif [ "$count" != "$infi_tx" ]; then
@@ -1460,7 +1444,7 @@  chk_infi_nr()
 	fi
 
 	print_check "infirx"
-	count=$(get_counter ${ns1} "MPTcpExtInfiniteMapRx")
+	count=$(mptcp_lib_get_counter ${ns1} "MPTcpExtInfiniteMapRx")
 	if [ -z "$count" ]; then
 		print_skip
 	elif [ "$count" != "$infi_rx" ]; then
@@ -1489,7 +1473,7 @@  chk_join_nr()
 	fi
 
 	print_check "syn"
-	count=$(get_counter ${ns1} "MPTcpExtMPJoinSynRx")
+	count=$(mptcp_lib_get_counter ${ns1} "MPTcpExtMPJoinSynRx")
 	if [ -z "$count" ]; then
 		print_skip
 	elif [ "$count" != "$syn_nr" ]; then
@@ -1500,7 +1484,7 @@  chk_join_nr()
 
 	print_check "synack"
 	with_cookie=$(ip netns exec $ns2 sysctl -n net.ipv4.tcp_syncookies)
-	count=$(get_counter ${ns2} "MPTcpExtMPJoinSynAckRx")
+	count=$(mptcp_lib_get_counter ${ns2} "MPTcpExtMPJoinSynAckRx")
 	if [ -z "$count" ]; then
 		print_skip
 	elif [ "$count" != "$syn_ack_nr" ]; then
@@ -1517,7 +1501,7 @@  chk_join_nr()
 	fi
 
 	print_check "ack"
-	count=$(get_counter ${ns1} "MPTcpExtMPJoinAckRx")
+	count=$(mptcp_lib_get_counter ${ns1} "MPTcpExtMPJoinAckRx")
 	if [ -z "$count" ]; then
 		print_skip
 	elif [ "$count" != "$ack_nr" ]; then
@@ -1550,8 +1534,8 @@  chk_stale_nr()
 
 	print_check "stale"
 
-	stale_nr=$(get_counter ${ns} "MPTcpExtSubflowStale")
-	recover_nr=$(get_counter ${ns} "MPTcpExtSubflowRecover")
+	stale_nr=$(mptcp_lib_get_counter ${ns} "MPTcpExtSubflowStale")
+	recover_nr=$(mptcp_lib_get_counter ${ns} "MPTcpExtSubflowRecover")
 	if [ -z "$stale_nr" ] || [ -z "$recover_nr" ]; then
 		print_skip
 	elif [ $stale_nr -lt $stale_min ] ||
@@ -1588,7 +1572,7 @@  chk_add_nr()
 	timeout=$(ip netns exec $ns1 sysctl -n net.mptcp.add_addr_timeout)
 
 	print_check "add"
-	count=$(get_counter ${ns2} "MPTcpExtAddAddr")
+	count=$(mptcp_lib_get_counter ${ns2} "MPTcpExtAddAddr")
 	if [ -z "$count" ]; then
 		print_skip
 	# if the test configured a short timeout tolerate greater then expected
@@ -1600,7 +1584,7 @@  chk_add_nr()
 	fi
 
 	print_check "echo"
-	count=$(get_counter ${ns1} "MPTcpExtEchoAdd")
+	count=$(mptcp_lib_get_counter ${ns1} "MPTcpExtEchoAdd")
 	if [ -z "$count" ]; then
 		print_skip
 	elif [ "$count" != "$echo_nr" ]; then
@@ -1611,7 +1595,7 @@  chk_add_nr()
 
 	if [ $port_nr -gt 0 ]; then
 		print_check "pt"
-		count=$(get_counter ${ns2} "MPTcpExtPortAdd")
+		count=$(mptcp_lib_get_counter ${ns2} "MPTcpExtPortAdd")
 		if [ -z "$count" ]; then
 			print_skip
 		elif [ "$count" != "$port_nr" ]; then
@@ -1621,7 +1605,7 @@  chk_add_nr()
 		fi
 
 		print_check "syn"
-		count=$(get_counter ${ns1} "MPTcpExtMPJoinPortSynRx")
+		count=$(mptcp_lib_get_counter ${ns1} "MPTcpExtMPJoinPortSynRx")
 		if [ -z "$count" ]; then
 			print_skip
 		elif [ "$count" != "$syn_nr" ]; then
@@ -1632,7 +1616,7 @@  chk_add_nr()
 		fi
 
 		print_check "synack"
-		count=$(get_counter ${ns2} "MPTcpExtMPJoinPortSynAckRx")
+		count=$(mptcp_lib_get_counter ${ns2} "MPTcpExtMPJoinPortSynAckRx")
 		if [ -z "$count" ]; then
 			print_skip
 		elif [ "$count" != "$syn_ack_nr" ]; then
@@ -1643,7 +1627,7 @@  chk_add_nr()
 		fi
 
 		print_check "ack"
-		count=$(get_counter ${ns1} "MPTcpExtMPJoinPortAckRx")
+		count=$(mptcp_lib_get_counter ${ns1} "MPTcpExtMPJoinPortAckRx")
 		if [ -z "$count" ]; then
 			print_skip
 		elif [ "$count" != "$ack_nr" ]; then
@@ -1654,7 +1638,7 @@  chk_add_nr()
 		fi
 
 		print_check "syn"
-		count=$(get_counter ${ns1} "MPTcpExtMismatchPortSynRx")
+		count=$(mptcp_lib_get_counter ${ns1} "MPTcpExtMismatchPortSynRx")
 		if [ -z "$count" ]; then
 			print_skip
 		elif [ "$count" != "$mis_syn_nr" ]; then
@@ -1665,7 +1649,7 @@  chk_add_nr()
 		fi
 
 		print_check "ack"
-		count=$(get_counter ${ns1} "MPTcpExtMismatchPortAckRx")
+		count=$(mptcp_lib_get_counter ${ns1} "MPTcpExtMismatchPortAckRx")
 		if [ -z "$count" ]; then
 			print_skip
 		elif [ "$count" != "$mis_ack_nr" ]; then
@@ -1687,7 +1671,7 @@  chk_add_tx_nr()
 	timeout=$(ip netns exec $ns1 sysctl -n net.mptcp.add_addr_timeout)
 
 	print_check "add TX"
-	count=$(get_counter ${ns1} "MPTcpExtAddAddrTx")
+	count=$(mptcp_lib_get_counter ${ns1} "MPTcpExtAddAddrTx")
 	if [ -z "$count" ]; then
 		print_skip
 	# if the test configured a short timeout tolerate greater then expected
@@ -1699,7 +1683,7 @@  chk_add_tx_nr()
 	fi
 
 	print_check "echo TX"
-	count=$(get_counter ${ns2} "MPTcpExtEchoAddTx")
+	count=$(mptcp_lib_get_counter ${ns2} "MPTcpExtEchoAddTx")
 	if [ -z "$count" ]; then
 		print_skip
 	elif [ "$count" != "$echo_tx_nr" ]; then
@@ -1737,7 +1721,7 @@  chk_rm_nr()
 	fi
 
 	print_check "rm"
-	count=$(get_counter ${addr_ns} "MPTcpExtRmAddr")
+	count=$(mptcp_lib_get_counter ${addr_ns} "MPTcpExtRmAddr")
 	if [ -z "$count" ]; then
 		print_skip
 	elif [ "$count" != "$rm_addr_nr" ]; then
@@ -1747,13 +1731,13 @@  chk_rm_nr()
 	fi
 
 	print_check "rmsf"
-	count=$(get_counter ${subflow_ns} "MPTcpExtRmSubflow")
+	count=$(mptcp_lib_get_counter ${subflow_ns} "MPTcpExtRmSubflow")
 	if [ -z "$count" ]; then
 		print_skip
 	elif [ -n "$simult" ]; then
 		local cnt suffix
 
-		cnt=$(get_counter ${addr_ns} "MPTcpExtRmSubflow")
+		cnt=$(mptcp_lib_get_counter ${addr_ns} "MPTcpExtRmSubflow")
 
 		# in case of simult flush, the subflow removal count on each side is
 		# unreliable
@@ -1782,7 +1766,7 @@  chk_rm_tx_nr()
 	local rm_addr_tx_nr=$1
 
 	print_check "rm TX"
-	count=$(get_counter ${ns2} "MPTcpExtRmAddrTx")
+	count=$(mptcp_lib_get_counter ${ns2} "MPTcpExtRmAddrTx")
 	if [ -z "$count" ]; then
 		print_skip
 	elif [ "$count" != "$rm_addr_tx_nr" ]; then
@@ -1799,7 +1783,7 @@  chk_prio_nr()
 	local count
 
 	print_check "ptx"
-	count=$(get_counter ${ns1} "MPTcpExtMPPrioTx")
+	count=$(mptcp_lib_get_counter ${ns1} "MPTcpExtMPPrioTx")
 	if [ -z "$count" ]; then
 		print_skip
 	elif [ "$count" != "$mp_prio_nr_tx" ]; then
@@ -1809,7 +1793,7 @@  chk_prio_nr()
 	fi
 
 	print_check "prx"
-	count=$(get_counter ${ns1} "MPTcpExtMPPrioRx")
+	count=$(mptcp_lib_get_counter ${ns1} "MPTcpExtMPPrioRx")
 	if [ -z "$count" ]; then
 		print_skip
 	elif [ "$count" != "$mp_prio_nr_rx" ]; then
@@ -1942,7 +1926,7 @@  wait_attempt_fail()
 	while [ $time -lt $timeout_ms ]; do
 		local cnt
 
-		cnt=$(get_counter ${ns} "TcpAttemptFails")
+		cnt=$(mptcp_lib_get_counter ${ns} "TcpAttemptFails")
 
 		[ "$cnt" = 1 ] && return 1
 		time=$((time + 100))
diff --git a/tools/testing/selftests/net/mptcp/mptcp_lib.sh b/tools/testing/selftests/net/mptcp/mptcp_lib.sh
index 447292cad33c..718c79dda2b3 100644
--- a/tools/testing/selftests/net/mptcp/mptcp_lib.sh
+++ b/tools/testing/selftests/net/mptcp/mptcp_lib.sh
@@ -231,3 +231,19 @@  mptcp_lib_kill_wait() {
 mptcp_lib_is_v6() {
 	[ -z "${1##*:*}" ]
 }
+
+# $1: ns, $2: MIB counter
+mptcp_lib_get_counter() {
+	local ns="${1}"
+	local counter="${2}"
+	local count
+
+	count=$(ip netns exec "${ns}" nstat -asz "${counter}" |
+		awk 'NR==1 {next} {print $2}')
+	if [ -z "${count}" ]; then
+		mptcp_lib_fail_if_expected_feature "${counter} counter"
+		return 1
+	fi
+
+	echo "${count}"
+}