xref: /openbmc/linux/lib/kunit/executor.c (revision b9dd2add)
1 // SPDX-License-Identifier: GPL-2.0
2 
3 #include <kunit/test.h>
4 
5 /*
6  * These symbols point to the .kunit_test_suites section and are defined in
7  * include/asm-generic/vmlinux.lds.h, and consequently must be extern.
8  */
9 extern struct kunit_suite * const * const __kunit_suites_start[];
10 extern struct kunit_suite * const * const __kunit_suites_end[];
11 
12 #if IS_BUILTIN(CONFIG_KUNIT)
13 
14 static void kunit_print_tap_header(void)
15 {
16 	struct kunit_suite * const * const *suites, * const *subsuite;
17 	int num_of_suites = 0;
18 
19 	for (suites = __kunit_suites_start;
20 	     suites < __kunit_suites_end;
21 	     suites++)
22 		for (subsuite = *suites; *subsuite != NULL; subsuite++)
23 			num_of_suites++;
24 
25 	pr_info("TAP version 14\n");
26 	pr_info("1..%d\n", num_of_suites);
27 }
28 
29 int kunit_run_all_tests(void)
30 {
31 	struct kunit_suite * const * const *suites;
32 
33 	kunit_print_tap_header();
34 
35 	for (suites = __kunit_suites_start;
36 	     suites < __kunit_suites_end;
37 	     suites++)
38 			__kunit_test_suites_init(*suites);
39 
40 	return 0;
41 }
42 
43 #endif /* IS_BUILTIN(CONFIG_KUNIT) */
44