1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright 2021 Google LLC
4 * Written by Simon Glass <sjg@chromium.org>
11 int ut_run_tests(struct unit_test_state *uts, const char *prefix,
12 struct unit_test *tests, int count, const char *select_name)
14 struct unit_test *test;
15 int prefix_len = prefix ? strlen(prefix) : 0;
18 for (test = tests; test < tests + count; test++) {
19 const char *test_name = test->name;
21 /* Remove the prefix */
22 if (prefix && !strncmp(test_name, prefix, prefix_len))
23 test_name += prefix_len;
25 if (select_name && strcmp(select_name, test_name))
27 printf("Test: %s\n", test_name);
30 if (test->flags & UT_TESTF_CONSOLE_REC) {
31 int ret = console_record_reset_enable();
34 printf("Skipping: Console recording disabled\n");
39 uts->start = mallinfo();
43 if (select_name && !found)
46 return uts->fail_count ? -EBADF : 0;
49 int ut_run_list(const char *category, const char *prefix,
50 struct unit_test *tests, int count, const char *select_name)
52 struct unit_test_state uts = { .fail_count = 0 };
56 printf("Running %d %s tests\n", count, category);
58 ret = ut_run_tests(&uts, prefix, tests, count, select_name);
61 printf("Test '%s' not found\n", select_name);
63 printf("Failures: %d\n", uts.fail_count);