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_gettype()
9 *
10 * Gets the mutex 'type' attribute.  This attribute is set in the 'type' parameter to
11 * these functions.  The default value is PTHREAD_MUTEX_DEFAULT.
12 *
13 * Testing the PTHREAD_MUTEX_NORMAL type.
14 *
15 * Steps:
16 * 1.  Initialize a pthread_mutexattr_t object with pthread_mutexattr_init()
17 * 2.  Set tye mutexattr type to PTHREAD_MUTEX_NORMAL
18 * 3.  Call pthread_mutexattr_gettype() to check if type
19 *     attribute is set as the value PTHREAD_MUTEX_NORMAL.
20 *
21 */
22
23#define _XOPEN_SOURCE 600
24
25#include <pthread.h>
26#include <stdio.h>
27#include "posixtest.h"
28
29int main()
30{
31	pthread_mutexattr_t mta;
32	int type;
33
34	/* Initialize a mutex attributes object */
35	if(pthread_mutexattr_init(&mta) != 0)
36	{
37		perror("Error at pthread_mutexattr_init()\n");
38		return PTS_UNRESOLVED;
39	}
40
41	/* Set the mutex attribute 'type' to PTHREAD_MUTEX_NORMAL. */
42	if(pthread_mutexattr_settype(&mta, PTHREAD_MUTEX_NORMAL) != 0)
43	{
44		fprintf(stderr,"pthread_mutexattr_settype(): Error setting the attribute 'type'\n");
45		return PTS_UNRESOLVED;
46	}
47
48	 /* The 'type' attribute should be PTHREAD_MUTEX_NORMAL  */
49	if(pthread_mutexattr_gettype(&mta, &type) != 0)
50	{
51		fprintf(stderr,"pthread_mutexattr_gettype(): Error obtaining the attribute 'type'\n");
52		return PTS_UNRESOLVED;
53	}
54
55	if(type != PTHREAD_MUTEX_NORMAL)
56	{
57		printf("Test FAILED: Incorrect mutexattr 'type' value: %d. Should be PTHREAD_MUTEX_NORMAL\n", type);
58		return PTS_FAIL;
59	}
60
61	printf("Test PASSED\n");
62	return PTS_PASS;
63}
64