source: rtems/testsuites/psxtests/psx07/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: 28.8 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 <pthread.h>
13#include <sched.h>
14
15#if !HAVE_DECL_PTHREAD_ATTR_GETCPUTIME
16extern int pthread_attr_getcputime(
17  pthread_attr_t  *attr,
18  int             *clock_allowed);
19#endif
20
21#if !HAVE_DECL_PTHREAD_ATTR_SETCPUTIME
22extern int pthread_attr_setcputime(
23  pthread_attr_t  *attr,
24  int             clock_allowed);
25#endif
26
27#define CONFIGURE_INIT
28#include "system.h"
29#include <errno.h>
30#include "tmacros.h"
31
32void print_schedparam(
33  char               *prefix,
34  struct sched_param *schedparam
35);
36
37void print_schedparam(
38  char               *prefix,
39  struct sched_param *schedparam
40)
41{
42  printf( "%ssched priority      = %d\n", prefix, schedparam->sched_priority );
43#if defined(_POSIX_SPORADIC_SERVER)
44  printf( "%ssched_ss_low_priority     = %d\n",
45     prefix, schedparam->sched_ss_low_priority );
46  printf( "%ssched_ss_replenish_period = (%ld, %ld)\n", prefix,
47     schedparam->sched_ss_repl_period.tv_sec,
48     schedparam->sched_ss_repl_period.tv_nsec );
49  printf( "%ssched_sched_ss_initial_budget = (%ld, %ld)\n", prefix,
50     schedparam->sched_ss_init_budget.tv_sec,
51     schedparam->sched_ss_init_budget.tv_nsec );
52#else
53  printf( "%s_POSIX_SPORADIC_SERVER is not defined\n" );
54#endif
55}
56
57void *POSIX_Init(
58  void *argument
59)
60{
61  int                 status;
62  int                 scope;
63  int                 inheritsched;
64  int                 schedpolicy;
65  size_t              stacksize;
66#if HAVE_DECL_PTHREAD_ATTR_SETGUARDSIZE
67  size_t              guardsize;
68#endif
69  void               *stackaddr;
70  int                 detachstate;
71  struct sched_param  schedparam;
72  pthread_attr_t      attr;
73  pthread_attr_t      destroyed_attr;
74  int                 clock_allowed;
75
76  puts( "\n\n*** POSIX TEST 7 ***" );
77
78  /* set the time of day, and print our buffer in multiple ways */
79
80  set_time( TM_FRIDAY, TM_MAY, 24, 96, 11, 5, 0 );
81
82  /* get id of this thread */
83
84  Init_id = pthread_self();
85  printf( "Init's ID is 0x%08" PRIxpthread_t "\n", Init_id );
86
87  /* exercise init and destroy */
88
89  puts( "Init - pthread_attr_init - EINVAL (NULL attr)" );
90  status = pthread_attr_init( NULL );
91  fatal_directive_check_status_only( status, EINVAL, "null attribute" );
92
93  puts( "Init - pthread_attr_init - SUCCESSFUL" );
94  status = pthread_attr_init( &attr );
95  posix_service_failed( status, "pthread_attr_init" );
96
97  puts( "Init - initialize and destroy an attribute - SUCCESSFUL" );
98  status = pthread_attr_init( &destroyed_attr );
99  posix_service_failed( status, "pthread_attr_init");
100
101  status = pthread_attr_destroy( &destroyed_attr );
102  posix_service_failed( status, "pthread_attr_destroy");
103
104  puts( "Init - pthread_attr_destroy - EINVAL (NULL attr)" );
105  status = pthread_attr_destroy( NULL );
106  fatal_directive_check_status_only( status, EINVAL, "NULL attribute" );
107
108  puts( "Init - pthread_attr_destroy - EINVAL (not initialized)" );
109  status = pthread_attr_destroy( &destroyed_attr );
110  fatal_directive_check_status_only( status, EINVAL, "not initialized" );
111
112  /* check some errors in pthread_create */
113
114  puts( "Init - pthread_create - EINVAL (attr not initialized)" );
115  status = pthread_create( &Task_id, &destroyed_attr, Task_1, NULL );
116  fatal_directive_check_status_only( status, EINVAL, "attribute not initialized" );
117
118  /* junk stack address */
119  status = pthread_attr_setstackaddr( &attr, (void *)&schedparam );
120  posix_service_failed( status, "setstackaddr");
121
122  /* must go around pthread_attr_setstacksize to set a bad stack size */
123  attr.stacksize = 0;
124
125  puts( "Init - pthread_create - EINVAL (stacksize too small)" );
126  status = pthread_create( &Task_id, &attr, Task_1, NULL );
127  fatal_directive_check_status_only( status, EINVAL, "stacksize too small" );
128
129  /* reset all the fields */
130  status = pthread_attr_init( &attr );
131  posix_service_failed( status, "pthread_attr_init");
132
133#if HAVE_DECL_PTHREAD_ATTR_SETSTACKADDR
134  attr.stacksize = rtems_configuration_get_work_space_size() * 10;
135  puts( "Init - pthread_create - EAGAIN (stacksize too large)" );
136  status = pthread_create( &Task_id, &attr, Task_1, NULL );
137  fatal_directive_check_status_only( status, EAGAIN, "stacksize too large" );
138#endif
139
140  status = pthread_attr_init( &attr );
141  posix_service_failed( status, "pthread_attr_init");
142
143  /* must go around pthread_attr_set routines to set a bad value */
144  attr.inheritsched = -1;
145
146  puts( "Init - pthread_create - EINVAL (invalid inherit scheduler)" );
147  status = pthread_create( &Task_id, &attr, Task_1, NULL );
148  fatal_directive_check_status_only( status, EINVAL, "invalid inherit scheduler" );
149
150  /* check out the error case for system scope not supported */
151
152  status = pthread_attr_init( &attr );
153  posix_service_failed( status, " pthread_attr_init");
154
155  /* Check out pthread_attr_settime and pthread_attr_gettime */
156  puts( "Init - pthread_attr_settime - EINVAL ( null attribute )" );
157  status = pthread_attr_setcputime( NULL, CLOCK_ENABLED );
158  fatal_directive_check_status_only( status, EINVAL, "null attribute" );
159
160  puts( "Init - pthread_attr_gettime - EINVAL ( null attribute )" );
161  status = pthread_attr_getcputime( NULL, &clock_allowed );
162  fatal_directive_check_status_only( status, EINVAL, " null attribute" );
163
164  puts( "Init - pthread_attr_settime - EINVAL ( is initialized )" );
165  status = pthread_attr_setcputime( &destroyed_attr, CLOCK_ENABLED );
166  fatal_directive_check_status_only( status, EINVAL, "is initialized" );
167
168  puts( "Init - pthread_attr_gettime - EINVAL ( is initialized )" );
169  status = pthread_attr_getcputime( &destroyed_attr, &clock_allowed  );
170  fatal_directive_check_status_only( status, EINVAL, "is initialized" );
171
172  puts( "Init - pthread_attr_settime - EINVAL ( invalid clock allowed )" );
173  status = pthread_attr_setcputime( &attr, ~(CLOCK_ENABLED | CLOCK_DISABLED) );
174  fatal_directive_check_status_only( status, EINVAL, "invalid clock allowed" );
175
176  puts( "Init - pthread_attr_gettime - EINVAL ( NULL clock allowed )" );
177  status = pthread_attr_getcputime( &attr, NULL );
178  fatal_directive_check_status_only( status, EINVAL, "NULL clock allowed" );
179
180  puts( "Init - validate pthread_attr_setcputime - CLOCK_DISABLED" );
181  status = pthread_attr_setcputime( &attr, CLOCK_DISABLED );
182  posix_service_failed( status, "pthread_attr_setcputime");
183  status = pthread_attr_getcputime( &attr, &clock_allowed );
184  posix_service_failed( status, "pthread_attr_getcputime");
185  if (attr.cputime_clock_allowed != CLOCK_DISABLED)
186    perror("ERROR==> pthread_attr_setcputime to CLOCK_DISABLED failed");
187
188  puts( "Init - validate pthread_attr_setcputime - CLOCK_ENABLED" );
189  status = pthread_attr_setcputime( &attr, CLOCK_ENABLED );
190  posix_service_failed( status, "pthread_attr_setcputime");
191  status = pthread_attr_getcputime( &attr, &clock_allowed );
192  posix_service_failed( status, "pthread_attr_getcputime");
193  if (attr.cputime_clock_allowed != CLOCK_ENABLED)
194    perror("ERROR==> pthread_attr_setcputime to CLOCK_ENABLED failed");
195
196  /* must go around pthread_attr_set routines to set a bad value */
197  attr.contentionscope = PTHREAD_SCOPE_SYSTEM;
198
199  puts( "Init - pthread_create - ENOTSUP (unsupported system contention scope)" );
200  status = pthread_create( &Task_id, &attr, Task_1, NULL );
201  fatal_directive_check_status_only( status, ENOTSUP,
202    "unsupported system contention scope" );
203
204  status = pthread_attr_init( &attr );
205  posix_service_failed( status, "pthread_attr_init");
206
207  /* now check out pthread_create for inherit scheduler */
208
209  status = pthread_attr_setinheritsched( &attr, PTHREAD_INHERIT_SCHED );
210  posix_service_failed( status, "pthread_attr_setinheritsched");
211
212  puts( "Init - pthread_create - SUCCESSFUL (inherit scheduler)" );
213  status = pthread_create( &Task_id, &attr, Task_1, NULL );
214  posix_service_failed( status, "pthread_create");
215
216  status = pthread_join( Task_id, NULL );
217  posix_service_failed( status, " pthread_join");
218
219    /* switch to Task_1 */
220
221  /* exercise get and set scope */
222
223  empty_line();
224
225  status = pthread_attr_init( &attr );
226  posix_service_failed( status, "pthread_attr_init");
227
228  puts( "Init - pthread_attr_setscope - EINVAL (NULL attr)" );
229  status = pthread_attr_setscope( NULL, PTHREAD_SCOPE_PROCESS );
230  fatal_directive_check_status_only( status, EINVAL , "NULL attr" );
231
232  puts( "Init - pthread_attr_setscope - ENOTSUP" );
233  status = pthread_attr_setscope( &attr, PTHREAD_SCOPE_SYSTEM );
234  fatal_directive_check_status_only( status, ENOTSUP, "PTHREAD_SCOPE_SYSTEM" );
235
236  puts( "Init - pthread_attr_setscope - EINVAL (not initialized attr)" );
237  status = pthread_attr_setscope( &destroyed_attr, PTHREAD_SCOPE_PROCESS );
238  fatal_directive_check_status_only( status, EINVAL, "not initialized attr" );
239
240  puts( "Init - pthread_attr_setscope - EINVAL (invalid scope)" );
241  status = pthread_attr_setscope( &attr, -1 );
242  fatal_directive_check_status_only( status, EINVAL, "invalid scope" );
243
244  puts( "Init - pthread_attr_setscope - SUCCESSFUL" );
245  status = pthread_attr_setscope( &attr, PTHREAD_SCOPE_PROCESS );
246  posix_service_failed( status, "pthread_attr_setscope");
247
248  puts( "Init - pthread_attr_getscope - EINVAL (NULL attr)" );
249  status = pthread_attr_getscope( NULL, &scope );
250  fatal_directive_check_status_only( status, EINVAL, "NULL attr" );
251
252  puts( "Init - pthread_attr_getscope - EINVAL (NULL scope)" );
253  status = pthread_attr_getscope( &attr, NULL );
254  fatal_directive_check_status_only( status, EINVAL, "NULL scope" );
255
256  puts( "Init - pthread_attr_getscope - EINVAL (not initialized attr)" );
257  status = pthread_attr_getscope( &destroyed_attr, &scope );
258  fatal_directive_check_status_only( status, EINVAL, "not initialized attr" );
259
260  puts( "Init - pthread_attr_getscope - SUCCESSFUL" );
261  status = pthread_attr_getscope( &attr, &scope );
262  posix_service_failed( status, "pthread_attr_getscope");
263  printf( "Init - current scope attribute = %d\n", scope );
264
265  /* exercise get and set inherit scheduler */
266
267  empty_line();
268
269  puts( "Init - pthread_attr_setinheritsched - EINVAL (NULL attr)" );
270  status = pthread_attr_setinheritsched( NULL, PTHREAD_INHERIT_SCHED );
271  fatal_directive_check_status_only( status, EINVAL, "NULL attr" );
272
273  puts( "Init - pthread_attr_setinheritsched - EINVAL (not initialized attr)" );
274  status =
275     pthread_attr_setinheritsched( &destroyed_attr, PTHREAD_INHERIT_SCHED );
276  fatal_directive_check_status_only( status, EINVAL, "not initialized attr" );
277
278  puts( "Init - pthread_attr_setinheritsched - ENOTSUP (invalid inheritsched)" );
279  status = pthread_attr_setinheritsched( &attr, -1 );
280  fatal_directive_check_status_only( status, ENOTSUP, "invalid inheritsched" );
281
282  puts( "Init - pthread_attr_setinheritsched - SUCCESSFUL" );
283  status = pthread_attr_setinheritsched( &attr, PTHREAD_INHERIT_SCHED );
284  posix_service_failed( status, "pthread_attr_setinheritsched");
285
286  puts( "Init - pthread_attr_getinheritsched - EINVAL (NULL attr)" );
287  status = pthread_attr_getinheritsched( NULL, &inheritsched );
288  fatal_directive_check_status_only( status, EINVAL, "NULL attr" );
289
290  puts( "Init - pthread_attr_getinheritsched - EINVAL (NULL inheritsched)" );
291  status = pthread_attr_getinheritsched( &attr, NULL );
292  fatal_directive_check_status_only( status, EINVAL, "NULL inheritsched" );
293
294  puts( "Init - pthread_attr_getinheritsched - EINVAL (not initialized attr)" );
295  status = pthread_attr_getinheritsched( &destroyed_attr, &inheritsched );
296  fatal_directive_check_status_only( status, EINVAL, "not initialized attr" );
297
298  puts( "Init - pthread_attr_getinheritsched - SUCCESSFUL" );
299  status = pthread_attr_getinheritsched( &attr, &inheritsched );
300  posix_service_failed( status, "pthread_attr_getinheritsched");
301  printf( "Init - current inherit scheduler attribute = %d\n", inheritsched );
302
303  /* exercise get and set inherit scheduler */
304
305  empty_line();
306
307  puts( "Init - pthread_attr_setschedpolicy - EINVAL (NULL attr)" );
308  status = pthread_attr_setschedpolicy( NULL, SCHED_FIFO );
309  fatal_directive_check_status_only( status, EINVAL, "NULL attr" );
310
311  puts( "Init - pthread_attr_setschedpolicy - EINVAL (not initialized attr)" );
312  status =
313     pthread_attr_setschedpolicy( &destroyed_attr, SCHED_OTHER );
314  fatal_directive_check_status_only( status, EINVAL, "not initialized attr" );
315
316  puts( "Init - pthread_attr_setschedpolicy - ENOTSUP (invalid schedpolicy)" );
317  status = pthread_attr_setschedpolicy( &attr, -1 );
318  fatal_directive_check_status_only( status, ENOTSUP, "invalid schedpolicy" );
319
320  puts( "Init - pthread_attr_setschedpolicy - SUCCESSFUL" );
321  status = pthread_attr_setschedpolicy( &attr, SCHED_RR );
322  posix_service_failed( status, "pthread_attr_setschedpolicy");
323
324  puts( "Init - pthread_attr_getschedpolicy - EINVAL (NULL attr)" );
325  status = pthread_attr_getschedpolicy( NULL, &schedpolicy );
326  fatal_directive_check_status_only( status, EINVAL, "NULL attr" );
327
328  puts( "Init - pthread_attr_getschedpolicy - EINVAL (NULL schedpolicy)" );
329  status = pthread_attr_getschedpolicy( &attr, NULL );
330  fatal_directive_check_status_only( status, EINVAL, "NULL schedpolicy" );
331
332  puts( "Init - pthread_attr_getschedpolicy - EINVAL (not initialized attr)" );
333  status = pthread_attr_getschedpolicy( &destroyed_attr, &schedpolicy );
334  fatal_directive_check_status_only( status, EINVAL, "not initialized attr" );
335
336  puts( "Init - pthread_attr_getschedpolicy - SUCCESSFUL" );
337  status = pthread_attr_getschedpolicy( &attr, &schedpolicy );
338  posix_service_failed( status, "pthread_attr_getschedpolicy");
339  printf( "Init - current scheduler policy attribute = %d\n", schedpolicy );
340
341  /* exercise get and set stack size */
342
343  empty_line();
344
345  puts( "Init - pthread_attr_setstacksize - EINVAL (NULL attr)" );
346  status = pthread_attr_setstacksize( NULL, 0 );
347  fatal_directive_check_status_only( status, EINVAL, "NULL attr" );
348
349  puts( "Init - pthread_attr_setstacksize - EINVAL (not initialized attr)" );
350  status =
351     pthread_attr_setstacksize( &destroyed_attr, 0 );
352  fatal_directive_check_status_only( status, EINVAL, "not initialized attr" );
353
354  puts( "Init - pthread_attr_setstacksize - SUCCESSFUL (low stacksize)" );
355  status = pthread_attr_setstacksize( &attr, 0 );
356  posix_service_failed( status, "pthread_attr_setstacksize");
357
358  puts( "Init - pthread_attr_setstacksize - SUCCESSFUL (high stacksize)" );
359  status = pthread_attr_setstacksize( &attr, STACK_MINIMUM_SIZE * 2 );
360  posix_service_failed( status, "");
361
362  puts( "Init - pthread_attr_getstacksize - EINVAL (NULL attr)" );
363  status = pthread_attr_getstacksize( NULL, &stacksize );
364  fatal_directive_check_status_only( status, EINVAL, "NULL attr" );
365
366  puts( "Init - pthread_attr_getstacksize - EINVAL (NULL stacksize)" );
367  status = pthread_attr_getstacksize( &attr, NULL );
368  fatal_directive_check_status_only( status, EINVAL, "NULL stacksize" );
369
370  puts( "Init - pthread_attr_getstacksize - EINVAL (not initialized attr)" );
371  status = pthread_attr_getstacksize( &destroyed_attr, &stacksize );
372  fatal_directive_check_status_only( status, EINVAL, "not initialized attr" );
373
374  puts( "Init - pthread_attr_getstacksize - SUCCESSFUL" );
375  status = pthread_attr_getstacksize( &attr, &stacksize );
376  posix_service_failed( status, "pthread_attr_getstacksize");
377  if ( stacksize == (STACK_MINIMUM_SIZE * 2) )
378    printf( "Init - current stack size attribute is OK\n" );
379
380  /* exercise get and set stack address */
381  empty_line();
382
383  puts( "Init - pthread_attr_setstackaddr - EINVAL (NULL attr)" );
384  status = pthread_attr_setstackaddr( NULL, NULL );
385  fatal_directive_check_status_only( status, EINVAL, "NULL attr" );
386
387  puts( "Init - pthread_attr_setstackaddr - EINVAL (not initialized attr)" );
388  status = pthread_attr_setstackaddr( &destroyed_attr, NULL );
389  fatal_directive_check_status_only( status, EINVAL, "not initialized attr" );
390
391  puts( "Init - pthread_attr_setstackaddr - SUCCESSFUL" );
392  status = pthread_attr_setstackaddr( &attr, 0 );
393  posix_service_failed( status, "");
394
395  /* get stack addr */
396  puts( "Init - pthread_attr_getstackaddr - EINVAL (NULL attr)" );
397  status = pthread_attr_getstackaddr( NULL, &stackaddr );
398  fatal_directive_check_status_only( status, EINVAL, "NULL attr" );
399
400  puts( "Init - pthread_attr_getstackaddr - EINVAL (NULL stackaddr)" );
401  status = pthread_attr_getstackaddr( &attr, NULL );
402  fatal_directive_check_status_only( status, EINVAL, "NULL stackaddr" );
403
404  puts( "Init - pthread_attr_getstackaddr - EINVAL (not initialized attr)" );
405  status = pthread_attr_getstackaddr( &destroyed_attr, &stackaddr );
406  fatal_directive_check_status_only( status, EINVAL, "not initialized attr" );
407
408  puts( "Init - pthread_attr_getstackaddr - SUCCESSFUL" );
409  status = pthread_attr_getstackaddr( &attr, &stackaddr );
410  posix_service_failed( status, "pthread_attr_getstackaddr");
411  printf( "Init - current stack address attribute = %p\n", stackaddr );
412
413  /* exercise get and set stack (as pair) */
414  empty_line();
415
416#if HAVE_DECL_PTHREAD_ATTR_SETSTACK
417  puts( "Init - pthread_attr_setstack- EINVAL (NULL attr)" );
418  status = pthread_attr_setstack( NULL, &stackaddr, 1024 );
419  fatal_directive_check_status_only( status, EINVAL, "NULL attr" );
420
421  puts( "Init - pthread_attr_setstack- EINVAL (destroyed attr)" );
422  status = pthread_attr_setstack( &destroyed_attr, &stackaddr, 1024 );
423  fatal_directive_check_status_only( status, EINVAL, "NULL attr" );
424
425  puts( "Init - pthread_attr_setstack- SUCCESSFUL (< min stack)" );
426  status = pthread_attr_setstack( &attr, stackaddr, 0 );
427  posix_service_failed( status, "OK");
428
429  puts( "Init - pthread_attr_setstack- SUCCESSFUL (big stack)" );
430  status = pthread_attr_setstack( &attr, stackaddr, STACK_MINIMUM_SIZE * 2 );
431  posix_service_failed( status, "OK");
432#endif
433
434#if HAVE_DECL_PTHREAD_ATTR_GETSTACK
435  puts( "Init - pthread_attr_getstack- EINVAL (NULL attr)" );
436  status = pthread_attr_getstack( NULL, &stackaddr, &stacksize );
437  fatal_directive_check_status_only( status, EINVAL, "NULL attr" );
438
439  puts( "Init - pthread_attr_getstack- EINVAL (destroyed attr)" );
440  status = pthread_attr_getstack( &destroyed_attr, &stackaddr, &stacksize );
441  fatal_directive_check_status_only( status, EINVAL, "&destroyed attr" );
442
443  puts( "Init - pthread_attr_getstack- EINVAL (NULL stack)" );
444  status = pthread_attr_getstack( &attr, NULL, &stacksize );
445  fatal_directive_check_status_only( status, EINVAL, "&NULL stack" );
446
447  puts( "Init - pthread_attr_getstack- EINVAL (NULL stacksize)" );
448  status = pthread_attr_getstack( &attr, &stackaddr, NULL );
449  fatal_directive_check_status_only( status, EINVAL, "&NULL size" );
450
451  puts( "Init - pthread_attr_getstack- SUCCESSFUL" );
452  status = pthread_attr_getstack( &attr, &stackaddr, &stacksize );
453  posix_service_failed( status, "pthread_attr_getstack");
454#endif
455
456  /* exercise get and set detach state */
457  empty_line();
458
459#if HAVE_DECL_PTHREAD_ATTR_SETGUARDSIZE
460  puts( "Init - pthread_attr_setguardsize - EINVAL (NULL attr)" );
461  status = pthread_attr_setguardsize( NULL, 0 );
462  fatal_directive_check_status_only( status, EINVAL, "NULL attr" );
463
464  puts( "Init - pthread_attr_setguardsize - EINVAL (not initialized attr)" );
465  status = pthread_attr_setguardsize( &destroyed_attr, 0 );
466  fatal_directive_check_status_only( status, EINVAL, "not initialized attr" );
467
468  puts( "Init - pthread_attr_setguardsize - SUCCESSFUL (low guardsize)" );
469  status = pthread_attr_setguardsize( &attr, 0 );
470  posix_service_failed( status, "pthread_attr_setguardsize");
471
472  puts( "Init - pthread_attr_setguardsize - SUCCESSFUL (high guardsize)" );
473  status = pthread_attr_setguardsize( &attr, STACK_MINIMUM_SIZE * 2 );
474  posix_service_failed( status, "");
475#endif
476
477#if HAVE_DECL_PTHREAD_ATTR_GETGUARDSIZE
478  puts( "Init - pthread_attr_getguardsize - EINVAL (NULL attr)" );
479  status = pthread_attr_getguardsize( NULL, &guardsize );
480  fatal_directive_check_status_only( status, EINVAL, "NULL attr" );
481
482  puts( "Init - pthread_attr_getguardsize - EINVAL (NULL guardsize)" );
483  status = pthread_attr_getguardsize( &attr, NULL );
484  fatal_directive_check_status_only( status, EINVAL, "NULL guardsize" );
485
486  puts( "Init - pthread_attr_getguardsize - EINVAL (not initialized attr)" );
487  status = pthread_attr_getguardsize( &destroyed_attr, &guardsize );
488  fatal_directive_check_status_only( status, EINVAL, "not initialized attr" );
489
490  puts( "Init - pthread_attr_getguardsize - SUCCESSFUL" );
491  status = pthread_attr_getguardsize( &attr, &guardsize );
492  posix_service_failed( status, "pthread_attr_getguardsize");
493#endif
494
495  /* exercise get and set detach state */
496  empty_line();
497
498  puts( "Init - pthread_attr_setdetachstate - EINVAL (NULL attr)" );
499  status = pthread_attr_setdetachstate( NULL, PTHREAD_CREATE_DETACHED );
500  fatal_directive_check_status_only( status, EINVAL, "NULL attr" );
501
502  puts( "Init - pthread_attr_setdetachstate - EINVAL (not initialized attr)" );
503  status =
504     pthread_attr_setdetachstate( &destroyed_attr, PTHREAD_CREATE_JOINABLE );
505  fatal_directive_check_status_only( status, EINVAL, "not initialized att" );
506
507  puts( "Init - pthread_attr_setdetachstate - EINVAL (invalid detachstate)" );
508  status = pthread_attr_setdetachstate( &attr, -1 );
509  fatal_directive_check_status_only( status, EINVAL, "invalid detachstate" );
510
511  puts( "Init - pthread_attr_setdetachstate - SUCCESSFUL" );
512  status = pthread_attr_setdetachstate( &attr, PTHREAD_CREATE_JOINABLE );
513  posix_service_failed( status, "pthread_attr_setdetachstate");
514
515  puts( "Init - pthread_attr_getdetachstate - EINVAL (NULL attr)" );
516  status = pthread_attr_getdetachstate( NULL, &detachstate );
517  fatal_directive_check_status_only( status, EINVAL, "NULL attr" );
518
519  puts( "Init - pthread_attr_getdetachstate - EINVAL (NULL detatchstate)" );
520  status = pthread_attr_getdetachstate( &attr, NULL );
521  fatal_directive_check_status_only( status, EINVAL, "NULL detatchstate" );
522
523  puts( "Init - pthread_attr_getdetachstate - EINVAL (not initialized attr)" );
524  status = pthread_attr_getdetachstate( &destroyed_attr, &detachstate );
525  fatal_directive_check_status_only( status, EINVAL, "not initialized attr" );
526
527  puts( "Init - pthread_attr_getdetachstate - SUCCESSFUL" );
528  status = pthread_attr_getdetachstate( &attr, &detachstate );
529  posix_service_failed( status, "pthread_attr_getdetachstate");
530  printf( "Init - current detach state attribute = %d\n", detachstate );
531
532  /* exercise get and set scheduling parameters */
533
534  empty_line();
535
536  puts( "Init - pthread_attr_getschedparam - SUCCESSFUL" );
537  status = pthread_attr_getschedparam( &attr, &schedparam );
538  posix_service_failed( status, "pthread_attr_getschedparam");
539
540  print_schedparam( "Init - ", &schedparam );
541
542  puts( "Init - pthread_attr_setschedparam - EINVAL (NULL attr)" );
543  status = pthread_attr_setschedparam( NULL, &schedparam );
544  fatal_directive_check_status_only( status, EINVAL, "NULL attr" );
545
546  puts( "Init - pthread_attr_setschedparam - EINVAL (not initialized attr)" );
547  status = pthread_attr_setschedparam( &destroyed_attr, &schedparam );
548  fatal_directive_check_status_only( status, EINVAL, "not initialized attr" );
549
550  puts( "Init - pthread_attr_setschedparam - EINVAL (NULL schedparam)" );
551  status = pthread_attr_setschedparam( &attr, NULL );
552  fatal_directive_check_status_only( status, EINVAL, "NULL schedparam" );
553
554  puts( "Init - pthread_attr_setschedparam - SUCCESSFUL" );
555  status = pthread_attr_setschedparam( &attr, &schedparam );
556  posix_service_failed( status, "pthread_attr_setschedparam");
557
558  puts( "Init - pthread_attr_getschedparam - EINVAL (NULL attr)" );
559  status = pthread_attr_getschedparam( NULL, &schedparam );
560  fatal_directive_check_status_only( status, EINVAL, "pthread_attr_getschedparam" );
561
562  puts( "Init - pthread_attr_getschedparam - EINVAL (not initialized attr)" );
563  status = pthread_attr_getschedparam( &destroyed_attr, &schedparam );
564  fatal_directive_check_status_only( status, EINVAL, "not initialized attr" );
565
566  puts( "Init - pthread_attr_getschedparam - EINVAL (NULL schedparam)" );
567  status = pthread_attr_getschedparam( &attr, NULL );
568  fatal_directive_check_status_only( status, EINVAL, "NULL schedparam" );
569
570  /* exercise pthread_getschedparam */
571
572  empty_line();
573
574  puts( "Init - pthread_getschedparam - EINVAL (NULL policy)" );
575  status = pthread_getschedparam( pthread_self(), NULL, &schedparam );
576  fatal_directive_check_status_only( status, EINVAL, "NULL policy" );
577
578  puts( "Init - pthread_getschedparam - EINVAL (NULL schedparam)" );
579  status = pthread_getschedparam( pthread_self(), &schedpolicy, NULL );
580  fatal_directive_check_status_only( status, EINVAL, "NULL schedparam" );
581
582  puts( "Init - pthread_getschedparam - ESRCH (bad thread)" );
583  status = pthread_getschedparam( (pthread_t) -1, &schedpolicy, &schedparam );
584  fatal_directive_check_status_only( status, ESRCH, "bad thread" );
585
586  puts( "Init - pthread_getschedparam - SUCCESSFUL" );
587  status = pthread_getschedparam( pthread_self(), &schedpolicy, &schedparam );
588  posix_service_failed( status, "pthread_getschedparam");
589
590  printf( "Init - policy = %d\n", schedpolicy );
591
592  print_schedparam( "Init - ", &schedparam );
593
594  /* exercise pthread_setschedparam */
595
596  empty_line();
597
598  puts( "Init - pthread_setschedparam - EINVAL (NULL schedparam)" );
599  status = pthread_setschedparam( pthread_self(), SCHED_OTHER, NULL );
600  fatal_directive_check_status_only( status, EINVAL, "NULL schedparam" );
601
602  schedparam.sched_priority = -1;
603
604  puts( "Init - pthread_setschedparam - EINVAL (invalid priority)" );
605  status = pthread_setschedparam( pthread_self(), SCHED_OTHER, NULL );
606  fatal_directive_check_status_only( status, EINVAL, "invalid priority" );
607
608  /* reset sched_param */
609  status = pthread_getschedparam( pthread_self(), &schedpolicy, &schedparam );
610  posix_service_failed( status, "pthread_getschedparam");
611
612  puts( "Init - pthread_setschedparam - EINVAL (invalid policy)" );
613  status = pthread_setschedparam( pthread_self(), -1, &schedparam );
614  fatal_directive_check_status_only( status, EINVAL, "invalid policy" );
615
616  puts( "Init - pthread_setschedparam - ESRCH (invalid thread)" );
617  status = pthread_setschedparam( (pthread_t) -1, SCHED_OTHER, &schedparam );
618  fatal_directive_check_status_only( status, ESRCH, "invalid thread" );
619
620  /* now get sporadic server errors */
621
622  schedparam.sched_ss_repl_period.tv_sec = 0;
623  schedparam.sched_ss_repl_period.tv_nsec = 0;
624  schedparam.sched_ss_init_budget.tv_sec = 1;
625  schedparam.sched_ss_init_budget.tv_nsec = 1;
626
627  puts( "Init - pthread_setschedparam - EINVAL (replenish == 0)" );
628  status = pthread_setschedparam( pthread_self(), SCHED_SPORADIC, &schedparam );
629  fatal_directive_check_status_only( status, EINVAL, "replenish == 0" );
630
631  schedparam.sched_ss_repl_period.tv_sec = 1;
632  schedparam.sched_ss_repl_period.tv_nsec = 1;
633  schedparam.sched_ss_init_budget.tv_sec = 0;
634  schedparam.sched_ss_init_budget.tv_nsec = 0;
635
636  puts( "Init - pthread_setschedparam - EINVAL (budget == 0)" );
637  status = pthread_setschedparam( pthread_self(), SCHED_SPORADIC, &schedparam );
638  fatal_directive_check_status_only( status, EINVAL, "budget == 0" );
639
640  schedparam.sched_ss_repl_period.tv_sec = 1;
641  schedparam.sched_ss_repl_period.tv_nsec = 0;
642  schedparam.sched_ss_init_budget.tv_sec = 1;
643  schedparam.sched_ss_init_budget.tv_nsec = 1;
644
645  puts( "Init - pthread_setschedparam - EINVAL (replenish < budget)" );
646  status = pthread_setschedparam( pthread_self(), SCHED_SPORADIC, &schedparam );
647  fatal_directive_check_status_only( status, EINVAL, "replenish < budget" );
648
649  schedparam.sched_ss_repl_period.tv_sec = 2;
650  schedparam.sched_ss_repl_period.tv_nsec = 0;
651  schedparam.sched_ss_init_budget.tv_sec = 1;
652  schedparam.sched_ss_init_budget.tv_nsec = 0;
653  schedparam.sched_ss_low_priority = -1;
654
655  puts( "Init - pthread_setschedparam - EINVAL (invalid priority)" );
656  status = pthread_setschedparam( pthread_self(), SCHED_SPORADIC, &schedparam );
657  fatal_directive_check_status_only( status, EINVAL, "invalid priority" );
658
659  /*
660   *  Create a sporadic thread that doesn't need it's priority
661   *  boosted
662   */
663  empty_line();
664
665  puts( "Init - pthread_attr_init - SUCCESSFUL" );
666  status = pthread_attr_init( &attr );
667  posix_service_failed( status, "pthread_attr_init" );
668
669  puts( "Init - pthread_attr_setinheritsched - EXPLICIT - SUCCESSFUL" );
670  status = pthread_attr_setinheritsched( &attr, PTHREAD_EXPLICIT_SCHED );
671  rtems_test_assert( !status );
672
673  schedparam.sched_ss_repl_period.tv_sec = 3;
674  schedparam.sched_ss_repl_period.tv_nsec = 3;
675  schedparam.sched_ss_init_budget.tv_sec = 1;
676  schedparam.sched_ss_init_budget.tv_nsec = 1;
677  schedparam.sched_priority = sched_get_priority_max( SCHED_FIFO );
678  schedparam.sched_ss_low_priority = sched_get_priority_max( SCHED_FIFO ) - 6;
679
680  puts( "Init - pthread_attr_setschedpolicy - SUCCESSFUL" );
681  status = pthread_attr_setschedpolicy( &attr, SCHED_SPORADIC );
682  posix_service_failed( status, "pthread_attr_setschedparam");
683  puts( "Init - pthread_attr_setschedparam - SUCCESSFUL" );
684  status = pthread_attr_setschedparam( &attr, &schedparam );
685  posix_service_failed( status, "pthread_attr_setschedparam");
686
687  status = pthread_create( &Task2_id, &attr, Task_2, NULL );
688  rtems_test_assert( !status );
689
690  status = pthread_join( Task2_id, NULL );
691  posix_service_failed( status, " pthread_join");
692
693  puts( "*** END OF POSIX TEST 7 ***" );
694  rtems_test_exit( 0 );
695
696  return NULL; /* just so the compiler thinks we returned something */
697}
Note: See TracBrowser for help on using the repository browser.