From: David Gow <david@davidgow.net>
To: "Nicolás Antinori" <nico.antinori.7@gmail.com>,
"Alice Ryhl" <aliceryhl@google.com>,
"Benno Lossin" <lossin@kernel.org>,
"Boqun Feng" <boqun@kernel.org>,
"Brendan Higgins" <brendan.higgins@linux.dev>,
"Daniel Almeida" <daniel.almeida@collabora.com>,
"Danilo Krummrich" <dakr@kernel.org>,
"Gary Guo" <gary@garyguo.net>, "Miguel Ojeda" <ojeda@kernel.org>,
"Onur Özkan" <work@onurozkan.dev>
Cc: "Alexandre Courbot" <acourbot@nvidia.com>,
"Andreas Hindborg" <a.hindborg@kernel.org>,
"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
"Burak Emir" <burak.emir@gmail.com>,
"Rae Moar" <raemoar63@gmail.com>,
"Tamir Duberstein" <tamird@kernel.org>,
"Trevor Gross" <tmgross@umich.edu>,
"Yury Norov" <yury.norov@gmail.com>,
kunit-dev@googlegroups.com, linux-kernel@vger.kernel.org,
linux-kselftest@vger.kernel.org, rust-for-linux@vger.kernel.org
Subject: Re: [PATCH v2 1/3] rust: kunit: add #[should_panic] support
Date: Tue, 3 Nov 2026 23:00:15 +0800 [thread overview]
Message-ID: <a60d2cf6-e44f-4fb4-be03-bb21e6d1ac85@davidgow.net> (raw)
In-Reply-To: <DMKTARY7GF4B.27HUM6XMDTQNV@gmail.com>
Le 02/11/2026 à 22:58, Nicolás Antinori a écrit :
> On Thu Oct 29, 2026 at 1:59 PM -03, Nicolás Antinori via B4 Relay wrote:
>> From: Nicolás Antinori <nico.antinori.7@gmail.com>
>>
>> KUnit tests in Rust are written using user-space like syntax. This patch
>> adds support for the `#[should_panic]` attribute, enabling the user to
>> test conditions that are expected to cause a panic and report the test
>> as successful.
>>
>> Signed-off-by: Nicolás Antinori <nico.antinori.7@gmail.com>
>
> Hello, Sashiko found two issues [1] with this patch:
>
>> [Severity: High]
>> Will these new selftests crash the kernel or hang when
>> CONFIG_RUST_KUNIT_SELFTEST is enabled under CONFIG_UML=y,
>> CONFIG_PANIC_ON_OOPS=y, or CONFIG_BUG=n?
>
> This is true, I tested this with:
>
> ./tools/testing/kunit/kunit.py run \
> --make_options LLVM=1 \
> --kconfig_add CONFIG_RUST=y \
> --kconfig_add CONFIG_RUST_KUNIT_TESTS=y \
> --kconfig_add CONFIG_KUNIT=y \
> --kconfig_add CONFIG_UML=y \
> --arch=um rust_kernel_kunit
>
> ./tools/testing/kunit/kunit.py run \
> --make_options LLVM=1 \
> --kconfig_add CONFIG_RUST=y \
> --kconfig_add CONFIG_RUST_KUNIT_TESTS=y \
> --kconfig_add CONFIG_KUNIT=y \
> --kconfig_add CONFIG_PANIC_ON_OOPS=y \
> --arch=x86_64 rust_kernel_kunit
>
> And some other configs using the configs causing problems.
>
> To solve this I created a new config "RUST_KUNIT_SHOULD_PANIC_ATTRIBUTE"
> that depends on !UML && !PANIC_ON_OOPS && BUG. If the test is annotated
> with `#[should_panic]` and CONFIG_RUST_KUNIT_SHOULD_PANIC_ATTRIBUTE=n,
> the test won't run and won't show up in the summary.
>
This is failing on UML for me, too. I'd rather have an implementation
which worked on UML (such as a panic_handler), rather than trying to
intercept BUG().
If you do want to add a new config option, I'd probably call it
something like HAVE_KUNIT_RUST_SHOULD_PANIC, and set it in the
architecture configs, but piggy-backing on the existing
CONFIG_KUNIT_FAULT_TEST is probably best. And if we do want to support
non-Rust panics, then this probably shouldn't be a rust-specific option.
The RFC's panic_handler-based implementation worked fine for me on UML,
so I'd stick with that.
And, of course, UML isn't the only architecture that can't handle faults
(though it might be the only one Rust supports at the moment). e.g.,
SPARC also would fail here.
>> [Severity: Medium]
>> Does defining macro_rules! assert and macro_rules! assert_eq at module scope
>> in kunit_tests() leak the preceding test's #should_panic value into helper
>> functions or impl blocks defined later in the module?
>
> This is also true, the solution was redefining the `assert!` and
> `assert_eq!` macros inside the function's body (as Sashiko suggested).
>
> I'll wait a bit in case there are any feedback on the current series and
> send a v3 with these changes.
>
As mentioned, I'm not a big fan of including should_panic in the
assert!() macros, so if we can just do away with that, this should no
longer be a problem.
> Best Regards,
> Nicolás
>
> [1] https://sashiko.dev/#/patchset/20261029-rust_kunit_v6_send-v2-0-5ce551efc48e@gmail.com?part=1
Cheers,
-- David
next prev parent reply other threads:[~2026-11-03 15:00 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-29 16:59 [PATCH v2 0/3] rust: kunit: support #[should_panic] and same test name with different #[cfg(...)] Nicolás Antinori via B4 Relay
2026-10-29 16:59 ` [PATCH v2 1/3] rust: kunit: add #[should_panic] support Nicolás Antinori via B4 Relay
2026-11-02 14:58 ` Nicolás Antinori
2026-11-02 15:51 ` Miguel Ojeda
2026-11-02 20:53 ` Nicolás Antinori
2026-11-02 21:25 ` Miguel Ojeda
2026-11-03 15:05 ` David Gow
2026-11-03 15:00 ` David Gow [this message]
2026-11-03 14:46 ` David Gow
2026-11-03 16:32 ` Miguel Ojeda
2026-10-29 16:59 ` [PATCH v2 2/3] rust: kunit: allow same test name with different #[cfg(...)] Nicolás Antinori via B4 Relay
2026-11-03 14:45 ` David Gow
2026-10-29 16:59 ` [PATCH v2 3/3] rust: bitmap: kunit: uncomment owned_bitmap_out_of_bounds panic case Nicolás Antinori via B4 Relay
2026-11-03 14:46 ` David Gow
2026-11-03 14:45 ` [PATCH v2 0/3] rust: kunit: support #[should_panic] and same test name with different #[cfg(...)] David Gow
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=a60d2cf6-e44f-4fb4-be03-bb21e6d1ac85@davidgow.net \
--to=david@davidgow.net \
--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=burak.emir@gmail.com \
--cc=dakr@kernel.org \
--cc=daniel.almeida@collabora.com \
--cc=gary@garyguo.net \
--cc=kunit-dev@googlegroups.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=lossin@kernel.org \
--cc=nico.antinori.7@gmail.com \
--cc=ojeda@kernel.org \
--cc=raemoar63@gmail.com \
--cc=rust-for-linux@vger.kernel.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®