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

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

added test case for pthread_attr_getscope being passed a NULL contentionscope

  • Property mode set to 100644
File size: 15.9 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 (not initialized attr)" );
220  status = pthread_attr_getinheritsched( &destroyed_attr, &inheritsched );
221  assert( status == EINVAL );
222 
223  puts( "Init: pthread_attr_getinheritsched - SUCCESSFUL" );
224  status = pthread_attr_getinheritsched( &attr, &inheritsched );
225  assert( !status );
226  printf( "Init: current inherit scheduler attribute = %d\n", inheritsched );
227
228  /* exercise get and set inherit scheduler */
229 
230  empty_line();
231 
232  puts( "Init: pthread_attr_setschedpolicy - EINVAL (NULL attr)" );
233  status = pthread_attr_setschedpolicy( NULL, SCHED_FIFO );
234  assert( status == EINVAL );
235 
236  puts( "Init: pthread_attr_setschedpolicy - EINVAL (not initialized attr)" );
237  status =
238     pthread_attr_setschedpolicy( &destroyed_attr, SCHED_OTHER );
239  assert( status == EINVAL );
240 
241  puts( "Init: pthread_attr_setschedpolicy - EINVAL (invalid schedpolicy)" );
242  status = pthread_attr_setschedpolicy( &attr, -1 );
243  assert( status == EINVAL );
244 
245  puts( "Init: pthread_attr_setschedpolicy - SUCCESSFUL" );
246  status = pthread_attr_setschedpolicy( &attr, SCHED_RR );
247  assert( !status );
248 
249  puts( "Init: pthread_attr_getschedpolicy - EINVAL (NULL attr)" );
250  status = pthread_attr_getschedpolicy( NULL, &schedpolicy );
251  assert( status == EINVAL );
252 
253  puts( "Init: pthread_attr_getschedpolicy - EINVAL (not initialized attr)" );
254  status = pthread_attr_getschedpolicy( &destroyed_attr, &schedpolicy );
255  assert( status == EINVAL );
256 
257  puts( "Init: pthread_attr_getschedpolicy - SUCCESSFUL" );
258  status = pthread_attr_getschedpolicy( &attr, &schedpolicy );
259  assert( !status );
260  printf( "Init: current scheduler policy attribute = %d\n", schedpolicy );
261 
262  /* exercise get and set stack size */
263 
264  empty_line();
265 
266  puts( "Init: pthread_attr_setstacksize - EINVAL (NULL attr)" );
267  status = pthread_attr_setstacksize( NULL, 0 );
268  assert( status == EINVAL );
269 
270  puts( "Init: pthread_attr_setstacksize - EINVAL (not initialized attr)" );
271  status =
272     pthread_attr_setstacksize( &destroyed_attr, 0 );
273  assert( status == EINVAL );
274 
275  puts( "Init: pthread_attr_setstacksize - SUCCESSFUL (low stacksize)" );
276  status = pthread_attr_setstacksize( &attr, 0 );
277  assert( !status );
278
279  puts( "Init: pthread_attr_setstacksize - SUCCESSFUL (high stacksize)" );
280  status = pthread_attr_setstacksize( &attr, STACK_MINIMUM_SIZE * 2 );
281  assert( !status );
282 
283  puts( "Init: pthread_attr_getstacksize - EINVAL (NULL attr)" );
284  status = pthread_attr_getstacksize( NULL, &stacksize );
285  assert( status == EINVAL );
286 
287  puts( "Init: pthread_attr_getstacksize - EINVAL (not initialized attr)" );
288  status = pthread_attr_getstacksize( &destroyed_attr, &stacksize );
289  assert( status == EINVAL );
290 
291  puts( "Init: pthread_attr_getstacksize - SUCCESSFUL" );
292  status = pthread_attr_getstacksize( &attr, &stacksize );
293  assert( !status );
294  printf( "Init: current stack size attribute = %ld\n", (long) stacksize );
295
296  /* exercise get and set stack address */
297 
298  empty_line();
299 
300  puts( "Init: pthread_attr_setstackaddr - EINVAL (NULL attr)" );
301  status = pthread_attr_setstackaddr( NULL, NULL );
302  assert( status == EINVAL );
303 
304  puts( "Init: pthread_attr_setstackaddr - EINVAL (not initialized attr)" );
305  status =
306     pthread_attr_setstackaddr( &destroyed_attr, NULL );
307  assert( status == EINVAL );
308 
309  puts( "Init: pthread_attr_setstackaddr - SUCCESSFUL" );
310  status = pthread_attr_setstackaddr( &attr, 0 );
311  assert( !status );
312 
313  puts( "Init: pthread_attr_getstackaddr - EINVAL (NULL attr)" );
314  status = pthread_attr_getstackaddr( NULL, &stackaddr );
315  assert( status == EINVAL );
316 
317  puts( "Init: pthread_attr_getstackaddr - EINVAL (not initialized attr)" );
318  status = pthread_attr_getstackaddr( &destroyed_attr, &stackaddr );
319  assert( status == EINVAL );
320 
321  puts( "Init: pthread_attr_getstackaddr - SUCCESSFUL" );
322  status = pthread_attr_getstackaddr( &attr, &stackaddr );
323  assert( !status );
324  printf( "Init: current stack address attribute = %p\n", stackaddr );
325 
326  /* exercise get and set detach state */
327 
328  empty_line();
329 
330  puts( "Init: pthread_attr_setdetachstate - EINVAL (NULL attr)" );
331  status = pthread_attr_setdetachstate( NULL, PTHREAD_CREATE_DETACHED );
332  assert( status == EINVAL );
333 
334  puts( "Init: pthread_attr_setdetachstate - EINVAL (not initialized attr)" );
335  status =
336     pthread_attr_setdetachstate( &destroyed_attr, PTHREAD_CREATE_JOINABLE );
337  assert( status == EINVAL );
338 
339  puts( "Init: pthread_attr_setdetachstate - EINVAL (invalid detachstate)" );
340  status = pthread_attr_setdetachstate( &attr, -1 );
341  assert( status == EINVAL );
342 
343  puts( "Init: pthread_attr_setdetachstate - SUCCESSFUL" );
344  status = pthread_attr_setdetachstate( &attr, PTHREAD_CREATE_JOINABLE );
345  assert( !status );
346 
347  puts( "Init: pthread_attr_getdetachstate - EINVAL (NULL attr)" );
348  status = pthread_attr_getdetachstate( NULL, &detachstate );
349  assert( status == EINVAL );
350 
351  puts( "Init: pthread_attr_getdetachstate - EINVAL (not initialized attr)" );
352  status = pthread_attr_getdetachstate( &destroyed_attr, &detachstate );
353  assert( status == EINVAL );
354 
355  puts( "Init: pthread_attr_getdetachstate - SUCCESSFUL" );
356  status = pthread_attr_getdetachstate( &attr, &detachstate );
357  assert( !status );
358  printf( "Init: current detach state attribute = %d\n", detachstate );
359
360  /* exercise get and set scheduling parameters */
361
362  empty_line();
363
364  puts( "Init: pthread_attr_getschedparam - SUCCESSFUL" );
365  status = pthread_attr_getschedparam( &attr, &schedparam );
366  assert( !status );
367
368  print_schedparam( "Init: ", &schedparam );
369
370  puts( "Init: pthread_attr_setschedparam - EINVAL (NULL attr)" );
371  status = pthread_attr_setschedparam( NULL, &schedparam );
372  assert( status == EINVAL );
373 
374  puts( "Init: pthread_attr_setschedparam - EINVAL (not initialized attr)" );
375  status = pthread_attr_setschedparam( &destroyed_attr, &schedparam );
376  assert( status == EINVAL );
377 
378  puts( "Init: pthread_attr_setschedparam - EINVAL (NULL schedparam)" );
379  status = pthread_attr_setschedparam( &attr, NULL );
380  assert( status == EINVAL );
381 
382  puts( "Init: pthread_attr_setschedparam - SUCCESSFUL" );
383  status = pthread_attr_setschedparam( &attr, &schedparam );
384  assert( !status );
385 
386  puts( "Init: pthread_attr_getschedparam - EINVAL (NULL attr)" );
387  status = pthread_attr_getschedparam( NULL, &schedparam );
388  assert( status == EINVAL );
389 
390  puts( "Init: pthread_attr_getschedparam - EINVAL (not initialized attr)" );
391  status = pthread_attr_getschedparam( &destroyed_attr, &schedparam );
392  assert( status == EINVAL );
393 
394  puts( "Init: pthread_attr_getschedparam - EINVAL (NULL schedparam)" );
395  status = pthread_attr_getschedparam( &attr, NULL );
396  assert( status == EINVAL );
397 
398  /* exercise pthread_getschedparam */
399
400  empty_line();
401
402  puts( "Init: pthread_getschedparam - EINVAL (NULL policy)" );
403  status = pthread_getschedparam( pthread_self(), NULL, &schedparam );
404  assert( status == EINVAL );
405 
406  puts( "Init: pthread_getschedparam - EINVAL (NULL schedparam)" );
407  status = pthread_getschedparam( pthread_self(), &schedpolicy, NULL );
408  assert( status == EINVAL );
409 
410  puts( "Init: pthread_getschedparam - ESRCH (bad thread)" );
411  status = pthread_getschedparam( -1, &schedpolicy, &schedparam );
412  assert( status == ESRCH );
413 
414  puts( "Init: pthread_getschedparam - SUCCESSFUL" );
415  status = pthread_getschedparam( pthread_self(), &schedpolicy, &schedparam );
416  assert( !status );
417 
418  printf( "Init: policy = %d\n", schedpolicy );
419
420  print_schedparam( "Init: ", &schedparam );
421
422  /* exercise pthread_setschedparam */
423
424  empty_line();
425
426  puts( "Init: pthread_setschedparam - EINVAL (NULL schedparam)" );
427  status = pthread_setschedparam( pthread_self(), SCHED_OTHER, NULL );
428  assert( status == EINVAL );
429
430  schedparam.sched_priority = -1;
431
432  puts( "Init: pthread_setschedparam - EINVAL (invalid priority)" );
433  status = pthread_setschedparam( pthread_self(), SCHED_OTHER, NULL );
434  assert( status == EINVAL );
435
436  schedparam.sched_priority = 128;
437
438  puts( "Init: pthread_setschedparam - EINVAL (invalid policy)" );
439  status = pthread_setschedparam( pthread_self(), -1, &schedparam );
440  assert( status == EINVAL );
441
442  puts( "Init: pthread_setschedparam - ESRCH (invalid thread)" );
443  status = pthread_setschedparam( -1, SCHED_OTHER, &schedparam );
444  assert( status == ESRCH );
445
446  /* now get sporadic server errors */
447
448  schedparam.ss_replenish_period.tv_sec = 1;
449  schedparam.ss_replenish_period.tv_nsec = 0;
450  schedparam.ss_initial_budget.tv_sec = 1;
451  schedparam.ss_initial_budget.tv_nsec = 1;
452
453  puts( "Init: pthread_setschedparam - EINVAL (replenish < budget)" );
454  status = pthread_setschedparam( pthread_self(), SCHED_SPORADIC, &schedparam );
455  assert( status == EINVAL );
456
457  schedparam.ss_replenish_period.tv_sec = 2;
458  schedparam.ss_replenish_period.tv_nsec = 0;
459  schedparam.ss_initial_budget.tv_sec = 1;
460  schedparam.ss_initial_budget.tv_nsec = 0;
461  schedparam.ss_low_priority = -1;
462
463  puts( "Init: pthread_setschedparam - EINVAL (invalid priority)" );
464  status = pthread_setschedparam( pthread_self(), SCHED_SPORADIC, &schedparam );
465  assert( status == EINVAL );
466
467  puts( "*** END OF POSIX TEST 7 ***" );
468  exit( 0 );
469
470  return NULL; /* just so the compiler thinks we returned something */
471}
Note: See TracBrowser for help on using the repository browser.