Home | History | Annotate | Download | only in pthread_condattr_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_condattr_getpshared()
      9  *
     10  *  It shall obtain the value of the process-shared attribute from 'attr'.
     11  *
     12  * Steps:
     13  * 1.  In a loop, initialize a pthread_condattr_t object with pthread_condattr_init()
     14  * 2.  Set 'pshared' of the object to PTHREAD_PROCESS_PRIVATE.
     15  * 3.  Call pthread_condattr_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 #define NUM_OF_CONDATTR 10
     26 
     27 int main(void)
     28 {
     29 
     30 	/* Make sure there is process-shared capability. */
     31 #ifndef PTHREAD_PROCESS_SHARED
     32 	fprintf(stderr,
     33 		"process-shared attribute is not available for testing\n");
     34 	return PTS_UNRESOLVED;
     35 #endif
     36 
     37 	pthread_condattr_t attr[NUM_OF_CONDATTR];
     38 	int ret, i, pshared;
     39 
     40 	for (i = 0; i < NUM_OF_CONDATTR; i++) {
     41 		/* Initialize a cond attributes object */
     42 		if (pthread_condattr_init(&attr[i]) != 0) {
     43 			perror("Error at pthread_condattr_init()\n");
     44 			return PTS_UNRESOLVED;
     45 		}
     46 
     47 		/* Set 'pshared' to PTHREAD_PROCESS_PRIVATE. */
     48 		ret =
     49 		    pthread_condattr_setpshared(&attr[i],
     50 						PTHREAD_PROCESS_PRIVATE);
     51 		if (ret != 0) {
     52 			printf
     53 			    ("Error in pthread_condattr_setpshared(), error: %d\n",
     54 			     ret);
     55 			return PTS_UNRESOLVED;
     56 		}
     57 
     58 		/* Get 'pshared'.  It should be PTHREAD_PROCESS_PRIVATE. */
     59 		if (pthread_condattr_getpshared(&attr[i], &pshared) != 0) {
     60 			fprintf(stderr,
     61 				"Error obtaining the attribute process-shared\n");
     62 			return PTS_UNRESOLVED;
     63 		}
     64 
     65 		if (pshared != PTHREAD_PROCESS_PRIVATE) {
     66 			printf("Test FAILED: Incorrect pshared value: %d\n",
     67 			       pshared);
     68 			return PTS_FAIL;
     69 		}
     70 
     71 		/* Destory the cond attributes object */
     72 		if (pthread_condattr_destroy(&attr[i]) != 0) {
     73 			perror("Error at pthread_condattr_destroy()\n");
     74 			return PTS_UNRESOLVED;
     75 		}
     76 	}
     77 
     78 	printf("Test PASSED\n");
     79 	return PTS_PASS;
     80 }
     81