sandbox: Allow ethernet bootdevs to be disabled for tests

Most tests don't want these and can create a lot of noise. Add a way to
disable them. Use that in tests, with a flag provided to enable them for
tests that need this feature.

Signed-off-by: Simon Glass <sjg@chromium.org>
This commit is contained in:
Simon Glass 2023-01-17 10:47:28 -07:00 committed by Tom Rini
parent f43b2df3e0
commit 70dd88657b
4 changed files with 48 additions and 2 deletions

View file

@ -886,4 +886,20 @@ static inline struct in_addr env_get_ip(char *var)
*/
void reset_phy(void);
#if CONFIG_IS_ENABLED(NET)
/**
* eth_set_enable_bootdevs() - Enable or disable binding of Ethernet bootdevs
*
* These get in the way of bootstd testing, so are normally disabled by tests.
* This provide control of this setting. It only affects binding of Ethernet
* devices, so if that has already happened, this flag does nothing.
*
* @enable: true to enable binding of bootdevs when binding new Ethernet
* devices, false to disable it
*/
void eth_set_enable_bootdevs(bool enable);
#else
static inline void eth_set_enable_bootdevs(bool enable) {}
#endif
#endif /* __NET_H__ */

View file

@ -71,6 +71,7 @@ enum {
* since it cannot access the flags.
*/
UT_TESTF_MANUAL = BIT(8),
UT_TESTF_ETH_BOOTDEV = BIT(9), /* enable Ethernet bootdevs */
};
/**
@ -194,4 +195,15 @@ static inline bool test_eth_enabled(void)
return enabled;
}
/* Allow ethernet bootdev to be ignored for testing purposes */
static inline bool test_eth_bootdev_enabled(void)
{
bool enabled = true;
#ifdef CONFIG_SANDBOX
enabled = sandbox_eth_enabled();
#endif
return enabled;
}
#endif /* __TEST_TEST_H */

View file

@ -38,9 +38,12 @@ struct eth_device_priv {
* struct eth_uclass_priv - The structure attached to the uclass itself
*
* @current: The Ethernet device that the network functions are using
* @no_bootdevs: true to skip binding Ethernet bootdevs (this is a negative flag
* so that the default value enables it)
*/
struct eth_uclass_priv {
struct udevice *current;
bool no_bootdevs;
};
/* eth_errno - This stores the most recent failure code from DM functions */
@ -59,6 +62,14 @@ static struct eth_uclass_priv *eth_get_uclass_priv(void)
return uclass_get_priv(uc);
}
void eth_set_enable_bootdevs(bool enable)
{
struct eth_uclass_priv *priv = eth_get_uclass_priv();
if (priv)
priv->no_bootdevs = !enable;
}
void eth_set_current_to_next(void)
{
struct eth_uclass_priv *uc_priv;
@ -477,6 +488,7 @@ int eth_initialize(void)
static int eth_post_bind(struct udevice *dev)
{
struct eth_uclass_priv *priv = uclass_get_priv(dev->uclass);
int ret;
if (strchr(dev->name, ' ')) {
@ -488,7 +500,7 @@ static int eth_post_bind(struct udevice *dev)
#ifdef CONFIG_DM_ETH_PHY
eth_phy_binds_nodes(dev);
#endif
if (CONFIG_IS_ENABLED(BOOTDEV_ETH)) {
if (CONFIG_IS_ENABLED(BOOTDEV_ETH) && !priv->no_bootdevs) {
ret = bootdev_setup_for_dev(dev, "eth_bootdev");
if (ret)
return log_msg_ret("bootdev", ret);

View file

@ -10,6 +10,7 @@
#include <cyclic.h>
#include <dm.h>
#include <event.h>
#include <net.h>
#include <of_live.h>
#include <os.h>
#include <dm/ofnode.h>
@ -303,8 +304,13 @@ static int test_pre_run(struct unit_test_state *uts, struct unit_test *test)
ut_assertok(do_autoprobe(uts));
if (!CONFIG_IS_ENABLED(OF_PLATDATA) &&
(test->flags & UT_TESTF_SCAN_FDT))
(test->flags & UT_TESTF_SCAN_FDT)) {
/*
* only set this if we know the ethernet uclass will be created
*/
eth_set_enable_bootdevs(test->flags & UT_TESTF_ETH_BOOTDEV);
ut_assertok(dm_extended_scan(false));
}
/*
* Do this after FDT scan since dm_scan_other() in bootstd-uclass.c