Skip to content

Commit 9f07fb3

Browse files
committed
selftest/futex: Make the error check more precise for futex_numa_mpol
JIRA: https://issues.redhat.com/browse/RHEL-101190 commit c1c8634 Author: André Almeida <andrealmeid@igalia.com> Date: Mon, 15 Sep 2025 23:26:28 +0200 selftest/futex: Make the error check more precise for futex_numa_mpol Instead of just checking if the syscall failed as expected, check as well if the returned error code matches the expected error code. [ bigeasy: reword the commmit message ] Signed-off-by: André Almeida <andrealmeid@igalia.com> Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Reviewed-by: Waiman Long <longman@redhat.com> Signed-off-by: Waiman Long <longman@redhat.com>
1 parent 4863d37 commit 9f07fb3

File tree

1 file changed

+21
-15
lines changed

1 file changed

+21
-15
lines changed

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

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ static void join_max_threads(void)
7777
}
7878
}
7979

80-
static void __test_futex(void *futex_ptr, int must_fail, unsigned int futex_flags)
80+
static void __test_futex(void *futex_ptr, int err_value, unsigned int futex_flags)
8181
{
8282
int to_wake, ret, i, need_exit = 0;
8383

@@ -88,11 +88,17 @@ static void __test_futex(void *futex_ptr, int must_fail, unsigned int futex_flag
8888

8989
do {
9090
ret = futex2_wake(futex_ptr, to_wake, futex_flags);
91-
if (must_fail) {
92-
if (ret < 0)
93-
break;
94-
ksft_exit_fail_msg("futex2_wake(%d, 0x%x) should fail, but didn't\n",
95-
to_wake, futex_flags);
91+
92+
if (err_value) {
93+
if (ret >= 0)
94+
ksft_exit_fail_msg("futex2_wake(%d, 0x%x) should fail, but didn't\n",
95+
to_wake, futex_flags);
96+
97+
if (errno != err_value)
98+
ksft_exit_fail_msg("futex2_wake(%d, 0x%x) expected error was %d, but returned %d (%s)\n",
99+
to_wake, futex_flags, err_value, errno, strerror(errno));
100+
101+
break;
96102
}
97103
if (ret < 0) {
98104
ksft_exit_fail_msg("Failed futex2_wake(%d, 0x%x): %m\n",
@@ -106,12 +112,12 @@ static void __test_futex(void *futex_ptr, int must_fail, unsigned int futex_flag
106112
join_max_threads();
107113

108114
for (i = 0; i < MAX_THREADS; i++) {
109-
if (must_fail && thread_args[i].result != -1) {
115+
if (err_value && thread_args[i].result != -1) {
110116
ksft_print_msg("Thread %d should fail but succeeded (%d)\n",
111117
i, thread_args[i].result);
112118
need_exit = 1;
113119
}
114-
if (!must_fail && thread_args[i].result != 0) {
120+
if (!err_value && thread_args[i].result != 0) {
115121
ksft_print_msg("Thread %d failed (%d)\n", i, thread_args[i].result);
116122
need_exit = 1;
117123
}
@@ -120,14 +126,14 @@ static void __test_futex(void *futex_ptr, int must_fail, unsigned int futex_flag
120126
ksft_exit_fail_msg("Aborting due to earlier errors.\n");
121127
}
122128

123-
static void test_futex(void *futex_ptr, int must_fail)
129+
static void test_futex(void *futex_ptr, int err_value)
124130
{
125-
__test_futex(futex_ptr, must_fail, FUTEX2_SIZE_U32 | FUTEX_PRIVATE_FLAG | FUTEX2_NUMA);
131+
__test_futex(futex_ptr, err_value, FUTEX2_SIZE_U32 | FUTEX_PRIVATE_FLAG | FUTEX2_NUMA);
126132
}
127133

128-
static void test_futex_mpol(void *futex_ptr, int must_fail)
134+
static void test_futex_mpol(void *futex_ptr, int err_value)
129135
{
130-
__test_futex(futex_ptr, must_fail, FUTEX2_SIZE_U32 | FUTEX_PRIVATE_FLAG | FUTEX2_NUMA | FUTEX2_MPOL);
136+
__test_futex(futex_ptr, err_value, FUTEX2_SIZE_U32 | FUTEX_PRIVATE_FLAG | FUTEX2_NUMA | FUTEX2_MPOL);
131137
}
132138

133139
static void usage(char *prog)
@@ -184,16 +190,16 @@ int main(int argc, char *argv[])
184190

185191
/* FUTEX2_NUMA futex must be 8-byte aligned */
186192
ksft_print_msg("Mis-aligned futex\n");
187-
test_futex(futex_ptr + mem_size - 4, 1);
193+
test_futex(futex_ptr + mem_size - 4, EINVAL);
188194

189195
futex_numa->numa = FUTEX_NO_NODE;
190196
mprotect(futex_ptr, mem_size, PROT_READ);
191197
ksft_print_msg("Memory, RO\n");
192-
test_futex(futex_ptr, 1);
198+
test_futex(futex_ptr, EFAULT);
193199

194200
mprotect(futex_ptr, mem_size, PROT_NONE);
195201
ksft_print_msg("Memory, no access\n");
196-
test_futex(futex_ptr, 1);
202+
test_futex(futex_ptr, EFAULT);
197203

198204
mprotect(futex_ptr, mem_size, PROT_READ | PROT_WRITE);
199205
ksft_print_msg("Memory back to RW\n");

0 commit comments

Comments
 (0)