source: rtems/testsuites/psxtests/psx05/init.c @ f188769

4.104.11
Last change on this file since f188769 was f188769, checked in by Joel Sherrill <joel.sherrill@…>, on Oct 12, 2009 at 12:07:16 AM

2009-10-11 Joel Sherrill <joel.sherrill@…>

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