diff mbox series

[net-next,v2,4/4] selftests: hsr: Add test for VLAN

Message ID 20241024103056.3201071-5-danishanwar@ti.com (mailing list archive)
State Superseded
Delegated to: Netdev Maintainers
Headers show
Series Introduce VLAN support in HSR | expand

Checks

Context Check Description
netdev/series_format success Posting correctly formatted
netdev/tree_selection success Clearly marked for net-next
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
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: 5 this patch: 5
netdev/build_tools success Errors and warnings before: 157 (+0) this patch: 157 (+0)
netdev/cc_maintainers success CCed 10 of 10 maintainers
netdev/build_clang success Errors and warnings before: 3 this patch: 3
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: 3 this patch: 3
netdev/checkpatch warning WARNING: Misplaced SPDX-License-Identifier tag - use line 1 instead
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
netdev/contest success net-next-2024-10-31--09-00 (tests: 779)

Commit Message

MD Danish Anwar Oct. 24, 2024, 10:30 a.m. UTC
Add test for VLAN ping for HSR. The test adds vlan interfaces to the hsr
interface and then verifies if ping to them works.

Signed-off-by: MD Danish Anwar <danishanwar@ti.com>
---
 tools/testing/selftests/net/hsr/config      |  1 +
 tools/testing/selftests/net/hsr/hsr_ping.sh | 63 ++++++++++++++++++++-
 2 files changed, 63 insertions(+), 1 deletion(-)

Comments

Paolo Abeni Oct. 31, 2024, 2:41 p.m. UTC | #1
On 10/24/24 12:30, MD Danish Anwar wrote:
> @@ -183,9 +232,21 @@ trap cleanup_all_ns EXIT
>  setup_hsr_interfaces 0
>  do_complete_ping_test
>  
> +# Run VLAN Test
> +if $vlan; then
> +	setup_vlan_interfaces
> +	hsr_vlan_ping
> +fi
> +
>  setup_ns ns1 ns2 ns3
>  
>  setup_hsr_interfaces 1
>  do_complete_ping_test
>  
> +# Run VLAN Test
> +if $vlan; then
> +	setup_vlan_interfaces
> +	hsr_vlan_ping
> +fi

The new tests should be enabled by default. Indeed ideally the test
script should be able to run successfully on kernel not supporting such
feature; you could cope with that looking for the hsr exposed feature
and skipping the vlan test when the relevant feature is not present.

Cheers,

Paolo
MD Danish Anwar Nov. 5, 2024, 11:14 a.m. UTC | #2
On 31/10/24 8:11 pm, Paolo Abeni wrote:
> On 10/24/24 12:30, MD Danish Anwar wrote:
>> @@ -183,9 +232,21 @@ trap cleanup_all_ns EXIT
>>  setup_hsr_interfaces 0
>>  do_complete_ping_test
>>  
>> +# Run VLAN Test
>> +if $vlan; then
>> +	setup_vlan_interfaces
>> +	hsr_vlan_ping
>> +fi
>> +
>>  setup_ns ns1 ns2 ns3
>>  
>>  setup_hsr_interfaces 1
>>  do_complete_ping_test
>>  
>> +# Run VLAN Test
>> +if $vlan; then
>> +	setup_vlan_interfaces
>> +	hsr_vlan_ping
>> +fi
> 
> The new tests should be enabled by default. Indeed ideally the test
> script should be able to run successfully on kernel not supporting such
> feature; you could cope with that looking for the hsr exposed feature
> and skipping the vlan test when the relevant feature is not present.
> 

Sure Paolo, I will make the new tests enabled by default. During the
test I will check the exposed feature `ethtool -k hsr1 | grep
"vlan-challenged"` and if vlan is not supported, skip the vlan test.

Below will be my API to run VLAN tests,

run_vlan_tests() {
	vlan_challenged_hsr1=$(ip net exec "$ns1" ethtool -k hsr1 | grep
"vlan-challenged" | awk '{print $2}')
	vlan_challenged_hsr2=$(ip net exec "$ns1" ethtool -k hsr2 | grep
"vlan-challenged" | awk '{print $2}')
	vlan_challenged_hsr3=$(ip net exec "$ns1" ethtool -k hsr3 | grep
"vlan-challenged" | awk '{print $2}')

	if [[ "$vlan_challenged_hsr1" = "off" || "$vlan_challenged_hsr2" =
"off" || "$vlan_challenged_hsr3" = "off" ]]; then
		setup_vlan_interfaces
		hsr_vlan_ping
	else
		echo "INFO: Not Running VLAN tests as the device does not support VLAN"
	fi
}

I will call this function after the ping test.
Let me know if this looks okay to you.

Thanks for the review.

> Cheers,
> 
> Paolo
>
diff mbox series

Patch

