1-1.c revision df3eb16e38c6a163b0a7367c885679eed6140964
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 pthread_mutexattr_settype()
9 * int pthread_mutexattr_settype(pthread_mutexattr_t *attr, int type);
10 * Sets 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
14#define _XOPEN_SOURCE 600
15
16#include <pthread.h>
17#include <stdio.h>
18#include <errno.h>
19#include "posixtest.h"
20
21int main()
22{
23	pthread_mutexattr_t mta;
24	int type;
25
26	/* Initialize a mutex attributes object */
27	if (pthread_mutexattr_init(&mta) != 0)
28	{
29		perror("Error at pthread_mutexattr_init()\n");
30		return PTS_UNRESOLVED;
31	}
32
33	if (pthread_mutexattr_gettype(&mta, &type) != 0)
34	{
35		printf("Error getting the attribute 'type'\n");
36		return PTS_UNRESOLVED;
37	}
38
39	if (type != PTHREAD_MUTEX_DEFAULT)
40	{
41		printf("Test FAILED: Default value of the 'type' attribute is not PTHREAD_MUTEX_DEFAULT \n");
42		return PTS_FAIL;
43	}
44
45	if (pthread_mutexattr_settype(&mta, PTHREAD_MUTEX_NORMAL) != 0)
46	{
47		printf("Test FAILED: Error setting the attribute 'type'\n");
48		return PTS_FAIL;
49	}
50
51	if (pthread_mutexattr_gettype(&mta, &type) != 0)
52	{
53		printf("Error getting the attribute 'type'\n");
54		return PTS_UNRESOLVED;
55	}
56
57	if (type != PTHREAD_MUTEX_NORMAL)
58	{
59		printf("Test FAILED: Type not correct get/set \n");
60		return PTS_FAIL;
61	}
62
63	if (pthread_mutexattr_settype(&mta, PTHREAD_MUTEX_ERRORCHECK) != 0)
64	{
65		printf("Test FAILED: Error setting the attribute 'type'\n");
66		return PTS_FAIL;
67	}
68	if (pthread_mutexattr_gettype(&mta, &type) != 0)
69	{
70		printf("Error getting the attribute 'type'\n");
71		return PTS_UNRESOLVED;
72	}
73
74	if (type != PTHREAD_MUTEX_ERRORCHECK)
75	{
76		printf("Test FAILED: Type not correct get/set \n");
77		return PTS_FAIL;
78	}
79
80	if (pthread_mutexattr_settype(&mta, PTHREAD_MUTEX_RECURSIVE) != 0)
81	{
82		printf("Test FAILED: Error setting the attribute 'type'\n");
83		return PTS_FAIL;
84	}
85
86	if (pthread_mutexattr_gettype(&mta, &type) != 0)
87	{
88		printf("Error getting the attribute 'type'\n");
89		return PTS_UNRESOLVED;
90	}
91
92	if (type != PTHREAD_MUTEX_RECURSIVE)
93	{
94		printf("Test FAILED: Type not correct get/set \n");
95		return PTS_FAIL;
96	}
97
98	if (pthread_mutexattr_destroy(&mta) != 0)
99	{
100		printf("Error at pthread_mutexattr_destroy()\n");
101		return PTS_UNRESOLVED;
102	}
103
104	printf("Test PASSED\n");
105	return PTS_PASS;
106}
107
108