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 pthread_mutexattr_settype() 9 * int pthread_mutexattr_settype(pthread_mutexattr_t *attr, int type); 10 * Sets the mutex 'type' attribute. This attribute is set in the 'type' parameter to 11 * these functions. The default value is PTHREAD_MUTEX_DEFAULT. 12 */ 13 14 15 #include <pthread.h> 16 #include <stdio.h> 17 #include <errno.h> 18 #include "posixtest.h" 19 20 int main(void) 21 { 22 pthread_mutexattr_t mta; 23 int type; 24 25 /* Initialize a mutex attributes object */ 26 if (pthread_mutexattr_init(&mta) != 0) { 27 perror("Error at pthread_mutexattr_init()\n"); 28 return PTS_UNRESOLVED; 29 } 30 31 if (pthread_mutexattr_gettype(&mta, &type) != 0) { 32 printf("Error getting the attribute 'type'\n"); 33 return PTS_UNRESOLVED; 34 } 35 36 if (type != PTHREAD_MUTEX_DEFAULT) { 37 printf 38 ("Test FAILED: Default value of the 'type' attribute is not PTHREAD_MUTEX_DEFAULT \n"); 39 return PTS_FAIL; 40 } 41 42 if (pthread_mutexattr_settype(&mta, PTHREAD_MUTEX_NORMAL) != 0) { 43 printf("Test FAILED: Error setting the attribute 'type'\n"); 44 return PTS_FAIL; 45 } 46 47 if (pthread_mutexattr_gettype(&mta, &type) != 0) { 48 printf("Error getting the attribute 'type'\n"); 49 return PTS_UNRESOLVED; 50 } 51 52 if (type != PTHREAD_MUTEX_NORMAL) { 53 printf("Test FAILED: Type not correct get/set \n"); 54 return PTS_FAIL; 55 } 56 57 if (pthread_mutexattr_settype(&mta, PTHREAD_MUTEX_ERRORCHECK) != 0) { 58 printf("Test FAILED: Error setting the attribute 'type'\n"); 59 return PTS_FAIL; 60 } 61 if (pthread_mutexattr_gettype(&mta, &type) != 0) { 62 printf("Error getting the attribute 'type'\n"); 63 return PTS_UNRESOLVED; 64 } 65 66 if (type != PTHREAD_MUTEX_ERRORCHECK) { 67 printf("Test FAILED: Type not correct get/set \n"); 68 return PTS_FAIL; 69 } 70 71 if (pthread_mutexattr_settype(&mta, PTHREAD_MUTEX_RECURSIVE) != 0) { 72 printf("Test FAILED: Error setting the attribute 'type'\n"); 73 return PTS_FAIL; 74 } 75 76 if (pthread_mutexattr_gettype(&mta, &type) != 0) { 77 printf("Error getting the attribute 'type'\n"); 78 return PTS_UNRESOLVED; 79 } 80 81 if (type != PTHREAD_MUTEX_RECURSIVE) { 82 printf("Test FAILED: Type not correct get/set \n"); 83 return PTS_FAIL; 84 } 85 86 if (pthread_mutexattr_destroy(&mta) != 0) { 87 printf("Error at pthread_mutexattr_destroy()\n"); 88 return PTS_UNRESOLVED; 89 } 90 91 printf("Test PASSED\n"); 92 return PTS_PASS; 93 } 94