blob: c6b4e12a758dd8344c5aeefcfb1ee97c0327a081 [file] [log] [blame]
Claudiu Manoild9eaa922021-03-14 20:14:57 +08001// SPDX-License-Identifier: GPL-2.0
2/*
Vladimir Oltean5041e422021-09-17 14:27:13 +03003 * Copyright 2020-2021 NXP
Claudiu Manoild9eaa922021-03-14 20:14:57 +08004 */
5
6#include <net/dsa.h>
7#include <dm/test.h>
8#include <test/ut.h>
9#include <net.h>
10#include <dm/uclass-internal.h>
11#include <dm/device-internal.h>
12
13/* This test exercises the major dsa.h API functions, after making sure
14 * that the DSA ports and the master Eth are correctly probed.
15 */
16static int dm_test_dsa_probe(struct unit_test_state *uts)
17{
18 struct udevice *dev_dsa, *dev_port, *dev_master;
19 struct dsa_pdata *dsa_pdata;
20 enum uclass_id id;
21
22 id = uclass_get_by_name("dsa");
23 ut_assert(id == UCLASS_DSA);
24
25 ut_assertok(uclass_find_device_by_name(UCLASS_DSA, "dsa-test",
26 &dev_dsa));
27 ut_assertok(uclass_find_device_by_name(UCLASS_ETH, "dsa-test-eth",
28 &dev_master));
29 ut_assertok(device_probe(dev_master));
30
31 ut_assertok(uclass_find_device_by_name(UCLASS_ETH, "dsa-test@0",
32 &dev_port));
33 ut_assertok(device_probe(dev_port));
34
35 ut_assertok(uclass_find_device_by_name(UCLASS_ETH, "dsa-test@1",
36 &dev_port));
37 ut_assertok(device_probe(dev_port));
38
39 /* exercise DSA API */
40 dsa_pdata = dev_get_uclass_plat(dev_dsa);
41 ut_assertnonnull(dsa_pdata);
42 /* includes CPU port */
43 ut_assert(dsa_pdata->num_ports == 3);
44
45 ut_assertok(uclass_find_device_by_name(UCLASS_ETH, "lan0",
46 &dev_port));
47 ut_assertok(device_probe(dev_port));
48
49 ut_assertok(uclass_find_device_by_name(UCLASS_ETH, "lan1",
50 &dev_port));
51 ut_assertok(device_probe(dev_port));
52
53 dev_master = dsa_get_master(dev_dsa);
54 ut_assertnonnull(dev_master);
55 ut_asserteq_str("dsa-test-eth", dev_master->name);
56
57 return 0;
58}
Simon Glass1a92f832024-08-22 07:57:48 -060059DM_TEST(dm_test_dsa_probe, UTF_SCAN_FDT);
Claudiu Manoild9eaa922021-03-14 20:14:57 +080060
61/* This test sends ping requests with the local address through each DSA port
62 * via the sandbox DSA master Eth.
63 */
64static int dm_test_dsa(struct unit_test_state *uts)
65{
66 net_ping_ip = string_to_ip("1.2.3.5");
67
68 env_set("ethact", "eth2");
69 ut_assertok(net_loop(PING));
70
71 env_set("ethact", "lan0");
72 ut_assertok(net_loop(PING));
73 env_set("ethact", "lan1");
74 ut_assertok(net_loop(PING));
75
76 env_set("ethact", "");
77
78 return 0;
79}
Simon Glass1a92f832024-08-22 07:57:48 -060080DM_TEST(dm_test_dsa, UTF_SCAN_FDT);