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_setpshared() 9 * 10 * If successful, the pthread_condattr_setpshared() function shall return zero; 11 * The pthread_condattr_setpshared() function may fail if: 12 * [EINVAL] The new value specified for the attribute is outside the range of legal values 13 * for that attribute. 14 * 15 * 16 * Steps: 17 * 18 * 1. Pass to pthread_condattr_setpshared() a negative value for 'pshared' 19 * 2. It may return EINVAL 20 * 21 */ 22 23 #include <pthread.h> 24 #include <stdio.h> 25 #include <errno.h> 26 #include "posixtest.h" 27 28 #define INVALID_PSHARED_VALUE -100 29 30 int main(void) 31 { 32 33 /* Make sure there is process-shared capability. */ 34 #ifndef PTHREAD_PROCESS_SHARED 35 fprintf(stderr, 36 "process-shared attribute is not available for testing\n"); 37 return PTS_UNRESOLVED; 38 #endif 39 40 pthread_condattr_t attr; 41 int ret; 42 43 /* Initialize a cond attributes object */ 44 if (pthread_condattr_init(&attr) != 0) { 45 perror("Error at pthread_condattr_init()\n"); 46 return PTS_UNRESOLVED; 47 } 48 49 /* Set 'pshared' to INVALID_PSHARED_VALUE. */ 50 ret = pthread_condattr_setpshared(&attr, INVALID_PSHARED_VALUE); 51 if (ret != 0) { 52 if (ret == EINVAL) { 53 printf("Test PASSED\n"); 54 return PTS_PASS; 55 } 56 57 printf 58 ("Test FAILED: Invalid return code, expected 0 or EINVAL, but got: %d\n", 59 ret); 60 return PTS_FAIL; 61 } 62 63 /* Destory the cond attributes object */ 64 if (pthread_condattr_destroy(&attr) != 0) { 65 perror("Error at pthread_condattr_destroy()\n"); 66 return PTS_UNRESOLVED; 67 } 68 69 printf 70 ("Test PASSED: NOTE*: Returned 0 when passed an invalid 'pshared', but standard says 'may' fail.\n"); 71 return PTS_PASS; 72 } 73