@@ -61,10 +61,8 @@ static void create_max_threads(void *futex_ptr)
61
61
thread_args [i ].flags = FUTEX2_SIZE_U32 | FUTEX_PRIVATE_FLAG | FUTEX2_NUMA ;
62
62
thread_args [i ].result = 0 ;
63
63
ret = pthread_create (& threads [i ], NULL , thread_lock_fn , & thread_args [i ]);
64
- if (ret ) {
65
- error ("pthread_create failed\n" , errno );
66
- exit (1 );
67
- }
64
+ if (ret )
65
+ ksft_exit_fail_msg ("pthread_create failed\n" );
68
66
}
69
67
}
70
68
@@ -74,10 +72,8 @@ static void join_max_threads(void)
74
72
75
73
for (i = 0 ; i < MAX_THREADS ; i ++ ) {
76
74
ret = pthread_join (threads [i ], NULL );
77
- if (ret ) {
78
- error ("pthread_join failed for thread %d\n" , errno , i );
79
- exit (1 );
80
- }
75
+ if (ret )
76
+ ksft_exit_fail_msg ("pthread_join failed for thread %d\n" , i );
81
77
}
82
78
}
83
79
@@ -95,12 +91,12 @@ static void __test_futex(void *futex_ptr, int must_fail, unsigned int futex_flag
95
91
if (must_fail ) {
96
92
if (ret < 0 )
97
93
break ;
98
- fail ( "Should fail, but didn't\n");
99
- exit ( 1 );
94
+ ksft_exit_fail_msg ( "futex2_wake(%d, 0x%x) should fail, but didn't\n",
95
+ to_wake , futex_flags );
100
96
}
101
97
if (ret < 0 ) {
102
- error ("Failed futex2_wake(%d) \n" , errno , to_wake );
103
- exit ( 1 );
98
+ ksft_exit_fail_msg ("Failed futex2_wake(%d, 0x%x): %m \n" ,
99
+ to_wake , futex_flags );
104
100
}
105
101
if (!ret )
106
102
usleep (50 );
@@ -111,16 +107,17 @@ static void __test_futex(void *futex_ptr, int must_fail, unsigned int futex_flag
111
107
112
108
for (i = 0 ; i < MAX_THREADS ; i ++ ) {
113
109
if (must_fail && thread_args [i ].result != -1 ) {
114
- fail ("Thread %d should fail but succeeded (%d)\n" , i , thread_args [i ].result );
110
+ ksft_print_msg ("Thread %d should fail but succeeded (%d)\n" ,
111
+ i , thread_args [i ].result );
115
112
need_exit = 1 ;
116
113
}
117
114
if (!must_fail && thread_args [i ].result != 0 ) {
118
- fail ("Thread %d failed (%d)\n" , i , thread_args [i ].result );
115
+ ksft_print_msg ("Thread %d failed (%d)\n" , i , thread_args [i ].result );
119
116
need_exit = 1 ;
120
117
}
121
118
}
122
119
if (need_exit )
123
- exit ( 1 );
120
+ ksft_exit_fail_msg ( "Aborting due to earlier errors.\n" );
124
121
}
125
122
126
123
static void test_futex (void * futex_ptr , int must_fail )
@@ -167,41 +164,41 @@ int main(int argc, char *argv[])
167
164
}
168
165
}
169
166
167
+ ksft_print_header ();
168
+ ksft_set_plan (1 );
169
+
170
170
mem_size = sysconf (_SC_PAGE_SIZE );
171
171
futex_ptr = mmap (NULL , mem_size , PROT_READ | PROT_WRITE , MAP_PRIVATE | MAP_ANONYMOUS , 0 , 0 );
172
- if (futex_ptr == MAP_FAILED ) {
173
- error ("mmap() for %d bytes failed\n" , errno , mem_size );
174
- return 1 ;
175
- }
172
+ if (futex_ptr == MAP_FAILED )
173
+ ksft_exit_fail_msg ("mmap() for %d bytes failed\n" , mem_size );
174
+
176
175
futex_numa = futex_ptr ;
177
176
178
- info ("Regular test\n" );
177
+ ksft_print_msg ("Regular test\n" );
179
178
futex_numa -> futex = 0 ;
180
179
futex_numa -> numa = FUTEX_NO_NODE ;
181
180
test_futex (futex_ptr , 0 );
182
181
183
- if (futex_numa -> numa == FUTEX_NO_NODE ) {
184
- fail ("NUMA node is left unitiliazed\n" );
185
- return 1 ;
186
- }
182
+ if (futex_numa -> numa == FUTEX_NO_NODE )
183
+ ksft_exit_fail_msg ("NUMA node is left unitiliazed\n" );
187
184
188
- info ("Memory too small\n" );
185
+ ksft_print_msg ("Memory too small\n" );
189
186
test_futex (futex_ptr + mem_size - 4 , 1 );
190
187
191
- info ("Memory out of range\n" );
188
+ ksft_print_msg ("Memory out of range\n" );
192
189
test_futex (futex_ptr + mem_size , 1 );
193
190
194
191
futex_numa -> numa = FUTEX_NO_NODE ;
195
192
mprotect (futex_ptr , mem_size , PROT_READ );
196
- info ("Memory, RO\n" );
193
+ ksft_print_msg ("Memory, RO\n" );
197
194
test_futex (futex_ptr , 1 );
198
195
199
196
mprotect (futex_ptr , mem_size , PROT_NONE );
200
- info ("Memory, no access\n" );
197
+ ksft_print_msg ("Memory, no access\n" );
201
198
test_futex (futex_ptr , 1 );
202
199
203
200
mprotect (futex_ptr , mem_size , PROT_READ | PROT_WRITE );
204
- info ("Memory back to RW\n" );
201
+ ksft_print_msg ("Memory back to RW\n" );
205
202
test_futex (futex_ptr , 0 );
206
203
207
204
/* MPOL test. Does not work as expected */
@@ -213,20 +210,22 @@ int main(int argc, char *argv[])
213
210
ret = mbind (futex_ptr , mem_size , MPOL_BIND , & nodemask ,
214
211
sizeof (nodemask ) * 8 , 0 );
215
212
if (ret == 0 ) {
216
- info ("Node %d test\n" , i );
213
+ ksft_print_msg ("Node %d test\n" , i );
217
214
futex_numa -> futex = 0 ;
218
215
futex_numa -> numa = FUTEX_NO_NODE ;
219
216
220
217
ret = futex2_wake (futex_ptr , 0 , FUTEX2_SIZE_U32 | FUTEX_PRIVATE_FLAG | FUTEX2_NUMA | FUTEX2_MPOL );
221
218
if (ret < 0 )
222
- error ("Failed to wake 0 with MPOL. \n" , errno );
219
+ ksft_test_result_fail ("Failed to wake 0 with MPOL: %m \n" );
223
220
if (0 )
224
221
test_futex_mpol (futex_numa , 0 );
225
222
if (futex_numa -> numa != i ) {
226
- fail ("Returned NUMA node is %d expected %d\n" ,
227
- futex_numa -> numa , i );
223
+ ksft_test_result_fail ("Returned NUMA node is %d expected %d\n" ,
224
+ futex_numa -> numa , i );
228
225
}
229
226
}
230
227
}
228
+ ksft_test_result_pass ("NUMA MPOL tests passed\n" );
229
+ ksft_finished ();
231
230
return 0 ;
232
231
}
0 commit comments