1/*
2 * Copyright (c) 2002, Intel Corporation. All rights reserved.
3 * This file is licensed under the GPL license.  For the full content
4 * of this license, see the COPYING file at the top level of this
5 * source tree.
6
7 * Test pthread_rwlock_trywrlock(pthread_rwlock_t *rwlock)
8 *
9 *	It may fail if:
10 *	[EINVAL] rwlock does not refer to an intialized read-write lock object
11 *
12 * Steps:
13 * 1. Call pthread_rwlock_trywrlock with an uninitialized rwlock object
14 * 2. Test for the return code.  It may be EINVAL or 0.
15 */
16#define _XOPEN_SOURCE 600
17#include <pthread.h>
18#include <stdio.h>
19#include <stdlib.h>
20#include <unistd.h>
21#include <errno.h>
22#include "posixtest.h"
23
24int main(void)
25{
26
27	static pthread_rwlock_t rwlock;
28	int rc;
29
30	/* Call without initializing rwlock */
31	rc = pthread_rwlock_trywrlock(&rwlock);
32
33	/* Clean up before checking return value */
34	if (pthread_rwlock_unlock(&rwlock) != 0) {
35		printf("main: Error at pthread_rwlock_unlock()\n");
36		exit(PTS_UNRESOLVED);
37	}
38
39	if (pthread_rwlock_destroy(&rwlock) != 0) {
40		printf("Error at pthread_rwlock_destroy()\n");
41		return PTS_UNRESOLVED;
42	}
43
44	if (rc != 0) {
45		if (rc == EINVAL) {
46			printf("Test PASSED\n");
47			return PTS_PASS;
48		} else {
49			printf("Test FAILED: Incorrect return code %d\n", rc);
50			return PTS_FAIL;
51		}
52	}
53
54	printf
55	    ("Test PASSED: Note*: Returned 0 instead of EINVAL, but standard specified _may_ fail. \n");
56	return PTS_PASS;
57}
58