source: rtems/testsuites/psxtests/psx03/init.c @ 2e7e636f

4.104.11
Last change on this file since 2e7e636f was 2e7e636f, checked in by Joel Sherrill <joel.sherrill@…>, on May 11, 2009 at 1:41:16 AM

2009-05-10 Joel Sherrill <joel.sherrill@…>

  • psx01/init.c, psx01/task.c, psx02/init.c, psx02/task.c, psx03/init.c, psx04/init.c, psx04/task1.c, psx04/task3.c, psx05/init.c, psx06/init.c, psx07/init.c, psx08/init.c, psx09/init.c, psx11/task.c, psx12/init.c, psx13/main.c, psx13/test.c, psxbarrier01/test.c, psxcancel/init.c, psxcleanup/psxcleanup.c, psxenosys/init.c, psxmsgq02/init.c, psxtime/main.c, psxtime/test.c, psxtimer01/psxtimer.c, psxtimer02/psxtimer.c: Fix warnings.
  • Property mode set to 100644
File size: 4.7 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>
16
17volatile int Signal_occurred;
18volatile int Signal_count;
19void Signal_handler( int signo );
20
21void Signal_handler(
22  int signo
23)
24{
25  Signal_count++;
26  printf(
27    "Signal: %d caught by 0x%x (%d)\n",
28    signo,
29    pthread_self(),
30    Signal_count
31  );
32  Signal_occurred = 1;
33}
34
35void *POSIX_Init(
36  void *argument
37)
38{
39  int               status;
40  struct timespec   timeout;
41  struct sigaction  act;
42  sigset_t          mask;
43  sigset_t          waitset;
44  int               signo;
45  siginfo_t         siginfo;
46
47  puts( "\n\n*** POSIX TEST 3 ***" );
48
49  /* set the time of day, and print our buffer in multiple ways */
50
51  set_time( TM_FRIDAY, TM_MAY, 24, 96, 11, 5, 0 );
52
53  /* get id of this thread */
54
55  Init_id = pthread_self();
56  printf( "Init's ID is 0x%08x\n", Init_id );
57
58  /* install a signal handler */
59
60  status = sigemptyset( &act.sa_mask );
61  assert( !status );
62
63  act.sa_handler = Signal_handler;
64  act.sa_flags   = 0;
65
66  sigaction( SIGUSR1, &act, NULL );
67
68  /* initialize signal handler variables */
69
70  Signal_count = 0;
71  Signal_occurred = 0;
72
73  /*
74   *  wait on SIGUSR1 for 3 seconds, will timeout
75   */
76
77  /* initialize the signal set we will wait for to SIGUSR1 */
78
79  status = sigemptyset( &waitset );
80  assert( !status );
81
82  status = sigaddset( &waitset, SIGUSR1 );
83  assert( !status );
84
85  timeout.tv_sec = 3;
86  timeout.tv_nsec = 0;
87
88  puts( "Init: waiting on any signal for 3 seconds." );
89  signo = sigtimedwait( &waitset, &siginfo, &timeout );
90  assert( signo == -1 );
91
92  if ( errno == EAGAIN )
93    puts( "Init: correctly timed out waiting for SIGUSR1." );
94  else
95    printf( "sigtimedwait returned wrong errno - %d\n", errno );
96
97  Signal_occurred = 0;
98
99  /*
100   *  wait on SIGUSR1 for 3 seconds, will timeout because Task_1 sends SIGUSR2
101   */
102
103  empty_line();
104
105  /* initialize a mask to block SIGUSR2 */
106
107  status = sigemptyset( &mask );
108  assert( !status );
109
110  status = sigaddset( &mask, SIGUSR2 );
111  assert( !status );
112
113  printf( "Init: Block SIGUSR2\n" );
114  status = sigprocmask( SIG_BLOCK, &mask, NULL );
115  assert( !status );
116
117  /* create a thread */
118
119  status = pthread_create( &Task_id, NULL, Task_1, NULL );
120  assert( !status );
121
122  /* signal handler is still installed, waitset is still set for SIGUSR1 */
123
124  timeout.tv_sec = 3;
125  timeout.tv_nsec = 0;
126
127  puts( "Init: waiting on any signal for 3 seconds." );
128  signo = sigtimedwait( &waitset, &siginfo, &timeout );
129
130     /* switch to Task 1 */
131
132  if ( errno == EAGAIN )
133    puts( "Init: correctly timed out waiting for SIGUSR1." );
134  else
135    printf( "sigtimedwait returned wrong errno - %d\n", errno );
136  assert( signo == -1 );
137
138  /*
139   *  wait on SIGUSR1 for 3 seconds, Task_2 will send it to us
140   */
141
142  empty_line();
143
144  /* create a thread */
145
146  status = pthread_create( &Task_id, NULL, Task_2, NULL );
147  assert( !status );
148
149  /* signal handler is still installed, waitset is still set for SIGUSR1 */
150
151  /* wait on SIGUSR1 for 3 seconds, will receive SIGUSR1 from Task_2 */
152
153  timeout.tv_sec = 3;
154  timeout.tv_nsec = 0;
155
156  /* just so we can check that these were altered */
157
158  siginfo.si_code = -1;
159  siginfo.si_signo = -1;
160  siginfo.si_value.sival_int = -1;
161
162  puts( "Init: waiting on any signal for 3 seconds." );
163  signo = sigtimedwait( &waitset, &siginfo, &timeout );
164  printf( "Init: received (%d) SIGUSR1=%d\n", siginfo.si_signo, SIGUSR1 );
165  assert( signo == SIGUSR1 );
166  assert( siginfo.si_signo == SIGUSR1 );
167  assert( siginfo.si_code == SI_USER );
168  assert( siginfo.si_value.sival_int != -1 );   /* rtems does always set this */
169
170  /* try out a process signal */
171
172  empty_line();
173  puts( "Init: kill with SIGUSR2." );
174  status = kill( getpid(), SIGUSR2 );
175  assert( !status );
176
177  siginfo.si_code = -1;
178  siginfo.si_signo = -1;
179  siginfo.si_value.sival_int = -1;
180
181  status = sigemptyset( &waitset );
182  assert( !status );
183
184  status = sigaddset( &waitset, SIGUSR1 );
185  assert( !status );
186
187  status = sigaddset( &waitset, SIGUSR2 );
188  assert( !status );
189
190  puts( "Init: waiting on any signal for 3 seconds." );
191  signo = sigtimedwait( &waitset, &siginfo, &timeout );
192  printf( "Init: received (%d) SIGUSR2=%d\n", siginfo.si_signo, SIGUSR2 );
193  assert( signo == SIGUSR2 );
194  assert( siginfo.si_signo == SIGUSR2 );
195  assert( siginfo.si_code == SI_USER );
196  assert( siginfo.si_value.sival_int != -1 );   /* rtems does always set this */
197
198  /* exit this thread */
199
200  puts( "*** END OF POSIX TEST 3 ***" );
201  rtems_test_exit( 0 );
202
203  return NULL; /* just so the compiler thinks we returned something */
204}
Note: See TracBrowser for help on using the repository browser.