source: rtems/testsuites/psxtests/psxsignal03/init.c @ 2ad8f85

4.104.115
Last change on this file since 2ad8f85 was 2ad8f85, checked in by Joel Sherrill <joel.sherrill@…>, on 07/29/09 at 18:31:20

2009-07-29 Joel Sherrill <joel.sherrill@…>

  • Makefile.am, configure.ac: Add test to address cases where a thread is waiting on a signal (sigwait) and we send it. Also address case where there are too many queued signals.
  • psxsignal03/.cvsignore, psxsignal03/Makefile.am, psxsignal03/init.c, psxsignal03/psxsignal03.doc, psxsignal03/psxsignal03.scn: New files.
  • Property mode set to 100644
File size: 3.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
13#include <pmacros.h>
14#include <signal.h>
15#include <errno.h>
16#include <pthread.h>
17#include <sched.h>
18
19volatile bool      Signal_occurred;
20volatile pthread_t Signal_thread;
21
22void Signal_handler(
23  int        signo,
24  siginfo_t *info,
25  void      *arg
26)
27{
28  Signal_occurred = true;
29  Signal_thread   = pthread_self();
30}
31
32void *Test_Thread(void *arg)
33{
34  bool        blocked = *((bool *)arg);
35  const char *name;
36  int         sc;
37  sigset_t    mask;
38  sigset_t    wait_mask;
39  sigset_t    pending_set;
40  sigset_t    oset;
41  siginfo_t   info;
42
43  if ( blocked )
44    name = "SignalBlocked";
45  else
46    name = "SignalNotBlocked";
47
48  /* build unblocked mask */
49  sc = sigemptyset( &mask );
50  assert( !sc );
51
52  printf( "%s - Unblock SIGUSR1\n", name );
53  sc = sigaddset( &mask, SIGUSR1 );
54  assert( !sc );
55
56  if ( !blocked ) {
57    printf( "%s - Unblock SIGUSR2\n", name );
58    sc = sigaddset( &mask, SIGUSR2 );
59    assert( !sc );
60  }
61
62  /* unblocked signals */
63  sc = pthread_sigmask( SIG_UNBLOCK, &mask, NULL );
64  assert( !sc );
65 
66  /* build wait mask */
67  sc = sigemptyset( &wait_mask );
68  assert( !sc );
69
70  sc = sigaddset( &wait_mask, SIGUSR1 );
71  assert( !sc );
72
73  /* wait for a signal */
74  memset( &info, 0, sizeof(info) );
75
76  printf( "%s - Wait for SIGUSR1 unblocked\n", name );
77  sigwaitinfo( &wait_mask, &info );
78  assert( !sc );
79
80  printf( "%s - siginfo.si_signo=%d\n", name, info.si_signo );
81  printf( "%s - siginfo.si_code=%d\n", name, info.si_code );
82  printf( "%s - siginfo.si_value=0x%08x\n", name, info.si_value );
83
84  assert( info.si_signo == SIGUSR2 );
85  assert( info.si_code == SI_USER );
86
87  printf( "%s - exiting\n", name );
88  return NULL;
89}
90
91void *POSIX_Init(
92  void *argument
93)
94{
95  int                 i;
96  int                 sc;
97  pthread_t           id;
98  struct sigaction    act;
99  bool                trueArg = true;
100  bool                falseArg = false;
101
102  puts( "\n\n*** POSIX TEST SIGNAL 03 ***" );
103
104  Signal_occurred = false;
105
106  act.sa_handler = NULL;
107  act.sa_sigaction = Signal_handler;
108  act.sa_flags   = SA_SIGINFO;
109  sigaction( SIGUSR1, &act, NULL );
110  sigaction( SIGUSR2, &act, NULL );
111
112  /* create threads */
113  sc = pthread_create( &id, NULL, Test_Thread, &falseArg );
114  assert( !sc );
115
116  sc = pthread_create( &id, NULL, Test_Thread, &trueArg );
117  assert( !sc );
118
119  puts( "Init - sleep - let threads settle - OK" );
120  usleep(500000);
121
122  puts( "Init - sleep - SignalBlocked thread settle - OK" );
123  usleep(500000);
124
125  puts( "Init - sending SIGUSR2 - deliver to one thread" );
126  sc =  kill( getpid(), SIGUSR2 );
127  assert( !sc );
128
129  puts( "Init - sending SIGUSR2 - deliver to other thread" );
130  sc =  kill( getpid(), SIGUSR2 );
131  assert( !sc );
132
133  puts( "Init - sending SIGUSR2 - expect EAGAIN" );
134  sc =  kill( getpid(), SIGUSR2 );
135  assert( sc == -1 );
136  assert( errno == EAGAIN );
137
138  puts( "Init - sleep - let thread report if it unblocked - OK" );
139  usleep(500000);
140
141  /* we are just sigwait'ing the signal, not delivering it */
142  assert( Signal_occurred == true );
143
144  puts( "*** END OF POSIX TEST SIGNAL 03 ***" );
145  rtems_test_exit(0);
146
147  return NULL; /* just so the compiler thinks we returned something */
148}
149
150/* configuration information */
151
152#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
153#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
154
155#define CONFIGURE_MAXIMUM_POSIX_THREADS        3
156#define CONFIGURE_MAXIMUM_POSIX_QUEUED_SIGNALS 1
157
158#define CONFIGURE_POSIX_INIT_THREAD_TABLE
159
160#define CONFIGURE_INIT
161#include <rtems/confdefs.h>
Note: See TracBrowser for help on using the repository browser.