Home | History | Annotate | Download | only in pthread_rwlockattr_init
      1 /*
      2  * Copyright (c) 2002, Intel Corporation. All rights reserved.
      3  * Created by:  adam.li 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_rwlockattr_init()
      9  *   shall initialize a read-write attributes object 'attr' with the default
     10  *   value for all of the attributes defined by the implementation.
     11 
     12  * Steps:
     13  * 1.  Initialize a pthread_rwlockattr_t object with pthread_rwlockattr_init()
     14  * 2.  Call pthread_rwlockattr_getpshared() to check if the process-shared
     15  *     attribute is set as the default value PTHREAD_PROCESS_PRIVATE.
     16  *
     17  */
     18 
     19 #define _XOPEN_SOURCE 600
     20 #include <pthread.h>
     21 #include <stdio.h>
     22 #include "posixtest.h"
     23 
     24 int main(void)
     25 {
     26 	pthread_rwlockattr_t rwa;
     27 	int rc;
     28 
     29 #ifdef PTHREAD_PROCESS_SHARED
     30 	int pshared;
     31 #endif
     32 	/* Initialize a read-write lock attributes object */
     33 	rc = pthread_rwlockattr_init(&rwa);
     34 	if (rc != 0) {
     35 		printf("Test FAILED, pthread_rwlockattr_init() returns %d\n",
     36 		       rc);
     37 		return PTS_FAIL;
     38 	}
     39 #ifdef PTHREAD_PROCESS_SHARED
     40 	/* If the symbol {PTHREAD_PROCESS_SHARED} is defined, the attribute
     41 	 * process-shared should be provided and its default value should be
     42 	 * PTHREAD_PROCESS_PRIVATE  */
     43 	if (pthread_rwlockattr_getpshared(&rwa, &pshared) != 0) {
     44 		printf("Error obtaining the attribute process-shared\n");
     45 		return PTS_UNRESOLVED;
     46 	}
     47 
     48 	if (pshared == PTHREAD_PROCESS_PRIVATE) {
     49 		printf("Test PASSED\n");
     50 		return PTS_PASS;
     51 	} else {
     52 		printf
     53 		    ("Test FAILED, the default process-shared attribute is not PTHREAD_PROCESS_PRIVATE\n");
     54 		return PTS_FAIL;
     55 	}
     56 #endif
     57 
     58 	fprintf(stderr,
     59 		"process-shared attribute is not available for testing\n");
     60 	return PTS_UNSUPPORTED;
     61 }
     62