summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/dm/Makefile1
-rw-r--r--test/dm/dsa.c82
-rw-r--r--test/dm/eth.c10
3 files changed, 88 insertions, 5 deletions
diff --git a/test/dm/Makefile b/test/dm/Makefile
index d54abb73413..5de6fbfb5d5 100644
--- a/test/dm/Makefile
+++ b/test/dm/Makefile
@@ -29,6 +29,7 @@ obj-$(CONFIG_CLK) += clk.o clk_ccf.o
obj-$(CONFIG_CROS_EC) += cros_ec.o
obj-$(CONFIG_DEVRES) += devres.o
obj-$(CONFIG_VIDEO_MIPI_DSI) += dsi_host.o
+obj-$(CONFIG_DM_DSA) += dsa.o
obj-$(CONFIG_DM_ETH) += eth.o
obj-$(CONFIG_FIRMWARE) += firmware.o
obj-$(CONFIG_DM_GPIO) += gpio.o
diff --git a/test/dm/dsa.c b/test/dm/dsa.c
new file mode 100644
index 00000000000..18c1776460d
--- /dev/null
+++ b/test/dm/dsa.c
@@ -0,0 +1,82 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright 2020-2021 NXP Semiconductors
+ */
+
+#include <net/dsa.h>
+#include <dm/test.h>
+#include <test/ut.h>
+#include <net.h>
+#include <dm/uclass-internal.h>
+#include <dm/device-internal.h>
+
+/* This test exercises the major dsa.h API functions, after making sure
+ * that the DSA ports and the master Eth are correctly probed.
+ */
+static int dm_test_dsa_probe(struct unit_test_state *uts)
+{
+ struct udevice *dev_dsa, *dev_port, *dev_master;
+ struct dsa_pdata *dsa_pdata;
+ enum uclass_id id;
+
+ id = uclass_get_by_name("dsa");
+ ut_assert(id == UCLASS_DSA);
+
+ ut_assertok(uclass_find_device_by_name(UCLASS_DSA, "dsa-test",
+ &dev_dsa));
+ ut_assertok(uclass_find_device_by_name(UCLASS_ETH, "dsa-test-eth",
+ &dev_master));
+ ut_assertok(device_probe(dev_master));
+
+ ut_assertok(uclass_find_device_by_name(UCLASS_ETH, "dsa-test@0",
+ &dev_port));
+ ut_assertok(device_probe(dev_port));
+
+ ut_assertok(uclass_find_device_by_name(UCLASS_ETH, "dsa-test@1",
+ &dev_port));
+ ut_assertok(device_probe(dev_port));
+
+ /* exercise DSA API */
+ dsa_pdata = dev_get_uclass_plat(dev_dsa);
+ ut_assertnonnull(dsa_pdata);
+ /* includes CPU port */
+ ut_assert(dsa_pdata->num_ports == 3);
+
+ ut_assertok(uclass_find_device_by_name(UCLASS_ETH, "lan0",
+ &dev_port));
+ ut_assertok(device_probe(dev_port));
+
+ ut_assertok(uclass_find_device_by_name(UCLASS_ETH, "lan1",
+ &dev_port));
+ ut_assertok(device_probe(dev_port));
+
+ dev_master = dsa_get_master(dev_dsa);
+ ut_assertnonnull(dev_master);
+ ut_asserteq_str("dsa-test-eth", dev_master->name);
+
+ return 0;
+}
+
+DM_TEST(dm_test_dsa_probe, UT_TESTF_SCAN_FDT);
+
+/* This test sends ping requests with the local address through each DSA port
+ * via the sandbox DSA master Eth.
+ */
+static int dm_test_dsa(struct unit_test_state *uts)
+{
+ net_ping_ip = string_to_ip("1.2.3.5");
+
+ env_set("ethact", "eth2");
+ ut_assertok(net_loop(PING));
+
+ env_set("ethact", "lan0");
+ ut_assertok(net_loop(PING));
+ env_set("ethact", "lan1");
+ ut_assertok(net_loop(PING));
+
+ env_set("ethact", "");
+
+ return 0;
+}
+
+DM_TEST(dm_test_dsa, UT_TESTF_SCAN_FDT);
diff --git a/test/dm/eth.c b/test/dm/eth.c
index fa8a69da701..e4ee6956106 100644
--- a/test/dm/eth.c
+++ b/test/dm/eth.c
@@ -53,8 +53,8 @@ static int dm_test_eth_alias(struct unit_test_state *uts)
ut_assertok(net_loop(PING));
ut_asserteq_str("eth@10004000", env_get("ethact"));
- /* Expected to fail since eth2 is not defined in the device tree */
- env_set("ethact", "eth2");
+ /* Expected to fail since eth1 is not defined in the device tree */
+ env_set("ethact", "eth1");
ut_assertok(net_loop(PING));
ut_asserteq_str("eth@10002000", env_get("ethact"));
@@ -227,7 +227,7 @@ static int _dm_test_net_retry(struct unit_test_state *uts)
* the active device should be eth0
*/
sandbox_eth_disable_response(1, true);
- env_set("ethact", "eth@10004000");
+ env_set("ethact", "lan1");
env_set("netretry", "yes");
sandbox_eth_skip_timeout();
ut_assertok(net_loop(PING));
@@ -237,11 +237,11 @@ static int _dm_test_net_retry(struct unit_test_state *uts)
* eth1 is disabled and netretry is no, so the ping should fail and the
* active device should be eth1
*/
- env_set("ethact", "eth@10004000");
+ env_set("ethact", "lan1");
env_set("netretry", "no");
sandbox_eth_skip_timeout();
ut_asserteq(-ENONET, net_loop(PING));
- ut_asserteq_str("eth@10004000", env_get("ethact"));
+ ut_asserteq_str("lan1", env_get("ethact"));
return 0;
}