summaryrefslogtreecommitdiff
path: root/rust/kernel
diff options
context:
space:
mode:
authorKaibo Ma <ent3rm4n@gmail.com>2025-09-15 22:12:56 -0400
committerShuah Khan <skhan@linuxfoundation.org>2025-09-16 08:26:56 -0600
commitc652dc44192d96820d73a7ecd89d275ca7e4355d (patch)
tree2d657c7ed5780633c67eccbcc43f0578d8ba0d79 /rust/kernel
parentf20e264262f1e6a6e5302249e37da355d844b52b (diff)
rust: kunit: allow `cfg` on `test`s
The `kunit_test` proc macro only checks for the `test` attribute immediately preceding a `fn`. If the function is disabled via a `cfg`, the generated code would result in a compile error referencing a non-existent function [1]. This collects attributes and specifically cherry-picks `cfg` attributes to be duplicated inside KUnit wrapper functions such that a test function disabled via `cfg` compiles and is marked as skipped in KUnit correctly. Link: https://lore.kernel.org/r/20250916021259.115578-1-ent3rm4n@gmail.com Link: https://lore.kernel.org/rust-for-linux/CANiq72==48=69hYiDo1321pCzgn_n1_jg=ez5UYXX91c+g5JVQ@mail.gmail.com/ [1] Closes: https://github.com/Rust-for-Linux/linux/issues/1185 Suggested-by: Miguel Ojeda <ojeda@kernel.org> Suggested-by: David Gow <davidgow@google.com> Signed-off-by: Kaibo Ma <ent3rm4n@gmail.com> Reviewed-by: David Gow <davidgow@google.com> Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
Diffstat (limited to 'rust/kernel')
-rw-r--r--rust/kernel/kunit.rs7
1 files changed, 7 insertions, 0 deletions
diff --git a/rust/kernel/kunit.rs b/rust/kernel/kunit.rs
index b1c97f8029c7..8a1e1b222ac8 100644
--- a/rust/kernel/kunit.rs
+++ b/rust/kernel/kunit.rs
@@ -361,4 +361,11 @@ mod tests {
fn rust_test_kunit_in_kunit_test() {
assert!(in_kunit_test());
}
+
+ #[test]
+ #[cfg(not(all()))]
+ fn rust_test_kunit_always_disabled_test() {
+ // This test should never run because of the `cfg`.
+ assert!(false);
+ }
}