]> git.kernelconcepts.de Git - karo-tx-uboot.git/blobdiff - test/dm/core.c
Merge branch 'master' of git://git.denx.de/u-boot-ti
[karo-tx-uboot.git] / test / dm / core.c
index be3646b968b5ddc38a8c01a55e407cfdbb215ea5..ff5c2a749c5e37dbbcca5340dabdf18374a8e5c2 100644 (file)
@@ -25,6 +25,7 @@ enum {
        TEST_INTVAL2            = 3,
        TEST_INTVAL3            = 6,
        TEST_INTVAL_MANUAL      = 101112,
+       TEST_INTVAL_PRE_RELOC   = 7,
 };
 
 static const struct dm_test_pdata test_pdata[] = {
@@ -37,6 +38,10 @@ static const struct dm_test_pdata test_pdata_manual = {
        .ping_add               = TEST_INTVAL_MANUAL,
 };
 
+static const struct dm_test_pdata test_pdata_pre_reloc = {
+       .ping_add               = TEST_INTVAL_PRE_RELOC,
+};
+
 U_BOOT_DEVICE(dm_test_info1) = {
        .name = "test_drv",
        .platdata = &test_pdata[0],
@@ -57,6 +62,39 @@ static struct driver_info driver_info_manual = {
        .platdata = &test_pdata_manual,
 };
 
+static struct driver_info driver_info_pre_reloc = {
+       .name = "test_pre_reloc_drv",
+       .platdata = &test_pdata_manual,
+};
+
+void dm_leak_check_start(struct dm_test_state *dms)
+{
+       dms->start = mallinfo();
+       if (!dms->start.uordblks)
+               puts("Warning: Please add '#define DEBUG' to the top of common/dlmalloc.c\n");
+}
+
+int dm_leak_check_end(struct dm_test_state *dms)
+{
+       struct mallinfo end;
+       int id;
+
+       /* Don't delete the root class, since we started with that */
+       for (id = UCLASS_ROOT + 1; id < UCLASS_COUNT; id++) {
+               struct uclass *uc;
+
+               uc = uclass_find(id);
+               if (!uc)
+                       continue;
+               ut_assertok(uclass_destroy(uc));
+       }
+
+       end = mallinfo();
+       ut_asserteq(dms->start.uordblks, end.uordblks);
+
+       return 0;
+}
+
 /* Test that binding with platdata occurs correctly */
 static int dm_test_autobind(struct dm_test_state *dms)
 {
@@ -71,7 +109,7 @@ static int dm_test_autobind(struct dm_test_state *dms)
        ut_asserteq(0, list_count_items(&gd->dm_root->child_head));
        ut_asserteq(0, dm_testdrv_op_count[DM_TEST_OP_POST_BIND]);
 
-       ut_assertok(dm_scan_platdata());
+       ut_assertok(dm_scan_platdata(false));
 
        /* We should have our test class now at least, plus more children */
        ut_assert(1 < list_count_items(&gd->uclass_root));
@@ -106,7 +144,7 @@ static int dm_test_autoprobe(struct dm_test_state *dms)
        ut_asserteq(0, dm_testdrv_op_count[DM_TEST_OP_POST_PROBE]);
 
        /* The root device should not be activated until needed */
-       ut_assert(!(dms->root->flags & DM_FLAG_ACTIVATED));
+       ut_assert(dms->root->flags & DM_FLAG_ACTIVATED);
 
        /*
         * We should be able to find the three test devices, and they should
@@ -181,7 +219,7 @@ static int dm_test_lifecycle(struct dm_test_state *dms)
 
        memcpy(op_count, dm_testdrv_op_count, sizeof(op_count));
 
-       ut_assertok(device_bind_by_name(dms->root, &driver_info_manual,
+       ut_assertok(device_bind_by_name(dms->root, false, &driver_info_manual,
                                        &dev));
        ut_assert(dev);
        ut_assert(dm_testdrv_op_count[DM_TEST_OP_BIND]
@@ -232,15 +270,15 @@ static int dm_test_ordering(struct dm_test_state *dms)
        struct udevice *dev, *dev_penultimate, *dev_last, *test_dev;
        int pingret;
 
-       ut_assertok(device_bind_by_name(dms->root, &driver_info_manual,
+       ut_assertok(device_bind_by_name(dms->root, false, &driver_info_manual,
                                        &dev));
        ut_assert(dev);
 
        /* Bind two new devices (numbers 4 and 5) */
-       ut_assertok(device_bind_by_name(dms->root, &driver_info_manual,
+       ut_assertok(device_bind_by_name(dms->root, false, &driver_info_manual,
                                        &dev_penultimate));
        ut_assert(dev_penultimate);
-       ut_assertok(device_bind_by_name(dms->root, &driver_info_manual,
+       ut_assertok(device_bind_by_name(dms->root, false, &driver_info_manual,
                                        &dev_last));
        ut_assert(dev_last);
 
@@ -255,7 +293,8 @@ static int dm_test_ordering(struct dm_test_state *dms)
        ut_assert(dev_last == test_dev);
 
        /* Add back the original device 3, now in position 5 */
-       ut_assertok(device_bind_by_name(dms->root, &driver_info_manual, &dev));
+       ut_assertok(device_bind_by_name(dms->root, false, &driver_info_manual,
+                                       &dev));
        ut_assert(dev);
 
        /* Try ping */
@@ -366,17 +405,14 @@ static int dm_test_leak(struct dm_test_state *dms)
        int i;
 
        for (i = 0; i < 2; i++) {
-               struct mallinfo start, end;
                struct udevice *dev;
                int ret;
                int id;
 
-               start = mallinfo();
-               if (!start.uordblks)
-                       puts("Warning: Please add '#define DEBUG' to the top of common/dlmalloc.c\n");
+               dm_leak_check_start(dms);
 
-               ut_assertok(dm_scan_platdata());
-               ut_assertok(dm_scan_fdt(gd->fdt_blob));
+               ut_assertok(dm_scan_platdata(false));
+               ut_assertok(dm_scan_fdt(gd->fdt_blob, false));
 
                /* Scanning the uclass is enough to probe all the devices */
                for (id = UCLASS_ROOT; id < UCLASS_COUNT; id++) {
@@ -387,18 +423,7 @@ static int dm_test_leak(struct dm_test_state *dms)
                        ut_assertok(ret);
                }
 
-               /* Don't delete the root class, since we started with that */
-               for (id = UCLASS_ROOT + 1; id < UCLASS_COUNT; id++) {
-                       struct uclass *uc;
-
-                       uc = uclass_find(id);
-                       if (!uc)
-                               continue;
-                       ut_assertok(uclass_destroy(uc));
-               }
-
-               end = mallinfo();
-               ut_asserteq(start.uordblks, end.uordblks);
+               ut_assertok(dm_leak_check_end(dms));
        }
 
        return 0;
@@ -444,8 +469,8 @@ static int create_children(struct dm_test_state *dms, struct udevice *parent,
        for (i = 0; i < count; i++) {
                struct dm_test_pdata *pdata;
 
-               ut_assertok(device_bind_by_name(parent, &driver_info_manual,
-                                               &dev));
+               ut_assertok(device_bind_by_name(parent, false,
+                                               &driver_info_manual, &dev));
                pdata = calloc(1, sizeof(*pdata));
                pdata->ping_add = key + i;
                dev->platdata = pdata;
@@ -542,3 +567,34 @@ static int dm_test_children(struct dm_test_state *dms)
        return 0;
 }
 DM_TEST(dm_test_children, 0);
+
+/* Test that pre-relocation devices work as expected */
+static int dm_test_pre_reloc(struct dm_test_state *dms)
+{
+       struct udevice *dev;
+
+       /* The normal driver should refuse to bind before relocation */
+       ut_asserteq(-EPERM, device_bind_by_name(dms->root, true,
+                                               &driver_info_manual, &dev));
+
+       /* But this one is marked pre-reloc */
+       ut_assertok(device_bind_by_name(dms->root, true,
+                                       &driver_info_pre_reloc, &dev));
+
+       return 0;
+}
+DM_TEST(dm_test_pre_reloc, 0);
+
+static int dm_test_uclass_before_ready(struct dm_test_state *dms)
+{
+       struct uclass *uc;
+
+       ut_assertok(uclass_get(UCLASS_TEST, &uc));
+
+       memset(gd, '\0', sizeof(*gd));
+       ut_asserteq_ptr(NULL, uclass_find(UCLASS_TEST));
+
+       return 0;
+}
+
+DM_TEST(dm_test_uclass_before_ready, 0);