Skip to content

Commit

Permalink
kunit: allow kunit to be loaded as a module
Browse files Browse the repository at this point in the history
Making kunit itself buildable as a module allows for "always-on"
kunit configuration; specifying CONFIG_KUNIT=m means the module
is built but only used when loaded.  Kunit test modules will load
kunit.ko as an implicit dependency, so simply running
"modprobe my-kunit-tests" will load the tests along with the kunit
module and run them.

Co-developed-by: Knut Omang <[email protected]>
Signed-off-by: Knut Omang <[email protected]>
Signed-off-by: Alan Maguire <[email protected]>
Reviewed-by: Brendan Higgins <[email protected]>
Signed-off-by: Shuah Khan <[email protected]>
  • Loading branch information
alan-maguire authored and shuahkh committed Jan 9, 2020
1 parent 1c024d4 commit 9fe124b
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/kunit/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#

menuconfig KUNIT
bool "KUnit - Enable support for unit tests"
tristate "KUnit - Enable support for unit tests"
help
Enables support for kernel unit tests (KUnit), a lightweight unit
testing and mocking framework for the Linux kernel. These tests are
Expand Down
4 changes: 3 additions & 1 deletion lib/kunit/Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
obj-$(CONFIG_KUNIT) += test.o \
obj-$(CONFIG_KUNIT) += kunit.o

kunit-objs += test.o \
string-stream.o \
assert.o \
try-catch.o
Expand Down
13 changes: 13 additions & 0 deletions lib/kunit/test.c
Original file line number Diff line number Diff line change
Expand Up @@ -486,3 +486,16 @@ void kunit_cleanup(struct kunit *test)
}
}
EXPORT_SYMBOL_GPL(kunit_cleanup);

static int __init kunit_init(void)
{
return 0;
}
late_initcall(kunit_init);

static void __exit kunit_exit(void)
{
}
module_exit(kunit_exit);

MODULE_LICENSE("GPL v2");

0 comments on commit 9fe124b

Please sign in to comment.