Home | History | Annotate | Download | only in pthread_mutexattr_getprotocol
      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 
     20 int main(void)
     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 		perror("Error at pthread_mutexattr_init()\n");
     29 		return PTS_UNRESOLVED;
     30 	}
     31 
     32 	protcls[0] = PTHREAD_PRIO_NONE;
     33 	protcls[1] = PTHREAD_PRIO_INHERIT;
     34 	protcls[2] = PTHREAD_PRIO_PROTECT;
     35 
     36 	for (i = 0; i < 3; i++) {
     37 		/* Set the protocol to one of the 3 valid protocols. */
     38 		if (pthread_mutexattr_setprotocol(&mta, protcls[i])) {
     39 			printf("Error setting protocol to %d\n", protcls[i]);
     40 			return PTS_UNRESOLVED;
     41 		}
     42 
     43 		/* Get the protocol mutex attr. */
     44 		if (pthread_mutexattr_getprotocol(&mta, &protocol) != 0) {
     45 			fprintf(stderr,
     46 				"Error obtaining the protocol attribute.\n");
     47 			return PTS_UNRESOLVED;
     48 		}
     49 
     50 		/* Make sure that the protocol set is the protocl we get when calling
     51 		 * pthread_mutexattr_getprocol() */
     52 		if (protocol != protcls[i]) {
     53 			printf
     54 			    ("Test FAILED: Set protocol %d, but instead got protocol %d.\n",
     55 			     protcls[i], protocol);
     56 			return PTS_FAIL;
     57 		}
     58 	}
     59 
     60 	printf("Test PASSED\n");
     61 	return PTS_PASS;
     62 }
     63