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_mutexattr_getpshared()
9 *
10 *  It shall obtain the value of the process-shared attribute from 'attr'.
11 *
12 * Steps:
13 * 1.  Initialize a pthread_mutexattr_t object with pthread_mutexattr_init()
14 * 2.  Set 'pshared' of the object to PTHREAD_PROCESS_PRIVATE.
15 * 3.  Call pthread_mutexattr_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
25int main()
26{
27
28	/* Make sure there is process-shared capability. */
29	#ifndef PTHREAD_PROCESS_SHARED
30	  fprintf(stderr,"process-shared attribute is not available for testing\n");
31	  return PTS_UNRESOLVED;
32	#endif
33
34	pthread_mutexattr_t mta;
35	int ret;
36	int pshared;
37
38	/* Initialize a mutex attributes object */
39	if(pthread_mutexattr_init(&mta) != 0)
40	{
41		perror("Error at pthread_mutexattr_init()\n");
42		return PTS_UNRESOLVED;
43	}
44
45	/* Set 'pshared' to PTHREAD_PROCESS_PRIVATE. */
46	ret=pthread_mutexattr_setpshared(&mta, PTHREAD_PROCESS_PRIVATE);
47	if(ret != 0)
48	{
49		printf("Error in pthread_mutexattr_setpshared(), error: %d\n", ret);
50		return PTS_UNRESOLVED;
51	}
52
53	/* Get 'pshared'.  It should be PTHREAD_PROCESS_PRIVATE. */
54	if(pthread_mutexattr_getpshared(&mta, &pshared) != 0)
55	{
56		fprintf(stderr,"Error obtaining the attribute process-shared\n");
57		return PTS_UNRESOLVED;
58	}
59
60	if(pshared != PTHREAD_PROCESS_PRIVATE)
61	{
62		printf("Test FAILED: Incorrect pshared value: %d\n", pshared);
63		return PTS_FAIL;
64	}
65
66	printf("Test PASSED\n");
67	return PTS_PASS;
68}
69