1-1.c revision 0dc076565f772bb1953209fb69ea150b494aaa40
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 * Sets 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. 17 * 18 */ 19 20#include <pthread.h> 21#include <stdio.h> 22#include <sched.h> 23#include "posixtest.h" 24 25int main() 26{ 27 28 /* Make sure there is prioceiling capability. */ 29 /* #ifndef _POSIX_PRIORITY_SCHEDULING 30 fprintf(stderr,"prioceiling attribute is not available for testing\n"); 31 return PTS_UNRESOLVED; 32 #endif */ 33 34 pthread_mutexattr_t mta; 35 int max_prio, min_prio, i; 36 37 /* Initialize a mutex attributes object */ 38 if(pthread_mutexattr_init(&mta) != 0) 39 { 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 { 50 /* Set the prioceiling to a priority number in the boundries 51 * of SCHED_FIFO policy */ 52 if(pthread_mutexattr_setprioceiling(&mta,i)) 53 { 54 printf("Test FAILED: Error setting prioceiling to %d\n", i); 55 return PTS_FAIL; 56 } 57 58 } 59 60 printf("Test PASSED\n"); 61 return PTS_PASS; 62} 63