[PATCH mptcp-next v6 10/10] selftests: mptcp: simplify deny_join_id0_tests

Geliang Tang posted 10 patches 1 year, 3 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>, Florian Westphal <fw@strlen.de>, Kishen Maloor <kishen.maloor@intel.com>
There is a newer version of this series
[PATCH mptcp-next v6 10/10] selftests: mptcp: simplify deny_join_id0_tests
Posted by Geliang Tang 1 year, 3 months ago
The six join id0 tests can be divided into three groups in sequence,
with two tests in each one. Both tests in one group are similar, only
different namespaces used. So a for-loop can be used to simplify these
tests.

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

diff --git a/tools/testing/selftests/net/mptcp/mptcp_join.sh b/tools/testing/selftests/net/mptcp/mptcp_join.sh
index 59f613c6d387..084d7a8088fb 100755
--- a/tools/testing/selftests/net/mptcp/mptcp_join.sh
+++ b/tools/testing/selftests/net/mptcp/mptcp_join.sh
@@ -383,11 +383,17 @@ reset_with_checksum()
 
 reset_with_allow_join_id0()
 {
-	local ns1_enable=$2
-	local ns2_enable=$3
+	local ns1_enable=0
+	local ns2_enable=0
 
 	reset "${1}" || return 1
 
+	if [ "${2}" == "ns1" ]; then
+		ns1_enable=1
+	elif [ "${2}" == "ns2" ]; then
+		ns2_enable=1
+	fi
+
 	ip netns exec $ns1 sysctl -q net.mptcp.allow_join_initial_addr_port=$ns1_enable
 	ip netns exec $ns2 sysctl -q net.mptcp.allow_join_initial_addr_port=$ns2_enable
 }
@@ -3054,65 +3060,47 @@ checksum_tests()
 
 deny_join_id0_tests()
 {
-	# subflow allow join id0 ns1
-	if reset_with_allow_join_id0 "single subflow allow join id0 ns1" 1 0; then
-		pm_nl_set_limits $ns1 1 1
-		pm_nl_set_limits $ns2 1 1
-		pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow
-		run_tests $ns1 $ns2 10.0.1.1
-		chk_join_nr 1 1 1
-	fi
+	local ns
 
-	# subflow allow join id0 ns2
-	if reset_with_allow_join_id0 "single subflow allow join id0 ns2" 0 1; then
-		pm_nl_set_limits $ns1 1 1
-		pm_nl_set_limits $ns2 1 1
-		pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow
-		run_tests $ns1 $ns2 10.0.1.1
-		chk_join_nr 0 0 0
-	fi
-
-	# signal address allow join id0 ns1
-	# ADD_ADDRs are not affected by allow_join_id0 value.
-	if reset_with_allow_join_id0 "signal address allow join id0 ns1" 1 0; then
-		pm_nl_set_limits $ns1 1 1
-		pm_nl_set_limits $ns2 1 1
-		pm_nl_add_endpoint $ns1 10.0.2.1 flags signal
-		run_tests $ns1 $ns2 10.0.1.1
-		chk_join_nr 1 1 1
-		chk_add_nr 1 1
-	fi
-
-	# signal address allow join id0 ns2
-	# ADD_ADDRs are not affected by allow_join_id0 value.
-	if reset_with_allow_join_id0 "signal address allow join id0 ns2" 0 1; then
-		pm_nl_set_limits $ns1 1 1
-		pm_nl_set_limits $ns2 1 1
-		pm_nl_add_endpoint $ns1 10.0.2.1 flags signal
-		run_tests $ns1 $ns2 10.0.1.1
-		chk_join_nr 1 1 1
-		chk_add_nr 1 1
-	fi
+	for ns in "ns1" "ns2"; do
+		# subflow allow join id0 ns1/ns2
+		if reset_with_allow_join_id0 "single subflow allow join id0 $ns" "$ns"; then
+			pm_nl_set_limits $ns1 1 1
+			pm_nl_set_limits $ns2 1 1
+			pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow
+			run_tests $ns1 $ns2 10.0.1.1
+			if [ "$ns" == "ns1" ]; then
+				chk_join_nr 1 1 1
+			elif [ "$ns" == "ns2" ]; then
+				chk_join_nr 0 0 0
+			fi
+		fi
 
-	# subflow and address allow join id0 ns1
-	if reset_with_allow_join_id0 "subflow and address allow join id0 1" 1 0; then
-		pm_nl_set_limits $ns1 2 2
-		pm_nl_set_limits $ns2 2 2
-		pm_nl_add_endpoint $ns1 10.0.2.1 flags signal
-		pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow
-		run_tests $ns1 $ns2 10.0.1.1
-		chk_join_nr 2 2 2
-	fi
+		# signal address allow join id0 ns1/ns2
+		# ADD_ADDRs are not affected by allow_join_id0 value.
+		if reset_with_allow_join_id0 "signal address allow join id0 $ns" "$ns"; then
+			pm_nl_set_limits $ns1 1 1
+			pm_nl_set_limits $ns2 1 1
+			pm_nl_add_endpoint $ns1 10.0.2.1 flags signal
+			run_tests $ns1 $ns2 10.0.1.1
+			chk_join_nr 1 1 1
+			chk_add_nr 1 1
+		fi
 
-	# subflow and address allow join id0 ns2
-	if reset_with_allow_join_id0 "subflow and address allow join id0 2" 0 1; then
-		pm_nl_set_limits $ns1 2 2
-		pm_nl_set_limits $ns2 2 2
-		pm_nl_add_endpoint $ns1 10.0.2.1 flags signal
-		pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow
-		run_tests $ns1 $ns2 10.0.1.1
-		chk_join_nr 1 1 1
-	fi
+		# subflow and address allow join id0 ns1/ns2
+		if reset_with_allow_join_id0 "subflow & address allow join id0 $ns" "$ns"; then
+			pm_nl_set_limits $ns1 2 2
+			pm_nl_set_limits $ns2 2 2
+			pm_nl_add_endpoint $ns1 10.0.2.1 flags signal
+			pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow
+			run_tests $ns1 $ns2 10.0.1.1
+			if [ "$ns" == "ns1" ]; then
+				chk_join_nr 2 2 2
+			elif [ "$ns" == "ns2" ]; then
+				chk_join_nr 1 1 1
+			fi
+		fi
+	done
 }
 
 fullmesh_tests()
-- 
2.35.3