[PATCH v5 1/7] selftests/futex: Add ASSERT_ macros

André Almeida posted 7 patches 3 months, 1 week ago
[PATCH v5 1/7] selftests/futex: Add ASSERT_ macros
Posted by André Almeida 3 months, 1 week ago
Create ASSERT_{EQ, NE, TRUE, FALSE} macros to make test creation easier.

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

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

-- 
2.49.0

Re: [PATCH v5 1/7] selftests/futex: Add ASSERT_ macros
Posted by Thomas Gleixner 3 months, 1 week ago
On Thu, Jun 26 2025 at 14:11, André Almeida wrote:

> Create ASSERT_{EQ, NE, TRUE, FALSE} macros to make test creation easier.

What's so futex special about this that it can't use the same muck in

tools/testing/selftests/kselftest_harness.h

or at least share the implementation in some way?

Thanks,

        tglx
Re: [PATCH v5 1/7] selftests/futex: Add ASSERT_ macros
Posted by André Almeida 3 months, 1 week ago
Em 26/06/2025 19:07, Thomas Gleixner escreveu:
> On Thu, Jun 26 2025 at 14:11, André Almeida wrote:
> 
>> Create ASSERT_{EQ, NE, TRUE, FALSE} macros to make test creation easier.
> 
> What's so futex special about this that it can't use the same muck in
> 
> tools/testing/selftests/kselftest_harness.h
> 

My previous version of this test used kselftest_harness.h, but Shuah 
request to keep consistency and don't use this header, giving that the 
rest of futex test doesn't use it:

https://lore.kernel.org/lkml/fe02f42b-7ba8-4a3b-a86c-2a4a7942fd3b@linuxfoundation.org/

> or at least share the implementation in some way?
> 
> Thanks,
> 
>          tglx

Re: [PATCH v5 1/7] selftests/futex: Add ASSERT_ macros
Posted by Thomas Gleixner 3 months, 1 week ago
On Fri, Jun 27 2025 at 17:23, André Almeida wrote:
> Em 26/06/2025 19:07, Thomas Gleixner escreveu:
>> On Thu, Jun 26 2025 at 14:11, André Almeida wrote:
>> 
>>> Create ASSERT_{EQ, NE, TRUE, FALSE} macros to make test creation easier.
>> 
>> What's so futex special about this that it can't use the same muck in
>> 
>> tools/testing/selftests/kselftest_harness.h
>> 
>
> My previous version of this test used kselftest_harness.h, but Shuah 
> request to keep consistency and don't use this header, giving that the 
> rest of futex test doesn't use it:
>
> https://lore.kernel.org/lkml/fe02f42b-7ba8-4a3b-a86c-2a4a7942fd3b@linuxfoundation.org/

So proliferating duplicate and pointlessly different code is the
preferred option here?

Cleaning up the existing mess first before adding more would be too
sensible, right?

I'm lost for words, which is an achievement.
Re: [PATCH v5 1/7] selftests/futex: Add ASSERT_ macros
Posted by Thomas Gleixner 3 months, 1 week ago
On Fri, Jun 27 2025 at 00:07, Thomas Gleixner wrote:

> On Thu, Jun 26 2025 at 14:11, André Almeida wrote:
>
>> Create ASSERT_{EQ, NE, TRUE, FALSE} macros to make test creation easier.
>
> What's so futex special about this that it can't use the same muck in
>
> tools/testing/selftests/kselftest_harness.h
>
> or at least share the implementation in some way?

BPF has it's own set as well. Sigh...