]> git.ipfire.org Git - thirdparty/kernel/stable.git/commit
rust: kunit: allow `cfg` on `test`s
authorKaibo Ma <ent3rm4n@gmail.com>
Tue, 16 Sep 2025 02:12:56 +0000 (22:12 -0400)
committerShuah Khan <skhan@linuxfoundation.org>
Tue, 16 Sep 2025 14:26:56 +0000 (08:26 -0600)
commitc652dc44192d96820d73a7ecd89d275ca7e4355d
tree2d657c7ed5780633c67eccbcc43f0578d8ba0d79
parentf20e264262f1e6a6e5302249e37da355d844b52b
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/
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>
rust/kernel/kunit.rs
rust/macros/kunit.rs