All of lore.kernel.org
 help / color / mirror / Atom feed
From: Joel Fernandes <joelagnelf@nvidia.com>
To: Yury Norov <yury.norov@gmail.com>
Cc: linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org,
	dakr@kernel.org, acourbot@nvidia.com,
	Alistair Popple <apopple@nvidia.com>,
	Miguel Ojeda <ojeda@kernel.org>,
	Alex Gaynor <alex.gaynor@gmail.com>,
	Boqun Feng <boqun.feng@gmail.com>, Gary Guo <gary@garyguo.net>,
	bjorn3_gh@protonmail.com, Benno Lossin <lossin@kernel.org>,
	Andreas Hindborg <a.hindborg@kernel.org>,
	Alice Ryhl <aliceryhl@google.com>,
	Trevor Gross <tmgross@umich.edu>,
	David Airlie <airlied@gmail.com>, Simona Vetter <simona@ffwll.ch>,
	Maarten Lankhorst <maarten.lankhorst@linux.intel.com>,
	Maxime Ripard <mripard@kernel.org>,
	Thomas Zimmermann <tzimmermann@suse.de>,
	John Hubbard <jhubbard@nvidia.com>, Timur Tabi <ttabi@nvidia.com>,
	joel@joelfernandes.org, Elle Rhumsaa <elle@weathered-steel.dev>,
	Daniel Almeida <daniel.almeida@collabora.com>,
	nouveau@lists.freedesktop.org
Subject: Re: [PATCH v3 5/5] rust: Add KUNIT tests for bitfield
Date: Tue, 16 Sep 2025 06:10:28 -0400	[thread overview]
Message-ID: <20250916101028.GA1655707@joelbox2> (raw)
In-Reply-To: <20250916095918.GA1647262@joelbox2>

On Tue, Sep 16, 2025 at 05:59:18AM -0400, Joel Fernandes wrote:
> Hi Jury,
> Sorry for late reply, I was busy with conference travel. Now I found a 3 hour
> break before my train journey. :-)
> 
> On Wed, Sep 10, 2025 at 09:47:04PM -0400, Yury Norov wrote:
> > On Wed, Sep 10, 2025 at 07:08:43PM -0400, Joel Fernandes wrote:
> > > > You've got only one negative test that covers the .from() method.
> > > > Can you add more?
> > > 
> > > Sure, but note that we can only add negative tests if there is a chance of
> > > failure, which at runtime can mainly happen with the fallible usage (?=>
> > > pattern). Also just to note, we already at ~300 lines of test code now :)
> > > 
> > > > 
> > > > What if I create a bitfield from a runtime value that exceeds
> > > > the capacity?
> > > > 
> > > >     bitfield! {
> > > >         struct bf: u8 {
> > > >             0:0       ready       as bool;
> > > >             1:1       error       as bool;
> > > >             3:2       state       as u32;
> > > Here you mean 'as u8', otherwise it wont compile.
> > 
> > No, I meant u32. Can you explain this limitation in docs please? From
> > a user perspective, the 'state' is a 2-bit variable, so any type wider
> > than that should be OK to hold the data. If it's just an implementation
> > limitation, maybe it's worth to relax it?
> 
> Yes it is a limitation because of the way the code does mask and shifts, it
> requires the width to not exceed the width of the struct itself. Yes, I can
> add a comment.
> 
> I think to do what you want, you have to write it as 'as u8 => u32'.
> Otherwise it wont compile.

I think I am convinced we should fix this, it is too much of a burden to the
user otherwise. 'as u32' should just work out of the box.. I'll add support
for this in v4 but if anyone has any objections, please let me know, thanks!

 - Joel


  reply	other threads:[~2025-10-06 20:48 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-09-09 21:20 [PATCH v3 0/5] Introduce bitfield and move register macro to rust/kernel/ Joel Fernandes
2025-09-09 21:20 ` [PATCH v3 1/5] nova-core: bitfield: Move bitfield-specific code from register! into new macro Joel Fernandes
2025-09-09 21:20 ` [PATCH v3 2/5] nova-core: bitfield: Add support for different storage widths Joel Fernandes
2025-09-09 21:20 ` [PATCH v3 3/5] nova-core: bitfield: Add support for custom visiblity Joel Fernandes
2025-09-09 21:20 ` [PATCH v3 4/5] rust: Move register and bitfield macros out of Nova Joel Fernandes
2025-09-09 21:36   ` Miguel Ojeda
2025-09-10  0:15     ` Joel Fernandes
2025-09-09 21:20 ` [PATCH v3 5/5] rust: Add KUNIT tests for bitfield Joel Fernandes
2025-09-10  3:04   ` Yury Norov
2025-09-10 23:08     ` Joel Fernandes
2025-09-11  1:47       ` Yury Norov
2025-09-16  9:59         ` Joel Fernandes
2025-09-16 10:10           ` Joel Fernandes [this message]
2025-09-19 23:02           ` Joel Fernandes
2025-09-20  0:39           ` Joel Fernandes
2025-09-20  0:52             ` John Hubbard
2025-09-20  9:33               ` Joel Fernandes
2025-09-21 11:41             ` Miguel Ojeda
2025-09-10 23:22     ` Joel Fernandes

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=20250916101028.GA1655707@joelbox2 \
    --to=joelagnelf@nvidia.com \
    --cc=a.hindborg@kernel.org \
    --cc=acourbot@nvidia.com \
    --cc=airlied@gmail.com \
    --cc=alex.gaynor@gmail.com \
    --cc=aliceryhl@google.com \
    --cc=apopple@nvidia.com \
    --cc=bjorn3_gh@protonmail.com \
    --cc=boqun.feng@gmail.com \
    --cc=dakr@kernel.org \
    --cc=daniel.almeida@collabora.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=elle@weathered-steel.dev \
    --cc=gary@garyguo.net \
    --cc=jhubbard@nvidia.com \
    --cc=joel@joelfernandes.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lossin@kernel.org \
    --cc=maarten.lankhorst@linux.intel.com \
    --cc=mripard@kernel.org \
    --cc=nouveau@lists.freedesktop.org \
    --cc=ojeda@kernel.org \
    --cc=simona@ffwll.ch \
    --cc=tmgross@umich.edu \
    --cc=ttabi@nvidia.com \
    --cc=tzimmermann@suse.de \
    --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.