From 4559deb7382861b5e920bbccdf62c470384ab0ac Mon Sep 17 00:00:00 2001 From: Wake Liu Date: Mon, 1 Jun 2026 06:51:22 +0000 Subject: [PATCH] selftests/futex: Migrate futex_requeue_pi_mismatched_ops to harness Migrate futex_requeue_pi_mismatched_ops test to the kselftest harness framework, removing mixed legacy ksft_* API usages and passing test metadata to helper thread. [ tglx: Fixup coding style ] Signed-off-by: Wake Liu Signed-off-by: Thomas Gleixner Link: https://patch.msgid.link/20260601065126.3623867-4-wakel@google.com --- .../futex_requeue_pi_mismatched_ops.c | 41 +++++++++++-------- 1 file changed, 25 insertions(+), 16 deletions(-) diff --git a/tools/testing/selftests/futex/functional/futex_requeue_pi_mismatched_ops.c b/tools/testing/selftests/futex/functional/futex_requeue_pi_mismatched_ops.c index f686e605359c..35bb8a807bb9 100644 --- a/tools/testing/selftests/futex/functional/futex_requeue_pi_mismatched_ops.c +++ b/tools/testing/selftests/futex/functional/futex_requeue_pi_mismatched_ops.c @@ -29,14 +29,17 @@ futex_t f1 = FUTEX_INITIALIZER; futex_t f2 = FUTEX_INITIALIZER; -int child_ret = 0; +int child_ret; void *blocking_child(void *arg) { + struct __test_metadata *_metadata = (struct __test_metadata *)arg; + child_ret = futex_wait(&f1, f1, NULL, FUTEX_PRIVATE_FLAG); if (child_ret < 0) { child_ret = -errno; - ksft_exit_fail_msg("futex_wait\n"); + ASSERT_EQ(child_ret, 0) + TH_LOG("futex_wait failed: %s", strerror(errno)); } return (void *)&child_ret; } @@ -46,8 +49,8 @@ TEST(requeue_pi_mismatched_ops) pthread_t child; int ret; - if (pthread_create(&child, NULL, blocking_child, NULL)) - ksft_exit_fail_msg("pthread_create\n"); + ASSERT_EQ(pthread_create(&child, NULL, blocking_child, _metadata), 0) + TH_LOG("pthread_create failed"); /* Allow the child to block in the kernel. */ sleep(1); @@ -67,27 +70,33 @@ TEST(requeue_pi_mismatched_ops) * FUTEX_WAKE. */ ret = futex_wake(&f1, 1, FUTEX_PRIVATE_FLAG); - if (ret == 1) + if (ret == 1) { ret = 0; - else if (ret < 0) - ksft_exit_fail_msg("futex_wake\n"); - else - ksft_exit_fail_msg("futex_wake did not wake the child\n"); + } else if (ret < 0) { + ASSERT_GE(ret, 0) + TH_LOG("futex_wake failed: %s", strerror(errno)); + } else { + ASSERT_TRUE(0) + TH_LOG("futex_wake did not wake the child"); + } } else { - ksft_exit_fail_msg("futex_cmp_requeue_pi\n"); + ASSERT_TRUE(0) + TH_LOG("futex_cmp_requeue_pi failed with unexpected errno: %s", strerror(errno)); } } else if (ret > 0) { - ksft_test_result_fail("futex_cmp_requeue_pi failed to detect the mismatch\n"); + EXPECT_EQ(ret, 0) + TH_LOG("futex_cmp_requeue_pi failed to detect the mismatch"); } else { - ksft_exit_fail_msg("futex_cmp_requeue_pi found no waiters\n"); + ASSERT_TRUE(0) + TH_LOG("futex_cmp_requeue_pi found no waiters"); } pthread_join(child, NULL); - if (!ret && !child_ret) - ksft_test_result_pass("futex_requeue_pi_mismatched_ops passed\n"); - else - ksft_test_result_pass("futex_requeue_pi_mismatched_ops failed\n"); + EXPECT_EQ(ret, 0) + TH_LOG("Test failed: ret=%d", ret); + EXPECT_EQ(child_ret, 0) + TH_LOG("Child failed: child_ret=%d", child_ret); } TEST_HARNESS_MAIN