12c28215423293e443469a07ae7011135d058b671Garrett Cooper/* 20dc076565f772bb1953209fb69ea150b494aaa40robbiew * Copyright (c) 2002, Intel Corporation. All rights reserved. 30dc076565f772bb1953209fb69ea150b494aaa40robbiew * Created by: bing.wei.liu REMOVE-THIS AT intel DOT com 40dc076565f772bb1953209fb69ea150b494aaa40robbiew * This file is licensed under the GPL license. For the full content 52c28215423293e443469a07ae7011135d058b671Garrett Cooper * of this license, see the COPYING file at the top level of this 60dc076565f772bb1953209fb69ea150b494aaa40robbiew * source tree. 70dc076565f772bb1953209fb69ea150b494aaa40robbiew 80dc076565f772bb1953209fb69ea150b494aaa40robbiew * Test that pthread_mutexattr_init() 90dc076565f772bb1953209fb69ea150b494aaa40robbiew * shall initialize a mutex attributes object 'attr' with the default 100dc076565f772bb1953209fb69ea150b494aaa40robbiew * value for all of the attributes defined by the implementation. 110dc076565f772bb1953209fb69ea150b494aaa40robbiew 120dc076565f772bb1953209fb69ea150b494aaa40robbiew * Steps: 130dc076565f772bb1953209fb69ea150b494aaa40robbiew * 1. Initialize a pthread_mutexattr_t object with pthread_mutexattr_init() 142c28215423293e443469a07ae7011135d058b671Garrett Cooper * 2. Call pthread_mutexattr_getpshared() to check if the process-shared 150dc076565f772bb1953209fb69ea150b494aaa40robbiew * attribute is set as the default value PTHREAD_PROCESS_PRIVATE. 162c28215423293e443469a07ae7011135d058b671Garrett Cooper * 170dc076565f772bb1953209fb69ea150b494aaa40robbiew */ 180dc076565f772bb1953209fb69ea150b494aaa40robbiew 190dc076565f772bb1953209fb69ea150b494aaa40robbiew#include <pthread.h> 200dc076565f772bb1953209fb69ea150b494aaa40robbiew#include <stdio.h> 210dc076565f772bb1953209fb69ea150b494aaa40robbiew#include "posixtest.h" 220dc076565f772bb1953209fb69ea150b494aaa40robbiew 234ca2bbdcd3003f3c8df4e6129e9c7b2bd1514f87Cyril Hrubisint main(void) 240dc076565f772bb1953209fb69ea150b494aaa40robbiew{ 250dc076565f772bb1953209fb69ea150b494aaa40robbiew pthread_mutexattr_t mta; 260dc076565f772bb1953209fb69ea150b494aaa40robbiew int rc; 270dc076565f772bb1953209fb69ea150b494aaa40robbiew 280dc076565f772bb1953209fb69ea150b494aaa40robbiew#ifdef PTHREAD_PROCESS_SHARED 290dc076565f772bb1953209fb69ea150b494aaa40robbiew int pshared; 300dc076565f772bb1953209fb69ea150b494aaa40robbiew#endif 310dc076565f772bb1953209fb69ea150b494aaa40robbiew /* Initialize a mutex attributes object */ 32354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gao if ((rc = pthread_mutexattr_init(&mta)) != 0) { 33354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gao fprintf(stderr, "Error at pthread_mutexattr_init(), rc=%d\n", 34354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gao rc); 350dc076565f772bb1953209fb69ea150b494aaa40robbiew printf("Test FAILED\n"); 360dc076565f772bb1953209fb69ea150b494aaa40robbiew return PTS_FAIL; 370dc076565f772bb1953209fb69ea150b494aaa40robbiew } 380dc076565f772bb1953209fb69ea150b494aaa40robbiew#ifdef PTHREAD_PROCESS_SHARED 390dc076565f772bb1953209fb69ea150b494aaa40robbiew /* If the symbol {PTHREAD_PROCESS_SHARED} is defined, the attribute 402c28215423293e443469a07ae7011135d058b671Garrett Cooper * process-shared should be provided and its default value should be 410dc076565f772bb1953209fb69ea150b494aaa40robbiew * PTHREAD_PROCESS_PRIVATE */ 42354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gao if (pthread_mutexattr_getpshared(&mta, &pshared) != 0) { 43354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gao fprintf(stderr, 44354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gao "Error obtaining the attribute process-shared\n"); 450dc076565f772bb1953209fb69ea150b494aaa40robbiew return PTS_UNRESOLVED; 460dc076565f772bb1953209fb69ea150b494aaa40robbiew } 472c28215423293e443469a07ae7011135d058b671Garrett Cooper 48354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gao if (pshared == PTHREAD_PROCESS_PRIVATE) { 490dc076565f772bb1953209fb69ea150b494aaa40robbiew printf("Test PASSED\n"); 500dc076565f772bb1953209fb69ea150b494aaa40robbiew return PTS_PASS; 51354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gao } else { 520dc076565f772bb1953209fb69ea150b494aaa40robbiew printf("Test FAILED\n"); 530dc076565f772bb1953209fb69ea150b494aaa40robbiew return PTS_FAIL; 540dc076565f772bb1953209fb69ea150b494aaa40robbiew } 552c28215423293e443469a07ae7011135d058b671Garrett Cooper#endif 562c28215423293e443469a07ae7011135d058b671Garrett Cooper 57354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gao fprintf(stderr, 58354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gao "process-shared attribute is not available for testing\n"); 592c28215423293e443469a07ae7011135d058b671Garrett Cooper return PTS_UNRESOLVED; 60ec6edca7aa42b6affd989ef91b5897f96795e40fChris Dearman} 61