Skip to content

Commit 18258c6

Browse files
jkrzyszt-intelshuahkh
authored andcommitted
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 <[email protected]> Cc: Rae Moar <[email protected]> Reviewed-by: David Gow <[email protected]> Signed-off-by: Shuah Khan <[email protected]>
1 parent c95e7c0 commit 18258c6

File tree

3 files changed

+34
-14
lines changed

3 files changed

+34
-14
lines changed

include/kunit/test.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,7 @@ static inline void kunit_set_failure(struct kunit *test)
309309
}
310310

311311
bool kunit_enabled(void);
312+
const char *kunit_action(void);
312313

313314
void kunit_init_test(struct kunit *test, const char *name, char *log);
314315

@@ -324,6 +325,7 @@ int __kunit_test_suites_init(struct kunit_suite * const * const suites, int num_
324325
void __kunit_test_suites_exit(struct kunit_suite **suites, int num_suites);
325326

326327
void kunit_exec_run_tests(struct kunit_suite_set *suite_set, bool builtin);
328+
void kunit_exec_list_tests(struct kunit_suite_set *suite_set, bool include_attr);
327329

328330
#if IS_BUILTIN(CONFIG_KUNIT)
329331
int kunit_run_all_tests(void);

lib/kunit/executor.c

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,22 +13,29 @@
1313
extern struct kunit_suite * const __kunit_suites_start[];
1414
extern struct kunit_suite * const __kunit_suites_end[];
1515

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+
1630
#if IS_BUILTIN(CONFIG_KUNIT)
1731

1832
static char *filter_glob_param;
19-
static char *action_param;
2033
static char *filter_param;
2134
static char *filter_action_param;
2235

2336
module_param_named(filter_glob, filter_glob_param, charp, 0);
2437
MODULE_PARM_DESC(filter_glob,
2538
"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");
3239
module_param_named(filter, filter_param, charp, 0);
3340
MODULE_PARM_DESC(filter,
3441
"Filter which KUnit test suites/tests run at boot-time using attributes, e.g. speed>slow");
@@ -239,10 +246,7 @@ void kunit_exec_run_tests(struct kunit_suite_set *suite_set, bool builtin)
239246
__kunit_test_suites_init(suite_set->start, num_suites);
240247
}
241248

242-
#if IS_BUILTIN(CONFIG_KUNIT)
243-
244-
static void kunit_exec_list_tests(struct kunit_suite_set *suite_set,
245-
bool include_attr)
249+
void kunit_exec_list_tests(struct kunit_suite_set *suite_set, bool include_attr)
246250
{
247251
struct kunit_suite * const *suites;
248252
struct kunit_case *test_case;
@@ -265,6 +269,8 @@ static void kunit_exec_list_tests(struct kunit_suite_set *suite_set,
265269
}
266270
}
267271

272+
#if IS_BUILTIN(CONFIG_KUNIT)
273+
268274
int kunit_run_all_tests(void)
269275
{
270276
struct kunit_suite_set suite_set = {

lib/kunit/test.c

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -739,13 +739,25 @@ static void kunit_module_init(struct module *mod)
739739
struct kunit_suite_set suite_set = {
740740
mod->kunit_suites, mod->kunit_suites + mod->num_kunit_suites,
741741
};
742-
743-
kunit_exec_run_tests(&suite_set, false);
742+
const char *action = kunit_action();
743+
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);
744752
}
745753

746754
static void kunit_module_exit(struct module *mod)
747755
{
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);
749761
}
750762

751763
static int kunit_module_notify(struct notifier_block *nb, unsigned long val,

0 commit comments

Comments
 (0)