kunit: add support for kunit_suites that reference init code
PATCH 1/1 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_suite(); this new registration macro allows the registration of kunit_suites that reference functions marked __init and data marked __initdata.
---
This is a follow-up to the RFC here[1].
This patch is in response to a KUnit user issue[2] in which the user was attempting to test some init functions; although this is a functional solution as long as KUnit tests only run during the init phase, we will need to do more work if we ever allow tests to run after the init phase is over; it is for this reason that this patch adds a new registration macro rather than simply modifying the existing macros.
Changes since last version:
- I added more to the kunit_test_init_suites() kernel-doc comment detailing "how" the modpost warnings are suppressed in addition to the existing information regarding "why" it is OK for the modpost warnings to be suppressed.
[1] https://lore.kernel.org/linux-kselftest/[email protected]/
[2] https://groups.google.com/g/kunit-dev/c/XDjieRHEneg/m/D0rFCwVABgAJ
--- include/kunit/test.h | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+)
include/kunit/test.h +26 -0
@@ -379,6 +379,32 @@ static inline int kunit_run_all_tests(void)#define kunit_test_suite (suite) kunit_test_suites(&suite) +/** +* kunit_test_init_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_suites(__suites...) \ + __kunit_test_suites(CONCATENATE(__UNIQUE_ID(array), _probe), \ + CONCATENATE(__UNIQUE_ID(suites), _probe), \ + ##__suites) + +#define kunit_test_init_suite (suite) kunit_test_init_suites(&suite) +#define kunit_suite_for_each_test_case (suite, test_case) \ for (test_case = suite->test_cases; test_case->run_case; test_case++)
base-commit: 330f4c53d3c2d8b11d86ec03a964b86dc81452f5
Signature · 1 line
2.35.1.723.g4982287a31-goog
Shuah Khan
maintainerHi Brendan,
Quoted 11 lines · Brendan Higgins
Add support for a new kind of
kunit_suiteregistration macro calledkunit_test_init_suite(); this new registration macro allows the registration ofkunit_suitesthat reference functions marked__initand data marked__initdata.Signed-off-by Brendan Higgins <[email protected]>Tested-by Martin Fernandez <[email protected]>Reviewed-by Kees Cook <[email protected]>Reviewed-by David Gow <[email protected]>---
I almost applied it ...
Quoted 50 lines
This is a follow-up to the RFC here[1].
This patch is in response to a KUnit user issue[2] in which the user was attempting to test some init functions; although this is a functional solution as long as KUnit tests only run during the init phase, we will need to do more work if we ever allow tests to run after the init phase is over; it is for this reason that this patch adds a new registration macro rather than simply modifying the existing macros.
Changes since last version:
- I added more to thekunit_test_init_suites()kernel-doc comment detailing "how" the modpost warnings are suppressed in addition to the existing information regarding "why" it is OK for the modpost warnings to be suppressed.[1] https://lore.kernel.org/linux-kselftest/[email protected]/
[2] https://groups.google.com/g/kunit-dev/c/XDjieRHEneg/m/D0rFCwVABgAJ--- include/kunit/test.h | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+)include/kunit/test.h +19
-0@@ -379,6 +379,32 @@ static inline int kunit_run_all_tests(void)#define kunit_test_suite (suite) kunit_test_suites(&suite) +/** +* kunit_test_init_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. +*/
include/kunit/test.h static inline int kunit_run_all_tests(void) · line 410
Quoted 10 lines
include/kunit/test.h +7
-0+#define kunit_test_init_suites(__suites...) \ + __kunit_test_suites(CONCATENATE(__UNIQUE_ID(array), _probe), \ + CONCATENATE(__UNIQUE_ID(suites), _probe), \ + ##__suites) + +#define kunit_test_init_suite (suite) kunit_test_init_suites(&suite) +#define kunit_suite_for_each_test_case (suite, test_case) \ for (test_case = suite->test_cases; test_case->run_case; test_case++)
The naming of the function and macro are rather confusing and can become error prone. Let's find better naming scheme.
Quoted 2 lines
base-commit:
330f4c53d3c2d8b11d86ec03a964b86dc81452f5
thanks,
-- Shuah
Quoted 73 lines · Shuah Khan
Hi Brendan,
Quoted 11 lines · Brendan Higgins
Add support for a new kind of
kunit_suiteregistration macro calledkunit_test_init_suite(); this new registration macro allows the registration ofkunit_suitesthat reference functions marked__initand data marked__initdata.Signed-off-by Brendan Higgins <[email protected]>Tested-by Martin Fernandez <[email protected]>Reviewed-by Kees Cook <[email protected]>Reviewed-by David Gow <[email protected]>---
I almost applied it ...
Quoted 55 lines
This is a follow-up to the RFC here[1].
This patch is in response to a KUnit user issue[2] in which the user was attempting to test some init functions; although this is a functional solution as long as KUnit tests only run during the init phase, we will need to do more work if we ever allow tests to run after the init phase is over; it is for this reason that this patch adds a new registration macro rather than simply modifying the existing macros.
Changes since last version:
- I added more to thekunit_test_init_suites()kernel-doc comment detailing "how" the modpost warnings are suppressed in addition to the existing information regarding "why" it is OK for the modpost warnings to be suppressed.[1] https://lore.kernel.org/linux-kselftest/[email protected]/
[2] https://groups.google.com/g/kunit-dev/c/XDjieRHEneg/m/D0rFCwVABgAJ--- include/kunit/test.h | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+)include/kunit/test.h +25
-0@@ -379,6 +379,32 @@ static inline int kunit_run_all_tests(void)#define kunit_test_suite (suite) kunit_test_suites(&suite) +/** +* kunit_test_init_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_suites(__suites...) \ + __kunit_test_suites(CONCATENATE(__UNIQUE_ID(array), _probe), \ + CONCATENATE(__UNIQUE_ID(suites), _probe), \ + ##__suites) + +#define kunit_test_init_suite (suite) kunit_test_init_suites(&suite)
Quoted 8 lines
include/kunit/test.h static inline int kunit_run_all_tests(void) · line 410
Quoted 5 lines
include/kunit/test.h +1
-0+#define kunit_suite_for_each_test_case (suite, test_case) \ for (test_case = suite->test_cases; test_case->run_case; test_case++)The naming of the function and macro are rather confusing and can become error prone. Let's find better naming scheme.
Yeah, I wasn't sure about the name. I didn't have any better ideas initially though. Any suggestions?
Quoted 5 lines
Quoted 2 lines
base-commit:
330f4c53d3c2d8b11d86ec03a964b86dc81452f5thanks,
-- Shuah
Quoted 96 lines · Brendan Higgins
Quoted 85 lines · Shuah Khan
Hi Brendan,
Quoted 11 lines · Brendan Higgins
Add support for a new kind of
kunit_suiteregistration macro calledkunit_test_init_suite(); this new registration macro allows the registration ofkunit_suitesthat reference functions marked__initand data marked__initdata.Signed-off-by Brendan Higgins <[email protected]>Tested-by Martin Fernandez <[email protected]>Reviewed-by Kees Cook <[email protected]>Reviewed-by David Gow <[email protected]>---
I almost applied it ...
Quoted 67 lines
This is a follow-up to the RFC here[1].
This patch is in response to a KUnit user issue[2] in which the user was
attempting to test some init functions; although this is a functional solution as long as KUnit tests only run during the init phase, we will need to do more work if we ever allow tests to run after the init phase is over; it is for this reason that this patch adds a new registration macro rather than simply modifying the existing macros.Changes since last version:
- I added more to thekunit_test_init_suites()kernel-doc comment detailing "how" the modpost warnings are suppressed in addition to the existing information regarding "why" it is OK for the modpost warnings to be suppressed.[1]
https://lore.kernel.org/linux-kselftest/[email protected]/
[2] https://groups.google.com/g/kunit-dev/c/XDjieRHEneg/m/D0rFCwVABgAJ--- include/kunit/test.h | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+)include/kunit/test.h +2
-0@@ -379,6 +379,32 @@ static inline int kunit_run_all_tests(void)#define kunit_test_suite (suite) kunit_test_suites(&suite) +/** +* kunit_test_init_suites() - used to register one or more &struct
kunit_suite
+ * containing init functions or init data.
+ *
+ * @__suites: a statically allocated list of &structkunit_suite.
+ *
+ * This functions identically as&kunit_test_suites()except that it suppresses
+ * modpost warnings for referencing functions marked__initor 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 fromkunit_test_suitesis
+ * 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.
+ */include/kunit/test.h +7
-0+#define kunit_test_init_suites(__suites...) \ + __kunit_test_suites(CONCATENATE(__UNIQUE_ID(array), _probe), \ + CONCATENATE(__UNIQUE_ID(suites), _probe), \ + ##__suites) + +#define kunit_test_init_suite (suite) kunit_test_init_suites(&suite) +Quoted 8 lines
Quoted 5 lines
#define kunit_suite_for_each_test_case(suite, test_case) \ for (test_case = suite->test_cases; test_case->run_case;test_case++)
The naming of the function and macro are rather confusing and can become error prone. Let's find better naming scheme.
Quoted 3 lines
Yeah, I wasn't sure about the name. I didn't have any better ideas initially though. Any suggestions?
What about kunit_test_init_section_suite?
Quoted 6 lines
Quoted 5 lines
Quoted 2 lines
base-commit:
330f4c53d3c2d8b11d86ec03a964b86dc81452f5thanks,
-- Shuah
Quoted 98 lines · Martin Fernandez
Quoted 96 lines · Brendan Higgins
Quoted 93 lines · Shuah Khan
Hi Brendan,
Quoted 11 lines · Brendan Higgins
Add support for a new kind of
kunit_suiteregistration macro calledkunit_test_init_suite(); this new registration macro allows the registration ofkunit_suitesthat reference functions marked__initand data marked__initdata.Signed-off-by Brendan Higgins <[email protected]>Tested-by Martin Fernandez <[email protected]>Reviewed-by Kees Cook <[email protected]>Reviewed-by David Gow <[email protected]>---
I almost applied it ...
Quoted 69 lines
This is a follow-up to the RFC here[1].
This patch is in response to a KUnit user issue[2] in which the user was
attempting to test some init functions; although this is a functional solution as long as KUnit tests only run during the init phase, we will need to do more work if we ever allow tests to run after the init phase is over; it is for this reason that this patch adds a new registration macro rather than simply modifying the existing macros.Changes since last version:
- I added more to thekunit_test_init_suites()kernel-doc comment detailing "how" the modpost warnings are suppressed in addition to the existing information regarding "why" it is OK for the modpost warnings to be suppressed.[1]
https://lore.kernel.org/linux-kselftest/[email protected]/
[2] https://groups.google.com/g/kunit-dev/c/XDjieRHEneg/m/D0rFCwVABgAJ--- include/kunit/test.h | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+)include/kunit/test.h +2
-0@@ -379,6 +379,32 @@ static inline int kunit_run_all_tests(void)#define kunit_test_suite (suite) kunit_test_suites(&suite) +/** +* kunit_test_init_suites() - used to register one or more &struct
kunit_suite
+ * containing init functions or init data.
+ *
+ * @__suites: a statically allocated list of &structkunit_suite.
+ *
+ * This functions identically as&kunit_test_suites()except that it suppresses
+ * modpost warnings for referencing functions marked__initor 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 fromkunit_test_suitesis
+ * 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.
+ */include/kunit/test.h +7
-0+#define kunit_test_init_suites(__suites...) \ + __kunit_test_suites(CONCATENATE(__UNIQUE_ID(array), _probe), \ + CONCATENATE(__UNIQUE_ID(suites), _probe), \ + ##__suites) + +#define kunit_test_init_suite (suite) kunit_test_init_suites(&suite) +#define kunit_suite_for_each_test_case (suite, test_case) \ for (test_case = suite->test_cases; test_case->run_case;Quoted 3 lines
test_case++)
The naming of the function and macro are rather confusing and can become error prone. Let's find better naming scheme.
Quoted 5 lines
Quoted 3 lines
Yeah, I wasn't sure about the name. I didn't have any better ideas initially though. Any suggestions?
What about
kunit_test_init_section_suite?
Sounds fine to me. Shuah, does that sound OK to you?
Quoted 6 lines
Quoted 6 lines
Quoted 5 lines
Quoted 2 lines
base-commit:
330f4c53d3c2d8b11d86ec03a964b86dc81452f5thanks,
-- Shuah
Shuah Khan
maintainerQuoted 100 lines · Brendan Higgins
Quoted 98 lines · Martin Fernandez
Quoted 96 lines · Brendan Higgins
Quoted 93 lines · Shuah Khan
Hi Brendan,
Quoted 11 lines · Brendan Higgins
Add support for a new kind of
kunit_suiteregistration macro calledkunit_test_init_suite(); this new registration macro allows the registration ofkunit_suitesthat reference functions marked__initand data marked__initdata.Signed-off-by Brendan Higgins <[email protected]>Tested-by Martin Fernandez <[email protected]>Reviewed-by Kees Cook <[email protected]>Reviewed-by David Gow <[email protected]>---
I almost applied it ...
Quoted 69 lines
This is a follow-up to the RFC here[1].
This patch is in response to a KUnit user issue[2] in which the user was
attempting to test some init functions; although this is a functional solution as long as KUnit tests only run during the init phase, we will need to do more work if we ever allow tests to run after the init phase is over; it is for this reason that this patch adds a new registration macro rather than simply modifying the existing macros.Changes since last version:
- I added more to thekunit_test_init_suites()kernel-doc comment detailing "how" the modpost warnings are suppressed in addition to the existing information regarding "why" it is OK for the modpost warnings to be suppressed.[1]
https://lore.kernel.org/linux-kselftest/[email protected]/
[2] https://groups.google.com/g/kunit-dev/c/XDjieRHEneg/m/D0rFCwVABgAJ--- include/kunit/test.h | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+)include/kunit/test.h +2
-0@@ -379,6 +379,32 @@ static inline int kunit_run_all_tests(void)#define kunit_test_suite (suite) kunit_test_suites(&suite) +/** +* kunit_test_init_suites() - used to register one or more &struct
kunit_suite
+ * containing init functions or init data.
+ *
+ * @__suites: a statically allocated list of &structkunit_suite.
+ *
+ * This functions identically as&kunit_test_suites()except that it suppresses
+ * modpost warnings for referencing functions marked__initor 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 fromkunit_test_suitesis
+ * 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.
+ */include/kunit/test.h +7
-0+#define kunit_test_init_suites(__suites...) \ + __kunit_test_suites(CONCATENATE(__UNIQUE_ID(array), _probe), \ + CONCATENATE(__UNIQUE_ID(suites), _probe), \ + ##__suites) + +#define kunit_test_init_suite (suite) kunit_test_init_suites(&suite) +#define kunit_suite_for_each_test_case (suite, test_case) \ for (test_case = suite->test_cases; test_case->run_case;Quoted 3 lines
test_case++)
The naming of the function and macro are rather confusing and can become error prone. Let's find better naming scheme.
Quoted 8 lines
Quoted 5 lines
Quoted 3 lines
Yeah, I wasn't sure about the name. I didn't have any better ideas initially though. Any suggestions?
What about
kunit_test_init_section_suite?Sounds fine to me. Shuah, does that sound OK to you?
Sorry for the delay in responding.
As long as the two names are different enough to tell them apart. The proposed name does that.
thanks,
-- Shuah