]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
test: dm: core: Add test case for uclass driver's child_post_probe()
authorBin Meng <bmeng.cn@gmail.com>
Mon, 15 Oct 2018 09:20:58 +0000 (02:20 -0700)
committerSimon Glass <sjg@chromium.org>
Wed, 14 Nov 2018 17:16:27 +0000 (09:16 -0800)
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>
include/dm/test.h
test/dm/bus.c
test/dm/test-fdt.c

index 83418eb48225b933067ac8f9e5cc2cc0cc531306..07385cd531fa2c9af660010ad4a439aab0ec75e0 100644 (file)
@@ -69,6 +69,7 @@ struct dm_test_priv {
        int op_count[DM_TEST_OP_COUNT];
        int uclass_flag;
        int uclass_total;
+       int uclass_postp;
 };
 
 /**
index d0cd5a009cdebd5eda63d8c47705ca5b01154eb1..93f3acd4308e97691a45e1594db2c7d7ea43afb8 100644 (file)
@@ -63,6 +63,15 @@ static int testbus_child_pre_probe_uclass(struct udevice *dev)
        return 0;
 }
 
+static int testbus_child_post_probe_uclass(struct udevice *dev)
+{
+       struct dm_test_priv *priv = dev_get_priv(dev);
+
+       priv->uclass_postp++;
+
+       return 0;
+}
+
 static int testbus_child_post_remove(struct udevice *dev)
 {
        struct dm_test_parent_data *parent_data = dev_get_parent_priv(dev);
@@ -102,6 +111,7 @@ UCLASS_DRIVER(testbus) = {
        .id             = UCLASS_TEST_BUS,
        .flags          = DM_UC_FLAG_SEQ_ALIAS,
        .child_pre_probe = testbus_child_pre_probe_uclass,
+       .child_post_probe = testbus_child_post_probe_uclass,
 };
 
 /* 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)
 }
 DM_TEST(dm_test_bus_child_pre_probe_uclass,
        DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
+
+/*
+ * Test that the bus' uclass' child_post_probe() is called after the
+ * device's probe() method
+ */
+static int dm_test_bus_child_post_probe_uclass(struct unit_test_state *uts)
+{
+       struct udevice *bus, *dev;
+       int child_count;
+
+       /*
+        * See testfdt_drv_probe() which effectively initializes that
+        * the uclass postp flag is set to a value
+        */
+       ut_assertok(uclass_get_device(UCLASS_TEST_BUS, 0, &bus));
+       for (device_find_first_child(bus, &dev), child_count = 0;
+            dev;
+            device_find_next_child(&dev)) {
+               struct dm_test_priv *priv = dev_get_priv(dev);
+
+               /* Check that things happened in the right order */
+               ut_asserteq_ptr(NULL, priv);
+               ut_assertok(device_probe(dev));
+
+               priv = dev_get_priv(dev);
+               ut_assert(priv != NULL);
+               ut_asserteq(0, priv->uclass_postp);
+               child_count++;
+       }
+       ut_asserteq(3, child_count);
+
+       return 0;
+}
+DM_TEST(dm_test_bus_child_post_probe_uclass,
+       DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
index 3da384f4c5887be568b15209837a1f1949511be2..e43acb21d5e710043be167ace4f3382682ddd860 100644 (file)
@@ -55,10 +55,13 @@ static int testfdt_drv_probe(struct udevice *dev)
 
        /*
         * If this device is on a bus, the uclass_flag will be set before
-        * calling this function. This is used by
-        * dm_test_bus_child_pre_probe_uclass().
+        * calling this function. In the meantime the uclass_postp is
+        * initlized to a value -1. These are used respectively by
+        * dm_test_bus_child_pre_probe_uclass() and
+        * dm_test_bus_child_post_probe_uclass().
         */
        priv->uclass_total += priv->uclass_flag;
+       priv->uclass_postp = -1;
 
        return 0;
 }