summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/dm/bus.c26
-rw-r--r--test/dm/eth.c64
2 files changed, 77 insertions, 13 deletions
diff --git a/test/dm/bus.c b/test/dm/bus.c
index a215905add..3b5a23b934 100644
--- a/test/dm/bus.c
+++ b/test/dm/bus.c
@@ -46,7 +46,7 @@ static int testbus_child_post_bind(struct udevice *dev)
static int testbus_child_pre_probe(struct udevice *dev)
{
- struct dm_test_parent_data *parent_data = dev_get_parentdata(dev);
+ struct dm_test_parent_data *parent_data = dev_get_parent_priv(dev);
parent_data->flag += FLAG_CHILD_PROBED;
@@ -64,7 +64,7 @@ static int testbus_child_pre_probe_uclass(struct udevice *dev)
static int testbus_child_post_remove(struct udevice *dev)
{
- struct dm_test_parent_data *parent_data = dev_get_parentdata(dev);
+ struct dm_test_parent_data *parent_data = dev_get_parent_priv(dev);
struct dm_test_state *dms = test_state;
parent_data->flag += FLAG_CHILD_REMOVED;
@@ -215,20 +215,20 @@ static int test_bus_parent_data(struct unit_test_state *uts)
/* Check that parent data is allocated */
ut_assertok(device_find_child_by_seq(bus, 0, true, &dev));
- ut_asserteq_ptr(NULL, dev_get_parentdata(dev));
+ ut_asserteq_ptr(NULL, dev_get_parent_priv(dev));
ut_assertok(device_get_child_by_seq(bus, 0, &dev));
- parent_data = dev_get_parentdata(dev);
+ parent_data = dev_get_parent_priv(dev);
ut_assert(NULL != parent_data);
/* Check that it starts at 0 and goes away when device is removed */
parent_data->sum += 5;
ut_asserteq(5, parent_data->sum);
device_remove(dev);
- ut_asserteq_ptr(NULL, dev_get_parentdata(dev));
+ ut_asserteq_ptr(NULL, dev_get_parent_priv(dev));
/* Check that we can do this twice */
ut_assertok(device_get_child_by_seq(bus, 0, &dev));
- parent_data = dev_get_parentdata(dev);
+ parent_data = dev_get_parent_priv(dev);
ut_assert(NULL != parent_data);
parent_data->sum += 5;
ut_asserteq(5, parent_data->sum);
@@ -239,11 +239,11 @@ static int test_bus_parent_data(struct unit_test_state *uts)
uclass_foreach_dev(dev, uc) {
/* Ignore these if they are not on this bus */
if (dev->parent != bus) {
- ut_asserteq_ptr(NULL, dev_get_parentdata(dev));
+ ut_asserteq_ptr(NULL, dev_get_parent_priv(dev));
continue;
}
ut_assertok(device_probe(dev));
- parent_data = dev_get_parentdata(dev);
+ parent_data = dev_get_parent_priv(dev);
parent_data->sum = value;
value += 5;
@@ -255,7 +255,7 @@ static int test_bus_parent_data(struct unit_test_state *uts)
/* Ignore these if they are not on this bus */
if (dev->parent != bus)
continue;
- parent_data = dev_get_parentdata(dev);
+ parent_data = dev_get_parent_priv(dev);
ut_asserteq(value, parent_data->sum);
value += 5;
@@ -311,10 +311,10 @@ static int dm_test_bus_parent_ops(struct unit_test_state *uts)
/* Ignore these if they are not on this bus */
if (dev->parent != bus)
continue;
- ut_asserteq_ptr(NULL, dev_get_parentdata(dev));
+ ut_asserteq_ptr(NULL, dev_get_parent_priv(dev));
ut_assertok(device_probe(dev));
- parent_data = dev_get_parentdata(dev);
+ parent_data = dev_get_parent_priv(dev);
ut_asserteq(FLAG_CHILD_PROBED, parent_data->flag);
}
@@ -322,10 +322,10 @@ static int dm_test_bus_parent_ops(struct unit_test_state *uts)
/* Ignore these if they are not on this bus */
if (dev->parent != bus)
continue;
- parent_data = dev_get_parentdata(dev);
+ parent_data = dev_get_parent_priv(dev);
ut_asserteq(FLAG_CHILD_PROBED, parent_data->flag);
ut_assertok(device_remove(dev));
- ut_asserteq_ptr(NULL, dev_get_parentdata(dev));
+ ut_asserteq_ptr(NULL, dev_get_parent_priv(dev));
ut_asserteq_ptr(dms->removed, dev);
}
test_state = NULL;
diff --git a/test/dm/eth.c b/test/dm/eth.c
index fcfb3e1ece..6288ae24ab 100644
--- a/test/dm/eth.c
+++ b/test/dm/eth.c
@@ -13,11 +13,15 @@
#include <malloc.h>
#include <net.h>
#include <dm/test.h>
+#include <dm/device-internal.h>
+#include <dm/uclass-internal.h>
#include <asm/eth.h>
#include <test/ut.h>
DECLARE_GLOBAL_DATA_PTR;
+#define DM_TEST_ETH_NUM 4
+
static int dm_test_eth(struct unit_test_state *uts)
{
net_ping_ip = string_to_ip("1.1.2.2");
@@ -82,6 +86,66 @@ static int dm_test_eth_prime(struct unit_test_state *uts)
}
DM_TEST(dm_test_eth_prime, DM_TESTF_SCAN_FDT);
+/**
+ * This test case is trying to test the following scenario:
+ * - All ethernet devices are not probed
+ * - "ethaddr" for all ethernet devices are not set
+ * - "ethact" is set to a valid ethernet device name
+ *
+ * With Sandbox default test configuration, all ethernet devices are
+ * probed after power-up, so we have to manually create such scenario:
+ * - Remove all ethernet devices
+ * - Remove all "ethaddr" environment variables
+ * - Set "ethact" to the first ethernet device
+ *
+ * Do a ping test to see if anything goes wrong.
+ */
+static int dm_test_eth_act(struct unit_test_state *uts)
+{
+ struct udevice *dev[DM_TEST_ETH_NUM];
+ const char *ethname[DM_TEST_ETH_NUM] = {"eth@10002000", "eth@10003000",
+ "sbe5", "eth@10004000"};
+ const char *addrname[DM_TEST_ETH_NUM] = {"ethaddr", "eth5addr",
+ "eth3addr", "eth1addr"};
+ char ethaddr[DM_TEST_ETH_NUM][18];
+ int i;
+
+ net_ping_ip = string_to_ip("1.1.2.2");
+
+ /* Prepare the test scenario */
+ for (i = 0; i < DM_TEST_ETH_NUM; i++) {
+ ut_assertok(uclass_find_device_by_name(UCLASS_ETH,
+ ethname[i], &dev[i]));
+ ut_assertok(device_remove(dev[i]));
+
+ /* Invalidate MAC address */
+ strcpy(ethaddr[i], getenv(addrname[i]));
+ /* Must disable access protection for ethaddr before clearing */
+ setenv(".flags", addrname[i]);
+ setenv(addrname[i], NULL);
+ }
+
+ /* Set ethact to "eth@10002000" */
+ setenv("ethact", ethname[0]);
+
+ /* Segment fault might happen if something is wrong */
+ ut_asserteq(-ENODEV, net_loop(PING));
+
+ for (i = 0; i < DM_TEST_ETH_NUM; i++) {
+ /* Restore the env */
+ setenv(".flags", addrname[i]);
+ setenv(addrname[i], ethaddr[i]);
+
+ /* Probe the device again */
+ ut_assertok(device_probe(dev[i]));
+ }
+ setenv(".flags", NULL);
+ setenv("ethact", NULL);
+
+ return 0;
+}
+DM_TEST(dm_test_eth_act, DM_TESTF_SCAN_FDT);
+
/* The asserts include a return on fail; cleanup in the caller */
static int _dm_test_eth_rotate1(struct unit_test_state *uts)
{
OpenPOWER on IntegriCloud