Home | History | Annotate | Download | only in pthread_mutexattr_getpshared
      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_getpshared()
      9  *
     10  *  It shall obtain the value of the process-shared attribute from 'attr'.
     11  *
     12  * Steps:
     13  * 1.  Initialize a pthread_mutexattr_t object with pthread_mutexattr_init()
     14  * 2.  Set 'pshared' of the object to PTHREAD_PROCESS_PRIVATE.
     15  * 3.  Call pthread_mutexattr_getpshared() to check if the process-shared
     16  *     attribute is set as PTHREAD_PROCESS_PRIVATE.
     17  *
     18  */
     19 
     20 #include <pthread.h>
     21 #include <stdio.h>
     22 #include <errno.h>
     23 #include "posixtest.h"
     24 
     25 int main(void)
     26 {
     27 
     28 	/* Make sure there is process-shared capability. */
     29 #ifndef PTHREAD_PROCESS_SHARED
     30 	fprintf(stderr,
     31 		"process-shared attribute is not available for testing\n");
     32 	return PTS_UNRESOLVED;
     33 #endif
     34 
     35 	pthread_mutexattr_t mta;
     36 	int ret;
     37 	int pshared;
     38 
     39 	/* Initialize a mutex attributes object */
     40 	if (pthread_mutexattr_init(&mta) != 0) {
     41 		perror("Error at pthread_mutexattr_init()\n");
     42 		return PTS_UNRESOLVED;
     43 	}
     44 
     45 	/* Set 'pshared' to PTHREAD_PROCESS_PRIVATE. */
     46 	ret = pthread_mutexattr_setpshared(&mta, PTHREAD_PROCESS_PRIVATE);
     47 	if (ret != 0) {
     48 		printf("Error in pthread_mutexattr_setpshared(), error: %d\n",
     49 		       ret);
     50 		return PTS_UNRESOLVED;
     51 	}
     52 
     53 	/* Get 'pshared'.  It should be PTHREAD_PROCESS_PRIVATE. */
     54 	if (pthread_mutexattr_getpshared(&mta, &pshared) != 0) {
     55 		fprintf(stderr,
     56 			"Error obtaining the attribute process-shared\n");
     57 		return PTS_UNRESOLVED;
     58 	}
     59 
     60 	if (pshared != PTHREAD_PROCESS_PRIVATE) {
     61 		printf("Test FAILED: Incorrect pshared value: %d\n", pshared);
     62 		return PTS_FAIL;
     63 	}
     64 
     65 	printf("Test PASSED\n");
     66 	return PTS_PASS;
     67 }
     68