source: rtems/testsuites/psxtests/psx09/init.c @ abf78d5

4.115
Last change on this file since abf78d5 was 33c46f1, checked in by Joel Sherrill <joel.sherrill@…>, on 10/21/10 at 21:22:25

2010-10-21 Joel Sherrill <joel.sherrill@…>

  • psx02/init.c, psx02/task.c, psx03/init.c, psx04/init.c, psx04/task1.c, psx04/task2.c, psx04/task3.c, psx05/init.c, psx05/task.c, psx05/task2.c, psx05/task3.c, psx06/init.c, psx06/task.c, psx06/task2.c, psx07/init.c, psx08/init.c, psx08/task2.c, psx08/task3.c, psx09/init.c, psx10/init.c, psx10/task.c, psx10/task2.c, psx10/task3.c, psx11/init.c, psx11/task.c, psx12/init.c, psxalarm01/init.c, psxbarrier01/test.c, psxcancel01/init.c, psxchroot01/test.c, psxitimer/init.c, psxkey01/task.c, psxkey02/init.c, psxkey03/init.c, psxmount/test.c, psxmsgq01/init.c, psxmsgq03/init.c, psxmsgq04/init.c, psxrwlock01/test.c, psxsem01/init.c, psxsignal01/init.c, psxsignal01/task1.c, psxsignal02/init.c, psxsignal03/init.c, psxsignal05/init.c, psxspin01/test.c, psxspin02/test.c, psxstack01/init.c, psxstack02/init.c, psxualarm/init.c: Eliminate double space after parenthesis on rtems_test_assert().
  • Property mode set to 100644
