source: rtems/testsuites/psxtests/psxsignal03/init.c @ ea7d86b

4.104.115
Last change on this file since ea7d86b was ea7d86b, checked in by Joel Sherrill <joel.sherrill@…>, on Nov 12, 2009 at 12:21:51 AM

2009-11-11 Joel Sherrill <joel.sherrill@…>

PR 1466/tests

  • Makefile.am, configure.ac, psxclock/init.c, psxclock/psxclock.doc, psxclock/psxclock.scn, psxkey03/init.c, psxsignal02/init.c, psxsignal03/init.c, psxstack01/init.c: Remove usleep() from tests. Add test specifically to test it since it is deprecated as of POSIX.1-2008.
  • psxusleep/.cvsignore, psxusleep/Makefile.am, psxusleep/init.c, psxusleep/psxusleep.doc, psxusleep/psxusleep.scn: New files.
  • Property mode set to 100644
File size: 5.8 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  siginfo_t   info;
89
90  if ( blocked )
91    name = "SignalBlocked";
92  else
93    name = "SignalNotBlocked";
94
95  /* build unblocked mask */
96  sc = sigemptyset( &mask );
97  assert( !sc );
98
99  printf( "%s - Unblock %s\n", name, signal_name(SIGNAL_ONE) );
100  sc = sigaddset( &mask, SIGNAL_ONE );
101  assert( !sc );
102
103  if ( !blocked ) {
104    printf( "%s - Unblock %s\n", name, signal_name(SIGNAL_TWO) );
105    sc = sigaddset( &mask, SIGNAL_TWO );
106    assert( !sc );
107  }
108
109  /* unblocked signals */
110  sc = pthread_sigmask( SIG_UNBLOCK, &mask, NULL );
111  assert( !sc );
112 
113  /* build wait mask */
114  sc = sigemptyset( &wait_mask );
115  assert( !sc );
116
117  sc = sigaddset( &wait_mask, SIGNAL_ONE );
118  assert( !sc );
119
120  /* wait for a signal */
121  memset( &info, 0, sizeof(info) );
122
123  printf( "%s - Wait for %s unblocked\n", name, signal_name(SIGNAL_ONE) );
124  sigwaitinfo( &wait_mask, &info );
125  assert( !sc );
126
127  printf( "%s - siginfo.si_signo=%d\n", name, info.si_signo );
128  printf( "%s - siginfo.si_code=%d\n", name, info.si_code );
129  /* FIXME: Instead of casting to (uintptr_t) and using PRIxPTR, we
130   * likely should use %p. However, this would render this test's
131   * behavior non-deterministic, because %p's behavior is
132   * "implementation defined" */
133  printf( "%s - siginfo.si_value=0x%08" PRIxPTR "\n", name, (uintptr_t) info.si_value.sival_ptr );
134
135  assert( info.si_signo == SIGNAL_TWO );
136  assert( info.si_code == SI_USER );
137
138  printf( "%s - exiting\n", name );
139  return NULL;
140}
141
142void *POSIX_Init(
143  void *argument
144)
145{
146  int                 sc;
147  pthread_t           id;
148  struct sigaction    act;
149  bool                trueArg = true;
150  bool                falseArg = false;
151  struct timespec     delay_request;
152
153  puts( "\n\n*** POSIX TEST SIGNAL " TEST_NAME " ***" );
154  puts( "Init - Variation is: " TEST_STRING );
155
156  Signal_occurred = false;
157
158  act.sa_handler = NULL;
159  act.sa_sigaction = Signal_handler;
160  act.sa_flags   = SA_SIGINFO;
161  sigaction( SIGNAL_ONE, &act, NULL );
162  sigaction( SIGNAL_TWO, &act, NULL );
163
164  /* create threads */
165  sc = pthread_create( &id, NULL, Test_Thread, &falseArg );
166  assert( !sc );
167
168  sc = pthread_create( &id, NULL, Test_Thread, &trueArg );
169  assert( !sc );
170
171  puts( "Init - sleep - let threads settle - OK" );
172  delay_request.tv_sec = 0;
173  delay_request.tv_nsec = 5 * 100000000;
174  sc = nanosleep( &delay_request, NULL );
175  assert( !sc );
176
177  puts( "Init - sleep - SignalBlocked thread settle - OK" );
178  sc = nanosleep( &delay_request, NULL );
179  assert( !sc );
180
181  printf( "Init - sending %s - deliver to one thread\n",
182          signal_name(SIGNAL_TWO));
183  sc =  SEND_SIGNAL( SIGNAL_TWO );
184  assert( !sc );
185
186  printf( "Init - sending %s - deliver to other thread\n",
187          signal_name(SIGNAL_TWO));
188  sc =  SEND_SIGNAL( SIGNAL_TWO );
189  assert( !sc );
190
191  #if defined(TO_PROCESS)
192    printf( "Init - sending %s - expect EAGAIN\n", signal_name(SIGNAL_TWO) );
193    sc =  SEND_SIGNAL( SIGNAL_TWO );
194    assert( sc == -1 );
195    assert( errno == EAGAIN );
196  #endif
197
198  puts( "Init - sleep - let thread report if it unblocked - OK" );
199  usleep(500000);
200
201  /* we are just sigwait'ing the signal, not delivering it */
202  assert( Signal_occurred == true );
203
204  puts( "*** END OF POSIX TEST SIGNAL " TEST_NAME " ***" );
205  rtems_test_exit(0);
206
207  return NULL; /* just so the compiler thinks we returned something */
208}
209
210/* configuration information */
211
212#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
213#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
214
215#define CONFIGURE_MAXIMUM_POSIX_THREADS        3
216#define CONFIGURE_MAXIMUM_POSIX_QUEUED_SIGNALS 1
217
218#define CONFIGURE_POSIX_INIT_THREAD_TABLE
219
220#define CONFIGURE_INIT
221#include <rtems/confdefs.h>
Note: See TracBrowser for help on using the repository browser.