source: rtems/testsuites/psxtests/psxsignal01/init.c @ 147c5d5

4.104.11
Last change on this file since 147c5d5 was 147c5d5, checked in by Joel Sherrill <joel.sherrill@…>, on Jul 6, 2009 at 9:03:05 PM

2009-07-06 Joel Sherrill <joel.sherrill@…>

  • psxsignal01/init.c: Tune code to really hit POSIX signal from ISR code.
  • Property mode set to 100644
File size: 5.2 KB
Line 
1/*
2 *  COPYRIGHT (c) 1989-1999.
3 *  On-Line Applications Research Corporation (OAR).
4 *
5 *  The license and distribution terms for this file may be
6 *  found in the file LICENSE in this distribution or at
7 *  http://www.rtems.com/license/LICENSE.
8 *
9 *  $Id$
10 */
11
12#define CONFIGURE_INIT
13#include "system.h"
14#include <signal.h>
15#include <errno.h>
16typedef void (*sighandler_t)(int);
17sighandler_t signal(int signum, sighandler_t handler);
18extern void _POSIX_signals_Abnormal_termination_handler( int signo );
19
20volatile int Signal_occurred;
21volatile int Signal_count;
22
23void Handler_1(
24  int signo
25)
26{
27  Signal_count++;
28  printf(
29    "Handler_1: Signal: %d caught by 0x%x (%d)\n",
30    signo,
31    pthread_self(),
32    Signal_count
33  );
34  Signal_occurred = 1;
35}
36
37void Signal_handler(
38  int signo
39)
40{
41  Signal_count++;
42  printf(
43    "Signal: %d caught by 0x%x (%d)\n",
44    signo,
45    pthread_self(),
46    Signal_count
47  );
48  Signal_occurred = 1;
49}
50
51void Signal_info_handler(
52  int        signo,
53  siginfo_t *info,
54  void      *context
55)
56{
57  Signal_count++;
58  printf(
59    "Signal_info: %d caught by 0x%x (%d) si_signo= %d si_code= %d value= %d\n",
60    signo,
61    pthread_self(),
62    Signal_count,
63    info->si_signo,
64    info->si_code,
65    info->si_value.sival_int
66  );
67  Signal_occurred = 1;
68}
69
70rtems_timer_service_routine Signal_duringISR_TSR(
71  rtems_id  ignored_id,
72  void     *ignored_address
73)
74{
75  int  status;
76  status = pthread_kill( pthread_self(), SIGUSR1 );
77}
78
79
80void *POSIX_Init(
81  void *argument
82)
83{
84  int               status;
85  struct sigaction  act;
86  sigset_t          mask;
87  sigset_t          pending_set;
88  sigset_t          oset;
89  struct timespec   timeout;
90  siginfo_t         info;
91  sighandler_t      oldHandler;
92  sighandler_t      newHandler;
93  rtems_interval start, end;
94
95  puts( "\n\n*** POSIX TEST SIGNAL ***" );
96
97  /* set the time of day, and print our buffer in multiple ways */
98
99  set_time( TM_FRIDAY, TM_MAY, 24, 96, 11, 5, 0 );
100
101  /* get id of this thread */
102
103  Init_id = pthread_self();
104  printf( "Init's ID is 0x%08x\n", Init_id );
105
106  Signal_occurred = 0;
107  Signal_count = 0;
108  act.sa_handler = Handler_1;
109  act.sa_flags   = 0;
110  sigaction( SIGUSR1, &act, NULL );
111  sigaction( SIGFPE, &act, NULL );
112  sigaction( SIGILL, &act, NULL );
113  sigaction( SIGSEGV, &act, NULL );
114
115
116  /*
117   * If we have the signal pending with default, we will die.
118   */
119  puts("Validate signal with SIG_DFL");
120  signal( SIGUSR1, SIG_DFL );
121  status = kill( getpid(), SIGUSR1 );
122  status = sleep( 1 );
123
124  puts("Validate signal with SIG_IGN");
125  signal( SIGUSR1, SIG_IGN );
126  status = kill( getpid(), SIGUSR1 );
127  status = sleep( 1 );
128
129/* unblock Signal and see if it happened */
130  status = sigemptyset( &mask );
131  assert( !status );
132
133  status = sigaddset( &mask, SIGUSR1 );
134  assert( !status );
135
136  status = sigaddset( &mask, SIGFPE );
137  assert( !status );
138
139  status = sigaddset( &mask, SIGILL );
140  assert( !status );
141
142  status = sigaddset( &mask, SIGSEGV );
143  assert( !status );
144
145  puts( "Init: Unblock SIGUSR1 SIGFPE SIGILL SIGSEGV" );
146  status = sigprocmask( SIG_UNBLOCK, &mask, NULL );
147  assert( !status );
148
149/* install a signal handler for SIGUSR1 */
150  Signal_occurred = 0;
151  Signal_count = 0;
152  act.sa_handler = Handler_1;
153  act.sa_flags   = 0;
154  sigaction( SIGUSR1, &act, NULL );
155
156  Signal_count = 0;
157  Signal_occurred = 0;
158
159  newHandler = Signal_handler;
160  oldHandler = signal( SIGUSR1, newHandler );
161  if (oldHandler == Handler_1 )
162    puts("Init: signal return value verified");
163  else
164    puts("Init: ERROR==> signal unexpected return value" );
165  status = sleep( 1 );
166
167  puts( "Init: send SIGUSR1 to process" );
168  status = kill( getpid(), SIGUSR1 );
169  status = sleep( 5 );
170
171  puts( "Init: send SIGFPE to process" );
172  status = _kill_r( NULL, getpid(), SIGFPE );
173  status = sleep(5);
174
175  puts( "Init: send SIGILL to process" );
176  status = _kill_r( NULL, getpid(), SIGILL );
177  status = sleep(5);
178
179  puts( "Init: send SIGSEGV to process" );
180  status = _kill_r( NULL, getpid(), SIGSEGV );
181  status = sleep(5);
182
183  Timer_name[0]= rtems_build_name( 'T', 'M', '1', ' ' );
184  status = rtems_timer_create( Timer_name[0], &Timer_id[0]);
185
186  Signal_count = 0;
187  Signal_occurred = 0;
188  puts( "Init: send SIGUSR1 to process from a TSR (interruptible sleep)" );
189  status = rtems_timer_fire_after(
190    Timer_id[ 0 ],
191    1,
192    Signal_duringISR_TSR,
193    NULL 
194  );
195  sleep(5);
196  /* signal occurs during interruptible sleep */
197
198  /* now schedule another one to fire but do not sleep */
199
200  puts( "Init: send SIGUSR1 to process from a TSR (spin)" );
201  rtems_clock_get( RTEMS_CLOCK_GET_TICKS_SINCE_BOOT, &start );
202  Signal_count = 0;
203  Signal_occurred = 0;
204  status = rtems_timer_fire_after(
205    Timer_id[ 0 ],
206    10,
207    Signal_duringISR_TSR,
208    NULL 
209  );
210  do {
211    rtems_clock_get( RTEMS_CLOCK_GET_TICKS_SINCE_BOOT, &end );
212  } while ( !Signal_occurred && ((end - start) <= 800));
213
214  if ( !Signal_occurred ) {
215    puts( "Signal did not occur" );
216    rtems_test_exit(0);
217  }
218
219/* end of install a signal handler for SIGUSR1 */
220
221  Signal_occurred = 0;
222 
223  puts("*** Validate unexpected program termination ***");
224  puts( "*** END OF POSIX TEST SIGNAL ***" );
225  _POSIX_signals_Abnormal_termination_handler( SIGUSR1 );
226  status = sleep( 1 );
227
228  puts( "ERROR==> Expected program termination");
229  rtems_test_exit(0);
230  return NULL; /* just so the compiler thinks we returned something */
231}
Note: See TracBrowser for help on using the repository browser.