2 * Copyright (c) 2013 Google, Inc
4 * SPDX-License-Identifier: GPL-2.0+
13 #include <dm/uclass-internal.h>
16 DECLARE_GLOBAL_DATA_PTR
;
18 struct dm_test_state global_test_state
;
20 /* Get ready for testing */
21 static int dm_test_init(struct dm_test_state
*dms
)
23 memset(dms
, '\0', sizeof(*dms
));
25 memset(dm_testdrv_op_count
, '\0', sizeof(dm_testdrv_op_count
));
27 ut_assertok(dm_init());
28 dms
->root
= dm_root();
33 /* Ensure all the test devices are probed */
34 static int do_autoprobe(struct dm_test_state
*dms
)
39 /* Scanning the uclass is enough to probe all the devices */
40 for (ret
= uclass_first_device(UCLASS_TEST
, &dev
);
42 ret
= uclass_next_device(&dev
))
48 static int dm_test_destroy(struct dm_test_state
*dms
)
52 for (id
= 0; id
< UCLASS_COUNT
; id
++) {
56 * If the uclass doesn't exist we don't want to create it. So
57 * check that here before we call uclass_find_device()/
62 ut_assertok(uclass_destroy(uc
));
68 int dm_test_main(const char *test_name
)
70 struct dm_test
*tests
= ll_entry_start(struct dm_test
, dm_test
);
71 const int n_ents
= ll_entry_count(struct dm_test
, dm_test
);
72 struct dm_test_state
*dms
= &global_test_state
;
76 * If we have no device tree, or it only has a root node, then these
77 * tests clearly aren't going to work...
79 if (!gd
->fdt_blob
|| fdt_next_node(gd
->fdt_blob
, 0, NULL
) < 0) {
80 puts("Please run with test device tree:\n"
81 " dtc -I dts -O dtb test/dm/test.dts -o test/dm/test.dtb\n"
82 " ./u-boot -d test/dm/test.dtb\n");
83 ut_assert(gd
->fdt_blob
);
87 printf("Running %d driver model tests\n", n_ents
);
89 for (test
= tests
; test
< tests
+ n_ents
; test
++) {
90 if (test_name
&& strcmp(test_name
, test
->name
))
92 printf("Test: %s\n", test
->name
);
93 ut_assertok(dm_test_init(dms
));
95 dms
->start
= mallinfo();
96 if (test
->flags
& DM_TESTF_SCAN_PDATA
)
97 ut_assertok(dm_scan_platdata(false));
98 if (test
->flags
& DM_TESTF_PROBE_TEST
)
99 ut_assertok(do_autoprobe(dms
));
100 if (test
->flags
& DM_TESTF_SCAN_FDT
)
101 ut_assertok(dm_scan_fdt(gd
->fdt_blob
, false));
106 ut_assertok(dm_test_destroy(dms
));
109 printf("Failures: %d\n", dms
->fail_count
);