Skip to content

Commit 4b513a0

Browse files
sulixshuahkh
authored andcommitted
kunit: test: Move fault tests behind KUNIT_FAULT_TEST Kconfig option
The NULL dereference tests in kunit_fault deliberately trigger a kernel BUG(), and therefore print the associated stack trace, even when the test passes. This is both annoying (as it bloats the test output), and can confuse some test harnesses, which assume any BUG() is a failure. Allow these tests to be specifically disabled (without disabling all of KUnit's other tests), by placing them behind the CONFIG_KUNIT_FAULT_TEST Kconfig option. This is enabled by default, but can be set to 'n' to disable the test. An empty 'kunit_fault' suite is left behind, which will automatically be marked 'skipped'. As the fault tests already were disabled under UML (as they weren't compatible with its fault handling), we can simply adapt those conditions, and add a dependency on !UML for our new option. Suggested-by: Guenter Roeck <linux@roeck-us.net> Link: https://lore.kernel.org/all/928249cc-e027-4f7f-b43f-502f99a1ea63@roeck-us.net/ Fixes: 82b0bef ("kunit: Add tests for fault") Signed-off-by: David Gow <davidgow@google.com> Reviewed-by: Mickaël Salaün <mic@digikod.net> Reviewed-by: Rae Moar <rmoar@google.com> Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
1 parent fabd480 commit 4b513a0

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

lib/kunit/Kconfig

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,17 @@ config KUNIT_DEBUGFS
2424
test suite, which allow users to see results of the last test suite
2525
run that occurred.
2626

27+
config KUNIT_FAULT_TEST
28+
bool "Enable KUnit tests which print BUG stacktraces"
29+
depends on KUNIT_TEST
30+
depends on !UML
31+
default y
32+
help
33+
Enables fault handling tests for the KUnit framework. These tests may
34+
trigger a kernel BUG(), and the associated stack trace, even when they
35+
pass. If this conflicts with your test infrastrcture (or is confusing
36+
or annoying), they can be disabled by setting this to N.
37+
2738
config KUNIT_TEST
2839
tristate "KUnit test for KUnit" if !KUNIT_ALL_TESTS
2940
default KUNIT_ALL_TESTS

lib/kunit/kunit-test.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ static struct kunit_suite kunit_try_catch_test_suite = {
109109
.test_cases = kunit_try_catch_test_cases,
110110
};
111111

112-
#ifndef CONFIG_UML
112+
#if IS_ENABLED(CONFIG_KUNIT_FAULT_TEST)
113113

114114
static void kunit_test_null_dereference(void *data)
115115
{
@@ -136,12 +136,12 @@ static void kunit_test_fault_null_dereference(struct kunit *test)
136136
KUNIT_EXPECT_TRUE(test, ctx->function_called);
137137
}
138138

139-
#endif /* !CONFIG_UML */
139+
#endif /* CONFIG_KUNIT_FAULT_TEST */
140140

141141
static struct kunit_case kunit_fault_test_cases[] = {
142-
#ifndef CONFIG_UML
142+
#if IS_ENABLED(CONFIG_KUNIT_FAULT_TEST)
143143
KUNIT_CASE(kunit_test_fault_null_dereference),
144-
#endif /* !CONFIG_UML */
144+
#endif /* CONFIG_KUNIT_FAULT_TEST */
145145
{}
146146
};
147147

0 commit comments

Comments
 (0)