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_getprioceiling() 9 * 10 * Gets the priority ceiling attribute of a mutexattr object (which was prev. created 11 * by the function pthread_mutexattr_init()). 12 * 13 * Steps: 14 * 1. Initialize a pthread_mutexattr_t object with pthread_mutexattr_init() 15 * 2. Get the min and max boundries for SCHED_FIFO of what prioceiling can be. 16 * 3. In a for loop, go through each valid SCHED_FIFO value, set the prioceiling, then 17 * get the prio ceiling. These should always be the same. If not, fail the test. 18 * 19 */ 20 21#include <pthread.h> 22#include <stdio.h> 23#include <sched.h> 24#include "posixtest.h" 25 26int main(void) 27{ 28 29 /* Make sure there is prioceiling capability. */ 30 /* #ifndef _POSIX_PRIORITY_SCHEDULING 31 fprintf(stderr,"prioceiling attribute is not available for testing\n"); 32 return PTS_UNRESOLVED; 33 #endif */ 34 35 pthread_mutexattr_t mta; 36 int prioceiling, max_prio, min_prio, i; 37 38 /* Initialize a mutex attributes object */ 39 if (pthread_mutexattr_init(&mta) != 0) { 40 perror("Error at pthread_mutexattr_init()\n"); 41 return PTS_UNRESOLVED; 42 } 43 44 /* Get the max and min prio according to SCHED_FIFO (posix scheduling policy) */ 45 max_prio = sched_get_priority_max(SCHED_FIFO); 46 min_prio = sched_get_priority_min(SCHED_FIFO); 47 48 for (i = min_prio; (i < max_prio + 1); i++) { 49 /* Set the prioceiling to a priority number in the boundries 50 * of SCHED_FIFO policy */ 51 if (pthread_mutexattr_setprioceiling(&mta, i)) { 52 printf("Error setting prioceiling to %d\n", i); 53 return PTS_UNRESOLVED; 54 } 55 56 /* Get the prioceiling mutex attr. */ 57 if (pthread_mutexattr_getprioceiling(&mta, &prioceiling) != 0) { 58 fprintf(stderr, 59 "Error obtaining the attribute process-shared\n"); 60 return PTS_UNRESOLVED; 61 } 62 63 /* Make sure that prioceiling is withing the legal SCHED_FIFO boundries. */ 64 if (prioceiling != i) { 65 printf 66 ("Test FAILED: Set prioceiling and get prioceiling did not match.\n"); 67 return PTS_FAIL; 68 } 69 } 70 71 printf("Test PASSED\n"); 72 return PTS_PASS; 73} 74