diff mbox

[1/2,i-g-t,v2] lib: Add 64-bit version of igt_assert_cmp

Message ID 1435671669-12572-1-git-send-email-michel.thierry@intel.com (mailing list archive)
State New, archived
Headers show

Commit Message

Michel Thierry June 30, 2015, 1:41 p.m. UTC
igt_assert_cmp64 and its derivatives:
- igt_assert_cmpu64
- igt_assert_eq64
- igt_assert_eq_u64
- igt_assert_neq64
- igt_assert_lte64
- igt_assert_lt64

v2: Add igt_assert_cmp_t, this macro handles int, long and
double var cases. (Chris)

Cc: Chris Wilson <chris@chris-wilson.co.uk>
Signed-off-by: Michel Thierry <michel.thierry@intel.com>
---
 lib/igt_core.h | 125 ++++++++++++++++++++++++++++++++++++++++++++-------------
 1 file changed, 97 insertions(+), 28 deletions(-)

Comments

Chris Wilson June 30, 2015, 1:49 p.m. UTC | #1
On Tue, Jun 30, 2015 at 02:41:08PM +0100, Michel Thierry wrote:
> igt_assert_cmp64 and its derivatives:
> - igt_assert_cmpu64
> - igt_assert_eq64
> - igt_assert_eq_u64
> - igt_assert_neq64
> - igt_assert_lte64
> - igt_assert_lt64
> 
> v2: Add igt_assert_cmp_t, this macro handles int, long and
> double var cases. (Chris)
> 
> Cc: Chris Wilson <chris@chris-wilson.co.uk>
> Signed-off-by: Michel Thierry <michel.thierry@intel.com>
> ---
>  lib/igt_core.h | 125 ++++++++++++++++++++++++++++++++++++++++++++-------------
>  1 file changed, 97 insertions(+), 28 deletions(-)
> 
> diff --git a/lib/igt_core.h b/lib/igt_core.h
> index 2b2b6e9..09af295 100644
> --- a/lib/igt_core.h
> +++ b/lib/igt_core.h
> @@ -323,6 +323,20 @@ void igt_exit(void) __attribute__((noreturn));
>   */
>  #define igt_fail_on_f(expr, f...) igt_assert_f(!(expr), f)
>  
> +#define INTDECFORMAT "%d"
> +#define UINTHEXFORMAT "%#x"
> +#define DOUBLEDECFORMAT "%#lf"
> +#define LONGHEXFORMAT "%#llx"

Any particular reason? Passing in "%d" or %d would have worked just as
well, right?

Reviewed-by: Chris Wilson <chris@chris-wilson.co.uk>
-Chris
Michel Thierry June 30, 2015, 1:56 p.m. UTC | #2
On 6/30/2015 2:49 PM, Chris Wilson wrote:
> On Tue, Jun 30, 2015 at 02:41:08PM +0100, Michel Thierry wrote:
>> igt_assert_cmp64 and its derivatives:
>>
>> +#define INTDECFORMAT "%d"
>> +#define UINTHEXFORMAT "%#x"
>> +#define DOUBLEDECFORMAT "%#lf"
>> +#define LONGHEXFORMAT "%#llx"
>
> Any particular reason? Passing in "%d" or %d would have worked just as
> well, right?

Not really, these defines are not needed. The format specifier can be 
passed directly.

>
> Reviewed-by: Chris Wilson <chris@chris-wilson.co.uk>
> -Chris
>
diff mbox

Patch

diff --git a/lib/igt_core.h b/lib/igt_core.h
index 2b2b6e9..09af295 100644
--- a/lib/igt_core.h
+++ b/lib/igt_core.h
@@ -323,6 +323,20 @@  void igt_exit(void) __attribute__((noreturn));
  */
 #define igt_fail_on_f(expr, f...) igt_assert_f(!(expr), f)
 
