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  * It Shall fail if:
     11  * 	[ENOTSUP] The value specified by protocol is an unsupported value.
     12  * It may fail if:
     13  *      [EINVAL]  'protocol' is invalid
     14  */
     15 
     16 #include <pthread.h>
     17 #include <stdio.h>
     18 #include <sched.h>
     19 #include <errno.h>
     20 #include "posixtest.h"
     21 
     22 #define INVALID_PROTOCOL -1
     23 
     24 int main(void)
     25 {
     26 
     27 	pthread_mutexattr_t mta;
     28 	int protocol = INVALID_PROTOCOL;
     29 
     30 	int ret;
     31 
     32 	/* Initialize a mutex attributes object */
     33 	if (pthread_mutexattr_init(&mta) != 0) {
     34 		perror("Error at pthread_mutexattr_init()\n");
     35 		return PTS_UNRESOLVED;
     36 	}
     37 
     38 	while (protocol == PTHREAD_PRIO_NONE || protocol == PTHREAD_PRIO_INHERIT
     39 	       || protocol == PTHREAD_PRIO_PROTECT) {
     40 		protocol--;
     41 	}
     42 
     43 	/* Set the protocol to an invalid value. */
     44 	ret = pthread_mutexattr_setprotocol(&mta, protocol);
     45 	if ((ret == ENOTSUP) || (ret == EINVAL)) {
     46 		printf("Test PASSED\n");
     47 		return PTS_PASS;
     48 	} else {
     49 
     50 		printf("Test FAILED: Expected error code ENOTSUP, got %d.\n",
     51 		       ret);
     52 		return PTS_FAIL;
     53 	}
     54 }
     55