blob: c857106eaf4a77b6815a1d28b58c1b95e79a87b8 [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}
59
60DM_TEST(dm_test_dsa_probe, UT_TESTF_SCAN_FDT);
61
62/* This test sends ping requests with the local address through each DSA port
63 * via the sandbox DSA master Eth.
64 */
65static int dm_test_dsa(struct unit_test_state *uts)
66{
67 net_ping_ip = string_to_ip("1.2.3.5");
68
69 env_set("ethact", "eth2");
70 ut_assertok(net_loop(PING));
71
72 env_set("ethact", "lan0");
73 ut_assertok(net_loop(PING));
74 env_set("ethact", "lan1");
75 ut_assertok(net_loop(PING));
76
77 env_set("ethact", "");
78
79 return 0;
80}
81
82DM_TEST(dm_test_dsa, UT_TESTF_SCAN_FDT);