2 * Copyright (c) 2013 Google, Inc
4 * SPDX-License-Identifier: GPL-2.0+
12 #include <dm/uclass-internal.h>
15 DECLARE_GLOBAL_DATA_PTR;
17 struct dm_test_state global_test_state;
19 /* Get ready for testing */
20 static int dm_test_init(struct dm_test_state *dms)
22 memset(dms, '\0', sizeof(*dms));
24 memset(dm_testdrv_op_count, '\0', sizeof(dm_testdrv_op_count));
26 ut_assertok(dm_init());
27 dms->root = dm_root();
32 /* Ensure all the test devices are probed */
33 static int do_autoprobe(struct dm_test_state *dms)
38 /* Scanning the uclass is enough to probe all the devices */
39 for (ret = uclass_first_device(UCLASS_TEST, &dev);
41 ret = uclass_next_device(&dev))
47 static int dm_test_destroy(struct dm_test_state *dms)
51 for (id = 0; id < UCLASS_COUNT; id++) {
55 * If the uclass doesn't exist we don't want to create it. So
56 * check that here before we call uclass_find_device()/
61 ut_assertok(uclass_destroy(uc));
67 int dm_test_main(void)
69 struct dm_test *tests = ll_entry_start(struct dm_test, dm_test);
70 const int n_ents = ll_entry_count(struct dm_test, dm_test);
71 struct dm_test_state *dms = &global_test_state;
75 * If we have no device tree, or it only has a root node, then these
76 * tests clearly aren't going to work...
78 if (!gd->fdt_blob || fdt_next_node(gd->fdt_blob, 0, NULL) < 0) {
79 puts("Please run with test device tree:\n"
80 " dtc -I dts -O dtb test/dm/test.dts -o test/dm/test.dtb\n"
81 " ./u-boot -d test/dm/test.dtb\n");
82 ut_assert(gd->fdt_blob);
85 printf("Running %d driver model tests\n", n_ents);
87 for (test = tests; test < tests + n_ents; test++) {
88 printf("Test: %s\n", test->name);
89 ut_assertok(dm_test_init(dms));
91 if (test->flags & DM_TESTF_SCAN_PDATA)
92 ut_assertok(dm_scan_platdata(false));
93 if (test->flags & DM_TESTF_PROBE_TEST)
94 ut_assertok(do_autoprobe(dms));
95 if (test->flags & DM_TESTF_SCAN_FDT)
96 ut_assertok(dm_scan_fdt(gd->fdt_blob, false));
101 ut_assertok(dm_test_destroy(dms));
104 printf("Failures: %d\n", dms->fail_count);