2727#include <libgen.h>
2828#include <signal.h>
2929
30- #include "logging.h"
3130#include "futextest.h"
31+ #include "../../kselftest_harness.h"
3232
33- #define TEST_NAME "futex-wait-private-mapped-file"
3433#define PAGE_SZ 4096
3534
3635char pad [PAGE_SZ ] = {1 };
@@ -40,86 +39,44 @@ char pad2[PAGE_SZ] = {1};
4039#define WAKE_WAIT_US 3000000
4140struct timespec wait_timeout = { .tv_sec = 5 , .tv_nsec = 0 };
4241
43- void usage (char * prog )
44- {
45- printf ("Usage: %s\n" , prog );
46- printf (" -c Use color\n" );
47- printf (" -h Display this help message\n" );
48- printf (" -v L Verbosity level: %d=QUIET %d=CRITICAL %d=INFO\n" ,
49- VQUIET , VCRITICAL , VINFO );
50- }
51-
5242void * thr_futex_wait (void * arg )
5343{
5444 int ret ;
5545
56- info ("futex wait\n" );
46+ ksft_print_dbg_msg ("futex wait\n" );
5747 ret = futex_wait (& val , 1 , & wait_timeout , 0 );
58- if (ret && errno != EWOULDBLOCK && errno != ETIMEDOUT ) {
59- error ("futex error.\n" , errno );
60- print_result (TEST_NAME , RET_ERROR );
61- exit (RET_ERROR );
62- }
48+ if (ret && errno != EWOULDBLOCK && errno != ETIMEDOUT )
49+ ksft_exit_fail_msg ("futex error.\n" );
6350
6451 if (ret && errno == ETIMEDOUT )
65- fail ("waiter timedout\n" );
52+ ksft_exit_fail_msg ("waiter timedout\n" );
6653
67- info ("futex_wait: ret = %d, errno = %d\n" , ret , errno );
54+ ksft_print_dbg_msg ("futex_wait: ret = %d, errno = %d\n" , ret , errno );
6855
6956 return NULL ;
7057}
7158
72- int main ( int argc , char * * argv )
59+ TEST ( wait_private_mapped_file )
7360{
7461 pthread_t thr ;
75- int ret = RET_PASS ;
7662 int res ;
77- int c ;
78-
79- while ((c = getopt (argc , argv , "chv:" )) != -1 ) {
80- switch (c ) {
81- case 'c' :
82- log_color (1 );
83- break ;
84- case 'h' :
85- usage (basename (argv [0 ]));
86- exit (0 );
87- case 'v' :
88- log_verbosity (atoi (optarg ));
89- break ;
90- default :
91- usage (basename (argv [0 ]));
92- exit (1 );
93- }
94- }
95-
96- ksft_print_header ();
97- ksft_set_plan (1 );
98- ksft_print_msg (
99- "%s: Test the futex value of private file mappings in FUTEX_WAIT\n" ,
100- basename (argv [0 ]));
101-
102- ret = pthread_create (& thr , NULL , thr_futex_wait , NULL );
103- if (ret < 0 ) {
104- fprintf (stderr , "pthread_create error\n" );
105- ret = RET_ERROR ;
106- goto out ;
107- }
108-
109- info ("wait a while\n" );
63+
64+ res = pthread_create (& thr , NULL , thr_futex_wait , NULL );
65+ if (res < 0 )
66+ ksft_exit_fail_msg ("pthread_create error\n" );
67+
68+ ksft_print_dbg_msg ("wait a while\n" );
11069 usleep (WAKE_WAIT_US );
11170 val = 2 ;
11271 res = futex_wake (& val , 1 , 0 );
113- info ("futex_wake %d\n" , res );
114- if (res != 1 ) {
115- fail ("FUTEX_WAKE didn't find the waiting thread.\n" );
116- ret = RET_FAIL ;
117- }
72+ ksft_print_dbg_msg ("futex_wake %d\n" , res );
73+ if (res != 1 )
74+ ksft_exit_fail_msg ("FUTEX_WAKE didn't find the waiting thread.\n" );
11875
119- info ("join\n" );
76+ ksft_print_dbg_msg ("join\n" );
12077 pthread_join (thr , NULL );
12178
122- out :
123- print_result (TEST_NAME , ret );
124- return ret ;
79+ ksft_test_result_pass ("wait_private_mapped_file" );
12580}
81+
82+ TEST_HARNESS_MAIN
0 commit comments