Re: [PATCH v2 2/3] rust: bitfield: Add KUNIT tests for bitfield

Yury Norov
2026-04-16T12:48:50Z

On Thu, Apr 16, 2026 at 06:59:46AM +0000, Alice Ryhl wrote:
> 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@nvidia.com>
> > >
> > > Add KUNIT tests to make sure the macro is working correctly.
> > >
> > > Signed-off-by: Joel Fernandes <joelagnelf@nvidia.com>
> > > [acourbot: update code to latest bitfield! macro.]
> > > Signed-off-by: Alexandre Courbot <acourbot@nvidia.com>
> > > ---
> > > 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 {
> ...
> }

Thanks, Alce!

I suspected that, but you never know all the rust tricks. :)

Joel, can you do as suggested here, and I can send a patch for the
existing tests, if no objections?

Thanks,
Yury