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