source: rtems/testsuites/psxtests/psxsignal03/init.c @ 1e2d7510

4.104.11
Last change on this file since 1e2d7510 was 1e2d7510, checked in by Joel Sherrill <joel.sherrill@…>, on Sep 14, 2009 at 12:15:55 AM

2009-09-13 Joel Sherrill <joel.sherrill@…>

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