source: rtems/testsuites/psxtests/psx10/init.c @ 645fc954

4.104.114.84.95
Last change on this file since 645fc954 was c9c94387, checked in by Mark Johannes <Mark.Johannes@…>, on 08/13/96 at 19:05:27

Init.c: added timewait case, added broadcast case

  • Property mode set to 100644
File size: 4.3 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_t           thread_id;
24  pthread_condattr_t  attr;
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" );
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" );
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 - attr" );
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" );
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" );
84
85  puts( "Init: pthread_cond_init - NULL attr" );
86  status = pthread_cond_init( &cond, NULL );
87  assert( !status );
88
89  puts( "Init: pthread_cond_destroy" );
90  status = pthread_cond_destroy( &cond );
91  assert( !status );
92
93/* initiailize the attribute for the rest of the test */
94
95  puts( "Init: pthread_cond_init - attr" );
96  status = pthread_cond_init( &Cond1_id, &attr );
97  assert( !status );
98
99/* signal task1 with a condition variable */
100
101  empty_line();
102
103  status = pthread_create( &Task_id, NULL, Task_1, NULL );
104  assert( !status );
105
106/* switch to task1 to allow it to wait for a condition variable */
107
108  puts( "Init: sleep to switch to Task_1" );
109  sleep( 1 );
110
111  puts( "Init: pthread_cond_signal" );
112  status = pthread_cond_signal( &Cond1_id );
113  assert( !status );
114
115  empty_line();
116
117  status = pthread_create( &Task2_id, NULL, Task_2, NULL );
118  assert( !status );
119
120/* switch to task1 and task2 to allow them to wait for broadcast signal */
121
122  puts( "Init: sleep - switch to Task_1 and Task_2" );
123  sleep( 1 );
124
125/* broadcast a condition variable to task1 and task2 */
126
127  puts( "Init: pthread_cond_broadcast" );
128  status = pthread_cond_broadcast( &Cond1_id );
129  assert( !status );
130
131  puts( "Init: sleep - switch to Task_1" );
132  sleep( 0 );
133
134/* timedwait case - timeout */
135
136  status = pthread_mutex_lock( &Mutex_id );
137  assert( !status );
138
139/* set timeout to 3 seconds */
140
141  timeout.tv_sec = 3;
142
143  puts( "Init: pthread_cond_timedwait for 3 seconds" );
144  status = pthread_cond_timedwait( &Cond1_id, &Mutex_id, &timeout );
145  if ( status != ETIMEDOUT )
146    printf( "status = %d\n", status );
147  assert( status == ETIMEDOUT );
148
149  puts( "Init: timedout on pthread_cond_timedwait release mutex" );
150  /* exit this thread */
151
152  puts( "*** END OF POSIX TEST 5 ***" );
153  exit( 0 );
154
155  return NULL; /* just so the compiler thinks we returned something */
156}
Note: See TracBrowser for help on using the repository browser.