@@ -33,110 +33,114 @@ typedef long (*vdso_clock_gettime_t)(clockid_t clk_id, struct timespec *ts);
33
33
typedef long (* vdso_clock_getres_t )(clockid_t clk_id , struct timespec * ts );
34
34
typedef time_t (* vdso_time_t )(time_t * t );
35
35
36
- static int vdso_test_gettimeofday (void )
36
+ #define VDSO_TEST_PASS_MSG () "\n%s(): PASS\n", __func__
37
+ #define VDSO_TEST_FAIL_MSG (x ) "\n%s(): %s FAIL\n", __func__, x
38
+ #define VDSO_TEST_SKIP_MSG (x ) "\n%s(): SKIP: Could not find %s\n", __func__, x
39
+
40
+ static void vdso_test_gettimeofday (void )
37
41
{
38
42
/* Find gettimeofday. */
39
43
vdso_gettimeofday_t vdso_gettimeofday =
40
44
(vdso_gettimeofday_t )vdso_sym (version , name [0 ]);
41
45
42
46
if (!vdso_gettimeofday ) {
43
- printf ( "Could not find %s\n" , name [0 ]);
44
- return KSFT_SKIP ;
47
+ ksft_test_result_skip ( VDSO_TEST_SKIP_MSG ( name [0 ]) );
48
+ return ;
45
49
}
46
50
47
51
struct timeval tv ;
48
52
long ret = vdso_gettimeofday (& tv , 0 );
49
53
50
54
if (ret == 0 ) {
51
- printf ("The time is %lld.%06lld\n" ,
52
- (long long )tv .tv_sec , (long long )tv .tv_usec );
55
+ ksft_print_msg ("The time is %lld.%06lld\n" ,
56
+ (long long )tv .tv_sec , (long long )tv .tv_usec );
57
+ ksft_test_result_pass (VDSO_TEST_PASS_MSG ());
53
58
} else {
54
- printf ("%s failed\n" , name [0 ]);
55
- return KSFT_FAIL ;
59
+ ksft_test_result_fail (VDSO_TEST_FAIL_MSG (name [0 ]));
56
60
}
57
-
58
- return KSFT_PASS ;
59
61
}
60
62
61
- static int vdso_test_clock_gettime (clockid_t clk_id )
63
+ static void vdso_test_clock_gettime (clockid_t clk_id )
62
64
{
63
65
/* Find clock_gettime. */
64
66
vdso_clock_gettime_t vdso_clock_gettime =
65
67
(vdso_clock_gettime_t )vdso_sym (version , name [1 ]);
66
68
67
69
if (!vdso_clock_gettime ) {
68
- printf ( "Could not find %s\n" , name [1 ]);
69
- return KSFT_SKIP ;
70
+ ksft_test_result_skip ( VDSO_TEST_SKIP_MSG ( name [1 ]) );
71
+ return ;
70
72
}
71
73
72
74
struct timespec ts ;
73
75
long ret = vdso_clock_gettime (clk_id , & ts );
74
76
75
77
if (ret == 0 ) {
76
- printf ("The time is %lld.%06lld\n" ,
77
- (long long )ts .tv_sec , (long long )ts .tv_nsec );
78
+ ksft_print_msg ("The time is %lld.%06lld\n" ,
79
+ (long long )ts .tv_sec , (long long )ts .tv_nsec );
80
+ ksft_test_result_pass (VDSO_TEST_PASS_MSG ());
78
81
} else {
79
- printf ("%s failed\n" , name [1 ]);
80
- return KSFT_FAIL ;
82
+ ksft_test_result_fail (VDSO_TEST_FAIL_MSG (name [1 ]));
81
83
}
82
-
83
- return KSFT_PASS ;
84
84
}
85
85
86
- static int vdso_test_time (void )
86
+ static void vdso_test_time (void )
87
87
{
88
88
/* Find time. */
89
89
vdso_time_t vdso_time =
90
90
(vdso_time_t )vdso_sym (version , name [2 ]);
91
91
92
92
if (!vdso_time ) {
93
- printf ( "Could not find %s\n" , name [2 ]);
94
- return KSFT_SKIP ;
93
+ ksft_test_result_skip ( VDSO_TEST_SKIP_MSG ( name [2 ]) );
94
+ return ;
95
95
}
96
96
97
97
long ret = vdso_time (NULL );
98
98
99
99
if (ret > 0 ) {
100
- printf ("The time in hours since January 1, 1970 is %lld\n" ,
100
+ ksft_print_msg ("The time in hours since January 1, 1970 is %lld\n" ,
101
101
(long long )(ret / 3600 ));
102
+ ksft_test_result_pass (VDSO_TEST_PASS_MSG ());
102
103
} else {
103
- printf ("%s failed\n" , name [2 ]);
104
- return KSFT_FAIL ;
104
+ ksft_test_result_fail (VDSO_TEST_FAIL_MSG (name [2 ]));
105
105
}
106
-
107
- return KSFT_PASS ;
108
106
}
109
107
110
- static int vdso_test_clock_getres (clockid_t clk_id )
108
+ static void vdso_test_clock_getres (clockid_t clk_id )
111
109
{
110
+ int clock_getres_fail = 0 ;
111
+
112
112
/* Find clock_getres. */
113
113
vdso_clock_getres_t vdso_clock_getres =
114
114
(vdso_clock_getres_t )vdso_sym (version , name [3 ]);
115
115
116
116
if (!vdso_clock_getres ) {
117
- printf ( "Could not find %s\n" , name [3 ]);
118
- return KSFT_SKIP ;
117
+ ksft_test_result_skip ( VDSO_TEST_SKIP_MSG ( name [3 ]) );
118
+ return ;
119
119
}
120
120
121
121
struct timespec ts , sys_ts ;
122
122
long ret = vdso_clock_getres (clk_id , & ts );
123
123
124
124
if (ret == 0 ) {
125
- printf ("The resolution is %lld %lld\n" ,
126
- (long long )ts .tv_sec , (long long )ts .tv_nsec );
125
+ ksft_print_msg ("The vdso resolution is %lld %lld\n" ,
126
+ (long long )ts .tv_sec , (long long )ts .tv_nsec );
127
127
} else {
128
- printf ("%s failed\n" , name [3 ]);
129
- return KSFT_FAIL ;
128
+ clock_getres_fail ++ ;
130
129
}
131
130
132
131
ret = syscall (SYS_clock_getres , clk_id , & sys_ts );
133
132
134
- if ((sys_ts .tv_sec != ts .tv_sec ) || (sys_ts .tv_nsec != ts .tv_nsec )) {
135
- printf ("%s failed\n" , name [3 ]);
136
- return KSFT_FAIL ;
137
- }
133
+ ksft_print_msg ("The syscall resolution is %lld %lld\n" ,
134
+ (long long )sys_ts .tv_sec , (long long )sys_ts .tv_nsec );
138
135
139
- return KSFT_PASS ;
136
+ if ((sys_ts .tv_sec != ts .tv_sec ) || (sys_ts .tv_nsec != ts .tv_nsec ))
137
+ clock_getres_fail ++ ;
138
+
139
+ if (clock_getres_fail > 0 ) {
140
+ ksft_test_result_fail (VDSO_TEST_FAIL_MSG (name [3 ]));
141
+ } else {
142
+ ksft_test_result_pass (VDSO_TEST_PASS_MSG ());
143
+ }
140
144
}
141
145
142
146
const char * vdso_clock_name [12 ] = {
@@ -158,36 +162,23 @@ const char *vdso_clock_name[12] = {
158
162
* This function calls vdso_test_clock_gettime and vdso_test_clock_getres
159
163
* with different values for clock_id.
160
164
*/
161
- static inline int vdso_test_clock (clockid_t clock_id )
165
+ static inline void vdso_test_clock (clockid_t clock_id )
162
166
{
163
- int ret0 , ret1 ;
164
-
165
- ret0 = vdso_test_clock_gettime (clock_id );
166
- /* A skipped test is considered passed */
167
- if (ret0 == KSFT_SKIP )
168
- ret0 = KSFT_PASS ;
169
-
170
- ret1 = vdso_test_clock_getres (clock_id );
171
- /* A skipped test is considered passed */
172
- if (ret1 == KSFT_SKIP )
173
- ret1 = KSFT_PASS ;
167
+ ksft_print_msg ("\nclock_id: %s\n" , vdso_clock_name [clock_id ]);
174
168
175
- ret0 += ret1 ;
169
+ vdso_test_clock_gettime ( clock_id ) ;
176
170
177
- printf ("clock_id: %s" , vdso_clock_name [clock_id ]);
178
-
179
- if (ret0 > 0 )
180
- printf (" [FAIL]\n" );
181
- else
182
- printf (" [PASS]\n" );
183
-
184
- return ret0 ;
171
+ vdso_test_clock_getres (clock_id );
185
172
}
186
173
174
+ #define VDSO_TEST_PLAN 16
175
+
187
176
int main (int argc , char * * argv )
188
177
{
189
178
unsigned long sysinfo_ehdr = getauxval (AT_SYSINFO_EHDR );
190
- int ret ;
179
+
180
+ ksft_print_header ();
181
+ ksft_set_plan (VDSO_TEST_PLAN );
191
182
192
183
if (!sysinfo_ehdr ) {
193
184
printf ("AT_SYSINFO_EHDR is not present!\n" );
@@ -201,44 +192,42 @@ int main(int argc, char **argv)
201
192
202
193
vdso_init_from_sysinfo_ehdr (getauxval (AT_SYSINFO_EHDR ));
203
194
204
- ret = vdso_test_gettimeofday ();
195
+ vdso_test_gettimeofday ();
205
196
206
197
#if _POSIX_TIMERS > 0
207
198
208
199
#ifdef CLOCK_REALTIME
209
- ret += vdso_test_clock (CLOCK_REALTIME );
200
+ vdso_test_clock (CLOCK_REALTIME );
210
201
#endif
211
202
212
203
#ifdef CLOCK_BOOTTIME
213
- ret += vdso_test_clock (CLOCK_BOOTTIME );
204
+ vdso_test_clock (CLOCK_BOOTTIME );
214
205
#endif
215
206
216
207
#ifdef CLOCK_TAI
217
- ret += vdso_test_clock (CLOCK_TAI );
208
+ vdso_test_clock (CLOCK_TAI );
218
209
#endif
219
210
220
211
#ifdef CLOCK_REALTIME_COARSE
221
- ret += vdso_test_clock (CLOCK_REALTIME_COARSE );
212
+ vdso_test_clock (CLOCK_REALTIME_COARSE );
222
213
#endif
223
214
224
215
#ifdef CLOCK_MONOTONIC
225
- ret += vdso_test_clock (CLOCK_MONOTONIC );
216
+ vdso_test_clock (CLOCK_MONOTONIC );
226
217
#endif
227
218
228
219
#ifdef CLOCK_MONOTONIC_RAW
229
- ret += vdso_test_clock (CLOCK_MONOTONIC_RAW );
220
+ vdso_test_clock (CLOCK_MONOTONIC_RAW );
230
221
#endif
231
222
232
223
#ifdef CLOCK_MONOTONIC_COARSE
233
- ret += vdso_test_clock (CLOCK_MONOTONIC_COARSE );
224
+ vdso_test_clock (CLOCK_MONOTONIC_COARSE );
234
225
#endif
235
226
236
227
#endif
237
228
238
- ret += vdso_test_time ();
239
-
240
- if (ret > 0 )
241
- return KSFT_FAIL ;
229
+ vdso_test_time ();
242
230
243
- return KSFT_PASS ;
231
+ ksft_print_cnts ();
232
+ return ksft_get_fail_cnt () == 0 ? KSFT_PASS : KSFT_FAIL ;
244
233
}
0 commit comments