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 <wakel@google.com>
Signed-off-by: Thomas Gleixner <tglx@kernel.org>
Link: https://patch.msgid.link/20260601065126.3623867-4-wakel@google.com
This commit is contained in:
Wake Liu
2026-07-05 21:49:18 +02:00
committed by Thomas Gleixner
parent b7d837c2d4
commit 4559deb738
@@ -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