12c28215423293e443469a07ae7011135d058b671Garrett Cooper/*
20dc076565f772bb1953209fb69ea150b494aaa40robbiew * Copyright (c) 2002, Intel Corporation. All rights reserved.
30dc076565f772bb1953209fb69ea150b494aaa40robbiew * Created by:  bing.wei.liu REMOVE-THIS AT intel DOT com
40dc076565f772bb1953209fb69ea150b494aaa40robbiew * This file is licensed under the GPL license.  For the full content
52c28215423293e443469a07ae7011135d058b671Garrett Cooper * of this license, see the COPYING file at the top level of this
60dc076565f772bb1953209fb69ea150b494aaa40robbiew * source tree.
70dc076565f772bb1953209fb69ea150b494aaa40robbiew
80dc076565f772bb1953209fb69ea150b494aaa40robbiew * Test that pthread_cond_destroy()
90dc076565f772bb1953209fb69ea150b494aaa40robbiew *   Upon succesful completion, it shall return a 0
100dc076565f772bb1953209fb69ea150b494aaa40robbiew *
110dc076565f772bb1953209fb69ea150b494aaa40robbiew */
120dc076565f772bb1953209fb69ea150b494aaa40robbiew
130dc076565f772bb1953209fb69ea150b494aaa40robbiew#include <pthread.h>
140dc076565f772bb1953209fb69ea150b494aaa40robbiew#include <stdio.h>
150dc076565f772bb1953209fb69ea150b494aaa40robbiew#include <errno.h>
160dc076565f772bb1953209fb69ea150b494aaa40robbiew#include "posixtest.h"
170dc076565f772bb1953209fb69ea150b494aaa40robbiew
184ca2bbdcd3003f3c8df4e6129e9c7b2bd1514f87Cyril Hrubisint main(void)
190dc076565f772bb1953209fb69ea150b494aaa40robbiew{
20354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gao	pthread_cond_t cond;
210dc076565f772bb1953209fb69ea150b494aaa40robbiew	int rc;
220dc076565f772bb1953209fb69ea150b494aaa40robbiew
230dc076565f772bb1953209fb69ea150b494aaa40robbiew	/* Initialize a cond object */
24354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gao	if ((rc = pthread_cond_init(&cond, NULL)) != 0) {
25354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gao		fprintf(stderr, "Fail to initialize cond, rc=%d\n", rc);
260dc076565f772bb1953209fb69ea150b494aaa40robbiew		return PTS_UNRESOLVED;
270dc076565f772bb1953209fb69ea150b494aaa40robbiew	}
282c28215423293e443469a07ae7011135d058b671Garrett Cooper
29354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gao	if ((rc = pthread_cond_destroy(&cond)) == 0) {
300dc076565f772bb1953209fb69ea150b494aaa40robbiew		printf("Test PASSED\n");
310dc076565f772bb1953209fb69ea150b494aaa40robbiew		return PTS_PASS;
320dc076565f772bb1953209fb69ea150b494aaa40robbiew	}
330dc076565f772bb1953209fb69ea150b494aaa40robbiew
340dc076565f772bb1953209fb69ea150b494aaa40robbiew	/* Check if returned values are tolerable */
35df3eb16e38c6a163b0a7367c885679eed6140964Garrett Cooper	else if (rc == EBUSY) {
36354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gao		fprintf(stderr,
37354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gao			"Detected an attempt to destroy a cond in use\n");
380dc076565f772bb1953209fb69ea150b494aaa40robbiew		return PTS_FAIL;
39354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gao	} else if (rc == EINVAL) {
40354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gao		fprintf(stderr, "The value specified by 'cond' is invalid\n");
410dc076565f772bb1953209fb69ea150b494aaa40robbiew		return PTS_FAIL;
420dc076565f772bb1953209fb69ea150b494aaa40robbiew	}
430dc076565f772bb1953209fb69ea150b494aaa40robbiew
440dc076565f772bb1953209fb69ea150b494aaa40robbiew	/* Any other returned value means the test failed */
45354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gao	else {
460dc076565f772bb1953209fb69ea150b494aaa40robbiew		printf("Test FAILED (error %i unexpected)\n", rc);
470dc076565f772bb1953209fb69ea150b494aaa40robbiew		return PTS_FAIL;
480dc076565f772bb1953209fb69ea150b494aaa40robbiew	}
49ec6edca7aa42b6affd989ef91b5897f96795e40fChris Dearman}
50