[PATCH] selftests/futex: Dynamically skip unsupported tests

From: Wake Liu

Date: Wed Jun 24 2026 - 03:04:10 EST


Some new futex tests rely on kernel features that may not be supported
on all configurations (e.g., FUTEX2_NUMA or PR_FUTEX_HASH).
Currently, these tests fail with EINVAL when the features are missing.

This patch adds dynamic skip logic to:
1. futex_priv_hash: Skip if PR_FUTEX_HASH returns ENOSYS or EINVAL.
2. futex_numa_mpol: Skip if futex2 or FUTEX2_NUMA returns ENOSYS or EINVAL.

This allows the tests to pass (as SKIPPED) on kernels without support,
while preserving coverage on configurations that do support them.

Signed-off-by: Wake Liu <wakel@xxxxxxxxxx>
---
tools/testing/selftests/futex/functional/futex_numa_mpol.c | 2 ++
tools/testing/selftests/futex/functional/futex_priv_hash.c | 2 ++
2 files changed, 4 insertions(+)

diff --git a/tools/testing/selftests/futex/functional/futex_numa_mpol.c b/tools/testing/selftests/futex/functional/futex_numa_mpol.c
index 78c0f7a59e17..d215acf88120 100644
--- a/tools/testing/selftests/futex/functional/futex_numa_mpol.c
+++ b/tools/testing/selftests/futex/functional/futex_numa_mpol.c
@@ -103,6 +103,8 @@ static void __test_futex(void *futex_ptr, int err_value, unsigned int futex_flag
break;
}
if (ret < 0) {
+ if (errno == ENOSYS || (errno == EINVAL && (futex_flags & FUTEX2_NUMA)))
+ ksft_exit_skip("futex2 or FUTEX2_NUMA not supported by kernel\n");
ksft_exit_fail_msg("Failed futex2_wake(%d, 0x%x): %m\n",
to_wake, futex_flags);
}
diff --git a/tools/testing/selftests/futex/functional/futex_priv_hash.c b/tools/testing/selftests/futex/functional/futex_priv_hash.c
index e8079d7c65e8..27c3ea5ff3ed 100644
--- a/tools/testing/selftests/futex/functional/futex_priv_hash.c
+++ b/tools/testing/selftests/futex/functional/futex_priv_hash.c
@@ -145,6 +145,8 @@ TEST(priv_hash)
}
/* First thread, expect to be 0, not yet initialized */
ret = futex_hash_slots_get();
+ if (ret < 0 && errno == EINVAL)
+ ksft_exit_skip("PR_FUTEX_HASH not supported by kernel\n");
if (ret != 0)
ksft_exit_fail_msg("futex_hash_slots_get() failed: %d, %m\n", ret);

--
2.55.0.rc0.799.gd6f94ed593-goog