Skip to content

Commit d159493

Browse files
Yuwen Chengregkh
authored andcommitted
selftests/futex: Fix incorrect result reporting of futex_requeue test item
[ Upstream commit d317e2e ] When using the TEST_HARNESS_MAIN macro definition to declare the main function, it is required to use the EXPECT*() and ASSERT*() macros in conjunction and not ksft_test_result_*(). Otherwise, even if a test item fails, the test will still return a success result because ksft_test_result_*() does not affect the test harness state. Convert the code to use EXPECT/ASSERT() variants, which ensures that the overall test result is fail if one of the EXPECT()s fails. [ tglx: Massaged change log to explain _why_ ksft_test_result*() is the wrong choice ] Fixes: f341a20 ("selftests/futex: Refactor futex_requeue with kselftest_harness.h") Signed-off-by: Yuwen Chen <ywen.chen@foxmail.com> Signed-off-by: Thomas Gleixner <tglx@kernel.org> Link: https://patch.msgid.link/tencent_51851B741CC4B5EC9C22AFF70BA82BB60805@qq.com Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent eaa8457 commit d159493

1 file changed

Lines changed: 8 additions & 41 deletions

File tree

tools/testing/selftests/futex/functional/futex_requeue.c

Lines changed: 8 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -34,73 +34,40 @@ TEST(requeue_single)
3434
volatile futex_t _f1 = 0;
3535
volatile futex_t f2 = 0;
3636
pthread_t waiter[10];
37-
int res;
3837

3938
f1 = &_f1;
4039

4140
/*
4241
* Requeue a waiter from f1 to f2, and wake f2.
4342
*/
44-
if (pthread_create(&waiter[0], NULL, waiterfn, NULL))
45-
ksft_exit_fail_msg("pthread_create failed\n");
43+
ASSERT_EQ(0, pthread_create(&waiter[0], NULL, waiterfn, NULL));
4644

4745
usleep(WAKE_WAIT_US);
4846

49-
ksft_print_dbg_msg("Requeuing 1 futex from f1 to f2\n");
50-
res = futex_cmp_requeue(f1, 0, &f2, 0, 1, 0);
51-
if (res != 1)
52-
ksft_test_result_fail("futex_requeue simple returned: %d %s\n",
53-
res ? errno : res,
54-
res ? strerror(errno) : "");
55-
56-
ksft_print_dbg_msg("Waking 1 futex at f2\n");
57-
res = futex_wake(&f2, 1, 0);
58-
if (res != 1) {
59-
ksft_test_result_fail("futex_requeue simple returned: %d %s\n",
60-
res ? errno : res,
61-
res ? strerror(errno) : "");
62-
} else {
63-
ksft_test_result_pass("futex_requeue simple succeeds\n");
64-
}
47+
EXPECT_EQ(1, futex_cmp_requeue(f1, 0, &f2, 0, 1, 0));
48+
EXPECT_EQ(1, futex_wake(&f2, 1, 0));
6549
}
6650

6751
TEST(requeue_multiple)
6852
{
6953
volatile futex_t _f1 = 0;
7054
volatile futex_t f2 = 0;
7155
pthread_t waiter[10];
72-
int res, i;
56+
int i;
7357

7458
f1 = &_f1;
7559

7660
/*
7761
* Create 10 waiters at f1. At futex_requeue, wake 3 and requeue 7.
7862
* At futex_wake, wake INT_MAX (should be exactly 7).
7963
*/
80-
for (i = 0; i < 10; i++) {
81-
if (pthread_create(&waiter[i], NULL, waiterfn, NULL))
82-
ksft_exit_fail_msg("pthread_create failed\n");
83-
}
64+
for (i = 0; i < 10; i++)
65+
ASSERT_EQ(0, pthread_create(&waiter[i], NULL, waiterfn, NULL));
8466

8567
usleep(WAKE_WAIT_US);
8668

87-
ksft_print_dbg_msg("Waking 3 futexes at f1 and requeuing 7 futexes from f1 to f2\n");
88-
res = futex_cmp_requeue(f1, 0, &f2, 3, 7, 0);
89-
if (res != 10) {
90-
ksft_test_result_fail("futex_requeue many returned: %d %s\n",
91-
res ? errno : res,
92-
res ? strerror(errno) : "");
93-
}
94-
95-
ksft_print_dbg_msg("Waking INT_MAX futexes at f2\n");
96-
res = futex_wake(&f2, INT_MAX, 0);
97-
if (res != 7) {
98-
ksft_test_result_fail("futex_requeue many returned: %d %s\n",
99-
res ? errno : res,
100-
res ? strerror(errno) : "");
101-
} else {
102-
ksft_test_result_pass("futex_requeue many succeeds\n");
103-
}
69+
EXPECT_EQ(10, futex_cmp_requeue(f1, 0, &f2, 3, 7, 0));
70+
EXPECT_EQ(7, futex_wake(&f2, INT_MAX, 0));
10471
}
10572

10673
TEST_HARNESS_MAIN

0 commit comments

Comments
 (0)