diff options
author | Simon Glass <sjg@chromium.org> | 2018-10-01 12:22:07 -0600 |
---|---|---|
committer | Simon Glass <sjg@chromium.org> | 2018-10-09 04:40:27 -0600 |
commit | cdb6aa0afb52da34306c4339f2f4d6cbd3b0ad02 (patch) | |
tree | 4940b03e27947c496c460da6df96d719fe29dedc /test | |
parent | 9f15cc14bf88a9ee8d7b1fbf607cde22923889d6 (diff) | |
download | u-boot-cdb6aa0afb52da34306c4339f2f4d6cbd3b0ad02.tar.gz |
dm: core: Add a function to find the first inactive child
Some devices have children and want to press an existing inactive child
into service when needed. Add a function to help with this.
Signed-off-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'test')
-rw-r--r-- | test/dm/core.c | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/test/dm/core.c b/test/dm/core.c index c15a8406c0..260f6494a2 100644 --- a/test/dm/core.c +++ b/test/dm/core.c @@ -870,3 +870,34 @@ static int dm_test_uclass_names(struct unit_test_state *uts) return 0; } DM_TEST(dm_test_uclass_names, DM_TESTF_SCAN_PDATA); + +static int dm_test_inactive_child(struct unit_test_state *uts) +{ + struct dm_test_state *dms = uts->priv; + struct udevice *parent, *dev1, *dev2; + + /* Skip the behaviour in test_post_probe() */ + dms->skip_post_probe = 1; + + ut_assertok(uclass_first_device_err(UCLASS_TEST, &parent)); + + /* + * Create a child but do not activate it. Calling the function again + * should return the same child. + */ + ut_asserteq(-ENODEV, device_find_first_inactive_child(parent, + UCLASS_TEST, &dev1)); + ut_assertok(device_bind_ofnode(parent, DM_GET_DRIVER(test_drv), + "test_child", 0, ofnode_null(), &dev1)); + + ut_assertok(device_find_first_inactive_child(parent, UCLASS_TEST, + &dev2)); + ut_asserteq_ptr(dev1, dev2); + + ut_assertok(device_probe(dev1)); + ut_asserteq(-ENODEV, device_find_first_inactive_child(parent, + UCLASS_TEST, &dev2)); + + return 0; +} +DM_TEST(dm_test_inactive_child, DM_TESTF_SCAN_PDATA); |