1 /* 2 * Copyright (c) 2010, Ngie Cooper. 3 * 4 * Test that pthread_mutex_getprioceiling() fails because: 5 * 6 * [EINVAL] 7 * The protocol attribute of mutex is PTHREAD_PRIO_NONE. 8 * 9 * by not specifying PTHREAD_PRIO_NONE and noting that the default (as per 10 * pthread_mutexattr_getprotocol) is PTHREAD_PRIO_NONE. 11 * 12 * Steps: 13 * 1. Initialize a mutex via pthread_mutex_init. 14 * 2. Do not modify the mutex. 15 * 3. Call pthread_mutex_getprioceiling() to obtain the prioceiling. 16 * 17 */ 18 19 #include <pthread.h> 20 #include <errno.h> 21 #include <sched.h> 22 #include <stdio.h> 23 #include <string.h> 24 #include <unistd.h> 25 #include "posixtest.h" 26 27 int main(void) 28 { 29 #if defined(_SC_PRIORITY_SCHEDULING) 30 31 if (sysconf(_SC_PRIORITY_SCHEDULING) == -1) { 32 printf("PRIORITY_SCHEDULING not supported\n"); 33 return PTS_UNSUPPORTED; 34 } 35 36 pthread_mutex_t mutex; 37 int error, prioceiling; 38 39 /* 40 * The default protocol is PTHREAD_PRIO_NONE according to 41 * pthread_mutexattr_getprotocol. 42 */ 43 44 /* Initialize a mutex object */ 45 error = pthread_mutex_init(&mutex, NULL); 46 if (error) { 47 printf("pthread_mutex_init failed: %s\n", strerror(error)); 48 return PTS_UNRESOLVED; 49 } 50 51 /* Get the prioceiling of the mutex. */ 52 error = pthread_mutex_getprioceiling(&mutex, &prioceiling); 53 if (error) { 54 if (error == EINVAL) { 55 printf("pthread_mutex_getprioceiling failed as " 56 "expected\n"); 57 } else { 58 printf("pthread_mutex_getprioceiling did not fail as " 59 "expected: %s\n", strerror(error)); 60 } 61 } else 62 printf("pthread_mutex_getprioceiling passed unexpectedly\n"); 63 64 (void)pthread_mutex_destroy(&mutex); 65 66 return (error == EINVAL ? PTS_PASS : PTS_FAIL); 67 #else 68 printf("pthread_mutex_getprioceiling not supported"); 69 return PTS_UNSUPPORTED; 70 #endif 71 72 } 73