OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [rtems-20020807/] [c/] [src/] [tests/] [psxtests/] [psx07/] [init.c] - Blame information for rev 1026

Go to most recent revision | Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.