summaryrefslogtreecommitdiff
path: root/lib/kunit/test.c
diff options
context:
space:
mode:
authorJanusz Krzysztofik <janusz.krzysztofik@linux.intel.com>2023-08-07 12:23:56 +0200
committerShuah Khan <skhan@linuxfoundation.org>2023-08-08 13:46:18 -0600
commitb67abaad4d25b5d9364a1d4f6bc18286ebaaa013 (patch)
tree93c43de64c607f2498b79582979b332eab4ebf67 /lib/kunit/test.c
parent18258c60f8a74b9c39b593d118f13f3265d44cd6 (diff)
kunit: Allow kunit test modules to use test filtering
External tools, e.g., Intel GPU tools (IGT), support execution of individual selftests provided by kernel modules. That could be also applicable to kunit test modules if they provided test filtering. But test filtering is now possible only when kunit code is built into the kernel. Moreover, a filter can be specified only at boot time, then reboot is required each time a different filter is needed. Build the test filtering code also when kunit is configured as a module, expose test filtering functions to other kunit source files, and use them in kunit module notifier callback functions. Userspace can then reload the kunit module with a value of the filter_glob parameter tuned to a specific kunit test module every time it wants to limit the scope of tests executed on that module load. Make the kunit.filter* parameters visible in sysfs for user convenience. v5: Refresh on tpp of attributes filtering fix v4: Refresh on top of newly applied attributes patches and changes introdced by new versions of other patches submitted in series with this one. v3: Fix CONFIG_GLOB, required by filtering functions, not selected when building as a module (lkp@intel.com). v2: Fix new name of a structure moved to kunit namespace not updated across all uses (lkp@intel.com). Signed-off-by: Janusz Krzysztofik <janusz.krzysztofik@linux.intel.com> Reviewed-by: David Gow <davidgow@google.com> Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
Diffstat (limited to 'lib/kunit/test.c')
-rw-r--r--lib/kunit/test.c17
1 files changed, 17 insertions, 0 deletions
diff --git a/lib/kunit/test.c b/lib/kunit/test.c
index 5232a4373782..49698a168437 100644
--- a/lib/kunit/test.c
+++ b/lib/kunit/test.c
@@ -740,6 +740,17 @@ static void kunit_module_init(struct module *mod)
mod->kunit_suites, mod->kunit_suites + mod->num_kunit_suites,
};
const char *action = kunit_action();
+ int err = 0;
+
+ suite_set = kunit_filter_suites(&suite_set,
+ kunit_filter_glob() ?: "*.*",
+ kunit_filter(), kunit_filter_action(),
+ &err);
+ if (err)
+ pr_err("kunit module: error filtering suites: %d\n", err);
+
+ mod->kunit_suites = (struct kunit_suite **)suite_set.start;
+ mod->num_kunit_suites = suite_set.end - suite_set.start;
if (!action)
kunit_exec_run_tests(&suite_set, false);
@@ -753,11 +764,17 @@ static void kunit_module_init(struct module *mod)
static void kunit_module_exit(struct module *mod)
{
+ struct kunit_suite_set suite_set = {
+ mod->kunit_suites, mod->kunit_suites + mod->num_kunit_suites,
+ };
const char *action = kunit_action();
if (!action)
__kunit_test_suites_exit(mod->kunit_suites,
mod->num_kunit_suites);
+
+ if (suite_set.start)
+ kunit_free_suite_set(suite_set);
}
static int kunit_module_notify(struct notifier_block *nb, unsigned long val,