Home | History | Annotate | Download | only in pthread_mutexattr_setprotocol
      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_setprotocol()
      9  *
     10  * Sets the protocol attribute of a mutexattr object (which was prev. created
     11  * by the function pthread_mutexattr_init()).
     12  *
     13  * Steps:
     14  * 1. In a for loop, call pthread_mutexattr_setprotocol with all the valid 'protocol' values.
     15  * 2. In the for loop, then call pthread_mutexattr_getprotocol and ensure that the same
     16  *    value that was set was the same value that was retrieved from this function.
     17  */
     18 
     19 #include <pthread.h>
     20 #include <stdio.h>
     21 #include <sched.h>
     22 #include "posixtest.h"
     23 
     24 int main(void)
     25 {
     26 
     27 	pthread_mutexattr_t mta;
     28 	int protocol, protcls[3], i;
     29 
     30 	/* Initialize a mutex attributes object */
     31 	if (pthread_mutexattr_init(&mta) != 0) {
     32 		perror("Error at pthread_mutexattr_init()\n");
     33 		return PTS_UNRESOLVED;
     34 	}
     35 
     36 	protcls[0] = PTHREAD_PRIO_NONE;
     37 	protcls[1] = PTHREAD_PRIO_INHERIT;
     38 	protcls[2] = PTHREAD_PRIO_PROTECT;
     39 
     40 	for (i = 0; i < 3; i++) {
     41 		/* Set the protocol to one of the 3 valid protocols. */
     42 		if (pthread_mutexattr_setprotocol(&mta, protcls[i]) != 0) {
     43 			printf("Error setting protocol to %d\n", protcls[i]);
     44 			return PTS_UNRESOLVED;
     45 		}
     46 
     47 		/* Get the protocol mutex attr. */
     48 		if (pthread_mutexattr_getprotocol(&mta, &protocol) != 0) {
     49 			fprintf(stderr,
     50 				"Error obtaining the protocol attribute.\n");
     51 			return PTS_UNRESOLVED;
     52 		}
     53 
     54 		/* Make sure that the protocol set is the protocl we get when calling
     55 		 * pthread_mutexattr_getprocol() */
     56 		if (protocol != protcls[i]) {
     57 			printf
     58 			    ("Test FAILED: Set protocol %d, but instead got protocol %d.\n",
     59 			     protcls[i], protocol);
     60 			return PTS_FAIL;
     61 		}
     62 	}
     63 
     64 	printf("Test PASSED\n");
     65 	return PTS_PASS;
     66 }
     67