summaryrefslogtreecommitdiff
path: root/include/kunit/test.h
diff options
context:
space:
mode:
authorBrendan Higgins <brendanhiggins@google.com>2022-04-18 21:05:15 -0700
committerShuah Khan <skhan@linuxfoundation.org>2022-04-26 18:08:25 -0600
commit9bf2eed995f9f8136f00110214c120f2d7912ad8 (patch)
tree52e387d519c62ee9ee5147013ac8ed9008496814 /include/kunit/test.h
parent59729170afcd4900e08997a482467ffda8d88c7f (diff)
kunit: add support for kunit_suites that reference init code
Add support for a new kind of kunit_suite registration macro called kunit_test_init_section_suite(); this new registration macro allows the registration of kunit_suites that reference functions marked __init and data marked __initdata. Signed-off-by: Brendan Higgins <brendanhiggins@google.com> Tested-by: Martin Fernandez <martin.fernandez@eclypsium.com> Reviewed-by: Kees Cook <keescook@chromium.org> Reviewed-by: David Gow <davidgow@google.com> Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
Diffstat (limited to 'include/kunit/test.h')
-rw-r--r--include/kunit/test.h28
1 files changed, 28 insertions, 0 deletions
diff --git a/include/kunit/test.h b/include/kunit/test.h
index 97cd76461886..17749b4467ad 100644
--- a/include/kunit/test.h
+++ b/include/kunit/test.h
@@ -308,6 +308,34 @@ static inline int kunit_run_all_tests(void)
#define kunit_test_suite(suite) kunit_test_suites(&suite)
+/**
+ * kunit_test_init_section_suites() - used to register one or more &struct
+ * kunit_suite containing init functions or
+ * init data.
+ *
+ * @__suites: a statically allocated list of &struct kunit_suite.
+ *
+ * This functions identically as &kunit_test_suites() except that it suppresses
+ * modpost warnings for referencing functions marked __init or data marked
+ * __initdata; this is OK because currently KUnit only runs tests upon boot
+ * during the init phase or upon loading a module during the init phase.
+ *
+ * NOTE TO KUNIT DEVS: If we ever allow KUnit tests to be run after boot, these
+ * tests must be excluded.
+ *
+ * The only thing this macro does that's different from kunit_test_suites is
+ * that it suffixes the array and suite declarations it makes with _probe;
+ * modpost suppresses warnings about referencing init data for symbols named in
+ * this manner.
+ */
+#define kunit_test_init_section_suites(__suites...) \
+ __kunit_test_suites(CONCATENATE(__UNIQUE_ID(array), _probe), \
+ CONCATENATE(__UNIQUE_ID(suites), _probe), \
+ ##__suites)
+
+#define kunit_test_init_section_suite(suite) \
+ kunit_test_init_section_suites(&suite)
+
#define kunit_suite_for_each_test_case(suite, test_case) \
for (test_case = suite->test_cases; test_case->run_case; test_case++)