The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: David Laight <david.laight.linux@gmail.com>
To: "Thomas Weißschuh" <linux@weissschuh.net>
Cc: Willy Tarreau <w@1wt.eu>,
	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: Wed, 2 Dec 2026 11:29:23 +0000	[thread overview]
Message-ID: <20261202112923.127f38d2@pumpkin> (raw)
In-Reply-To: <20261202-nolibc-fcntl-v2-2-651ff5781baa@weissschuh.net>

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?
I might have called them (struct_1, struct_2, member).
Those variables don't need protecting with a leading _ ...

> +	bool different = false;								\

... but, in theory, that one does.
(Clearly the calls are very limited.)

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-02 11:29 UTC|newest]

Thread overview: 6+ 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-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 [this message]
2026-12-02  7:29 ` [PATCH v2 3/4] tools/nolibc: add support for fcntl() Thomas Weißschuh
2026-12-02  7:29 ` [PATCH v2 4/4] tools/nolibc: remove the open-coded fcntl() in dup2() Thomas Weißschuh

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