source: rtems/testsuites/psxtests/psx07/init.c @ cafefbf

4.115
Last change on this file since cafefbf was cafefbf, checked in by Ralf Corsepius <ralf.corsepius@…>, on 02/22/11 at 09:47:36

Add HAVE_CONFIG_H.

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