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 uts->start = mallinfo();
35 if (test->flags & UT_TESTF_SCAN_PDATA)
36 ut_assertok(dm_scan_plat(false));
38 if (test->flags & UT_TESTF_PROBE_TEST)
39 ut_assertok(do_autoprobe(uts));
41 if (!CONFIG_IS_ENABLED(OF_PLATDATA) &&
42 (test->flags & UT_TESTF_SCAN_FDT))
43 ut_assertok(dm_extended_scan(false));
45 if (test->flags & UT_TESTF_CONSOLE_REC) {
46 int ret = console_record_reset_enable();
49 printf("Skipping: Console recording disabled\n");
57 int test_post_run(struct unit_test_state *uts, struct unit_test *test)
59 gd->flags &= ~GD_FLG_RECORD;
64 int ut_run_tests(struct unit_test_state *uts, const char *prefix,
65 struct unit_test *tests, int count, const char *select_name)
67 struct unit_test *test;
68 int prefix_len = prefix ? strlen(prefix) : 0;
71 for (test = tests; test < tests + count; test++) {
72 const char *test_name = test->name;
75 /* Remove the prefix */
76 if (prefix && !strncmp(test_name, prefix, prefix_len))
77 test_name += prefix_len;
79 if (select_name && strcmp(select_name, test_name))
81 printf("Test: %s\n", test_name);
84 ret = test_pre_run(uts, test);
92 ret = test_post_run(uts, test);
96 if (select_name && !found)
99 return uts->fail_count ? -EBADF : 0;
102 int ut_run_list(const char *category, const char *prefix,
103 struct unit_test *tests, int count, const char *select_name)
105 struct unit_test_state uts = { .fail_count = 0 };
109 printf("Running %d %s tests\n", count, category);
111 ret = ut_run_tests(&uts, prefix, tests, count, select_name);
114 printf("Test '%s' not found\n", select_name);
116 printf("Failures: %d\n", uts.fail_count);