[PATCH mptcp-next v15 5/7] selftests: mptcp: check add_addr infos

Geliang Tang posted 7 patches 2 years, 8 months ago
Maintainers: Matthieu Baerts <matthieu.baerts@tessares.net>, Mat Martineau <martineau@kernel.org>, "David S. Miller" <davem@davemloft.net>, Eric Dumazet <edumazet@google.com>, Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>, Shuah Khan <shuah@kernel.org>
There is a newer version of this series
[PATCH mptcp-next v15 5/7] selftests: mptcp: check add_addr infos
Posted by Geliang Tang 2 years, 8 months ago
This patch checks add_addr_signal and add_addr_accepted in
chk_mptcp_info(), and do this checks in userspace_tests()
and endpoint_tests().

Signed-off-by: Geliang Tang <geliang.tang@suse.com>
---
 .../testing/selftests/net/mptcp/mptcp_join.sh | 26 ++++++++++++-------
 1 file changed, 16 insertions(+), 10 deletions(-)

diff --git a/tools/testing/selftests/net/mptcp/mptcp_join.sh b/tools/testing/selftests/net/mptcp/mptcp_join.sh
index 75f1c69ae78b..60cdc36d280f 100755
--- a/tools/testing/selftests/net/mptcp/mptcp_join.sh
+++ b/tools/testing/selftests/net/mptcp/mptcp_join.sh
@@ -1816,13 +1816,17 @@ chk_subflow_nr()
 chk_mptcp_info()
 {
 	local nr_info=$1
-	local info
-	local cnt1
-	local cnt2
+	local info1 info2
+	local cnt1 cnt2
 	local dump_stats
 
 	if [[ $nr_info = "subflows_"* ]]; then
-		info="subflows"
+		info1="subflows"
+		info2="subflows"
+		nr_info=${nr_info:9}
+	elif [[ $nr_info = "add_addr_"* ]]; then
+		info1="add_addr_signal"
+		info2="add_addr_accepted"
 		nr_info=${nr_info:9}
 	else
 		echo "[fail] unsupported argument: $nr_info"
@@ -1830,16 +1834,16 @@ chk_mptcp_info()
 		return 1
 	fi
 
-	printf "%-${nr_blank}s %-30s" " " "mptcp_info $info=$nr_info"
+	printf "%-${nr_blank}s %-30s" " " "mptcp_info $info1:$info2=$nr_info"
 
-	cnt1=$(ss -N $ns1 -inmHM | grep "$info:" |
-		sed -n 's/.*\('"$info"':\)\([[:digit:]]*\).*$/\2/p;q')
+	cnt1=$(ss -N $ns1 -inmHM | grep "$info1:" |
+		sed -n 's/.*\('"$info1"':\)\([[:digit:]]*\).*$/\2/p;q')
 	[ -z "$cnt1" ] && cnt1=0
-	cnt2=$(ss -N $ns2 -inmHM | grep "$info:" |
-		sed -n 's/.*\('"$info"':\)\([[:digit:]]*\).*$/\2/p;q')
+	cnt2=$(ss -N $ns2 -inmHM | grep "$info2:" |
+		sed -n 's/.*\('"$info2"':\)\([[:digit:]]*\).*$/\2/p;q')
 	[ -z "$cnt2" ] && cnt2=0
 	if [ "$cnt1" != "$nr_info" ] || [ "$cnt2" != "$nr_info" ]; then
-		echo "[fail] got $cnt1:$cnt2 $info expected $nr_info"
+		echo "[fail] got $cnt1:$cnt2 $info1:$info2 expected $nr_info"
 		fail_test
 		dump_stats=1
 	else
@@ -3313,6 +3317,7 @@ userspace_tests()
 		chk_join_nr 1 1 1
 		chk_add_nr 1 1
 		chk_mptcp_info subflows_1
+		chk_mptcp_info add_addr_1
 		userspace_pm_rm_addr 10.0.2.1 10
 		wait_rm_addr $ns1 1
 		chk_rm_nr 1 1 invert
@@ -3356,6 +3361,7 @@ endpoint_tests()
 		pm_nl_check_endpoint 1 "creation" \
 			$ns2 10.0.2.2 id 1 flags implicit
 		chk_mptcp_info subflows_1
+		chk_mptcp_info add_addr_1
 
 		pm_nl_add_endpoint $ns2 10.0.2.2 id 33
 		pm_nl_check_endpoint 0 "ID change is prevented" \
-- 
2.35.3
Re: [PATCH mptcp-next v15 5/7] selftests: mptcp: check add_addr infos
Posted by Matthieu Baerts 2 years, 8 months ago
Hi Geliang,

On 31/05/2023 10:58, Geliang Tang wrote:
> This patch checks add_addr_signal and add_addr_accepted in
> chk_mptcp_info(), and do this checks in userspace_tests()
> and endpoint_tests().
> 
> Signed-off-by: Geliang Tang <geliang.tang@suse.com>
> ---
>  .../testing/selftests/net/mptcp/mptcp_join.sh | 26 ++++++++++++-------
>  1 file changed, 16 insertions(+), 10 deletions(-)
> 
> diff --git a/tools/testing/selftests/net/mptcp/mptcp_join.sh b/tools/testing/selftests/net/mptcp/mptcp_join.sh
> index 75f1c69ae78b..60cdc36d280f 100755
> --- a/tools/testing/selftests/net/mptcp/mptcp_join.sh
> +++ b/tools/testing/selftests/net/mptcp/mptcp_join.sh
> @@ -1816,13 +1816,17 @@ chk_subflow_nr()
>  chk_mptcp_info()
>  {
>  	local nr_info=$1
> -	local info
> -	local cnt1
> -	local cnt2
> +	local info1 info2
> +	local cnt1 cnt2
>  	local dump_stats
>  
>  	if [[ $nr_info = "subflows_"* ]]; then
> -		info="subflows"
> +		info1="subflows"
> +		info2="subflows"
> +		nr_info=${nr_info:9}
> +	elif [[ $nr_info = "add_addr_"* ]]; then
> +		info1="add_addr_signal"
> +		info2="add_addr_accepted"
>  		nr_info=${nr_info:9}

I think it would be clearer if chk_mptcp_info() was getting 3 parameters:
- counter name for ns1
- counter name for ns2
- the expected value for both (or 2 different ones)

If you do that, you can remove this if/elif/else section.

So we would call:

  chk_mptcp_info subflows subflows 1
  chk_mptcp_info add_addr_signal add_addr_accepted 1

But you can also add helpers:

  check_mptcp_info_subflows()
  {
          chk_mptcp_info subflows subflows "${1}"
  }

  check_mptcp_info_add_addr()
  {
          chk_mptcp_info add_addr_signal add_addr_accepted "${1}"
  }

  check_mptcp_info_subflows 1
  check_mptcp_info_add_addr 1

WDYT?

Cheers,
Matt
-- 
Tessares | Belgium | Hybrid Access Solutions
www.tessares.net