source: rtems/testsuites/psxtests/psx07/init.c @ 39615f4

4.104.115
Last change on this file since 39615f4 was 39615f4, checked in by Ralf Corsepius <ralf.corsepius@…>, on 10/27/09 at 14:10:54

Use PRIxpthread_t to print pthread_t's.

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