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