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 * pthread_barrierattr_setpshared() 8 * 9 * The pthread_barrierattr_setpshared() function may fail if: 10 * [EINVAL] The new value specified for the process-shared attribute is not one of 11 * the legal values PTHREAD_PROCESS_SHARED or PTHREAD_PROCESS_PRIVATE. 12 * This case will always pass 13 */ 14 15#define _XOPEN_SOURCE 600 16#include <pthread.h> 17#include <stdio.h> 18#include <stdlib.h> 19#include <unistd.h> 20#include <errno.h> 21#include <string.h> 22#include "posixtest.h" 23 24int main(void) 25{ 26 27 /* Make sure there is process-shared capability. */ 28#ifndef PTHREAD_PROCESS_SHARED 29 fprintf(stderr, 30 "process-shared attribute is not available for testing\n"); 31 return PTS_UNSUPPORTED; 32#endif 33 34 pthread_barrierattr_t ba; 35 int pshared = PTHREAD_PROCESS_PRIVATE + 1; 36 int rc; 37 38 /* Set pshared to an invalid value */ 39 if (pshared == PTHREAD_PROCESS_SHARED) { 40 pshared += 1; 41 } 42 43 /* Initialize a barrier attributes object */ 44 if (pthread_barrierattr_init(&ba) != 0) { 45 printf("Error at pthread_barrierattr_init()\n"); 46 return PTS_UNRESOLVED; 47 } 48 49 /* Set process-shared attribute to an invalid value */ 50 rc = pthread_barrierattr_setpshared(&ba, pshared); 51 if (rc == EINVAL) 52 printf("Test PASSED\n"); 53 else { 54 printf("Get return code: %d, %s\n", rc, strerror(rc)); 55 printf 56 ("Test PASSED: Note*: Expected EINVAL, but standard says 'may' fail.\n"); 57 } 58 59 return PTS_PASS; 60 61} 62