2019-04-05 09:58:56 +08:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0+ */
|
|
|
|
#ifndef __KSELFTEST_MODULE_H
|
|
|
|
#define __KSELFTEST_MODULE_H
|
|
|
|
|
|
|
|
#include <linux/module.h>
|
selftest: Taint kernel when test module loaded
Make any kselftest test module (using the kselftest_module framework)
taint the kernel with TAINT_TEST on module load.
Also mark the module as a test module using MODULE_INFO(test, "Y") so
that other tools can tell this is a test module. We can't rely solely
on this, though, as these test modules are also often built-in.
Finally, update the kselftest documentation to mention that the kernel
should be tainted, and how to do so manually (as below).
Note that several selftests use kernel modules which are not based on
the kselftest_module framework, and so will not automatically taint the
kernel.
This can be done in two ways:
- Moving the module to the tools/testing directory. All modules under
this directory will taint the kernel.
- Adding the 'test' module property with:
MODULE_INFO(test, "Y")
Similarly, selftests which do not load modules into the kernel generally
should not taint the kernel (or possibly should only do so on failure),
as it's assumed that testing from user-space should be safe. Regardless,
they can write to /proc/sys/kernel/tainted if required.
Reviewed-by: Luis Chamberlain <mcgrof@kernel.org>
Acked-by: Brendan Higgins <brendanhiggins@google.com>
Signed-off-by: David Gow <davidgow@google.com>
Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
2022-07-08 12:48:47 +08:00
|
|
|
#include <linux/panic.h>
|
2019-04-05 09:58:56 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Test framework for writing test modules to be loaded by kselftest.
|
|
|
|
* See Documentation/dev-tools/kselftest.rst for an example test module.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define KSTM_MODULE_GLOBALS() \
|
|
|
|
static unsigned int total_tests __initdata; \
|
2021-02-15 00:13:47 +08:00
|
|
|
static unsigned int failed_tests __initdata; \
|
|
|
|
static unsigned int skipped_tests __initdata
|
2019-04-05 09:58:56 +08:00
|
|
|
|
|
|
|
#define KSTM_CHECK_ZERO(x) do { \
|
|
|
|
total_tests++; \
|
|
|
|
if (x) { \
|
|
|
|
pr_warn("TC failed at %s:%d\n", __func__, __LINE__); \
|
|
|
|
failed_tests++; \
|
|
|
|
} \
|
|
|
|
} while (0)
|
|
|
|
|
2021-02-15 00:13:47 +08:00
|
|
|
static inline int kstm_report(unsigned int total_tests, unsigned int failed_tests,
|
|
|
|
unsigned int skipped_tests)
|
2019-04-05 09:58:56 +08:00
|
|
|
{
|
2021-02-15 00:13:47 +08:00
|
|
|
if (failed_tests == 0) {
|
|
|
|
if (skipped_tests) {
|
|
|
|
pr_info("skipped %u tests\n", skipped_tests);
|
|
|
|
pr_info("remaining %u tests passed\n", total_tests);
|
|
|
|
} else
|
|
|
|
pr_info("all %u tests passed\n", total_tests);
|
|
|
|
} else
|
2019-04-05 09:58:56 +08:00
|
|
|
pr_warn("failed %u out of %u tests\n", failed_tests, total_tests);
|
|
|
|
|
|
|
|
return failed_tests ? -EINVAL : 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define KSTM_MODULE_LOADERS(__module) \
|
|
|
|
static int __init __module##_init(void) \
|
|
|
|
{ \
|
|
|
|
pr_info("loaded.\n"); \
|
selftest: Taint kernel when test module loaded
Make any kselftest test module (using the kselftest_module framework)
taint the kernel with TAINT_TEST on module load.
Also mark the module as a test module using MODULE_INFO(test, "Y") so
that other tools can tell this is a test module. We can't rely solely
on this, though, as these test modules are also often built-in.
Finally, update the kselftest documentation to mention that the kernel
should be tainted, and how to do so manually (as below).
Note that several selftests use kernel modules which are not based on
the kselftest_module framework, and so will not automatically taint the
kernel.
This can be done in two ways:
- Moving the module to the tools/testing directory. All modules under
this directory will taint the kernel.
- Adding the 'test' module property with:
MODULE_INFO(test, "Y")
Similarly, selftests which do not load modules into the kernel generally
should not taint the kernel (or possibly should only do so on failure),
as it's assumed that testing from user-space should be safe. Regardless,
they can write to /proc/sys/kernel/tainted if required.
Reviewed-by: Luis Chamberlain <mcgrof@kernel.org>
Acked-by: Brendan Higgins <brendanhiggins@google.com>
Signed-off-by: David Gow <davidgow@google.com>
Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
2022-07-08 12:48:47 +08:00
|
|
|
add_taint(TAINT_TEST, LOCKDEP_STILL_OK); \
|
2019-04-05 09:58:56 +08:00
|
|
|
selftest(); \
|
2021-02-15 00:13:47 +08:00
|
|
|
return kstm_report(total_tests, failed_tests, skipped_tests); \
|
2019-04-05 09:58:56 +08:00
|
|
|
} \
|
|
|
|
static void __exit __module##_exit(void) \
|
|
|
|
{ \
|
|
|
|
pr_info("unloaded.\n"); \
|
|
|
|
} \
|
|
|
|
module_init(__module##_init); \
|
|
|
|
module_exit(__module##_exit)
|
|
|
|
|
selftest: Taint kernel when test module loaded
Make any kselftest test module (using the kselftest_module framework)
taint the kernel with TAINT_TEST on module load.
Also mark the module as a test module using MODULE_INFO(test, "Y") so
that other tools can tell this is a test module. We can't rely solely
on this, though, as these test modules are also often built-in.
Finally, update the kselftest documentation to mention that the kernel
should be tainted, and how to do so manually (as below).
Note that several selftests use kernel modules which are not based on
the kselftest_module framework, and so will not automatically taint the
kernel.
This can be done in two ways:
- Moving the module to the tools/testing directory. All modules under
this directory will taint the kernel.
- Adding the 'test' module property with:
MODULE_INFO(test, "Y")
Similarly, selftests which do not load modules into the kernel generally
should not taint the kernel (or possibly should only do so on failure),
as it's assumed that testing from user-space should be safe. Regardless,
they can write to /proc/sys/kernel/tainted if required.
Reviewed-by: Luis Chamberlain <mcgrof@kernel.org>
Acked-by: Brendan Higgins <brendanhiggins@google.com>
Signed-off-by: David Gow <davidgow@google.com>
Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
2022-07-08 12:48:47 +08:00
|
|
|
MODULE_INFO(test, "Y");
|
|
|
|
|
2019-04-05 09:58:56 +08:00
|
|
|
#endif /* __KSELFTEST_MODULE_H */
|