Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

kunit: Make 'list' action available to kunit test modules

Results from kunit tests reported via dmesg may be interleaved with other
kernel messages. When parsing dmesg for modular kunit results in real
time, external tools, e.g., Intel GPU tools (IGT), may want to insert
their own test name markers into dmesg at the start of each test, before
any kernel message related to that test appears there, so existing upper
level test result parsers have no doubt which test to blame for a specific
kernel message. Unfortunately, kunit reports names of tests only at their
completion (with the exeption of a not standarized "# Subtest: <name>"
header above a test plan of each test suite or parametrized test).

External tools could be able to insert their own "start of the test"
markers with test names included if they new those names in advance.
Test names could be learned from a list if provided by a kunit test
module.

There exists a feature of listing kunit tests without actually executing
them, but it is now limited to configurations with the kunit module built
in and covers only built-in tests, already available at boot time.
Moreover, switching from list to normal mode requires reboot. If that
feature was also available when kunit is built as a module, userspace
could load the module with action=list parameter, load some kunit test
modules they are interested in and learn about the list of tests provided
by those modules, then unload them, reload the kunit module in normal mode
and execute the tests with their lists already known.

Extend kunit module notifier initialization callback with a processing
path for only listing the tests provided by a module if the kunit action
parameter is set to "list" or "list_attr". For user convenience, make the
kunit.action parameter visible in sysfs.

v2: Don't use a different format, use kunit_exec_list_tests() (Rae),
- refresh on top of new attributes patches, handle newly introduced
kunit.action=list_attr case (Rae).

Signed-off-by: Janusz Krzysztofik <janusz.krzysztofik@linux.intel.com>
Cc: Rae Moar <rmoar@google.com>
Reviewed-by: David Gow <davidgow@google.com>
Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>

authored by

Janusz Krzysztofik and committed by
Shuah Khan
18258c60 c95e7c05

+33 -13
+2
include/kunit/test.h
··· 309 309 } 310 310 311 311 bool kunit_enabled(void); 312 + const char *kunit_action(void); 312 313 313 314 void kunit_init_test(struct kunit *test, const char *name, char *log); 314 315 ··· 325 324 void __kunit_test_suites_exit(struct kunit_suite **suites, int num_suites); 326 325 327 326 void kunit_exec_run_tests(struct kunit_suite_set *suite_set, bool builtin); 327 + void kunit_exec_list_tests(struct kunit_suite_set *suite_set, bool include_attr); 328 328 329 329 #if IS_BUILTIN(CONFIG_KUNIT) 330 330 int kunit_run_all_tests(void);
+17 -11
lib/kunit/executor.c
··· 13 13 extern struct kunit_suite * const __kunit_suites_start[]; 14 14 extern struct kunit_suite * const __kunit_suites_end[]; 15 15 16 + static char *action_param; 17 + 18 + module_param_named(action, action_param, charp, 0400); 19 + MODULE_PARM_DESC(action, 20 + "Changes KUnit executor behavior, valid values are:\n" 21 + "<none>: run the tests like normal\n" 22 + "'list' to list test names instead of running them.\n" 23 + "'list_attr' to list test names and attributes instead of running them.\n"); 24 + 25 + const char *kunit_action(void) 26 + { 27 + return action_param; 28 + } 29 + 16 30 #if IS_BUILTIN(CONFIG_KUNIT) 17 31 18 32 static char *filter_glob_param; 19 - static char *action_param; 20 33 static char *filter_param; 21 34 static char *filter_action_param; 22 35 23 36 module_param_named(filter_glob, filter_glob_param, charp, 0); 24 37 MODULE_PARM_DESC(filter_glob, 25 38 "Filter which KUnit test suites/tests run at boot-time, e.g. list* or list*.*del_test"); 26 - module_param_named(action, action_param, charp, 0); 27 - MODULE_PARM_DESC(action, 28 - "Changes KUnit executor behavior, valid values are:\n" 29 - "<none>: run the tests like normal\n" 30 - "'list' to list test names instead of running them.\n" 31 - "'list_attr' to list test names and attributes instead of running them.\n"); 32 39 module_param_named(filter, filter_param, charp, 0); 33 40 MODULE_PARM_DESC(filter, 34 41 "Filter which KUnit test suites/tests run at boot-time using attributes, e.g. speed>slow"); ··· 246 239 __kunit_test_suites_init(suite_set->start, num_suites); 247 240 } 248 241 249 - #if IS_BUILTIN(CONFIG_KUNIT) 250 - 251 - static void kunit_exec_list_tests(struct kunit_suite_set *suite_set, 252 - bool include_attr) 242 + void kunit_exec_list_tests(struct kunit_suite_set *suite_set, bool include_attr) 253 243 { 254 244 struct kunit_suite * const *suites; 255 245 struct kunit_case *test_case; ··· 268 264 } 269 265 } 270 266 } 267 + 268 + #if IS_BUILTIN(CONFIG_KUNIT) 271 269 272 270 int kunit_run_all_tests(void) 273 271 {
+14 -2
lib/kunit/test.c
··· 739 739 struct kunit_suite_set suite_set = { 740 740 mod->kunit_suites, mod->kunit_suites + mod->num_kunit_suites, 741 741 }; 742 + const char *action = kunit_action(); 742 743 743 - kunit_exec_run_tests(&suite_set, false); 744 + if (!action) 745 + kunit_exec_run_tests(&suite_set, false); 746 + else if (!strcmp(action, "list")) 747 + kunit_exec_list_tests(&suite_set, false); 748 + else if (!strcmp(action, "list_attr")) 749 + kunit_exec_list_tests(&suite_set, true); 750 + else 751 + pr_err("kunit: unknown action '%s'\n", action); 744 752 } 745 753 746 754 static void kunit_module_exit(struct module *mod) 747 755 { 748 - __kunit_test_suites_exit(mod->kunit_suites, mod->num_kunit_suites); 756 + const char *action = kunit_action(); 757 + 758 + if (!action) 759 + __kunit_test_suites_exit(mod->kunit_suites, 760 + mod->num_kunit_suites); 749 761 } 750 762 751 763 static int kunit_module_notify(struct notifier_block *nb, unsigned long val,