From: "Gary Guo" <gary@garyguo.net>
To: <nico.antinori.7@gmail.com>, "Alice Ryhl" <aliceryhl@google.com>,
"Burak Emir" <burak.emir@gmail.com>,
"Brendan Higgins" <brendan.higgins@linux.dev>,
"David Gow" <david@davidgow.net>,
"Miguel Ojeda" <ojeda@kernel.org>
Cc: "Alexandre Courbot" <acourbot@nvidia.com>,
"Andreas Hindborg" <a.hindborg@kernel.org>,
"Benno Lossin" <lossin@kernel.org>,
"Björn Roy Baron" <bjorn1_gh@protonmail.com>,
"Boqun Feng" <boqun@kernel.org>,
"Brigham Campbell" <me@brighamcampbell.com>,
"Daniel Almeida" <daniel.almeida@collabora.com>,
"Danilo Krummrich" <dakr@kernel.org>,
"Gary Guo" <gary@garyguo.net>,
"Jori Koolstra" <jkoolstra@xs4all.nl>,
"Onur Özkan" <work@onurozkan.dev>,
"Rae Moar" <raemoar63@gmail.com>,
"Shuah Khan" <skhan@linuxfoundation.org>,
"Tamir Duberstein" <tamird@kernel.org>,
"Trevor Gross" <tmgross@umich.edu>,
"Yury Norov" <yury.norov@gmail.com>,
linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org,
linux-kernel-mentees@lists.linux.dev
Subject: Re: [PATCH 0/3] rust: kunit: support #[should_panic] and same test name with different #[cfg(...)]
Date: Wed, 30 Sep 2026 15:54:14 +0100 [thread overview]
Message-ID: <DLSQJS2QT4JW.3BPUMU5M6N171@garyguo.net> (raw)
In-Reply-To: <20260930-rust_kunit_v4-v1-0-e3b0d45311dd@gmail.com>
On Wed Sep 30, 2026 at 2:23 PM BST, Nicolás Antinori via B4 Relay wrote:
> This patch series intends to implement two features for KUnit tests
> written in Rust. The work is based on a TODO comment made in the
> `bitmap.rs` module [1].
>
> Changelog:
> - RFC patch: [3]
>
> 1. Supporting `#[should_panic]` [2]:
>
> KUnit tests in Rust follow the user-space syntax, but at the moment
> `#[should_panic]` is not supported. The first patch of this series adds
> support for the attribute (only in its basic form, `#[should_panic =
> "message"]` is not supported yet).
>
> The way it is supported is by adding a new boolean property called
> `rust_should_panic` to `kunit_attributes` struct in kunit/test.h and
This is now more general than Rust panics? Perhaps this should just be
"should_bug"?
Best,
Gary
> check for the `try_catch->try_result` code and the named flag to detect
> if there was a panic in `lib/kunit/test.c::kunit_run_case_catch_errors`
> function.
>
> The difference with the previous version [3] is that now, almost
> everything is handled in the C side, meaning that we don't have a
> separate `#[panic_handler]` when KUnit tests are active. In other words
> there's no need of a Rust side panic handler because the C side catches
> Rust's panics too, since the `#[panic_hanlder]` executes a
> bindings::BUG().
>
> 2. Allow same test name with different #[cfg(...)]:
>
> When testing `#[should_panic]` in `bitmap.rs` (check the last patch of
> the series) I found that the test that was supposed to panic had the
> same name as another one, but they were run on different configurations.
> This caused the following compilation error:
>
> ERROR:root:error[E0428]: the name `kunit_rust_wrapper_owned_bitmap_out_of_bounds` is defined multiple times
> --> ../rust/kernel/bitmap.rs:503:1
> |
> 503 | #[macros::kunit_tests(rust_kernel_bitmap)]
> | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `kunit_rust_wrapper_owned_bitmap_out_of_bounds` redefined here
> |
> = note: `kunit_rust_wrapper_owned_bitmap_out_of_bounds` must be defined only once in the value namespace of this module
> = note: this error originates in the attribute macro `macros::kunit_tests` (in Nightly builds, run with -Z macro-backtrace for more info)
>
> Now, only the tests with an active `#[cfg(...)]` will be executed by the
> runner. Tests with an inactive `#[cfg(...)]` will not appear in the
> report since they are not added to the TEST_CASES array.
>
> [1] https://github.com/Rust-for-Linux/linux/blob/fd73f4a6659897191fa0d40695fe370925dd3780/rust/kernel/bitmap.rs#L592-L600
> [2] https://doc.rust-lang.org/rust-by-example/testing/unit_testing.html#testing-panics
> [3] https://lore.kernel.org/rust-for-linux/cover.1789500084.git.nico.antinori.7@gmail.com/
>
> Signed-off-by: Nicolás Antinori <nico.antinori.7@gmail.com>
> ---
> Nicolás Antinori (3):
> rust: kunit: add #[should_panic] support
> rust: kunit: allow same test name with different #[cfg(...)]
> rust: bitmap: kunit: uncomment owned_bitmap_out_of_bounds panic case
>
> include/kunit/test.h | 1 +
> lib/kunit/attributes.c | 18 ++++++++++++++++++
> lib/kunit/test.c | 5 +++++
> rust/kernel/bitmap.rs | 40 ++++++++++++++++++----------------------
> rust/kernel/kunit.rs | 37 +++++++++++++++++++++++++++++++++++++
> rust/macros/kunit.rs | 48 ++++++++++++++++++++++++++++++++++++++----------
> 6 files changed, 117 insertions(+), 32 deletions(-)
> ---
> base-commit: d266640c6c760c9bc215bf5a3ece122ca488b6f5
> change-id: 20260930-rust_kunit_v4-7abaee11e6ac
>
> Best regards,
next prev parent reply other threads:[~2026-09-30 14:54 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-30 13:23 Nicolás Antinori via B4 Relay
2026-09-30 13:23 ` [PATCH 1/3] rust: kunit: add #[should_panic] support Nicolás Antinori via B4 Relay
2026-09-30 13:23 ` [PATCH 2/3] rust: kunit: allow same test name with different #[cfg(...)] Nicolás Antinori via B4 Relay
2026-09-30 13:23 ` [PATCH 3/3] rust: bitmap: kunit: uncomment owned_bitmap_out_of_bounds panic case Nicolás Antinori via B4 Relay
2026-09-30 14:41 ` [PATCH 0/3] rust: kunit: support #[should_panic] and same test name with different #[cfg(...)] Miguel Ojeda
2026-10-01 13:43 ` Nicolás Antinori
2026-09-30 14:54 ` Gary Guo [this message]
2026-10-01 14:08 ` Nicolás Antinori
-- strict thread matches above, loose matches on Subject: below --
2026-09-29 14:07 Nicolás Antinori
2026-09-29 16:02 ` Nicolás Antinori
2026-09-29 16:22 ` Miguel Ojeda
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=DLSQJS2QT4JW.3BPUMU5M6N171@garyguo.net \
--to=gary@garyguo.net \
--cc=a.hindborg@kernel.org \
--cc=acourbot@nvidia.com \
--cc=aliceryhl@google.com \
--cc=bjorn1_gh@protonmail.com \
--cc=boqun@kernel.org \
--cc=brendan.higgins@linux.dev \
--cc=burak.emir@gmail.com \
--cc=dakr@kernel.org \
--cc=daniel.almeida@collabora.com \
--cc=david@davidgow.net \
--cc=jkoolstra@xs4all.nl \
--cc=linux-kernel-mentees@lists.linux.dev \
--cc=linux-kernel@vger.kernel.org \
--cc=lossin@kernel.org \
--cc=me@brighamcampbell.com \
--cc=nico.antinori.7@gmail.com \
--cc=ojeda@kernel.org \
--cc=raemoar63@gmail.com \
--cc=rust-for-linux@vger.kernel.org \
--cc=skhan@linuxfoundation.org \
--cc=tamird@kernel.org \
--cc=tmgross@umich.edu \
--cc=work@onurozkan.dev \
--cc=yury.norov@gmail.com \
/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
all inboxes | Powered by JetHome®