source: rtems/testsuites/psxtests/psxsignal01/init.c @ 2317457

4.104.115
Last change on this file since 2317457 was 2317457, checked in by Joel Sherrill <joel.sherrill@…>, on 12/08/09 at 17:52:53

2009-12-08 Joel Sherrill <joel.sherrill@…>

  • include/pmacros.h, psx01/task.c, psx02/init.c, psx02/task.c, psx03/init.c, psx03/task.c, psx04/init.c, psx04/task1.c, psx04/task2.c, psx04/task3.c, psx05/init.c, psx05/task.c, psx05/task2.c, psx05/task3.c, psx06/init.c, psx06/task.c, psx06/task2.c, psx07/init.c, psx08/init.c, psx08/task2.c, psx08/task3.c, psx09/init.c, psx10/init.c, psx10/task.c, psx10/task2.c, psx10/task3.c, psx11/init.c, psx11/task.c, psx12/init.c, psxalarm01/init.c, psxbarrier01/test.c, psxcancel01/init.c, psxchroot01/test.c, psxclock/init.c, psxfile01/test.c, psxfile01/test_cat.c, psxfile01/test_extend.c, psxfile01/test_write.c, psxitimer/init.c, psxkey01/task.c, psxkey02/init.c, psxkey03/init.c, psxmount/test.c, psxmsgq01/init.c, psxmsgq03/init.c, psxmsgq04/init.c, psxreaddir/test.c, psxrwlock01/test.c, psxsem01/init.c, psxsignal01/init.c, psxsignal01/task1.c, psxsignal02/init.c, psxsignal03/init.c, psxsignal05/init.c, psxspin01/test.c, psxspin02/test.c, psxstack01/init.c, psxstat/test.c, psxtime/test.c, psxualarm/init.c: Use rtems_test_assert() consistently instead of system assert(). rtems_test_assert() is designed to integrate into the RTEMS test suite infrastructure.
  • Property mode set to 100644
File size: 5.2 KB
Line 
1/*
2 *  COPYRIGHT (c) 1989-2009.
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%" PRIxpthread_t " (%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%"PRIxpthread_t " (%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%" PRIxpthread_t " (%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  sighandler_t      oldHandler;
88  sighandler_t      newHandler;
89  rtems_interval start, end;
90
91  puts( "\n\n*** POSIX TEST SIGNAL ***" );
92
93  /* set the time of day, and print our buffer in multiple ways */
94
95  set_time( TM_FRIDAY, TM_MAY, 24, 96, 11, 5, 0 );
96
97  /* get id of this thread */
98
99  Init_id = pthread_self();
100  printf( "Init's ID is 0x%08" PRIxpthread_t "\n", Init_id );
101
102  Signal_occurred = 0;
103  Signal_count = 0;
104  act.sa_handler = Handler_1;
105  act.sa_flags   = 0;
106  sigaction( SIGUSR1, &act, NULL );
107  sigaction( SIGFPE, &act, NULL );
108  sigaction( SIGILL, &act, NULL );
109  sigaction( SIGSEGV, &act, NULL );
110
111
112  /*
113   * If we have the signal pending with default, we will die.
114   */
115  puts("Validate signal with SIG_DFL");
116  signal( SIGUSR1, SIG_DFL );
117  status = kill( getpid(), SIGUSR1 );
118  status = sleep( 1 );
119
120  puts("Validate signal with SIG_IGN");
121  signal( SIGUSR1, SIG_IGN );
122  status = kill( getpid(), SIGUSR1 );
123  status = sleep( 1 );
124
125/* unblock Signal and see if it happened */
126  status = sigemptyset( &mask );
127  rtems_test_assert(  !status );
128
129  status = sigaddset( &mask, SIGUSR1 );
130  rtems_test_assert(  !status );
131
132  status = sigaddset( &mask, SIGFPE );
133  rtems_test_assert(  !status );
134
135  status = sigaddset( &mask, SIGILL );
136  rtems_test_assert(  !status );
137
138  status = sigaddset( &mask, SIGSEGV );
139  rtems_test_assert(  !status );
140
141  puts( "Init: Unblock SIGUSR1 SIGFPE SIGILL SIGSEGV" );
142  status = sigprocmask( SIG_UNBLOCK, &mask, NULL );
143  rtems_test_assert(  !status );
144
145/* install a signal handler for SIGUSR1 */
146  Signal_occurred = 0;
147  Signal_count = 0;
148  act.sa_handler = Handler_1;
149  act.sa_flags   = 0;
150  sigaction( SIGUSR1, &act, NULL );
151
152  Signal_count = 0;
153  Signal_occurred = 0;
154
155  newHandler = Signal_handler;
156  oldHandler = signal( SIGUSR1, newHandler );
157  if (oldHandler == Handler_1 )
158    puts("Init: signal return value verified");
159  else
160    puts("Init: ERROR==> signal unexpected return value" );
161  status = sleep( 1 );
162
163  puts( "Init: send SIGUSR1 to process" );
164  status = kill( getpid(), SIGUSR1 );
165  status = sleep( 5 );
166
167  puts( "Init: send SIGFPE to process" );
168  status = _kill_r( NULL, getpid(), SIGFPE );
169  status = sleep(5);
170
171  puts( "Init: send SIGILL to process" );
172  status = _kill_r( NULL, getpid(), SIGILL );
173  status = sleep(5);
174
175  puts( "Init: send SIGSEGV to process" );
176  status = _kill_r( NULL, getpid(), SIGSEGV );
177  status = sleep(5);
178
179  Timer_name[0]= rtems_build_name( 'T', 'M', '1', ' ' );
180  status = rtems_timer_create( Timer_name[0], &Timer_id[0]);
181
182  Signal_count = 0;
183  Signal_occurred = 0;
184  puts( "Init: send SIGUSR1 to process from a TSR (interruptible sleep)" );
185  status = rtems_timer_fire_after(
186    Timer_id[ 0 ],
187    1,
188    Signal_duringISR_TSR,
189    NULL
190  );
191  sleep(5);
192  /* signal occurs during interruptible sleep */
193
194  /* now schedule another one to fire but do not sleep */
195
196  puts( "Init: send SIGUSR1 to process from a TSR (spin)" );
197  start = rtems_clock_get_ticks_since_boot();
198  Signal_count = 0;
199  Signal_occurred = 0;
200  status = rtems_timer_fire_after(
201    Timer_id[ 0 ],
202    10,
203    Signal_duringISR_TSR,
204    NULL
205  );
206  do {
207    end = rtems_clock_get_ticks_since_boot();
208  } while ( !Signal_occurred && ((end - start) <= 800));
209
210  if ( !Signal_occurred ) {
211    puts( "Signal did not occur" );
212    rtems_test_exit(0);
213  }
214
215/* end of install a signal handler for SIGUSR1 */
216
217  Signal_occurred = 0;
218
219  puts("*** Validate unexpected program termination ***");
220  puts( "*** END OF POSIX TEST SIGNAL ***" );
221  _POSIX_signals_Abnormal_termination_handler( SIGUSR1 );
222  status = sleep( 1 );
223
224  puts( "ERROR==> Expected program termination");
225  rtems_test_exit(0);
226  return NULL; /* just so the compiler thinks we returned something */
227}
Note: See TracBrowser for help on using the repository browser.