Linux Kernel Selftest development
 help / color / mirror / Atom feed
From: Felix Maurer <fmaurer@redhat.com>
To: Vincent Mailhol <mailhol.vincent@wanadoo.fr>
Cc: socketcan@hartkopp.net, mkl@pengutronix.de, shuah@kernel.org,
	davem@davemloft.net, edumazet@google.com, kuba@kernel.org,
	pabeni@redhat.com, horms@kernel.org, linux-can@vger.kernel.org,
	netdev@vger.kernel.org, linux-kselftest@vger.kernel.org,
	dcaratti@redhat.com, fstornio@redhat.com
Subject: Re: [PATCH 4/4] selftests: can: Document test_raw_filter test cases
Date: Thu, 24 Apr 2025 16:02:19 +0200	[thread overview]
Message-ID: <a28ff624-c73a-4e16-867a-66e423315c29@redhat.com> (raw)
In-Reply-To: <CAMZ6RqKcp=JNcbZjX6xSGo9Hyw=1nXbpS9Nc36xuDkbGG+=wtA@mail.gmail.com>

On 24.04.25 09:44, Vincent Mailhol wrote:
> On Tue. 22 Apr. 2025 at 21:03, Felix Maurer <fmaurer@redhat.com> wrote:
[...]
>> diff --git a/tools/testing/selftests/net/can/test_raw_filter.c b/tools/testing/selftests/net/can/test_raw_filter.c
>> index 7fe11e020a1c..8d43053824d2 100644
>> --- a/tools/testing/selftests/net/can/test_raw_filter.c
>> +++ b/tools/testing/selftests/net/can/test_raw_filter.c
>> @@ -101,94 +101,113 @@ FIXTURE_VARIANT(can_filters) {
>>         int exp_num_rx;
>>         int exp_rxbits;
>>  };
>> +#define T_EFF (CAN_EFF_FLAG >> 28)
>> +#define T_RTR (CAN_RTR_FLAG >> 28)
> 
> I do not like this
> 
>   >> 28
> 
> shift. I understand that it is part of the original design, but for
> me, this is just obfuscation.
> 
> Why just not using CAN_EFF_FLAG and CAN_RTR_FLAG as-is for the
> expected values? What benefit does this shift add?

I agree, that looks like magic numbers and the original design is not
very nice here. The main reason for the >>28 is that later on values are
shifted by T_EFF and/or T_RTR, so they shouldn't be too large (with the
>>28, the shift value later is in the range 0-14). See below for a
slightly different idea.

>> +/* Ignore EFF flag in filter ID if not covered by filter mask */
>>  FIXTURE_VARIANT_ADD(can_filters, base_eff) {
>>         .testcase = 2,
>>         .id = ID | CAN_EFF_FLAG,
>>         .mask = CAN_SFF_MASK,
>>         .exp_num_rx = 4,
>> -       .exp_rxbits = 4369,
>> +       .exp_rxbits = (1 | 1 << (T_EFF) | 1 << (T_RTR) | 1 << (T_EFF | T_RTR)),
>                          ^
> What is the meaning of this 1?

The 1 means that a packet will be received with no flags set.

The whole rxbit thing took me a while to understand and the result now
is not straightforward either. Let's see if we can come up with
something better.

The exp_rxbits is basically a bitfield that describes which flags should
be set on the received frames. Maybe this could be made more explicit
with something like this:

.exp_rxbits = FRAME_NOFLAGS | FRAME_EFF | FRAME_RTR | FRAME_EFFRTR,

And in the receive loop something like this:

rxbits |= FRAME_RCVD(frame.can_id);

Of course, the definitions of these macros would still have the >>28,
but at a central point, with better explanation. Do you think that's
more understandable? Or do you have a different idea?

Thanks,
   Felix


  parent reply	other threads:[~2025-04-24 14:02 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-04-22 12:02 [PATCH 0/4] selftest: can: Start importing selftests from can-tests Felix Maurer
2025-04-22 12:02 ` [PATCH 1/4] selftests: can: Import tst-filter " Felix Maurer
2025-04-24  7:42   ` Vincent Mailhol
2025-04-24 14:02     ` Felix Maurer
2025-04-24 14:23       ` Vincent Mailhol
2025-04-22 12:02 ` [PATCH 2/4] selftests: can: use kselftest harness in test_raw_filter Felix Maurer
2025-04-24  7:42   ` Vincent Mailhol
2025-04-22 12:02 ` [PATCH 3/4] selftests: can: Use fixtures " Felix Maurer
2025-04-24  7:43   ` Vincent Mailhol
2025-04-22 12:02 ` [PATCH 4/4] selftests: can: Document test_raw_filter test cases Felix Maurer
2025-04-24  7:44   ` Vincent Mailhol
2025-04-24  8:21     ` Vincent Mailhol
2025-04-24 14:02     ` Felix Maurer [this message]
2025-04-24 15:08       ` Vincent Mailhol
2025-04-30  9:36         ` Felix Maurer
2025-04-24  7:45 ` [PATCH 0/4] selftest: can: Start importing selftests from can-tests Vincent Mailhol
2025-04-24 14:01   ` Felix Maurer
2025-04-24 15:19     ` Vincent Mailhol
2025-04-24 23:02 ` Jakub Kicinski

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=a28ff624-c73a-4e16-867a-66e423315c29@redhat.com \
    --to=fmaurer@redhat.com \
    --cc=davem@davemloft.net \
    --cc=dcaratti@redhat.com \
    --cc=edumazet@google.com \
    --cc=fstornio@redhat.com \
    --cc=horms@kernel.org \
    --cc=kuba@kernel.org \
    --cc=linux-can@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=mailhol.vincent@wanadoo.fr \
    --cc=mkl@pengutronix.de \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=shuah@kernel.org \
    --cc=socketcan@hartkopp.net \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox