source: rtems/testsuites/psxtests/psxsignal03/init.c @ 307b6b9

4.104.11
Last change on this file since 307b6b9 was 307b6b9, checked in by Joel Sherrill <joel.sherrill@…>, on Aug 2, 2009 at 3:00:05 PM

2009-08-02 Joel Sherrill <joel.sherrill@…>

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