nitro_enclaves: test: Use kunit_test_suite() macro
authorDavid Gow <davidgow@google.com>
Sat, 9 Jul 2022 03:20:00 +0000 (11:20 +0800)
committerShuah Khan <skhan@linuxfoundation.org>
Mon, 11 Jul 2022 23:13:27 +0000 (17:13 -0600)
The kunit_test_suite() macro previously conflicted with module_init,
making it unsuitable for use in the nitro_enclaves test. Now that it's
fixed, we can use it instead of a custom call into internal KUnit
functions to run the test.

As a side-effect, this means that the test results are properly included
with other suites when built-in. To celebrate, enable the test by
default when KUNIT_ALL_TESTS is set (and NITRO_ENCLAVES enabled).

The nitro_enclave tests can now be run via kunit_tool with:
./tools/testing/kunit/kunit.py run --arch=x86_64 \
--kconfig_add CONFIG_PCI=y --kconfig_add CONFIG_SMP=y \
--kconfig_add CONFIG_HOTPLUG_CPU=y \
--kconfig_add CONFIG_VIRT_DRIVERS=y \
--kconfig_add CONFIG_NITRO_ENCLAVES=y \
'ne_misc_dev_test'

(This is a pretty long command, so it may be worth adding a .kunitconfig
file at some point, instead.)

Reviewed-by: Andra Paraschiv <andraprs@amazon.com>
Acked-by: Brendan Higgins <brendanhiggins@google.com>
Signed-off-by: David Gow <davidgow@google.com>
Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
drivers/virt/nitro_enclaves/Kconfig
drivers/virt/nitro_enclaves/ne_misc_dev.c
drivers/virt/nitro_enclaves/ne_misc_dev_test.c

index 2d3d9815812188582cf44e1ea35c7ed32c133d40..ce91add81401a22805d253a585d2b15b11572a31 100644 (file)
@@ -16,8 +16,9 @@ config NITRO_ENCLAVES
          The module will be called nitro_enclaves.
 
 config NITRO_ENCLAVES_MISC_DEV_TEST
-       bool "Tests for the misc device functionality of the Nitro Enclaves"
-       depends on NITRO_ENCLAVES && KUNIT=y
+       bool "Tests for the misc device functionality of the Nitro Enclaves" if !KUNIT_ALL_TESTS
+       depends on NITRO_ENCLAVES && KUNIT
+       default KUNIT_ALL_TESTS
        help
          Enable KUnit tests for the misc device functionality of the Nitro
          Enclaves. Select this option only if you will boot the kernel for
index 20c881b6a4b652fef2caeb2e9e64400942e68ea7..241b94f62e56e216987e85cd0474f52f5fd66359 100644 (file)
@@ -1759,35 +1759,10 @@ static long ne_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
 
 #if defined(CONFIG_NITRO_ENCLAVES_MISC_DEV_TEST)
 #include "ne_misc_dev_test.c"
-
-static inline int ne_misc_dev_test_init(void)
-{
-       return __kunit_test_suites_init(ne_misc_dev_test_suites);
-}
-
-static inline void ne_misc_dev_test_exit(void)
-{
-       __kunit_test_suites_exit(ne_misc_dev_test_suites);
-}
-#else
-static inline int ne_misc_dev_test_init(void)
-{
-       return 0;
-}
-
-static inline void ne_misc_dev_test_exit(void)
-{
-}
 #endif
 
 static int __init ne_init(void)
 {
-       int rc = 0;
-
-       rc = ne_misc_dev_test_init();
-       if (rc < 0)
-               return rc;
-
        mutex_init(&ne_cpu_pool.mutex);
 
        return pci_register_driver(&ne_pci_driver);
@@ -1798,8 +1773,6 @@ static void __exit ne_exit(void)
        pci_unregister_driver(&ne_pci_driver);
 
        ne_teardown_cpu_pool();
-
-       ne_misc_dev_test_exit();
 }
 
 module_init(ne_init);
index 265797bed0ea874ba5fa648894d71f6e4c6ddcc4..74df43b925be3a3143ef60298fa64d22163e156f 100644 (file)
@@ -151,7 +151,4 @@ static struct kunit_suite ne_misc_dev_test_suite = {
        .test_cases = ne_misc_dev_test_cases,
 };
 
-static struct kunit_suite *ne_misc_dev_test_suites[] = {
-       &ne_misc_dev_test_suite,
-       NULL
-};
+kunit_test_suite(ne_misc_dev_test_suite);