Re: [PATCH v3 1/3] rust: kunit: add #[should_panic] support

From: Nicolás Antinori

Date: Thu Nov 26 2026 - 10:16:35 EST


On Mon Nov 23, 2026 at 10:36 AM -03, David Gow wrote:
> Le 14/11/2026 à 02:20, 'Nicolás Antinori via B4 Relay' via KUnit
> Development a écrit :
>> From: Nicolás Antinori <nico.antinori.7@xxxxxxxxx>
>>
>> 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@xxxxxxxxx>
>> ---
>
> Okay -- this looks good to go to me. Thanks very much for all of your
> effort!

Thank you for the reviews and explanations! I'll be sending the
implementation for `#[should_panic = "message"]` once this lands.

There's a sashiko observation [1] but I dismissed it because before this
patch `KUNIT_ASSERT_NOT_ERR_OR_NULL` already aborted before setting
`priv` and executing `kunit_init_test` and `kunit_resource_test_exit`
performed the frees without any check. I assume that this is acceptable
in this context, but let me know otherwise!

> I'm not 100% happy with how pushing the attributes into struct kunit has
> balooned into all of the different kunit_init_test() call, but I think
> all of the other options are either worse, or involve even more invasive
> refactoring. (That being said, I do think this might be the thing which
> finally makes me look into refactoring how we handle the struct kunit /
> struct kunit_case dichotomy better... :-))

Yes, this was tricky! The alternative I thought was setting attrs
directly when declaring `struct kunit ...` (right before the two calls
of `kunit_init_test` in `test.c`) but I was not sure if it was the right
place (we would have avoided passing the attrs in all the calls if I am
not mistaken though).

Regards,
Nicolás

[1] https://sashiko.dev/#/patchset/20261113-rust_kunit_v6_send-v3-0-0d7832c07166@xxxxxxxxx?part=1