source: rtems/c/src/tests/psxtests/psx03/init.c @ f88310da

4.104.114.84.95
Last change on this file since f88310da was f88310da, checked in by Joel Sherrill <joel.sherrill@…>, on 06/15/96 at 19:56:19

initial modifications to test sigtimedwait.

  • Property mode set to 100644
File size: 5.1 KB
Line 
1/*
2 *  COPYRIGHT (c) 1989, 1990, 1991, 1992, 1993, 1994.
3 *  On-Line Applications Research Corporation (OAR).
4 *  All rights assigned to U.S. Government, 1994.
5 *
6 *  This material may be reproduced by or for the U.S. Government pursuant
7 *  to the copyright license under the clause at DFARS 252.227-7013.  This
8 *  notice must appear in all copies of this file and its derivatives.
9 *
10 *  $Id$
11 */
12
13#define CONFIGURE_INIT
14#include "system.h"
15#include <signal.h>
16#include <errno.h>
17
18volatile int Signal_occurred;
19volatile int Signal_count;
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, mask 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( &mask, &siginfo, &timeout );
164  printf( "Init: correctly received SIGUSR1 - %d\n", siginfo.si_signo );
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
171/*
172  status = sigemptyset( &mask );
173  assert( !status );
174
175  status = sigaddset( &mask, SIGUSR1 );
176  assert( !status );
177
178  printf( "Init: Block SIGUSR1\n" );
179  status = sigprocmask( SIG_BLOCK, &mask, NULL );
180  assert( !status );
181
182  status = sigpending( &pending_set );
183  assert( !status );
184  printf( "Init: Signals pending 0x%08x\n", pending_set );
185 
186  printf( "Init: send SIGUSR1 to self\n" );
187  status = pthread_kill( Init_id, SIGUSR1 );
188  assert( !status );
189
190  status = sigpending( &pending_set );
191  assert( !status );
192  printf( "Init: Signals pending 0x%08x\n", pending_set );
193 
194  printf( "Init: Unblock SIGUSR1\n" );
195  status = sigprocmask( SIG_UNBLOCK, &mask, NULL );
196  assert( !status );
197
198*/
199
200  /*
201   *  Loop for 5 seconds seeing how many signals we catch
202   */
203
204/*
205  tr.tv_sec = 5;
206  tr.tv_nsec = 0;
207 
208  do {
209    tv = tr;
210
211    Signal_occurred = 0;
212
213    status = nanosleep ( &tv, &tr );
214    assert( !status );
215
216    printf(
217      "Init: signal was %sprocessed with %d:%d time remaining\n",
218      (Signal_occurred) ? "" : "not ",
219      (int) tr.tv_sec,
220      (int) tr.tv_nsec
221   );
222
223  } while ( tr.tv_sec || tr.tv_nsec );
224
225*/
226
227  /* exit this thread */
228
229  puts( "*** END OF POSIX TEST 3 ***" );
230  exit( 0 );
231
232  return NULL; /* just so the compiler thinks we returned something */
233}
Note: See TracBrowser for help on using the repository browser.