1 | /* |
---|
2 | * Copyright (c) 2015 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 <assert.h> |
---|
20 | #include <string.h> |
---|
21 | #include <stdlib.h> |
---|
22 | |
---|
23 | #include <rtems.h> |
---|
24 | #include <rtems/libio_.h> |
---|
25 | #include <rtems/sysinit.h> |
---|
26 | #include <rtems/test.h> |
---|
27 | |
---|
28 | #include <rtems/extensionimpl.h> |
---|
29 | #ifdef RTEMS_POSIX_API |
---|
30 | #include <rtems/posix/psignalimpl.h> |
---|
31 | #include <rtems/posix/pthreadimpl.h> |
---|
32 | #endif /* RTEMS_POSIX_API */ |
---|
33 | #include <rtems/rtems/barrierimpl.h> |
---|
34 | #include <rtems/rtems/dpmemimpl.h> |
---|
35 | #include <rtems/rtems/messageimpl.h> |
---|
36 | #include <rtems/rtems/partimpl.h> |
---|
37 | #include <rtems/rtems/ratemonimpl.h> |
---|
38 | #include <rtems/rtems/regionimpl.h> |
---|
39 | #include <rtems/rtems/semimpl.h> |
---|
40 | #include <rtems/rtems/tasksimpl.h> |
---|
41 | #include <rtems/rtems/timerimpl.h> |
---|
42 | #include <rtems/score/apimutex.h> |
---|
43 | #include <rtems/score/sysstate.h> |
---|
44 | #include <rtems/score/userextimpl.h> |
---|
45 | #include <rtems/score/wkspace.h> |
---|
46 | |
---|
47 | const char rtems_test_name[] = "SPSYSINIT 1"; |
---|
48 | |
---|
49 | typedef enum { |
---|
50 | BSP_WORK_AREAS_PRE, |
---|
51 | BSP_WORK_AREAS_POST, |
---|
52 | BSP_START_PRE, |
---|
53 | BSP_START_POST, |
---|
54 | INITIAL_EXTENSIONS_PRE, |
---|
55 | INITIAL_EXTENSIONS_POST, |
---|
56 | DATA_STRUCTURES_PRE, |
---|
57 | DATA_STRUCTURES_POST, |
---|
58 | USER_EXTENSIONS_PRE, |
---|
59 | USER_EXTENSIONS_POST, |
---|
60 | CLASSIC_TASKS_PRE, |
---|
61 | CLASSIC_TASKS_POST, |
---|
62 | CLASSIC_TIMER_PRE, |
---|
63 | CLASSIC_TIMER_POST, |
---|
64 | CLASSIC_SIGNAL_PRE, |
---|
65 | CLASSIC_SIGNAL_POST, |
---|
66 | CLASSIC_EVENT_PRE, |
---|
67 | CLASSIC_EVENT_POST, |
---|
68 | CLASSIC_MESSAGE_QUEUE_PRE, |
---|
69 | CLASSIC_MESSAGE_QUEUE_POST, |
---|
70 | CLASSIC_SEMAPHORE_PRE, |
---|
71 | CLASSIC_SEMAPHORE_POST, |
---|
72 | CLASSIC_PARTITION_PRE, |
---|
73 | CLASSIC_PARTITION_POST, |
---|
74 | CLASSIC_REGION_PRE, |
---|
75 | CLASSIC_REGION_POST, |
---|
76 | CLASSIC_DUAL_PORTED_MEMORY_PRE, |
---|
77 | CLASSIC_DUAL_PORTED_MEMORY_POST, |
---|
78 | CLASSIC_RATE_MONOTONIC_PRE, |
---|
79 | CLASSIC_RATE_MONOTONIC_POST, |
---|
80 | CLASSIC_BARRIER_PRE, |
---|
81 | CLASSIC_BARRIER_POST, |
---|
82 | #ifdef RTEMS_POSIX_API |
---|
83 | POSIX_SIGNALS_PRE, |
---|
84 | POSIX_SIGNALS_POST, |
---|
85 | POSIX_THREADS_PRE, |
---|
86 | POSIX_THREADS_POST, |
---|
87 | #endif /* RTEMS_POSIX_API */ |
---|
88 | IDLE_THREADS_PRE, |
---|
89 | IDLE_THREADS_POST, |
---|
90 | BSP_LIBC_PRE, |
---|
91 | BSP_LIBC_POST, |
---|
92 | BEFORE_DRIVERS_PRE, |
---|
93 | BEFORE_DRIVERS_POST, |
---|
94 | BSP_PRE_DRIVERS_PRE, |
---|
95 | BSP_PRE_DRIVERS_POST, |
---|
96 | DEVICE_DRIVERS_PRE, |
---|
97 | DEVICE_DRIVERS_POST, |
---|
98 | BSP_POST_DRIVERS_PRE, |
---|
99 | BSP_POST_DRIVERS_POST, |
---|
100 | INIT_TASK, |
---|
101 | DONE |
---|
102 | } init_step; |
---|
103 | |
---|
104 | #define FIRST(x) \ |
---|
105 | static void x##_first(void); \ |
---|
106 | RTEMS_SYSINIT_ITEM( \ |
---|
107 | x##_first, \ |
---|
108 | x, \ |
---|
109 | RTEMS_SYSINIT_ORDER_FIRST \ |
---|
110 | ); \ |
---|
111 | static void x##_first(void) |
---|
112 | |
---|
113 | #define LAST(x) \ |
---|
114 | static void x##_last(void); \ |
---|
115 | RTEMS_SYSINIT_ITEM( \ |
---|
116 | x##_last, \ |
---|
117 | x, \ |
---|
118 | RTEMS_SYSINIT_ORDER_LAST \ |
---|
119 | ); \ |
---|
120 | static void x##_last(void) |
---|
121 | |
---|
122 | static init_step step; |
---|
123 | |
---|
124 | static void next_step(init_step expected) |
---|
125 | { |
---|
126 | assert(step == expected); |
---|
127 | step = expected + 1; |
---|
128 | } |
---|
129 | |
---|
130 | FIRST(RTEMS_SYSINIT_BSP_WORK_AREAS) |
---|
131 | { |
---|
132 | rtems_test_begink(); |
---|
133 | assert(_Workspace_Area.area_begin == 0); |
---|
134 | next_step(BSP_WORK_AREAS_PRE); |
---|
135 | } |
---|
136 | |
---|
137 | LAST(RTEMS_SYSINIT_BSP_WORK_AREAS) |
---|
138 | { |
---|
139 | assert(_Workspace_Area.area_begin != 0); |
---|
140 | next_step(BSP_WORK_AREAS_POST); |
---|
141 | } |
---|
142 | |
---|
143 | FIRST(RTEMS_SYSINIT_BSP_START) |
---|
144 | { |
---|
145 | /* |
---|
146 | * Since the work performed here is BSP-specific, there is no way to test pre |
---|
147 | * and post conditions. |
---|
148 | */ |
---|
149 | next_step(BSP_START_PRE); |
---|
150 | } |
---|
151 | |
---|
152 | LAST(RTEMS_SYSINIT_BSP_START) |
---|
153 | { |
---|
154 | next_step(BSP_START_POST); |
---|
155 | } |
---|
156 | |
---|
157 | FIRST(RTEMS_SYSINIT_INITIAL_EXTENSIONS) |
---|
158 | { |
---|
159 | assert(_Chain_Is_empty(&_User_extensions_Switches_list)); |
---|
160 | next_step(INITIAL_EXTENSIONS_PRE); |
---|
161 | } |
---|
162 | |
---|
163 | LAST(RTEMS_SYSINIT_INITIAL_EXTENSIONS) |
---|
164 | { |
---|
165 | assert(!_Chain_Is_empty(&_User_extensions_Switches_list)); |
---|
166 | next_step(INITIAL_EXTENSIONS_POST); |
---|
167 | } |
---|
168 | |
---|
169 | FIRST(RTEMS_SYSINIT_DATA_STRUCTURES) |
---|
170 | { |
---|
171 | assert(_RTEMS_Allocator_Mutex == NULL); |
---|
172 | next_step(DATA_STRUCTURES_PRE); |
---|
173 | } |
---|
174 | |
---|
175 | LAST(RTEMS_SYSINIT_DATA_STRUCTURES) |
---|
176 | { |
---|
177 | assert(_RTEMS_Allocator_Mutex != NULL); |
---|
178 | next_step(DATA_STRUCTURES_POST); |
---|
179 | } |
---|
180 | |
---|
181 | FIRST(RTEMS_SYSINIT_USER_EXTENSIONS) |
---|
182 | { |
---|
183 | assert(_Extension_Information.maximum == 0); |
---|
184 | next_step(USER_EXTENSIONS_PRE); |
---|
185 | } |
---|
186 | |
---|
187 | LAST(RTEMS_SYSINIT_USER_EXTENSIONS) |
---|
188 | { |
---|
189 | assert(_Extension_Information.maximum != 0); |
---|
190 | next_step(USER_EXTENSIONS_POST); |
---|
191 | } |
---|
192 | |
---|
193 | FIRST(RTEMS_SYSINIT_CLASSIC_TASKS) |
---|
194 | { |
---|
195 | assert(_RTEMS_tasks_Information.Objects.maximum == 0); |
---|
196 | next_step(CLASSIC_TASKS_PRE); |
---|
197 | } |
---|
198 | |
---|
199 | LAST(RTEMS_SYSINIT_CLASSIC_TASKS) |
---|
200 | { |
---|
201 | assert(_RTEMS_tasks_Information.Objects.maximum != 0); |
---|
202 | next_step(CLASSIC_TASKS_POST); |
---|
203 | } |
---|
204 | |
---|
205 | FIRST(RTEMS_SYSINIT_CLASSIC_TIMER) |
---|
206 | { |
---|
207 | assert(_Timer_Information.maximum == 0); |
---|
208 | next_step(CLASSIC_TIMER_PRE); |
---|
209 | } |
---|
210 | |
---|
211 | LAST(RTEMS_SYSINIT_CLASSIC_TIMER) |
---|
212 | { |
---|
213 | assert(_Timer_Information.maximum != 0); |
---|
214 | next_step(CLASSIC_TIMER_POST); |
---|
215 | } |
---|
216 | |
---|
217 | FIRST(RTEMS_SYSINIT_CLASSIC_SIGNAL) |
---|
218 | { |
---|
219 | /* There is nothing to do in case RTEMS_MULTIPROCESSING is not defined */ |
---|
220 | next_step(CLASSIC_SIGNAL_PRE); |
---|
221 | } |
---|
222 | |
---|
223 | LAST(RTEMS_SYSINIT_CLASSIC_SIGNAL) |
---|
224 | { |
---|
225 | next_step(CLASSIC_SIGNAL_POST); |
---|
226 | } |
---|
227 | |
---|
228 | FIRST(RTEMS_SYSINIT_CLASSIC_EVENT) |
---|
229 | { |
---|
230 | /* There is nothing to do in case RTEMS_MULTIPROCESSING is not defined */ |
---|
231 | next_step(CLASSIC_EVENT_PRE); |
---|
232 | } |
---|
233 | |
---|
234 | LAST(RTEMS_SYSINIT_CLASSIC_EVENT) |
---|
235 | { |
---|
236 | next_step(CLASSIC_EVENT_POST); |
---|
237 | } |
---|
238 | |
---|
239 | FIRST(RTEMS_SYSINIT_CLASSIC_MESSAGE_QUEUE) |
---|
240 | { |
---|
241 | assert(_Message_queue_Information.maximum == 0); |
---|
242 | next_step(CLASSIC_MESSAGE_QUEUE_PRE); |
---|
243 | } |
---|
244 | |
---|
245 | LAST(RTEMS_SYSINIT_CLASSIC_MESSAGE_QUEUE) |
---|
246 | { |
---|
247 | assert(_Message_queue_Information.maximum != 0); |
---|
248 | next_step(CLASSIC_MESSAGE_QUEUE_POST); |
---|
249 | } |
---|
250 | |
---|
251 | FIRST(RTEMS_SYSINIT_CLASSIC_SEMAPHORE) |
---|
252 | { |
---|
253 | assert(_Semaphore_Information.maximum == 0); |
---|
254 | next_step(CLASSIC_SEMAPHORE_PRE); |
---|
255 | } |
---|
256 | |
---|
257 | LAST(RTEMS_SYSINIT_CLASSIC_SEMAPHORE) |
---|
258 | { |
---|
259 | assert(_Semaphore_Information.maximum != 0); |
---|
260 | next_step(CLASSIC_SEMAPHORE_POST); |
---|
261 | } |
---|
262 | |
---|
263 | FIRST(RTEMS_SYSINIT_CLASSIC_PARTITION) |
---|
264 | { |
---|
265 | assert(_Partition_Information.maximum == 0); |
---|
266 | next_step(CLASSIC_PARTITION_PRE); |
---|
267 | } |
---|
268 | |
---|
269 | LAST(RTEMS_SYSINIT_CLASSIC_PARTITION) |
---|
270 | { |
---|
271 | assert(_Partition_Information.maximum != 0); |
---|
272 | next_step(CLASSIC_PARTITION_POST); |
---|
273 | } |
---|
274 | |
---|
275 | FIRST(RTEMS_SYSINIT_CLASSIC_REGION) |
---|
276 | { |
---|
277 | assert(_Region_Information.maximum == 0); |
---|
278 | next_step(CLASSIC_REGION_PRE); |
---|
279 | } |
---|
280 | |
---|
281 | LAST(RTEMS_SYSINIT_CLASSIC_REGION) |
---|
282 | { |
---|
283 | assert(_Region_Information.maximum != 0); |
---|
284 | next_step(CLASSIC_REGION_POST); |
---|
285 | } |
---|
286 | |
---|
287 | FIRST(RTEMS_SYSINIT_CLASSIC_DUAL_PORTED_MEMORY) |
---|
288 | { |
---|
289 | assert(_Dual_ported_memory_Information.maximum == 0); |
---|
290 | next_step(CLASSIC_DUAL_PORTED_MEMORY_PRE); |
---|
291 | } |
---|
292 | |
---|
293 | LAST(RTEMS_SYSINIT_CLASSIC_DUAL_PORTED_MEMORY) |
---|
294 | { |
---|
295 | assert(_Dual_ported_memory_Information.maximum != 0); |
---|
296 | next_step(CLASSIC_DUAL_PORTED_MEMORY_POST); |
---|
297 | } |
---|
298 | |
---|
299 | FIRST(RTEMS_SYSINIT_CLASSIC_RATE_MONOTONIC) |
---|
300 | { |
---|
301 | assert(_Rate_monotonic_Information.maximum == 0); |
---|
302 | next_step(CLASSIC_RATE_MONOTONIC_PRE); |
---|
303 | } |
---|
304 | |
---|
305 | LAST(RTEMS_SYSINIT_CLASSIC_RATE_MONOTONIC) |
---|
306 | { |
---|
307 | assert(_Rate_monotonic_Information.maximum != 0); |
---|
308 | next_step(CLASSIC_RATE_MONOTONIC_POST); |
---|
309 | } |
---|
310 | |
---|
311 | FIRST(RTEMS_SYSINIT_CLASSIC_BARRIER) |
---|
312 | { |
---|
313 | assert(_Barrier_Information.maximum == 0); |
---|
314 | next_step(CLASSIC_BARRIER_PRE); |
---|
315 | } |
---|
316 | |
---|
317 | LAST(RTEMS_SYSINIT_CLASSIC_BARRIER) |
---|
318 | { |
---|
319 | assert(_Barrier_Information.maximum != 0); |
---|
320 | next_step(CLASSIC_BARRIER_POST); |
---|
321 | } |
---|
322 | |
---|
323 | #ifdef RTEMS_POSIX_API |
---|
324 | |
---|
325 | FIRST(RTEMS_SYSINIT_POSIX_SIGNALS) |
---|
326 | { |
---|
327 | assert( |
---|
328 | memcmp( |
---|
329 | &_POSIX_signals_Vectors, |
---|
330 | _POSIX_signals_Default_vectors, |
---|
331 | sizeof(_POSIX_signals_Vectors) |
---|
332 | ) != 0 |
---|
333 | ); |
---|
334 | next_step(POSIX_SIGNALS_PRE); |
---|
335 | } |
---|
336 | |
---|
337 | LAST(RTEMS_SYSINIT_POSIX_SIGNALS) |
---|
338 | { |
---|
339 | assert( |
---|
340 | memcmp( |
---|
341 | &_POSIX_signals_Vectors, |
---|
342 | _POSIX_signals_Default_vectors, |
---|
343 | sizeof(_POSIX_signals_Vectors) |
---|
344 | ) == 0 |
---|
345 | ); |
---|
346 | next_step(POSIX_SIGNALS_POST); |
---|
347 | } |
---|
348 | |
---|
349 | FIRST(RTEMS_SYSINIT_POSIX_THREADS) |
---|
350 | { |
---|
351 | assert(_POSIX_Threads_Information.Objects.maximum == 0); |
---|
352 | next_step(POSIX_THREADS_PRE); |
---|
353 | } |
---|
354 | |
---|
355 | LAST(RTEMS_SYSINIT_POSIX_THREADS) |
---|
356 | { |
---|
357 | assert(_POSIX_Threads_Information.Objects.maximum != 0); |
---|
358 | next_step(POSIX_THREADS_POST); |
---|
359 | } |
---|
360 | |
---|
361 | #endif /* RTEMS_POSIX_API */ |
---|
362 | |
---|
363 | FIRST(RTEMS_SYSINIT_IDLE_THREADS) |
---|
364 | { |
---|
365 | assert(_System_state_Is_before_initialization(_System_state_Get())); |
---|
366 | next_step(IDLE_THREADS_PRE); |
---|
367 | } |
---|
368 | |
---|
369 | LAST(RTEMS_SYSINIT_IDLE_THREADS) |
---|
370 | { |
---|
371 | assert(_System_state_Is_before_multitasking(_System_state_Get())); |
---|
372 | next_step(IDLE_THREADS_POST); |
---|
373 | } |
---|
374 | |
---|
375 | FIRST(RTEMS_SYSINIT_BSP_LIBC) |
---|
376 | { |
---|
377 | assert(rtems_libio_semaphore == 0); |
---|
378 | next_step(BSP_LIBC_PRE); |
---|
379 | } |
---|
380 | |
---|
381 | LAST(RTEMS_SYSINIT_BSP_LIBC) |
---|
382 | { |
---|
383 | assert(rtems_libio_semaphore != 0); |
---|
384 | next_step(BSP_LIBC_POST); |
---|
385 | } |
---|
386 | |
---|
387 | FIRST(RTEMS_SYSINIT_BEFORE_DRIVERS) |
---|
388 | { |
---|
389 | /* Omit test of build configuration specific pre and post conditions */ |
---|
390 | next_step(BEFORE_DRIVERS_PRE); |
---|
391 | } |
---|
392 | |
---|
393 | LAST(RTEMS_SYSINIT_BEFORE_DRIVERS) |
---|
394 | { |
---|
395 | next_step(BEFORE_DRIVERS_POST); |
---|
396 | } |
---|
397 | |
---|
398 | FIRST(RTEMS_SYSINIT_BSP_PRE_DRIVERS) |
---|
399 | { |
---|
400 | /* |
---|
401 | * Since the work performed here is BSP-specific, there is no way to test pre |
---|
402 | * and post conditions. |
---|
403 | */ |
---|
404 | next_step(BSP_PRE_DRIVERS_PRE); |
---|
405 | } |
---|
406 | |
---|
407 | LAST(RTEMS_SYSINIT_BSP_PRE_DRIVERS) |
---|
408 | { |
---|
409 | next_step(BSP_PRE_DRIVERS_POST); |
---|
410 | } |
---|
411 | |
---|
412 | FIRST(RTEMS_SYSINIT_DEVICE_DRIVERS) |
---|
413 | { |
---|
414 | assert(!_IO_All_drivers_initialized); |
---|
415 | next_step(DEVICE_DRIVERS_PRE); |
---|
416 | } |
---|
417 | |
---|
418 | LAST(RTEMS_SYSINIT_DEVICE_DRIVERS) |
---|
419 | { |
---|
420 | assert(_IO_All_drivers_initialized); |
---|
421 | next_step(DEVICE_DRIVERS_POST); |
---|
422 | } |
---|
423 | |
---|
424 | FIRST(RTEMS_SYSINIT_BSP_POST_DRIVERS) |
---|
425 | { |
---|
426 | assert(rtems_libio_iop_freelist != NULL); |
---|
427 | next_step(BSP_POST_DRIVERS_PRE); |
---|
428 | } |
---|
429 | |
---|
430 | LAST(RTEMS_SYSINIT_BSP_POST_DRIVERS) |
---|
431 | { |
---|
432 | assert(rtems_libio_iop_freelist == NULL); |
---|
433 | next_step(BSP_POST_DRIVERS_POST); |
---|
434 | } |
---|
435 | |
---|
436 | static void Init(rtems_task_argument arg) |
---|
437 | { |
---|
438 | next_step(INIT_TASK); |
---|
439 | rtems_test_endk(); |
---|
440 | exit(0); |
---|
441 | } |
---|
442 | |
---|
443 | #define CONFIGURE_APPLICATION_DOES_NOT_NEED_CLOCK_DRIVER |
---|
444 | #define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER |
---|
445 | |
---|
446 | #define CONFIGURE_MAXIMUM_USER_EXTENSIONS 1 |
---|
447 | |
---|
448 | #define CONFIGURE_MAXIMUM_BARRIERS 1 |
---|
449 | |
---|
450 | #define CONFIGURE_MAXIMUM_MESSAGE_QUEUES 1 |
---|
451 | |
---|
452 | #define CONFIGURE_MAXIMUM_PARTITIONS 1 |
---|
453 | |
---|
454 | #define CONFIGURE_MAXIMUM_PERIODS 1 |
---|
455 | |
---|
456 | #define CONFIGURE_MAXIMUM_PORTS 1 |
---|
457 | |
---|
458 | #define CONFIGURE_MAXIMUM_REGIONS 1 |
---|
459 | |
---|
460 | #define CONFIGURE_MAXIMUM_SEMAPHORES 1 |
---|
461 | |
---|
462 | #define CONFIGURE_MAXIMUM_TASKS 1 |
---|
463 | |
---|
464 | #define CONFIGURE_MAXIMUM_TIMERS 1 |
---|
465 | |
---|
466 | #ifdef RTEMS_POSIX_API |
---|
467 | |
---|
468 | #define CONFIGURE_MAXIMUM_POSIX_THREADS 1 |
---|
469 | |
---|
470 | #endif /* RTEMS_POSIX_API */ |
---|
471 | |
---|
472 | #define CONFIGURE_RTEMS_INIT_TASKS_TABLE |
---|
473 | |
---|
474 | #define CONFIGURE_STACK_CHECKER_ENABLED |
---|
475 | |
---|
476 | #define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION |
---|
477 | |
---|
478 | #define CONFIGURE_INIT |
---|
479 | |
---|
480 | #include <rtems/confdefs.h> |
---|