77
88#include <pthread.h>
99#include <limits.h>
10- #include "logging.h"
10+
1111#include "futextest.h"
12+ #include "../../kselftest_harness.h"
1213
13- #define TEST_NAME "futex-requeue"
1414#define timeout_ns 30000000
1515#define WAKE_WAIT_US 10000
1616
1717volatile futex_t * f1 ;
1818
19- void usage (char * prog )
20- {
21- printf ("Usage: %s\n" , prog );
22- printf (" -c Use color\n" );
23- printf (" -h Display this help message\n" );
24- printf (" -v L Verbosity level: %d=QUIET %d=CRITICAL %d=INFO\n" ,
25- VQUIET , VCRITICAL , VINFO );
26- }
27-
2819void * waiterfn (void * arg )
2920{
3021 struct timespec to ;
@@ -38,99 +29,78 @@ void *waiterfn(void *arg)
3829 return NULL ;
3930}
4031
41- int main ( int argc , char * argv [] )
32+ TEST ( requeue_single )
4233{
43- pthread_t waiter [10 ];
44- int res , ret = RET_PASS ;
45- int c , i ;
4634 volatile futex_t _f1 = 0 ;
4735 volatile futex_t f2 = 0 ;
36+ pthread_t waiter [10 ];
37+ int res ;
4838
4939 f1 = & _f1 ;
5040
51- while ((c = getopt (argc , argv , "cht:v:" )) != -1 ) {
52- switch (c ) {
53- case 'c' :
54- log_color (1 );
55- break ;
56- case 'h' :
57- usage (basename (argv [0 ]));
58- exit (0 );
59- case 'v' :
60- log_verbosity (atoi (optarg ));
61- break ;
62- default :
63- usage (basename (argv [0 ]));
64- exit (1 );
65- }
66- }
67-
68- ksft_print_header ();
69- ksft_set_plan (2 );
70- ksft_print_msg ("%s: Test futex_requeue\n" ,
71- basename (argv [0 ]));
72-
7341 /*
7442 * Requeue a waiter from f1 to f2, and wake f2.
7543 */
7644 if (pthread_create (& waiter [0 ], NULL , waiterfn , NULL ))
77- error ("pthread_create failed\n" , errno );
45+ ksft_exit_fail_msg ("pthread_create failed\n" );
7846
7947 usleep (WAKE_WAIT_US );
8048
81- info ("Requeuing 1 futex from f1 to f2\n" );
49+ ksft_print_dbg_msg ("Requeuing 1 futex from f1 to f2\n" );
8250 res = futex_cmp_requeue (f1 , 0 , & f2 , 0 , 1 , 0 );
83- if (res != 1 ) {
51+ if (res != 1 )
8452 ksft_test_result_fail ("futex_requeue simple returned: %d %s\n" ,
8553 res ? errno : res ,
8654 res ? strerror (errno ) : "" );
87- ret = RET_FAIL ;
88- }
8955
90-
91- info ("Waking 1 futex at f2\n" );
56+ ksft_print_dbg_msg ("Waking 1 futex at f2\n" );
9257 res = futex_wake (& f2 , 1 , 0 );
9358 if (res != 1 ) {
9459 ksft_test_result_fail ("futex_requeue simple returned: %d %s\n" ,
9560 res ? errno : res ,
9661 res ? strerror (errno ) : "" );
97- ret = RET_FAIL ;
9862 } else {
9963 ksft_test_result_pass ("futex_requeue simple succeeds\n" );
10064 }
65+ }
66+
67+ TEST (requeue_multiple )
68+ {
69+ volatile futex_t _f1 = 0 ;
70+ volatile futex_t f2 = 0 ;
71+ pthread_t waiter [10 ];
72+ int res , i ;
10173
74+ f1 = & _f1 ;
10275
10376 /*
10477 * Create 10 waiters at f1. At futex_requeue, wake 3 and requeue 7.
10578 * At futex_wake, wake INT_MAX (should be exactly 7).
10679 */
10780 for (i = 0 ; i < 10 ; i ++ ) {
10881 if (pthread_create (& waiter [i ], NULL , waiterfn , NULL ))
109- error ("pthread_create failed\n" , errno );
82+ ksft_exit_fail_msg ("pthread_create failed\n" );
11083 }
11184
11285 usleep (WAKE_WAIT_US );
11386
114- info ("Waking 3 futexes at f1 and requeuing 7 futexes from f1 to f2\n" );
87+ ksft_print_dbg_msg ("Waking 3 futexes at f1 and requeuing 7 futexes from f1 to f2\n" );
11588 res = futex_cmp_requeue (f1 , 0 , & f2 , 3 , 7 , 0 );
11689 if (res != 10 ) {
11790 ksft_test_result_fail ("futex_requeue many returned: %d %s\n" ,
11891 res ? errno : res ,
11992 res ? strerror (errno ) : "" );
120- ret = RET_FAIL ;
12193 }
12294
123- info ("Waking INT_MAX futexes at f2\n" );
95+ ksft_print_dbg_msg ("Waking INT_MAX futexes at f2\n" );
12496 res = futex_wake (& f2 , INT_MAX , 0 );
12597 if (res != 7 ) {
12698 ksft_test_result_fail ("futex_requeue many returned: %d %s\n" ,
12799 res ? errno : res ,
128100 res ? strerror (errno ) : "" );
129- ret = RET_FAIL ;
130101 } else {
131102 ksft_test_result_pass ("futex_requeue many succeeds\n" );
132103 }
133-
134- ksft_print_cnts ();
135- return ret ;
136104}
105+
106+ TEST_HARNESS_MAIN
0 commit comments