blob: 6e002b8dce954dfca681393a0bea9f01d6224ea8 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0
Joe Hershberger4c197242015-03-22 17:09:15 -05002/*
3 * Copyright (c) 2015 National Instruments
4 *
5 * (C) Copyright 2015
6 * Joe Hershberger <joe.hershberger@ni.com>
Joe Hershberger4c197242015-03-22 17:09:15 -05007 */
8
9#include <common.h>
10#include <dm.h>
Joe Hershberger4c197242015-03-22 17:09:15 -050011#include <fdtdec.h>
12#include <malloc.h>
13#include <net.h>
Joe Hershberger3a77be52015-05-20 14:27:27 -050014#include <dm/test.h>
Bin Meng111473a2015-10-07 21:45:43 -070015#include <dm/device-internal.h>
16#include <dm/uclass-internal.h>
Joe Hershbergerf933a932015-03-22 17:09:20 -050017#include <asm/eth.h>
Joe Hershberger3a77be52015-05-20 14:27:27 -050018#include <test/ut.h>
Joe Hershberger4c197242015-03-22 17:09:15 -050019
Bin Meng111473a2015-10-07 21:45:43 -070020#define DM_TEST_ETH_NUM 4
21
Joe Hershberger3a77be52015-05-20 14:27:27 -050022static int dm_test_eth(struct unit_test_state *uts)
Joe Hershberger4c197242015-03-22 17:09:15 -050023{
Joe Hershberger5874dec2015-04-08 01:41:01 -050024 net_ping_ip = string_to_ip("1.1.2.2");
Joe Hershberger4c197242015-03-22 17:09:15 -050025
Simon Glass6a38e412017-08-03 12:22:09 -060026 env_set("ethact", "eth@10002000");
Joe Hershbergerc80b41b02015-04-08 01:41:21 -050027 ut_assertok(net_loop(PING));
Simon Glass64b723f2017-08-03 12:22:12 -060028 ut_asserteq_str("eth@10002000", env_get("ethact"));
Joe Hershberger4c197242015-03-22 17:09:15 -050029
Simon Glass6a38e412017-08-03 12:22:09 -060030 env_set("ethact", "eth@10003000");
Joe Hershbergerc80b41b02015-04-08 01:41:21 -050031 ut_assertok(net_loop(PING));
Simon Glass64b723f2017-08-03 12:22:12 -060032 ut_asserteq_str("eth@10003000", env_get("ethact"));
Joe Hershberger4c197242015-03-22 17:09:15 -050033
Simon Glass6a38e412017-08-03 12:22:09 -060034 env_set("ethact", "eth@10004000");
Joe Hershbergerc80b41b02015-04-08 01:41:21 -050035 ut_assertok(net_loop(PING));
Simon Glass64b723f2017-08-03 12:22:12 -060036 ut_asserteq_str("eth@10004000", env_get("ethact"));
Joe Hershberger4c197242015-03-22 17:09:15 -050037
38 return 0;
39}
40DM_TEST(dm_test_eth, DM_TESTF_SCAN_FDT);
Joe Hershberger279d2f62015-03-22 17:09:16 -050041
Joe Hershberger3a77be52015-05-20 14:27:27 -050042static int dm_test_eth_alias(struct unit_test_state *uts)
Joe Hershberger279d2f62015-03-22 17:09:16 -050043{
Joe Hershberger5874dec2015-04-08 01:41:01 -050044 net_ping_ip = string_to_ip("1.1.2.2");
Simon Glass6a38e412017-08-03 12:22:09 -060045 env_set("ethact", "eth0");
Joe Hershbergerc80b41b02015-04-08 01:41:21 -050046 ut_assertok(net_loop(PING));
Simon Glass64b723f2017-08-03 12:22:12 -060047 ut_asserteq_str("eth@10002000", env_get("ethact"));
Joe Hershberger279d2f62015-03-22 17:09:16 -050048
Simon Glass6a38e412017-08-03 12:22:09 -060049 env_set("ethact", "eth1");
Joe Hershbergerc80b41b02015-04-08 01:41:21 -050050 ut_assertok(net_loop(PING));
Simon Glass64b723f2017-08-03 12:22:12 -060051 ut_asserteq_str("eth@10004000", env_get("ethact"));
Joe Hershberger279d2f62015-03-22 17:09:16 -050052
53 /* Expected to fail since eth2 is not defined in the device tree */
Simon Glass6a38e412017-08-03 12:22:09 -060054 env_set("ethact", "eth2");
Joe Hershbergerc80b41b02015-04-08 01:41:21 -050055 ut_assertok(net_loop(PING));
Simon Glass64b723f2017-08-03 12:22:12 -060056 ut_asserteq_str("eth@10002000", env_get("ethact"));
Joe Hershberger279d2f62015-03-22 17:09:16 -050057
Simon Glass6a38e412017-08-03 12:22:09 -060058 env_set("ethact", "eth5");
Joe Hershbergerc80b41b02015-04-08 01:41:21 -050059 ut_assertok(net_loop(PING));
Simon Glass64b723f2017-08-03 12:22:12 -060060 ut_asserteq_str("eth@10003000", env_get("ethact"));
Joe Hershberger279d2f62015-03-22 17:09:16 -050061
62 return 0;
63}
64DM_TEST(dm_test_eth_alias, DM_TESTF_SCAN_FDT);
Joe Hershbergeraa52edd2015-03-22 17:09:17 -050065
Joe Hershberger3a77be52015-05-20 14:27:27 -050066static int dm_test_eth_prime(struct unit_test_state *uts)
Joe Hershbergeraa52edd2015-03-22 17:09:17 -050067{
Joe Hershberger5874dec2015-04-08 01:41:01 -050068 net_ping_ip = string_to_ip("1.1.2.2");
Joe Hershbergeraa52edd2015-03-22 17:09:17 -050069
70 /* Expected to be "eth@10003000" because of ethprime variable */
Simon Glass6a38e412017-08-03 12:22:09 -060071 env_set("ethact", NULL);
72 env_set("ethprime", "eth5");
Joe Hershbergerc80b41b02015-04-08 01:41:21 -050073 ut_assertok(net_loop(PING));
Simon Glass64b723f2017-08-03 12:22:12 -060074 ut_asserteq_str("eth@10003000", env_get("ethact"));
Joe Hershbergeraa52edd2015-03-22 17:09:17 -050075
76 /* Expected to be "eth@10002000" because it is first */
Simon Glass6a38e412017-08-03 12:22:09 -060077 env_set("ethact", NULL);
78 env_set("ethprime", NULL);
Joe Hershbergerc80b41b02015-04-08 01:41:21 -050079 ut_assertok(net_loop(PING));
Simon Glass64b723f2017-08-03 12:22:12 -060080 ut_asserteq_str("eth@10002000", env_get("ethact"));
Joe Hershbergeraa52edd2015-03-22 17:09:17 -050081
82 return 0;
83}
84DM_TEST(dm_test_eth_prime, DM_TESTF_SCAN_FDT);
Joe Hershbergerf340e542015-03-22 17:09:18 -050085
Bin Meng111473a2015-10-07 21:45:43 -070086/**
87 * This test case is trying to test the following scenario:
88 * - All ethernet devices are not probed
89 * - "ethaddr" for all ethernet devices are not set
90 * - "ethact" is set to a valid ethernet device name
91 *
92 * With Sandbox default test configuration, all ethernet devices are
93 * probed after power-up, so we have to manually create such scenario:
94 * - Remove all ethernet devices
95 * - Remove all "ethaddr" environment variables
96 * - Set "ethact" to the first ethernet device
97 *
98 * Do a ping test to see if anything goes wrong.
99 */
100static int dm_test_eth_act(struct unit_test_state *uts)
101{
102 struct udevice *dev[DM_TEST_ETH_NUM];
103 const char *ethname[DM_TEST_ETH_NUM] = {"eth@10002000", "eth@10003000",
104 "sbe5", "eth@10004000"};
105 const char *addrname[DM_TEST_ETH_NUM] = {"ethaddr", "eth5addr",
106 "eth3addr", "eth1addr"};
107 char ethaddr[DM_TEST_ETH_NUM][18];
108 int i;
109
Tom Rini0ac17d82017-09-26 14:08:30 -0400110 memset(ethaddr, '\0', sizeof(ethaddr));
Bin Meng111473a2015-10-07 21:45:43 -0700111 net_ping_ip = string_to_ip("1.1.2.2");
112
113 /* Prepare the test scenario */
114 for (i = 0; i < DM_TEST_ETH_NUM; i++) {
115 ut_assertok(uclass_find_device_by_name(UCLASS_ETH,
116 ethname[i], &dev[i]));
Stefan Roese80b5bc92017-03-20 12:51:48 +0100117 ut_assertok(device_remove(dev[i], DM_REMOVE_NORMAL));
Bin Meng111473a2015-10-07 21:45:43 -0700118
119 /* Invalidate MAC address */
Tom Rini0ac17d82017-09-26 14:08:30 -0400120 strncpy(ethaddr[i], env_get(addrname[i]), 17);
Bin Meng111473a2015-10-07 21:45:43 -0700121 /* Must disable access protection for ethaddr before clearing */
Simon Glass6a38e412017-08-03 12:22:09 -0600122 env_set(".flags", addrname[i]);
123 env_set(addrname[i], NULL);
Bin Meng111473a2015-10-07 21:45:43 -0700124 }
125
126 /* Set ethact to "eth@10002000" */
Simon Glass6a38e412017-08-03 12:22:09 -0600127 env_set("ethact", ethname[0]);
Bin Meng111473a2015-10-07 21:45:43 -0700128
129 /* Segment fault might happen if something is wrong */
130 ut_asserteq(-ENODEV, net_loop(PING));
131
132 for (i = 0; i < DM_TEST_ETH_NUM; i++) {
133 /* Restore the env */
Simon Glass6a38e412017-08-03 12:22:09 -0600134 env_set(".flags", addrname[i]);
135 env_set(addrname[i], ethaddr[i]);
Bin Meng111473a2015-10-07 21:45:43 -0700136
137 /* Probe the device again */
138 ut_assertok(device_probe(dev[i]));
139 }
Simon Glass6a38e412017-08-03 12:22:09 -0600140 env_set(".flags", NULL);
141 env_set("ethact", NULL);
Bin Meng111473a2015-10-07 21:45:43 -0700142
143 return 0;
144}
145DM_TEST(dm_test_eth_act, DM_TESTF_SCAN_FDT);
146
Joe Hershbergerfc755f92015-05-20 14:27:33 -0500147/* The asserts include a return on fail; cleanup in the caller */
148static int _dm_test_eth_rotate1(struct unit_test_state *uts)
Joe Hershbergerf340e542015-03-22 17:09:18 -0500149{
Joe Hershbergerf340e542015-03-22 17:09:18 -0500150 /* Make sure that the default is to rotate to the next interface */
Simon Glass6a38e412017-08-03 12:22:09 -0600151 env_set("ethact", "eth@10004000");
Joe Hershbergerc80b41b02015-04-08 01:41:21 -0500152 ut_assertok(net_loop(PING));
Simon Glass64b723f2017-08-03 12:22:12 -0600153 ut_asserteq_str("eth@10002000", env_get("ethact"));
Joe Hershbergerf340e542015-03-22 17:09:18 -0500154
155 /* If ethrotate is no, then we should fail on a bad MAC */
Simon Glass6a38e412017-08-03 12:22:09 -0600156 env_set("ethact", "eth@10004000");
157 env_set("ethrotate", "no");
Joe Hershbergerc80b41b02015-04-08 01:41:21 -0500158 ut_asserteq(-EINVAL, net_loop(PING));
Simon Glass64b723f2017-08-03 12:22:12 -0600159 ut_asserteq_str("eth@10004000", env_get("ethact"));
Joe Hershbergerf340e542015-03-22 17:09:18 -0500160
Joe Hershbergerfc755f92015-05-20 14:27:33 -0500161 return 0;
162}
Joe Hershbergerf340e542015-03-22 17:09:18 -0500163
Joe Hershbergerfc755f92015-05-20 14:27:33 -0500164static int _dm_test_eth_rotate2(struct unit_test_state *uts)
165{
Joe Hershbergerf340e542015-03-22 17:09:18 -0500166 /* Make sure we can skip invalid devices */
Simon Glass6a38e412017-08-03 12:22:09 -0600167 env_set("ethact", "eth@10004000");
Joe Hershbergerc80b41b02015-04-08 01:41:21 -0500168 ut_assertok(net_loop(PING));
Simon Glass64b723f2017-08-03 12:22:12 -0600169 ut_asserteq_str("eth@10004000", env_get("ethact"));
Joe Hershbergerf340e542015-03-22 17:09:18 -0500170
Bin Meng04a11cb2015-08-27 22:25:53 -0700171 /* Make sure we can handle device name which is not eth# */
Simon Glass6a38e412017-08-03 12:22:09 -0600172 env_set("ethact", "sbe5");
Bin Meng04a11cb2015-08-27 22:25:53 -0700173 ut_assertok(net_loop(PING));
Simon Glass64b723f2017-08-03 12:22:12 -0600174 ut_asserteq_str("sbe5", env_get("ethact"));
Bin Meng04a11cb2015-08-27 22:25:53 -0700175
Joe Hershbergerfc755f92015-05-20 14:27:33 -0500176 return 0;
177}
178
179static int dm_test_eth_rotate(struct unit_test_state *uts)
180{
181 char ethaddr[18];
182 int retval;
183
184 /* Set target IP to mock ping */
185 net_ping_ip = string_to_ip("1.1.2.2");
186
187 /* Invalidate eth1's MAC address */
Tom Rini0ac17d82017-09-26 14:08:30 -0400188 memset(ethaddr, '\0', sizeof(ethaddr));
189 strncpy(ethaddr, env_get("eth1addr"), 17);
Joe Hershbergerfc755f92015-05-20 14:27:33 -0500190 /* Must disable access protection for eth1addr before clearing */
Simon Glass6a38e412017-08-03 12:22:09 -0600191 env_set(".flags", "eth1addr");
192 env_set("eth1addr", NULL);
Joe Hershbergerfc755f92015-05-20 14:27:33 -0500193
194 retval = _dm_test_eth_rotate1(uts);
195
Joe Hershbergerf340e542015-03-22 17:09:18 -0500196 /* Restore the env */
Simon Glass6a38e412017-08-03 12:22:09 -0600197 env_set("eth1addr", ethaddr);
198 env_set("ethrotate", NULL);
Joe Hershbergerfc755f92015-05-20 14:27:33 -0500199
200 if (!retval) {
201 /* Invalidate eth0's MAC address */
Tom Rini0ac17d82017-09-26 14:08:30 -0400202 strncpy(ethaddr, env_get("ethaddr"), 17);
Joe Hershbergerfc755f92015-05-20 14:27:33 -0500203 /* Must disable access protection for ethaddr before clearing */
Simon Glass6a38e412017-08-03 12:22:09 -0600204 env_set(".flags", "ethaddr");
205 env_set("ethaddr", NULL);
Joe Hershbergerfc755f92015-05-20 14:27:33 -0500206
207 retval = _dm_test_eth_rotate2(uts);
208
209 /* Restore the env */
Simon Glass6a38e412017-08-03 12:22:09 -0600210 env_set("ethaddr", ethaddr);
Joe Hershbergerfc755f92015-05-20 14:27:33 -0500211 }
212 /* Restore the env */
Simon Glass6a38e412017-08-03 12:22:09 -0600213 env_set(".flags", NULL);
Joe Hershbergerf340e542015-03-22 17:09:18 -0500214
Joe Hershbergerfc755f92015-05-20 14:27:33 -0500215 return retval;
Joe Hershbergerf340e542015-03-22 17:09:18 -0500216}
217DM_TEST(dm_test_eth_rotate, DM_TESTF_SCAN_FDT);
Joe Hershbergerf933a932015-03-22 17:09:20 -0500218
Joe Hershbergerfc755f92015-05-20 14:27:33 -0500219/* The asserts include a return on fail; cleanup in the caller */
220static int _dm_test_net_retry(struct unit_test_state *uts)
Joe Hershbergerf933a932015-03-22 17:09:20 -0500221{
Joe Hershbergerf933a932015-03-22 17:09:20 -0500222 /*
223 * eth1 is disabled and netretry is yes, so the ping should succeed and
224 * the active device should be eth0
225 */
226 sandbox_eth_disable_response(1, true);
Simon Glass6a38e412017-08-03 12:22:09 -0600227 env_set("ethact", "eth@10004000");
228 env_set("netretry", "yes");
Joe Hershberger6901f432015-04-21 13:57:20 -0500229 sandbox_eth_skip_timeout();
Joe Hershbergerc80b41b02015-04-08 01:41:21 -0500230 ut_assertok(net_loop(PING));
Simon Glass64b723f2017-08-03 12:22:12 -0600231 ut_asserteq_str("eth@10002000", env_get("ethact"));
Joe Hershbergerf933a932015-03-22 17:09:20 -0500232
233 /*
234 * eth1 is disabled and netretry is no, so the ping should fail and the
235 * active device should be eth1
236 */
Simon Glass6a38e412017-08-03 12:22:09 -0600237 env_set("ethact", "eth@10004000");
238 env_set("netretry", "no");
Joe Hershberger6901f432015-04-21 13:57:20 -0500239 sandbox_eth_skip_timeout();
Thomas RIENOESSL2dee4192018-11-21 15:56:07 +0100240 ut_asserteq(-ENONET, net_loop(PING));
Simon Glass64b723f2017-08-03 12:22:12 -0600241 ut_asserteq_str("eth@10004000", env_get("ethact"));
Joe Hershbergerf933a932015-03-22 17:09:20 -0500242
Joe Hershbergerfc755f92015-05-20 14:27:33 -0500243 return 0;
244}
245
246static int dm_test_net_retry(struct unit_test_state *uts)
247{
248 int retval;
249
250 net_ping_ip = string_to_ip("1.1.2.2");
251
252 retval = _dm_test_net_retry(uts);
253
Joe Hershbergerf933a932015-03-22 17:09:20 -0500254 /* Restore the env */
Simon Glass6a38e412017-08-03 12:22:09 -0600255 env_set("netretry", NULL);
Joe Hershbergerf933a932015-03-22 17:09:20 -0500256 sandbox_eth_disable_response(1, false);
257
Joe Hershbergerfc755f92015-05-20 14:27:33 -0500258 return retval;
Joe Hershbergerf933a932015-03-22 17:09:20 -0500259}
260DM_TEST(dm_test_net_retry, DM_TESTF_SCAN_FDT);
Joe Hershberger54418d02018-09-26 16:49:00 -0500261
262static int sb_check_arp_reply(struct udevice *dev, void *packet,
263 unsigned int len)
264{
265 struct eth_sandbox_priv *priv = dev_get_priv(dev);
266 struct ethernet_hdr *eth = packet;
267 struct arp_hdr *arp;
268 /* Used by all of the ut_assert macros */
269 struct unit_test_state *uts = priv->priv;
270
271 if (ntohs(eth->et_protlen) != PROT_ARP)
272 return 0;
273
274 arp = packet + ETHER_HDR_SIZE;
275
276 if (ntohs(arp->ar_op) != ARPOP_REPLY)
277 return 0;
278
279 /* This test would be worthless if we are not waiting */
280 ut_assert(arp_is_waiting());
281
282 /* Validate response */
283 ut_assert(memcmp(eth->et_src, net_ethaddr, ARP_HLEN) == 0);
284 ut_assert(memcmp(eth->et_dest, priv->fake_host_hwaddr, ARP_HLEN) == 0);
285 ut_assert(eth->et_protlen == htons(PROT_ARP));
286
287 ut_assert(arp->ar_hrd == htons(ARP_ETHER));
288 ut_assert(arp->ar_pro == htons(PROT_IP));
289 ut_assert(arp->ar_hln == ARP_HLEN);
290 ut_assert(arp->ar_pln == ARP_PLEN);
291 ut_assert(memcmp(&arp->ar_sha, net_ethaddr, ARP_HLEN) == 0);
292 ut_assert(net_read_ip(&arp->ar_spa).s_addr == net_ip.s_addr);
293 ut_assert(memcmp(&arp->ar_tha, priv->fake_host_hwaddr, ARP_HLEN) == 0);
294 ut_assert(net_read_ip(&arp->ar_tpa).s_addr ==
295 string_to_ip("1.1.2.4").s_addr);
296
297 return 0;
298}
299
300static int sb_with_async_arp_handler(struct udevice *dev, void *packet,
301 unsigned int len)
302{
303 struct eth_sandbox_priv *priv = dev_get_priv(dev);
304 struct ethernet_hdr *eth = packet;
305 struct arp_hdr *arp = packet + ETHER_HDR_SIZE;
306 int ret;
307
308 /*
309 * If we are about to generate a reply to ARP, first inject a request
310 * from another host
311 */
312 if (ntohs(eth->et_protlen) == PROT_ARP &&
313 ntohs(arp->ar_op) == ARPOP_REQUEST) {
314 /* Make sure sandbox_eth_recv_arp_req() knows who is asking */
315 priv->fake_host_ipaddr = string_to_ip("1.1.2.4");
316
317 ret = sandbox_eth_recv_arp_req(dev);
318 if (ret)
319 return ret;
320 }
321
322 sandbox_eth_arp_req_to_reply(dev, packet, len);
323 sandbox_eth_ping_req_to_reply(dev, packet, len);
324
325 return sb_check_arp_reply(dev, packet, len);
326}
327
328static int dm_test_eth_async_arp_reply(struct unit_test_state *uts)
329{
330 net_ping_ip = string_to_ip("1.1.2.2");
331
332 sandbox_eth_set_tx_handler(0, sb_with_async_arp_handler);
333 /* Used by all of the ut_assert macros in the tx_handler */
334 sandbox_eth_set_priv(0, uts);
Joe Hershberger54418d02018-09-26 16:49:00 -0500335
336 env_set("ethact", "eth@10002000");
Joe Hershbergere79a5182018-09-26 16:49:02 -0500337 ut_assertok(net_loop(PING));
Joe Hershberger54418d02018-09-26 16:49:00 -0500338 ut_asserteq_str("eth@10002000", env_get("ethact"));
339
340 sandbox_eth_set_tx_handler(0, NULL);
341
342 return 0;
343}
344
345DM_TEST(dm_test_eth_async_arp_reply, DM_TESTF_SCAN_FDT);
Joe Hershberger9716dc12018-09-26 16:49:01 -0500346
347static int sb_check_ping_reply(struct udevice *dev, void *packet,
348 unsigned int len)
349{
350 struct eth_sandbox_priv *priv = dev_get_priv(dev);
351 struct ethernet_hdr *eth = packet;
352 struct ip_udp_hdr *ip;
353 struct icmp_hdr *icmp;
354 /* Used by all of the ut_assert macros */
355 struct unit_test_state *uts = priv->priv;
356
357 if (ntohs(eth->et_protlen) != PROT_IP)
358 return 0;
359
360 ip = packet + ETHER_HDR_SIZE;
361
362 if (ip->ip_p != IPPROTO_ICMP)
363 return 0;
364
365 icmp = (struct icmp_hdr *)&ip->udp_src;
366
367 if (icmp->type != ICMP_ECHO_REPLY)
368 return 0;
369
370 /* This test would be worthless if we are not waiting */
371 ut_assert(arp_is_waiting());
372
373 /* Validate response */
374 ut_assert(memcmp(eth->et_src, net_ethaddr, ARP_HLEN) == 0);
375 ut_assert(memcmp(eth->et_dest, priv->fake_host_hwaddr, ARP_HLEN) == 0);
376 ut_assert(eth->et_protlen == htons(PROT_IP));
377
378 ut_assert(net_read_ip(&ip->ip_src).s_addr == net_ip.s_addr);
379 ut_assert(net_read_ip(&ip->ip_dst).s_addr ==
380 string_to_ip("1.1.2.4").s_addr);
381
382 return 0;
383}
384
385static int sb_with_async_ping_handler(struct udevice *dev, void *packet,
386 unsigned int len)
387{
388 struct eth_sandbox_priv *priv = dev_get_priv(dev);
389 struct ethernet_hdr *eth = packet;
390 struct arp_hdr *arp = packet + ETHER_HDR_SIZE;
391 int ret;
392
393 /*
394 * If we are about to generate a reply to ARP, first inject a request
395 * from another host
396 */
397 if (ntohs(eth->et_protlen) == PROT_ARP &&
398 ntohs(arp->ar_op) == ARPOP_REQUEST) {
399 /* Make sure sandbox_eth_recv_arp_req() knows who is asking */
400 priv->fake_host_ipaddr = string_to_ip("1.1.2.4");
401
402 ret = sandbox_eth_recv_ping_req(dev);
403 if (ret)
404 return ret;
405 }
406
407 sandbox_eth_arp_req_to_reply(dev, packet, len);
408 sandbox_eth_ping_req_to_reply(dev, packet, len);
409
410 return sb_check_ping_reply(dev, packet, len);
411}
412
413static int dm_test_eth_async_ping_reply(struct unit_test_state *uts)
414{
415 net_ping_ip = string_to_ip("1.1.2.2");
416
417 sandbox_eth_set_tx_handler(0, sb_with_async_ping_handler);
418 /* Used by all of the ut_assert macros in the tx_handler */
419 sandbox_eth_set_priv(0, uts);
Joe Hershberger9716dc12018-09-26 16:49:01 -0500420
421 env_set("ethact", "eth@10002000");
Joe Hershbergere79a5182018-09-26 16:49:02 -0500422 ut_assertok(net_loop(PING));
Joe Hershberger9716dc12018-09-26 16:49:01 -0500423 ut_asserteq_str("eth@10002000", env_get("ethact"));
424
425 sandbox_eth_set_tx_handler(0, NULL);
426
427 return 0;
428}
429
430DM_TEST(dm_test_eth_async_ping_reply, DM_TESTF_SCAN_FDT);