From c652dc44192d96820d73a7ecd89d275ca7e4355d Mon Sep 17 00:00:00 2001 From: Kaibo Ma Date: Mon, 15 Sep 2025 22:12:56 -0400 Subject: 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 Suggested-by: David Gow Signed-off-by: Kaibo Ma Reviewed-by: David Gow Signed-off-by: Shuah Khan --- rust/kernel/kunit.rs | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'rust/kernel') 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); + } } -- cgit