static int dm_test_main(const char *test_name) { struct unit_test *tests = ll_entry_start(struct unit_test, dm_test); const int n_ents = ll_entry_count(struct unit_test, dm_test); struct unit_test_state *uts = &global_dm_test_state; uts->priv = &_global_priv_dm_test_state; struct unit_test *test; int run_count; /* * If we have no device tree, or it only has a root node, then these * tests clearly aren't going to work... */ if (!gd->fdt_blob || fdt_next_node(gd->fdt_blob, 0, NULL) < 0) { puts("Please run with test device tree:\n" " ./u-boot -d arch/sandbox/dts/test.dtb\n"); ut_assert(gd->fdt_blob); } if (!test_name) printf("Running %d driver model tests\n", n_ents); run_count = 0; for (test = tests; test < tests + n_ents; test++) { const char *name = test->name; /* All tests have this prefix */ if (!strncmp(name, "dm_test_", 8)) name += 8; if (test_name && strcmp(test_name, name)) continue; printf("Test: %s\n", test->name); run_count++; ut_assertok(dm_test_init(uts)); uts->start = mallinfo(); if (test->flags & DM_TESTF_SCAN_PDATA) ut_assertok(dm_scan_platdata(false)); if (test->flags & DM_TESTF_PROBE_TEST) ut_assertok(do_autoprobe(uts)); if (test->flags & DM_TESTF_SCAN_FDT) ut_assertok(dm_scan_fdt(gd->fdt_blob, false)); test->func(uts); ut_assertok(dm_test_destroy(uts)); } if (test_name && !run_count) printf("Test '%s' not found\n", test_name); else printf("Failures: %d\n", uts->fail_count); gd->dm_root = NULL; ut_assertok(dm_init()); dm_scan_platdata(false); dm_scan_fdt(gd->fdt_blob, false); return uts->fail_count ? CMD_RET_FAILURE : 0; }
/* 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; }
/* Remove and recreate everything, check for memory leaks */ static int dm_test_leak(struct unit_test_state *uts) { int i; for (i = 0; i < 2; i++) { struct udevice *dev; int ret; int id; dm_leak_check_start(uts); 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++) { for (ret = uclass_first_device(UCLASS_TEST, &dev); dev; ret = uclass_next_device(&dev)) ; ut_assertok(ret); } ut_assertok(dm_leak_check_end(uts)); } return 0; }
int dm_init_and_scan(bool pre_reloc_only) { int ret; ret = dm_init(); if (ret) { debug("dm_init() failed: %d\n", ret); return ret; } ret = dm_scan_platdata(pre_reloc_only); if (ret) { debug("dm_scan_platdata() failed: %d\n", ret); return ret; } if (CONFIG_IS_ENABLED(OF_CONTROL)) { ret = dm_scan_fdt(gd->fdt_blob, pre_reloc_only); if (ret) { debug("dm_scan_fdt() failed: %d\n", ret); return ret; } } ret = dm_scan_other(pre_reloc_only); if (ret) return ret; return 0; }
static int dm_do_test(struct unit_test_state *uts, struct unit_test *test, bool of_live) { struct sandbox_state *state = state_get_current(); const char *fname = strrchr(test->file, '/') + 1; printf("Test: %s: %s%s\n", test->name, fname, !of_live ? " (flat tree)" : ""); ut_assertok(dm_test_init(uts, of_live)); uts->start = mallinfo(); if (test->flags & DM_TESTF_SCAN_PDATA) ut_assertok(dm_scan_platdata(false)); if (test->flags & DM_TESTF_PROBE_TEST) ut_assertok(do_autoprobe(uts)); if (test->flags & DM_TESTF_SCAN_FDT) ut_assertok(dm_extended_scan_fdt(gd->fdt_blob, false)); /* * Silence the console and rely on console reocrding to get * our output. */ console_record_reset(); if (!state->show_test_output) gd->flags |= GD_FLG_SILENT; test->func(uts); gd->flags &= ~GD_FLG_SILENT; state_set_skip_delays(false); ut_assertok(dm_test_destroy(uts)); return 0; }
int dm_init_and_scan(bool pre_reloc_only) { int ret; ret = dm_init(); if (ret) { debug("dm_init() failed: %d\n", ret); return ret; } ret = dm_scan_platdata(pre_reloc_only); if (ret) { debug("dm_scan_platdata() failed: %d\n", ret); return ret; } #ifdef CONFIG_OF_CONTROL ret = dm_scan_fdt(gd->fdt_blob, pre_reloc_only); if (ret) { debug("dm_scan_fdt() failed: %d\n", ret); return ret; } #endif ret = dm_scan_other(pre_reloc_only); if (ret) return ret; return 0; }
int dm_test_main(const char *test_name) { struct dm_test *tests = ll_entry_start(struct dm_test, dm_test); const int n_ents = ll_entry_count(struct dm_test, dm_test); struct dm_test_state *dms = &global_test_state; struct dm_test *test; /* * If we have no device tree, or it only has a root node, then these * tests clearly aren't going to work... */ if (!gd->fdt_blob || fdt_next_node(gd->fdt_blob, 0, NULL) < 0) { puts("Please run with test device tree:\n" " dtc -I dts -O dtb test/dm/test.dts -o test/dm/test.dtb\n" " ./u-boot -d test/dm/test.dtb\n"); ut_assert(gd->fdt_blob); } if (!test_name) printf("Running %d driver model tests\n", n_ents); for (test = tests; test < tests + n_ents; test++) { if (test_name && strcmp(test_name, test->name)) continue; printf("Test: %s\n", test->name); ut_assertok(dm_test_init(dms)); dms->start = mallinfo(); if (test->flags & DM_TESTF_SCAN_PDATA) ut_assertok(dm_scan_platdata(false)); if (test->flags & DM_TESTF_PROBE_TEST) ut_assertok(do_autoprobe(dms)); if (test->flags & DM_TESTF_SCAN_FDT) ut_assertok(dm_scan_fdt(gd->fdt_blob, false)); if (test->func(dms)) break; ut_assertok(dm_test_destroy(dms)); } printf("Failures: %d\n", dms->fail_count); return 0; }
/* Remove and recreate everything, check for memory leaks */ 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"); ut_assertok(dm_scan_platdata()); ut_assertok(dm_scan_fdt(gd->fdt_blob)); /* Scanning the uclass is enough to probe all the devices */ for (id = UCLASS_ROOT; id < UCLASS_COUNT; id++) { for (ret = uclass_first_device(UCLASS_TEST, &dev); dev; ret = uclass_next_device(&dev)) ; 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); } return 0; }
static int dm_test_main(const char *test_name) { struct unit_test *tests = ll_entry_start(struct unit_test, dm_test); const int n_ents = ll_entry_count(struct unit_test, dm_test); struct unit_test_state *uts = &global_dm_test_state; struct unit_test *test; int run_count; uts->priv = &_global_priv_dm_test_state; uts->fail_count = 0; /* * If we have no device tree, or it only has a root node, then these * tests clearly aren't going to work... */ if (!gd->fdt_blob || fdt_next_node(gd->fdt_blob, 0, NULL) < 0) { puts("Please run with test device tree:\n" " ./u-boot -d arch/sandbox/dts/test.dtb\n"); ut_assert(gd->fdt_blob); } if (!test_name) printf("Running %d driver model tests\n", n_ents); run_count = 0; #ifdef CONFIG_OF_LIVE uts->of_root = gd->of_root; #endif for (test = tests; test < tests + n_ents; test++) { const char *name = test->name; int runs; /* All tests have this prefix */ if (!strncmp(name, "dm_test_", 8)) name += 8; if (test_name && strcmp(test_name, name)) continue; /* Run with the live tree if possible */ runs = 0; if (IS_ENABLED(CONFIG_OF_LIVE)) { if (!(test->flags & DM_TESTF_FLAT_TREE)) { ut_assertok(dm_do_test(uts, test, true)); runs++; } } /* * Run with the flat tree if we couldn't run it with live tree, * or it is a core test. */ if (!(test->flags & DM_TESTF_LIVE_TREE) && (!runs || dm_test_run_on_flattree(test))) { ut_assertok(dm_do_test(uts, test, false)); runs++; } run_count += runs; } if (test_name && !run_count) printf("Test '%s' not found\n", test_name); else printf("Failures: %d\n", uts->fail_count); gd->dm_root = NULL; ut_assertok(dm_init(false)); dm_scan_platdata(false); dm_scan_fdt(gd->fdt_blob, false); return uts->fail_count ? CMD_RET_FAILURE : 0; }