source: rtems/c/src/tests/psxtests/psx10/init.c @ 257adba

4.104.114.84.95
Last change on this file since 257adba was 257adba, checked in by Mark Johannes <Mark.Johannes@…>, on 08/23/96 at 15:17:16

Changed test 5 to test 10 at bottom

  • Property mode set to 100644
File size: 9.1 KB
Line 
1/*
2 *  COPYRIGHT (c) 1989, 1990, 1991, 1992, 1993, 1994.
3 *  On-Line Applications Research Corporation (OAR).
4 *  All rights assigned to U.S. Government, 1994.
5 *
6 *  This material may be reproduced by or for the U.S. Government pursuant
7 *  to the copyright license under the clause at DFARS 252.227-7013.  This
8 *  notice must appear in all copies of this file and its derivatives.
9 *
10 *  $Id$
11 */
12
13#define CONFIGURE_INIT
14#include "system.h"
15#include <sched.h>
16
17
18void *POSIX_Init(
19  void *argument
20)
21{
22  int                 status;
23  pthread_condattr_t  attr;
24  pthread_condattr_t  attr_error;
25  int                 pshared;
26  pthread_cond_t      cond;
27  struct timespec     timeout;
28
29  puts( "\n\n*** POSIX TEST 10 ***" );
30
31  puts( "Init: pthread_condattr_init" );
32  status = pthread_condattr_init( &attr );
33  assert( !status );
34
35  puts( "Init: pthread_condattr_init - EINVAL (attribute invalid)" );
36  status = pthread_condattr_init( NULL );
37  if ( status != EINVAL )
38    printf( "status = %d\n", status );
39  assert( status == EINVAL );
40
41  puts( "Init: pthread_condattr_destroy" );
42  status = pthread_condattr_destroy( &attr );
43  assert( !status );
44
45  puts( "Init: pthread_condattr_destroy - EINVAL (attribute invalid)" );
46  status = pthread_condattr_destroy( NULL );
47  if ( status != EINVAL )
48    printf( "status = %d\n", status );
49  assert( status == EINVAL );
50
51  puts( "Init: pthread_condattr_init" );
52  status = pthread_condattr_init( &attr );
53  assert( !status );
54
55  puts( "Init: pthread_condattr_setpshared - PTHREAD_PROCESS_SHARED" );
56  status = pthread_condattr_setpshared( &attr, PTHREAD_PROCESS_SHARED );
57  assert( !status );
58
59  puts( "Init: pthread_condattr_setpshared - PTHREAD_PROCESS_PRIVATE" );
60  status = pthread_condattr_setpshared( &attr, PTHREAD_PROCESS_PRIVATE );
61  assert( !status );
62
63  status = pthread_condattr_setpshared( NULL, PTHREAD_PROCESS_PRIVATE );
64  if ( status != EINVAL )
65    printf( "status = %d\n", status );
66  assert( status == EINVAL );
67  puts( "Init: pthread_condattr_setpshared - EINVAL (attribute invalid)" );
68
69  status = pthread_condattr_setpshared( &attr, 0xFFFFFF );
70  if ( status != EINVAL )
71    printf( "status = %d\n", status );
72  assert( status == EINVAL );
73  puts( "Init: pthread_condattr_setpshared - EINVAL (pshared invalid)" );
74
75  status = pthread_condattr_getpshared( &attr, &pshared );
76  assert( !status );
77  printf( "Init: pthread_condattr_getpshared - %d\n", pshared );
78
79  status = pthread_condattr_getpshared( NULL, &pshared );
80  if ( status != EINVAL )
81    printf( "status = %d\n", status );
82  assert( status == EINVAL );
83  puts( "Init: pthread_condattr_getpshared - EINVAL (attribute invalid)" );
84
85  puts( "Init: pthread_cond_init - NULL attr" );
86  status = pthread_cond_init( &cond, NULL );
87  assert( !status );
88
89/* error for attribute not initialized */
90
91  attr_error.is_initialized = FALSE;
92  status = pthread_cond_init( &cond, &attr_error );
93  if ( status != EINVAL )
94    printf( "status = %d\n", status );
95  assert( status == EINVAL );
96  puts( "Init: pthread_cond_init - EINVAL (attr not initialized)" );
97
98  status = pthread_cond_init( &cond, NULL );
99  if ( status != ENOMEM )
100    printf( "status = %d\n", status );
101  assert( status == ENOMEM );
102  puts( "Init: pthread_cond_init - ENOMEM (too many conds)" );
103
104  puts( "Init: pthread_cond_destroy" );
105  status = pthread_cond_destroy( &cond );
106  assert( !status );
107
108/* error for bad condition variable passed */
109
110  status = pthread_cond_destroy( NULL );
111  if ( status != EINVAL )
112    printf( "status = %d\n", status );
113  assert( status == EINVAL );
114  puts( "Init: pthread_cond_destroy - EINVAL (cond invalid)" );
115
116/* initiailize the attribute for the rest of the test */
117
118  puts( "Init: pthread_cond_init - attr" );
119  status = pthread_cond_init( &Cond1_id, &attr );
120  assert( !status );
121
122/* signal task1 with a condition variable */
123
124  empty_line();
125
126  status = pthread_create( &Task_id, NULL, Task_1, NULL );
127  assert( !status );
128
129/* switch to task1 to allow it to wait for a condition variable */
130
131  puts( "Init: sleep to switch to Task_1" );
132  sleep( 1 );
133
134  status = pthread_cond_destroy( &Cond1_id );
135  if ( status != EBUSY )
136    printf( "status = %d\n", status );
137  assert( status == EBUSY );
138  puts( "Init: pthread_cond_destroy - EBUSY (task1 waiting)" );
139
140  puts( "Init: pthread_cond_signal" );
141  status = pthread_cond_signal( &Cond1_id );
142  assert( !status );
143
144  empty_line();
145
146  status = pthread_create( &Task2_id, NULL, Task_2, NULL );
147  assert( !status );
148
149/* switch to task1 and task2 to allow them to wait for broadcast signal */
150
151  puts( "Init: sleep - switch to Task_1 and Task_2" );
152  sleep( 1 );
153
154/* broadcast a condition variable to task1 and task2 */
155
156  puts( "Init: pthread_cond_broadcast" );
157  status = pthread_cond_broadcast( &Cond1_id );
158  assert( !status );
159
160  puts( "Init: sleep - switch to Task_1" );
161  sleep( 0 );
162
163/* timedwait case - timeout */
164
165  status = pthread_mutex_lock( &Mutex_id );
166  assert( !status );
167
168/* set timeout to 3 seconds */
169
170  timeout.tv_sec = 3;
171  timeout.tv_nsec = 0;
172
173  puts( "Init: pthread_cond_timedwait for 3 seconds" );
174  status = pthread_cond_timedwait( &Cond1_id, &Mutex_id, &timeout );
175  if ( status != ETIMEDOUT )
176    printf( "status = %d\n", status );
177  assert( status == ETIMEDOUT );
178  puts( "Init: pthread_cond_timedwait - ETIMEDOUT - (mutex not acquired)" );
179
180/* remaining error messages */
181
182  empty_line();
183
184/* errors for bad variable passed */
185
186  status = pthread_cond_signal( NULL );
187  if ( status != EINVAL )
188    printf( "status = %d\n", status );
189  assert( status == EINVAL );
190  puts( "Init: pthread_cond_signal - EINVAL (cond invalid)" );
191
192  status = pthread_cond_broadcast( NULL );
193  if ( status != EINVAL )
194    printf( "status = %d\n", status );
195  assert( status == EINVAL );
196  puts( "Init: pthread_cond_broadcast - EINVAL (cond invalid)" );
197
198/* acquire mutex so errors will occur */
199
200  status = pthread_mutex_lock( &Mutex_id );
201  assert( !status );
202
203  status = pthread_cond_wait( NULL, &Mutex_id );
204  if ( status != EINVAL )
205    printf( "status = %d\n", status );
206  assert( status == EINVAL );
207  puts( "Init: pthread_cond_wait - EINVAL (cond invalid)" );
208
209  status = pthread_cond_timedwait( NULL, &Mutex_id, &timeout );
210  if ( status != EINVAL )
211    printf( "status = %d\n", status );
212  assert( status == EINVAL );
213  puts( "Init: pthread_cond_timedwait - EINVAL (cond invalid)" );
214
215  status = pthread_cond_wait( &Cond1_id, NULL );
216  if ( status != EINVAL )
217    printf( "status = %d\n", status );
218  assert( status == EINVAL );
219  puts( "Init: pthread_cond_wait - EINVAL (mutex invalid)" );
220 
221  status = pthread_cond_timedwait( &Cond1_id, NULL, &timeout );
222  if ( status != EINVAL )
223    printf( "status = %d\n", status );
224  assert( status == EINVAL );
225  puts( "Init: pthread_cond_timedwait - EINVAL (mutex invalid)" );
226
227  status = pthread_cond_timedwait( &Cond1_id, &Mutex_id, NULL );
228  if ( status != EINVAL )
229    printf( "status = %d\n", status );
230  assert( status == EINVAL );
231  puts( "Init: pthread_cond_timedwait - EINVAL (abstime NULL)" );
232
233  timeout.tv_sec = -1;
234  status = pthread_cond_timedwait( &Cond1_id, &Mutex_id, &timeout );
235  if ( status != EINVAL )
236    printf( "status = %d\n", status );
237  assert( status == EINVAL );
238  puts( "Init: pthread_cond_timedwait - EINVAL (abstime->tv_sec invalid)" );
239
240  timeout.tv_sec = 2;
241  timeout.tv_nsec = -1;
242  status = pthread_cond_timedwait( &Cond1_id, &Mutex_id, &timeout );
243  if ( status != EINVAL )
244    printf( "status = %d\n", status );
245  assert( status == EINVAL );
246  puts( "Init: pthread_cond_timedwait - EINVAL (abstime->tv_nsec invalid)" );
247
248  timeout.tv_sec = 2;
249  timeout.tv_nsec = 2;
250  timeout.tv_nsec = 0x7FFFFFFF;
251  status = pthread_cond_timedwait( &Cond1_id, &Mutex_id, &timeout );
252  if ( status != EINVAL )
253    printf( "status = %d\n", status );
254  assert( status == EINVAL );
255  puts( "Init: pthread_cond_timedwait - EINVAL (abstime->tv_nsec to large)" );
256
257/* unlock mutex for rest of test */
258
259  status = pthread_mutex_unlock( &Mutex_id );
260  assert( !status );
261
262/* wait and timedwait without mutex */
263
264/* XXX - this case is commented out in the code pending review
265 *
266 *   status = pthread_cond_wait( &Cond1_id, &Mutex_id );
267 *   if ( status != EINVAL )
268 *     printf( "status = %d\n", status );
269 *   assert( status == EINVAL );
270 */
271  puts( "Init: pthread_cond_wait - EINVAL (mutex not locked before call)" );
272
273  status = pthread_cond_timedwait( &Cond1_id, &Mutex_id, &timeout );
274  if ( status != EINVAL )
275    printf( "status = %d\n", status );
276  assert( status == EINVAL );
277  puts( "Init: pthread_cond_timedwait - EINVAL (mutex not locked before call)");
278
279  empty_line();
280
281  status = pthread_create( &Task3_id, NULL, Task_3, NULL );
282  assert( !status );
283
284/* switch to task3 to allow it to wait for broadcast signal */
285
286  puts( "Init: sleep - switch to Task_3" );
287  sleep( 1 );
288
289/* destroy the mutex so Task3 can not acguire at the end of Wait_support */
290
291  status = pthread_mutex_destroy( &Mutex_id );
292  assert( !status );
293
294/* signal a condition variable to task3 */
295
296  puts( "Init: pthread_cond_signal" );
297  status = pthread_cond_signal( &Cond1_id );
298
299  puts( "Init: sleep - switch to Task_3" );
300  sleep( 1 );
301
302  puts( "*** END OF POSIX TEST 10 ***" );
303  exit( 0 );
304
305  return NULL; /* just so the compiler thinks we returned something */
306}
Note: See TracBrowser for help on using the repository browser.