source: rtems/testsuites/psxtests/psx05/init.c @ 39615f4

4.104.115
Last change on this file since 39615f4 was 39615f4, checked in by Ralf Corsepius <ralf.corsepius@…>, on 10/27/09 at 14:10:54

Use PRIxpthread_t to print pthread_t's.

  • Property mode set to 100644
File size: 20.1 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.com/license/LICENSE.
8 *
9 *  $Id$
10 */
11
12#include <sched.h>
13
14#define CONFIGURE_INIT
15#include "system.h"
16#include <errno.h>
17#include <rtems/posix/priority.h>
18
19#define MUTEX_BAD_ID 0xfffffffe
20
21void Print_mutexattr(
22  char                *msg,
23  pthread_mutexattr_t *attr
24);
25
26void calculate_abstimeout(
27  struct timespec *times,
28  uint32_t         seconds,
29  uint32_t         nanoseconds
30);
31
32void Print_mutexattr(
33  char                *msg,
34  pthread_mutexattr_t *attr
35)
36{
37  int status;
38  int protocol;
39  int prioceiling;
40  int pshared;
41
42  /* protocol */
43
44  status = pthread_mutexattr_getprotocol( attr, &protocol );
45  assert( !status );
46
47  printf( "%smutex protocol is (%d) -- ", msg, protocol );
48  switch ( protocol ) {
49    case PTHREAD_PRIO_NONE:
50      puts( "PTHREAD_PRIO_NONE" );
51      break;
52    case PTHREAD_PRIO_INHERIT:
53      puts( "PTHREAD_PRIO_INHERIT" );
54      break;
55    case PTHREAD_PRIO_PROTECT:
56      puts( "PTHREAD_PRIO_PROTECT" );
57      break;
58    default:
59      puts( "UNKNOWN" );
60      assert( 0 );
61      break;
62  }
63
64  /* priority ceiling */
65
66  status = pthread_mutexattr_getprioceiling( attr, &prioceiling );
67  assert( !status );
68  printf( "%smutex priority ceiling is %d\n", msg, prioceiling );
69
70  /* process shared */
71
72  status = pthread_mutexattr_getpshared( attr, &pshared );
73  assert( !status );
74  printf( "%smutex process shared is (%d) -- ", msg, pshared );
75  switch ( pshared ) {
76    case PTHREAD_PROCESS_PRIVATE:
77      puts( "PTHREAD_PROCESS_PRIVATE" );
78      break;
79    case PTHREAD_PROCESS_SHARED:
80      puts( "PTHREAD_PROCESS_SHARED" );
81      break;
82    default:
83      puts( "UNKNOWN" );
84      assert( 0 );
85      break;
86  }
87}
88
89void calculate_abstimeout(
90  struct timespec *times,
91  uint32_t         seconds,
92  uint32_t         nanoseconds
93)
94{
95  struct timeval       tv1;
96  struct timezone      tz1;
97
98  gettimeofday( &tv1, &tz1 );
99
100  times->tv_sec  = seconds     + tv1.tv_sec;
101  times->tv_nsec = nanoseconds + (tv1.tv_usec * 1000);
102
103  while ( times->tv_nsec >= TOD_NANOSECONDS_PER_SECOND ) {
104    times->tv_sec++;
105    times->tv_nsec -= TOD_NANOSECONDS_PER_SECOND;
106  }
107
108}
109
110void *POSIX_Init(
111  void *argument
112)
113{
114  int                  status;
115  pthread_mutexattr_t  attr;
116  pthread_mutexattr_t  destroyed_attr;
117  struct timespec      times;
118  struct sched_param   param;
119  int                  pshared;
120  int                  policy;
121  int                  protocol;
122  int                  ceiling;
123  int                  old_ceiling;
124  int                  priority;
125
126  assert( MUTEX_BAD_ID != PTHREAD_MUTEX_INITIALIZER );
127  Mutex_bad_id = MUTEX_BAD_ID;
128
129  puts( "\n\n*** POSIX TEST 5 ***" );
130
131  /* set the time of day, and print our buffer in multiple ways */
132
133  set_time( TM_FRIDAY, TM_MAY, 24, 96, 11, 5, 0 );
134
135  /* get id of this thread */
136
137  Init_id = pthread_self();
138  printf( "Init's ID is 0x%08" PRIxpthread_t "\n", Init_id );
139
140  /* tes pthread_mutex_attr_init */
141
142  puts( "Init: pthread_mutexattr_init - EINVAL (NULL attr)" );
143  status = pthread_mutexattr_init( NULL );
144  assert( status == EINVAL );
145
146  puts( "Init: pthread_mutexattr_init - SUCCESSFUL" );
147  status = pthread_mutexattr_init( &attr );
148  assert( !status );
149
150  Print_mutexattr( "Init: ", &attr );
151
152  /* create an "uninitialized" attribute structure */
153
154  status = pthread_mutexattr_init( &destroyed_attr );
155  assert( !status );
156
157  puts( "Init: pthread_mutexattr_destroy - SUCCESSFUL" );
158  status = pthread_mutexattr_destroy( &destroyed_attr );
159  assert( !status );
160
161  puts( "Init: pthread_mutexattr_destroy - EINVAL (NULL attr)" );
162  status = pthread_mutexattr_destroy( NULL );
163  assert( status == EINVAL );
164
165  puts( "Init: pthread_mutexattr_destroy - EINVAL (not initialized)" );
166  status = pthread_mutexattr_destroy( &destroyed_attr );
167  assert( status == EINVAL );
168
169  /* error cases for set and get pshared attribute */
170
171  empty_line();
172
173  puts( "Init: pthread_mutexattr_getpshared - EINVAL (NULL attr)" );
174  status = pthread_mutexattr_getpshared( NULL, &pshared );
175  assert( status == EINVAL );
176
177  puts( "Init: pthread_mutexattr_getpshared - EINVAL (NULL pshared)" );
178  status = pthread_mutexattr_getpshared( &attr, NULL );
179  assert( status == EINVAL );
180
181  puts( "Init: pthread_mutexattr_getpshared - EINVAL (not initialized)" );
182  status = pthread_mutexattr_getpshared( &destroyed_attr, &pshared );
183  assert( status == EINVAL );
184
185  pshared = PTHREAD_PROCESS_PRIVATE;
186  puts( "Init: pthread_mutexattr_setpshared - EINVAL (NULL attr)" );
187  status = pthread_mutexattr_setpshared( NULL, pshared );
188  assert( status == EINVAL );
189
190  pshared = PTHREAD_PROCESS_PRIVATE;
191  puts( "Init: pthread_mutexattr_setpshared - EINVAL (not initialized)" );
192  status = pthread_mutexattr_setpshared( &destroyed_attr, pshared );
193  assert( status == EINVAL );
194
195  /* error cases for set and get protocol attribute */
196
197  empty_line();
198
199  puts( "Init: pthread_mutexattr_getprotocol - EINVAL (NULL attr)" );
200  status = pthread_mutexattr_getprotocol( NULL, &protocol );
201  assert( status == EINVAL );
202
203  puts( "Init: pthread_mutexattr_getprotocol - EINVAL (NULL protocol)" );
204  status = pthread_mutexattr_getprotocol( &attr, NULL );
205  assert( status == EINVAL );
206
207  puts( "Init: pthread_mutexattr_getprotocol - EINVAL (not initialized)" );
208  status = pthread_mutexattr_getprotocol( &destroyed_attr, &protocol );
209  assert( status == EINVAL );
210
211  puts( "Init: pthread_mutexattr_setprotocol - EINVAL (NULL attr)" );
212  status = pthread_mutexattr_setprotocol( NULL, PTHREAD_PRIO_NONE );
213  assert( status == EINVAL );
214
215  puts( "Init: pthread_mutexattr_setprotocol - EINVAL (invalid protocol)" );
216  status = pthread_mutexattr_setprotocol( &attr, -1 );
217  assert( status == EINVAL );
218
219  puts( "Init: pthread_mutexattr_setprotocol - EINVAL (not initialized)" );
220  status = pthread_mutexattr_setprotocol( &destroyed_attr, -1 );
221  assert( status == EINVAL );
222
223  /* error cases for set and get prioceiling attribute */
224
225  empty_line();
226
227  puts( "Init: pthread_mutexattr_getprioceiling - EINVAL (NULL attr)" );
228  status = pthread_mutexattr_getprioceiling( NULL, &ceiling );
229  assert( status == EINVAL );
230
231  puts( "Init: pthread_mutexattr_getprioceiling - EINVAL (NULL prioceiling)" );
232  status = pthread_mutexattr_getprioceiling( &attr, NULL );
233  assert( status == EINVAL );
234
235  puts( "Init: pthread_mutexattr_getprioceiling - EINVAL (not initialized)" );
236  status = pthread_mutexattr_getprioceiling( &destroyed_attr, &ceiling );
237  assert( status == EINVAL );
238
239  puts( "Init: pthread_mutexattr_setprioceiling - EINVAL (NULL attr)" );
240  status = pthread_mutexattr_setprioceiling( NULL, 128 );
241  assert( status == EINVAL );
242
243  puts( "Init: pthread_mutexattr_setprioceiling - EINVAL (invalid priority)" );
244  status = pthread_mutexattr_setprioceiling( &attr, 512 );
245  if ( status != EINVAL )
246    printf( "status = %d\n", status );
247  assert( status == EINVAL );
248
249  puts( "Init: pthread_mutexattr_setprioceiling - EINVAL (not initialized)" );
250  status = pthread_mutexattr_setprioceiling( &destroyed_attr, -1 );
251  assert( status == EINVAL );
252
253  /* create a thread */
254
255  status = pthread_create( &Task_id, NULL, Task_1, NULL );
256  assert( !status );
257
258  /* now try some basic mutex operations */
259
260  empty_line();
261
262  puts( "Init: pthread_mutex_init - EINVAL (NULL mutex_id)" );
263  status = pthread_mutex_init( NULL, &attr );
264  assert( status == EINVAL );
265
266  puts( "Init: pthread_mutex_init - EINVAL (not initialized attr)" );
267  status = pthread_mutex_init( &Mutex_id, &destroyed_attr );
268  assert( status == EINVAL );
269
270  /* must get around error checks in attribute set routines */
271  attr.protocol = -1;
272
273  puts( "Init: pthread_mutex_init - EINVAL (bad protocol)" );
274  status = pthread_mutex_init( &Mutex_id, &attr );
275  assert( status == EINVAL );
276
277  /* must get around error checks in attribute set routines */
278  attr.protocol = PTHREAD_PRIO_INHERIT;
279  attr.prio_ceiling = -1;
280
281  puts( "Init: pthread_mutex_init - EINVAL (bad priority ceiling)" );
282  status = pthread_mutex_init( &Mutex_id, &attr );
283  assert( status == EINVAL );
284
285  /* must get around various error checks before checking bad scope */
286  puts( "Init: Resetting mutex attributes" );
287  status = pthread_mutexattr_init( &attr );
288  assert( !status );
289
290  puts( "Init: pthread_mutex_init - ENOSYS (process wide scope)" );
291  attr.process_shared = PTHREAD_PROCESS_SHARED;
292  status = pthread_mutex_init( &Mutex_id, &attr );
293  assert( status == ENOSYS );
294
295  puts( "Init: pthread_mutex_init - EINVAL (invalid scope)" );
296  attr.process_shared = -1;
297  status = pthread_mutex_init( &Mutex_id, &attr );
298  assert( status == EINVAL );
299
300  /* bad kind */
301  status = pthread_mutexattr_init( &attr );
302  assert( !status );
303
304  puts( "Init: pthread_mutex_init - EINVAL (invalid type)" );
305  attr.type = -1;
306  status = pthread_mutex_init( &Mutex_id, &attr );
307  assert( status == EINVAL );
308
309  /* now set up for a success pthread_mutex_init */
310
311  puts( "Init: Resetting mutex attributes" );
312  status = pthread_mutexattr_init( &attr );
313  assert( !status );
314
315  puts( "Init: Changing mutex attributes" );
316  status = pthread_mutexattr_setprotocol( &attr, PTHREAD_PRIO_INHERIT );
317  assert( !status );
318
319  status = pthread_mutexattr_setprioceiling(
320    &attr,
321    (sched_get_priority_max(SCHED_FIFO) / 2) + 1
322  );
323  assert( !status );
324
325  status = pthread_mutexattr_setpshared( &attr, PTHREAD_PROCESS_SHARED );
326  assert( !status );
327
328  Print_mutexattr( "Init: ", &attr );
329
330  puts( "Init: Resetting mutex attributes" );
331  status = pthread_mutexattr_init( &attr );
332  assert( !status );
333
334  /*
335   *  Set the protocol to priority ceiling so the owner check happens
336   *  and the EPERM test (later) will work.
337   */
338
339  status = pthread_mutexattr_setprotocol( &attr, PTHREAD_PRIO_INHERIT );
340  assert( !status );
341
342  puts( "Init: pthread_mutex_init - SUCCESSFUL" );
343  status = pthread_mutex_init( &Mutex_id, &attr );
344  if ( status )
345    printf( "status = %d\n", status );
346  assert( !status );
347
348  /*
349   *  This is not required to be an error and when it is, there are
350   *  behavioral conflicts with other implementations.
351   */
352  puts( "Init: pthread_mutex_init - EBUSY (reinitialize an existing mutex) - skipped" );
353
354#if 0
355  status = pthread_mutex_init( &Mutex_id, &attr );
356  if ( !status )
357    printf( "status = %d\n", status );
358  assert( status == EBUSY );
359#endif
360
361  puts( "Init: pthread_mutex_trylock - EINVAL (illegal ID)" );
362  status = pthread_mutex_trylock( &Mutex_bad_id );
363  if ( status != EINVAL )
364    printf( "status = %d\n", status );
365  assert( status == EINVAL );
366
367  puts( "Init: pthread_mutex_trylock - SUCCESSFUL" );
368  status = pthread_mutex_trylock( &Mutex_id );
369  if ( status )
370    printf( "status = %d\n", status );
371  assert( !status );
372
373  puts( "Init: pthread_mutex_trylock - EDEADLK (already locked)" );
374  status = pthread_mutex_trylock( &Mutex_id );
375  if ( status != EDEADLK )
376    printf( "status = %d\n", status );
377  assert( status == EDEADLK );
378
379  puts( "Init: pthread_mutex_lock - EINVAL (NULL id)" );
380  status = pthread_mutex_lock( NULL );
381  if ( status != EINVAL )
382    printf( "status = %d\n", status );
383  assert( status == EINVAL );
384
385  puts( "Init: pthread_mutex_unlock - EINVAL (NULL id)" );
386  status = pthread_mutex_unlock( NULL );
387  if ( status != EINVAL )
388    printf( "status = %d\n", status );
389  assert( status == EINVAL );
390
391  puts( "Init: pthread_mutex_lock - EDEADLK (already locked)" );
392  status = pthread_mutex_lock( &Mutex_id );
393  if ( status != EDEADLK )
394    printf( "status = %d\n", status );
395  assert( status == EDEADLK );
396
397  puts( "Init: Sleep 1 second" );
398
399  sleep( 1 );
400
401     /* switch to task 1 */
402
403  puts( "Init: pthread_mutex_unlock - EINVAL (invalid id)" );
404  status = pthread_mutex_unlock( &Mutex_bad_id );
405  if ( status != EINVAL )
406    printf( "status = %d\n", status );
407  assert( status == EINVAL );
408
409  puts( "Init: pthread_mutex_unlock - SUCCESSFUL" );
410  status = pthread_mutex_unlock( &Mutex_id );
411  if ( status )
412    printf( "status = %d\n", status );
413  assert( !status );
414
415  puts( "Init: pthread_mutex_unlock - EPERM (not owner)" );
416  status = pthread_mutex_unlock( &Mutex_id );
417  if ( status != EPERM )
418    printf( "status = %d\n", status );
419  assert( status == EPERM );
420
421  puts( "Init: pthread_mutex_timedlock - time out in 1/2 second" );
422  calculate_abstimeout( &times, 0, (TOD_NANOSECONDS_PER_SECOND / 2) );
423
424  status = pthread_mutex_timedlock( &Mutex_id, &times );
425  if ( status != ETIMEDOUT )
426    printf( "status = %d\n", status );
427  assert( status == ETIMEDOUT );
428
429  puts( "Init: pthread_mutex_timedlock - time out in the past" );
430  calculate_abstimeout( &times, -1, (TOD_NANOSECONDS_PER_SECOND / 2) );
431
432  status = pthread_mutex_timedlock( &Mutex_id, &times );
433  if ( status != EBUSY )
434    printf( "status = %d\n", status );
435  assert( status == EBUSY );
436
437     /* switch to idle */
438
439  puts( "Init: pthread_mutex_timedlock - EAGAIN (timeout)" );
440
441  /* destroy a mutex */
442
443  empty_line();
444
445  puts( "Init: pthread_mutex_init - SUCCESSFUL" );
446  status = pthread_mutex_init( &Mutex2_id, &attr );
447  if ( status )
448    printf( "status = %d\n", status );
449  assert( !status );
450
451  puts( "Init: pthread_mutex_init - EAGAIN (too many)" );
452  status = pthread_mutex_init( &Mutex3_id, &attr );
453  assert( status == EAGAIN );
454
455  puts( "Init: pthread_mutexattr_destroy - SUCCESSFUL" );
456  status = pthread_mutexattr_destroy( &attr );
457  assert( !status );
458
459  puts( "Init: pthread_mutex_destroy - SUCCESSFUL" );
460  status = pthread_mutex_destroy( &Mutex2_id );
461  assert( !status );
462
463  puts( "Init: pthread_mutex_destroy - EINVAL (invalid id)" );
464  status = pthread_mutex_destroy( &Mutex_bad_id );
465  assert( status == EINVAL );
466
467  /* destroy a busy mutex */
468
469  empty_line();
470
471  puts( "Init: pthread_mutexattr_init - SUCCESSFUL" );
472  status = pthread_mutexattr_init( &attr );
473  assert( !status );
474
475  puts( "Init: pthread_mutex_init - SUCCESSFUL" );
476  status = pthread_mutex_init( &Mutex2_id, &attr );
477  assert( !status );
478
479  puts( "Init: pthread_mutex_trylock - SUCCESSFUL" );
480  status = pthread_mutex_trylock( &Mutex2_id );
481  if ( status )
482    printf( "status = %d\n", status );
483  assert( !status );
484
485  puts( "Init: pthread_mutex_destroy - EBUSY (already locked)" );
486  status = pthread_mutex_destroy( &Mutex2_id );
487  if ( status != EBUSY )
488    printf( "status = %d\n", status );
489  assert( status == EBUSY );
490
491  puts( "Init: pthread_mutex_unlock - SUCCESSFUL" );
492  status = pthread_mutex_unlock( &Mutex2_id );
493  assert( !status );
494
495  puts( "Init: pthread_mutex_destroy - SUCCESSFUL" );
496  status = pthread_mutex_destroy( &Mutex2_id );
497  assert( !status );
498
499  /* priority inherit mutex */
500
501  empty_line();
502
503  puts( "Init: pthread_mutexattr_init - SUCCESSFUL" );
504  status = pthread_mutexattr_init( &attr );
505  assert( !status );
506
507  puts(
508    "Init: pthread_mutexattr_setprotocol - SUCCESSFUL (PTHREAD_PRIO_INHERIT)"
509  );
510  status = pthread_mutexattr_setprotocol( &attr, PTHREAD_PRIO_INHERIT );
511  assert( !status );
512
513  puts( "Init: pthread_mutex_init - SUCCESSFUL" );
514  status = pthread_mutex_init( &Mutex2_id, &attr );
515  assert( !status );
516
517  puts( "Init: pthread_mutex_trylock - SUCCESSFUL" );
518  status = pthread_mutex_trylock( &Mutex2_id );
519  assert( !status );
520
521  /* create a thread at a lower priority */
522
523  status = pthread_create( &Task2_id, NULL, Task_2, NULL );
524  assert( !status );
525
526  /* set priority of Task2 to highest priority */
527
528  param.sched_priority = sched_get_priority_max( SCHED_FIFO );
529
530  puts( "Init: pthread_setschedparam - Setting Task2 priority to highest" );
531  status = pthread_setschedparam( Task2_id, SCHED_FIFO, &param );
532  assert( !status );
533
534  /* switching to Task2 */
535
536  status = pthread_getschedparam( pthread_self(), &policy, &param );
537  assert( !status );
538  printf( "Init: pthread_getschedparam - priority = %d\n", param.sched_priority);
539
540  puts( "Init: pthread_mutex_unlock - SUCCESSFUL" );
541  status = pthread_mutex_unlock( &Mutex2_id );
542  assert( !status );
543
544  puts( "Init: pthread_mutexattr_destroy - SUCCESSFUL" );
545  status = pthread_mutexattr_destroy( &attr );
546  assert( !status );
547
548  puts( "Init: pthread_mutex_destroy - SUCCESSFUL" );
549  status = pthread_mutex_destroy( &Mutex2_id );
550  assert( !status );
551
552  /* priority ceiling mutex */
553
554  empty_line();
555
556  puts( "Init: pthread_mutexattr_init - SUCCESSFUL" );
557  status = pthread_mutexattr_init( &attr );
558  assert( !status );
559
560  puts(
561    "Init: pthread_mutexattr_setprotocol - SUCCESSFUL (PTHREAD_PRIO_PROTECT)"
562  );
563  status = pthread_mutexattr_setprotocol( &attr, PTHREAD_PRIO_PROTECT );
564  assert( !status );
565
566  puts( "Init: pthread_mutex_init - SUCCESSFUL" );
567  status = pthread_mutex_init( &Mutex2_id, &attr );
568  assert( !status );
569
570  puts( "Init: pthread_mutex_getprioceiling - EINVAL (invalid id)" );
571  status = pthread_mutex_getprioceiling( &Mutex_bad_id, &ceiling );
572  assert( status == EINVAL );
573
574  puts( "Init: pthread_mutex_getprioceiling - EINVAL (NULL ceiling)" );
575  status = pthread_mutex_getprioceiling( &Mutex2_id, NULL );
576  assert( status == EINVAL );
577
578  status = pthread_mutex_getprioceiling( &Mutex2_id, &ceiling );
579  assert( !status );
580  printf( "Init: pthread_mutex_getprioceiling - %d\n", ceiling );
581
582  puts( "Init: pthread_mutex_setprioceiling - EINVAL (invalid id)" );
583  status = pthread_mutex_setprioceiling( &Mutex_bad_id, 200, &old_ceiling );
584  assert( status == EINVAL );
585
586  puts( "Init: pthread_mutex_setprioceiling - EINVAL (illegal priority)" );
587  status = pthread_mutex_setprioceiling( &Mutex2_id, 512, &old_ceiling );
588  assert( status == EINVAL );
589
590  puts( "Init: pthread_mutex_setprioceiling - EINVAL (NULL ceiling)" );
591  status = pthread_mutex_setprioceiling( &Mutex2_id, 128, NULL );
592  assert( status == EINVAL );
593
594  /* normal cases of set priority ceiling */
595
596  priority = sched_get_priority_max( SCHED_FIFO );
597  priority = (priority == 254) ? 200 : 13;
598 
599  printf( "Init: pthread_mutex_setprioceiling - new ceiling = %d\n", priority );
600  status = pthread_mutex_setprioceiling( &Mutex2_id, priority, &old_ceiling );
601  assert( !status );
602  printf(
603    "Init: pthread_mutex_setprioceiling - old ceiling = %d\n",old_ceiling
604  );
605
606  status = pthread_getschedparam( pthread_self(), &policy, &param );
607  assert( !status );
608  printf(
609    "Init: pthread_getschedparam - priority = %d\n", param.sched_priority
610  );
611
612  puts( "Init: pthread_mutex_trylock - SUCCESSFUL" );
613  status = pthread_mutex_trylock( &Mutex2_id );
614  assert( !status );
615
616  status = pthread_getschedparam( pthread_self(), &policy, &param );
617  assert( !status );
618  printf(
619    "Init: pthread_getschedparam - priority = %d\n", param.sched_priority
620  );
621
622  /* create a thread at a higher priority */
623
624  status = pthread_create( &Task3_id, NULL, Task_3, NULL );
625  assert( !status );
626
627  /* set priority of Task3 to highest priority */
628
629  param.sched_priority = --priority;
630
631  status = pthread_setschedparam( Task3_id, SCHED_FIFO, &param );
632  assert( !status );
633  puts( "Init: pthread_setschedparam - set Task3 priority to highest" );
634
635  /* DOES NOT SWITCH to Task3 */
636
637  puts( "Init: Sleep 1 second" );
638  assert( !status );
639  sleep( 1 );
640
641  /* switch to task 3 */
642
643  puts( "Init: pthread_mutex_unlock - SUCCESSFUL" );
644  status = pthread_mutex_unlock( &Mutex2_id );
645  assert( !status );
646
647  status = pthread_mutex_getprioceiling( &Mutex2_id, &ceiling );
648  assert( !status );
649  printf( "Init: pthread_mutex_getprioceiling- ceiling = %d\n", ceiling );
650
651  /* set priority of Init to highest priority */
652
653  param.sched_priority = sched_get_priority_max(SCHED_FIFO);
654
655  status = pthread_setschedparam( Init_id, SCHED_FIFO, &param );
656  assert( !status );
657  puts( "Init: pthread_setschedparam - set Init priority to highest" );
658
659  puts( "Init: pthread_mutex_lock - EINVAL (priority ceiling violation)" );
660  status = pthread_mutex_lock( &Mutex2_id );
661  if ( status != EINVAL )
662    printf( "status = %d\n", status );
663  assert( status == EINVAL );
664
665  /* mutexinit.c: Initialising recursive mutex */
666
667  puts( "Init: Recursive Mutex" );
668
669  status = pthread_mutex_destroy( &Mutex2_id );
670  if( status )
671    printf( "status mutex destroy:%d\n", status );
672 
673  status = pthread_mutexattr_init( &attr );
674  if( status )
675    printf( "status mutexattr:%d\n", status );
676
677  attr.recursive=true;
678  status = pthread_mutex_init( &Mutex2_id, &attr );
679  if ( status )
680    printf( "status recursive mutex :%d\n", status );
681  assert( !status );
682 
683  puts( "*** END OF POSIX TEST 5 ***" );
684  rtems_test_exit( 0 );
685
686  return NULL; /* just so the compiler thinks we returned something */
687}
Note: See TracBrowser for help on using the repository browser.