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_mutex_trylock()
9 *   Upon failure, it shall return:
10 *   -[EBUSY]   The mutex could not be acquired because it was already locked.
11
12 * Steps:
13 *   -- Initilize a mutex object
14 *   -- Lock the mutex using pthread_mutex_lock()
15 *   -- Try to lock the mutex using pthread_mutex_trylock() and expect EBUSY
16 *
17 */
18
19#include <pthread.h>
20#include <stdio.h>
21#include <errno.h>
22#include "posixtest.h"
23
24pthread_mutex_t    mutex = PTHREAD_MUTEX_INITIALIZER;
25
26int main()
27{
28  	int           	rc;
29
30	if((rc=pthread_mutex_lock(&mutex))!=0) {
31		fprintf(stderr,"Error at pthread_mutex_lock(), rc=%d\n",rc);
32		return PTS_UNRESOLVED;
33	}
34
35   	rc = pthread_mutex_trylock(&mutex);
36      	if(rc!=EBUSY) {
37        	fprintf(stderr,"Expected %d(EBUSY), got %d\n",EBUSY,rc);
38        	printf("Test FAILED\n");
39		return PTS_FAIL;
40      	}
41
42    	pthread_mutex_unlock(&mutex);
43  	pthread_mutex_destroy(&mutex);
44
45	printf("Test PASSED\n");
46	return PTS_PASS;
47}
48