From: Kamil Konieczny <kamil.konieczny@linux.intel.com>
To: igt-dev@lists.freedesktop.org
Cc: "Kamil Konieczny" <kamil.konieczny@linux.intel.com>,
"Zbigniew Kempczyński" <zbigniew.kempczynski@intel.com>
Subject: [PATCH i-g-t v2 1/2] lib/igt_core: Create asserts for pointer comparision
Date: Fri, 17 Apr 2026 20:11:56 +0200 [thread overview]
Message-ID: <20260417181157.177299-2-kamil.konieczny@linux.intel.com> (raw)
In-Reply-To: <20260417181157.177299-1-kamil.konieczny@linux.intel.com>
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>
---
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
--
2.53.0
next prev parent reply other threads:[~2026-04-17 18:12 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 ` Kamil Konieczny [this message]
2026-04-20 10:26 ` [PATCH i-g-t v2 1/2] lib/igt_core: Create asserts for pointer comparision Karthik B S
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=20260417181157.177299-2-kamil.konieczny@linux.intel.com \
--to=kamil.konieczny@linux.intel.com \
--cc=igt-dev@lists.freedesktop.org \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox