diff mbox series

[v4,1/2] selftests/futex: Add ASSERT_ macros

Message ID 20241212210436.112076-2-andrealmeid@igalia.com
State New
Headers show
Series selftests/futex: Create test for robust list | expand

Commit Message

André Almeida Dec. 12, 2024, 9:04 p.m. UTC
Create ASSERT_{EQ, NE, TRUE, FALSE} macros to make test creation easier.

Signed-off-by: André Almeida <andrealmeid@igalia.com>
---
 .../testing/selftests/futex/include/logging.h | 28 +++++++++++++++++++
 1 file changed, 28 insertions(+)
diff mbox series

Patch

diff --git a/tools/testing/selftests/futex/include/logging.h b/tools/testing/selftests/futex/include/logging.h
index 874c69ce5cce..a7070e7cf313 100644
--- a/tools/testing/selftests/futex/include/logging.h
+++ b/tools/testing/selftests/futex/include/logging.h
@@ -23,6 +23,34 @@ 
 #include <linux/futex.h>
 #include "kselftest.h"
 
+#define ASSERT_EQ(var, value) \
+	if (var != value) { \
+		ksft_test_result_fail("%s: expected %ld, but %s has %ld\n", \
+				      __func__, (long int) value, #var, (long int) var); \
+		return; \
+	}
+
+#define ASSERT_NE(var, value) \
+	if (var == value) { \
+		ksft_test_result_fail("%s: expected not %ld, but %s has %ld\n", \
+				      __func__, (long int) value, #var, (long int) var); \
+		return; \
+	}
+
+#define ASSERT_TRUE(var) \
+	if ((var) == 0) { \
+		ksft_test_result_fail("%s: expected %s to be true\n", \
+				      __func__, #var); \
+		return; \
+	}
+
+#define ASSERT_FALSE(var) \
+	if (var) { \
+		ksft_test_result_fail("%s: expected %s to be false\n", \
+				      __func__, #var); \
+		return; \
+	}
+
 /*
  * Define PASS, ERROR, and FAIL strings with and without color escape
  * sequences, default to no color.