Home | History | Annotate | Download | only in pthread_rwlockattr_getpshared
      1 /*
      2  * Copyright (c) 2002, Intel Corporation. All rights reserved.
      3  * This file is licensed under the GPL license.  For the full content
      4  * of this license, see the COPYING file at the top level of this
      5  * source tree.
      6 
      7  * Test that pthread_rwlockattr_getpshared()
      8  *
      9  *  It shall obtain the value of the process-shared attribute from 'attr'.
     10  *  The default value of the process-shared attribute shall be PTHREAD_PROCESS_PRIVATE.
     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 #define _XOPEN_SOURCE 600
     19 #include <pthread.h>
     20 #include <stdio.h>
     21 #include "posixtest.h"
     22 
     23 int main(void)
     24 {
     25 	pthread_rwlockattr_t rwla;
     26 	int pshared;
     27 
     28 #ifndef PTHREAD_PROCESS_SHARED
     29 	printf("process-shared attribute is not available for testing\n");
     30 	return PTS_UNSUPPORTED;
     31 #endif
     32 
     33 	/* Initialize a rwlock attributes object */
     34 	if (pthread_rwlockattr_init(&rwla) != 0) {
     35 		printf("Error at pthread_rwlockattr_init()\n");
     36 		return PTS_UNRESOLVED;
     37 	}
     38 
     39 	/* The default 'pshared' attribute should be PTHREAD_PROCESS_PRIVATE  */
     40 	if (pthread_rwlockattr_getpshared(&rwla, &pshared) != 0) {
     41 		printf("Error at pthread_rwlockattr_getpshared()\n");
     42 		return PTS_UNRESOLVED;
     43 	}
     44 
     45 	if (pshared != PTHREAD_PROCESS_PRIVATE) {
     46 		printf("Test FAILED: Incorrect default pshared value: %d\n",
     47 		       pshared);
     48 		return PTS_FAIL;
     49 	}
     50 
     51 	/* Cleanup */
     52 	if ((pthread_rwlockattr_destroy(&rwla)) != 0) {
     53 		printf("Error at pthread_rwlockattr_destroy()\n");
     54 		return PTS_UNRESOLVED;
     55 	}
     56 
     57 	printf("Test PASSED\n");
     58 	return PTS_PASS;
     59 }
     60