u-boot/test/dm/dsa.c
Jerome Forissier 58ea7c3b50 test: dm: eth, dsa: update tests for NET_LWIP
Convert the tests to use the do_ping() interface which is now
common to NET and NET_LWIP. This allows running most network test with
SANDBOX and NET_LWIP. A few things to note though:

1. The ARP and IPv6 tests are enabled for NET only

2. The net_retry test is modified to use eth0 (eth@10002000) as the
active (but disabled) interface, and therefore we expect eth1
(eth@10003000) to be the fallback when "netretry" is "yes". This is in
replacement of eth7 (lan1) and eth0 (eth@10002000) respectively.
Indeed, it seems eth7 works with NET by chance and it certainly does not
work with NET_LWIP. I observed that even with NET,
sandbox_eth_disable_response(1, true) has no effect: remove it and
the test still passes. The interface ID is not correct to begin with; 1
corresponds to eth1 (eth@10003000) as shown by debug traces, it is not
eth7 (lan1). And using index 7 causes a SEGV.  In fact, it is not the
call to sandbox_eth_disable_response() that prevents the stack from
processing the ICMP reply but the timeout caused by the call to
sandbox_eth_skip_timeout(). Here is what happens when trying to ping
using the eth7 (lan1) interface with NET:

 do_ping(...)
     net_loop(PING)
         ping_start()
         eth_rx()
             sb_eth_recv()
                 time_test_add_offset(11000UL);
         if (get_timer(0) - time_start > time_delta)
             ping_timeout_handler()  // ping error, as expected

And the same with NET_LWIP:

 do_ping(...)
     ping_loop(...)
         sys_check_timeouts()
         net_lwip_rx(...)
             sb_eth_recv()
                 time_test_add_offset(11000UL);
             netif->input(...)  // the packet is processed succesfully

By choosing eth0 and sandbox_eth_disable_response(0, true), the incoming
packet is indeed discarded and things work as expected with both network
stacks.

Signed-off-by: Jerome Forissier <jerome.forissier@linaro.org>
Reviewed-by: Simon Glass <sjg@chromium.org>
2025-04-23 10:02:49 +02:00

81 lines
2.1 KiB
C

// SPDX-License-Identifier: GPL-2.0
/*
* Copyright 2020-2021 NXP
*/
#include <net/dsa.h>
#include <dm/test.h>
#include <test/ut.h>
#include <net.h>
#include <dm/uclass-internal.h>
#include <dm/device-internal.h>
/* This test exercises the major dsa.h API functions, after making sure
* that the DSA ports and the master Eth are correctly probed.
*/
static int dm_test_dsa_probe(struct unit_test_state *uts)
{
struct udevice *dev_dsa, *dev_port, *dev_master;
struct dsa_pdata *dsa_pdata;
enum uclass_id id;
id = uclass_get_by_name("dsa");
ut_assert(id == UCLASS_DSA);
ut_assertok(uclass_find_device_by_name(UCLASS_DSA, "dsa-test",
&dev_dsa));
ut_assertok(uclass_find_device_by_name(UCLASS_ETH, "dsa-test-eth",
&dev_master));
ut_assertok(device_probe(dev_master));
ut_assertok(uclass_find_device_by_name(UCLASS_ETH, "dsa-test@0",
&dev_port));
ut_assertok(device_probe(dev_port));
ut_assertok(uclass_find_device_by_name(UCLASS_ETH, "dsa-test@1",
&dev_port));
ut_assertok(device_probe(dev_port));
/* exercise DSA API */
dsa_pdata = dev_get_uclass_plat(dev_dsa);
ut_assertnonnull(dsa_pdata);
/* includes CPU port */
ut_assert(dsa_pdata->num_ports == 3);
ut_assertok(uclass_find_device_by_name(UCLASS_ETH, "lan0",
&dev_port));
ut_assertok(device_probe(dev_port));
ut_assertok(uclass_find_device_by_name(UCLASS_ETH, "lan1",
&dev_port));
ut_assertok(device_probe(dev_port));
dev_master = dsa_get_master(dev_dsa);
ut_assertnonnull(dev_master);
ut_asserteq_str("dsa-test-eth", dev_master->name);
return 0;
}
DM_TEST(dm_test_dsa_probe, UTF_SCAN_FDT);
/* This test sends ping requests with the local address through each DSA port
* via the sandbox DSA master Eth.
*/
static int dm_test_dsa(struct unit_test_state *uts)
{
char *argv[] = { "ping", "1.1.2.2" };
env_set("ethact", "eth2");
ut_assertok(do_ping(NULL, 0, ARRAY_SIZE(argv), argv));
env_set("ethact", "lan0");
ut_assertok(do_ping(NULL, 0, ARRAY_SIZE(argv), argv));
env_set("ethact", "lan1");
ut_assertok(do_ping(NULL, 0, ARRAY_SIZE(argv), argv));
env_set("ethact", "");
return 0;
}
DM_TEST(dm_test_dsa, UTF_SCAN_FDT);