mirror of
https://github.com/linux-msm/laptops-kernel.git
synced 2026-08-13 14:19:53 -07:00
selftests/futex: Migrate futex_requeue to harness
Migrate futex_requeue test to the kselftest harness framework, removing mixed legacy ksft_* API usages and ensuring proper thread joining. [ 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-2-wakel@google.com
This commit is contained in:
committed by
Thomas Gleixner
parent
78834d8b9c
commit
d0f7df9bb7
@@ -5,8 +5,9 @@
|
|||||||
* futex cmp requeue test by André Almeida <andrealmeid@collabora.com>
|
* futex cmp requeue test by André Almeida <andrealmeid@collabora.com>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <pthread.h>
|
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
|
#include <pthread.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
#include "futextest.h"
|
#include "futextest.h"
|
||||||
#include "kselftest_harness.h"
|
#include "kselftest_harness.h"
|
||||||
@@ -18,13 +19,18 @@ volatile futex_t *f1;
|
|||||||
|
|
||||||
void *waiterfn(void *arg)
|
void *waiterfn(void *arg)
|
||||||
{
|
{
|
||||||
|
struct __test_metadata *_metadata = (struct __test_metadata *)arg;
|
||||||
struct timespec to;
|
struct timespec to;
|
||||||
|
int res;
|
||||||
|
|
||||||
to.tv_sec = 0;
|
to.tv_sec = 0;
|
||||||
to.tv_nsec = timeout_ns;
|
to.tv_nsec = timeout_ns;
|
||||||
|
|
||||||
if (futex_wait(f1, *f1, &to, 0))
|
res = futex_wait(f1, *f1, &to, 0);
|
||||||
printf("waiter failed errno %d\n", errno);
|
if (res) {
|
||||||
|
EXPECT_EQ(res, 0)
|
||||||
|
TH_LOG("waiter failed errno %d: %s", errno, strerror(errno));
|
||||||
|
}
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@@ -40,12 +46,15 @@ TEST(requeue_single)
|
|||||||
/*
|
/*
|
||||||
* Requeue a waiter from f1 to f2, and wake f2.
|
* 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);
|
usleep(WAKE_WAIT_US);
|
||||||
|
|
||||||
EXPECT_EQ(1, futex_cmp_requeue(f1, 0, &f2, 0, 1, 0));
|
EXPECT_EQ(futex_cmp_requeue(f1, 0, &f2, 0, 1, 0), 1);
|
||||||
EXPECT_EQ(1, futex_wake(&f2, 1, 0));
|
EXPECT_EQ(futex_wake(&f2, 1, 0), 1);
|
||||||
|
|
||||||
|
pthread_join(waiter[0], NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(requeue_multiple)
|
TEST(requeue_multiple)
|
||||||
@@ -61,13 +70,18 @@ TEST(requeue_multiple)
|
|||||||
* Create 10 waiters at f1. At futex_requeue, wake 3 and requeue 7.
|
* Create 10 waiters at f1. At futex_requeue, wake 3 and requeue 7.
|
||||||
* At futex_wake, wake INT_MAX (should be exactly 7).
|
* At futex_wake, wake INT_MAX (should be exactly 7).
|
||||||
*/
|
*/
|
||||||
for (i = 0; i < 10; i++)
|
for (i = 0; i < 10; i++) {
|
||||||
ASSERT_EQ(0, pthread_create(&waiter[i], NULL, waiterfn, NULL));
|
ASSERT_EQ(pthread_create(&waiter[i], NULL, waiterfn, _metadata), 0)
|
||||||
|
TH_LOG("pthread_create failed for waiter %d", i);
|
||||||
|
}
|
||||||
|
|
||||||
usleep(WAKE_WAIT_US);
|
usleep(WAKE_WAIT_US);
|
||||||
|
|
||||||
EXPECT_EQ(10, futex_cmp_requeue(f1, 0, &f2, 3, 7, 0));
|
EXPECT_EQ(futex_cmp_requeue(f1, 0, &f2, 3, 7, 0), 10);
|
||||||
EXPECT_EQ(7, futex_wake(&f2, INT_MAX, 0));
|
EXPECT_EQ(futex_wake(&f2, INT_MAX, 0), 7);
|
||||||
|
|
||||||
|
for (i = 0; i < 10; i++)
|
||||||
|
pthread_join(waiter[i], NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_HARNESS_MAIN
|
TEST_HARNESS_MAIN
|
||||||
|
|||||||
Reference in New Issue
Block a user