1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright 2021 Google LLC
4 * Written by Simon Glass <sjg@chromium.org>
11 #include <test/test.h>
14 DECLARE_GLOBAL_DATA_PTR;
16 /* Ensure all the test devices are probed */
17 static int do_autoprobe(struct unit_test_state *uts)
22 /* Scanning the uclass is enough to probe all the devices */
23 for (ret = uclass_first_device(UCLASS_TEST, &dev);
25 ret = uclass_next_device(&dev))
31 int test_pre_run(struct unit_test_state *uts, struct unit_test *test)
33 /* DM tests have already done this */
34 if (!(test->flags & UT_TESTF_DM))
35 uts->start = mallinfo();
37 if (test->flags & UT_TESTF_SCAN_PDATA)
38 ut_assertok(dm_scan_plat(false));
40 if (test->flags & UT_TESTF_PROBE_TEST)
41 ut_assertok(do_autoprobe(uts));
43 if (!CONFIG_IS_ENABLED(OF_PLATDATA) &&
44 (test->flags & UT_TESTF_SCAN_FDT))
45 ut_assertok(dm_extended_scan(false));
47 if (test->flags & UT_TESTF_CONSOLE_REC) {
48 int ret = console_record_reset_enable();
51 printf("Skipping: Console recording disabled\n");
59 int test_post_run(struct unit_test_state *uts, struct unit_test *test)
61 gd->flags &= ~GD_FLG_RECORD;
66 int ut_run_tests(struct unit_test_state *uts, const char *prefix,
67 struct unit_test *tests, int count, const char *select_name)
69 struct unit_test *test;
70 int prefix_len = prefix ? strlen(prefix) : 0;
73 for (test = tests; test < tests + count; test++) {
74 const char *test_name = test->name;
77 /* Remove the prefix */
78 if (prefix && !strncmp(test_name, prefix, prefix_len))
79 test_name += prefix_len;
81 if (select_name && strcmp(select_name, test_name))
83 printf("Test: %s\n", test_name);
86 ret = test_pre_run(uts, test);
94 ret = test_post_run(uts, test);
98 if (select_name && !found)
101 return uts->fail_count ? -EBADF : 0;
104 int ut_run_list(const char *category, const char *prefix,
105 struct unit_test *tests, int count, const char *select_name)
107 struct unit_test_state uts = { .fail_count = 0 };
111 printf("Running %d %s tests\n", count, category);
113 ret = ut_run_tests(&uts, prefix, tests, count, select_name);
116 printf("Test '%s' not found\n", select_name);
118 printf("Failures: %d\n", uts.fail_count);