source: rtems/testsuites/psxtests/psxsignal02/init.c @ 9b4422a2

4.115
Last change on this file since 9b4422a2 was 9b4422a2, checked in by Joel Sherrill <joel.sherrill@…>, on 05/03/12 at 15:09:24

Remove All CVS Id Strings Possible Using a Script

Script does what is expected and tries to do it as
smartly as possible.

+ remove occurrences of two blank comment lines

next to each other after Id string line removed.

+ remove entire comment blocks which only exited to

contain CVS Ids

+ If the processing left a blank line at the top of

a file, it was removed.

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