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