+#define INTDECFORMAT "%d"
+#define UINTHEXFORMAT "%#x"
+#define DOUBLEDECFORMAT "%#lf"
+#define LONGHEXFORMAT "%#llx"
+
+#define igt_assert_cmp_t(T, F, n1, cmp, ncmp, n2) \
+	do { \
+		T __n1 = (n1), __n2 = (n2); \
+		if (!(__n1 cmp __n2)) \
+		__igt_fail_assert(IGT_LOG_DOMAIN, __FILE__, __LINE__, __func__, \
+				  #n1 " " #cmp " " #n2, \
+				  "error: " F " " #ncmp " " F "\n", __n1, __n2); \
+	} while (0)
+
 /**
  * igt_assert_cmpint:
  * @n1: first value
@@ -333,18 +347,13 @@  void igt_exit(void) __attribute__((noreturn));
  * Fails (sub-)test if the condition is not met
  *
  * Should be used everywhere where a test compares two integer values.
+ * For 64-bit values use igt_assert_cmp64().
  *
  * Like igt_assert(), but displays the values being compared on failure instead
  * of simply printing the stringified expression.
  */
 #define igt_assert_cmpint(n1, cmp, ncmp, n2) \
-	do { \
-		int __n1 = (n1), __n2 = (n2); \
-		if (__n1 cmp __n2) ; else \
-		__igt_fail_assert(IGT_LOG_DOMAIN, __FILE__, __LINE__, __func__, \
-				  #n1 " " #cmp " " #n2, \
-				  "error: %d " #ncmp " %d\n", __n1, __n2); \
-	} while (0)
+	igt_assert_cmp_t(int, INTDECFORMAT, n1, cmp, ncmp, n2)
 
 /**
  * igt_assert_cmpuint:
@@ -353,16 +362,35 @@  void igt_exit(void) __attribute__((noreturn));
  * @ncmp: negated version of @cmp
  * @n2: second value
  *
- * Like igt_assert_cmpint(), but for unsigned ints;
+ * Like igt_assert_cmpint(), but for unsigned ints. For 64-bit values
+ * use igt_assert_cmpu64().
  */
 #define igt_assert_cmpuint(n1, cmp, ncmp, n2) \
-	do { \
-		uint32_t __n1 = (n1), __n2 = (n2); \
-		if (__n1 cmp __n2) ; else \
-		__igt_fail_assert(IGT_LOG_DOMAIN, __FILE__, __LINE__, __func__, \
-				  #n1 " " #cmp " " #n2, \
-				  "error: %#x " #ncmp " %#x\n", __n1, __n2); \
-	} while (0)
+	igt_assert_cmp_t(uint32_t, UINTHEXFORMAT, n1, cmp, ncmp, n2)
+
+/**
+ * igt_assert_cmp64:
+ * @n1: first value
+ * @cmp: compare operator
+ * @ncmp: negated version of @cmp
+ * @n2: second value
+ *
+ * Like igt_assert_cmpint(), but for long longs;
+ */
+#define igt_assert_cmp64(n1, cmp, ncmp, n2) \
+	igt_assert_cmp_t(long long, LONGHEXFORMAT, n1, cmp, ncmp, n2)
+
+/**
+ * igt_assert_cmpu64:
+ * @n1: first value
+ * @cmp: compare operator
+ * @ncmp: negated version of @cmp
+ * @n2: second value
+ *
+ * Like igt_assert_cmpint(), but for unsigned long longs;
+ */
+#define igt_assert_cmpu64(n1, cmp, ncmp, n2) \
+	igt_assert_cmp_t(unsigned long long, LONGHEXFORMAT, n1, cmp, ncmp, n2)
 
 /**
  * igt_assert_cmpdouble:
@@ -374,21 +402,15 @@  void igt_exit(void) __attribute__((noreturn));
  * Like igt_assert_cmpint(), but for doubles;
  */
 #define igt_assert_cmpdouble(n1, cmp, ncmp, n2) \
-	do { \
-		double __n1 = (n1), __n2 = (n2); \
-		if (__n1 cmp __n2) ; else \
-		__igt_fail_assert(IGT_LOG_DOMAIN, __FILE__, __LINE__, __func__, \
-				  #n1 " " #cmp " " #n2, \
-				  "error: %#lf " #ncmp " %#lf\n", __n1, __n2); \
-	} while (0)
+	igt_assert_cmp_t(double, DOUBLEDECFORMAT, n1, cmp, ncmp, n2)
 
 /**
  * igt_assert_eq:
  * @n1: first integer
  * @n2: second integer
  *
- * Fails (sub-)test if the two integers are not equal. Beware that for now this
- * only works on integers.
+ * Fails (sub-)test if the two integers are not equal. Beware that this only
+ * works on integers. For 64-bit values, use igt_assert_eq64().
  *
  * Like igt_assert(), but displays the values being compared on failure instead
  * of simply printing the stringified expression.
@@ -405,6 +427,24 @@  void igt_exit(void) __attribute__((noreturn));
 #define igt_assert_eq_u32(n1, n2) igt_assert_cmpuint(n1, ==, !=, n2)
 
 /**
+ * igt_assert_eq64:
+ * @n1: first value
+ * @n2: second value
+ *
+ * Like igt_assert_eq(), but for long long.
+ */
+#define igt_assert_eq64(n1, n2) igt_assert_cmp64(n1, ==, !=, n2)
+
+/**
+ * igt_assert_eq_u64:
+ * @n1: first value
+ * @n2: second value
+ *
+ * Like igt_assert_eq(), but for unsigned long long.
+ */
+#define igt_assert_eq_u64(n1, n2) igt_assert_cmpu64(n1, ==, !=, n2)
+
+/**
  * igt_assert_eq_double:
  * @n1: first double
  * @n2: second double
@@ -418,8 +458,8 @@  void igt_exit(void) __attribute__((noreturn));
  * @n1: first integer
  * @n2: second integer
  *
- * Fails (sub-)test if the two integers are equal. Beware that for now this
- * only works on integers.
+ * Fails (sub-)test if the two integers are equal. Beware that this only works
+ * on integers. For 64-bit values, use igt_assert_neq64().
  *
  * Like igt_assert(), but displays the values being compared on failure instead
  * of simply printing the stringified expression.
@@ -427,12 +467,22 @@  void igt_exit(void) __attribute__((noreturn));
 #define igt_assert_neq(n1, n2) igt_assert_cmpint(n1, !=, ==, n2)
 
 /**
+ * igt_assert_neq64:
+ * @n1: first value
+ * @n2: second value
+ *
+ * Like igt_assert_neq(), but for long long.
+ */
+#define igt_assert_neq64(n1, n2) igt_assert_cmp64(n1, !=, ==, n2)
+
+/**
  * igt_assert_lte:
  * @n1: first integer
  * @n2: second integer
  *
  * Fails (sub-)test if the second integers is greater than the first.
- * Beware that for now this only works on integers.
+ * Beware that this only works on integers, for 64-bit values, use
+ * igt_assert_lte64().
  *
  * Like igt_assert(), but displays the values being compared on failure instead
  * of simply printing the stringified expression.
@@ -440,12 +490,22 @@  void igt_exit(void) __attribute__((noreturn));
 #define igt_assert_lte(n1, n2) igt_assert_cmpint(n1, <=, >, n2)
 
 /**
+ * igt_assert_lte64:
+ * @n1: first value
+ * @n2: second value
+ *
+ * Like igt_assert_lte(), but for long long.
+ */
+#define igt_assert_lte64(n1, n2) igt_assert_cmp64(n1, <=, >, n2)
+
+/**
  * igt_assert_lt:
  * @n1: first integer
  * @n2: second integer
  *
  * Fails (sub-)test if the second integers is strictly smaller than the first.
- * Beware that for now this only works on integers.
+ * Beware that this only works on integers. For 64-bit values, use
+ * igt_assert_lt64().
  *
  * Like igt_assert(), but displays the values being compared on failure instead
  * of simply printing the stringified expression.
@@ -453,6 +513,15 @@  void igt_exit(void) __attribute__((noreturn));
 #define igt_assert_lt(n1, n2) igt_assert_cmpint(n1, <, >=, n2)
 
 /**
+ * igt_assert_lt64:
+ * @n1: first value
+ * @n2: second value
+ *
+ * Like igt_assert_lt(), but for long long.
+ */
+#define igt_assert_lt64(n1, n2) igt_assert_cmp64(n1, <, >=, n2)
+
+/**
  * igt_require:
  * @expr: condition to test
  *