Re: [PATCH v2 2/3] rust: bitfield: Add KUNIT tests for bitfield
From: Alice Ryhl
Date: Thu Apr 16 2026 - 03:01:41 EST
On Wed, Apr 15, 2026 at 10:44:01PM -0400, Yury Norov wrote:
> On Thu, Apr 09, 2026 at 11:58:48PM +0900, Alexandre Courbot wrote:
> > From: Joel Fernandes <joelagnelf@xxxxxxxxxx>
> >
> > Add KUNIT tests to make sure the macro is working correctly.
> >
> > Signed-off-by: Joel Fernandes <joelagnelf@xxxxxxxxxx>
> > [acourbot: update code to latest bitfield! macro.]
> > Signed-off-by: Alexandre Courbot <acourbot@xxxxxxxxxx>
> > ---
> > rust/kernel/bitfield.rs | 318 ++++++++++++++++++++++++++++++++++++++++++++++++
> > 1 file changed, 318 insertions(+)
> >
> > diff --git a/rust/kernel/bitfield.rs b/rust/kernel/bitfield.rs
> > index f5948eec8a76..9ab8dafff36c 100644
> > --- a/rust/kernel/bitfield.rs
> > +++ b/rust/kernel/bitfield.rs
> > @@ -489,3 +489,321 @@ fn fmt(&self, f: &mut ::kernel::fmt::Formatter<'_>) -> ::kernel::fmt::Result {
> > }
> > };
> > }
> > +
> > +#[::kernel::macros::kunit_tests(kernel_bitfield)]
>
> Reading the Documentation/rust/testing.rst, and can't understand how
> should one configure it to _not_ build the tests? This should be the
> default behavior.
>
> There's half a dozen already existing unit tests, and I didn't find
> a mechanism to individually control them.
If you want this set of kunit tests to have its own config option, then
you can declare a Kconfig option for it and do this:
#[cfg(CONFIG_MY_RUST_KCONFIG_OPTION)]
#[kunit_tests(kernel_bitfield)]
mod tests {
...
}
Alice