Merge tag 'dm-9oct18' of git://git.denx.de/u-boot-dm
[platform/kernel/u-boot.git] / test / dm / bus.c
index d94dcf7..08137a2 100644 (file)
@@ -1,10 +1,12 @@
+// SPDX-License-Identifier: GPL-2.0+
 /*
  * Copyright (c) 2014 Google, Inc
- *
- * SPDX-License-Identifier:    GPL-2.0+
  */
 
 #include <common.h>
+#ifdef CONFIG_SANDBOX
+#include <os.h>
+#endif
 #include <dm.h>
 #include <dm/device-internal.h>
 #include <dm/test.h>
@@ -105,7 +107,7 @@ UCLASS_DRIVER(testbus) = {
 /* Test that we can probe for children */
 static int dm_test_bus_children(struct unit_test_state *uts)
 {
-       int num_devices = 6;
+       int num_devices = 7;
        struct udevice *bus;
        struct uclass *uc;
 
@@ -160,16 +162,33 @@ static int dm_test_bus_children_funcs(struct unit_test_state *uts)
        node = fdt_path_offset(blob, "/d-test");
        ut_asserteq(-ENODEV, device_find_child_by_of_offset(bus, node, &dev));
 
+       return 0;
+}
+DM_TEST(dm_test_bus_children_funcs, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
+
+static int dm_test_bus_children_of_offset(struct unit_test_state *uts)
+{
+       const void *blob = gd->fdt_blob;
+       struct udevice *bus, *dev;
+       int node;
+
+       ut_assertok(uclass_get_device(UCLASS_TEST_BUS, 0, &bus));
+       ut_assertnonnull(bus);
+
        /* Find a valid child */
        node = fdt_path_offset(blob, "/some-bus/c-test@1");
+       ut_assert(node > 0);
        ut_assertok(device_find_child_by_of_offset(bus, node, &dev));
+       ut_assertnonnull(dev);
        ut_assert(!(dev->flags & DM_FLAG_ACTIVATED));
        ut_assertok(device_get_child_by_of_offset(bus, node, &dev));
+       ut_assertnonnull(dev);
        ut_assert(dev->flags & DM_FLAG_ACTIVATED);
 
        return 0;
 }
-DM_TEST(dm_test_bus_children_funcs, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
+DM_TEST(dm_test_bus_children_of_offset,
+       DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT | DM_TESTF_FLAT_TREE);
 
 /* Test that we can iterate through children */
 static int dm_test_bus_children_iterators(struct unit_test_state *uts)
@@ -222,7 +241,7 @@ static int test_bus_parent_data(struct unit_test_state *uts)
        /* Check that it starts at 0 and goes away when device is removed */
        parent_data->sum += 5;
        ut_asserteq(5, parent_data->sum);
-       device_remove(dev);
+       device_remove(dev, DM_REMOVE_NORMAL);
        ut_asserteq_ptr(NULL, dev_get_parent_priv(dev));
 
        /* Check that we can do this twice */
@@ -281,6 +300,11 @@ static int dm_test_bus_parent_data_uclass(struct unit_test_state *uts)
        ut_assertok(uclass_find_device(UCLASS_TEST_BUS, 0, &bus));
        drv = (struct driver *)bus->driver;
        size = drv->per_child_auto_alloc_size;
+
+#ifdef CONFIG_SANDBOX
+       os_mprotect_allow(bus->uclass->uc_drv, sizeof(*bus->uclass->uc_drv));
+       os_mprotect_allow(drv, sizeof(*drv));
+#endif
        bus->uclass->uc_drv->per_child_auto_alloc_size = size;
        drv->per_child_auto_alloc_size = 0;
        ret = test_bus_parent_data(uts);
@@ -323,7 +347,7 @@ static int dm_test_bus_parent_ops(struct unit_test_state *uts)
                        continue;
                parent_data = dev_get_parent_priv(dev);
                ut_asserteq(FLAG_CHILD_PROBED, parent_data->flag);
-               ut_assertok(device_remove(dev));
+               ut_assertok(device_remove(dev, DM_REMOVE_NORMAL));
                ut_asserteq_ptr(NULL, dev_get_parent_priv(dev));
                ut_asserteq_ptr(dms->removed, dev);
        }
@@ -360,7 +384,7 @@ static int test_bus_parent_platdata(struct unit_test_state *uts)
                plat->count++;
                ut_asserteq(1, plat->count);
                device_probe(dev);
-               device_remove(dev);
+               device_remove(dev, DM_REMOVE_NORMAL);
 
                ut_asserteq_ptr(plat, dev_get_parent_platdata(dev));
                ut_asserteq(1, plat->count);
@@ -370,7 +394,7 @@ static int test_bus_parent_platdata(struct unit_test_state *uts)
        ut_asserteq(3, child_count);
 
        /* Removing the bus should also have no effect (it is still bound) */
-       device_remove(bus);
+       device_remove(bus, DM_REMOVE_NORMAL);
        for (device_find_first_child(bus, &dev), child_count = 0;
             dev;
             device_find_next_child(&dev)) {
@@ -424,6 +448,10 @@ static int dm_test_bus_parent_platdata_uclass(struct unit_test_state *uts)
        ut_assertok(uclass_find_device(UCLASS_TEST_BUS, 0, &bus));
        drv = (struct driver *)bus->driver;
        size = drv->per_child_platdata_auto_alloc_size;
+#ifdef CONFIG_SANDBOX
+       os_mprotect_allow(bus->uclass->uc_drv, sizeof(*bus->uclass->uc_drv));
+       os_mprotect_allow(drv, sizeof(*drv));
+#endif
        bus->uclass->uc_drv->per_child_platdata_auto_alloc_size = size;
        drv->per_child_platdata_auto_alloc_size = 0;
        ret = test_bus_parent_platdata(uts);