summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorSimon Glass <sjg@chromium.org>2014-10-13 23:41:49 -0600
committerSimon Glass <sjg@chromium.org>2014-10-22 10:36:45 -0600
commita8981d4f80b010666ad754d20a4f389f94d6726d (patch)
tree48bf392bb2e0f00248ac4949fdceefa4b7509cb6 /test
parent0b304a2494eed170562a9fdd64e31332ad5ae73a (diff)
downloadtalos-obmc-uboot-a8981d4f80b010666ad754d20a4f389f94d6726d.tar.gz
talos-obmc-uboot-a8981d4f80b010666ad754d20a4f389f94d6726d.zip
dm: core: Add functions for iterating through device children
Buses need to iterate through their children in some situations. Add a few functions to make this easy. Signed-off-by: Simon Glass <sjg@chromium.org> Acked-by: Jagannadha Sutradharudu Teki <jagannadh.teki@gmail.com>
Diffstat (limited to 'test')
-rw-r--r--test/dm/bus.c31
1 files changed, 31 insertions, 0 deletions
diff --git a/test/dm/bus.c b/test/dm/bus.c
index 873d64e42a..abbaccff50 100644
--- a/test/dm/bus.c
+++ b/test/dm/bus.c
@@ -140,6 +140,37 @@ static int dm_test_bus_children_funcs(struct dm_test_state *dms)
}
DM_TEST(dm_test_bus_children_funcs, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
+/* Test that we can iterate through children */
+static int dm_test_bus_children_iterators(struct dm_test_state *dms)
+{
+ struct udevice *bus, *dev, *child;
+
+ /* Walk through the children one by one */
+ ut_assertok(uclass_get_device(UCLASS_TEST_BUS, 0, &bus));
+ ut_assertok(device_find_first_child(bus, &dev));
+ ut_asserteq_str("c-test@5", dev->name);
+ ut_assertok(device_find_next_child(&dev));
+ ut_asserteq_str("c-test@0", dev->name);
+ ut_assertok(device_find_next_child(&dev));
+ ut_asserteq_str("c-test@1", dev->name);
+ ut_assertok(device_find_next_child(&dev));
+ ut_asserteq_ptr(dev, NULL);
+
+ /* Move to the next child without using device_find_first_child() */
+ ut_assertok(device_find_child_by_seq(bus, 5, true, &dev));
+ ut_asserteq_str("c-test@5", dev->name);
+ ut_assertok(device_find_next_child(&dev));
+ ut_asserteq_str("c-test@0", dev->name);
+
+ /* Try a device with no children */
+ ut_assertok(device_find_first_child(dev, &child));
+ ut_asserteq_ptr(child, NULL);
+
+ return 0;
+}
+DM_TEST(dm_test_bus_children_iterators,
+ DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
+
/* Test that the bus can store data about each child */
static int dm_test_bus_parent_data(struct dm_test_state *dms)
{
OpenPOWER on IntegriCloud