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_getprotocol() 9 * 10 * Gets the protocol attribute of a mutexattr object (which was prev. created 11 * by the function pthread_mutexattr_init()). 12 * 13 */ 14 15#include <pthread.h> 16#include <stdio.h> 17#include <sched.h> 18#include "posixtest.h" 19 20int main() 21{ 22 23 pthread_mutexattr_t mta; 24 int protocol, protcls[3],i; 25 26 /* Initialize a mutex attributes object */ 27 if(pthread_mutexattr_init(&mta) != 0) 28 { 29 perror("Error at pthread_mutexattr_init()\n"); 30 return PTS_UNRESOLVED; 31 } 32 33 protcls[0]=PTHREAD_PRIO_NONE; 34 protcls[1]=PTHREAD_PRIO_INHERIT; 35 protcls[2]=PTHREAD_PRIO_PROTECT; 36 37 for(i=0;i<3;i++) 38 { 39 /* Set the protocol to one of the 3 valid protocols. */ 40 if(pthread_mutexattr_setprotocol(&mta,protcls[i])) 41 { 42 printf("Error setting protocol to %d\n", protcls[i]); 43 return PTS_UNRESOLVED; 44 } 45 46 /* Get the protocol mutex attr. */ 47 if(pthread_mutexattr_getprotocol(&mta, &protocol) != 0) 48 { 49 fprintf(stderr,"Error obtaining the protocol attribute.\n"); 50 return PTS_UNRESOLVED; 51 } 52 53 /* Make sure that the protocol set is the protocl we get when calling 54 * pthread_mutexattr_getprocol() */ 55 if(protocol != protcls[i]) 56 { 57 printf("Test FAILED: Set protocol %d, but instead got protocol %d.\n", protcls[i], protocol); 58 return PTS_FAIL; 59 } 60 } 61 62 printf("Test PASSED\n"); 63 return PTS_PASS; 64} 65