The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: Willy Tarreau <w@1wt.eu>
To: David Laight <david.laight.linux@gmail.com>
Cc: "Thomas Weißschuh" <linux@weissschuh.net>,
	linux-kernel@vger.kernel.org,
	"Danish Khateeb" <danishkhateeb03@gmail.com>
Subject: Re: [PATCH v2 2/4] selftests/nolibc: split out the structure member compatibility checks
Date: Sat, 5 Dec 2026 15:31:33 +0100	[thread overview]
Message-ID: <axQgRdfrpeuCN4Lh@1wt.eu> (raw)
In-Reply-To: <20261202112923.127f38d2@pumpkin>

On Wed, Dec 02, 2026 at 11:29:23AM +0000, David Laight wrote:
> On Wed, 02 Dec 2026 08:29:47 +0100
> Thomas Weißschuh <linux@weissschuh.net> wrote:
> 
> > A future test will add more similar tests.
> > 
> > Factor out a helper to validate that two structures have compatible
> > members.
> > 
> > Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
> > ---
> >  tools/testing/selftests/nolibc/nolibc-test.c | 30 +++++++++++++++++-----------
> >  1 file changed, 18 insertions(+), 12 deletions(-)
> > 
> > diff --git a/tools/testing/selftests/nolibc/nolibc-test.c b/tools/testing/selftests/nolibc/nolibc-test.c
> > index a924d53260fd..fce755ffed14 100644
> > --- a/tools/testing/selftests/nolibc/nolibc-test.c
> > +++ b/tools/testing/selftests/nolibc/nolibc-test.c
> > @@ -58,6 +58,18 @@
> >  #define SINT_MAX_OF_TYPE(type) (((type)1 << (sizeof(type) * 8 - 2)) - (type)1 + ((type)1 << (sizeof(type) * 8 - 2)))
> >  #define SINT_MIN_OF_TYPE(type) (-SINT_MAX_OF_TYPE(type) - 1)
> >  
> > +#define struct_members_identical(_member, _left, _right) ({				\
> 
> Maybe put the member parameter last?

Honestly it's a matter or taste, habit or context you're working on. Most
likely depending on how you start you'll use either one or the other.

> I might have called them (struct_1, struct_2, member).
> Those variables don't need protecting with a leading _ ...

Sure but sometimes it makes it more obvious when reading the rest of the
macro what is an argument and what is not, like in the series of
different |= ... statements after that.

> > +	bool different = false;								\
> 
> ... but, in theory, that one does.
> (Clearly the calls are very limited.)

Indeed it could, though unlikely to cause a problem, but might still
warrant a last-minute change without emitting a 3rd version.

Overall this looks good to me.

Reviewed-by: Willy Tarreau <w@1wt.eu>
Willy

> David
> 
> > +											\
> > +	different |= sizeof((_left)._member) != sizeof((_right)._member);		\
> > +	different |= offsetof(__typeof__(_left), _member) !=				\
> > +		     offsetof(__typeof__(_right), _member);				\
> > +	different |= !__builtin_types_compatible_p(__typeof__((_left)._member),		\
> > +						   __typeof__((_right)._member));	\
> > +											\
> > +	!different;									\
> > +})
> > +
> >  /* will be used to test initialization of environ */
> >  static char **test_envp;
> >  
> > @@ -1903,22 +1915,16 @@ int test_time_types(void)
> >  	struct timespec ts;
> >  
> >  	if (!__builtin_types_compatible_p(time_t, __kernel_time64_t))
> > -		return 1;
> > +		return __LINE__;
> >  
> >  	if (sizeof(ts) != sizeof(kts))
> > -		return 1;
> > -
> > -	if (!__builtin_types_compatible_p(__typeof__(ts.tv_sec), __typeof__(kts.tv_sec)))
> > -		return 1;
> > -
> > -	if (!__builtin_types_compatible_p(__typeof__(ts.tv_nsec), __typeof__(kts.tv_nsec)))
> > -		return 1;
> > +		return __LINE__;
> >  
> > -	if (offsetof(__typeof__(ts), tv_sec) != offsetof(__typeof__(kts), tv_sec))
> > -		return 1;
> > +	if (!struct_members_identical(tv_sec, ts, kts))
> > +		return __LINE__;
> >  
> > -	if (offsetof(__typeof__(ts), tv_nsec) != offsetof(__typeof__(kts), tv_nsec))
> > -		return 1;
> > +	if (!struct_members_identical(tv_nsec, ts, kts))
> > +		return __LINE__;
> >  #endif /* NOLIBC */
> >  
> >  	return 0;
> > 
> 

  reply	other threads:[~2026-12-05 14:31 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-02  7:29 [PATCH v2 0/4] tools/nolibc: add support for fcntl() Thomas Weißschuh
2026-12-02  7:29 ` [PATCH v2 1/4] tools/nolibc: derive clang target flags from ARCH if CROSS_COMPILE is not set Thomas Weißschuh
2026-12-05 14:33   ` Willy Tarreau
2026-12-02  7:29 ` [PATCH v2 2/4] selftests/nolibc: split out the structure member compatibility checks Thomas Weißschuh
2026-12-02 11:29   ` David Laight
2026-12-05 14:31     ` Willy Tarreau [this message]
2026-12-02  7:29 ` [PATCH v2 3/4] tools/nolibc: add support for fcntl() Thomas Weißschuh
2026-12-05 14:25   ` Willy Tarreau
2026-12-05 14:56     ` Thomas Weißschuh
2026-12-05 16:08       ` Willy Tarreau
2026-12-02  7:29 ` [PATCH v2 4/4] tools/nolibc: remove the open-coded fcntl() in dup2() Thomas Weißschuh
2026-12-05 14:26   ` Willy Tarreau

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=axQgRdfrpeuCN4Lh@1wt.eu \
    --to=w@1wt.eu \
    --cc=danishkhateeb03@gmail.com \
    --cc=david.laight.linux@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@weissschuh.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