Skip to content

Commit 8c0d884

Browse files
bjh83shuahkh
authored andcommitted
init: main: add KUnit to kernel init
Although we have not seen any actual examples where KUnit doesn't work because it runs in the late init phase of the kernel, it has been a concern for some time that this could potentially be an issue in the future. So, remove KUnit from init calls entirely, instead call directly from kernel_init() so that KUnit runs after late init. Co-developed-by: Alan Maguire <[email protected]> Signed-off-by: Alan Maguire <[email protected]> Signed-off-by: Brendan Higgins <[email protected]> Reviewed-by: Stephen Boyd <[email protected]> Reviewed-by: Kees Cook <[email protected]> Reviewed-by: Luis Chamberlain <[email protected]> Signed-off-by: Shuah Khan <[email protected]>
1 parent aac3546 commit 8c0d884

File tree

3 files changed

+14
-3
lines changed

3 files changed

+14
-3
lines changed

include/kunit/test.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,15 @@ int __kunit_test_suites_init(struct kunit_suite * const * const suites);
237237

238238
void __kunit_test_suites_exit(struct kunit_suite **suites);
239239

240+
#if IS_BUILTIN(CONFIG_KUNIT)
241+
int kunit_run_all_tests(void);
242+
#else
243+
static inline int kunit_run_all_tests(void)
244+
{
245+
return 0;
246+
}
247+
#endif /* IS_BUILTIN(CONFIG_KUNIT) */
248+
240249
/**
241250
* kunit_test_suites() - used to register one or more &struct kunit_suite
242251
* with KUnit.

init/main.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,8 @@
107107
#define CREATE_TRACE_POINTS
108108
#include <trace/events/initcall.h>
109109

110+
#include <kunit/test.h>
111+
110112
static int kernel_init(void *);
111113

112114
extern void init_IRQ(void);
@@ -1511,6 +1513,8 @@ static noinline void __init kernel_init_freeable(void)
15111513

15121514
do_basic_setup();
15131515

1516+
kunit_run_all_tests();
1517+
15141518
console_on_rootfs();
15151519

15161520
/*

lib/kunit/executor.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ extern struct kunit_suite * const * const __kunit_suites_end[];
1111

1212
#if IS_BUILTIN(CONFIG_KUNIT)
1313

14-
static int kunit_run_all_tests(void)
14+
int kunit_run_all_tests(void)
1515
{
1616
struct kunit_suite * const * const *suites;
1717

@@ -23,6 +23,4 @@ static int kunit_run_all_tests(void)
2323
return 0;
2424
}
2525

26-
late_initcall(kunit_run_all_tests);
27-
2826
#endif /* IS_BUILTIN(CONFIG_KUNIT) */

0 commit comments

Comments
 (0)