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 unit_test_state global_dm_test_state
;
19 static struct dm_test_state _global_priv_dm_test_state
;
21 /* Get ready for testing */
22 static int dm_test_init(struct unit_test_state
*uts
)
24 struct dm_test_state
*dms
= uts
->priv
;
26 memset(uts
, '\0', sizeof(*uts
));
28 memset(dms
, '\0', sizeof(*dms
));
30 memset(dm_testdrv_op_count
, '\0', sizeof(dm_testdrv_op_count
));
32 ut_assertok(dm_init());
33 dms
->root
= dm_root();
38 /* Ensure all the test devices are probed */
39 static int do_autoprobe(struct unit_test_state
*uts
)
44 /* Scanning the uclass is enough to probe all the devices */
45 for (ret
= uclass_first_device(UCLASS_TEST
, &dev
);
47 ret
= uclass_next_device(&dev
))
53 static int dm_test_destroy(struct unit_test_state
*uts
)
57 for (id
= 0; id
< UCLASS_COUNT
; id
++) {
61 * If the uclass doesn't exist we don't want to create it. So
62 * check that here before we call uclass_find_device()/
67 ut_assertok(uclass_destroy(uc
));
73 int dm_test_main(const char *test_name
)
75 struct unit_test
*tests
= ll_entry_start(struct unit_test
, dm_test
);
76 const int n_ents
= ll_entry_count(struct unit_test
, dm_test
);
77 struct unit_test_state
*uts
= &global_dm_test_state
;
78 uts
->priv
= &_global_priv_dm_test_state
;
79 struct unit_test
*test
;
82 * If we have no device tree, or it only has a root node, then these
83 * tests clearly aren't going to work...
85 if (!gd
->fdt_blob
|| fdt_next_node(gd
->fdt_blob
, 0, NULL
) < 0) {
86 puts("Please run with test device tree:\n"
87 " ./u-boot -d arch/sandbox/dts/test.dtb\n");
88 ut_assert(gd
->fdt_blob
);
92 printf("Running %d driver model tests\n", n_ents
);
94 for (test
= tests
; test
< tests
+ n_ents
; test
++) {
95 if (test_name
&& strcmp(test_name
, test
->name
))
97 printf("Test: %s\n", test
->name
);
98 ut_assertok(dm_test_init(uts
));
100 uts
->start
= mallinfo();
101 if (test
->flags
& DM_TESTF_SCAN_PDATA
)
102 ut_assertok(dm_scan_platdata(false));
103 if (test
->flags
& DM_TESTF_PROBE_TEST
)
104 ut_assertok(do_autoprobe(uts
));
105 if (test
->flags
& DM_TESTF_SCAN_FDT
)
106 ut_assertok(dm_scan_fdt(gd
->fdt_blob
, false));
111 ut_assertok(dm_test_destroy(uts
));
114 printf("Failures: %d\n", uts
->fail_count
);