1515#include <pthread.h>
1616#include <stdint.h>
1717#include <sys/shm.h>
18+
1819#include "futextest.h"
1920#include "futex2test.h"
20- #include "logging .h"
21+ #include "../../kselftest_harness .h"
2122
22- #define TEST_NAME "futex-wait"
2323#define WAKE_WAIT_US 10000
2424#define NR_FUTEXES 30
2525static struct futex_waitv waitv [NR_FUTEXES ];
2626u_int32_t futexes [NR_FUTEXES ] = {0 };
2727
28- void usage (char * prog )
29- {
30- printf ("Usage: %s\n" , prog );
31- printf (" -c Use color\n" );
32- printf (" -h Display this help message\n" );
33- printf (" -v L Verbosity level: %d=QUIET %d=CRITICAL %d=INFO\n" ,
34- VQUIET , VCRITICAL , VINFO );
35- }
36-
3728void * waiterfn (void * arg )
3829{
3930 struct timespec to ;
4031 int res ;
4132
4233 /* setting absolute timeout for futex2 */
4334 if (clock_gettime (CLOCK_MONOTONIC , & to ))
44- error ("gettime64 failed\n" , errno );
35+ ksft_exit_fail_msg ("gettime64 failed\n" );
4536
4637 to .tv_sec ++ ;
4738
@@ -57,34 +48,10 @@ void *waiterfn(void *arg)
5748 return NULL ;
5849}
5950
60- int main ( int argc , char * argv [] )
51+ TEST ( private_waitv )
6152{
6253 pthread_t waiter ;
63- int res , ret = RET_PASS ;
64- struct timespec to ;
65- int c , i ;
66-
67- while ((c = getopt (argc , argv , "cht:v:" )) != -1 ) {
68- switch (c ) {
69- case 'c' :
70- log_color (1 );
71- break ;
72- case 'h' :
73- usage (basename (argv [0 ]));
74- exit (0 );
75- case 'v' :
76- log_verbosity (atoi (optarg ));
77- break ;
78- default :
79- usage (basename (argv [0 ]));
80- exit (1 );
81- }
82- }
83-
84- ksft_print_header ();
85- ksft_set_plan (7 );
86- ksft_print_msg ("%s: Test FUTEX_WAITV\n" ,
87- basename (argv [0 ]));
54+ int res , i ;
8855
8956 for (i = 0 ; i < NR_FUTEXES ; i ++ ) {
9057 waitv [i ].uaddr = (uintptr_t )& futexes [i ];
@@ -95,7 +62,7 @@ int main(int argc, char *argv[])
9562
9663 /* Private waitv */
9764 if (pthread_create (& waiter , NULL , waiterfn , NULL ))
98- error ("pthread_create failed\n" , errno );
65+ ksft_exit_fail_msg ("pthread_create failed\n" );
9966
10067 usleep (WAKE_WAIT_US );
10168
@@ -104,10 +71,15 @@ int main(int argc, char *argv[])
10471 ksft_test_result_fail ("futex_wake private returned: %d %s\n" ,
10572 res ? errno : res ,
10673 res ? strerror (errno ) : "" );
107- ret = RET_FAIL ;
10874 } else {
10975 ksft_test_result_pass ("futex_waitv private\n" );
11076 }
77+ }
78+
79+ TEST (shared_waitv )
80+ {
81+ pthread_t waiter ;
82+ int res , i ;
11183
11284 /* Shared waitv */
11385 for (i = 0 ; i < NR_FUTEXES ; i ++ ) {
@@ -128,7 +100,7 @@ int main(int argc, char *argv[])
128100 }
129101
130102 if (pthread_create (& waiter , NULL , waiterfn , NULL ))
131- error ("pthread_create failed\n" , errno );
103+ ksft_exit_fail_msg ("pthread_create failed\n" );
132104
133105 usleep (WAKE_WAIT_US );
134106
@@ -137,19 +109,24 @@ int main(int argc, char *argv[])
137109 ksft_test_result_fail ("futex_wake shared returned: %d %s\n" ,
138110 res ? errno : res ,
139111 res ? strerror (errno ) : "" );
140- ret = RET_FAIL ;
141112 } else {
142113 ksft_test_result_pass ("futex_waitv shared\n" );
143114 }
144115
145116 for (i = 0 ; i < NR_FUTEXES ; i ++ )
146117 shmdt (u64_to_ptr (waitv [i ].uaddr ));
118+ }
119+
120+ TEST (invalid_flag )
121+ {
122+ struct timespec to ;
123+ int res ;
147124
148125 /* Testing a waiter without FUTEX_32 flag */
149126 waitv [0 ].flags = FUTEX_PRIVATE_FLAG ;
150127
151128 if (clock_gettime (CLOCK_MONOTONIC , & to ))
152- error ("gettime64 failed\n" , errno );
129+ ksft_exit_fail_msg ("gettime64 failed\n" );
153130
154131 to .tv_sec ++ ;
155132
@@ -158,17 +135,22 @@ int main(int argc, char *argv[])
158135 ksft_test_result_fail ("futex_waitv private returned: %d %s\n" ,
159136 res ? errno : res ,
160137 res ? strerror (errno ) : "" );
161- ret = RET_FAIL ;
162138 } else {
163139 ksft_test_result_pass ("futex_waitv without FUTEX_32\n" );
164140 }
141+ }
142+
143+ TEST (unaligned_address )
144+ {
145+ struct timespec to ;
146+ int res ;
165147
166148 /* Testing a waiter with an unaligned address */
167149 waitv [0 ].flags = FUTEX_PRIVATE_FLAG | FUTEX_32 ;
168150 waitv [0 ].uaddr = 1 ;
169151
170152 if (clock_gettime (CLOCK_MONOTONIC , & to ))
171- error ("gettime64 failed\n" , errno );
153+ ksft_exit_fail_msg ("gettime64 failed\n" );
172154
173155 to .tv_sec ++ ;
174156
@@ -177,16 +159,21 @@ int main(int argc, char *argv[])
177159 ksft_test_result_fail ("futex_wake private returned: %d %s\n" ,
178160 res ? errno : res ,
179161 res ? strerror (errno ) : "" );
180- ret = RET_FAIL ;
181162 } else {
182163 ksft_test_result_pass ("futex_waitv with an unaligned address\n" );
183164 }
165+ }
166+
167+ TEST (null_address )
168+ {
169+ struct timespec to ;
170+ int res ;
184171
185172 /* Testing a NULL address for waiters.uaddr */
186173 waitv [0 ].uaddr = 0x00000000 ;
187174
188175 if (clock_gettime (CLOCK_MONOTONIC , & to ))
189- error ("gettime64 failed\n" , errno );
176+ ksft_exit_fail_msg ("gettime64 failed\n" );
190177
191178 to .tv_sec ++ ;
192179
@@ -195,14 +182,13 @@ int main(int argc, char *argv[])
195182 ksft_test_result_fail ("futex_waitv private returned: %d %s\n" ,
196183 res ? errno : res ,
197184 res ? strerror (errno ) : "" );
198- ret = RET_FAIL ;
199185 } else {
200186 ksft_test_result_pass ("futex_waitv NULL address in waitv.uaddr\n" );
201187 }
202188
203189 /* Testing a NULL address for *waiters */
204190 if (clock_gettime (CLOCK_MONOTONIC , & to ))
205- error ("gettime64 failed\n" , errno );
191+ ksft_exit_fail_msg ("gettime64 failed\n" );
206192
207193 to .tv_sec ++ ;
208194
@@ -211,14 +197,19 @@ int main(int argc, char *argv[])
211197 ksft_test_result_fail ("futex_waitv private returned: %d %s\n" ,
212198 res ? errno : res ,
213199 res ? strerror (errno ) : "" );
214- ret = RET_FAIL ;
215200 } else {
216201 ksft_test_result_pass ("futex_waitv NULL address in *waiters\n" );
217202 }
203+ }
204+
205+ TEST (invalid_clockid )
206+ {
207+ struct timespec to ;
208+ int res ;
218209
219210 /* Testing an invalid clockid */
220211 if (clock_gettime (CLOCK_MONOTONIC , & to ))
221- error ("gettime64 failed\n" , errno );
212+ ksft_exit_fail_msg ("gettime64 failed\n" );
222213
223214 to .tv_sec ++ ;
224215
@@ -227,11 +218,9 @@ int main(int argc, char *argv[])
227218 ksft_test_result_fail ("futex_waitv private returned: %d %s\n" ,
228219 res ? errno : res ,
229220 res ? strerror (errno ) : "" );
230- ret = RET_FAIL ;
231221 } else {
232222 ksft_test_result_pass ("futex_waitv invalid clockid\n" );
233223 }
234-
235- ksft_print_cnts ();
236- return ret ;
237224}
225+
226+ TEST_HARNESS_MAIN
0 commit comments