Home | History | Annotate | Download | only in pthread_mutexattr_gettype
      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_gettype()
      9  *
     10  * Gets 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  * Testing the PTHREAD_MUTEX_ERRORCHECK type.
     14  *
     15  * Steps:
     16  * 1.  Initialize a pthread_mutexattr_t object with pthread_mutexattr_init()
     17  * 2.  Set tye mutexattr type to PTHREAD_MUTEX_ERRORCHECK
     18  * 3.  Call pthread_mutexattr_gettype() to check if type
     19  *     attribute is set as the value PTHREAD_MUTEX_ERRORCHECK.
     20  *
     21  */
     22 
     23 #define _XOPEN_SOURCE 600
     24 
     25 #include <pthread.h>
     26 #include <stdio.h>
     27 #include "posixtest.h"
     28 
     29 int main(void)
     30 {
     31 	pthread_mutexattr_t mta;
     32 	int type;
     33 
     34 	/* Initialize a mutex attributes object */
     35 	if (pthread_mutexattr_init(&mta) != 0) {
     36 		perror("Error at pthread_mutexattr_init()\n");
     37 		return PTS_UNRESOLVED;
     38 	}
     39 
     40 	/* Set the mutex attribute 'type' to PTHREAD_MUTEX_ERRORCHECK. */
     41 	if (pthread_mutexattr_settype(&mta, PTHREAD_MUTEX_ERRORCHECK) != 0) {
     42 		fprintf(stderr,
     43 			"pthread_mutexattr_settype(): Error setting the attribute 'type'\n");
     44 		return PTS_UNRESOLVED;
     45 	}
     46 
     47 	/* The 'type' attribute should be PTHREAD_MUTEX_ERRORCHECK  */
     48 	if (pthread_mutexattr_gettype(&mta, &type) != 0) {
     49 		fprintf(stderr,
     50 			"pthread_mutexattr_gettype(): Error obtaining the attribute 'type'\n");
     51 		return PTS_UNRESOLVED;
     52 	}
     53 
     54 	if (type != PTHREAD_MUTEX_ERRORCHECK) {
     55 		printf
     56 		    ("Test FAILED: Incorrect mutexattr 'type' value: %d. Should be PTHREAD_MUTEX_ERRORCHECK\n",
     57 		     type);
     58 		return PTS_FAIL;
     59 	}
     60 
     61 	printf("Test PASSED\n");
     62 	return PTS_PASS;
     63 }
     64