diff mbox series

[v3,3/6] test: dm: add a simple unit test for DSA class

Message ID 20191203145645.13361-4-alexandru.marginean@nxp.com
State New
Delegated to: Joe Hershberger
Headers show
Series Introduce DSA Ethernet switch class and Felix driver | expand

Commit Message

Alexandru Marginean Dec. 3, 2019, 2:56 p.m. UTC
The test pings the local IP address though different ports of a sandbox
DSA device.  Port traffic is filtered and the test verifies that ping
works only on enabled ports.
The additional interfaces require MAC addresses, these have been added
to sandbox default environment.

Signed-off-by: Alex Marginean <alexandru.marginean@nxp.com>
---
 arch/Kconfig              |  1 +
 arch/sandbox/dts/test.dts | 49 +++++++++++++++++++++++++++++++++
 include/configs/sandbox.h |  4 +++
 test/dm/Makefile          |  1 +
 test/dm/dsa.c             | 58 +++++++++++++++++++++++++++++++++++++++
 test/dm/test-fdt.c        |  2 +-
 6 files changed, 114 insertions(+), 1 deletion(-)
 create mode 100644 test/dm/dsa.c

Comments

Priyanka Jain Dec. 4, 2019, 4:14 a.m. UTC | #1
>-----Original Message-----
>From: U-Boot <u-boot-bounces@lists.denx.de> On Behalf Of Alex Marginean
>Sent: Tuesday, December 3, 2019 8:27 PM
>To: u-boot@lists.denx.de
>Cc: Joe Hershberger <joe.hershberger@ni.com>; Claudiu Manoil
><claudiu.manoil@nxp.com>; Vladimir Oltean <vladimir.oltean@nxp.com>
>Subject: [PATCH v3 3/6] test: dm: add a simple unit test for DSA class
>
>The test pings the local IP address though different ports of a sandbox DSA
>device.  Port traffic is filtered and the test verifies that ping works only on
>enabled ports.
>The additional interfaces require MAC addresses, these have been added to
>sandbox default environment.
>
>Signed-off-by: Alex Marginean <alexandru.marginean@nxp.com>
>---
> arch/Kconfig              |  1 +
> arch/sandbox/dts/test.dts | 49 +++++++++++++++++++++++++++++++++
>include/configs/sandbox.h |  4 +++
> test/dm/Makefile          |  1 +
> test/dm/dsa.c             | 58 +++++++++++++++++++++++++++++++++++++++
> test/dm/test-fdt.c        |  2 +-
> 6 files changed, 114 insertions(+), 1 deletion(-)  create mode 100644
>test/dm/dsa.c
>
>diff --git a/arch/Kconfig b/arch/Kconfig index 141e48bc43..70907d69a1 100644
>--- a/arch/Kconfig
>+++ b/arch/Kconfig
>@@ -133,6 +133,7 @@ config SANDBOX
> 	imply PHYLIB
> 	imply DM_MDIO
> 	imply DM_MDIO_MUX
>+	imply DM_DSA
>
> config SH
> 	bool "SuperH architecture"
>diff --git a/arch/sandbox/dts/test.dts b/arch/sandbox/dts/test.dts index
>fdb08f2111..0f565f066a 100644
>--- a/arch/sandbox/dts/test.dts
>+++ b/arch/sandbox/dts/test.dts
>@@ -40,6 +40,10 @@
> 		usb2 = &usb_2;
> 		axi0 = &axi;
> 		osd0 = "/osd";
>+		eth8 = &swp_0;
>+		eth9 = &swp_1;
>+		eth10 = &swp_2;
>+		eth11 = &dsa_eth0;
> 	};
>
> 	audio: audio-codec {
>@@ -889,6 +893,51 @@
> 	mdio: mdio-test {
> 		compatible = "sandbox,mdio";
> 	};
>+
>+	dsa_eth0: dsa-test-eth {
>+		compatible = "sandbox,dsa-eth";
>+	};
>+
>+	dsa-test {
>+		compatible = "sandbox,dsa";
>+
>+		ports {
>+			#address-cells = <1>;
>+			#size-cells = <0>;
>+			swp_0: port@0 {
>+				reg = <0>;
>+				label = "lan0";
>+			};
>+
>+			swp_1: port@1 {
>+				reg = <1>;
>+				label = "lan1";
>+				phy-mode = "rgmii-txid";
>+				fixed-link {
>+					speed = <1000>;
>+					full-duplex;
>+				};
>+			};
>+
>+			swp_2: port@2 {
>+				reg = <2>;
>+				label = "lan2";
>+				fixed-link {
>+					speed = <100>;
>+					full-duplex;
>+				};
>+			};
>+
>+			port@3 {
>+				reg = <3>;
>+				ethernet = <&dsa_eth0>;
>+				fixed-link {
>+					speed = <100>;
>+					full-duplex;
>+				};
>+			};
>+		};
>+	};
> };
>
> #include "sandbox_pmic.dtsi"
>diff --git a/include/configs/sandbox.h b/include/configs/sandbox.h index
>1c13055cdc..35a5676eb9 100644
>--- a/include/configs/sandbox.h
>+++ b/include/configs/sandbox.h
>@@ -100,6 +100,10 @@
> 					"eth1addr=00:00:11:22:33:45\0" \
> 					"eth3addr=00:00:11:22:33:46\0" \
> 					"eth5addr=00:00:11:22:33:47\0" \
>+					"eth8addr=00:00:11:22:33:48\0" \
>+					"eth9addr=00:00:11:22:33:49\0" \
>+					"eth10addr=00:00:11:22:33:4a\0" \
>+					"eth11addr=00:00:11:22:33:4b\0" \
> 					"ipaddr=1.2.3.4\0"
>
> #define MEM_LAYOUT_ENV_SETTINGS \
>diff --git a/test/dm/Makefile b/test/dm/Makefile index 0c2fd5cb5e..69e9feed91
>100644
>--- a/test/dm/Makefile
>+++ b/test/dm/Makefile
>@@ -65,4 +65,5 @@ obj-$(CONFIG_VIRTIO_SANDBOX) += virtio.o
> obj-$(CONFIG_DMA) += dma.o
> obj-$(CONFIG_DM_MDIO) += mdio.o
> obj-$(CONFIG_DM_MDIO_MUX) += mdio_mux.o
>+obj-$(CONFIG_DM_DSA) += dsa.o
> endif
>diff --git a/test/dm/dsa.c b/test/dm/dsa.c new file mode 100644 index
>0000000000..5aa3847fe5
>--- /dev/null
>+++ b/test/dm/dsa.c
>@@ -0,0 +1,58 @@
>+// SPDX-License-Identifier: GPL-2.0
>+/*
>+ * Copyright (c) 2019 NXP
Please use Copyright 2019 NXP
>+ */
>+
>+#include <net/dsa.h>
>+#include <dm/test.h>
>+#include <test/ut.h>
>+
>+extern int dsa_sandbox_port_mask;
>+
>+/* this test sends ping requests with the local address through each
>+DSA port
>+ * via the dummy DSA master Eth.
>+ * The dummy Eth filters traffic based on DSA port used to Tx and the
>+port
>+ * mask set here, so we can check that port information gets trough correctly.
>+ */
>+static int dm_test_dsa(struct unit_test_state *uts) {
>+	dsa_sandbox_port_mask = 0x5;
>+
>+	env_set("ethrotate", "no");
>+	net_ping_ip = string_to_ip("1.2.3.4");
>+
>+	env_set("ethact", "dsa-test-eth");
>+	ut_assertok(net_loop(PING));
>+
>+	dsa_sandbox_port_mask = 0x7;
>+	env_set("ethact", "lan0");
>+	ut_assertok(net_loop(PING));
>+	env_set("ethact", "lan1");
>+	ut_assertok(net_loop(PING));
>+	env_set("ethact", "lan2");
>+	ut_assertok(net_loop(PING));
>+
>+	dsa_sandbox_port_mask = 0x1;
>+	env_set("ethact", "lan0");
>+	ut_assertok(net_loop(PING));
>+	env_set("ethact", "lan1");
>+	ut_assert(net_loop(PING) != 0);
>+	env_set("ethact", "lan2");
>+	ut_assert(net_loop(PING) != 0);
>+
>+	dsa_sandbox_port_mask = 0x6;
>+	env_set("ethact", "lan0");
>+	ut_assert(net_loop(PING) != 0);
>+	env_set("ethact", "lan1");
>+	ut_assertok(net_loop(PING));
>+	env_set("ethact", "lan2");
>+	ut_assertok(net_loop(PING));
>+
>+	dsa_sandbox_port_mask = 0;
>+	env_set("ethact", "");
>+	env_set("ethrotate", "yes");
>+
>+	return 0;
>+}
>+
>+DM_TEST(dm_test_dsa, DM_TESTF_SCAN_FDT);
>diff --git a/test/dm/test-fdt.c b/test/dm/test-fdt.c index 1fb8b5c248..0d7dd053e2
>100644
>--- a/test/dm/test-fdt.c
>+++ b/test/dm/test-fdt.c
>@@ -224,7 +224,7 @@ static int dm_test_alias_highest_id(struct unit_test_state
>*uts)
> 	int ret;
>
> 	ret = dev_read_alias_highest_id("eth");
>-	ut_asserteq(5, ret);
>+	ut_asserteq(11, ret);
>
> 	ret = dev_read_alias_highest_id("gpio");
> 	ut_asserteq(2, ret);
>--
>2.17.1
Priyanka
diff mbox series

