Home | History | Annotate | Download | only in pthread_mutexattr_setprioceiling
      1 /*
      2  * Copyright (c) 2002, Intel Corporation. All rights reserved.
      3  * Created by:  bing.wei.liu REMOVE-THIS AT intel DOT com
      4  * This file is licensed under the GPL license.  For the full content
      5  * of this license, see the COPYING file at the top level of this
      6  * source tree.
      7 
      8  * Test that pthread_mutexattr_setprioceiling()
      9  *
     10  * It MAY fail if:
     11  *
     12  * [EINVAL] - 'attr' or 'prioceiling' is invalid.
     13  * [EPERM] - The caller doesn't have the privilege to perform the operation.
     14  *
     15  * Steps:
     16  * 1.  Initialize a pthread_mutexattr_t object with pthread_mutexattr_init()
     17  * 2.  Call pthread_mutexattr_setprioceiling() with an invalid prioceiling value.
     18  *
     19  */
     20 
     21 #include <pthread.h>
     22 #include <stdio.h>
     23 #include <sched.h>
     24 #include <errno.h>
     25 #include "posixtest.h"
     26 
     27 int main(void)
     28 {
     29 
     30 	/* Make sure there is prioceiling capability. */
     31 	/* #ifndef _POSIX_PRIORITY_SCHEDULING
     32 	   fprintf(stderr,"prioceiling attribute is not available for testing\n");
     33 	   return PTS_UNRESOLVED;
     34 	   #endif */
     35 
     36 	pthread_mutexattr_t mta;
     37 	int prioceiling, ret;
     38 
     39 	/* Set 'prioceiling' out of SCHED_FIFO boundry. */
     40 	prioceiling = sched_get_priority_max(SCHED_FIFO);
     41 	prioceiling++;
     42 
     43 	/* Set the prioceiling to an invalid prioceiling. */
     44 	if ((ret = pthread_mutexattr_setprioceiling(&mta, prioceiling)) == 0) {
     45 		printf
     46 		    ("Test PASSED: *Note: Returned 0 instead of EINVAL when passed an invalid 'proceiling' to pthread_mutexattr_setprioceiling, but standard says 'may' fail.\n");
     47 		return PTS_PASS;
     48 	}
     49 
     50 	if (ret != EINVAL) {
     51 		printf
     52 		    ("Test FAILED: Invalid return code %d. Expected EINVAL or 0.\n",
     53 		     ret);
     54 		return PTS_FAIL;
     55 	}
     56 
     57 	printf("Test PASSED\n");
     58 	return PTS_PASS;
     59 }
     60