aboutsummaryrefslogtreecommitdiff
path: root/testcases/open_posix_testsuite/conformance/interfaces/pthread_mutex_init/4-1.c
blob: d7b4f204e6817b094c00b7fa68c1d37df06edb94 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
/*
 * Copyright (c) 2002, Intel Corporation. All rights reserved.
 * Created by:  bing.wei.liu REMOVE-THIS AT intel DOT com
 * This file is licensed under the GPL license.  For the full content
 * of this license, see the COPYING file at the top level of this
 * source tree.

 * Test that pthread_mutex_init()
 *   Upon succesful completion, it shall return a 0
 *
 */

#include <pthread.h>
#include <stdio.h>
#include <errno.h>
#include "posixtest.h"

int main(void)
{
	pthread_mutexattr_t mta;
	pthread_mutex_t mutex;
	int rc;

	/* Initialize a mutex attributes object */
	if ((rc = pthread_mutexattr_init(&mta)) != 0) {
		fprintf(stderr, "Error at pthread_mutexattr_init(), rc=%d\n",
			rc);
		return PTS_UNRESOLVED;
	}

	/* Initialize a mutex object with the default mutex attributes */
	if ((rc = pthread_mutex_init(&mutex, &mta)) == 0) {
		printf("Test PASSED\n");
		return PTS_PASS;
	}

	/* Check if returned values are tolerable */
	else if (rc == ENOMEM) {
		fprintf(stderr,
			"Insufficient memory to initialize the mutex\n");
		return PTS_UNRESOLVED;
	} else if (rc == EAGAIN) {
		fprintf(stderr,
			"Lack of the necessary resources to initilize the mutex\n");
		return PTS_UNRESOLVED;
	} else if (rc == EPERM) {
		fprintf(stderr, "Permission denied\n");
		return PTS_UNRESOLVED;
	} else if (rc == EBUSY) {
		fprintf(stderr,
			"Detected an attemp to reinitilize a previously initilized mutex\n");
		return PTS_UNRESOLVED;
	}

	/* Any other returned value means the test failed */
	else {
		printf("Test FAILED\n");
		return PTS_FAIL;
	}
}