Patch

diff --git a/arch/Kconfig b/arch/Kconfig
index 141e48bc43..70907d69a1 100644
--- a/arch/Kconfig
+++ b/arch/Kconfig
@@ -133,6 +133,7 @@  config SANDBOX
 	imply PHYLIB
 	imply DM_MDIO
 	imply DM_MDIO_MUX
+	imply DM_DSA
 
 config SH
 	bool "SuperH architecture"
diff --git a/arch/sandbox/dts/test.dts b/arch/sandbox/dts/test.dts
index fdb08f2111..0f565f066a 100644
--- a/arch/sandbox/dts/test.dts
+++ b/arch/sandbox/dts/test.dts
@@ -40,6 +40,10 @@ 
 		usb2 = &usb_2;
 		axi0 = &axi;
 		osd0 = "/osd";
+		eth8 = &swp_0;
+		eth9 = &swp_1;
+		eth10 = &swp_2;
+		eth11 = &dsa_eth0;
 	};
 
 	audio: audio-codec {
@@ -889,6 +893,51 @@ 
 	mdio: mdio-test {
 		compatible = "sandbox,mdio";
 	};
+
+	dsa_eth0: dsa-test-eth {
+		compatible = "sandbox,dsa-eth";
+	};
+
+	dsa-test {
+		compatible = "sandbox,dsa";
+
+		ports {
+			#address-cells = <1>;
+			#size-cells = <0>;
+			swp_0: port@0 {
+				reg = <0>;
+				label = "lan0";
+			};
+
+			swp_1: port@1 {
+				reg = <1>;
+				label = "lan1";
+				phy-mode = "rgmii-txid";
+				fixed-link {
+					speed = <1000>;
+					full-duplex;
+				};
+			};
+
+			swp_2: port@2 {
+				reg = <2>;
+				label = "lan2";
+				fixed-link {
+					speed = <100>;
+					full-duplex;
+				};
+			};
+
+			port@3 {
+				reg = <3>;
+				ethernet = <&dsa_eth0>;
+				fixed-link {
+					speed = <100>;
+					full-duplex;
+				};
+			};
+		};
+	};
 };
 
 #include "sandbox_pmic.dtsi"
