@@ -61,10 +61,8 @@ static void create_max_threads(void *futex_ptr)
6161 thread_args [i ].flags = FUTEX2_SIZE_U32 | FUTEX_PRIVATE_FLAG | FUTEX2_NUMA ;
6262 thread_args [i ].result = 0 ;
6363 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" );
6866 }
6967}
7068
@@ -74,10 +72,8 @@ static void join_max_threads(void)
7472
7573 for (i = 0 ; i < MAX_THREADS ; i ++ ) {
7674 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 );
8177 }
8278}
8379
@@ -95,12 +91,12 @@ static void __test_futex(void *futex_ptr, int must_fail, unsigned int futex_flag
9591 if (must_fail ) {
9692 if (ret < 0 )
9793 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 );
10096 }
10197 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 );
104100 }
105101 if (!ret )
106102 usleep (50 );
@@ -111,16 +107,17 @@ static void __test_futex(void *futex_ptr, int must_fail, unsigned int futex_flag
111107
112108 for (i = 0 ; i < MAX_THREADS ; i ++ ) {
113109 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 );
115112 need_exit = 1 ;
116113 }
117114 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 );
119116 need_exit = 1 ;
120117 }
121118 }
122119 if (need_exit )
123- exit ( 1 );
120+ ksft_exit_fail_msg ( "Aborting due to earlier errors.\n" );
124121}
125122
126123static void test_futex (void * futex_ptr , int must_fail )
@@ -167,41 +164,41 @@ int main(int argc, char *argv[])
167164 }
168165 }
169166
167+ ksft_print_header ();
168+ ksft_set_plan (1 );
169+
170170 mem_size = sysconf (_SC_PAGE_SIZE );
171171 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+
176175 futex_numa = futex_ptr ;
177176
178- info ("Regular test\n" );
177+ ksft_print_msg ("Regular test\n" );
179178 futex_numa -> futex = 0 ;
180179 futex_numa -> numa = FUTEX_NO_NODE ;
181180 test_futex (futex_ptr , 0 );
182181
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" );
187184
188- info ("Memory too small\n" );
185+ ksft_print_msg ("Memory too small\n" );
189186 test_futex (futex_ptr + mem_size - 4 , 1 );
190187
191- info ("Memory out of range\n" );
188+ ksft_print_msg ("Memory out of range\n" );
192189 test_futex (futex_ptr + mem_size , 1 );
193190
194191 futex_numa -> numa = FUTEX_NO_NODE ;
195192 mprotect (futex_ptr , mem_size , PROT_READ );
196- info ("Memory, RO\n" );
193+ ksft_print_msg ("Memory, RO\n" );
197194 test_futex (futex_ptr , 1 );
198195
199196 mprotect (futex_ptr , mem_size , PROT_NONE );
200- info ("Memory, no access\n" );
197+ ksft_print_msg ("Memory, no access\n" );
201198 test_futex (futex_ptr , 1 );
202199
203200 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" );
205202 test_futex (futex_ptr , 0 );
206203
207204 /* MPOL test. Does not work as expected */
@@ -213,20 +210,22 @@ int main(int argc, char *argv[])
213210 ret = mbind (futex_ptr , mem_size , MPOL_BIND , & nodemask ,
214211 sizeof (nodemask ) * 8 , 0 );
215212 if (ret == 0 ) {
216- info ("Node %d test\n" , i );
213+ ksft_print_msg ("Node %d test\n" , i );
217214 futex_numa -> futex = 0 ;
218215 futex_numa -> numa = FUTEX_NO_NODE ;
219216
220217 ret = futex2_wake (futex_ptr , 0 , FUTEX2_SIZE_U32 | FUTEX_PRIVATE_FLAG | FUTEX2_NUMA | FUTEX2_MPOL );
221218 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" );
223220 if (0 )
224221 test_futex_mpol (futex_numa , 0 );
225222 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 );
228225 }
229226 }
230227 }
228+ ksft_test_result_pass ("NUMA MPOL tests passed\n" );
229+ ksft_finished ();
231230 return 0 ;
232231}
0 commit comments