Subject: Re: [PATCH net 2/2] selftests: mptcp: explicitly trigger the listener diag code-path

From: Simon Horman <[email-masked]>
Date: Thu, 22 Feb 2024 13:13:38 +0000

On Wed, Feb 22, 2024 at 12:46:59PM +0100, Paolo Abeni wrote:
>l The mptcp diag interface already experienced a few locking bugs
> that lockdep and appropriate coverage have detected in advance.
> 
> Let's add a test-case triggering the relevant code path, to prevent
> similar issues in the future.
> 
> Signed-off-by: Paolo Abeni <[email-masked]>
> ---
>  tools/testing/selftests/net/mptcp/diag.sh | 30 +++++++++++++++++++++++
>  1 file changed, 30 insertions(+)
> 
> diff --git a/tools/testing/selftests/net/mptcp/diag.sh b/tools/testing/selftests/net/mptcp/diag.sh
> index 60a7009ce1b5..3ab584b38566 100755
> --- a/tools/testing/selftests/net/mptcp/diag.sh
> +++ b/tools/testing/selftests/net/mptcp/diag.sh
> @@ -81,6 +81,21 @@ chk_msk_nr()
>  	__chk_msk_nr "grep -c token:" "$@"
>  }
>  
> +chk_listener_nr()
> +{
> +	local expected=$1
> +	local msg="$2"
> +
> +	if [ $expected -gt 0 ] && \
> +	   ! mptcp_lib_kallsyms_has "mptcp_diag_dump_listeners"; then
> +		printf "%-50s%s\n" "$msg - mptcp" "[ skip ]"
> +		mptcp_lib_result_skip "many listener sockets"
> +	else
> +		__chk_nr "ss -inmlHMON $ns | wc -l" "$expected" "$msg - mptcp"
> +	fi
> +	__chk_nr "ss -inmlHtON $ns | wc -l" "$expected" "$msg - subflows"
> +}
> +
>  wait_msk_nr()
>  {
>  	local condition="grep -c token:"
> @@ -279,5 +294,20 @@ flush_pids
>  chk_msk_inuse 0 "many->0"
>  chk_msk_cestab 0 "many->0"
>  
> +chk_listener_nr 0 "no listener sockets"
> +NR_SERVERS=100
> +for I in $(seq 1 $NR_SERVERS); do
> +	ip netns exec $ns ./mptcp_connect -p $((I + 20001)) -l 0.0.0.0 2>&1 >/dev/null &
> +	mptcp_lib_wait_local_port_listen $ns $((I + 20001))
> +done
> +
> +chk_listener_nr $NR_SERVERS "many listener sockets"
> +
> +# gracefull termination

nit, as you plan to re-spin anyway: graceful

> +for I in $(seq 1 $NR_SERVERS); do
> +	echo a | ip netns exec $ns ./mptcp_connect -p $((I + 20001)) 127.0.0.1 2>&1 >/dev/null

I'm not sure of the validity of this but shellcheck complains that:

  SC2069 (warning): To redirect stdout+stderr, 2>&1 must be last (or use '{ cmd > file; } 2>&1' to clarify).

Also for the same constriction slightly earlier in this patch.

> +done
> +flush_pids
> +
>  mptcp_lib_result_print_all_tap
>  exit $ret
> -- 
> 2.43.0
> 
>