[Devel] [PATCH hci-8.1 v2 7/7] selftests/futex: fail futex_waitv when the waiter failed
Eva Kurchatova
eva.kurchatova at virtuozzo.com
Tue Oct 27 18:51:33 MSK 2026
The waiter thread records a failed futex_waitv() with
ksft_test_result_fail(), while the main thread reports the same
subtest as passed and exits with the status it collected, so a waiter
that returned the wrong index or an error ended in a pass; and the
main thread never waited for the waiter, so its result could land
after the verdict. Have the waiter return its status instead, join it
after each wake and report one result for the subtest.
https://virtuozzo.atlassian.net/browse/VSTOR-134205
Feature: fix selftests
Signed-off-by: Eva Kurchatova <eva.kurchatova at virtuozzo.com>
---
.../selftests/futex/functional/futex_waitv.c | 28 ++++++++++++++++---
1 file changed, 24 insertions(+), 4 deletions(-)
diff --git a/tools/testing/selftests/futex/functional/futex_waitv.c b/tools/testing/selftests/futex/functional/futex_waitv.c
index a94337f677e1..a9de197637ea 100644
--- a/tools/testing/selftests/futex/functional/futex_waitv.c
+++ b/tools/testing/selftests/futex/functional/futex_waitv.c
@@ -47,16 +47,28 @@ void *waiterfn(void *arg)
res = futex_waitv(waitv, NR_FUTEXES, 0, &to, CLOCK_MONOTONIC);
if (res < 0) {
- ksft_test_result_fail("futex_waitv returned: %d %s\n",
- errno, strerror(errno));
+ ksft_print_msg("futex_waitv returned: %d %s\n",
+ errno, strerror(errno));
+ return (void *)1;
} else if (res != NR_FUTEXES - 1) {
- ksft_test_result_fail("futex_waitv returned: %d, expecting %d\n",
- res, NR_FUTEXES - 1);
+ ksft_print_msg("futex_waitv returned: %d, expecting %d\n",
+ res, NR_FUTEXES - 1);
+ return (void *)1;
}
return NULL;
}
+static int join_waiter(pthread_t waiter)
+{
+ void *failed;
+
+ /* A waiter that cannot be joined counts as failed */
+ if (pthread_join(waiter, &failed))
+ return 1;
+ return failed != NULL;
+}
+
int main(int argc, char *argv[])
{
pthread_t waiter;
@@ -104,6 +116,10 @@ int main(int argc, char *argv[])
ksft_test_result_fail("futex_wake private returned: %d %s\n",
res ? errno : res,
res ? strerror(errno) : "");
+ join_waiter(waiter);
+ ret = RET_FAIL;
+ } else if (join_waiter(waiter)) {
+ ksft_test_result_fail("futex_waitv private\n");
ret = RET_FAIL;
} else {
ksft_test_result_pass("futex_waitv private\n");
@@ -137,6 +153,10 @@ int main(int argc, char *argv[])
ksft_test_result_fail("futex_wake shared returned: %d %s\n",
res ? errno : res,
res ? strerror(errno) : "");
+ join_waiter(waiter);
+ ret = RET_FAIL;
+ } else if (join_waiter(waiter)) {
+ ksft_test_result_fail("futex_waitv shared\n");
ret = RET_FAIL;
} else {
ksft_test_result_pass("futex_waitv shared\n");
--
2.56.0
More information about the Devel
mailing list