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_cond_destroy()
9 * shall destroy the condition variable referenced by 'cond';
10 * the condition variable object in effect becomes uninitialized.
11 *
12 */
13
14 #include <pthread.h>
15 #include <stdio.h>
16 #include "posixtest.h"
17
18 static pthread_cond_t cond1, cond2;
19 static pthread_cond_t cond3 = PTHREAD_COND_INITIALIZER;
20
posix_testcase(void)21 static int posix_testcase(void)
22 {
23 pthread_condattr_t condattr;
24 int rc;
25
26 /* Initialize a condition variable attribute object */
27 if ((rc = pthread_condattr_init(&condattr)) != 0) {
28 fprintf(stderr, "Error at pthread_condattr_init(), rc=%d\n",
29 rc);
30 return PTS_UNRESOLVED;
31 }
32 printf("Line-%04d\n", __LINE__);
33
34 /* Initialize cond1 with the default condition variable attribute */
35 if ((rc = pthread_cond_init(&cond1, &condattr)) != 0) {
36 fprintf(stderr, "Fail to initialize cond1, rc=%d\n", rc);
37 return PTS_UNRESOLVED;
38 }
39
40 printf("Line-%04d\n", __LINE__);
41 /* Initialize cond2 with NULL attributes */
42 if ((rc = pthread_cond_init(&cond2, NULL)) != 0) {
43 fprintf(stderr, "Fail to initialize cond2, rc=%d\n", rc);
44 return PTS_UNRESOLVED;
45 }
46
47 printf("Line-%04d\n", __LINE__);
48 /* Destroy the condition variable attribute object */
49 if ((rc = pthread_condattr_destroy(&condattr)) != 0) {
50 fprintf(stderr, "Error at pthread_condattr_destroy(), rc=%d\n",
51 rc);
52 return PTS_UNRESOLVED;
53 }
54
55 printf("Line-%04d\n", __LINE__);
56 /* Destroy cond1 */
57 if ((rc = pthread_cond_destroy(&cond1)) != 0) {
58 fprintf(stderr, "Fail to destroy cond1, rc=%d\n", rc);
59 printf("Test FAILED\n");
60 return PTS_FAIL;
61 }
62
63 printf("Line-%04d\n", __LINE__);
64 /* Destroy cond2 */
65 if ((rc = pthread_cond_destroy(&cond2)) != 0) {
66 fprintf(stderr, "Fail to destroy cond2, rc=%d\n", rc);
67 printf("Test FAILED\n");
68 return PTS_FAIL;
69 }
70
71 printf("Line-%04d", __LINE__);
72 /* Destroy cond3 */
73 if ((rc = pthread_cond_destroy(&cond3)) != 0) {
74 fprintf(stderr, "Fail to destroy cond3, rc=%d\n", rc);
75 printf("Test FAILED\n");
76 return PTS_FAIL;
77 }
78
79 printf("Line-%04d", __LINE__);
80 printf("Test PASSED\n");
81 return PTS_PASS;
82 }
83 #include <rtt_utest_internal.h>
84 UTEST_TC_EXPORT(testcase, "posix.pthread_cond_destroy.1-1.c", RT_NULL, RT_NULL, 10);
85
86