/* Test that binding with platdata occurs correctly */ static int dm_test_autobind(struct unit_test_state *uts) { struct dm_test_state *dms = uts->priv; struct udevice *dev; /* * We should have a single class (UCLASS_ROOT) and a single root * device with no children. */ ut_assert(dms->root); ut_asserteq(1, list_count_items(&gd->uclass_root)); 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(false)); /* We should have our test class now at least, plus more children */ ut_assert(1 < list_count_items(&gd->uclass_root)); ut_assert(0 < list_count_items(&gd->dm_root->child_head)); /* Our 3 dm_test_infox children should be bound to the test uclass */ ut_asserteq(3, dm_testdrv_op_count[DM_TEST_OP_POST_BIND]); /* No devices should be probed */ list_for_each_entry(dev, &gd->dm_root->child_head, sibling_node) ut_assert(!(dev->flags & DM_FLAG_ACTIVATED)); /* Our test driver should have been bound 3 times */ ut_assert(dm_testdrv_op_count[DM_TEST_OP_BIND] == 3); return 0; }
/* Test that FDT-based binding works correctly */ static int dm_test_fdt(struct unit_test_state *uts) { const int num_devices = 6; struct udevice *dev; struct uclass *uc; int ret; int i; ret = dm_scan_fdt(gd->fdt_blob, false); ut_assert(!ret); ret = uclass_get(UCLASS_TEST_FDT, &uc); ut_assert(!ret); /* These are num_devices compatible root-level device tree nodes */ ut_asserteq(num_devices, list_count_items(&uc->dev_head)); /* Each should have platform data but no private data */ for (i = 0; i < num_devices; i++) { ret = uclass_find_device(UCLASS_TEST_FDT, i, &dev); ut_assert(!ret); ut_assert(!dev_get_priv(dev)); ut_assert(dev->platdata); } ut_assertok(dm_check_devices(uts, num_devices)); return 0; }
/* Test that we can probe for children */ static int dm_test_bus_children(struct unit_test_state *uts) { int num_devices = 6; struct udevice *bus; struct uclass *uc; ut_assertok(uclass_get(UCLASS_TEST_FDT, &uc)); ut_asserteq(num_devices, list_count_items(&uc->dev_head)); /* Probe the bus, which should yield 3 more devices */ ut_assertok(uclass_get_device(UCLASS_TEST_BUS, 0, &bus)); num_devices += 3; ut_assertok(uclass_get(UCLASS_TEST_FDT, &uc)); ut_asserteq(num_devices, list_count_items(&uc->dev_head)); ut_assert(!dm_check_devices(uts, num_devices)); return 0; }
static int dm_test_fdt_pre_reloc(struct unit_test_state *uts) { struct uclass *uc; int ret; ret = dm_scan_fdt(gd->fdt_blob, true); ut_assert(!ret); ret = uclass_get(UCLASS_TEST_FDT, &uc); ut_assert(!ret); /* These is only one pre-reloc device */ ut_asserteq(1, list_count_items(&uc->dev_head)); return 0; }