@@ -50,39 +50,41 @@ static char *cmd_to_str(unsigned long cmd)
5050void * gup_thread (void * data )
5151{
5252 struct gup_test gup = * (struct gup_test * )data ;
53- int i ;
53+ int i , status ;
5454
5555 /* Only report timing information on the *_BENCHMARK commands: */
5656 if ((cmd == PIN_FAST_BENCHMARK ) || (cmd == GUP_FAST_BENCHMARK ) ||
5757 (cmd == PIN_LONGTERM_BENCHMARK )) {
5858 for (i = 0 ; i < repeats ; i ++ ) {
5959 gup .size = size ;
60- if (ioctl (gup_fd , cmd , & gup ))
61- perror ("ioctl" ), exit (1 );
60+ status = ioctl (gup_fd , cmd , & gup );
61+ if (status )
62+ break ;
6263
6364 pthread_mutex_lock (& print_mutex );
64- printf ("%s: Time: get:%lld put:%lld us" ,
65- cmd_to_str (cmd ), gup .get_delta_usec ,
66- gup .put_delta_usec );
65+ ksft_print_msg ("%s: Time: get:%lld put:%lld us" ,
66+ cmd_to_str (cmd ), gup .get_delta_usec ,
67+ gup .put_delta_usec );
6768 if (gup .size != size )
68- printf (", truncated (size: %lld)" , gup .size );
69- printf ("\n" );
69+ ksft_print_msg (", truncated (size: %lld)" , gup .size );
70+ ksft_print_msg ("\n" );
7071 pthread_mutex_unlock (& print_mutex );
7172 }
7273 } else {
7374 gup .size = size ;
74- if (ioctl (gup_fd , cmd , & gup )) {
75- perror ("ioctl" );
76- exit (1 );
77- }
75+ status = ioctl (gup_fd , cmd , & gup );
76+ if (status )
77+ goto return_ ;
7878
7979 pthread_mutex_lock (& print_mutex );
80- printf ("%s: done\n" , cmd_to_str (cmd ));
80+ ksft_print_msg ("%s: done\n" , cmd_to_str (cmd ));
8181 if (gup .size != size )
82- printf ("Truncated (size: %lld)\n" , gup .size );
82+ ksft_print_msg ("Truncated (size: %lld)\n" , gup .size );
8383 pthread_mutex_unlock (& print_mutex );
8484 }
8585
86+ return_ :
87+ ksft_test_result (!status , "ioctl status %d\n" , status );
8688 return NULL ;
8789}
8890
@@ -170,7 +172,7 @@ int main(int argc, char **argv)
170172 touch = 1 ;
171173 break ;
172174 default :
173- return -1 ;
175+ ksft_exit_fail_msg ( "Wrong argument\n" ) ;
174176 }
175177 }
176178
@@ -198,11 +200,12 @@ int main(int argc, char **argv)
198200 }
199201 }
200202
203+ ksft_print_header ();
204+ ksft_set_plan (nthreads );
205+
201206 filed = open (file , O_RDWR |O_CREAT );
202- if (filed < 0 ) {
203- perror ("open" );
204- exit (filed );
205- }
207+ if (filed < 0 )
208+ ksft_exit_fail_msg ("Unable to open %s: %s\n" , file , strerror (errno ));
206209
207210 gup .nr_pages_per_call = nr_pages ;
208211 if (write )
@@ -213,27 +216,24 @@ int main(int argc, char **argv)
213216 switch (errno ) {
214217 case EACCES :
215218 if (getuid ())
216- printf ("Please run this test as root\n" );
219+ ksft_print_msg ("Please run this test as root\n" );
217220 break ;
218221 case ENOENT :
219- if (opendir ("/sys/kernel/debug" ) == NULL ) {
220- printf ("mount debugfs at /sys/kernel/debug\n" );
221- break ;
222- }
223- printf ("check if CONFIG_GUP_TEST is enabled in kernel config\n" );
222+ if (opendir ("/sys/kernel/debug" ) == NULL )
223+ ksft_print_msg ("mount debugfs at /sys/kernel/debug\n" );
224+ ksft_print_msg ("check if CONFIG_GUP_TEST is enabled in kernel config\n" );
224225 break ;
225226 default :
226- perror ("failed to open " GUP_TEST_FILE );
227+ ksft_print_msg ("failed to open %s: %s\n" , GUP_TEST_FILE , strerror ( errno ) );
227228 break ;
228229 }
229- exit (KSFT_SKIP );
230+ ksft_test_result_skip ("Please run this test as root\n" );
231+ return ksft_exit_pass ();
230232 }
231233
232234 p = mmap (NULL , size , PROT_READ | PROT_WRITE , flags , filed , 0 );
233- if (p == MAP_FAILED ) {
234- perror ("mmap" );
235- exit (1 );
236- }
235+ if (p == MAP_FAILED )
236+ ksft_exit_fail_msg ("mmap: %s\n" , strerror (errno ));
237237 gup .addr = (unsigned long )p ;
238238
239239 if (thp == 1 )
@@ -264,7 +264,8 @@ int main(int argc, char **argv)
264264 ret = pthread_join (tid [i ], NULL );
265265 assert (ret == 0 );
266266 }
267+
267268 free (tid );
268269
269- return 0 ;
270+ return ksft_exit_pass () ;
270271}
0 commit comments