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 /* The asserts include a return on fail; cleanup in the caller */
86 static int _dm_test_eth_rotate1(struct unit_test_state *uts)
88 /* Make sure that the default is to rotate to the next interface */
89 setenv("ethact", "eth@10004000");
90 ut_assertok(net_loop(PING));
91 ut_asserteq_str("eth@10002000", getenv("ethact"));
93 /* If ethrotate is no, then we should fail on a bad MAC */
94 setenv("ethact", "eth@10004000");
95 setenv("ethrotate", "no");
96 ut_asserteq(-EINVAL, net_loop(PING));
97 ut_asserteq_str("eth@10004000", getenv("ethact"));
102 static int _dm_test_eth_rotate2(struct unit_test_state *uts)
104 /* Make sure we can skip invalid devices */
105 setenv("ethact", "eth@10004000");
106 ut_assertok(net_loop(PING));
107 ut_asserteq_str("eth@10004000", getenv("ethact"));
112 static int dm_test_eth_rotate(struct unit_test_state *uts)
117 /* Set target IP to mock ping */
118 net_ping_ip = string_to_ip("1.1.2.2");
120 /* Invalidate eth1's MAC address */
121 strcpy(ethaddr, getenv("eth1addr"));
122 /* Must disable access protection for eth1addr before clearing */
123 setenv(".flags", "eth1addr");
124 setenv("eth1addr", NULL);
126 retval = _dm_test_eth_rotate1(uts);
128 /* Restore the env */
129 setenv("eth1addr", ethaddr);
130 setenv("ethrotate", NULL);
133 /* Invalidate eth0's MAC address */
134 strcpy(ethaddr, getenv("ethaddr"));
135 /* Must disable access protection for ethaddr before clearing */
136 setenv(".flags", "ethaddr");
137 setenv("ethaddr", NULL);
139 retval = _dm_test_eth_rotate2(uts);
141 /* Restore the env */
142 setenv("ethaddr", ethaddr);
144 /* Restore the env */
145 setenv(".flags", NULL);
149 DM_TEST(dm_test_eth_rotate, DM_TESTF_SCAN_FDT);
151 /* The asserts include a return on fail; cleanup in the caller */
152 static int _dm_test_net_retry(struct unit_test_state *uts)
155 * eth1 is disabled and netretry is yes, so the ping should succeed and
156 * the active device should be eth0
158 sandbox_eth_disable_response(1, true);
159 setenv("ethact", "eth@10004000");
160 setenv("netretry", "yes");
161 sandbox_eth_skip_timeout();
162 ut_assertok(net_loop(PING));
163 ut_asserteq_str("eth@10002000", getenv("ethact"));
166 * eth1 is disabled and netretry is no, so the ping should fail and the
167 * active device should be eth1
169 setenv("ethact", "eth@10004000");
170 setenv("netretry", "no");
171 sandbox_eth_skip_timeout();
172 ut_asserteq(-ETIMEDOUT, net_loop(PING));
173 ut_asserteq_str("eth@10004000", getenv("ethact"));
178 static int dm_test_net_retry(struct unit_test_state *uts)
182 net_ping_ip = string_to_ip("1.1.2.2");
184 retval = _dm_test_net_retry(uts);
186 /* Restore the env */
187 setenv("netretry", NULL);
188 sandbox_eth_disable_response(1, false);
192 DM_TEST(dm_test_net_retry, DM_TESTF_SCAN_FDT);