Simon Glass | 5722fb2 | 2021-03-07 17:34:47 -0700 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | /* |
| 3 | * Copyright 2021 Google LLC |
| 4 | * Written by Simon Glass <sjg@chromium.org> |
| 5 | */ |
| 6 | |
| 7 | #include <common.h> |
| 8 | #include <console.h> |
Simon Glass | d18f739 | 2021-03-07 17:34:50 -0700 | [diff] [blame] | 9 | #include <dm.h> |
| 10 | #include <dm/root.h> |
Simon Glass | 2dba476 | 2021-03-07 17:34:58 -0700 | [diff] [blame] | 11 | #include <dm/test.h> |
Simon Glass | 5b7e55b | 2021-03-07 17:34:59 -0700 | [diff] [blame] | 12 | #include <dm/uclass-internal.h> |
Simon Glass | 5722fb2 | 2021-03-07 17:34:47 -0700 | [diff] [blame] | 13 | #include <test/test.h> |
Simon Glass | d18f739 | 2021-03-07 17:34:50 -0700 | [diff] [blame] | 14 | #include <test/ut.h> |
Simon Glass | 5722fb2 | 2021-03-07 17:34:47 -0700 | [diff] [blame] | 15 | |
Simon Glass | 0f8f677 | 2021-03-07 17:34:49 -0700 | [diff] [blame] | 16 | DECLARE_GLOBAL_DATA_PTR; |
| 17 | |
Simon Glass | 4066d8d | 2021-03-07 17:35:04 -0700 | [diff] [blame] | 18 | /* This is valid when a test is running, NULL otherwise */ |
| 19 | static struct unit_test_state *cur_test_state; |
| 20 | |
| 21 | struct unit_test_state *test_get_state(void) |
| 22 | { |
| 23 | return cur_test_state; |
| 24 | } |
| 25 | |
| 26 | void test_set_state(struct unit_test_state *uts) |
| 27 | { |
| 28 | cur_test_state = uts; |
| 29 | } |
| 30 | |
Simon Glass | 2dba476 | 2021-03-07 17:34:58 -0700 | [diff] [blame] | 31 | /** |
| 32 | * dm_test_pre_run() - Get ready to run a driver model test |
| 33 | * |
| 34 | * This clears out the driver model data structures. For sandbox it resets the |
| 35 | * state structure |
| 36 | * |
| 37 | * @uts: Test state |
| 38 | */ |
| 39 | static int dm_test_pre_run(struct unit_test_state *uts) |
| 40 | { |
| 41 | bool of_live = uts->of_live; |
| 42 | |
| 43 | uts->root = NULL; |
| 44 | uts->testdev = NULL; |
| 45 | uts->force_fail_alloc = false; |
| 46 | uts->skip_post_probe = false; |
| 47 | gd->dm_root = NULL; |
Simon Glass | 45b807d | 2021-03-25 10:44:33 +1300 | [diff] [blame] | 48 | if (IS_ENABLED(CONFIG_UT_DM) && !CONFIG_IS_ENABLED(OF_PLATDATA)) |
Simon Glass | 2dba476 | 2021-03-07 17:34:58 -0700 | [diff] [blame] | 49 | memset(dm_testdrv_op_count, '\0', sizeof(dm_testdrv_op_count)); |
Simon Glass | 45b807d | 2021-03-25 10:44:33 +1300 | [diff] [blame] | 50 | arch_reset_for_test(); |
Simon Glass | 2dba476 | 2021-03-07 17:34:58 -0700 | [diff] [blame] | 51 | |
| 52 | /* Determine whether to make the live tree available */ |
| 53 | gd_set_of_root(of_live ? uts->of_root : NULL); |
| 54 | ut_assertok(dm_init(of_live)); |
| 55 | uts->root = dm_root(); |
| 56 | |
| 57 | return 0; |
| 58 | } |
| 59 | |
Simon Glass | 5b7e55b | 2021-03-07 17:34:59 -0700 | [diff] [blame] | 60 | static int dm_test_post_run(struct unit_test_state *uts) |
| 61 | { |
| 62 | int id; |
| 63 | |
Simon Glass | 96113c1 | 2021-03-15 17:25:21 +1300 | [diff] [blame] | 64 | /* |
| 65 | * With of-platdata-inst the uclasses are created at build time. If we |
| 66 | * destroy them we cannot get them back since uclass_add() is not |
| 67 | * supported. So skip this. |
| 68 | */ |
| 69 | if (!CONFIG_IS_ENABLED(OF_PLATDATA_INST)) { |
| 70 | for (id = 0; id < UCLASS_COUNT; id++) { |
| 71 | struct uclass *uc; |
Simon Glass | 5b7e55b | 2021-03-07 17:34:59 -0700 | [diff] [blame] | 72 | |
Simon Glass | 96113c1 | 2021-03-15 17:25:21 +1300 | [diff] [blame] | 73 | /* |
| 74 | * If the uclass doesn't exist we don't want to create |
| 75 | * it. So check that here before we call |
| 76 | * uclass_find_device(). |
| 77 | */ |
| 78 | uc = uclass_find(id); |
| 79 | if (!uc) |
| 80 | continue; |
| 81 | ut_assertok(uclass_destroy(uc)); |
| 82 | } |
Simon Glass | 5b7e55b | 2021-03-07 17:34:59 -0700 | [diff] [blame] | 83 | } |
| 84 | |
| 85 | return 0; |
| 86 | } |
| 87 | |
Simon Glass | 242357c | 2021-03-07 17:34:51 -0700 | [diff] [blame] | 88 | /* Ensure all the test devices are probed */ |
| 89 | static int do_autoprobe(struct unit_test_state *uts) |
| 90 | { |
| 91 | struct udevice *dev; |
| 92 | int ret; |
| 93 | |
| 94 | /* Scanning the uclass is enough to probe all the devices */ |
| 95 | for (ret = uclass_first_device(UCLASS_TEST, &dev); |
| 96 | dev; |
| 97 | ret = uclass_next_device(&dev)) |
| 98 | ; |
| 99 | |
| 100 | return ret; |
| 101 | } |
| 102 | |
Simon Glass | 0d32ec2 | 2021-03-07 17:35:03 -0700 | [diff] [blame] | 103 | /* |
| 104 | * ut_test_run_on_flattree() - Check if we should run a test with flat DT |
| 105 | * |
| 106 | * This skips long/slow tests where there is not much value in running a flat |
| 107 | * DT test in addition to a live DT test. |
| 108 | * |
| 109 | * @return true to run the given test on the flat device tree |
| 110 | */ |
| 111 | static bool ut_test_run_on_flattree(struct unit_test *test) |
| 112 | { |
| 113 | const char *fname = strrchr(test->file, '/') + 1; |
| 114 | |
| 115 | if (!(test->flags & UT_TESTF_DM)) |
| 116 | return false; |
| 117 | |
| 118 | return !strstr(fname, "video") || strstr(test->name, "video_base"); |
| 119 | } |
| 120 | |
Simon Glass | 436687e | 2021-03-07 17:35:01 -0700 | [diff] [blame] | 121 | /** |
Simon Glass | bb2b173 | 2021-03-07 17:35:05 -0700 | [diff] [blame] | 122 | * test_matches() - Check if a test should be run |
| 123 | * |
| 124 | * This checks if the a test should be run. In the normal case of running all |
| 125 | * tests, @select_name is NULL. |
| 126 | * |
| 127 | * @prefix: String prefix for the tests. Any tests that have this prefix will be |
| 128 | * printed without the prefix, so that it is easier to see the unique part |
Simon Glass | 1ef74ab | 2021-03-07 17:35:12 -0700 | [diff] [blame] | 129 | * of the test name. If NULL, any suite name (xxx_test) is considered to be |
| 130 | * a prefix. |
Simon Glass | bb2b173 | 2021-03-07 17:35:05 -0700 | [diff] [blame] | 131 | * @test_name: Name of current test |
| 132 | * @select_name: Name of test to run (or NULL for all) |
| 133 | * @return true to run this test, false to skip it |
| 134 | */ |
| 135 | static bool test_matches(const char *prefix, const char *test_name, |
| 136 | const char *select_name) |
| 137 | { |
| 138 | if (!select_name) |
| 139 | return true; |
| 140 | |
| 141 | if (!strcmp(test_name, select_name)) |
| 142 | return true; |
| 143 | |
Simon Glass | 1ef74ab | 2021-03-07 17:35:12 -0700 | [diff] [blame] | 144 | if (!prefix) { |
| 145 | const char *p = strstr(test_name, "_test_"); |
| 146 | |
| 147 | /* convert xxx_test_yyy to yyy, i.e. remove the suite name */ |
| 148 | if (p) |
| 149 | test_name = p + 6; |
| 150 | } else { |
| 151 | /* All tests have this prefix */ |
| 152 | if (!strncmp(test_name, prefix, strlen(prefix))) |
| 153 | test_name += strlen(prefix); |
| 154 | } |
Simon Glass | bb2b173 | 2021-03-07 17:35:05 -0700 | [diff] [blame] | 155 | |
| 156 | if (!strcmp(test_name, select_name)) |
| 157 | return true; |
| 158 | |
| 159 | return false; |
| 160 | } |
| 161 | |
Simon Glass | 53d1b19 | 2021-03-07 17:35:08 -0700 | [diff] [blame] | 162 | /** |
Simon Glass | 1899e13 | 2021-03-07 17:35:07 -0700 | [diff] [blame] | 163 | * ut_list_has_dm_tests() - Check if a list of tests has driver model ones |
| 164 | * |
| 165 | * @tests: List of tests to run |
| 166 | * @count: Number of tests to ru |
| 167 | * @return true if any of the tests have the UT_TESTF_DM flag |
| 168 | */ |
| 169 | static bool ut_list_has_dm_tests(struct unit_test *tests, int count) |
| 170 | { |
| 171 | struct unit_test *test; |
| 172 | |
| 173 | for (test = tests; test < tests + count; test++) { |
| 174 | if (test->flags & UT_TESTF_DM) |
| 175 | return true; |
| 176 | } |
| 177 | |
| 178 | return false; |
| 179 | } |
| 180 | |
Simon Glass | bb2b173 | 2021-03-07 17:35:05 -0700 | [diff] [blame] | 181 | /** |
Simon Glass | 53d1b19 | 2021-03-07 17:35:08 -0700 | [diff] [blame] | 182 | * dm_test_restore() Put things back to normal so sandbox works as expected |
| 183 | * |
| 184 | * @of_root: Value to set for of_root |
| 185 | * @return 0 if OK, -ve on error |
| 186 | */ |
| 187 | static int dm_test_restore(struct device_node *of_root) |
| 188 | { |
| 189 | int ret; |
| 190 | |
| 191 | gd_set_of_root(of_root); |
| 192 | gd->dm_root = NULL; |
| 193 | ret = dm_init(CONFIG_IS_ENABLED(OF_LIVE)); |
| 194 | if (ret) |
| 195 | return ret; |
| 196 | dm_scan_plat(false); |
| 197 | if (!CONFIG_IS_ENABLED(OF_PLATDATA)) |
| 198 | dm_scan_fdt(false); |
| 199 | |
| 200 | return 0; |
| 201 | } |
| 202 | |
| 203 | /** |
Simon Glass | 436687e | 2021-03-07 17:35:01 -0700 | [diff] [blame] | 204 | * test_pre_run() - Handle any preparation needed to run a test |
| 205 | * |
| 206 | * @uts: Test state |
| 207 | * @test: Test to prepare for |
| 208 | * @return 0 if OK, -EAGAIN to skip this test since some required feature is not |
| 209 | * available, other -ve on error (meaning that testing cannot likely |
| 210 | * continue) |
| 211 | */ |
| 212 | static int test_pre_run(struct unit_test_state *uts, struct unit_test *test) |
Simon Glass | d93dc7d | 2021-03-07 17:34:48 -0700 | [diff] [blame] | 213 | { |
Simon Glass | b2890a1 | 2021-03-07 17:34:56 -0700 | [diff] [blame] | 214 | if (test->flags & UT_TESTF_DM) |
Simon Glass | 2dba476 | 2021-03-07 17:34:58 -0700 | [diff] [blame] | 215 | ut_assertok(dm_test_pre_run(uts)); |
Simon Glass | b2890a1 | 2021-03-07 17:34:56 -0700 | [diff] [blame] | 216 | |
Simon Glass | 59cad96 | 2021-03-07 17:34:55 -0700 | [diff] [blame] | 217 | ut_set_skip_delays(uts, false); |
| 218 | |
Simon Glass | 86a5bd0 | 2021-03-07 17:34:53 -0700 | [diff] [blame] | 219 | uts->start = mallinfo(); |
Simon Glass | d93dc7d | 2021-03-07 17:34:48 -0700 | [diff] [blame] | 220 | |
Simon Glass | 177e0fd | 2021-03-07 17:34:52 -0700 | [diff] [blame] | 221 | if (test->flags & UT_TESTF_SCAN_PDATA) |
| 222 | ut_assertok(dm_scan_plat(false)); |
| 223 | |
Simon Glass | 242357c | 2021-03-07 17:34:51 -0700 | [diff] [blame] | 224 | if (test->flags & UT_TESTF_PROBE_TEST) |
| 225 | ut_assertok(do_autoprobe(uts)); |
| 226 | |
Simon Glass | d18f739 | 2021-03-07 17:34:50 -0700 | [diff] [blame] | 227 | if (!CONFIG_IS_ENABLED(OF_PLATDATA) && |
| 228 | (test->flags & UT_TESTF_SCAN_FDT)) |
| 229 | ut_assertok(dm_extended_scan(false)); |
| 230 | |
Simon Glass | d93dc7d | 2021-03-07 17:34:48 -0700 | [diff] [blame] | 231 | if (test->flags & UT_TESTF_CONSOLE_REC) { |
| 232 | int ret = console_record_reset_enable(); |
| 233 | |
| 234 | if (ret) { |
| 235 | printf("Skipping: Console recording disabled\n"); |
| 236 | return -EAGAIN; |
| 237 | } |
| 238 | } |
Simon Glass | 2b566b9 | 2021-03-07 17:34:54 -0700 | [diff] [blame] | 239 | ut_silence_console(uts); |
Simon Glass | d93dc7d | 2021-03-07 17:34:48 -0700 | [diff] [blame] | 240 | |
| 241 | return 0; |
| 242 | } |
| 243 | |
Simon Glass | 436687e | 2021-03-07 17:35:01 -0700 | [diff] [blame] | 244 | /** |
| 245 | * test_post_run() - Handle cleaning up after a test |
| 246 | * |
| 247 | * @uts: Test state |
| 248 | * @test: Test to clean up after |
| 249 | * @return 0 if OK, -ve on error (meaning that testing cannot likely continue) |
| 250 | */ |
| 251 | static int test_post_run(struct unit_test_state *uts, struct unit_test *test) |
Simon Glass | d93dc7d | 2021-03-07 17:34:48 -0700 | [diff] [blame] | 252 | { |
Simon Glass | 2b566b9 | 2021-03-07 17:34:54 -0700 | [diff] [blame] | 253 | ut_unsilence_console(uts); |
Simon Glass | 5b7e55b | 2021-03-07 17:34:59 -0700 | [diff] [blame] | 254 | if (test->flags & UT_TESTF_DM) |
| 255 | ut_assertok(dm_test_post_run(uts)); |
Simon Glass | 0f8f677 | 2021-03-07 17:34:49 -0700 | [diff] [blame] | 256 | |
Simon Glass | d93dc7d | 2021-03-07 17:34:48 -0700 | [diff] [blame] | 257 | return 0; |
| 258 | } |
| 259 | |
Simon Glass | 0d32ec2 | 2021-03-07 17:35:03 -0700 | [diff] [blame] | 260 | /** |
| 261 | * ut_run_test() - Run a single test |
| 262 | * |
| 263 | * This runs the test, handling any preparation and clean-up needed. It prints |
| 264 | * the name of each test before running it. |
| 265 | * |
| 266 | * @uts: Test state to update. The caller should ensure that this is zeroed for |
| 267 | * the first call to this function. On exit, @uts->fail_count is |
| 268 | * incremented by the number of failures (0, one hopes) |
| 269 | * @test_name: Test to run |
| 270 | * @name: Name of test, possibly skipping a prefix that should not be displayed |
| 271 | * @return 0 if all tests passed, -EAGAIN if the test should be skipped, -1 if |
| 272 | * any failed |
| 273 | */ |
| 274 | static int ut_run_test(struct unit_test_state *uts, struct unit_test *test, |
| 275 | const char *test_name) |
Simon Glass | 5517edb | 2021-03-07 17:35:00 -0700 | [diff] [blame] | 276 | { |
Simon Glass | 436687e | 2021-03-07 17:35:01 -0700 | [diff] [blame] | 277 | const char *fname = strrchr(test->file, '/') + 1; |
| 278 | const char *note = ""; |
Simon Glass | 5517edb | 2021-03-07 17:35:00 -0700 | [diff] [blame] | 279 | int ret; |
| 280 | |
Simon Glass | 436687e | 2021-03-07 17:35:01 -0700 | [diff] [blame] | 281 | if ((test->flags & UT_TESTF_DM) && !uts->of_live) |
| 282 | note = " (flat tree)"; |
| 283 | printf("Test: %s: %s%s\n", test_name, fname, note); |
Simon Glass | 5517edb | 2021-03-07 17:35:00 -0700 | [diff] [blame] | 284 | |
Simon Glass | 4066d8d | 2021-03-07 17:35:04 -0700 | [diff] [blame] | 285 | /* Allow access to test state from drivers */ |
| 286 | test_set_state(uts); |
| 287 | |
Simon Glass | 5517edb | 2021-03-07 17:35:00 -0700 | [diff] [blame] | 288 | ret = test_pre_run(uts, test); |
| 289 | if (ret == -EAGAIN) |
| 290 | return -EAGAIN; |
| 291 | if (ret) |
| 292 | return ret; |
| 293 | |
| 294 | test->func(uts); |
| 295 | |
| 296 | ret = test_post_run(uts, test); |
| 297 | if (ret) |
| 298 | return ret; |
| 299 | |
Simon Glass | 4066d8d | 2021-03-07 17:35:04 -0700 | [diff] [blame] | 300 | test_set_state( NULL); |
| 301 | |
Simon Glass | 5517edb | 2021-03-07 17:35:00 -0700 | [diff] [blame] | 302 | return 0; |
| 303 | } |
| 304 | |
Simon Glass | bb2b173 | 2021-03-07 17:35:05 -0700 | [diff] [blame] | 305 | /** |
| 306 | * ut_run_test_live_flat() - Run a test with both live and flat tree |
| 307 | * |
| 308 | * This calls ut_run_test() with livetree enabled, which is the standard setup |
| 309 | * for runnig tests. Then, for driver model test, it calls it again with |
| 310 | * livetree disabled. This allows checking of flattree being used when OF_LIVE |
| 311 | * is enabled, as is the case in U-Boot proper before relocation, as well as in |
| 312 | * SPL. |
| 313 | * |
| 314 | * @uts: Test state to update. The caller should ensure that this is zeroed for |
| 315 | * the first call to this function. On exit, @uts->fail_count is |
| 316 | * incremented by the number of failures (0, one hopes) |
| 317 | * @test: Test to run |
| 318 | * @name: Name of test, possibly skipping a prefix that should not be displayed |
| 319 | * @return 0 if all tests passed, -EAGAIN if the test should be skipped, -1 if |
| 320 | * any failed |
| 321 | */ |
| 322 | static int ut_run_test_live_flat(struct unit_test_state *uts, |
| 323 | struct unit_test *test, const char *name) |
Simon Glass | 0d32ec2 | 2021-03-07 17:35:03 -0700 | [diff] [blame] | 324 | { |
| 325 | int runs; |
| 326 | |
| 327 | /* Run with the live tree if possible */ |
| 328 | runs = 0; |
| 329 | if (CONFIG_IS_ENABLED(OF_LIVE)) { |
| 330 | if (!(test->flags & UT_TESTF_FLAT_TREE)) { |
| 331 | uts->of_live = true; |
| 332 | ut_assertok(ut_run_test(uts, test, test->name)); |
| 333 | runs++; |
| 334 | } |
| 335 | } |
| 336 | |
| 337 | /* |
| 338 | * Run with the flat tree if we couldn't run it with live tree, |
| 339 | * or it is a core test. |
| 340 | */ |
| 341 | if (!(test->flags & UT_TESTF_LIVE_TREE) && |
| 342 | (!runs || ut_test_run_on_flattree(test))) { |
| 343 | uts->of_live = false; |
| 344 | ut_assertok(ut_run_test(uts, test, test->name)); |
| 345 | runs++; |
| 346 | } |
| 347 | |
| 348 | return 0; |
| 349 | } |
| 350 | |
Simon Glass | bb2b173 | 2021-03-07 17:35:05 -0700 | [diff] [blame] | 351 | /** |
| 352 | * ut_run_tests() - Run a set of tests |
| 353 | * |
| 354 | * This runs the tests, handling any preparation and clean-up needed. It prints |
| 355 | * the name of each test before running it. |
| 356 | * |
| 357 | * @uts: Test state to update. The caller should ensure that this is zeroed for |
| 358 | * the first call to this function. On exit, @uts->fail_count is |
| 359 | * incremented by the number of failures (0, one hopes) |
| 360 | * @prefix: String prefix for the tests. Any tests that have this prefix will be |
| 361 | * printed without the prefix, so that it is easier to see the unique part |
| 362 | * of the test name. If NULL, no prefix processing is done |
| 363 | * @tests: List of tests to run |
| 364 | * @count: Number of tests to run |
| 365 | * @select_name: Name of a single test to run (from the list provided). If NULL |
| 366 | * then all tests are run |
| 367 | * @return 0 if all tests passed, -ENOENT if test @select_name was not found, |
| 368 | * -EBADF if any failed |
| 369 | */ |
| 370 | static int ut_run_tests(struct unit_test_state *uts, const char *prefix, |
| 371 | struct unit_test *tests, int count, |
| 372 | const char *select_name) |
Simon Glass | 5722fb2 | 2021-03-07 17:34:47 -0700 | [diff] [blame] | 373 | { |
| 374 | struct unit_test *test; |
Simon Glass | 5722fb2 | 2021-03-07 17:34:47 -0700 | [diff] [blame] | 375 | int found = 0; |
| 376 | |
| 377 | for (test = tests; test < tests + count; test++) { |
| 378 | const char *test_name = test->name; |
Simon Glass | d93dc7d | 2021-03-07 17:34:48 -0700 | [diff] [blame] | 379 | int ret; |
Simon Glass | 5722fb2 | 2021-03-07 17:34:47 -0700 | [diff] [blame] | 380 | |
Simon Glass | bb2b173 | 2021-03-07 17:35:05 -0700 | [diff] [blame] | 381 | if (!test_matches(prefix, test_name, select_name)) |
Simon Glass | 5722fb2 | 2021-03-07 17:34:47 -0700 | [diff] [blame] | 382 | continue; |
Simon Glass | bb2b173 | 2021-03-07 17:35:05 -0700 | [diff] [blame] | 383 | ret = ut_run_test_live_flat(uts, test, select_name); |
Simon Glass | 5722fb2 | 2021-03-07 17:34:47 -0700 | [diff] [blame] | 384 | found++; |
Simon Glass | d93dc7d | 2021-03-07 17:34:48 -0700 | [diff] [blame] | 385 | if (ret == -EAGAIN) |
| 386 | continue; |
| 387 | if (ret) |
| 388 | return ret; |
Simon Glass | 5722fb2 | 2021-03-07 17:34:47 -0700 | [diff] [blame] | 389 | } |
| 390 | if (select_name && !found) |
| 391 | return -ENOENT; |
| 392 | |
| 393 | return uts->fail_count ? -EBADF : 0; |
| 394 | } |
| 395 | |
| 396 | int ut_run_list(const char *category, const char *prefix, |
| 397 | struct unit_test *tests, int count, const char *select_name) |
| 398 | { |
| 399 | struct unit_test_state uts = { .fail_count = 0 }; |
Simon Glass | 53d1b19 | 2021-03-07 17:35:08 -0700 | [diff] [blame] | 400 | bool has_dm_tests = false; |
Simon Glass | 5722fb2 | 2021-03-07 17:34:47 -0700 | [diff] [blame] | 401 | int ret; |
| 402 | |
Simon Glass | 1899e13 | 2021-03-07 17:35:07 -0700 | [diff] [blame] | 403 | if (!CONFIG_IS_ENABLED(OF_PLATDATA) && |
| 404 | ut_list_has_dm_tests(tests, count)) { |
Simon Glass | 53d1b19 | 2021-03-07 17:35:08 -0700 | [diff] [blame] | 405 | has_dm_tests = true; |
Simon Glass | 1899e13 | 2021-03-07 17:35:07 -0700 | [diff] [blame] | 406 | /* |
| 407 | * If we have no device tree, or it only has a root node, then |
| 408 | * these * tests clearly aren't going to work... |
| 409 | */ |
| 410 | if (!gd->fdt_blob || fdt_next_node(gd->fdt_blob, 0, NULL) < 0) { |
| 411 | puts("Please run with test device tree:\n" |
| 412 | " ./u-boot -d arch/sandbox/dts/test.dtb\n"); |
| 413 | return CMD_RET_FAILURE; |
| 414 | } |
| 415 | } |
| 416 | |
Simon Glass | 5722fb2 | 2021-03-07 17:34:47 -0700 | [diff] [blame] | 417 | if (!select_name) |
| 418 | printf("Running %d %s tests\n", count, category); |
| 419 | |
Simon Glass | bb2b173 | 2021-03-07 17:35:05 -0700 | [diff] [blame] | 420 | uts.of_root = gd_of_root(); |
Simon Glass | 5722fb2 | 2021-03-07 17:34:47 -0700 | [diff] [blame] | 421 | ret = ut_run_tests(&uts, prefix, tests, count, select_name); |
| 422 | |
| 423 | if (ret == -ENOENT) |
| 424 | printf("Test '%s' not found\n", select_name); |
| 425 | else |
| 426 | printf("Failures: %d\n", uts.fail_count); |
| 427 | |
Simon Glass | 53d1b19 | 2021-03-07 17:35:08 -0700 | [diff] [blame] | 428 | /* Best efforts only...ignore errors */ |
| 429 | if (has_dm_tests) |
| 430 | dm_test_restore(uts.of_root); |
| 431 | |
Simon Glass | 5722fb2 | 2021-03-07 17:34:47 -0700 | [diff] [blame] | 432 | return ret; |
| 433 | } |