Skip to contentSkip to conversation

selftests/futex: Add ASSERT_ macros

PATCH Superseded André Almeida 1 participant 2 messages Feb 12, 2025

Subsystems (2)

v5 of 6 Superseded Latest is v6 →

lore
Share & tools
lore

André Almeida

author reviewer
#0 lore raw

PATCH v5 1/2 selftests/futex: Add ASSERT_ macros

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

---
 .../testing/selftests/futex/include/logging.h | 38 +++++++++++++++++++
 1 file changed, 38 insertions(+)
tools/testing/selftests/futex/include/logging.h +38 -0
index 874c69ce5cce..a19755622a87 100644
@@ -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.
Signature · 1 line
2.48.1
author reviewer
#1 lore raw

PATCH v5 2/2 selftests/futex: Create test for robust list

Create a test for the robust list mechanism. Test the following uAPI operations:

- Creating a robust mutex where the lock waiter is wake by the kernel when the lock owner died
- Setting a robust list to the current task
- Getting a robust list from the current task
- Getting a robust list from another task
- Using the list_op_pending field from robust_list_head struct to test robustness when the lock owner dies before completing the locking
- Setting a invalid size for syscall argument len
- Adding multiple elements to a robust list wait waiting for each of them
- Creating a circular list and checking that the kernel does not get stuck in an infinity loop

This is the expected output:

TAP version 13
1..7
ok 1 test_robustness
ok 2 test_set_robust_list_invalid_size
ok 3 test_get_robust_list_self
ok 4 test_get_robust_list_child
ok 5 test_set_list_op_pending
ok 6 test_robust_list_multiple_elements
ok 7 test_circular_list
# Totals: pass:7 fail:0 xfail:0 xpass:0 skip:0 error:0

---
Changelog:

v5:
- Added circular list test

---
 .../selftests/futex/functional/.gitignore     |   1 +
 .../selftests/futex/functional/Makefile       |   3 +-
 .../selftests/futex/functional/robust_list.c  | 554 ++++++++++++++++++
 3 files changed, 557 insertions(+), 1 deletion(-)
 create mode 100644 tools/testing/selftests/futex/functional/robust_list.c
tools/testing/selftests/futex/functional/.gitignore +1 -0
index fbcbdb6963b3..4726e1be7497 100644
@@ -9,3 +9,4 @@ futex_wait_wouldblock
 futex_wait
 futex_requeue
 futex_waitv
+robust_list
tools/testing/selftests/futex/functional/Makefile +2 -1
index f79f9bac7918..b8635a1ac7f6 100644
@@ -17,7 +17,8 @@ TEST_GEN_PROGS := \
 	futex_wait_private_mapped_file \
 	futex_wait \
 	futex_requeue \
-	futex_waitv
+	futex_waitv \
+	robust_list
 
 TEST_PROGS := run.sh
 
tools/testing/selftests/futex/functional/robust_list.c new file +554 -0

554 lines not on this page · raw message

Signature · 1 line
2.48.1