3
3
#include <linux/sched.h>
4
4
#include <linux/wait.h>
5
5
6
+ #include "kselftest.h"
7
+
6
8
#define SYS_TPIDR2 "S3_3_C13_C0_5"
7
9
8
10
#define EXPECTED_TESTS 5
9
11
10
- static void putstr (const char * str )
11
- {
12
- write (1 , str , strlen (str ));
13
- }
14
-
15
- static void putnum (unsigned int num )
16
- {
17
- char c ;
18
-
19
- if (num / 10 )
20
- putnum (num / 10 );
21
-
22
- c = '0' + (num % 10 );
23
- write (1 , & c , 1 );
24
- }
25
-
26
- static int tests_run ;
27
- static int tests_passed ;
28
- static int tests_failed ;
29
- static int tests_skipped ;
30
-
31
12
static void set_tpidr2 (uint64_t val )
32
13
{
33
14
asm volatile (
@@ -50,20 +31,6 @@ static uint64_t get_tpidr2(void)
50
31
return val ;
51
32
}
52
33
53
- static void print_summary (void )
54
- {
55
- if (tests_passed + tests_failed + tests_skipped != EXPECTED_TESTS )
56
- putstr ("# UNEXPECTED TEST COUNT: " );
57
-
58
- putstr ("# Totals: pass:" );
59
- putnum (tests_passed );
60
- putstr (" fail:" );
61
- putnum (tests_failed );
62
- putstr (" xfail:0 xpass:0 skip:" );
63
- putnum (tests_skipped );
64
- putstr (" error:0\n" );
65
- }
66
-
67
34
/* Processes should start with TPIDR2 == 0 */
68
35
static int default_value (void )
69
36
{
@@ -105,24 +72,21 @@ static int write_fork_read(void)
105
72
if (newpid == 0 ) {
106
73
/* In child */
107
74
if (get_tpidr2 () != oldpid ) {
108
- putstr ("# TPIDR2 changed in child: " );
109
- putnum (get_tpidr2 ());
110
- putstr ("\n" );
75
+ ksft_print_msg ("TPIDR2 changed in child: %llx\n" ,
76
+ get_tpidr2 ());
111
77
exit (0 );
112
78
}
113
79
114
80
set_tpidr2 (getpid ());
115
81
if (get_tpidr2 () == getpid ()) {
116
82
exit (1 );
117
83
} else {
118
- putstr ( "# Failed to set TPIDR2 in child\n" );
84
+ ksft_print_msg ( " Failed to set TPIDR2 in child\n" );
119
85
exit (0 );
120
86
}
121
87
}
122
88
if (newpid < 0 ) {
123
- putstr ("# fork() failed: -" );
124
- putnum (- newpid );
125
- putstr ("\n" );
89
+ ksft_print_msg ("fork() failed: %d\n" , newpid );
126
90
return 0 ;
127
91
}
128
92
@@ -132,23 +96,22 @@ static int write_fork_read(void)
132
96
if (waiting < 0 ) {
133
97
if (errno == EINTR )
134
98
continue ;
135
- putstr ("# waitpid() failed: " );
136
- putnum (errno );
137
- putstr ("\n" );
99
+ ksft_print_msg ("waitpid() failed: %d\n" , errno );
138
100
return 0 ;
139
101
}
140
102
if (waiting != newpid ) {
141
- putstr ("# waitpid() returned wrong PID\n" );
103
+ ksft_print_msg ("waitpid() returned wrong PID: %d != %d\n" ,
104
+ waiting , newpid );
142
105
return 0 ;
143
106
}
144
107
145
108
if (!WIFEXITED (status )) {
146
- putstr ( "# child did not exit\n" );
109
+ ksft_print_msg ( " child did not exit\n" );
147
110
return 0 ;
148
111
}
149
112
150
113
if (getpid () != get_tpidr2 ()) {
151
- putstr ( "# TPIDR2 corrupted in parent\n" );
114
+ ksft_print_msg ( " TPIDR2 corrupted in parent\n" );
152
115
return 0 ;
153
116
}
154
117
@@ -188,35 +151,32 @@ static int write_clone_read(void)
188
151
189
152
stack = malloc (__STACK_SIZE );
190
153
if (!stack ) {
191
- putstr ( "# malloc() failed\n" );
154
+ ksft_print_msg ( " malloc() failed\n" );
192
155
return 0 ;
193
156
}
194
157
195
158
ret = sys_clone (CLONE_VM , (unsigned long )stack + __STACK_SIZE ,
196
159
& parent_tid , 0 , & child_tid );
197
160
if (ret == -1 ) {
198
- putstr ("# clone() failed\n" );
199
- putnum (errno );
200
- putstr ("\n" );
161
+ ksft_print_msg ("clone() failed: %d\n" , errno );
201
162
return 0 ;
202
163
}
203
164
204
165
if (ret == 0 ) {
205
166
/* In child */
206
167
if (get_tpidr2 () != 0 ) {
207
- putstr ("# TPIDR2 non-zero in child: " );
208
- putnum (get_tpidr2 ());
209
- putstr ("\n" );
168
+ ksft_print_msg ("TPIDR2 non-zero in child: %llx\n" ,
169
+ get_tpidr2 ());
210
170
exit (0 );
211
171
}
212
172
213
173
if (gettid () == 0 )
214
- putstr ( "# Child TID==0\n" );
174
+ ksft_print_msg ( " Child TID==0\n" );
215
175
set_tpidr2 (gettid ());
216
176
if (get_tpidr2 () == gettid ()) {
217
177
exit (1 );
218
178
} else {
219
- putstr ( "# Failed to set TPIDR2 in child\n" );
179
+ ksft_print_msg ( " Failed to set TPIDR2 in child\n" );
220
180
exit (0 );
221
181
}
222
182
}
@@ -227,61 +187,37 @@ static int write_clone_read(void)
227
187
if (waiting < 0 ) {
228
188
if (errno == EINTR )
229
189
continue ;
230
- putstr ("# wait4() failed: " );
231
- putnum (errno );
232
- putstr ("\n" );
190
+ ksft_print_msg ("wait4() failed: %d\n" , errno );
233
191
return 0 ;
234
192
}
235
193
if (waiting != ret ) {
236
- putstr ("# wait4() returned wrong PID " );
237
- putnum (waiting );
238
- putstr ("\n" );
194
+ ksft_print_msg ("wait4() returned wrong PID %d\n" ,
195
+ waiting );
239
196
return 0 ;
240
197
}
241
198
242
199
if (!WIFEXITED (status )) {
243
- putstr ( "# child did not exit\n" );
200
+ ksft_print_msg ( " child did not exit\n" );
244
201
return 0 ;
245
202
}
246
203
247
204
if (parent != get_tpidr2 ()) {
248
- putstr ( "# TPIDR2 corrupted in parent\n" );
205
+ ksft_print_msg ( " TPIDR2 corrupted in parent\n" );
249
206
return 0 ;
250
207
}
251
208
252
209
return WEXITSTATUS (status );
253
210
}
254
211
}
255
212
256
- #define run_test (name ) \
257
- if (name()) { \
258
- tests_passed++; \
259
- } else { \
260
- tests_failed++; \
261
- putstr("not "); \
262
- } \
263
- putstr("ok "); \
264
- putnum(++tests_run); \
265
- putstr(" " #name "\n");
266
-
267
- #define skip_test (name ) \
268
- tests_skipped++; \
269
- putstr("ok "); \
270
- putnum(++tests_run); \
271
- putstr(" # SKIP " #name "\n");
272
-
273
213
int main (int argc , char * * argv )
274
214
{
275
215
int ret ;
276
216
277
- putstr ("TAP version 13\n" );
278
- putstr ("1.." );
279
- putnum (EXPECTED_TESTS );
280
- putstr ("\n" );
217
+ ksft_print_header ();
218
+ ksft_set_plan (5 );
281
219
282
- putstr ("# PID: " );
283
- putnum (getpid ());
284
- putstr ("\n" );
220
+ ksft_print_msg ("PID: %d\n" , getpid ());
285
221
286
222
/*
287
223
* This test is run with nolibc which doesn't support hwcap and
@@ -290,23 +226,21 @@ int main(int argc, char **argv)
290
226
*/
291
227
ret = open ("/proc/sys/abi/sme_default_vector_length" , O_RDONLY , 0 );
292
228
if (ret >= 0 ) {
293
- run_test (default_value );
294
- run_test (write_read );
295
- run_test (write_sleep_read );
296
- run_test (write_fork_read );
297
- run_test (write_clone_read );
229
+ ksft_test_result (default_value (), "default_value\n" );
230
+ ksft_test_result (write_read , "write_read\n" );
231
+ ksft_test_result (write_sleep_read , "write_sleep_read\n" );
232
+ ksft_test_result (write_fork_read , "write_fork_read\n" );
233
+ ksft_test_result (write_clone_read , "write_clone_read\n" );
298
234
299
235
} else {
300
- putstr ( "# SME support not present\n" );
236
+ ksft_print_msg ( " SME support not present\n" );
301
237
302
- skip_test ( default_value );
303
- skip_test ( write_read );
304
- skip_test ( write_sleep_read );
305
- skip_test ( write_fork_read );
306
- skip_test ( write_clone_read );
238
+ ksft_test_result_skip ( " default_value\n" );
239
+ ksft_test_result_skip ( " write_read\n" );
240
+ ksft_test_result_skip ( " write_sleep_read\n" );
241
+ ksft_test_result_skip ( " write_fork_read\n" );
242
+ ksft_test_result_skip ( " write_clone_read\n" );
307
243
}
308
244
309
- print_summary ();
310
-
311
- return 0 ;
245
+ ksft_finished ();
312
246
}
0 commit comments