Skip to content

Commit 9fe124b

Browse files
alan-maguireshuahkh
authored andcommitted
kunit: allow kunit to be loaded as a module
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]>
1 parent 1c024d4 commit 9fe124b

File tree

3 files changed

+17
-2
lines changed

3 files changed

+17
-2
lines changed

lib/kunit/Kconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#
44

55
menuconfig KUNIT
6-
bool "KUnit - Enable support for unit tests"
6+
tristate "KUnit - Enable support for unit tests"
77
help
88
Enables support for kernel unit tests (KUnit), a lightweight unit
99
testing and mocking framework for the Linux kernel. These tests are

lib/kunit/Makefile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
obj-$(CONFIG_KUNIT) += test.o \
1+
obj-$(CONFIG_KUNIT) += kunit.o
2+
3+
kunit-objs += test.o \
24
string-stream.o \
35
assert.o \
46
try-catch.o

lib/kunit/test.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -486,3 +486,16 @@ void kunit_cleanup(struct kunit *test)
486486
}
487487
}
488488
EXPORT_SYMBOL_GPL(kunit_cleanup);
489+
490+
static int __init kunit_init(void)
491+
{
492+
return 0;
493+
}
494+
late_initcall(kunit_init);
495+
496+
static void __exit kunit_exit(void)
497+
{
498+
}
499+
module_exit(kunit_exit);
500+
501+
MODULE_LICENSE("GPL v2");

0 commit comments

Comments
 (0)