source: rtems/testsuites/psxtests/psx04/init.c @ ce0f7d95

4.104.114.84.95
Last change on this file since ce0f7d95 was ce0f7d95, checked in by Joel Sherrill <joel.sherrill@…>, on 06/13/96 at 16:44:46

Added more test cases for kill() and alarm(). kill() now can unblock a
thread which has the signal unblocked.

  • Property mode set to 100644
File size: 4.3 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
17volatile int Signal_occurred;
18volatile int Signal_count;
19
20void Signal_handler(
21  int signo
22)
23{
24  Signal_count++;
25  printf(
26    "Signal: %d caught by 0x%x (%d)\n",
27    signo,
28    pthread_self(),
29    Signal_count
30  );
31  Signal_occurred = 1;
32}
33
34void *POSIX_Init(
35  void *argument
36)
37{
38  int               status;
39  struct sigaction  act;
40  sigset_t          mask;
41  sigset_t          pending_set;
42
43  puts( "\n\n*** POSIX TEST 4 ***" );
44
45  /* set the time of day, and print our buffer in multiple ways */
46
47  set_time( TM_FRIDAY, TM_MAY, 24, 96, 11, 5, 0 );
48
49  /* get id of this thread */
50
51  Init_id = pthread_self();
52  printf( "Init's ID is 0x%08x\n", Init_id );
53
54  /* install a signal handler for SIGUSR1 */
55
56  status = sigemptyset( &act.sa_mask );
57  assert( !status );
58
59  act.sa_handler = Signal_handler;
60  act.sa_flags   = 0;
61 
62  sigaction( SIGUSR1, &act, NULL );
63
64  /* simple signal to process */
65
66  Signal_count = 0;
67  Signal_occurred = 0;
68
69  printf( "Init: send SIGUSR1 to process\n" );
70  status = kill( getpid(), SIGUSR1 );
71  assert( !status );
72
73  Signal_occurred = 0;
74
75  /* now block the signal, send it, see if it is pending, and unblock it */
76
77  empty_line();
78
79  status = sigemptyset( &mask );
80  assert( !status );
81
82  status = sigaddset( &mask, SIGUSR1 );
83  assert( !status );
84
85  printf( "Init: Block SIGUSR1\n" );
86  status = sigprocmask( SIG_BLOCK, &mask, NULL );
87  assert( !status );
88
89  status = sigpending( &pending_set );
90  assert( !status );
91  printf( "Init: Signals pending 0x%08x\n", pending_set );
92 
93  printf( "Init: send SIGUSR1 to process\n" );
94  status = kill( getpid(), SIGUSR1 );
95  assert( !status );
96
97  status = sigpending( &pending_set );
98  assert( !status );
99  printf( "Init: Signals pending 0x%08x\n", pending_set );
100 
101  printf( "Init: Unblock SIGUSR1\n" );
102  status = sigprocmask( SIG_UNBLOCK, &mask, NULL );
103  assert( !status );
104
105  /* now let another task get interrupted by a signal */
106
107  empty_line();
108
109  printf( "Init: create a thread interested in SIGUSR1\n" );
110  status = pthread_create( &Task_id, NULL, Task_1_through_3, NULL );
111  assert( !status );
112
113  printf( "Init: Block SIGUSR1\n" );
114  status = sigprocmask( SIG_BLOCK, &mask, NULL );
115  assert( !status );
116 
117  status = sigpending( &pending_set );
118  assert( !status );
119  printf( "Init: Signals pending 0x%08x\n", pending_set );
120
121  printf( "Init: sleep so the other task can block\n" );
122  status = sleep( 1 );
123  assert( !status );
124
125     /* switch to task 1 */
126
127  printf( "Init: send SIGUSR1 to process\n" );
128  status = kill( getpid(), SIGUSR1 );
129  assert( !status );
130 
131  status = sigpending( &pending_set );
132  assert( !status );
133  printf( "Init: Signals pending 0x%08x\n", pending_set );
134
135  printf( "Init: sleep so the other task can catch signal\n" );
136  status = sleep( 1 );
137  assert( !status );
138
139     /* switch to task 1 */
140
141  /* test alarm */
142
143  empty_line();
144
145  /* install a signal handler for SIGALRM and unblock it */
146 
147  status = sigemptyset( &act.sa_mask );
148  assert( !status );
149 
150  act.sa_handler = Signal_handler;
151  act.sa_flags   = 0;
152 
153  sigaction( SIGALRM, &act, NULL );
154 
155  status = sigemptyset( &mask );
156  assert( !status );
157 
158  status = sigaddset( &mask, SIGALRM );
159  assert( !status );
160 
161  printf( "Init: Unblock SIGALRM\n" );
162  status = sigprocmask( SIG_UNBLOCK, &mask, NULL );
163  assert( !status );
164
165  /* schedule the alarm */
166 
167  printf( "Init: Firing alarm in 5 seconds\n" );
168  status = alarm( 5 );
169  printf( "Init: %d seconds left on previous alarm\n", status );
170  assert( !status );
171
172  printf( "Init: Firing alarm in 2 seconds\n" );
173  status = alarm( 2 );
174  printf( "Init: %d seconds left on previous alarm\n", status );
175  assert( status );
176
177  printf( "Init: Wait 4 seconds for alarm\n" );
178  status = sleep( 4 );
179  printf( "Init: %d seconds left in sleep\n", status );
180  assert( status );
181
182  /* exit this thread */
183
184  puts( "*** END OF POSIX TEST 4 ***" );
185  exit( 0 );
186
187  return NULL; /* just so the compiler thinks we returned something */
188}
Note: See TracBrowser for help on using the repository browser.