1 | /* |
---|
2 | * Copyright (c) 2015, 2018 embedded brains GmbH. All rights reserved. |
---|
3 | * |
---|
4 | * embedded brains GmbH |
---|
5 | * Dornierstr. 4 |
---|
6 | * 82178 Puchheim |
---|
7 | * Germany |
---|
8 | * <rtems@embedded-brains.de> |
---|
9 | * |
---|
10 | * The license and distribution terms for this file may be |
---|
11 | * found in the file LICENSE in this distribution or at |
---|
12 | * http://www.rtems.com/license/LICENSE. |
---|
13 | */ |
---|
14 | |
---|
15 | #ifdef HAVE_CONFIG_H |
---|
16 | #include "config.h" |
---|
17 | #endif |
---|
18 | |
---|
19 | #include "tmacros.h" |
---|
20 | |
---|
21 | #include <sys/types.h> |
---|
22 | #include <sys/mman.h> |
---|
23 | #include <sys/stat.h> |
---|
24 | |
---|
25 | #include <assert.h> |
---|
26 | #include <fcntl.h> |
---|
27 | #include <mqueue.h> |
---|
28 | #include <pthread.h> |
---|
29 | #include <semaphore.h> |
---|
30 | #include <signal.h> |
---|
31 | #include <stdlib.h> |
---|
32 | #include <string.h> |
---|
33 | #include <time.h> |
---|
34 | #include <unistd.h> |
---|
35 | |
---|
36 | #include <rtems.h> |
---|
37 | #include <rtems/ioimpl.h> |
---|
38 | #include <rtems/libio_.h> |
---|
39 | #include <rtems/sysinit.h> |
---|
40 | |
---|
41 | #include <rtems/extensionimpl.h> |
---|
42 | #include <rtems/posix/barrierimpl.h> |
---|
43 | #include <rtems/posix/mqueueimpl.h> |
---|
44 | #include <rtems/posix/muteximpl.h> |
---|
45 | #ifdef RTEMS_POSIX_API |
---|
46 | #include <rtems/posix/psignalimpl.h> |
---|
47 | #endif /* RTEMS_POSIX_API */ |
---|
48 | #include <rtems/posix/pthreadimpl.h> |
---|
49 | #include <rtems/posix/rwlockimpl.h> |
---|
50 | #include <rtems/posix/semaphoreimpl.h> |
---|
51 | #include <rtems/posix/shmimpl.h> |
---|
52 | #ifdef RTEMS_POSIX_API |
---|
53 | #include <rtems/posix/timerimpl.h> |
---|
54 | #endif /* RTEMS_POSIX_API */ |
---|
55 | #include <rtems/posix/keyimpl.h> |
---|
56 | #include <rtems/rtems/barrierimpl.h> |
---|
57 | #include <rtems/rtems/dpmemimpl.h> |
---|
58 | #include <rtems/rtems/messageimpl.h> |
---|
59 | #include <rtems/rtems/partimpl.h> |
---|
60 | #include <rtems/rtems/ratemonimpl.h> |
---|
61 | #include <rtems/rtems/regionimpl.h> |
---|
62 | #include <rtems/rtems/semimpl.h> |
---|
63 | #include <rtems/rtems/tasksimpl.h> |
---|
64 | #include <rtems/rtems/timerimpl.h> |
---|
65 | #include <rtems/score/apimutex.h> |
---|
66 | #include <rtems/score/chainimpl.h> |
---|
67 | #include <rtems/score/sysstate.h> |
---|
68 | #include <rtems/score/userextimpl.h> |
---|
69 | #include <rtems/score/wkspace.h> |
---|
70 | |
---|
71 | const char rtems_test_name[] = "SPSYSINIT 1"; |
---|
72 | |
---|
73 | typedef enum { |
---|
74 | BSP_WORK_AREAS_PRE, |
---|
75 | BSP_WORK_AREAS_POST, |
---|
76 | BSP_START_PRE, |
---|
77 | BSP_START_POST, |
---|
78 | CPU_COUNTER_PRE, |
---|
79 | CPU_COUNTER_POST, |
---|
80 | INITIAL_EXTENSIONS_PRE, |
---|
81 | INITIAL_EXTENSIONS_POST, |
---|
82 | DATA_STRUCTURES_PRE, |
---|
83 | DATA_STRUCTURES_POST, |
---|
84 | USER_EXTENSIONS_PRE, |
---|
85 | USER_EXTENSIONS_POST, |
---|
86 | CLASSIC_TASKS_PRE, |
---|
87 | CLASSIC_TASKS_POST, |
---|
88 | CLASSIC_TIMER_PRE, |
---|
89 | CLASSIC_TIMER_POST, |
---|
90 | CLASSIC_MESSAGE_QUEUE_PRE, |
---|
91 | CLASSIC_MESSAGE_QUEUE_POST, |
---|
92 | CLASSIC_SEMAPHORE_PRE, |
---|
93 | CLASSIC_SEMAPHORE_POST, |
---|
94 | CLASSIC_PARTITION_PRE, |
---|
95 | CLASSIC_PARTITION_POST, |
---|
96 | CLASSIC_REGION_PRE, |
---|
97 | CLASSIC_REGION_POST, |
---|
98 | CLASSIC_DUAL_PORTED_MEMORY_PRE, |
---|
99 | CLASSIC_DUAL_PORTED_MEMORY_POST, |
---|
100 | CLASSIC_RATE_MONOTONIC_PRE, |
---|
101 | CLASSIC_RATE_MONOTONIC_POST, |
---|
102 | CLASSIC_BARRIER_PRE, |
---|
103 | CLASSIC_BARRIER_POST, |
---|
104 | #ifdef RTEMS_POSIX_API |
---|
105 | POSIX_SIGNALS_PRE, |
---|
106 | POSIX_SIGNALS_POST, |
---|
107 | #endif /* RTEMS_POSIX_API */ |
---|
108 | POSIX_THREADS_PRE, |
---|
109 | POSIX_THREADS_POST, |
---|
110 | POSIX_MESSAGE_QUEUE_PRE, |
---|
111 | POSIX_MESSAGE_QUEUE_POST, |
---|
112 | POSIX_SEMAPHORE_PRE, |
---|
113 | POSIX_SEMAPHORE_POST, |
---|
114 | #ifdef RTEMS_POSIX_API |
---|
115 | POSIX_TIMER_PRE, |
---|
116 | POSIX_TIMER_POST, |
---|
117 | #endif /* RTEMS_POSIX_API */ |
---|
118 | POSIX_SHM_PRE, |
---|
119 | POSIX_SHM_POST, |
---|
120 | POSIX_KEYS_PRE, |
---|
121 | POSIX_KEYS_POST, |
---|
122 | POSIX_CLEANUP_PRE, |
---|
123 | POSIX_CLEANUP_POST, |
---|
124 | IDLE_THREADS_PRE, |
---|
125 | IDLE_THREADS_POST, |
---|
126 | LIBIO_PRE, |
---|
127 | LIBIO_POST, |
---|
128 | ROOT_FILESYSTEM_PRE, |
---|
129 | ROOT_FILESYSTEM_POST, |
---|
130 | BSP_PRE_DRIVERS_PRE, |
---|
131 | BSP_PRE_DRIVERS_POST, |
---|
132 | DEVICE_DRIVERS_PRE, |
---|
133 | DEVICE_DRIVERS_POST, |
---|
134 | CLASSIC_USER_TASKS_PRE, |
---|
135 | CLASSIC_USER_TASKS_POST, |
---|
136 | POSIX_USER_THREADS_PRE, |
---|
137 | POSIX_USER_THREADS_POST, |
---|
138 | STD_FILE_DESCRIPTORS_PRE, |
---|
139 | STD_FILE_DESCRIPTORS_POST, |
---|
140 | LAST_FIRST, |
---|
141 | LAST_SECOND, |
---|
142 | LAST_THIRD, |
---|
143 | LAST_FOURTH, |
---|
144 | LAST_FIFTH, |
---|
145 | LAST_SIXTH, |
---|
146 | LAST_SEVENTH, |
---|
147 | LAST_EIGHTH, |
---|
148 | LAST_NINETH, |
---|
149 | LAST_TENTH, |
---|
150 | LAST_MIDDLE, |
---|
151 | LAST_LAST, |
---|
152 | INIT_TASK, |
---|
153 | DONE |
---|
154 | } init_step; |
---|
155 | |
---|
156 | #define FIRST(x) \ |
---|
157 | static void x##_first(void); \ |
---|
158 | RTEMS_SYSINIT_ITEM( \ |
---|
159 | x##_first, \ |
---|
160 | x, \ |
---|
161 | RTEMS_SYSINIT_ORDER_FIRST \ |
---|
162 | ); \ |
---|
163 | static void x##_first(void) |
---|
164 | |
---|
165 | #define LAST(x) \ |
---|
166 | static void x##_last(void); \ |
---|
167 | RTEMS_SYSINIT_ITEM( \ |
---|
168 | x##_last, \ |
---|
169 | x, \ |
---|
170 | RTEMS_SYSINIT_ORDER_LAST \ |
---|
171 | ); \ |
---|
172 | static void x##_last(void) |
---|
173 | |
---|
174 | #define LAST_STEP(x) \ |
---|
175 | static void last_##x(void) \ |
---|
176 | { \ |
---|
177 | next_step(LAST_##x); \ |
---|
178 | } \ |
---|
179 | RTEMS_SYSINIT_ITEM( \ |
---|
180 | last_##x, \ |
---|
181 | RTEMS_SYSINIT_LAST, \ |
---|
182 | RTEMS_SYSINIT_ORDER_##x \ |
---|
183 | ) |
---|
184 | |
---|
185 | static init_step step; |
---|
186 | |
---|
187 | static void next_step(init_step expected) |
---|
188 | { |
---|
189 | assert(step == expected); |
---|
190 | step = expected + 1; |
---|
191 | } |
---|
192 | |
---|
193 | static bool info_not_init(const Objects_Information *info) |
---|
194 | { |
---|
195 | return _Chain_Is_empty(&info->Inactive); |
---|
196 | } |
---|
197 | |
---|
198 | static bool info_is_init(const Objects_Information *info, size_t count) |
---|
199 | { |
---|
200 | return _Chain_Node_count_unprotected(&info->Inactive) == count; |
---|
201 | } |
---|
202 | |
---|
203 | FIRST(RTEMS_SYSINIT_BSP_WORK_AREAS) |
---|
204 | { |
---|
205 | assert(_Workspace_Area.area_begin == 0); |
---|
206 | next_step(BSP_WORK_AREAS_PRE); |
---|
207 | } |
---|
208 | |
---|
209 | LAST(RTEMS_SYSINIT_BSP_WORK_AREAS) |
---|
210 | { |
---|
211 | assert(_Workspace_Area.area_begin != 0); |
---|
212 | next_step(BSP_WORK_AREAS_POST); |
---|
213 | } |
---|
214 | |
---|
215 | FIRST(RTEMS_SYSINIT_BSP_START) |
---|
216 | { |
---|
217 | /* |
---|
218 | * Since the work performed here is BSP-specific, there is no way to test pre |
---|
219 | * and post conditions. |
---|
220 | */ |
---|
221 | next_step(BSP_START_PRE); |
---|
222 | } |
---|
223 | |
---|
224 | LAST(RTEMS_SYSINIT_BSP_START) |
---|
225 | { |
---|
226 | /* |
---|
227 | * Some BSPs initialize the printk() support in bsp_start(). So, print begin |
---|
228 | * of test after bsp_start(). |
---|
229 | */ |
---|
230 | TEST_BEGIN(); |
---|
231 | |
---|
232 | next_step(BSP_START_POST); |
---|
233 | } |
---|
234 | |
---|
235 | FIRST(RTEMS_SYSINIT_CPU_COUNTER) |
---|
236 | { |
---|
237 | /* |
---|
238 | * Since the work performed here is BSP-specific, there is no way to test pre |
---|
239 | * and post conditions. |
---|
240 | */ |
---|
241 | next_step(CPU_COUNTER_PRE); |
---|
242 | } |
---|
243 | |
---|
244 | LAST(RTEMS_SYSINIT_CPU_COUNTER) |
---|
245 | { |
---|
246 | next_step(CPU_COUNTER_POST); |
---|
247 | } |
---|
248 | |
---|
249 | FIRST(RTEMS_SYSINIT_INITIAL_EXTENSIONS) |
---|
250 | { |
---|
251 | assert(_Chain_Is_empty(&_User_extensions_Switches_list)); |
---|
252 | next_step(INITIAL_EXTENSIONS_PRE); |
---|
253 | } |
---|
254 | |
---|
255 | LAST(RTEMS_SYSINIT_INITIAL_EXTENSIONS) |
---|
256 | { |
---|
257 | assert(!_Chain_Is_empty(&_User_extensions_Switches_list)); |
---|
258 | next_step(INITIAL_EXTENSIONS_POST); |
---|
259 | } |
---|
260 | |
---|
261 | FIRST(RTEMS_SYSINIT_DATA_STRUCTURES) |
---|
262 | { |
---|
263 | assert(info_not_init(&_Thread_Information.Objects)); |
---|
264 | next_step(DATA_STRUCTURES_PRE); |
---|
265 | } |
---|
266 | |
---|
267 | LAST(RTEMS_SYSINIT_DATA_STRUCTURES) |
---|
268 | { |
---|
269 | assert(info_is_init(&_Thread_Information.Objects, 1)); |
---|
270 | next_step(DATA_STRUCTURES_POST); |
---|
271 | } |
---|
272 | |
---|
273 | FIRST(RTEMS_SYSINIT_USER_EXTENSIONS) |
---|
274 | { |
---|
275 | assert(info_not_init(&_Extension_Information)); |
---|
276 | next_step(USER_EXTENSIONS_PRE); |
---|
277 | } |
---|
278 | |
---|
279 | LAST(RTEMS_SYSINIT_USER_EXTENSIONS) |
---|
280 | { |
---|
281 | assert(info_is_init(&_Extension_Information, 1)); |
---|
282 | next_step(USER_EXTENSIONS_POST); |
---|
283 | } |
---|
284 | |
---|
285 | FIRST(RTEMS_SYSINIT_CLASSIC_TASKS) |
---|
286 | { |
---|
287 | assert(info_not_init(&_RTEMS_tasks_Information.Objects)); |
---|
288 | next_step(CLASSIC_TASKS_PRE); |
---|
289 | } |
---|
290 | |
---|
291 | LAST(RTEMS_SYSINIT_CLASSIC_TASKS) |
---|
292 | { |
---|
293 | assert(info_is_init(&_RTEMS_tasks_Information.Objects, 2)); |
---|
294 | next_step(CLASSIC_TASKS_POST); |
---|
295 | } |
---|
296 | |
---|
297 | FIRST(RTEMS_SYSINIT_CLASSIC_TIMER) |
---|
298 | { |
---|
299 | assert(info_not_init(&_Timer_Information)); |
---|
300 | next_step(CLASSIC_TIMER_PRE); |
---|
301 | } |
---|
302 | |
---|
303 | LAST(RTEMS_SYSINIT_CLASSIC_TIMER) |
---|
304 | { |
---|
305 | assert(info_is_init(&_Timer_Information, 1)); |
---|
306 | next_step(CLASSIC_TIMER_POST); |
---|
307 | } |
---|
308 | |
---|
309 | FIRST(RTEMS_SYSINIT_CLASSIC_MESSAGE_QUEUE) |
---|
310 | { |
---|
311 | assert(info_not_init(&_Message_queue_Information)); |
---|
312 | next_step(CLASSIC_MESSAGE_QUEUE_PRE); |
---|
313 | } |
---|
314 | |
---|
315 | LAST(RTEMS_SYSINIT_CLASSIC_MESSAGE_QUEUE) |
---|
316 | { |
---|
317 | assert(info_is_init(&_Message_queue_Information, 1)); |
---|
318 | next_step(CLASSIC_MESSAGE_QUEUE_POST); |
---|
319 | } |
---|
320 | |
---|
321 | FIRST(RTEMS_SYSINIT_CLASSIC_SEMAPHORE) |
---|
322 | { |
---|
323 | assert(_Semaphore_Information.initial_objects[0].id == 0); |
---|
324 | next_step(CLASSIC_SEMAPHORE_PRE); |
---|
325 | } |
---|
326 | |
---|
327 | LAST(RTEMS_SYSINIT_CLASSIC_SEMAPHORE) |
---|
328 | { |
---|
329 | assert(_Semaphore_Information.initial_objects[0].id != 0); |
---|
330 | next_step(CLASSIC_SEMAPHORE_POST); |
---|
331 | } |
---|
332 | |
---|
333 | FIRST(RTEMS_SYSINIT_CLASSIC_PARTITION) |
---|
334 | { |
---|
335 | assert(info_not_init(&_Partition_Information)); |
---|
336 | next_step(CLASSIC_PARTITION_PRE); |
---|
337 | } |
---|
338 | |
---|
339 | LAST(RTEMS_SYSINIT_CLASSIC_PARTITION) |
---|
340 | { |
---|
341 | assert(info_is_init(&_Partition_Information, 1)); |
---|
342 | next_step(CLASSIC_PARTITION_POST); |
---|
343 | } |
---|
344 | |
---|
345 | FIRST(RTEMS_SYSINIT_CLASSIC_REGION) |
---|
346 | { |
---|
347 | assert(info_not_init(&_Region_Information)); |
---|
348 | next_step(CLASSIC_REGION_PRE); |
---|
349 | } |
---|
350 | |
---|
351 | LAST(RTEMS_SYSINIT_CLASSIC_REGION) |
---|
352 | { |
---|
353 | assert(info_is_init(&_Region_Information, 1)); |
---|
354 | next_step(CLASSIC_REGION_POST); |
---|
355 | } |
---|
356 | |
---|
357 | FIRST(RTEMS_SYSINIT_CLASSIC_DUAL_PORTED_MEMORY) |
---|
358 | { |
---|
359 | assert(info_not_init(&_Dual_ported_memory_Information)); |
---|
360 | next_step(CLASSIC_DUAL_PORTED_MEMORY_PRE); |
---|
361 | } |
---|
362 | |
---|
363 | LAST(RTEMS_SYSINIT_CLASSIC_DUAL_PORTED_MEMORY) |
---|
364 | { |
---|
365 | assert(info_is_init(&_Dual_ported_memory_Information, 1)); |
---|
366 | next_step(CLASSIC_DUAL_PORTED_MEMORY_POST); |
---|
367 | } |
---|
368 | |
---|
369 | FIRST(RTEMS_SYSINIT_CLASSIC_RATE_MONOTONIC) |
---|
370 | { |
---|
371 | assert(info_not_init(&_Rate_monotonic_Information)); |
---|
372 | next_step(CLASSIC_RATE_MONOTONIC_PRE); |
---|
373 | } |
---|
374 | |
---|
375 | LAST(RTEMS_SYSINIT_CLASSIC_RATE_MONOTONIC) |
---|
376 | { |
---|
377 | assert(info_is_init(&_Rate_monotonic_Information, 1)); |
---|
378 | next_step(CLASSIC_RATE_MONOTONIC_POST); |
---|
379 | } |
---|
380 | |
---|
381 | FIRST(RTEMS_SYSINIT_CLASSIC_BARRIER) |
---|
382 | { |
---|
383 | assert(info_not_init(&_Barrier_Information)); |
---|
384 | next_step(CLASSIC_BARRIER_PRE); |
---|
385 | } |
---|
386 | |
---|
387 | LAST(RTEMS_SYSINIT_CLASSIC_BARRIER) |
---|
388 | { |
---|
389 | assert(info_is_init(&_Barrier_Information, 1)); |
---|
390 | next_step(CLASSIC_BARRIER_POST); |
---|
391 | } |
---|
392 | |
---|
393 | #ifdef RTEMS_POSIX_API |
---|
394 | FIRST(RTEMS_SYSINIT_POSIX_SIGNALS) |
---|
395 | { |
---|
396 | assert( |
---|
397 | memcmp( |
---|
398 | &_POSIX_signals_Vectors, |
---|
399 | _POSIX_signals_Default_vectors, |
---|
400 | sizeof(_POSIX_signals_Vectors) |
---|
401 | ) != 0 |
---|
402 | ); |
---|
403 | next_step(POSIX_SIGNALS_PRE); |
---|
404 | } |
---|
405 | |
---|
406 | LAST(RTEMS_SYSINIT_POSIX_SIGNALS) |
---|
407 | { |
---|
408 | assert( |
---|
409 | memcmp( |
---|
410 | &_POSIX_signals_Vectors, |
---|
411 | _POSIX_signals_Default_vectors, |
---|
412 | sizeof(_POSIX_signals_Vectors) |
---|
413 | ) == 0 |
---|
414 | ); |
---|
415 | next_step(POSIX_SIGNALS_POST); |
---|
416 | } |
---|
417 | #endif /* RTEMS_POSIX_API */ |
---|
418 | |
---|
419 | FIRST(RTEMS_SYSINIT_POSIX_THREADS) |
---|
420 | { |
---|
421 | assert(info_not_init(&_POSIX_Threads_Information.Objects)); |
---|
422 | next_step(POSIX_THREADS_PRE); |
---|
423 | } |
---|
424 | |
---|
425 | LAST(RTEMS_SYSINIT_POSIX_THREADS) |
---|
426 | { |
---|
427 | assert(info_is_init(&_POSIX_Threads_Information.Objects, 1)); |
---|
428 | next_step(POSIX_THREADS_POST); |
---|
429 | } |
---|
430 | |
---|
431 | FIRST(RTEMS_SYSINIT_POSIX_MESSAGE_QUEUE) |
---|
432 | { |
---|
433 | assert(info_not_init(&_POSIX_Message_queue_Information)); |
---|
434 | next_step(POSIX_MESSAGE_QUEUE_PRE); |
---|
435 | } |
---|
436 | |
---|
437 | LAST(RTEMS_SYSINIT_POSIX_MESSAGE_QUEUE) |
---|
438 | { |
---|
439 | assert(info_is_init(&_POSIX_Message_queue_Information, 1)); |
---|
440 | next_step(POSIX_MESSAGE_QUEUE_POST); |
---|
441 | } |
---|
442 | |
---|
443 | FIRST(RTEMS_SYSINIT_POSIX_SEMAPHORE) |
---|
444 | { |
---|
445 | assert(info_not_init(&_POSIX_Semaphore_Information)); |
---|
446 | next_step(POSIX_SEMAPHORE_PRE); |
---|
447 | } |
---|
448 | |
---|
449 | LAST(RTEMS_SYSINIT_POSIX_SEMAPHORE) |
---|
450 | { |
---|
451 | assert(info_is_init(&_POSIX_Semaphore_Information, 1)); |
---|
452 | next_step(POSIX_SEMAPHORE_POST); |
---|
453 | } |
---|
454 | |
---|
455 | #ifdef RTEMS_POSIX_API |
---|
456 | FIRST(RTEMS_SYSINIT_POSIX_TIMER) |
---|
457 | { |
---|
458 | assert(info_not_init(&_POSIX_Timer_Information)); |
---|
459 | next_step(POSIX_TIMER_PRE); |
---|
460 | } |
---|
461 | |
---|
462 | LAST(RTEMS_SYSINIT_POSIX_TIMER) |
---|
463 | { |
---|
464 | assert(info_is_init(&_POSIX_Timer_Information, 1)); |
---|
465 | next_step(POSIX_TIMER_POST); |
---|
466 | } |
---|
467 | #endif /* RTEMS_POSIX_API */ |
---|
468 | |
---|
469 | FIRST(RTEMS_SYSINIT_POSIX_SHM) |
---|
470 | { |
---|
471 | assert(info_not_init(&_POSIX_Shm_Information)); |
---|
472 | next_step(POSIX_SHM_PRE); |
---|
473 | } |
---|
474 | |
---|
475 | LAST(RTEMS_SYSINIT_POSIX_SHM) |
---|
476 | { |
---|
477 | assert(info_is_init(&_POSIX_Shm_Information, 1)); |
---|
478 | next_step(POSIX_SHM_POST); |
---|
479 | } |
---|
480 | |
---|
481 | static size_t user_extensions_pre_posix_cleanup; |
---|
482 | |
---|
483 | FIRST(RTEMS_SYSINIT_POSIX_CLEANUP) |
---|
484 | { |
---|
485 | user_extensions_pre_posix_cleanup = |
---|
486 | _Chain_Node_count_unprotected(&_User_extensions_List.Active); |
---|
487 | next_step(POSIX_CLEANUP_PRE); |
---|
488 | } |
---|
489 | |
---|
490 | LAST(RTEMS_SYSINIT_POSIX_CLEANUP) |
---|
491 | { |
---|
492 | assert( |
---|
493 | user_extensions_pre_posix_cleanup + 1 == |
---|
494 | _Chain_Node_count_unprotected(&_User_extensions_List.Active) |
---|
495 | ); |
---|
496 | next_step(POSIX_CLEANUP_POST); |
---|
497 | } |
---|
498 | |
---|
499 | FIRST(RTEMS_SYSINIT_POSIX_KEYS) |
---|
500 | { |
---|
501 | assert(info_not_init(&_POSIX_Keys_Information)); |
---|
502 | next_step(POSIX_KEYS_PRE); |
---|
503 | } |
---|
504 | |
---|
505 | LAST(RTEMS_SYSINIT_POSIX_KEYS) |
---|
506 | { |
---|
507 | assert(info_is_init(&_POSIX_Keys_Information, 2)); |
---|
508 | next_step(POSIX_KEYS_POST); |
---|
509 | } |
---|
510 | |
---|
511 | FIRST(RTEMS_SYSINIT_IDLE_THREADS) |
---|
512 | { |
---|
513 | assert(_System_state_Is_before_initialization(_System_state_Get())); |
---|
514 | next_step(IDLE_THREADS_PRE); |
---|
515 | } |
---|
516 | |
---|
517 | LAST(RTEMS_SYSINIT_IDLE_THREADS) |
---|
518 | { |
---|
519 | assert(_System_state_Is_before_multitasking(_System_state_Get())); |
---|
520 | next_step(IDLE_THREADS_POST); |
---|
521 | } |
---|
522 | |
---|
523 | FIRST(RTEMS_SYSINIT_LIBIO) |
---|
524 | { |
---|
525 | assert(rtems_libio_iop_free_head == NULL); |
---|
526 | next_step(LIBIO_PRE); |
---|
527 | } |
---|
528 | |
---|
529 | LAST(RTEMS_SYSINIT_LIBIO) |
---|
530 | { |
---|
531 | assert(rtems_libio_iop_free_head == &rtems_libio_iops[0]); |
---|
532 | next_step(LIBIO_POST); |
---|
533 | } |
---|
534 | |
---|
535 | FIRST(RTEMS_SYSINIT_ROOT_FILESYSTEM) |
---|
536 | { |
---|
537 | struct stat st; |
---|
538 | int rv; |
---|
539 | |
---|
540 | rv = stat("/", &st); |
---|
541 | assert(rv == -1); |
---|
542 | next_step(ROOT_FILESYSTEM_PRE); |
---|
543 | } |
---|
544 | |
---|
545 | LAST(RTEMS_SYSINIT_ROOT_FILESYSTEM) |
---|
546 | { |
---|
547 | struct stat st; |
---|
548 | int rv; |
---|
549 | |
---|
550 | rv = stat("/", &st); |
---|
551 | assert(rv == 0); |
---|
552 | next_step(ROOT_FILESYSTEM_POST); |
---|
553 | } |
---|
554 | |
---|
555 | FIRST(RTEMS_SYSINIT_BSP_PRE_DRIVERS) |
---|
556 | { |
---|
557 | /* |
---|
558 | * Since the work performed here is BSP-specific, there is no way to test pre |
---|
559 | * and post conditions. |
---|
560 | */ |
---|
561 | next_step(BSP_PRE_DRIVERS_PRE); |
---|
562 | } |
---|
563 | |
---|
564 | LAST(RTEMS_SYSINIT_BSP_PRE_DRIVERS) |
---|
565 | { |
---|
566 | next_step(BSP_PRE_DRIVERS_POST); |
---|
567 | } |
---|
568 | |
---|
569 | FIRST(RTEMS_SYSINIT_DEVICE_DRIVERS) |
---|
570 | { |
---|
571 | assert(!_IO_All_drivers_initialized); |
---|
572 | next_step(DEVICE_DRIVERS_PRE); |
---|
573 | } |
---|
574 | |
---|
575 | LAST(RTEMS_SYSINIT_DEVICE_DRIVERS) |
---|
576 | { |
---|
577 | assert(_IO_All_drivers_initialized); |
---|
578 | next_step(DEVICE_DRIVERS_POST); |
---|
579 | } |
---|
580 | |
---|
581 | FIRST(RTEMS_SYSINIT_CLASSIC_USER_TASKS) |
---|
582 | { |
---|
583 | _Objects_Allocator_lock(); |
---|
584 | assert(_Objects_Active_count(&_RTEMS_tasks_Information.Objects) == 0); |
---|
585 | _Objects_Allocator_unlock(); |
---|
586 | next_step(CLASSIC_USER_TASKS_PRE); |
---|
587 | } |
---|
588 | |
---|
589 | LAST(RTEMS_SYSINIT_CLASSIC_USER_TASKS) |
---|
590 | { |
---|
591 | _Objects_Allocator_lock(); |
---|
592 | assert(_Objects_Active_count(&_RTEMS_tasks_Information.Objects) == 1); |
---|
593 | _Objects_Allocator_unlock(); |
---|
594 | next_step(CLASSIC_USER_TASKS_POST); |
---|
595 | } |
---|
596 | |
---|
597 | FIRST(RTEMS_SYSINIT_POSIX_USER_THREADS) |
---|
598 | { |
---|
599 | _Objects_Allocator_lock(); |
---|
600 | assert(_Objects_Active_count(&_POSIX_Threads_Information.Objects) == 0); |
---|
601 | _Objects_Allocator_unlock(); |
---|
602 | next_step(POSIX_USER_THREADS_PRE); |
---|
603 | } |
---|
604 | |
---|
605 | LAST(RTEMS_SYSINIT_POSIX_USER_THREADS) |
---|
606 | { |
---|
607 | _Objects_Allocator_lock(); |
---|
608 | assert(_Objects_Active_count(&_POSIX_Threads_Information.Objects) == 1); |
---|
609 | _Objects_Allocator_unlock(); |
---|
610 | next_step(POSIX_USER_THREADS_POST); |
---|
611 | } |
---|
612 | |
---|
613 | FIRST(RTEMS_SYSINIT_STD_FILE_DESCRIPTORS) |
---|
614 | { |
---|
615 | struct stat st; |
---|
616 | int rv; |
---|
617 | |
---|
618 | rv = fstat(0, &st); |
---|
619 | assert(rv == -1); |
---|
620 | next_step(STD_FILE_DESCRIPTORS_PRE); |
---|
621 | } |
---|
622 | |
---|
623 | LAST(RTEMS_SYSINIT_STD_FILE_DESCRIPTORS) |
---|
624 | { |
---|
625 | struct stat st; |
---|
626 | int rv; |
---|
627 | |
---|
628 | rv = fstat(0, &st); |
---|
629 | assert(rv == 0); |
---|
630 | next_step(STD_FILE_DESCRIPTORS_POST); |
---|
631 | } |
---|
632 | |
---|
633 | LAST_STEP(FIRST); |
---|
634 | LAST_STEP(SECOND); |
---|
635 | LAST_STEP(THIRD); |
---|
636 | LAST_STEP(FOURTH); |
---|
637 | LAST_STEP(FIFTH); |
---|
638 | LAST_STEP(SIXTH); |
---|
639 | LAST_STEP(SEVENTH); |
---|
640 | LAST_STEP(EIGHTH); |
---|
641 | LAST_STEP(NINETH); |
---|
642 | LAST_STEP(TENTH); |
---|
643 | LAST_STEP(MIDDLE); |
---|
644 | LAST_STEP(LAST); |
---|
645 | |
---|
646 | static void do_barrier_create(void) |
---|
647 | { |
---|
648 | rtems_status_code sc; |
---|
649 | rtems_id id; |
---|
650 | |
---|
651 | sc = rtems_barrier_create( |
---|
652 | rtems_build_name('T', 'E', 'S', 'T'), |
---|
653 | RTEMS_DEFAULT_ATTRIBUTES, |
---|
654 | 1, |
---|
655 | &id |
---|
656 | ); |
---|
657 | rtems_test_assert(sc == RTEMS_SUCCESSFUL); |
---|
658 | |
---|
659 | sc = rtems_barrier_delete(id); |
---|
660 | rtems_test_assert(sc == RTEMS_SUCCESSFUL); |
---|
661 | } |
---|
662 | |
---|
663 | static void do_extensions_create(void) |
---|
664 | { |
---|
665 | rtems_status_code sc; |
---|
666 | rtems_id id; |
---|
667 | rtems_extensions_table table; |
---|
668 | |
---|
669 | memset(&table, 0, sizeof(table)); |
---|
670 | sc = rtems_extension_create( |
---|
671 | rtems_build_name('T', 'E', 'S', 'T'), |
---|
672 | &table, |
---|
673 | &id |
---|
674 | ); |
---|
675 | rtems_test_assert(sc == RTEMS_SUCCESSFUL); |
---|
676 | |
---|
677 | sc = rtems_extension_delete(id); |
---|
678 | rtems_test_assert(sc == RTEMS_SUCCESSFUL); |
---|
679 | } |
---|
680 | |
---|
681 | static void do_message_queue_create(void) |
---|
682 | { |
---|
683 | rtems_status_code sc; |
---|
684 | rtems_id id; |
---|
685 | |
---|
686 | sc = rtems_message_queue_create( |
---|
687 | rtems_build_name('T', 'E', 'S', 'T'), |
---|
688 | 1, |
---|
689 | 1, |
---|
690 | RTEMS_DEFAULT_ATTRIBUTES, |
---|
691 | &id |
---|
692 | ); |
---|
693 | rtems_test_assert(sc == RTEMS_SUCCESSFUL); |
---|
694 | |
---|
695 | sc = rtems_message_queue_delete(id); |
---|
696 | rtems_test_assert(sc == RTEMS_SUCCESSFUL); |
---|
697 | } |
---|
698 | |
---|
699 | static void do_partition_create(void) |
---|
700 | { |
---|
701 | rtems_status_code sc; |
---|
702 | rtems_id id; |
---|
703 | long buf[32]; |
---|
704 | |
---|
705 | sc = rtems_partition_create( |
---|
706 | rtems_build_name('T', 'E', 'S', 'T'), |
---|
707 | buf, |
---|
708 | sizeof(buf), |
---|
709 | sizeof(buf), |
---|
710 | RTEMS_DEFAULT_ATTRIBUTES, |
---|
711 | &id |
---|
712 | ); |
---|
713 | rtems_test_assert(sc == RTEMS_SUCCESSFUL); |
---|
714 | |
---|
715 | sc = rtems_partition_delete(id); |
---|
716 | rtems_test_assert(sc == RTEMS_SUCCESSFUL); |
---|
717 | } |
---|
718 | |
---|
719 | static void do_period_create(void) |
---|
720 | { |
---|
721 | rtems_status_code sc; |
---|
722 | rtems_id id; |
---|
723 | |
---|
724 | sc = rtems_rate_monotonic_create( |
---|
725 | rtems_build_name('T', 'E', 'S', 'T'), |
---|
726 | &id |
---|
727 | ); |
---|
728 | rtems_test_assert(sc == RTEMS_SUCCESSFUL); |
---|
729 | |
---|
730 | sc = rtems_rate_monotonic_delete(id); |
---|
731 | rtems_test_assert(sc == RTEMS_SUCCESSFUL); |
---|
732 | } |
---|
733 | |
---|
734 | static void do_port_create(void) |
---|
735 | { |
---|
736 | rtems_status_code sc; |
---|
737 | rtems_id id; |
---|
738 | |
---|
739 | sc = rtems_port_create( |
---|
740 | rtems_build_name('T', 'E', 'S', 'T'), |
---|
741 | NULL, |
---|
742 | NULL, |
---|
743 | 1, |
---|
744 | &id |
---|
745 | ); |
---|
746 | rtems_test_assert(sc == RTEMS_SUCCESSFUL); |
---|
747 | |
---|
748 | sc = rtems_port_delete(id); |
---|
749 | rtems_test_assert(sc == RTEMS_SUCCESSFUL); |
---|
750 | } |
---|
751 | |
---|
752 | static void do_region_create(void) |
---|
753 | { |
---|
754 | rtems_status_code sc; |
---|
755 | rtems_id id; |
---|
756 | long buf[32]; |
---|
757 | |
---|
758 | sc = rtems_region_create( |
---|
759 | rtems_build_name('T', 'E', 'S', 'T'), |
---|
760 | buf, |
---|
761 | sizeof(buf), |
---|
762 | 1, |
---|
763 | RTEMS_DEFAULT_ATTRIBUTES, |
---|
764 | &id |
---|
765 | ); |
---|
766 | rtems_test_assert(sc == RTEMS_SUCCESSFUL); |
---|
767 | |
---|
768 | sc = rtems_region_delete(id); |
---|
769 | rtems_test_assert(sc == RTEMS_SUCCESSFUL); |
---|
770 | } |
---|
771 | |
---|
772 | static void do_semaphore_create(void) |
---|
773 | { |
---|
774 | rtems_status_code sc; |
---|
775 | rtems_id id; |
---|
776 | |
---|
777 | sc = rtems_semaphore_create( |
---|
778 | rtems_build_name('T', 'E', 'S', 'T'), |
---|
779 | 0, |
---|
780 | RTEMS_DEFAULT_ATTRIBUTES, |
---|
781 | 0, |
---|
782 | &id |
---|
783 | ); |
---|
784 | rtems_test_assert(sc == RTEMS_SUCCESSFUL); |
---|
785 | |
---|
786 | sc = rtems_semaphore_delete(id); |
---|
787 | rtems_test_assert(sc == RTEMS_SUCCESSFUL); |
---|
788 | } |
---|
789 | |
---|
790 | static void do_task_create(void) |
---|
791 | { |
---|
792 | rtems_status_code sc; |
---|
793 | rtems_id id; |
---|
794 | |
---|
795 | sc = rtems_task_create( |
---|
796 | rtems_build_name('T', 'E', 'S', 'T'), |
---|
797 | 1, |
---|
798 | RTEMS_MINIMUM_STACK_SIZE, |
---|
799 | RTEMS_DEFAULT_MODES, |
---|
800 | RTEMS_DEFAULT_ATTRIBUTES, |
---|
801 | &id |
---|
802 | ); |
---|
803 | rtems_test_assert(sc == RTEMS_SUCCESSFUL); |
---|
804 | |
---|
805 | sc = rtems_task_delete(id); |
---|
806 | rtems_test_assert(sc == RTEMS_SUCCESSFUL); |
---|
807 | } |
---|
808 | |
---|
809 | static void do_timer_create(void) |
---|
810 | { |
---|
811 | rtems_status_code sc; |
---|
812 | rtems_id id; |
---|
813 | |
---|
814 | sc = rtems_timer_create(rtems_build_name('T', 'E', 'S', 'T'), &id); |
---|
815 | rtems_test_assert(sc == RTEMS_SUCCESSFUL); |
---|
816 | |
---|
817 | sc = rtems_timer_delete(id); |
---|
818 | rtems_test_assert(sc == RTEMS_SUCCESSFUL); |
---|
819 | } |
---|
820 | |
---|
821 | static void do_cleanup_push_pop(void) |
---|
822 | { |
---|
823 | pthread_cleanup_push(NULL, NULL); |
---|
824 | pthread_cleanup_pop(0); |
---|
825 | } |
---|
826 | |
---|
827 | static void do_posix_mq_open(void) |
---|
828 | { |
---|
829 | struct mq_attr attr; |
---|
830 | mqd_t mq; |
---|
831 | int rv; |
---|
832 | |
---|
833 | memset(&attr, 0, sizeof(attr)); |
---|
834 | attr.mq_maxmsg = 1; |
---|
835 | attr.mq_msgsize = 1; |
---|
836 | mq = mq_open("mq", O_CREAT | O_RDWR, S_IRWXU | S_IRWXG | S_IRWXO, &attr); |
---|
837 | rtems_test_assert(mq != (mqd_t) -1); |
---|
838 | |
---|
839 | rv = mq_close(mq); |
---|
840 | rtems_test_assert(rv == 0); |
---|
841 | |
---|
842 | rv = mq_unlink("mq"); |
---|
843 | rtems_test_assert(rv == 0); |
---|
844 | } |
---|
845 | |
---|
846 | static void do_posix_sem_open(void) |
---|
847 | { |
---|
848 | sem_t *sem; |
---|
849 | int rv; |
---|
850 | |
---|
851 | sem = sem_open("sem", O_CREAT | O_RDWR, S_IRWXU | S_IRWXG | S_IRWXO); |
---|
852 | rtems_test_assert(sem != SEM_FAILED); |
---|
853 | |
---|
854 | rv = sem_close(sem); |
---|
855 | rtems_test_assert(rv == 0); |
---|
856 | |
---|
857 | rv = sem_unlink("sem"); |
---|
858 | rtems_test_assert(rv == 0); |
---|
859 | } |
---|
860 | |
---|
861 | static void do_posix_shm_open(void) |
---|
862 | { |
---|
863 | int fd; |
---|
864 | int rv; |
---|
865 | |
---|
866 | fd = shm_open("/shm", O_CREAT | O_RDWR, S_IRWXU | S_IRWXG | S_IRWXO); |
---|
867 | rtems_test_assert(fd >= 0); |
---|
868 | |
---|
869 | rv = close(fd); |
---|
870 | rtems_test_assert(rv == 0); |
---|
871 | |
---|
872 | rv = shm_unlink("/shm"); |
---|
873 | rtems_test_assert(rv == 0); |
---|
874 | } |
---|
875 | |
---|
876 | static void do_posix_timer_create(void) |
---|
877 | { |
---|
878 | #ifdef RTEMS_POSIX_API |
---|
879 | int rv; |
---|
880 | timer_t timer; |
---|
881 | |
---|
882 | rv = timer_create(CLOCK_REALTIME, NULL, &timer); |
---|
883 | rtems_test_assert(rv == 0); |
---|
884 | |
---|
885 | rv = timer_delete(timer); |
---|
886 | rtems_test_assert(rv == 0); |
---|
887 | #endif /* RTEMS_POSIX_API */ |
---|
888 | } |
---|
889 | |
---|
890 | static void Init(rtems_task_argument arg) |
---|
891 | { |
---|
892 | next_step(INIT_TASK); |
---|
893 | do_barrier_create(); |
---|
894 | do_extensions_create(); |
---|
895 | do_message_queue_create(); |
---|
896 | do_partition_create(); |
---|
897 | do_period_create(); |
---|
898 | do_port_create(); |
---|
899 | do_region_create(); |
---|
900 | do_semaphore_create(); |
---|
901 | do_task_create(); |
---|
902 | do_timer_create(); |
---|
903 | do_cleanup_push_pop(); |
---|
904 | do_posix_mq_open(); |
---|
905 | do_posix_sem_open(); |
---|
906 | do_posix_shm_open(); |
---|
907 | do_posix_timer_create(); |
---|
908 | TEST_END(); |
---|
909 | exit(0); |
---|
910 | } |
---|
911 | |
---|
912 | static void *POSIX_Init(void *arg) |
---|
913 | { |
---|
914 | return NULL; |
---|
915 | } |
---|
916 | |
---|
917 | #define CONFIGURE_APPLICATION_DOES_NOT_NEED_CLOCK_DRIVER |
---|
918 | |
---|
919 | #define CONFIGURE_APPLICATION_NEEDS_SIMPLE_CONSOLE_DRIVER |
---|
920 | |
---|
921 | #define CONFIGURE_MAXIMUM_FILE_DESCRIPTORS 4 |
---|
922 | |
---|
923 | #define CONFIGURE_MAXIMUM_USER_EXTENSIONS 1 |
---|
924 | |
---|
925 | #define CONFIGURE_MAXIMUM_BARRIERS 1 |
---|
926 | |
---|
927 | #define CONFIGURE_MAXIMUM_MESSAGE_QUEUES 1 |
---|
928 | |
---|
929 | #define CONFIGURE_MAXIMUM_PARTITIONS 1 |
---|
930 | |
---|
931 | #define CONFIGURE_MAXIMUM_PERIODS 1 |
---|
932 | |
---|
933 | #define CONFIGURE_MAXIMUM_PORTS 1 |
---|
934 | |
---|
935 | #define CONFIGURE_MAXIMUM_REGIONS 1 |
---|
936 | |
---|
937 | #define CONFIGURE_MAXIMUM_SEMAPHORES 1 |
---|
938 | |
---|
939 | #define CONFIGURE_MAXIMUM_TASKS 2 |
---|
940 | |
---|
941 | #define CONFIGURE_MAXIMUM_TIMERS 1 |
---|
942 | |
---|
943 | #define CONFIGURE_MAXIMUM_POSIX_MESSAGE_QUEUES 1 |
---|
944 | |
---|
945 | #define CONFIGURE_MAXIMUM_POSIX_SEMAPHORES 1 |
---|
946 | |
---|
947 | #define CONFIGURE_MAXIMUM_POSIX_SHMS 1 |
---|
948 | |
---|
949 | #ifdef RTEMS_POSIX_API |
---|
950 | #define CONFIGURE_MAXIMUM_POSIX_TIMERS 1 |
---|
951 | #endif /* RTEMS_POSIX_API */ |
---|
952 | |
---|
953 | #define CONFIGURE_MAXIMUM_POSIX_THREADS 1 |
---|
954 | |
---|
955 | #define CONFIGURE_POSIX_INIT_THREAD_TABLE |
---|
956 | |
---|
957 | #define CONFIGURE_MAXIMUM_POSIX_KEYS 1 |
---|
958 | |
---|
959 | #define CONFIGURE_MESSAGE_BUFFER_MEMORY \ |
---|
960 | CONFIGURE_MESSAGE_BUFFERS_FOR_QUEUE(1, 1) |
---|
961 | |
---|
962 | #define CONFIGURE_RTEMS_INIT_TASKS_TABLE |
---|
963 | |
---|
964 | #define CONFIGURE_STACK_CHECKER_ENABLED |
---|
965 | |
---|
966 | #define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION |
---|
967 | |
---|
968 | #define CONFIGURE_INIT |
---|
969 | |
---|
970 | #include <rtems/confdefs.h> |
---|