Migrate futex_requeue test to the kselftest harness framework,
removing mixed legacy ksft_* API usages and ensuring proper thread joining.

Signed-off-by: Wake Liu <[email protected]>
---
 .../futex/functional/futex_requeue.c          | 32 +++++++++++++------
 1 file changed, 23 insertions(+), 9 deletions(-)

diff --git a/tools/testing/selftests/futex/functional/futex_requeue.c 
b/tools/testing/selftests/futex/functional/futex_requeue.c
index dcf0d5f2f312..76f0eb6756f8 100644
--- a/tools/testing/selftests/futex/functional/futex_requeue.c
+++ b/tools/testing/selftests/futex/functional/futex_requeue.c
@@ -7,6 +7,7 @@
 
 #include <pthread.h>
 #include <limits.h>
+#include <string.h>
 
 #include "futextest.h"
 #include "kselftest_harness.h"
@@ -18,13 +19,18 @@ volatile futex_t *f1;
 
 void *waiterfn(void *arg)
 {
+       struct __test_metadata *_metadata = (struct __test_metadata *)arg;
        struct timespec to;
+       int res;
 
        to.tv_sec = 0;
        to.tv_nsec = timeout_ns;
 
-       if (futex_wait(f1, *f1, &to, 0))
-               printf("waiter failed errno %d\n", errno);
+       res = futex_wait(f1, *f1, &to, 0);
+       if (res) {
+               EXPECT_EQ(res, 0)
+                       TH_LOG("waiter failed errno %d: %s", errno, 
strerror(errno));
+       }
 
        return NULL;
 }
@@ -40,12 +46,15 @@ TEST(requeue_single)
        /*
         * Requeue a waiter from f1 to f2, and wake f2.
         */
-       ASSERT_EQ(0, pthread_create(&waiter[0], NULL, waiterfn, NULL));
+       ASSERT_EQ(pthread_create(&waiter[0], NULL, waiterfn, _metadata), 0)
+               TH_LOG("pthread_create failed");
 
        usleep(WAKE_WAIT_US);
 
-       EXPECT_EQ(1, futex_cmp_requeue(f1, 0, &f2, 0, 1, 0));
-       EXPECT_EQ(1, futex_wake(&f2, 1, 0));
+       EXPECT_EQ(futex_cmp_requeue(f1, 0, &f2, 0, 1, 0), 1);
+       EXPECT_EQ(futex_wake(&f2, 1, 0), 1);
+
+       pthread_join(waiter[0], NULL);
 }
 
 TEST(requeue_multiple)
@@ -61,13 +70,18 @@ TEST(requeue_multiple)
         * Create 10 waiters at f1. At futex_requeue, wake 3 and requeue 7.
         * At futex_wake, wake INT_MAX (should be exactly 7).
         */
-       for (i = 0; i < 10; i++)
-               ASSERT_EQ(0, pthread_create(&waiter[i], NULL, waiterfn, NULL));
+       for (i = 0; i < 10; i++) {
+               ASSERT_EQ(pthread_create(&waiter[i], NULL, waiterfn, 
_metadata), 0)
+                       TH_LOG("pthread_create failed for waiter %d", i);
+       }
 
        usleep(WAKE_WAIT_US);
 
-       EXPECT_EQ(10, futex_cmp_requeue(f1, 0, &f2, 3, 7, 0));
-       EXPECT_EQ(7, futex_wake(&f2, INT_MAX, 0));
+       EXPECT_EQ(futex_cmp_requeue(f1, 0, &f2, 3, 7, 0), 10);
+       EXPECT_EQ(futex_wake(&f2, INT_MAX, 0), 7);
+
+       for (i = 0; i < 10; i++)
+               pthread_join(waiter[i], NULL);
 }
 
 TEST_HARNESS_MAIN
-- 
2.54.0.823.g6e5bcc1fc9-goog


Reply via email to