source: rtems/c/src/tests/psxtests/psx07/init.c @ ac81b6ca

4.104.114.84.95
Last change on this file since ac81b6ca was ac81b6ca, checked in by Joel Sherrill <joel.sherrill@…>, on 08/14/96 at 19:41:47

added test cases for NULL being passed to pthread attribute get routines

  • Property mode set to 100644
File size: 16.7 KB
Line 
1/*
2 *  COPYRIGHT (c) 1989, 1990, 1991, 1992, 1993, 1994.
3 *  On-Line Applications Research Corporation (OAR).
4 *  All rights assigned to U.S. Government, 1994.
5 *
6 *  This material may be reproduced by or for the U.S. Government pursuant
7 *  to the copyright license under the clause at DFARS 252.227-7013.  This
8 *  notice must appear in all copies of this file and its derivatives.
9 *
10 *  $Id$
11 */
12
13#define CONFIGURE_INIT
14#include "system.h"
15#include <errno.h>
16
17void print_schedparam(
18  char               *prefix,
19  struct sched_param *schedparam
20)
21{
22  printf( "%ssched priority      = %d\n", prefix, schedparam->sched_priority );
23#if defined(_POSIX_SPORADIC_SERVER)
24  printf( "%sss_low_priority     = %d\n", prefix, schedparam->ss_low_priority );
25  printf( "%sss_replenish_period = (%ld, %ld)\n", prefix,
26     schedparam->ss_replenish_period.tv_sec,
27     schedparam->ss_replenish_period.tv_nsec );
28  printf( "%sss_initial_budget = (%ld, %ld)\n", prefix,
29     schedparam->ss_initial_budget.tv_sec,
30     schedparam->ss_initial_budget.tv_nsec );
31#else
32  printf( "%s_POSIX_SPORADIC_SERVER is not defined\n" );
33#endif
34}
35 
36extern rtems_configuration_table BSP_Configuration;
37
38void *POSIX_Init(
39  void *argument
40)
41{
42  int                 status;
43  int                 scope;
44  int                 inheritsched;
45  int                 schedpolicy;
46  size_t              stacksize;
47  void               *stackaddr;
48  int                 detachstate;
49  struct sched_param  schedparam;
50  pthread_attr_t      attr;
51  pthread_attr_t      destroyed_attr;
52
53  puts( "\n\n*** POSIX TEST 7 ***" );
54
55  /* set the time of day, and print our buffer in multiple ways */
56
57  set_time( TM_FRIDAY, TM_MAY, 24, 96, 11, 5, 0 );
58
59  /* get id of this thread */
60
61  Init_id = pthread_self();
62  printf( "Init's ID is 0x%08x\n", Init_id );
63 
64  /* exercise init and destroy */
65
66  puts( "Init: pthread_attr_init - EINVAL (NULL attr)" );
67  status = pthread_attr_init( NULL );
68  assert( status == EINVAL );
69
70  puts( "Init: pthread_attr_init - SUCCESSFUL" );
71  status = pthread_attr_init( &attr );
72  assert( !status );
73
74  puts( "Init: initialize and destroy an attribute - SUCCESSFUL" );
75  status = pthread_attr_init( &destroyed_attr );
76  assert( !status );
77
78  status = pthread_attr_destroy( &destroyed_attr );
79  assert( !status );
80
81  puts( "Init: pthread_attr_destroy - EINVAL (NULL attr)" );
82  status = pthread_attr_destroy( NULL );
83  assert( status == EINVAL );
84
85  puts( "Init: pthread_attr_destroy - EINVAL (not initialized)" );
86  status = pthread_attr_destroy( &destroyed_attr );
87  assert( status == EINVAL );
88
89  /* check some errors in pthread_create */
90
91  puts( "Init: pthread_create - EINVAL (attr not initialized)" );
92  status = pthread_create( &Task_id, &destroyed_attr, Task_1, NULL );
93  assert( status == EINVAL );
94
95  /* junk stack address */
96  status = pthread_attr_setstackaddr( &attr, (void *)&schedparam );
97  assert( !status );
98 
99  /* must go around pthread_attr_setstacksize to set a bad stack size */
100  attr.stacksize = 0;
101 
102  puts( "Init: pthread_create - EINVAL (stacksize too small)" );
103  status = pthread_create( &Task_id, &attr, Task_1, NULL );
104  assert( status == EINVAL );
105
106  attr.stacksize = BSP_Configuration.work_space_size;
107  puts( "Init: pthread_create - EINVAL (stacksize too large)" );
108  status = pthread_create( &Task_id, &attr, Task_1, NULL );
109  assert( status == EINVAL );
110
111  status = pthread_attr_init( &attr );
112  assert( !status );
113
114  /* must go around pthread_attr_set routines to set a bad value */
115  attr.inheritsched = -1;
116 
117  puts( "Init: pthread_create - EINVAL (invalid inherit scheduler)" );
118  status = pthread_create( &Task_id, &attr, Task_1, NULL );
119  assert( status == EINVAL );
120
121  /* check out the error case for system scope not supported */
122
123  status = pthread_attr_init( &attr );
124  assert( !status );
125
126  /* must go around pthread_attr_set routines to set a bad value */
127  attr.contentionscope = PTHREAD_SCOPE_SYSTEM;
128
129  puts( "Init: pthread_create - ENOSYS (unsupported system contention scope)" );
130  status = pthread_create( &Task_id, &attr, Task_1, NULL );
131  assert( status == ENOSYS );
132
133  status = pthread_attr_init( &attr );
134  assert( !status );
135
136  /* now check out pthread_create for inherit scheduler */
137
138  status = pthread_attr_setinheritsched( &attr, PTHREAD_INHERIT_SCHED );
139  assert( !status );
140 
141  puts( "Init: pthread_create - SUCCESSFUL (inherit scheduler)" );
142  status = pthread_create( &Task_id, &attr, Task_1, NULL );
143  assert( !status );
144
145  status = pthread_join( Task_id, NULL );
146  assert( !status );
147
148    /* switch to Task_1 */
149
150  /* exercise get and set scope */
151
152  empty_line();
153
154  status = pthread_attr_init( &attr );
155  assert( !status );
156
157  puts( "Init: pthread_attr_setscope - EINVAL (NULL attr)" );
158  status = pthread_attr_setscope( NULL, PTHREAD_SCOPE_PROCESS );
159  assert( status == EINVAL );
160
161  puts( "Init: pthread_attr_setscope - ENOTSUP" );
162  status = pthread_attr_setscope( &attr, PTHREAD_SCOPE_SYSTEM );
163  assert( status == ENOTSUP );
164
165  puts( "Init: pthread_attr_setscope - EINVAL (not initialized attr)" );
166  status = pthread_attr_setscope( &destroyed_attr, PTHREAD_SCOPE_PROCESS );
167  assert( status == EINVAL );
168
169  puts( "Init: pthread_attr_setscope - EINVAL (invalid scope)" );
170  status = pthread_attr_setscope( &attr, -1 );
171  assert( status == EINVAL );
172
173  puts( "Init: pthread_attr_setscope - SUCCESSFUL" );
174  status = pthread_attr_setscope( &attr, PTHREAD_SCOPE_PROCESS );
175  assert( !status );
176 
177  puts( "Init: pthread_attr_getscope - EINVAL (NULL attr)" );
178  status = pthread_attr_getscope( NULL, &scope );
179  assert( status == EINVAL );
180 
181  puts( "Init: pthread_attr_getscope - EINVAL (NULL scope)" );
182  status = pthread_attr_getscope( &attr, NULL );
183  assert( status == EINVAL );
184 
185  puts( "Init: pthread_attr_getscope - EINVAL (not initialized attr)" );
186  status = pthread_attr_getscope( &destroyed_attr, &scope );
187  assert( status == EINVAL );
188 
189  puts( "Init: pthread_attr_getscope - SUCCESSFUL" );
190  status = pthread_attr_getscope( &attr, &scope );
191  assert( !status );
192  printf( "Init: current scope attribute = %d\n", scope );
193
194  /* exercise get and set inherit scheduler */
195
196  empty_line();
197
198  puts( "Init: pthread_attr_setinheritsched - EINVAL (NULL attr)" );
199  status = pthread_attr_setinheritsched( NULL, PTHREAD_INHERIT_SCHED );
200  assert( status == EINVAL );
201 
202  puts( "Init: pthread_attr_setinheritsched - EINVAL (not initialized attr)" );
203  status =
204     pthread_attr_setinheritsched( &destroyed_attr, PTHREAD_INHERIT_SCHED );
205  assert( status == EINVAL );
206 
207  puts( "Init: pthread_attr_setinheritsched - EINVAL (invalid inheritsched)" );
208  status = pthread_attr_setinheritsched( &attr, -1 );
209  assert( status == EINVAL );
210 
211  puts( "Init: pthread_attr_setinheritsched - SUCCESSFUL" );
212  status = pthread_attr_setinheritsched( &attr, PTHREAD_INHERIT_SCHED );
213  assert( !status );
214 
215  puts( "Init: pthread_attr_getinheritsched - EINVAL (NULL attr)" );
216  status = pthread_attr_getinheritsched( NULL, &inheritsched );
217  assert( status == EINVAL );
218 
219  puts( "Init: pthread_attr_getinheritsched - EINVAL (NULL inheritsched)" );
220  status = pthread_attr_getinheritsched( &attr, NULL );
221  assert( status == EINVAL );
222 
223  puts( "Init: pthread_attr_getinheritsched - EINVAL (not initialized attr)" );
224  status = pthread_attr_getinheritsched( &destroyed_attr, &inheritsched );
225  assert( status == EINVAL );
226 
227  puts( "Init: pthread_attr_getinheritsched - SUCCESSFUL" );
228  status = pthread_attr_getinheritsched( &attr, &inheritsched );
229  assert( !status );
230  printf( "Init: current inherit scheduler attribute = %d\n", inheritsched );
231
232  /* exercise get and set inherit scheduler */
233 
234  empty_line();
235 
236  puts( "Init: pthread_attr_setschedpolicy - EINVAL (NULL attr)" );
237  status = pthread_attr_setschedpolicy( NULL, SCHED_FIFO );
238  assert( status == EINVAL );
239 
240  puts( "Init: pthread_attr_setschedpolicy - EINVAL (not initialized attr)" );
241  status =
242     pthread_attr_setschedpolicy( &destroyed_attr, SCHED_OTHER );
243  assert( status == EINVAL );
244 
245  puts( "Init: pthread_attr_setschedpolicy - EINVAL (invalid schedpolicy)" );
246  status = pthread_attr_setschedpolicy( &attr, -1 );
247  assert( status == EINVAL );
248 
249  puts( "Init: pthread_attr_setschedpolicy - SUCCESSFUL" );
250  status = pthread_attr_setschedpolicy( &attr, SCHED_RR );
251  assert( !status );
252 
253  puts( "Init: pthread_attr_getschedpolicy - EINVAL (NULL attr)" );
254  status = pthread_attr_getschedpolicy( NULL, &schedpolicy );
255  assert( status == EINVAL );
256 
257  puts( "Init: pthread_attr_getschedpolicy - EINVAL (NULL schedpolicy)" );
258  status = pthread_attr_getschedpolicy( &attr, NULL );
259  assert( status == EINVAL );
260 
261  puts( "Init: pthread_attr_getschedpolicy - EINVAL (not initialized attr)" );
262  status = pthread_attr_getschedpolicy( &destroyed_attr, &schedpolicy );
263  assert( status == EINVAL );
264 
265  puts( "Init: pthread_attr_getschedpolicy - SUCCESSFUL" );
266  status = pthread_attr_getschedpolicy( &attr, &schedpolicy );
267  assert( !status );
268  printf( "Init: current scheduler policy attribute = %d\n", schedpolicy );
269 
270  /* exercise get and set stack size */
271 
272  empty_line();
273 
274  puts( "Init: pthread_attr_setstacksize - EINVAL (NULL attr)" );
275  status = pthread_attr_setstacksize( NULL, 0 );
276  assert( status == EINVAL );
277 
278  puts( "Init: pthread_attr_setstacksize - EINVAL (not initialized attr)" );
279  status =
280     pthread_attr_setstacksize( &destroyed_attr, 0 );
281  assert( status == EINVAL );
282 
283  puts( "Init: pthread_attr_setstacksize - SUCCESSFUL (low stacksize)" );
284  status = pthread_attr_setstacksize( &attr, 0 );
285  assert( !status );
286
287  puts( "Init: pthread_attr_setstacksize - SUCCESSFUL (high stacksize)" );
288  status = pthread_attr_setstacksize( &attr, STACK_MINIMUM_SIZE * 2 );
289  assert( !status );
290 
291  puts( "Init: pthread_attr_getstacksize - EINVAL (NULL attr)" );
292  status = pthread_attr_getstacksize( NULL, &stacksize );
293  assert( status == EINVAL );
294 
295  puts( "Init: pthread_attr_getstacksize - EINVAL (NULL stacksize)" );
296  status = pthread_attr_getstacksize( &attr, NULL );
297  assert( status == EINVAL );
298 
299  puts( "Init: pthread_attr_getstacksize - EINVAL (not initialized attr)" );
300  status = pthread_attr_getstacksize( &destroyed_attr, &stacksize );
301  assert( status == EINVAL );
302 
303  puts( "Init: pthread_attr_getstacksize - SUCCESSFUL" );
304  status = pthread_attr_getstacksize( &attr, &stacksize );
305  assert( !status );
306  printf( "Init: current stack size attribute = %ld\n", (long) stacksize );
307
308  /* exercise get and set stack address */
309 
310  empty_line();
311 
312  puts( "Init: pthread_attr_setstackaddr - EINVAL (NULL attr)" );
313  status = pthread_attr_setstackaddr( NULL, NULL );
314  assert( status == EINVAL );
315 
316  puts( "Init: pthread_attr_setstackaddr - EINVAL (not initialized attr)" );
317  status =
318     pthread_attr_setstackaddr( &destroyed_attr, NULL );
319  assert( status == EINVAL );
320 
321  puts( "Init: pthread_attr_setstackaddr - SUCCESSFUL" );
322  status = pthread_attr_setstackaddr( &attr, 0 );
323  assert( !status );
324 
325  puts( "Init: pthread_attr_getstackaddr - EINVAL (NULL attr)" );
326  status = pthread_attr_getstackaddr( NULL, &stackaddr );
327  assert( status == EINVAL );
328 
329  puts( "Init: pthread_attr_getstackaddr - EINVAL (NULL stackaddr)" );
330  status = pthread_attr_getstackaddr( &attr, NULL );
331  assert( status == EINVAL );
332 
333  puts( "Init: pthread_attr_getstackaddr - EINVAL (not initialized attr)" );
334  status = pthread_attr_getstackaddr( &destroyed_attr, &stackaddr );
335  assert( status == EINVAL );
336 
337  puts( "Init: pthread_attr_getstackaddr - SUCCESSFUL" );
338  status = pthread_attr_getstackaddr( &attr, &stackaddr );
339  assert( !status );
340  printf( "Init: current stack address attribute = %p\n", stackaddr );
341 
342  /* exercise get and set detach state */
343 
344  empty_line();
345 
346  puts( "Init: pthread_attr_setdetachstate - EINVAL (NULL attr)" );
347  status = pthread_attr_setdetachstate( NULL, PTHREAD_CREATE_DETACHED );
348  assert( status == EINVAL );
349 
350  puts( "Init: pthread_attr_setdetachstate - EINVAL (not initialized attr)" );
351  status =
352     pthread_attr_setdetachstate( &destroyed_attr, PTHREAD_CREATE_JOINABLE );
353  assert( status == EINVAL );
354 
355  puts( "Init: pthread_attr_setdetachstate - EINVAL (invalid detachstate)" );
356  status = pthread_attr_setdetachstate( &attr, -1 );
357  assert( status == EINVAL );
358 
359  puts( "Init: pthread_attr_setdetachstate - SUCCESSFUL" );
360  status = pthread_attr_setdetachstate( &attr, PTHREAD_CREATE_JOINABLE );
361  assert( !status );
362 
363  puts( "Init: pthread_attr_getdetachstate - EINVAL (NULL attr)" );
364  status = pthread_attr_getdetachstate( NULL, &detachstate );
365  assert( status == EINVAL );
366 
367  puts( "Init: pthread_attr_getdetachstate - EINVAL (NULL detatchstate)" );
368  status = pthread_attr_getdetachstate( &attr, NULL );
369  assert( status == EINVAL );
370 
371  puts( "Init: pthread_attr_getdetachstate - EINVAL (not initialized attr)" );
372  status = pthread_attr_getdetachstate( &destroyed_attr, &detachstate );
373  assert( status == EINVAL );
374 
375  puts( "Init: pthread_attr_getdetachstate - SUCCESSFUL" );
376  status = pthread_attr_getdetachstate( &attr, &detachstate );
377  assert( !status );
378  printf( "Init: current detach state attribute = %d\n", detachstate );
379
380  /* exercise get and set scheduling parameters */
381
382  empty_line();
383
384  puts( "Init: pthread_attr_getschedparam - SUCCESSFUL" );
385  status = pthread_attr_getschedparam( &attr, &schedparam );
386  assert( !status );
387
388  print_schedparam( "Init: ", &schedparam );
389
390  puts( "Init: pthread_attr_setschedparam - EINVAL (NULL attr)" );
391  status = pthread_attr_setschedparam( NULL, &schedparam );
392  assert( status == EINVAL );
393 
394  puts( "Init: pthread_attr_setschedparam - EINVAL (not initialized attr)" );
395  status = pthread_attr_setschedparam( &destroyed_attr, &schedparam );
396  assert( status == EINVAL );
397 
398  puts( "Init: pthread_attr_setschedparam - EINVAL (NULL schedparam)" );
399  status = pthread_attr_setschedparam( &attr, NULL );
400  assert( status == EINVAL );
401 
402  puts( "Init: pthread_attr_setschedparam - SUCCESSFUL" );
403  status = pthread_attr_setschedparam( &attr, &schedparam );
404  assert( !status );
405 
406  puts( "Init: pthread_attr_getschedparam - EINVAL (NULL attr)" );
407  status = pthread_attr_getschedparam( NULL, &schedparam );
408  assert( status == EINVAL );
409 
410  puts( "Init: pthread_attr_getschedparam - EINVAL (not initialized attr)" );
411  status = pthread_attr_getschedparam( &destroyed_attr, &schedparam );
412  assert( status == EINVAL );
413 
414  puts( "Init: pthread_attr_getschedparam - EINVAL (NULL schedparam)" );
415  status = pthread_attr_getschedparam( &attr, NULL );
416  assert( status == EINVAL );
417 
418  /* exercise pthread_getschedparam */
419
420  empty_line();
421
422  puts( "Init: pthread_getschedparam - EINVAL (NULL policy)" );
423  status = pthread_getschedparam( pthread_self(), NULL, &schedparam );
424  assert( status == EINVAL );
425 
426  puts( "Init: pthread_getschedparam - EINVAL (NULL schedparam)" );
427  status = pthread_getschedparam( pthread_self(), &schedpolicy, NULL );
428  assert( status == EINVAL );
429 
430  puts( "Init: pthread_getschedparam - ESRCH (bad thread)" );
431  status = pthread_getschedparam( -1, &schedpolicy, &schedparam );
432  assert( status == ESRCH );
433 
434  puts( "Init: pthread_getschedparam - SUCCESSFUL" );
435  status = pthread_getschedparam( pthread_self(), &schedpolicy, &schedparam );
436  assert( !status );
437 
438  printf( "Init: policy = %d\n", schedpolicy );
439
440  print_schedparam( "Init: ", &schedparam );
441
442  /* exercise pthread_setschedparam */
443
444  empty_line();
445
446  puts( "Init: pthread_setschedparam - EINVAL (NULL schedparam)" );
447  status = pthread_setschedparam( pthread_self(), SCHED_OTHER, NULL );
448  assert( status == EINVAL );
449
450  schedparam.sched_priority = -1;
451
452  puts( "Init: pthread_setschedparam - EINVAL (invalid priority)" );
453  status = pthread_setschedparam( pthread_self(), SCHED_OTHER, NULL );
454  assert( status == EINVAL );
455
456  schedparam.sched_priority = 128;
457
458  puts( "Init: pthread_setschedparam - EINVAL (invalid policy)" );
459  status = pthread_setschedparam( pthread_self(), -1, &schedparam );
460  assert( status == EINVAL );
461
462  puts( "Init: pthread_setschedparam - ESRCH (invalid thread)" );
463  status = pthread_setschedparam( -1, SCHED_OTHER, &schedparam );
464  assert( status == ESRCH );
465
466  /* now get sporadic server errors */
467
468  schedparam.ss_replenish_period.tv_sec = 1;
469  schedparam.ss_replenish_period.tv_nsec = 0;
470  schedparam.ss_initial_budget.tv_sec = 1;
471  schedparam.ss_initial_budget.tv_nsec = 1;
472
473  puts( "Init: pthread_setschedparam - EINVAL (replenish < budget)" );
474  status = pthread_setschedparam( pthread_self(), SCHED_SPORADIC, &schedparam );
475  assert( status == EINVAL );
476
477  schedparam.ss_replenish_period.tv_sec = 2;
478  schedparam.ss_replenish_period.tv_nsec = 0;
479  schedparam.ss_initial_budget.tv_sec = 1;
480  schedparam.ss_initial_budget.tv_nsec = 0;
481  schedparam.ss_low_priority = -1;
482
483  puts( "Init: pthread_setschedparam - EINVAL (invalid priority)" );
484  status = pthread_setschedparam( pthread_self(), SCHED_SPORADIC, &schedparam );
485  assert( status == EINVAL );
486
487  puts( "*** END OF POSIX TEST 7 ***" );
488  exit( 0 );
489
490  return NULL; /* just so the compiler thinks we returned something */
491}
Note: See TracBrowser for help on using the repository browser.