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

4.104.114.84.95
Last change on this file since 221bd65 was 221bd65, checked in by Joel Sherrill <joel.sherrill@…>, on 08/12/96 at 20:00:02

added test case for stack too large

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