source: rtems/testsuites/sptests/spfatal/fatal.c @ ac7d5ef0

4.104.114.84.95
Last change on this file since ac7d5ef0 was ac7d5ef0, checked in by Joel Sherrill <joel.sherrill@…>, on May 11, 1995 at 5:39:37 PM

Initial revision

  • Property mode set to 100644
File size: 3.3 KB
Line 
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, 1990, 1991, 1992, 1993, 1994.
10 *  On-Line Applications Research Corporation (OAR).
11 *  All rights assigned to U.S. Government, 1994.
12 *
13 *  This material may be reproduced by or for the U.S. Government pursuant
14 *  to the copyright license under the clause at DFARS 252.227-7013.  This
15 *  notice must appear in all copies of this file and its derivatives.
16 *
17 *  $Id$
18 */
19
20#include "system.h"
21
22#include <setjmp.h>
23
24char Workspace[ 64 * 1024 ] CPU_STRUCTURE_ALIGNMENT;
25
26typedef 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
36volatile Fatal_errors_t Case_in_switch;
37
38rtems_status_code Expected_Errors[] = {
39  RTEMS_UNSATISFIED,
40  RTEMS_INVALID_ADDRESS,
41  RTEMS_UNSATISFIED,
42  RTEMS_INVALID_PRIORITY,
43  RTEMS_TASK_EXITTED
44};
45
46rtems_status_code Error_Happened[ FATAL_LAST + 1];
47
48jmp_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
55rtems_unsigned32  First_Time_Through;
56
57void Process_case();
58
59rtems_extension Fatal_extension(
60  rtems_unsigned32 error
61)
62{
63  int index;
64
65  Error_Happened[ Case_in_switch ] = error;
66
67  if ( First_Time_Through == 0 ) {
68    Case_in_switch = FATAL_WORKSPACE_OF_ZERO;
69    First_Time_Through = 1;
70    setjmp( Restart_Context );
71  } else if ( Case_in_switch == FATAL_LAST ) {
72
73    /*
74     *  Depending on the C library we use, we cannot get the
75     *  task exitted error so do not check for it.
76     */
77
78    puts( "*** TEST FATAL ***" );
79    for ( index=0 ; index< FATAL_LAST ; index++ )
80      put_error( Error_Happened[ index ], Expected_Errors[ index ] );
81    puts( "NOT TESTING FATAL ERROR WHEN TASK EXITS -- C LIBRARY CATCHES THIS" );
82    puts( "*** END OF TEST FATAL ***" );
83
84    /*
85     *  returns to the default fatal error handler instead of
86     *  calling rtems_shutdown_executive
87     */
88    return;
89
90  } else {
91
92    longjmp( Restart_Context, 1 );
93  }
94
95  Process_case();
96}
97
98
99
100void Process_case()
101{
102  switch ( Case_in_switch ) {
103    case FATAL_WORKSPACE_OF_ZERO:
104      New_Configuration = BSP_Configuration;
105      New_Configuration.work_space_start = NULL;
106      Case_in_switch = FATAL_NULL_WORKSPACE;
107      break;
108
109    case FATAL_NULL_WORKSPACE:
110      New_Configuration.work_space_start = Workspace;
111      New_Configuration.work_space_size  = 256;
112      Case_in_switch = FATAL_WORKSPACE_TOO_SMALL;
113      break;
114
115    case FATAL_WORKSPACE_TOO_SMALL:
116      Initialization_tasks[ 0 ].initial_priority = RTEMS_CURRENT_PRIORITY;
117      New_Configuration.work_space_size = sizeof( Workspace );
118      Case_in_switch = FATAL_TASK_CREATE;
119      break;
120
121    case FATAL_TASK_CREATE:
122      Initialization_tasks[ 0 ].initial_priority = 1;
123      Initialization_tasks[ 0 ].entry_point      = NULL;
124      Case_in_switch = FATAL_TASK_START;
125      break;
126
127    case FATAL_TASK_START:
128      /* this extension exits the test */
129      Initialization_tasks[ 0 ].entry_point = Init;
130      break;
131  }
132  rtems_initialize_executive( &New_Configuration, &Cpu_table );
133}
134
Note: See TracBrowser for help on using the repository browser.