source: rtems/testsuites/psxtests/psxsignal02/init.c @ b6912c40

4.104.115
Last change on this file since b6912c40 was b6912c40, checked in by Ralf Corsepius <ralf.corsepius@…>, on 10/25/09 at 06:25:04

Remove unused vars.
Add missing prototypes.

  • Property mode set to 100644
File size: 4.2 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)
25{
26  Signal_occurred = true;
27  Signal_thread   = pthread_self();
28}
29
30void Install_Signal_Handler(
31  const char *task_name
32)
33{
34  int               sc;
35  sigset_t          mask;
36
37  sc = sigemptyset( &mask );
38  assert( !sc );
39
40  sc = sigaddset( &mask, SIGUSR1 );
41  assert( !sc );
42
43  printf( "%s - Unblock SIGUSR1\n", task_name );
44  sc = pthread_sigmask( SIG_UNBLOCK, &mask, NULL );
45  assert( !sc );
46}
47
48/*
49
50Tasks and actions, created in this order, all interested in SIGUSR1
51  - 20     - interested, suspend?
52  - 18     - interested, suspend?
53  - 16     - interested, spins
54  - 14     - interested, spins
55  - 12     - interested, sleeps
56  - 10     - interested, suspends
57  - 8      - interested, sleeps
58
59Order is critical because the algorithm works by thread index
60*/
61
62typedef enum {
63  SUSPEND,
64  SPIN,
65  SLEEP
66} Action_t;
67
68const char *Actions[] = {
69  "Suspends self",
70  "Spins",
71  "Sleeps"
72};
73 
74
75typedef struct {
76  int         priority;
77  Action_t    action;
78  const char *name;
79} Test_t;
80
81Test_t Threads[] = {
82  {  8, SUSPEND,  "P8"  },  /* base priority */
83  {  7, SUSPEND,  "P7"  },  /* lower priority -- no change */
84  { 12, SUSPEND,  "P12" },  /* higher priority, blocked */
85  { 12, SUSPEND,  "P12" },  /* equal priority, blocked */
86  { 12, SLEEP,    "P12" },  /* equal priority, interruptible */
87  { 12, SLEEP,    "P12" },  /* equal priority, interruptible */
88  { 12, SPIN,     "P12" },  /* equal priority, ready */
89  { 12, SPIN,     "P12" },  /* equal priority, ready -- no change */
90  { -1, 0,        ""    },
91};
92
93void *Test_Thread(void *arg)
94{
95  Test_t *test = (Test_t *)arg;
96
97  Install_Signal_Handler( test->name );
98 
99  printf( "%s - %s\n", test->name, Actions[test->action] );
100  switch ( test->action ) {
101    case SUSPEND:
102      (void) rtems_task_suspend( RTEMS_SELF );
103      break;
104    case SPIN:
105      while (1) ;
106      break;
107    case SLEEP:
108      sleep( 30 );
109      break;
110  }
111
112  printf( "%s - exiting\n", test->name );
113  return NULL;
114
115}
116
117void *POSIX_Init(
118  void *argument
119)
120{
121  int                 i;
122  int                 sc;
123  pthread_t           id;
124  pthread_attr_t      attr;
125  struct sched_param  param;
126  Test_t             *test;
127  struct sigaction    act;
128
129  puts( "\n\n*** POSIX TEST SIGNAL 02 ***" );
130
131  Signal_occurred = false;
132
133  act.sa_handler = Signal_handler;
134  act.sa_flags   = 0;
135  sigaction( SIGUSR1, &act, NULL );
136
137  puts( "Init - Raise my priority" );
138  sc = pthread_attr_init( &attr );
139  assert( !sc );
140
141  param.sched_priority = 30;
142  sc = pthread_setschedparam( pthread_self(), SCHED_RR, &param );
143  assert( !sc );
144
145  for ( i=0, test=Threads ; test->priority != -1 ; i++, test++ ) {
146    printf( "Init - Create thread %d, priority=%d\n", i, test->priority );
147    sc = pthread_attr_init( &attr );
148    assert( !sc );
149
150    sc = pthread_attr_setinheritsched( &attr, PTHREAD_EXPLICIT_SCHED );
151    assert( !sc );
152
153    sc = pthread_attr_setschedpolicy( &attr, SCHED_RR );
154    assert( !sc );
155
156    param.sched_priority = test->priority;
157    sc = pthread_attr_setschedparam( &attr, &param );
158    assert( !sc );
159
160    sc = pthread_create( &id, &attr, Test_Thread, test );
161    assert( !sc );
162
163    puts( "Init - sleep - let thread settle - OK" );
164    usleep(500000);
165  }
166
167  puts( "Init - sending SIGUSR1" );
168  sc =  kill( getpid(), SIGUSR1 );
169  assert( !sc );
170
171  /* we are just scheduling the signal, not delivering it */
172  assert( Signal_occurred == false );
173
174  puts( "*** END OF POSIX TEST SIGNAL 02 ***" );
175  rtems_test_exit(0);
176
177  return NULL; /* just so the compiler thinks we returned something */
178}
179
180/* configuration information */
181
182#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
183#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
184
185#define CONFIGURE_MICROSECONDS_PER_TICK        1000
186#define CONFIGURE_MAXIMUM_POSIX_THREADS        9
187
188#define CONFIGURE_POSIX_INIT_THREAD_TABLE
189
190#define CONFIGURE_INIT
191#include <rtems/confdefs.h>
Note: See TracBrowser for help on using the repository browser.