1 /*
2 * File: condvar1_2.c
3 *
4 *
5 * --------------------------------------------------------------------------
6 *
7 * Pthreads-win32 - POSIX Threads Library for Win32
8 * Copyright(C) 1998 John E. Bossom
9 * Copyright(C) 1999,2005 Pthreads-win32 contributors
10 *
11 * Contact Email: rpj@callisto.canberra.edu.au
12 *
13 * The current list of contributors is contained
14 * in the file CONTRIBUTORS included with the source
15 * code distribution. The list can also be seen at the
16 * following World Wide Web location:
17 * http://sources.redhat.com/pthreads-win32/contributors.html
18 *
19 * This library is free software; you can redistribute it and/or
20 * modify it under the terms of the GNU Lesser General Public
21 * License as published by the Free Software Foundation; either
22 * version 2 of the License, or (at your option) any later version.
23 *
24 * This library is distributed in the hope that it will be useful,
25 * but WITHOUT ANY WARRANTY; without even the implied warranty of
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
27 * Lesser General Public License for more details.
28 *
29 * You should have received a copy of the GNU Lesser General Public
30 * License along with this library in the file COPYING.LIB;
31 * if not, write to the Free Software Foundation, Inc.,
32 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
33 *
34 * --------------------------------------------------------------------------
35 *
36 * Test Synopsis:
37 * - Test CV linked list management and serialisation.
38 *
39 * Test Method (Validation or Falsification):
40 * - Validation:
41 * Initiate and destroy several CVs in random order.
42 * Asynchronously traverse the CV list and broadcast.
43 *
44 * Requirements Tested:
45 * -
46 *
47 * Features Tested:
48 * -
49 *
50 * Cases Tested:
51 * -
52 *
53 * Description:
54 * - Creates and then imediately destroys a CV. Does not
55 * test the CV.
56 *
57 * Environment:
58 * -
59 *
60 * Input:
61 * - None.
62 *
63 * Output:
64 * - File name, Line number, and failed expression on failure.
65 * - No output on success.
66 *
67 * Assumptions:
68 * -
69 *
70 * Pass Criteria:
71 * - All initialised CVs destroyed without segfault.
72 * - Successfully broadcasts all remaining CVs after
73 * each CV is removed.
74 *
75 * Fail Criteria:
76 */
77
78 #include <stdlib.h>
79 #include "test.h"
80
81 enum {
82 NUM_CV = 5,
83 NUM_LOOPS = 5
84 };
85
86 static pthread_cond_t cv[NUM_CV];
87
88 int
main()89 main()
90 {
91 int i, j, k;
92 intptr_t result = 0;
93 pthread_t t;
94
95 for (k = 0; k < NUM_LOOPS; k++)
96 {
97 for (i = 0; i < NUM_CV; i++)
98 {
99 assert(pthread_cond_init(&cv[i], NULL) == 0);
100 }
101
102 j = NUM_CV;
103 (void) srand((unsigned)time(NULL));
104
105 /* Traverse the list asynchronously. */
106 assert(pthread_create(&t, NULL, pthread_timechange_handler_np, NULL) == 0);
107
108 do
109 {
110 i = (NUM_CV - 1) * rand() / RAND_MAX;
111 if (cv[i] != NULL)
112 {
113 j--;
114 assert(pthread_cond_destroy(&cv[i]) == 0);
115 }
116 }
117 while (j > 0);
118
119 assert(pthread_join(t, (void **) &result) == 0);
120 assert (result == 0);
121 }
122
123 return 0;
124 }
125