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

5
Last change on this file since af43554 was af43554, checked in by Sebastian Huber <sebastian.huber@…>, on Oct 26, 2017 at 11:59:11 AM

tests: Remove TEST_INIT

The TEST_EXTERN is a used only by the system.h style tests and they use
CONFIGURE_INIT appropriately.

Update #3170.
Update #3199.

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