diff --git a/include/configs/sandbox.h b/include/configs/sandbox.h
index 1c13055cdc..35a5676eb9 100644
--- a/include/configs/sandbox.h
+++ b/include/configs/sandbox.h
@@ -100,6 +100,10 @@ 
 					"eth1addr=00:00:11:22:33:45\0" \
 					"eth3addr=00:00:11:22:33:46\0" \
 					"eth5addr=00:00:11:22:33:47\0" \
+					"eth8addr=00:00:11:22:33:48\0" \
+					"eth9addr=00:00:11:22:33:49\0" \
+					"eth10addr=00:00:11:22:33:4a\0" \
+					"eth11addr=00:00:11:22:33:4b\0" \
 					"ipaddr=1.2.3.4\0"
 
 #define MEM_LAYOUT_ENV_SETTINGS \
diff --git a/test/dm/Makefile b/test/dm/Makefile
index 0c2fd5cb5e..69e9feed91 100644
--- a/test/dm/Makefile
+++ b/test/dm/Makefile
@@ -65,4 +65,5 @@  obj-$(CONFIG_VIRTIO_SANDBOX) += virtio.o
 obj-$(CONFIG_DMA) += dma.o
 obj-$(CONFIG_DM_MDIO) += mdio.o
 obj-$(CONFIG_DM_MDIO_MUX) += mdio_mux.o
