2 * Copyright (c) 2015 National Instruments
5 * Joe Hershberger <joe.hershberger@ni.com>
7 * SPDX-License-Identifier: GPL-2.0
19 DECLARE_GLOBAL_DATA_PTR;
21 static int dm_test_eth(struct unit_test_state *uts)
23 net_ping_ip = string_to_ip("1.1.2.2");
25 setenv("ethact", "eth@10002000");
26 ut_assertok(net_loop(PING));
27 ut_asserteq_str("eth@10002000", getenv("ethact"));
29 setenv("ethact", "eth@10003000");
30 ut_assertok(net_loop(PING));
31 ut_asserteq_str("eth@10003000", getenv("ethact"));
33 setenv("ethact", "eth@10004000");
34 ut_assertok(net_loop(PING));
35 ut_asserteq_str("eth@10004000", getenv("ethact"));
39 DM_TEST(dm_test_eth, DM_TESTF_SCAN_FDT);
41 static int dm_test_eth_alias(struct unit_test_state *uts)
43 net_ping_ip = string_to_ip("1.1.2.2");
44 setenv("ethact", "eth0");
45 ut_assertok(net_loop(PING));
46 ut_asserteq_str("eth@10002000", getenv("ethact"));
48 setenv("ethact", "eth1");
49 ut_assertok(net_loop(PING));
50 ut_asserteq_str("eth@10004000", getenv("ethact"));
52 /* Expected to fail since eth2 is not defined in the device tree */
53 setenv("ethact", "eth2");
54 ut_assertok(net_loop(PING));
55 ut_asserteq_str("eth@10002000", getenv("ethact"));
57 setenv("ethact", "eth5");
58 ut_assertok(net_loop(PING));
59 ut_asserteq_str("eth@10003000", getenv("ethact"));
63 DM_TEST(dm_test_eth_alias, DM_TESTF_SCAN_FDT);
65 static int dm_test_eth_prime(struct unit_test_state *uts)
67 net_ping_ip = string_to_ip("1.1.2.2");
69 /* Expected to be "eth@10003000" because of ethprime variable */
70 setenv("ethact", NULL);
71 setenv("ethprime", "eth5");
72 ut_assertok(net_loop(PING));
73 ut_asserteq_str("eth@10003000", getenv("ethact"));
75 /* Expected to be "eth@10002000" because it is first */
76 setenv("ethact", NULL);
77 setenv("ethprime", NULL);
78 ut_assertok(net_loop(PING));
79 ut_asserteq_str("eth@10002000", getenv("ethact"));
83 DM_TEST(dm_test_eth_prime, DM_TESTF_SCAN_FDT);
85 static int dm_test_eth_rotate(struct unit_test_state *uts)
89 /* Invalidate eth1's MAC address */
90 net_ping_ip = string_to_ip("1.1.2.2");
91 strcpy(ethaddr, getenv("eth1addr"));
92 /* Must disable access protection for eth1addr before clearing */
93 setenv(".flags", "eth1addr");
94 setenv("eth1addr", NULL);
96 /* Make sure that the default is to rotate to the next interface */
97 setenv("ethact", "eth@10004000");
98 ut_assertok(net_loop(PING));
99 ut_asserteq_str("eth@10002000", getenv("ethact"));
101 /* If ethrotate is no, then we should fail on a bad MAC */
102 setenv("ethact", "eth@10004000");
103 setenv("ethrotate", "no");
104 ut_asserteq(-EINVAL, net_loop(PING));
105 ut_asserteq_str("eth@10004000", getenv("ethact"));
107 /* Restore the env */
108 setenv("eth1addr", ethaddr);
109 setenv("ethrotate", NULL);
111 /* Invalidate eth0's MAC address */
112 strcpy(ethaddr, getenv("ethaddr"));
113 /* Must disable access protection for ethaddr before clearing */
114 setenv(".flags", "ethaddr");
115 setenv("ethaddr", NULL);
117 /* Make sure we can skip invalid devices */
118 setenv("ethact", "eth@10004000");
119 ut_assertok(net_loop(PING));
120 ut_asserteq_str("eth@10004000", getenv("ethact"));
122 /* Restore the env */
123 setenv("ethaddr", ethaddr);
124 setenv(".flags", NULL);
128 DM_TEST(dm_test_eth_rotate, DM_TESTF_SCAN_FDT);
130 static int dm_test_net_retry(struct unit_test_state *uts)
132 net_ping_ip = string_to_ip("1.1.2.2");
135 * eth1 is disabled and netretry is yes, so the ping should succeed and
136 * the active device should be eth0
138 sandbox_eth_disable_response(1, true);
139 setenv("ethact", "eth@10004000");
140 setenv("netretry", "yes");
141 sandbox_eth_skip_timeout();
142 ut_assertok(net_loop(PING));
143 ut_asserteq_str("eth@10002000", getenv("ethact"));
146 * eth1 is disabled and netretry is no, so the ping should fail and the
147 * active device should be eth1
149 setenv("ethact", "eth@10004000");
150 setenv("netretry", "no");
151 sandbox_eth_skip_timeout();
152 ut_asserteq(-ETIMEDOUT, net_loop(PING));
153 ut_asserteq_str("eth@10004000", getenv("ethact"));
155 /* Restore the env */
156 setenv("netretry", NULL);
157 sandbox_eth_disable_response(1, false);
161 DM_TEST(dm_test_net_retry, DM_TESTF_SCAN_FDT);