blob: 082821ef3e032ea083f5f3d26a52905a2ff4d8c6 [file] [log] [blame]
Simon Glass5722fb22021-03-07 17:34:47 -07001// 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>
Stefan Roese5be8f372022-09-02 13:57:54 +02009#include <cyclic.h>
Simon Glassd18f7392021-03-07 17:34:50 -070010#include <dm.h>
Simon Glassa128b1b2022-03-04 08:43:01 -070011#include <event.h>
Simon Glass3ba76752022-09-06 20:27:05 -060012#include <os.h>
Simon Glassd18f7392021-03-07 17:34:50 -070013#include <dm/root.h>
Simon Glass2dba4762021-03-07 17:34:58 -070014#include <dm/test.h>
Simon Glass5b7e55b2021-03-07 17:34:59 -070015#include <dm/uclass-internal.h>
Simon Glass5722fb22021-03-07 17:34:47 -070016#include <test/test.h>
Simon Glassd18f7392021-03-07 17:34:50 -070017#include <test/ut.h>
Simon Glass3ba76752022-09-06 20:27:05 -060018#include <u-boot/crc.h>
Simon Glass5722fb22021-03-07 17:34:47 -070019
Simon Glass0f8f6772021-03-07 17:34:49 -070020DECLARE_GLOBAL_DATA_PTR;
21
Simon Glass3ba76752022-09-06 20:27:05 -060022/**
23 * enum fdtchk_t - what to do with the device tree (gd->fdt_blob)
24 *
25 * This affects what happens with the device tree before and after a test
26 *
27 * @FDTCHK_NONE: Do nothing
28 * @FDTCHK_CHECKSUM: Take a checksum of the FDT before the test runs and
29 * compare it afterwards to detect any changes
30 * @FDTCHK_COPY: Make a copy of the FDT and restore it afterwards
31 */
32enum fdtchk_t {
33 FDTCHK_NONE,
34 FDTCHK_CHECKSUM,
35 FDTCHK_COPY,
36};
37
38/**
39 * fdt_action() - get the required action for the FDT
40 *
41 * @return the action that should be taken for this build
42 */
43static enum fdtchk_t fdt_action(void)
44{
45 /* Do a copy for sandbox (but only the U-Boot build, not SPL) */
46 if (CONFIG_IS_ENABLED(SANDBOX))
47 return FDTCHK_COPY;
48
49 /* For sandbox SPL builds, do nothing */
50 if (IS_ENABLED(CONFIG_SANDBOX))
51 return FDTCHK_NONE;
52
53 /* For all other boards, do a checksum */
54 return FDTCHK_CHECKSUM;
55}
56
Simon Glass4066d8d2021-03-07 17:35:04 -070057/* This is valid when a test is running, NULL otherwise */
58static struct unit_test_state *cur_test_state;
59
60struct unit_test_state *test_get_state(void)
61{
62 return cur_test_state;
63}
64
65void test_set_state(struct unit_test_state *uts)
66{
67 cur_test_state = uts;
68}
69
Simon Glass2dba4762021-03-07 17:34:58 -070070/**
71 * dm_test_pre_run() - Get ready to run a driver model test
72 *
73 * This clears out the driver model data structures. For sandbox it resets the
74 * state structure
75 *
76 * @uts: Test state
77 */
78static int dm_test_pre_run(struct unit_test_state *uts)
79{
80 bool of_live = uts->of_live;
81
82 uts->root = NULL;
83 uts->testdev = NULL;
84 uts->force_fail_alloc = false;
85 uts->skip_post_probe = false;
Simon Glass3ba76752022-09-06 20:27:05 -060086 if (fdt_action() == FDTCHK_CHECKSUM)
87 uts->fdt_chksum = crc8(0, gd->fdt_blob,
88 fdt_totalsize(gd->fdt_blob));
Simon Glass2dba4762021-03-07 17:34:58 -070089 gd->dm_root = NULL;
Simon Glass1a3e39b2022-09-06 20:27:00 -060090 malloc_disable_testing();
Simon Glassf7005042021-07-05 16:32:43 -060091 if (CONFIG_IS_ENABLED(UT_DM) && !CONFIG_IS_ENABLED(OF_PLATDATA))
Simon Glass2dba4762021-03-07 17:34:58 -070092 memset(dm_testdrv_op_count, '\0', sizeof(dm_testdrv_op_count));
Simon Glass45b807d2021-03-25 10:44:33 +130093 arch_reset_for_test();
Simon Glass2dba4762021-03-07 17:34:58 -070094
95 /* Determine whether to make the live tree available */
96 gd_set_of_root(of_live ? uts->of_root : NULL);
97 ut_assertok(dm_init(of_live));
98 uts->root = dm_root();
99
100 return 0;
101}
102
Simon Glass5b7e55b2021-03-07 17:34:59 -0700103static int dm_test_post_run(struct unit_test_state *uts)
104{
105 int id;
106
Simon Glass3ba76752022-09-06 20:27:05 -0600107 if (gd->fdt_blob) {
108 switch (fdt_action()) {
109 case FDTCHK_COPY:
110 memcpy((void *)gd->fdt_blob, uts->fdt_copy, uts->fdt_size);
111 break;
112 case FDTCHK_CHECKSUM: {
113 uint chksum;
114
115 chksum = crc8(0, gd->fdt_blob, fdt_totalsize(gd->fdt_blob));
116
117 if (chksum != uts->fdt_chksum)
118 printf("Device tree changed: cannot run live tree tests\n");
119 break;
120 }
121 case FDTCHK_NONE:
122 break;
123 }
124 }
125
Simon Glass96113c12021-03-15 17:25:21 +1300126 /*
127 * With of-platdata-inst the uclasses are created at build time. If we
128 * destroy them we cannot get them back since uclass_add() is not
129 * supported. So skip this.
130 */
131 if (!CONFIG_IS_ENABLED(OF_PLATDATA_INST)) {
132 for (id = 0; id < UCLASS_COUNT; id++) {
133 struct uclass *uc;
Simon Glass5b7e55b2021-03-07 17:34:59 -0700134
Simon Glass96113c12021-03-15 17:25:21 +1300135 /*
136 * If the uclass doesn't exist we don't want to create
137 * it. So check that here before we call
138 * uclass_find_device().
139 */
140 uc = uclass_find(id);
141 if (!uc)
142 continue;
143 ut_assertok(uclass_destroy(uc));
144 }
Simon Glass5b7e55b2021-03-07 17:34:59 -0700145 }
146
147 return 0;
148}
149
Simon Glass242357c2021-03-07 17:34:51 -0700150/* Ensure all the test devices are probed */
151static int do_autoprobe(struct unit_test_state *uts)
152{
153 struct udevice *dev;
154 int ret;
155
156 /* Scanning the uclass is enough to probe all the devices */
157 for (ret = uclass_first_device(UCLASS_TEST, &dev);
158 dev;
159 ret = uclass_next_device(&dev))
160 ;
161
162 return ret;
163}
164
Simon Glass0d32ec22021-03-07 17:35:03 -0700165/*
166 * ut_test_run_on_flattree() - Check if we should run a test with flat DT
167 *
168 * This skips long/slow tests where there is not much value in running a flat
169 * DT test in addition to a live DT test.
170 *
Heinrich Schuchardt47b4c022022-01-19 18:05:50 +0100171 * Return: true to run the given test on the flat device tree
Simon Glass0d32ec22021-03-07 17:35:03 -0700172 */
173static bool ut_test_run_on_flattree(struct unit_test *test)
174{
175 const char *fname = strrchr(test->file, '/') + 1;
176
177 if (!(test->flags & UT_TESTF_DM))
178 return false;
179
180 return !strstr(fname, "video") || strstr(test->name, "video_base");
181}
182
Simon Glass436687e2021-03-07 17:35:01 -0700183/**
Simon Glassbb2b1732021-03-07 17:35:05 -0700184 * test_matches() - Check if a test should be run
185 *
186 * This checks if the a test should be run. In the normal case of running all
187 * tests, @select_name is NULL.
188 *
189 * @prefix: String prefix for the tests. Any tests that have this prefix will be
190 * printed without the prefix, so that it is easier to see the unique part
Simon Glass1ef74ab2021-03-07 17:35:12 -0700191 * of the test name. If NULL, any suite name (xxx_test) is considered to be
192 * a prefix.
Simon Glassbb2b1732021-03-07 17:35:05 -0700193 * @test_name: Name of current test
194 * @select_name: Name of test to run (or NULL for all)
Heinrich Schuchardt47b4c022022-01-19 18:05:50 +0100195 * Return: true to run this test, false to skip it
Simon Glassbb2b1732021-03-07 17:35:05 -0700196 */
197static bool test_matches(const char *prefix, const char *test_name,
198 const char *select_name)
199{
Andy Shevchenkod91cfbb2021-02-11 16:40:10 +0200200 size_t len;
201
Simon Glassbb2b1732021-03-07 17:35:05 -0700202 if (!select_name)
203 return true;
204
Andy Shevchenkod91cfbb2021-02-11 16:40:10 +0200205 /* Allow glob expansion in the test name */
206 len = select_name[strlen(select_name) - 1] == '*' ? strlen(select_name) : 0;
207 if (len-- == 1)
208 return true;
209
210 if (!strncmp(test_name, select_name, len))
Simon Glassbb2b1732021-03-07 17:35:05 -0700211 return true;
212
Andy Shevchenko00d42902021-02-11 16:40:11 +0200213 if (prefix) {
214 /* All tests have this prefix */
215 if (!strncmp(test_name, prefix, strlen(prefix)))
216 test_name += strlen(prefix);
217 } else {
Simon Glass1ef74ab2021-03-07 17:35:12 -0700218 const char *p = strstr(test_name, "_test_");
219
220 /* convert xxx_test_yyy to yyy, i.e. remove the suite name */
221 if (p)
Andy Shevchenko00d42902021-02-11 16:40:11 +0200222 test_name = p + strlen("_test_");
Simon Glass1ef74ab2021-03-07 17:35:12 -0700223 }
Simon Glassbb2b1732021-03-07 17:35:05 -0700224
Andy Shevchenkod91cfbb2021-02-11 16:40:10 +0200225 if (!strncmp(test_name, select_name, len))
Simon Glassbb2b1732021-03-07 17:35:05 -0700226 return true;
227
228 return false;
229}
230
Simon Glass53d1b192021-03-07 17:35:08 -0700231/**
Simon Glass1899e132021-03-07 17:35:07 -0700232 * ut_list_has_dm_tests() - Check if a list of tests has driver model ones
233 *
234 * @tests: List of tests to run
235 * @count: Number of tests to ru
Heinrich Schuchardt47b4c022022-01-19 18:05:50 +0100236 * Return: true if any of the tests have the UT_TESTF_DM flag
Simon Glass1899e132021-03-07 17:35:07 -0700237 */
238static bool ut_list_has_dm_tests(struct unit_test *tests, int count)
239{
240 struct unit_test *test;
241
242 for (test = tests; test < tests + count; test++) {
243 if (test->flags & UT_TESTF_DM)
244 return true;
245 }
246
247 return false;
248}
249
Simon Glassbb2b1732021-03-07 17:35:05 -0700250/**
Simon Glass53d1b192021-03-07 17:35:08 -0700251 * dm_test_restore() Put things back to normal so sandbox works as expected
252 *
253 * @of_root: Value to set for of_root
Heinrich Schuchardt47b4c022022-01-19 18:05:50 +0100254 * Return: 0 if OK, -ve on error
Simon Glass53d1b192021-03-07 17:35:08 -0700255 */
256static int dm_test_restore(struct device_node *of_root)
257{
258 int ret;
259
260 gd_set_of_root(of_root);
261 gd->dm_root = NULL;
262 ret = dm_init(CONFIG_IS_ENABLED(OF_LIVE));
263 if (ret)
264 return ret;
265 dm_scan_plat(false);
266 if (!CONFIG_IS_ENABLED(OF_PLATDATA))
267 dm_scan_fdt(false);
268
269 return 0;
270}
271
272/**
Simon Glass436687e2021-03-07 17:35:01 -0700273 * test_pre_run() - Handle any preparation needed to run a test
274 *
275 * @uts: Test state
276 * @test: Test to prepare for
Heinrich Schuchardt47b4c022022-01-19 18:05:50 +0100277 * Return: 0 if OK, -EAGAIN to skip this test since some required feature is not
Simon Glass436687e2021-03-07 17:35:01 -0700278 * available, other -ve on error (meaning that testing cannot likely
279 * continue)
280 */
281static int test_pre_run(struct unit_test_state *uts, struct unit_test *test)
Simon Glassd93dc7d2021-03-07 17:34:48 -0700282{
Simon Glassa128b1b2022-03-04 08:43:01 -0700283 ut_assertok(event_init());
Stefan Roese5be8f372022-09-02 13:57:54 +0200284 ut_assertok(cyclic_init());
Simon Glassa128b1b2022-03-04 08:43:01 -0700285
Simon Glassb2890a12021-03-07 17:34:56 -0700286 if (test->flags & UT_TESTF_DM)
Simon Glass2dba4762021-03-07 17:34:58 -0700287 ut_assertok(dm_test_pre_run(uts));
Simon Glassb2890a12021-03-07 17:34:56 -0700288
Simon Glass59cad962021-03-07 17:34:55 -0700289 ut_set_skip_delays(uts, false);
290
Simon Glass86a5bd02021-03-07 17:34:53 -0700291 uts->start = mallinfo();
Simon Glassd93dc7d2021-03-07 17:34:48 -0700292
Simon Glass9c80e542022-07-30 15:52:26 -0600293 if (test->flags & UT_TESTF_SCAN_PDATA) {
Simon Glass177e0fd2021-03-07 17:34:52 -0700294 ut_assertok(dm_scan_plat(false));
Simon Glass9c80e542022-07-30 15:52:26 -0600295 ut_assertok(dm_scan_other(false));
296 }
Simon Glass177e0fd2021-03-07 17:34:52 -0700297
Simon Glass242357c2021-03-07 17:34:51 -0700298 if (test->flags & UT_TESTF_PROBE_TEST)
299 ut_assertok(do_autoprobe(uts));
300
Simon Glassd18f7392021-03-07 17:34:50 -0700301 if (!CONFIG_IS_ENABLED(OF_PLATDATA) &&
302 (test->flags & UT_TESTF_SCAN_FDT))
303 ut_assertok(dm_extended_scan(false));
304
Simon Glassd93dc7d2021-03-07 17:34:48 -0700305 if (test->flags & UT_TESTF_CONSOLE_REC) {
306 int ret = console_record_reset_enable();
307
308 if (ret) {
309 printf("Skipping: Console recording disabled\n");
310 return -EAGAIN;
311 }
312 }
Simon Glass2b566b92021-03-07 17:34:54 -0700313 ut_silence_console(uts);
Simon Glassd93dc7d2021-03-07 17:34:48 -0700314
315 return 0;
316}
317
Simon Glass436687e2021-03-07 17:35:01 -0700318/**
319 * test_post_run() - Handle cleaning up after a test
320 *
321 * @uts: Test state
322 * @test: Test to clean up after
Heinrich Schuchardt47b4c022022-01-19 18:05:50 +0100323 * Return: 0 if OK, -ve on error (meaning that testing cannot likely continue)
Simon Glass436687e2021-03-07 17:35:01 -0700324 */
325static int test_post_run(struct unit_test_state *uts, struct unit_test *test)
Simon Glassd93dc7d2021-03-07 17:34:48 -0700326{
Simon Glass2b566b92021-03-07 17:34:54 -0700327 ut_unsilence_console(uts);
Simon Glass5b7e55b2021-03-07 17:34:59 -0700328 if (test->flags & UT_TESTF_DM)
329 ut_assertok(dm_test_post_run(uts));
Stefan Roese5be8f372022-09-02 13:57:54 +0200330 ut_assertok(cyclic_uninit());
Simon Glassa128b1b2022-03-04 08:43:01 -0700331 ut_assertok(event_uninit());
Simon Glass0f8f6772021-03-07 17:34:49 -0700332
Simon Glassd93dc7d2021-03-07 17:34:48 -0700333 return 0;
334}
335
Simon Glass0d32ec22021-03-07 17:35:03 -0700336/**
337 * ut_run_test() - Run a single test
338 *
339 * This runs the test, handling any preparation and clean-up needed. It prints
340 * the name of each test before running it.
341 *
342 * @uts: Test state to update. The caller should ensure that this is zeroed for
343 * the first call to this function. On exit, @uts->fail_count is
344 * incremented by the number of failures (0, one hopes)
345 * @test_name: Test to run
346 * @name: Name of test, possibly skipping a prefix that should not be displayed
Heinrich Schuchardt47b4c022022-01-19 18:05:50 +0100347 * Return: 0 if all tests passed, -EAGAIN if the test should be skipped, -1 if
Simon Glass0d32ec22021-03-07 17:35:03 -0700348 * any failed
349 */
350static int ut_run_test(struct unit_test_state *uts, struct unit_test *test,
351 const char *test_name)
Simon Glass5517edb2021-03-07 17:35:00 -0700352{
Simon Glass436687e2021-03-07 17:35:01 -0700353 const char *fname = strrchr(test->file, '/') + 1;
354 const char *note = "";
Simon Glass5517edb2021-03-07 17:35:00 -0700355 int ret;
356
Simon Glass436687e2021-03-07 17:35:01 -0700357 if ((test->flags & UT_TESTF_DM) && !uts->of_live)
358 note = " (flat tree)";
359 printf("Test: %s: %s%s\n", test_name, fname, note);
Simon Glass5517edb2021-03-07 17:35:00 -0700360
Simon Glass4066d8d2021-03-07 17:35:04 -0700361 /* Allow access to test state from drivers */
362 test_set_state(uts);
363
Simon Glass5517edb2021-03-07 17:35:00 -0700364 ret = test_pre_run(uts, test);
365 if (ret == -EAGAIN)
366 return -EAGAIN;
367 if (ret)
368 return ret;
369
370 test->func(uts);
371
372 ret = test_post_run(uts, test);
373 if (ret)
374 return ret;
375
Simon Glass4066d8d2021-03-07 17:35:04 -0700376 test_set_state( NULL);
377
Simon Glass5517edb2021-03-07 17:35:00 -0700378 return 0;
379}
380
Simon Glassbb2b1732021-03-07 17:35:05 -0700381/**
382 * ut_run_test_live_flat() - Run a test with both live and flat tree
383 *
384 * This calls ut_run_test() with livetree enabled, which is the standard setup
385 * for runnig tests. Then, for driver model test, it calls it again with
386 * livetree disabled. This allows checking of flattree being used when OF_LIVE
387 * is enabled, as is the case in U-Boot proper before relocation, as well as in
388 * SPL.
389 *
390 * @uts: Test state to update. The caller should ensure that this is zeroed for
391 * the first call to this function. On exit, @uts->fail_count is
392 * incremented by the number of failures (0, one hopes)
393 * @test: Test to run
394 * @name: Name of test, possibly skipping a prefix that should not be displayed
Heinrich Schuchardt47b4c022022-01-19 18:05:50 +0100395 * Return: 0 if all tests passed, -EAGAIN if the test should be skipped, -1 if
Simon Glassbb2b1732021-03-07 17:35:05 -0700396 * any failed
397 */
398static int ut_run_test_live_flat(struct unit_test_state *uts,
399 struct unit_test *test, const char *name)
Simon Glass0d32ec22021-03-07 17:35:03 -0700400{
401 int runs;
402
403 /* Run with the live tree if possible */
404 runs = 0;
405 if (CONFIG_IS_ENABLED(OF_LIVE)) {
Simon Glass7f9b5802022-09-06 20:26:59 -0600406 if (!(test->flags & UT_TESTF_FLAT_TREE)) {
Simon Glass0d32ec22021-03-07 17:35:03 -0700407 uts->of_live = true;
408 ut_assertok(ut_run_test(uts, test, test->name));
409 runs++;
410 }
411 }
412
413 /*
414 * Run with the flat tree if we couldn't run it with live tree,
415 * or it is a core test.
416 */
417 if (!(test->flags & UT_TESTF_LIVE_TREE) &&
418 (!runs || ut_test_run_on_flattree(test))) {
419 uts->of_live = false;
420 ut_assertok(ut_run_test(uts, test, test->name));
421 runs++;
422 }
423
424 return 0;
425}
426
Simon Glassbb2b1732021-03-07 17:35:05 -0700427/**
428 * ut_run_tests() - Run a set of tests
429 *
430 * This runs the tests, handling any preparation and clean-up needed. It prints
431 * the name of each test before running it.
432 *
433 * @uts: Test state to update. The caller should ensure that this is zeroed for
434 * the first call to this function. On exit, @uts->fail_count is
435 * incremented by the number of failures (0, one hopes)
436 * @prefix: String prefix for the tests. Any tests that have this prefix will be
437 * printed without the prefix, so that it is easier to see the unique part
438 * of the test name. If NULL, no prefix processing is done
439 * @tests: List of tests to run
440 * @count: Number of tests to run
441 * @select_name: Name of a single test to run (from the list provided). If NULL
442 * then all tests are run
Heinrich Schuchardt47b4c022022-01-19 18:05:50 +0100443 * Return: 0 if all tests passed, -ENOENT if test @select_name was not found,
Simon Glassbb2b1732021-03-07 17:35:05 -0700444 * -EBADF if any failed
445 */
446static int ut_run_tests(struct unit_test_state *uts, const char *prefix,
447 struct unit_test *tests, int count,
448 const char *select_name)
Simon Glass5722fb22021-03-07 17:34:47 -0700449{
450 struct unit_test *test;
Simon Glass5722fb22021-03-07 17:34:47 -0700451 int found = 0;
452
453 for (test = tests; test < tests + count; test++) {
454 const char *test_name = test->name;
Simon Glass91a187b2022-08-01 07:58:45 -0600455 int ret, i, old_fail_count;
Simon Glass5722fb22021-03-07 17:34:47 -0700456
Simon Glassbb2b1732021-03-07 17:35:05 -0700457 if (!test_matches(prefix, test_name, select_name))
Simon Glass5722fb22021-03-07 17:34:47 -0700458 continue;
Simon Glass91a187b2022-08-01 07:58:45 -0600459 old_fail_count = uts->fail_count;
460 for (i = 0; i < uts->runs_per_test; i++)
461 ret = ut_run_test_live_flat(uts, test, select_name);
462 if (uts->fail_count != old_fail_count) {
463 printf("Test %s failed %d times\n", select_name,
464 uts->fail_count - old_fail_count);
465 }
Simon Glass5722fb22021-03-07 17:34:47 -0700466 found++;
Simon Glassd93dc7d2021-03-07 17:34:48 -0700467 if (ret == -EAGAIN)
468 continue;
469 if (ret)
470 return ret;
Simon Glass5722fb22021-03-07 17:34:47 -0700471 }
472 if (select_name && !found)
473 return -ENOENT;
474
475 return uts->fail_count ? -EBADF : 0;
476}
477
478int ut_run_list(const char *category, const char *prefix,
Simon Glass91a187b2022-08-01 07:58:45 -0600479 struct unit_test *tests, int count, const char *select_name,
480 int runs_per_test)
Simon Glass5722fb22021-03-07 17:34:47 -0700481{
482 struct unit_test_state uts = { .fail_count = 0 };
Simon Glass53d1b192021-03-07 17:35:08 -0700483 bool has_dm_tests = false;
Simon Glass5722fb22021-03-07 17:34:47 -0700484 int ret;
485
Simon Glass1899e132021-03-07 17:35:07 -0700486 if (!CONFIG_IS_ENABLED(OF_PLATDATA) &&
487 ut_list_has_dm_tests(tests, count)) {
Simon Glass53d1b192021-03-07 17:35:08 -0700488 has_dm_tests = true;
Simon Glass1899e132021-03-07 17:35:07 -0700489 /*
490 * If we have no device tree, or it only has a root node, then
491 * these * tests clearly aren't going to work...
492 */
493 if (!gd->fdt_blob || fdt_next_node(gd->fdt_blob, 0, NULL) < 0) {
494 puts("Please run with test device tree:\n"
495 " ./u-boot -d arch/sandbox/dts/test.dtb\n");
496 return CMD_RET_FAILURE;
497 }
498 }
499
Simon Glass5722fb22021-03-07 17:34:47 -0700500 if (!select_name)
501 printf("Running %d %s tests\n", count, category);
502
Simon Glassbb2b1732021-03-07 17:35:05 -0700503 uts.of_root = gd_of_root();
Simon Glass91a187b2022-08-01 07:58:45 -0600504 uts.runs_per_test = runs_per_test;
Simon Glass3ba76752022-09-06 20:27:05 -0600505 if (fdt_action() == FDTCHK_COPY && gd->fdt_blob) {
506 uts.fdt_size = fdt_totalsize(gd->fdt_blob);
507 uts.fdt_copy = os_malloc(uts.fdt_size);
508 if (!uts.fdt_copy) {
509 printf("Out of memory for device tree copy\n");
510 return -ENOMEM;
511 }
512 memcpy(uts.fdt_copy, gd->fdt_blob, uts.fdt_size);
513 }
Simon Glass5722fb22021-03-07 17:34:47 -0700514 ret = ut_run_tests(&uts, prefix, tests, count, select_name);
515
Simon Glass3ba76752022-09-06 20:27:05 -0600516 /* Best efforts only...ignore errors */
517 if (has_dm_tests)
518 dm_test_restore(uts.of_root);
519 if (IS_ENABLED(CONFIG_SANDBOX))
520 os_free(uts.fdt_copy);
521
Simon Glass5722fb22021-03-07 17:34:47 -0700522 if (ret == -ENOENT)
523 printf("Test '%s' not found\n", select_name);
524 else
525 printf("Failures: %d\n", uts.fail_count);
526
Simon Glass53d1b192021-03-07 17:35:08 -0700527 /* Best efforts only...ignore errors */
528 if (has_dm_tests)
529 dm_test_restore(uts.of_root);
530
Simon Glass5722fb22021-03-07 17:34:47 -0700531 return ret;
532}