source: rtems/testsuites/psxtests/psx07/init.c @ 6baf5a5

4.115
Last change on this file since 6baf5a5 was 6baf5a5, checked in by Joel Sherrill <joel.sherrill@…>, on 10/04/10 at 15:53:45

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

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