All of lore.kernel.org
 help / color / mirror / Atom feed
From: Karthik B S <karthik.b.s@intel.com>
To: Kamil Konieczny <kamil.konieczny@linux.intel.com>,
	<igt-dev@lists.freedesktop.org>
Cc: "Zbigniew Kempczyński" <zbigniew.kempczynski@intel.com>
Subject: Re: [PATCH i-g-t v2 1/2] lib/igt_core: Create asserts for pointer comparision
Date: Mon, 20 Apr 2026 15:56:20 +0530	[thread overview]
Message-ID: <028fe462-fa81-48bb-b030-ef10ab48e96f@intel.com> (raw)
In-Reply-To: <20260417181157.177299-2-kamil.konieczny@linux.intel.com>


On 4/17/2026 11:41 PM, Kamil Konieczny wrote:
> Create two macros for pointer comparisions, igt_assert_eq_ptr
> and igt_assert_neq_ptr. They will print corresponding pointers
> on fail. This will allow us to remove ugly casts, for example
>
> igt_assert_eq_u64((uint64_t)ptr, (uint64_t)MAP_FAILED);
>
> could be rewritten into
>
> igt_assert_eq_ptr(ptr, MAP_FAILED);
>
> v2: add cast to 'void *' in macro (Zbigniew)
>
> Cc: "Zbigniew Kempczyński" <zbigniew.kempczynski@intel.com>
> Signed-off-by: Kamil Konieczny <kamil.konieczny@linux.intel.com>
Reviewed-by: Karthik B S <karthik.b.s@intel.com>
> ---
>   lib/igt_core.h | 42 ++++++++++++++++++++++++++++++++++++++++++
>   1 file changed, 42 insertions(+)
>
> diff --git a/lib/igt_core.h b/lib/igt_core.h
> index 6845f853c..9fe3997e7 100644
> --- a/lib/igt_core.h
> +++ b/lib/igt_core.h
> @@ -723,6 +723,48 @@ void igt_describe_f(const char *fmt, ...);
>    */
>   #define igt_fail_on_f(expr, f...) igt_assert_f(!(expr), f)
>   
> +/**
> + * igt_assert_cmpptr:
> + * @n1: first value
> + * @cmp: compare operator
> + * @ncmp: negated version of @cmp
> + * @n2: second value
> + *
> + * Fails (sub-)test if the condition is not met
> + *
> + * Should be used everywhere where a test compares two pointers.
> + *
> + * Like igt_assert(), but displays the pointers being compared on failure instead
> + * of simply printing the stringified expression.
> + */
> +#define igt_assert_cmpptr(n1, cmp, ncmp, n2) \
> +	do { \
> +		void *__n1 = (void *)(n1); \
> +		void *__n2 = (void *)(n2); \
> +		if (__n1 cmp __n2) ; else \
> +		__igt_fail_assert(IGT_LOG_DOMAIN, __FILE__, __LINE__, __func__, \
> +				  #n1 " " #cmp " " #n2, \
> +				  "error: %p " #ncmp " %p\n", __n1, __n2); \
> +	} while (0)
> +
> +/**
> + * igt_assert_eq_ptr:
> + * @n1: first pointer
> + * @n2: second pointer
> + *
> + * Like igt_assert_eq(), but for pointers.
> + */
> +#define igt_assert_eq_ptr(n1, n2) igt_assert_cmpptr(n1, ==, !=, n2)
> +
> +/**
> + * igt_assert_neq_ptr:
> + * @n1: first pointer
> + * @n2: second pointer
> + *
> + * Like igt_assert_neq(), but for pointers.
> + */
> +#define igt_assert_neq_ptr(n1, n2) igt_assert_cmpptr(n1, !=, ==, n2)
> +
>   /**
>    * igt_assert_cmpint:
>    * @n1: first value

  reply	other threads:[~2026-04-20 10:26 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-17 18:11 [PATCH i-g-t v2 0/2] Add assert for pointers compare and fix armhf compilation Kamil Konieczny
2026-04-17 18:11 ` [PATCH i-g-t v2 1/2] lib/igt_core: Create asserts for pointer comparision Kamil Konieczny
2026-04-20 10:26   ` Karthik B S [this message]
2026-04-17 18:11 ` [PATCH i-g-t v2 2/2] tests/intel/xe_madvise: Fix armhf compilation Kamil Konieczny
2026-04-20 10:27   ` Karthik B S
2026-04-21 11:51 ` ✗ Fi.CI.BAT: failure for Add assert for pointers compare and fix armhf compilation (rev2) Patchwork

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=028fe462-fa81-48bb-b030-ef10ab48e96f@intel.com \
    --to=karthik.b.s@intel.com \
    --cc=igt-dev@lists.freedesktop.org \
    --cc=kamil.konieczny@linux.intel.com \
    --cc=zbigniew.kempczynski@intel.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.