source: rtems/testsuites/psxtests/psx03/init.c @ 08311cc3

4.104.114.84.95
Last change on this file since 08311cc3 was 08311cc3, checked in by Joel Sherrill <joel.sherrill@…>, on 11/17/99 at 17:51:34

Updated copyright notice.

  • Property mode set to 100644
File size: 3.9 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.OARcorp.com/rtems/license.html.
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;
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 timespec   timeout;
40  struct sigaction  act;
41  sigset_t          mask;
42  sigset_t          waitset;
43  int               signo;
44  siginfo_t         siginfo;
45
46  puts( "\n\n*** POSIX TEST 3 ***" );
47
48  /* set the time of day, and print our buffer in multiple ways */
49
50  set_time( TM_FRIDAY, TM_MAY, 24, 96, 11, 5, 0 );
51
52  /* get id of this thread */
53
54  Init_id = pthread_self();
55  printf( "Init's ID is 0x%08x\n", Init_id );
56
57  /* install a signal handler */
58
59  status = sigemptyset( &act.sa_mask );
60  assert( !status );
61
62  act.sa_handler = Signal_handler;
63  act.sa_flags   = 0;
64 
65  sigaction( SIGUSR1, &act, NULL );
66
67  /* initialize signal handler variables */
68
69  Signal_count = 0;
70  Signal_occurred = 0;
71
72  /*
73   *  wait on SIGUSR1 for 3 seconds, will timeout
74   */
75
76  /* initialize the signal set we will wait for to SIGUSR1 */
77
78  status = sigemptyset( &waitset );
79  assert( !status );
80
81  status = sigaddset( &waitset, SIGUSR1 );
82  assert( !status );
83
84  timeout.tv_sec = 3;
85  timeout.tv_nsec = 0;
86
87  puts( "Init: waiting on any signal for 3 seconds." );
88  signo = sigtimedwait( &waitset, &siginfo, &timeout );
89  assert( signo == -1 );
90
91  if ( errno == EAGAIN )
92    puts( "Init: correctly timed out waiting for SIGUSR1." );
93  else
94    printf( "sigtimedwait returned wrong errno - %d\n", errno );
95
96  Signal_occurred = 0;
97
98  /*
99   *  wait on SIGUSR1 for 3 seconds, will timeout because Task_1 sends SIGUSR2
100   */
101
102  empty_line();
103
104  /* initialize a mask to block SIGUSR2 */
105
106  status = sigemptyset( &mask );
107  assert( !status );
108
109  status = sigaddset( &mask, SIGUSR2 );
110  assert( !status );
111
112  printf( "Init: Block SIGUSR2\n" );
113  status = sigprocmask( SIG_BLOCK, &mask, NULL );
114  assert( !status );
115
116  /* create a thread */
117
118  status = pthread_create( &Task_id, NULL, Task_1, NULL );
119  assert( !status );
120
121  /* signal handler is still installed, waitset is still set for SIGUSR1 */
122   
123  timeout.tv_sec = 3;
124  timeout.tv_nsec = 0;
125 
126  puts( "Init: waiting on any signal for 3 seconds." );
127  signo = sigtimedwait( &waitset, &siginfo, &timeout );
128
129     /* switch to Task 1 */
130
131  if ( errno == EAGAIN )
132    puts( "Init: correctly timed out waiting for SIGUSR1." );
133  else
134    printf( "sigtimedwait returned wrong errno - %d\n", errno );
135  assert( signo == -1 );
136 
137  /*
138   *  wait on SIGUSR1 for 3 seconds, Task_2 will send it to us
139   */
140
141  empty_line();
142
143  /* create a thread */
144
145  status = pthread_create( &Task_id, NULL, Task_2, NULL );
146  assert( !status );
147
148  /* signal handler is still installed, waitset is still set for SIGUSR1 */
149 
150  /* wait on SIGUSR1 for 3 seconds, will receive SIGUSR1 from Task_2 */
151 
152  timeout.tv_sec = 3;
153  timeout.tv_nsec = 0;
154 
155  /* just so we can check that these were altered */
156
157  siginfo.si_code = -1;
158  siginfo.si_signo = -1;
159  siginfo.si_value.sival_int = -1;
160
161  puts( "Init: waiting on any signal for 3 seconds." );
162  signo = sigtimedwait( &waitset, &siginfo, &timeout );
163  printf( "Init: received (%d) SIGUSR1=%d\n", siginfo.si_signo, SIGUSR1 );
164  assert( signo == SIGUSR1 );
165  assert( siginfo.si_signo == SIGUSR1 );
166  assert( siginfo.si_code == SI_USER );
167  assert( siginfo.si_value.sival_int != -1 );   /* rtems does always set this */
168 
169  /* exit this thread */
170
171  puts( "*** END OF POSIX TEST 3 ***" );
172  exit( 0 );
173
174  return NULL; /* just so the compiler thinks we returned something */
175}
Note: See TracBrowser for help on using the repository browser.