diff --git a/tools/testing/selftests/net/hsr/config b/tools/testing/selftests/net/hsr/config
index 241542441c51..555a868743f0 100644
--- a/tools/testing/selftests/net/hsr/config
+++ b/tools/testing/selftests/net/hsr/config
@@ -3,3 +3,4 @@  CONFIG_NET_SCH_NETEM=m
 CONFIG_HSR=y
 CONFIG_VETH=y
 CONFIG_BRIDGE=y
+CONFIG_VLAN_8021Q=m
diff --git a/tools/testing/selftests/net/hsr/hsr_ping.sh b/tools/testing/selftests/net/hsr/hsr_ping.sh
index f5d207fc770a..fb7c7d3fb6c7 100755
--- a/tools/testing/selftests/net/hsr/hsr_ping.sh
+++ b/tools/testing/selftests/net/hsr/hsr_ping.sh
@@ -2,13 +2,15 @@ 
 # SPDX-License-Identifier: GPL-2.0
 
 ipv6=true
+vlan=false
 
 source ./hsr_common.sh
 
-optstring="h4"
+optstring="h4v"
 usage() {
 	echo "Usage: $0 [OPTION]"
 	echo -e "\t-4: IPv4 only: disable IPv6 tests (default: test both IPv4 and IPv6)"
+	echo -e "\t-v: Enable VLAN tests"
 }
 
 while getopts "$optstring" option;do
@@ -20,6 +22,9 @@  while getopts "$optstring" option;do
 	"4")
 		ipv6=false
 		;;
+	"v")
+		vlan=true
+		;;
 	"?")
 		usage $0
 		exit 1
@@ -175,6 +180,50 @@  setup_hsr_interfaces()
 	ip -net "$ns3" link set hsr3 up
 }
 
+setup_vlan_interfaces() {
+	ip link add link hsr1 name hsr1.2 type vlan id 2
+	ip link add link hsr1 name hsr1.3 type vlan id 3
+	ip link add link hsr1 name hsr1.4 type vlan id 4
+	ip link add link hsr1 name hsr1.5 type vlan id 5
+
+	ip link add link hsr2 name hsr2.2 type vlan id 2
+	ip link add link hsr2 name hsr2.3 type vlan id 3
+	ip link add link hsr2 name hsr2.4 type vlan id 4
+	ip link add link hsr2 name hsr2.5 type vlan id 5
+
+	ip link add link hsr3 name hsr3.2 type vlan id 2
+	ip link add link hsr3 name hsr3.3 type vlan id 3
+	ip link add link hsr3 name hsr3.4 type vlan id 4
+	ip link add link hsr3 name hsr3.5 type vlan id 5
+
+	ip -net "$ns1" addr add 100.64.2.1/24 dev hsr1.2
+	ip -net "$ns1" addr add 100.64.3.1/24 dev hsr1.3
+	ip -net "$ns1" addr add 100.64.4.1/24 dev hsr1.4
+	ip -net "$ns1" addr add 100.64.5.1/24 dev hsr1.5
+
+	ip -net "$ns2" addr add 100.64.2.2/24 dev hsr2.2
+	ip -net "$ns2" addr add 100.64.3.2/24 dev hsr2.3
+	ip -net "$ns2" addr add 100.64.4.2/24 dev hsr2.4
+	ip -net "$ns2" addr add 100.64.5.2/24 dev hsr2.5
+
+	ip -net "$ns3" addr add 100.64.2.3/24 dev hsr3.2
+	ip -net "$ns3" addr add 100.64.3.3/24 dev hsr3.3
+	ip -net "$ns3" addr add 100.64.4.3/24 dev hsr3.4
+	ip -net "$ns3" addr add 100.64.5.3/24 dev hsr3.5
+}
+
+hsr_vlan_ping() {
+	do_ping "$ns2" 100.64.2.1
+	do_ping "$ns2" 100.64.3.1
+	do_ping "$ns2" 100.64.4.1
+	do_ping "$ns2" 100.64.5.1
+
+	do_ping "$ns2" 100.64.2.3
+	do_ping "$ns2" 100.64.3.3
+	do_ping "$ns2" 100.64.4.3
+	do_ping "$ns2" 100.64.5.3
+}
+
 check_prerequisites
 setup_ns ns1 ns2 ns3
 
@@ -183,9 +232,21 @@  trap cleanup_all_ns EXIT
 setup_hsr_interfaces 0
 do_complete_ping_test
 
+# Run VLAN Test
+if $vlan; then
+	setup_vlan_interfaces
+	hsr_vlan_ping
+fi
+
 setup_ns ns1 ns2 ns3
 
 setup_hsr_interfaces 1
 do_complete_ping_test
 
+# Run VLAN Test
+if $vlan; then
+	setup_vlan_interfaces
+	hsr_vlan_ping
+fi
+
 exit $ret