1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright 2021 Google LLC
4 * Written by Simon Glass <sjg@chromium.org>
11 DECLARE_GLOBAL_DATA_PTR;
13 int test_pre_run(struct unit_test_state *uts, struct unit_test *test)
15 /* DM tests have already done this */
16 if (!(test->flags & UT_TESTF_DM))
17 uts->start = mallinfo();
19 if (test->flags & UT_TESTF_CONSOLE_REC) {
20 int ret = console_record_reset_enable();
23 printf("Skipping: Console recording disabled\n");
31 int test_post_run(struct unit_test_state *uts, struct unit_test *test)
33 gd->flags &= ~GD_FLG_RECORD;
38 int ut_run_tests(struct unit_test_state *uts, const char *prefix,
39 struct unit_test *tests, int count, const char *select_name)
41 struct unit_test *test;
42 int prefix_len = prefix ? strlen(prefix) : 0;
45 for (test = tests; test < tests + count; test++) {
46 const char *test_name = test->name;
49 /* Remove the prefix */
50 if (prefix && !strncmp(test_name, prefix, prefix_len))
51 test_name += prefix_len;
53 if (select_name && strcmp(select_name, test_name))
55 printf("Test: %s\n", test_name);
58 ret = test_pre_run(uts, test);
66 ret = test_post_run(uts, test);
70 if (select_name && !found)
73 return uts->fail_count ? -EBADF : 0;
76 int ut_run_list(const char *category, const char *prefix,
77 struct unit_test *tests, int count, const char *select_name)
79 struct unit_test_state uts = { .fail_count = 0 };
83 printf("Running %d %s tests\n", count, category);
85 ret = ut_run_tests(&uts, prefix, tests, count, select_name);
88 printf("Test '%s' not found\n", select_name);
90 printf("Failures: %d\n", uts.fail_count);