1 | /* Fatal Error Test |
---|
2 | * |
---|
3 | * NOTE: |
---|
4 | * |
---|
5 | * This test actually modifies the Configuration table and restarts |
---|
6 | * the executive. It is very carefully constructed to do this and |
---|
7 | * uses the Configuration very carefully. |
---|
8 | * |
---|
9 | * COPYRIGHT (c) 1989-1998. |
---|
10 | * On-Line Applications Research Corporation (OAR). |
---|
11 | * Copyright assigned to U.S. Government, 1994. |
---|
12 | * |
---|
13 | * The license and distribution terms for this file may be |
---|
14 | * found in the file LICENSE in this distribution or at |
---|
15 | * http://www.OARcorp.com/rtems/license.html. |
---|
16 | * |
---|
17 | * $Id$ |
---|
18 | */ |
---|
19 | |
---|
20 | #include "system.h" |
---|
21 | |
---|
22 | #include <setjmp.h> |
---|
23 | |
---|
24 | char Workspace[ 64 * 1024 ] CPU_STRUCTURE_ALIGNMENT; |
---|
25 | |
---|
26 | typedef enum { |
---|
27 | FATAL_WORKSPACE_OF_ZERO, |
---|
28 | FATAL_NULL_WORKSPACE, |
---|
29 | FATAL_WORKSPACE_TOO_SMALL, |
---|
30 | FATAL_TASK_CREATE, |
---|
31 | FATAL_TASK_START |
---|
32 | } Fatal_errors_t; |
---|
33 | |
---|
34 | #define FATAL_LAST FATAL_TASK_START |
---|
35 | |
---|
36 | volatile Fatal_errors_t Case_in_switch; |
---|
37 | |
---|
38 | rtems_status_code Expected_Errors[] = { |
---|
39 | RTEMS_UNSATISFIED, |
---|
40 | RTEMS_INVALID_ADDRESS, |
---|
41 | RTEMS_UNSATISFIED, |
---|
42 | RTEMS_INVALID_PRIORITY, |
---|
43 | RTEMS_TASK_EXITTED |
---|
44 | }; |
---|
45 | |
---|
46 | rtems_status_code Error_Happened[ FATAL_LAST + 1]; |
---|
47 | |
---|
48 | jmp_buf Restart_Context; |
---|
49 | |
---|
50 | /* |
---|
51 | * We depend on this being zeroed during initialization. This |
---|
52 | * occurs automatically because this is part of the BSS. |
---|
53 | */ |
---|
54 | |
---|
55 | rtems_unsigned32 First_Time_Through; |
---|
56 | |
---|
57 | void Process_case(); |
---|
58 | |
---|
59 | rtems_extension Fatal_extension( |
---|
60 | rtems_unsigned32 source, |
---|
61 | boolean is_internal, |
---|
62 | rtems_unsigned32 error |
---|
63 | ) |
---|
64 | { |
---|
65 | int index; |
---|
66 | |
---|
67 | Error_Happened[ Case_in_switch ] = error; |
---|
68 | |
---|
69 | if ( First_Time_Through == 0 ) { |
---|
70 | Case_in_switch = FATAL_WORKSPACE_OF_ZERO; |
---|
71 | First_Time_Through = 1; |
---|
72 | setjmp( Restart_Context ); |
---|
73 | } else if ( Case_in_switch == FATAL_LAST ) { |
---|
74 | |
---|
75 | /* |
---|
76 | * Depending on the C library we use, we cannot get the |
---|
77 | * task exitted error so do not check for it. |
---|
78 | */ |
---|
79 | |
---|
80 | puts( "*** TEST FATAL ***" ); |
---|
81 | for ( index=0 ; index< FATAL_LAST ; index++ ) |
---|
82 | put_error( Error_Happened[ index ], Expected_Errors[ index ] ); |
---|
83 | puts( "NOT TESTING FATAL ERROR WHEN TASK EXITS -- C LIBRARY CATCHES THIS" ); |
---|
84 | puts( "*** END OF TEST FATAL ***" ); |
---|
85 | |
---|
86 | /* |
---|
87 | * returns to the default fatal error handler instead of |
---|
88 | * calling rtems_shutdown_executive |
---|
89 | */ |
---|
90 | return; |
---|
91 | |
---|
92 | } else { |
---|
93 | |
---|
94 | longjmp( Restart_Context, 1 ); |
---|
95 | } |
---|
96 | |
---|
97 | Process_case(); |
---|
98 | } |
---|
99 | |
---|
100 | |
---|
101 | |
---|
102 | void Process_case() |
---|
103 | { |
---|
104 | switch ( Case_in_switch ) { |
---|
105 | case FATAL_WORKSPACE_OF_ZERO: |
---|
106 | New_Configuration = rtems_configuration_get_table(); |
---|
107 | New_Configuration.work_space_start = NULL; |
---|
108 | Case_in_switch = FATAL_NULL_WORKSPACE; |
---|
109 | break; |
---|
110 | |
---|
111 | case FATAL_NULL_WORKSPACE: |
---|
112 | New_Configuration.work_space_start = Workspace; |
---|
113 | New_Configuration.work_space_size = 256; |
---|
114 | Case_in_switch = FATAL_WORKSPACE_TOO_SMALL; |
---|
115 | break; |
---|
116 | |
---|
117 | case FATAL_WORKSPACE_TOO_SMALL: |
---|
118 | Initialization_tasks[ 0 ].initial_priority = RTEMS_CURRENT_PRIORITY; |
---|
119 | New_Configuration.work_space_size = sizeof( Workspace ); |
---|
120 | Case_in_switch = FATAL_TASK_CREATE; |
---|
121 | break; |
---|
122 | |
---|
123 | case FATAL_TASK_CREATE: |
---|
124 | Initialization_tasks[ 0 ].initial_priority = 1; |
---|
125 | Initialization_tasks[ 0 ].entry_point = NULL; |
---|
126 | Case_in_switch = FATAL_TASK_START; |
---|
127 | break; |
---|
128 | |
---|
129 | case FATAL_TASK_START: |
---|
130 | /* this extension exits the test */ |
---|
131 | Initialization_tasks[ 0 ].entry_point = Init; |
---|
132 | break; |
---|
133 | } |
---|
134 | rtems_initialize_executive( |
---|
135 | &New_Configuration, rtems_cpu_configuration_get_table() ); |
---|
136 | } |
---|
137 | |
---|