kunit: allow kunit to be loaded as a module
authorAlan Maguire <alan.maguire@oracle.com>
Mon, 6 Jan 2020 22:28:22 +0000 (22:28 +0000)
committerShuah Khan <skhan@linuxfoundation.org>
Thu, 9 Jan 2020 23:43:40 +0000 (16:43 -0700)
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 <knut.omang@oracle.com>
Signed-off-by: Knut Omang <knut.omang@oracle.com>
Signed-off-by: Alan Maguire <alan.maguire@oracle.com>
Reviewed-by: Brendan Higgins <brendanhiggins@google.com>
Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
lib/kunit/Kconfig
lib/kunit/Makefile
lib/kunit/test.c

index 9ebd5e6..065aa16 100644 (file)
@@ -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
index bc6e5e5..fab5564 100644 (file)
@@ -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
index 87b5cf1..9242f93 100644 (file)
@@ -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");