source: rtems/testsuites/psxtests/psxsignal03/init.c @ 9b4422a2

4.115
Last change on this file since 9b4422a2 was 9b4422a2, checked in by Joel Sherrill <joel.sherrill@…>, on 05/03/12 at 15:09:24

Remove All CVS Id Strings Possible Using a Script

Script does what is expected and tries to do it as
smartly as possible.

+ remove occurrences of two blank comment lines

next to each other after Id string line removed.

+ remove entire comment blocks which only exited to

contain CVS Ids

+ If the processing left a blank line at the top of

a file, it was removed.

  • Property mode set to 100644
File size: 6.0 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
10#ifdef HAVE_CONFIG_H
11#include "config.h"
12#endif
13
14#if defined(USE_USER_SIGNALS_PROCESS)
15  #define TEST_NAME                "03"
16  #define TEST_STRING              "User Signals to Process"
17  #define SIGNAL_ONE               SIGUSR1
18  #define SIGNAL_TWO               SIGUSR2
19  #define SEND_SIGNAL(_sig)        kill( getpid(), _sig )
20  #define TO_PROCESS
21
22#elif defined(USE_REAL_TIME_SIGNALS_PROCESS)
23  #define TEST_NAME                "04"
24  #define TEST_STRING              "Real-Time Signals to Process"
25  #define SIGNAL_ONE               SIGRTMIN
26  #define SIGNAL_TWO               SIGRTMAX
27  #define SEND_SIGNAL(_sig)        kill( getpid(), _sig )
28  #define TO_PROCESS
29
30#elif defined(USE_USER_SIGNALS_THREAD)
31  #define TEST_NAME                "05"
32  #define TEST_STRING              "User Signals to Thread"
33  #define SIGNAL_ONE               SIGUSR1
34  #define SIGNAL_TWO               SIGUSR2
35  #define SEND_SIGNAL(_sig)        pthread_kill( id, _sig )
36  #define TO_THREAD
37
38#elif defined(USE_REAL_TIME_SIGNALS_THREAD)
39  #define TEST_NAME                "05"
40  #define TEST_STRING              "Real-Time Signals to Thread"
41  #define SIGNAL_ONE               SIGRTMIN
42  #define SIGNAL_TWO               SIGRTMAX
43  #define SEND_SIGNAL(_sig)        pthread_kill( id, _sig )
44  #define TO_THREAD
45
46#else
47  #error "Test Mode not defined"
48
49#endif
50
51#include <pmacros.h>
52#include <signal.h>
53#include <errno.h>
54#include <pthread.h>
55#include <sched.h>
56
57volatile bool      Signal_occurred;
58volatile pthread_t Signal_thread;
59
60void Signal_handler(
61  int        signo,
62  siginfo_t *info,
63  void      *arg
64)
65{
66  Signal_occurred = true;
67  Signal_thread   = pthread_self();
68}
69
70const char *signal_name(int signo)
71{
72  if (signo == SIGUSR1)
73    return "SIGUSR1";
74  if (signo == SIGUSR2)
75    return "SIGUSR2";
76  if (signo == SIGRTMIN)
77    return "SIGRTMIN";
78  if (signo == SIGRTMAX)
79    return "SIGRTMAX";
80  return "unknown-signal";
81}
82
83void *Test_Thread(void *arg)
84{
85  bool        blocked = *((bool *)arg);
86  const char *name;
87  int         sc;
88  sigset_t    mask;
89  sigset_t    wait_mask;
90  siginfo_t   info;
91
92  if ( blocked )
93    name = "SignalBlocked";
94  else
95    name = "SignalNotBlocked";
96
97  /* build unblocked mask */
98  sc = sigemptyset( &mask );
99  rtems_test_assert( !sc );
100
101  printf( "%s - Unblock %s\n", name, signal_name(SIGNAL_ONE) );
102  sc = sigaddset( &mask, SIGNAL_ONE );
103  rtems_test_assert( !sc );
104
105  if ( !blocked ) {
106    printf( "%s - Unblock %s\n", name, signal_name(SIGNAL_TWO) );
107    sc = sigaddset( &mask, SIGNAL_TWO );
108    rtems_test_assert( !sc );
109  }
110
111  /* unblocked signals */
112  sc = pthread_sigmask( SIG_UNBLOCK, &mask, NULL );
113  rtems_test_assert( !sc );
114
115  /* build wait mask */
116  sc = sigemptyset( &wait_mask );
117  rtems_test_assert( !sc );
118
119  sc = sigaddset( &wait_mask, SIGNAL_ONE );
120  rtems_test_assert( !sc );
121
122  /* wait for a signal */
123  memset( &info, 0, sizeof(info) );
124
125  printf( "%s - Wait for %s unblocked\n", name, signal_name(SIGNAL_ONE) );
126  sigwaitinfo( &wait_mask, &info );
127  rtems_test_assert( !sc );
128
129  printf( "%s - siginfo.si_signo=%d\n", name, info.si_signo );
130  printf( "%s - siginfo.si_code=%d\n", name, info.si_code );
131  /* FIXME: Instead of casting to (uintptr_t) and using PRIxPTR, we
132   * likely should use %p. However, this would render this test's
133   * behavior non-deterministic, because %p's behavior is
134   * "implementation defined" */
135  printf( "%s - siginfo.si_value=0x%08" PRIxPTR "\n", name, (uintptr_t) info.si_value.sival_ptr );
136
137  rtems_test_assert( info.si_signo == SIGNAL_TWO );
138  rtems_test_assert( info.si_code == SI_USER );
139
140  printf( "%s - exiting\n", name );
141  return NULL;
142}
143
144void *POSIX_Init(
145  void *argument
146)
147{
148  int                 sc;
149  pthread_t           id;
150  struct sigaction    act;
151  bool                trueArg = true;
152  bool                falseArg = false;
153  struct timespec     delay_request;
154
155  puts( "\n\n*** POSIX TEST SIGNAL " TEST_NAME " ***" );
156  puts( "Init - Variation is: " TEST_STRING );
157
158  Signal_occurred = false;
159
160  act.sa_handler = NULL;
161  act.sa_sigaction = Signal_handler;
162  act.sa_flags   = SA_SIGINFO;
163  sigaction( SIGNAL_ONE, &act, NULL );
164  sigaction( SIGNAL_TWO, &act, NULL );
165
166  /* create threads */
167  sc = pthread_create( &id, NULL, Test_Thread, &falseArg );
168  rtems_test_assert( !sc );
169
170  sc = pthread_create( &id, NULL, Test_Thread, &trueArg );
171  rtems_test_assert( !sc );
172
173  puts( "Init - sleep - let threads settle - OK" );
174  delay_request.tv_sec = 0;
175  delay_request.tv_nsec = 5 * 100000000;
176  sc = nanosleep( &delay_request, NULL );
177  rtems_test_assert( !sc );
178
179  puts( "Init - sleep - SignalBlocked thread settle - OK" );
180  sc = nanosleep( &delay_request, NULL );
181  rtems_test_assert( !sc );
182
183  printf( "Init - sending %s - deliver to one thread\n",
184          signal_name(SIGNAL_TWO));
185  sc =  SEND_SIGNAL( SIGNAL_TWO );
186  rtems_test_assert( !sc );
187
188  printf( "Init - sending %s - deliver to other thread\n",
189          signal_name(SIGNAL_TWO));
190  sc =  SEND_SIGNAL( SIGNAL_TWO );
191  rtems_test_assert( !sc );
192
193  #if defined(TO_PROCESS)
194    printf( "Init - sending %s - expect EAGAIN\n", signal_name(SIGNAL_TWO) );
195    sc =  SEND_SIGNAL( SIGNAL_TWO );
196    rtems_test_assert( sc == -1 );
197    rtems_test_assert( errno == EAGAIN );
198  #endif
199
200  puts( "Init - sleep - let thread report if it unblocked - OK" );
201  usleep(500000);
202
203  /* we are just sigwait'ing the signal, not delivering it */
204  rtems_test_assert( Signal_occurred == true );
205
206  puts( "*** END OF POSIX TEST SIGNAL " TEST_NAME " ***" );
207  rtems_test_exit(0);
208
209  return NULL; /* just so the compiler thinks we returned something */
210}
211
212/* configuration information */
213
214#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
215#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
216
217#define CONFIGURE_MAXIMUM_POSIX_THREADS        3
218#define CONFIGURE_MAXIMUM_POSIX_QUEUED_SIGNALS 1
219
220#define CONFIGURE_POSIX_INIT_THREAD_TABLE
221
222#define CONFIGURE_INIT
223#include <rtems/confdefs.h>
Note: See TracBrowser for help on using the repository browser.