Skip to content

Commit

Permalink
init: main: add KUnit to kernel init
Browse files Browse the repository at this point in the history
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 <alan.maguire@oracle.com>
Signed-off-by: Alan Maguire <alan.maguire@oracle.com>
Signed-off-by: Brendan Higgins <brendanhiggins@google.com>
Reviewed-by: Stephen Boyd <sboyd@kernel.org>
Reviewed-by: Kees Cook <keescook@chromium.org>
Reviewed-by: Luis Chamberlain <mcgrof@kernel.org>
Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
  • Loading branch information
Brendan Higgins authored and Shuah Khan committed Oct 9, 2020
1 parent aac3546 commit 8c0d884
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
9 changes: 9 additions & 0 deletions include/kunit/test.h
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,15 @@ int __kunit_test_suites_init(struct kunit_suite * const * const suites);

void __kunit_test_suites_exit(struct kunit_suite **suites);

#if IS_BUILTIN(CONFIG_KUNIT)
int kunit_run_all_tests(void);
#else
static inline int kunit_run_all_tests(void)
{
return 0;
}
#endif /* IS_BUILTIN(CONFIG_KUNIT) */

/**
* kunit_test_suites() - used to register one or more &struct kunit_suite
* with KUnit.
Expand Down
4 changes: 4 additions & 0 deletions init/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@
#define CREATE_TRACE_POINTS
#include <trace/events/initcall.h>

#include <kunit/test.h>

static int kernel_init(void *);

extern void init_IRQ(void);
Expand Down Expand Up @@ -1511,6 +1513,8 @@ static noinline void __init kernel_init_freeable(void)

do_basic_setup();

kunit_run_all_tests();

console_on_rootfs();

/*
Expand Down
4 changes: 1 addition & 3 deletions lib/kunit/executor.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ extern struct kunit_suite * const * const __kunit_suites_end[];

#if IS_BUILTIN(CONFIG_KUNIT)

static int kunit_run_all_tests(void)
int kunit_run_all_tests(void)
{
struct kunit_suite * const * const *suites;

Expand All @@ -23,6 +23,4 @@ static int kunit_run_all_tests(void)
return 0;
}

late_initcall(kunit_run_all_tests);

#endif /* IS_BUILTIN(CONFIG_KUNIT) */

0 comments on commit 8c0d884

Please sign in to comment.