File size: 7.0 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#include <sched.h>
13
14#define CONFIGURE_INIT
15#include "system.h"
16#include <errno.h>
17
18void print_schedparam(
19  char               *prefix,
20  struct sched_param *schedparam
21);
22
23int HIGH_PRIORITY;
24int MEDIUM_PRIORITY;
25int LOW_PRIORITY;
26
27void print_schedparam(
28  char               *prefix,
29  struct sched_param *schedparam
30)
31{
32  printf( "%ssched priority      = %d\n", prefix, schedparam->sched_priority );
33#if defined(_POSIX_SPORADIC_SERVER)
34  printf( "%ssched_ss_low_priority     = %d\n",
35      prefix, schedparam->sched_ss_low_priority );
36  printf( "%ssched_ss_repl_period = (%ld, %ld)\n", prefix,
37     schedparam->sched_ss_repl_period.tv_sec,
38     schedparam->sched_ss_repl_period.tv_nsec );
39  printf( "%ssched_ss_init_budget = (%ld, %ld)\n", prefix,
40     schedparam->sched_ss_init_budget.tv_sec,
41     schedparam->sched_ss_init_budget.tv_nsec );
42#else
43  printf( "%s_POSIX_SPORADIC_SERVER is not defined\n" );
44#endif
45}
46
47void *POSIX_Init(
48  void *argument
49)
50{
51  int                  status;
52  int                  passes;
53  int                  schedpolicy;
54  int                  priority;
55  struct sched_param   schedparam;
56  char                 buffer[ 80 ];
57  pthread_mutexattr_t  attr;
58  time_t               start;
59  time_t               now;
60
61  puts( "\n\n*** POSIX TEST 9 ***" );
62
63  /* set the time of day, and print our buffer in multiple ways */
64
65  set_time( TM_FRIDAY, TM_MAY, 24, 96, 11, 5, 0 );
66
67  /* get id of this thread */
68
69  Init_id = pthread_self();
70  printf( "Init's ID is 0x%08" PRIxpthread_t "\n", Init_id );
71
72  /* try to use this thread as a sporadic server */
73
74  puts( "Init: pthread_getschedparam - SUCCESSFUL" );
75  status = pthread_getschedparam( pthread_self(), &schedpolicy, &schedparam );
76  rtems_test_assert( !status );
77
78  priority = schedparam.sched_priority;
79  sprintf( buffer, " - current priority = %d", priority );
80  print_current_time( "Init: ", buffer );
81
82  schedparam.sched_ss_repl_period.tv_sec = 0;
83  schedparam.sched_ss_repl_period.tv_nsec = 500000000;  /* 1/2 second */
84  schedparam.sched_ss_init_budget.tv_sec = 0;
85  schedparam.sched_ss_init_budget.tv_nsec = 250000000;    /* 1/4 second */
86
87  schedparam.sched_priority = sched_get_priority_max(SCHED_SPORADIC);
88  schedparam.sched_ss_low_priority = sched_get_priority_max(SCHED_SPORADIC) - 2;
89
90  puts( "Init: pthread_setschedparam - SUCCESSFUL (sporadic server)" );
91  status = pthread_setschedparam( pthread_self(), SCHED_SPORADIC, &schedparam );
92  rtems_test_assert( !status );
93
94  status = pthread_getschedparam( pthread_self(), &schedpolicy, &schedparam );
95  rtems_test_assert( !status );
96
97  priority = schedparam.sched_priority;
98  sprintf( buffer, " - new priority = %d", priority );
99  print_current_time( "Init: ", buffer );
100
101  /* go into a loop consuming CPU time to watch our priority change */
102
103  for ( passes=0 ; passes <= 3 ; ) {
104    status = pthread_getschedparam( pthread_self(), &schedpolicy, &schedparam );
105    rtems_test_assert( !status );
106
107    if ( priority != schedparam.sched_priority ) {
108      priority = schedparam.sched_priority;
109      sprintf( buffer, " - new priority = %d", priority );
110      print_current_time( "Init: ", buffer );
111      passes++;
112    }
113  }
114
115  /* now see if this works if we are holding a priority ceiling mutex */
116
117  empty_line();
118
119  status = pthread_getschedparam( pthread_self(), &schedpolicy, &schedparam );
120  rtems_test_assert( !status );
121
122  schedparam.sched_ss_repl_period.tv_sec = 0;
123  schedparam.sched_ss_repl_period.tv_nsec = 500000000;  /* 1/2 second */
124  schedparam.sched_ss_init_budget.tv_sec = 0;
125  schedparam.sched_ss_init_budget.tv_nsec = 250000000;    /* 1/4 second */
126
127  HIGH_PRIORITY = sched_get_priority_max( SCHED_SPORADIC );
128  MEDIUM_PRIORITY = sched_get_priority_max( SCHED_SPORADIC ) - 2;
129  LOW_PRIORITY = sched_get_priority_max( SCHED_SPORADIC ) - 4;
130
131  schedparam.sched_priority = HIGH_PRIORITY;
132  schedparam.sched_ss_low_priority = LOW_PRIORITY;
133
134  puts( "Init: pthread_setschedparam - SUCCESSFUL (sporadic server)" );
135  status = pthread_setschedparam( pthread_self(), SCHED_SPORADIC, &schedparam );
136  rtems_test_assert( !status );
137
138  puts( "Init: Initializing mutex attributes for priority ceiling" );
139  status = pthread_mutexattr_init( &attr );
140  rtems_test_assert( !status );
141
142  status = pthread_mutexattr_setprotocol( &attr, PTHREAD_PRIO_INHERIT );
143  rtems_test_assert( !status );
144
145  puts( "Init: Creating a mutex" );
146  status = pthread_mutex_init( &Mutex_id, &attr );
147  if ( status )
148    printf( "status = %d\n", status );
149  rtems_test_assert( !status );
150
151  status = pthread_getschedparam( pthread_self(), &schedpolicy, &schedparam );
152  rtems_test_assert( !status );
153
154  priority = schedparam.sched_priority;
155  sprintf( buffer, " - new priority = %d", priority );
156  print_current_time( "Init: ", buffer );
157
158  /* go into a loop consuming CPU time to watch our priority NOT lower */
159
160  start = time( &start );
161
162  puts( "Init: pthread_mutex_lock acquire the lock" );
163  status = pthread_mutex_lock( &Mutex_id );
164  if ( status )
165    printf( "status = %d %s\n", status, strerror(status) );
166  rtems_test_assert( !status );
167
168  for ( ; ; ) {
169    status = pthread_getschedparam( pthread_self(), &schedpolicy, &schedparam );
170    rtems_test_assert( !status );
171
172    if ( schedparam.sched_priority == LOW_PRIORITY ) {
173      puts( "ERROR - Init's priority lowered while holding mutex" );
174      rtems_test_exit(0);
175    }
176
177    now = time( &now );
178    if ( now - start > 3 )
179      break;
180
181    priority = schedparam.sched_priority;
182    sprintf( buffer, " - new priority = %d", priority );
183    print_current_time( "Init: ", buffer );
184
185    status = pthread_getschedparam( pthread_self(), &schedpolicy, &schedparam );
186    rtems_test_assert( !status );
187
188    priority = schedparam.sched_priority;
189    sprintf( buffer, " - new priority = %d", priority );
190    print_current_time( "Init: ", buffer );
191
192    break;
193  }
194
195  /* with this unlock we should be able to go to low priority */
196
197  puts( "Init: unlock mutex" );
198  status = pthread_mutex_unlock( &Mutex_id );
199  if ( status )
200    printf( "status = %d\n", status );
201  rtems_test_assert( !status );
202
203  status = pthread_getschedparam( pthread_self(), &schedpolicy, &schedparam );
204  rtems_test_assert( !status );
205
206  priority = schedparam.sched_priority;
207  sprintf( buffer, " - new priority = %d", priority );
208  print_current_time( "Init: ", buffer );
209
210  for ( ; ; ) {
211    status = pthread_getschedparam( pthread_self(), &schedpolicy, &schedparam );
212    rtems_test_assert( !status );
213
214    if ( schedparam.sched_priority == LOW_PRIORITY )
215      break;
216  }
217
218  status = pthread_getschedparam( pthread_self(), &schedpolicy, &schedparam );
219  rtems_test_assert( !status );
220
221  priority = schedparam.sched_priority;
222  sprintf( buffer, " - new priority = %d", priority );
223  print_current_time( "Init: ", buffer );
224
225  puts( "*** END OF POSIX TEST 9 ***" );
226  rtems_test_exit( 0 );
227
228  return NULL; /* just so the compiler thinks we returned something */
229}
Note: See TracBrowser for help on using the repository browser.