From: "Nicolás Antinori" <nico.antinori.7@gmail.com>
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" <bjorn3_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 1/3] rust: kunit: add #[should_panic] support
Date: Tue, 13 Oct 2026 18:58:14 -0300 [thread overview]
Message-ID: <DM41PHVITKOG.3I6P2X8048BEP@gmail.com> (raw)
In-Reply-To: <20260930-rust_kunit_v4-v1-1-e3b0d45311dd@gmail.com>
Hello,
There are two observations by Sashiko in this patch [1]:
> [Severity: Low]
> Does this interception occur too late to prevent spurious error logs?
>
> When a Rust test panics as expected, it triggers a kernel fault caught by
> KUnit with an exit code of -EINTR. However, kunit_try_catch_run()
> unconditionally logs an error message for -EINTR before returning to this
> function
>
> lib/kunit/try-catch.c:kunit_try_catch_run() {
> ...
> else if (exit_code == -EINTR) {
> if (test->last_seen.file)
> kunit_err(test, "try faulted: last line seen %s:%d\n", ...);
> else
> kunit_err(test, "try faulted\n");
> }
> ...
> }
Even though the tests marked as `#[should_panic]` are reported as
successful by KUnit, when run with `--raw_output=all` those log errors
appear. Is this a problem? Along with those the Oops message and stack
trace message show up as well. The report summary is clean if no special
logging options are used.
> [Severity: Medium]
> Will this condition correctly handle KUnit assertions inside a
> #[should_panic] test?
>
> The kunit_tests macro overrides assert! with kunit_assert!. If an
> assert! fails, kunit_assert! reports a KUnit assertion failure and
> aborts the thread via __kunit_abort, which results in -EFAULT rather
> than -EINTR.
>
> Since -EFAULT is cleared to 0 in kunit_try_catch_run(), this condition
> checking strictly for -EINTR will fail to intercept the abort. Will this
> cause valid #[should_panic] tests containing an assert! failure to be
> incorrectly marked as KUNIT_FAILURE instead of passing?
This is something I missed when working on the series and is accurate.
The following test:
#[test]
#[should_panic]
fn rust_test_assert_false() {
assert!(false)
}
Is reported as failed:
[18:31:00] # rust_test_assert_false: ASSERTION FAILED at rust/kernel/kunit.rs:383
[18:31:00] Expected false to be true, but is false
[18:31:00] # rust_test_assert_false.speed: normal
[18:31:00] [FAILED] rust_test_assert_false
But the user-space behavior is to pass the test [2].
Does it make sense to leave this behavior as it is for the kernel? If I
am not mistaken tests like those can easily be expressed without the
`#[should_panic]` attribute and negating the condition inside `assert!`.
`assert!` that are not in the test body behave as expected.
To solve those I'd need to check the `rust_should_panic` flag inside in
`kunit_try_catch_run` function. That would require changing its
signature (since the `kunit_try_catch` struct does not contain the
`test_case` struct and the context argument is void*, so I can't safely
cast it to what I need). Other alternative is to create a new function
for cases where `rust_should_panic` is true.
My approach to this was to modify as little as possible in the C side.
I think the current behavior is ok but I want to know your opinion.
Best regards,
Nicolás
[1] https://sashiko.dev/#/patchset/20260930-rust_kunit_v4-v1-0-e3b0d45311dd@gmail.com?part=1
[2] https://play.rust-lang.org/?version=stable&mode=debug&edition=2024&gist=2b4b29a266271497ea9932068ecdb8ff
next prev parent reply other threads:[~2026-10-13 21:58 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-30 13:23 [PATCH 0/3] rust: kunit: support #[should_panic] and same test name with different #[cfg(...)] Nicolás Antinori via B4 Relay
2026-09-30 13:23 ` Nicolás Antinori
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 ` Nicolás Antinori
2026-10-13 21:58 ` Nicolás Antinori [this message]
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 ` Nicolás Antinori
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 13:23 ` Nicolás Antinori
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
2026-10-01 14:08 ` Nicolás Antinori
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=DM41PHVITKOG.3I6P2X8048BEP@gmail.com \
--to=nico.antinori.7@gmail.com \
--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=david@davidgow.net \
--cc=gary@garyguo.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=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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.