+obj-$(CONFIG_DM_DSA) += dsa.o
 endif
diff --git a/test/dm/dsa.c b/test/dm/dsa.c
new file mode 100644
index 0000000000..5aa3847fe5
--- /dev/null
+++ b/test/dm/dsa.c
@@ -0,0 +1,58 @@ 
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (c) 2019 NXP
+ */
+
+#include <net/dsa.h>
+#include <dm/test.h>
+#include <test/ut.h>
+
+extern int dsa_sandbox_port_mask;
+
+/* this test sends ping requests with the local address through each DSA port
+ * via the dummy DSA master Eth.
+ * The dummy Eth filters traffic based on DSA port used to Tx and the port
+ * mask set here, so we can check that port information gets trough correctly.
+ */
+static int dm_test_dsa(struct unit_test_state *uts)
+{
+	dsa_sandbox_port_mask = 0x5;
+
+	env_set("ethrotate", "no");
+	net_ping_ip = string_to_ip("1.2.3.4");
+
+	env_set("ethact", "dsa-test-eth");
+	ut_assertok(net_loop(PING));
+
+	dsa_sandbox_port_mask = 0x7;
+	env_set("ethact", "lan0");
+	ut_assertok(net_loop(PING));
+	env_set("ethact", "lan1");
+	ut_assertok(net_loop(PING));
+	env_set("ethact", "lan2");
+	ut_assertok(net_loop(PING));
+
+	dsa_sandbox_port_mask = 0x1;
+	env_set("ethact", "lan0");
+	ut_assertok(net_loop(PING));
+	env_set("ethact", "lan1");
+	ut_assert(net_loop(PING) != 0);
+	env_set("ethact", "lan2");
+	ut_assert(net_loop(PING) != 0);
+
+	dsa_sandbox_port_mask = 0x6;
+	env_set("ethact", "lan0");
+	ut_assert(net_loop(PING) != 0);
+	env_set("ethact", "lan1");
+	ut_assertok(net_loop(PING));
+	env_set("ethact", "lan2");
+	ut_assertok(net_loop(PING));
+
+	dsa_sandbox_port_mask = 0;
+	env_set("ethact", "");
+	env_set("ethrotate", "yes");
+
+	return 0;
+}
+
+DM_TEST(dm_test_dsa, DM_TESTF_SCAN_FDT);
diff --git a/test/dm/test-fdt.c b/test/dm/test-fdt.c
index 1fb8b5c248..0d7dd053e2 100644
--- a/test/dm/test-fdt.c
+++ b/test/dm/test-fdt.c
@@ -224,7 +224,7 @@  static int dm_test_alias_highest_id(struct unit_test_state *uts)
 	int ret;
 
 	ret = dev_read_alias_highest_id("eth");
-	ut_asserteq(5, ret);
+	ut_asserteq(11, ret);
 
 	ret = dev_read_alias_highest_id("gpio");
 	ut_asserteq(2, ret);