From: Malte Wechter <maltewechter@gmail.com>
To: "Brendan Higgins" <brendan.higgins@linux.dev>,
"David Gow" <david@davidgow.net>,
"Rae Moar" <raemoar63@gmail.com>,
"Miguel Ojeda" <ojeda@kernel.org>,
"Boqun Feng" <boqun@kernel.org>, "Gary Guo" <gary@garyguo.net>,
"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
"Benno Lossin" <lossin@kernel.org>,
"Andreas Hindborg" <a.hindborg@kernel.org>,
"Alice Ryhl" <aliceryhl@google.com>,
"Trevor Gross" <tmgross@umich.edu>,
"Danilo Krummrich" <dakr@kernel.org>,
"Daniel Almeida" <daniel.almeida@collabora.com>,
"Tamir Duberstein" <tamird@kernel.org>,
"Alexandre Courbot" <acourbot@nvidia.com>,
"Onur Özkan" <work@onurozkan.dev>,
"Jonathan Corbet" <corbet@lwn.net>,
"Shuah Khan" <skhan@linuxfoundation.org>,
"Randy Dunlap" <rdunlap@infradead.org>
Cc: linux-kselftest@vger.kernel.org, kunit-dev@googlegroups.com,
linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org,
workflows@vger.kernel.org, linux-doc@vger.kernel.org,
Malte Wechter <maltewechter@gmail.com>
Subject: [PATCH v3 3/4] kunit: add assertions for TAINT_WARN inside of kunit
Date: Tue, 13 Oct 2026 12:22:23 +0200 [thread overview]
Message-ID: <20261013-lockdep-kunit-v3-3-cdb8ff720c1f@gmail.com> (raw)
In-Reply-To: <20261013-lockdep-kunit-v3-0-cdb8ff720c1f@gmail.com>
Assert that the kernel is not tainted with `TAINT_WARN` prior to running
a KUnit test case, and assert that it has not become tainted with
`TAINT_WARN` while the test has run. If this is not enabled,
writing and running KUnit test cases that trigger a `WARN()` does not
fail the test if the test itself passes. If enabled, it marks any test
that triggers a warning as failed, and forcefully skips all proceeding
test cases, since the taint cannot be cleared and the kernel is now seen
as unreliable.
The assertions are gated behind `CONFIG_KUNIT_FAIL_TEST_ON_WARN=y`
Signed-off-by: Malte Wechter <maltewechter@gmail.com>
---
lib/kunit/test.c | 27 +++++++++++++++++++++++++++
1 file changed, 27 insertions(+)
diff --git a/lib/kunit/test.c b/lib/kunit/test.c
index 1292a0799c33..6d6f1e947db5 100644
--- a/lib/kunit/test.c
+++ b/lib/kunit/test.c
@@ -81,6 +81,30 @@ void __printf(3, 4) __kunit_fail_current_test_impl(const char *file, int line, c
kunit_kfree(current->kunit_test, buffer);
}
+/*
+ * Fails current test if TAINT_WARN has been set (changed) after the test has run.
+ */
+static void kunit_check_taint_warn(struct kunit *test, unsigned long tainted_before)
+{
+ if (IS_ENABLED(CONFIG_KUNIT_FAIL_TEST_ON_WARN) &&
+ test_taint(TAINT_WARN) && !tainted_before) {
+ kunit_err(test, "Test triggered a kernel WARN");
+ kunit_set_failure(test);
+ }
+}
+
+/*
+ * Skip a KUnit test if the kernel is tainted with TAINT_WARN.
+ */
+static void kunit_skip_if_taint_warn(struct kunit *test, struct kunit_suite *suite)
+{
+ if (IS_ENABLED(CONFIG_KUNIT_FAIL_TEST_ON_WARN) && test_taint(TAINT_WARN)) {
+ suite->forced_skip = true;
+ test->forced_skip = true;
+ kunit_skip(test, "force skip: kernel is tainted with TAINT_WARN");
+ }
+}
+
/*
* Fails current test if test turns off debug_locks.
*/
@@ -487,6 +511,7 @@ static void kunit_run_case_internal(struct kunit *test,
struct timespec64 start, end;
kunit_skip_if_lockdep(test, suite);
+ kunit_skip_if_taint_warn(test, suite);
if (suite->init) {
int ret;
@@ -539,6 +564,7 @@ static void kunit_try_run_case(void *data)
struct kunit_suite *suite = ctx->suite;
struct kunit_case *test_case = ctx->test_case;
int debug_locks_snapshot = debug_locks;
+ unsigned long tainted_warn_snapshot = test_taint(TAINT_WARN);
current->kunit_test = test;
@@ -549,6 +575,7 @@ static void kunit_try_run_case(void *data)
*/
kunit_run_case_internal(test, suite, test_case);
+ kunit_check_taint_warn(test, tainted_warn_snapshot);
kunit_check_lockdep(test, debug_locks_snapshot);
}
--
2.54.0
next prev parent reply other threads:[~2026-10-13 10:22 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-13 10:22 [PATCH v3 0/4] kunit: add optional assertions to catch taint and lockdep warnings Malte Wechter
2026-10-13 10:22 ` [PATCH v3 1/4] kunit: add logic for tracking forcefully skipped test cases/suites Malte Wechter
2026-10-13 10:22 ` [PATCH v3 2/4] kunit: add assertions for lockdep inside of kunit Malte Wechter
2026-10-13 10:22 ` Malte Wechter [this message]
2026-10-13 10:22 ` [PATCH v3 4/4] Documentation: kunit: add documentation and examples to kunit documentation Malte Wechter
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261013-lockdep-kunit-v3-3-cdb8ff720c1f@gmail.com \
--to=maltewechter@gmail.com \
--cc=a.hindborg@kernel.org \
--cc=acourbot@nvidia.com \
--cc=aliceryhl@google.com \
--cc=bjorn3_gh@protonmail.com \
--cc=boqun@kernel.org \
--cc=brendan.higgins@linux.dev \
--cc=corbet@lwn.net \
--cc=dakr@kernel.org \
--cc=daniel.almeida@collabora.com \
--cc=david@davidgow.net \
--cc=gary@garyguo.net \
--cc=kunit-dev@googlegroups.com \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=lossin@kernel.org \
--cc=ojeda@kernel.org \
--cc=raemoar63@gmail.com \
--cc=rdunlap@infradead.org \
--cc=rust-for-linux@vger.kernel.org \
--cc=skhan@linuxfoundation.org \
--cc=tamird@kernel.org \
--cc=tmgross@umich.edu \
--cc=work@onurozkan.dev \
--cc=workflows@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox