Skip to contentSkip to conversation

selftests: futex: Expand futex testing

PATCH Applied André Almeida 3 participants 6 messages May 31, 2021 – Jun 22, 2021

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover selftests: futex: Expand futex testing

This patchset expands test coverage for futex, implementing two new
selftests: one for testing different types of futexes and one for the requeue operation.

André Almeida (2):
selftests: futex: Add futex wait test
selftests: futex: Add futex compare requeue test

 .../selftests/futex/functional/.gitignore     |   2 +
 .../selftests/futex/functional/Makefile       |   4 +-
 .../futex/functional/futex_requeue.c          | 145 ++++++++++++++
 .../selftests/futex/functional/futex_wait.c   | 180 ++++++++++++++++++
 .../testing/selftests/futex/functional/run.sh |   6 +
 5 files changed, 336 insertions(+), 1 deletion(-)
 create mode 100644 tools/testing/selftests/futex/functional/futex_requeue.c
 create mode 100644 tools/testing/selftests/futex/functional/futex_wait.c
Signature · 1 line
2.31.1
#1 lore raw

PATCH 1/2 selftests: futex: Add futex wait test

There are three different strategies to uniquely identify a futex in the kernel:
- Private futexes: uses the pointer to mm_struct and the page address
- Shared futexes: checks if the page containing the address is a PageAnon:
- If it is, uses the same data as a private futexes
- If it isn't, uses an inode sequence number from struct inode and the page's index

Create a selftest to check those three paths and basic wait/wake mechanism.

---
 .../selftests/futex/functional/.gitignore     |   1 +
 .../selftests/futex/functional/Makefile       |   3 +-
 .../selftests/futex/functional/futex_wait.c   | 171 ++++++++++++++++++
 .../testing/selftests/futex/functional/run.sh |   3 +
 4 files changed, 177 insertions(+), 1 deletion(-)
 create mode 100644 tools/testing/selftests/futex/functional/futex_wait.c
tools/testing/selftests/futex/functional/.gitignore +1 -0
index 0efcd494daab..bd24699bacc9 100644
@@ -6,3 +6,4 @@ futex_wait_private_mapped_file
 futex_wait_timeout
 futex_wait_uninitialized_heap
 futex_wait_wouldblock
+futex_wait
tools/testing/selftests/futex/functional/Makefile +2 -1
index 1d2b3b2a5b86..20a5b4a1bc87 100644
@@ -15,7 +15,8 @@ TEST_GEN_FILES := \
 	futex_requeue_pi_signal_restart \
 	futex_requeue_pi_mismatched_ops \
 	futex_wait_uninitialized_heap \
-	futex_wait_private_mapped_file
+	futex_wait_private_mapped_file \
+	futex_wait
 
 TEST_PROGS := run.sh
 
tools/testing/selftests/futex/functional/futex_wait.c new file +171 -0

171 lines not on this page · raw message

tools/testing/selftests/futex/functional/run.sh +3 -0
index 1acb6ace1680..d5e1430bcdca 100755
@@ -73,3 +73,6 @@ echo
 echo
 ./futex_wait_uninitialized_heap $COLOR
 ./futex_wait_private_mapped_file $COLOR
+
+echo
+./futex_wait $COLOR
Signature · 1 line
2.31.1
merge bot Applied
#2 lore raw

[tip: locking/core] selftests: futex: Add futex wait test

The following commit has been merged into the locking/core branch of tip:

The following commit has been merged into the locking/core branch of tip:

Commit-ID:     c3d128581f64a9b3729e697a63760ff0a2c4a8fe
Gitweb:        https://git.kernel.org/tip/c3d128581f64a9b3729e697a63760ff0a2c4a8fe
Author:        André Almeida <[email protected]>
AuthorDate:    Mon, 31 May 2021 13:50:35 -03:00
Committer:     Thomas Gleixner <[email protected]>
CommitterDate: Tue, 22 Jun 2021 11:20:15 +02:00

selftests: futex: Add futex wait test

There are three different strategies to uniquely identify a futex in the kernel:

- Private futexes: uses the pointer to mm_struct and the page address

- Shared futexes: checks if the page containing the address is a PageAnon:
- If it is, uses the same data as a private futexes
- If it isn't, uses an inode sequence number from struct inode and the page's index

Create a selftest to check those three paths and basic wait/wake mechanism.

---
 tools/testing/selftests/futex/functional/.gitignore   |   1 +-
 tools/testing/selftests/futex/functional/Makefile     |   3 +-
 tools/testing/selftests/futex/functional/futex_wait.c | 171 +++++++++-
 tools/testing/selftests/futex/functional/run.sh       |   3 +-
 4 files changed, 177 insertions(+), 1 deletion(-)
 create mode 100644 tools/testing/selftests/futex/functional/futex_wait.c
tools/testing/selftests/futex/functional/.gitignore +1 -0
index 0efcd49..bd24699 100644
@@ -6,3 +6,4 @@ futex_wait_private_mapped_file
 futex_wait_timeout
 futex_wait_uninitialized_heap
 futex_wait_wouldblock
+futex_wait
tools/testing/selftests/futex/functional/Makefile +2 -1
index 1d2b3b2..20a5b4a 100644
@@ -15,7 +15,8 @@ TEST_GEN_FILES := \
 	futex_requeue_pi_signal_restart \
 	futex_requeue_pi_mismatched_ops \
 	futex_wait_uninitialized_heap \
-	futex_wait_private_mapped_file
+	futex_wait_private_mapped_file \
+	futex_wait
 
 TEST_PROGS := run.sh
 
tools/testing/selftests/futex/functional/futex_wait.c new file +171 -0

171 lines not on this page · raw message

tools/testing/selftests/futex/functional/run.sh +3 -0
index 1acb6ac..d5e1430 100755
@@ -73,3 +73,6 @@ echo
 echo
 ./futex_wait_uninitialized_heap $COLOR
 ./futex_wait_private_mapped_file $COLOR
+
+echo
+./futex_wait $COLOR
#3 lore raw

PATCH 2/2 selftests: futex: Add futex compare requeue test

In reply to André Almeida

Add testing for futex_cmp_requeue(). The first test just requeue from one waiter to another one, and wake it. The second performs both wake and requeue, and we check return values to see if the operation woke/requeued the expected number of waiters.

---
 .../selftests/futex/functional/.gitignore     |   1 +
 .../selftests/futex/functional/Makefile       |   3 +-
 .../futex/functional/futex_requeue.c          | 136 ++++++++++++++++++
 .../testing/selftests/futex/functional/run.sh |   3 +
 4 files changed, 142 insertions(+), 1 deletion(-)
 create mode 100644 tools/testing/selftests/futex/functional/futex_requeue.c
tools/testing/selftests/futex/functional/.gitignore +1 -0
index bd24699bacc9..0e78b49d0f2f 100644
@@ -7,3 +7,4 @@ futex_wait_timeout
 futex_wait_uninitialized_heap
 futex_wait_wouldblock
 futex_wait
+futex_requeue
tools/testing/selftests/futex/functional/Makefile +2 -1
index 20a5b4a1bc87..bd1fec59e010 100644
@@ -16,7 +16,8 @@ TEST_GEN_FILES := \
 	futex_requeue_pi_mismatched_ops \
 	futex_wait_uninitialized_heap \
 	futex_wait_private_mapped_file \
-	futex_wait
+	futex_wait \
+	futex_requeue
 
 TEST_PROGS := run.sh
 
tools/testing/selftests/futex/functional/futex_requeue.c new file +136 -0

136 lines not on this page · raw message

tools/testing/selftests/futex/functional/run.sh +3 -0
index d5e1430bcdca..11a9d62290f5 100755
@@ -76,3 +76,6 @@ echo
 
 echo
 ./futex_wait $COLOR
+
+echo
+./futex_requeue $COLOR
Signature · 1 line
2.31.1
merge bot Applied
#4 lore raw

[tip: locking/core] selftests: futex: Add futex compare requeue test

The following commit has been merged into the locking/core branch of tip:

The following commit has been merged into the locking/core branch of tip:

Commit-ID:     7cb5dd8e2c8ce2b8f778f37cfd8bb955d663d16d
Gitweb:        https://git.kernel.org/tip/7cb5dd8e2c8ce2b8f778f37cfd8bb955d663d16d
Author:        André Almeida <[email protected]>
AuthorDate:    Mon, 31 May 2021 13:50:36 -03:00
Committer:     Thomas Gleixner <[email protected]>
CommitterDate: Tue, 22 Jun 2021 11:20:16 +02:00

selftests: futex: Add futex compare requeue test

Add testing for futex_cmp_requeue(). The first test just requeues from one waiter to another one, and wakes it. The second performs both wake and requeue, and checks the return values to see if the operation woke/requeued the expected number of waiters.

---
 tools/testing/selftests/futex/functional/.gitignore      |   1 +-
 tools/testing/selftests/futex/functional/Makefile        |   3 +-
 tools/testing/selftests/futex/functional/futex_requeue.c | 136 +++++++-
 tools/testing/selftests/futex/functional/run.sh          |   3 +-
 4 files changed, 142 insertions(+), 1 deletion(-)
 create mode 100644 tools/testing/selftests/futex/functional/futex_requeue.c
tools/testing/selftests/futex/functional/.gitignore +1 -0
index bd24699..0e78b49 100644
@@ -7,3 +7,4 @@ futex_wait_timeout
 futex_wait_uninitialized_heap
 futex_wait_wouldblock
 futex_wait
+futex_requeue
tools/testing/selftests/futex/functional/Makefile +2 -1
index 20a5b4a..bd1fec5 100644
@@ -16,7 +16,8 @@ TEST_GEN_FILES := \
 	futex_requeue_pi_mismatched_ops \
 	futex_wait_uninitialized_heap \
 	futex_wait_private_mapped_file \
-	futex_wait
+	futex_wait \
+	futex_requeue
 
 TEST_PROGS := run.sh
 
tools/testing/selftests/futex/functional/futex_requeue.c new file +136 -0

136 lines not on this page · raw message

tools/testing/selftests/futex/functional/run.sh +3 -0
index d5e1430..11a9d62 100755
@@ -76,3 +76,6 @@ echo
 
 echo
 ./futex_wait $COLOR
+
+echo
+./futex_requeue $COLOR
reviewer Acked-by on the v1 series
#5 lore raw
In reply to André Almeida
Quoted 3 lines · Andr� Almeida

This patchset expands test coverage for futex, implementing two new
selftests: one for testing different types of futexes and one for the requeue operation.

So these cases are covered by LTP, but I have no objection for also having them in the kernel selftests too.