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