aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBin Meng2018-10-15 04:20:58 -0500
committerSimon Glass2018-11-14 11:16:27 -0600
commitd92878aa4089e1c91f8a6cb7b9655cd27e6ea23c (patch)
treee9f5a5a6d0d6cedeadda52da4cc8a38e26163289
parent651d0c019a428ca8b14352210c1ce7804dd51fae (diff)
downloadu-boot-d92878aa4089e1c91f8a6cb7b9655cd27e6ea23c.tar.gz
u-boot-d92878aa4089e1c91f8a6cb7b9655cd27e6ea23c.tar.xz
u-boot-d92878aa4089e1c91f8a6cb7b9655cd27e6ea23c.zip
test: dm: core: Add test case for uclass driver's child_post_probe()
Add test case to cover uclass driver's child_post_probe() method. Signed-off-by: Bin Meng <bmeng.cn@gmail.com> Reviewed-by: Simon Glass <sjg@chromium.org>
-rw-r--r--include/dm/test.h1
-rw-r--r--test/dm/bus.c45
-rw-r--r--test/dm/test-fdt.c7
3 files changed, 51 insertions, 2 deletions
diff --git a/include/dm/test.h b/include/dm/test.h
index 83418eb482..07385cd531 100644
--- a/include/dm/test.h
+++ b/include/dm/test.h
@@ -69,6 +69,7 @@ struct dm_test_priv {
69 int op_count[DM_TEST_OP_COUNT]; 69 int op_count[DM_TEST_OP_COUNT];
70 int uclass_flag; 70 int uclass_flag;
71 int uclass_total; 71 int uclass_total;
72 int uclass_postp;
72}; 73};
73 74
74/** 75/**
diff --git a/test/dm/bus.c b/test/dm/bus.c
index d0cd5a009c..93f3acd430 100644
--- a/test/dm/bus.c
+++ b/test/dm/bus.c
@@ -63,6 +63,15 @@ static int testbus_child_pre_probe_uclass(struct udevice *dev)
63 return 0; 63 return 0;
64} 64}
65 65
66static int testbus_child_post_probe_uclass(struct udevice *dev)
67{
68 struct dm_test_priv *priv = dev_get_priv(dev);
69
70 priv->uclass_postp++;
71
72 return 0;
73}
74
66static int testbus_child_post_remove(struct udevice *dev) 75static int testbus_child_post_remove(struct udevice *dev)
67{ 76{
68 struct dm_test_parent_data *parent_data = dev_get_parent_priv(dev); 77 struct dm_test_parent_data *parent_data = dev_get_parent_priv(dev);
@@ -102,6 +111,7 @@ UCLASS_DRIVER(testbus) = {
102 .id = UCLASS_TEST_BUS, 111 .id = UCLASS_TEST_BUS,
103 .flags = DM_UC_FLAG_SEQ_ALIAS, 112 .flags = DM_UC_FLAG_SEQ_ALIAS,
104 .child_pre_probe = testbus_child_pre_probe_uclass, 113 .child_pre_probe = testbus_child_pre_probe_uclass,
114 .child_post_probe = testbus_child_post_probe_uclass,
105}; 115};
106 116
107/* Test that we can probe for children */ 117/* Test that we can probe for children */
@@ -547,3 +557,38 @@ static int dm_test_bus_child_pre_probe_uclass(struct unit_test_state *uts)
547} 557}
548DM_TEST(dm_test_bus_child_pre_probe_uclass, 558DM_TEST(dm_test_bus_child_pre_probe_uclass,
549 DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT); 559 DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
560
561/*
562 * Test that the bus' uclass' child_post_probe() is called after the
563 * device's probe() method
564 */
565static int dm_test_bus_child_post_probe_uclass(struct unit_test_state *uts)
566{
567 struct udevice *bus, *dev;
568 int child_count;
569
570 /*
571 * See testfdt_drv_probe() which effectively initializes that
572 * the uclass postp flag is set to a value
573 */
574 ut_assertok(uclass_get_device(UCLASS_TEST_BUS, 0, &bus));
575 for (device_find_first_child(bus, &dev), child_count = 0;
576 dev;
577 device_find_next_child(&dev)) {
578 struct dm_test_priv *priv = dev_get_priv(dev);
579
580 /* Check that things happened in the right order */
581 ut_asserteq_ptr(NULL, priv);
582 ut_assertok(device_probe(dev));
583
584 priv = dev_get_priv(dev);
585 ut_assert(priv != NULL);
586 ut_asserteq(0, priv->uclass_postp);
587 child_count++;
588 }
589 ut_asserteq(3, child_count);
590
591 return 0;
592}
593DM_TEST(dm_test_bus_child_post_probe_uclass,
594 DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
diff --git a/test/dm/test-fdt.c b/test/dm/test-fdt.c
index 3da384f4c5..e43acb21d5 100644
--- a/test/dm/test-fdt.c
+++ b/test/dm/test-fdt.c
@@ -55,10 +55,13 @@ static int testfdt_drv_probe(struct udevice *dev)
55 55
56 /* 56 /*
57 * If this device is on a bus, the uclass_flag will be set before 57 * If this device is on a bus, the uclass_flag will be set before
58 * calling this function. This is used by 58 * calling this function. In the meantime the uclass_postp is
59 * dm_test_bus_child_pre_probe_uclass(). 59 * initlized to a value -1. These are used respectively by
60 * dm_test_bus_child_pre_probe_uclass() and
61 * dm_test_bus_child_post_probe_uclass().
60 */ 62 */
61 priv->uclass_total += priv->uclass_flag; 63 priv->uclass_total += priv->uclass_flag;
64 priv->uclass_postp = -1;
62 65
63 return 0; 66 return 0;
64} 67}