source: rtems/testsuites/itrontests/itronsem01/init.c @ ac0ba84

4.104.114.84.95
Last change on this file since ac0ba84 was 352c9b2, checked in by Joel Sherrill <joel.sherrill@…>, on Nov 9, 1999 at 10:07:23 PM

This patch adds the basic framework for the ITRON 3.0 API implementation
for RTEMS.

  • Property mode set to 100644
File size: 8.8 KB
Line 
1/*  Init
2 *
3 *  This routine is the initialization task for this test program.
4 *  It is called from init_exec and has the responsibility for creating
5 *  and starting the tasks that make up the test.  If the time of day
6 *  clock is required for the test, it should also be set to a known
7 *  value by this function.
8 *
9 *  Input parameters:  NONE
10 *
11 *  Output parameters:  NONE
12 *
13 *  The license and distribution terms for this file may be
14 *  found in the file LICENSE in this distribution or at
15 *  http://www.OARcorp.com/rtems/license.html.
16 *
17 *  $Id$
18 */
19
20#define TEST_INIT
21#include "system.h"
22#include <stdio.h>
23
24/*
25 *  The following is hopefully temporary.
26 */
27
28#include <time.h>
29
30#define put_time(_s) \
31  do { \
32    time_t a_time_t; \
33    a_time_t = time( 0 ); \
34    printf( "%s%s", _s, ctime( &a_time_t ) ); \
35  } while(0)
36
37void ITRON_Init( void )
38{
39  ER      status;
40  T_CSEM  pk_csem;
41  T_RSEM  pk_rsem;
42
43  printf( "\n\n*** ITRONSEM01 -- ITRON SEMAPHORE TEST ***\n" );
44
45  /*
46   *  Exercise cre_sem - this code seems to exercise every path.
47   */
48
49  puts( "Init - cre_sem - NULL pk_sem returns E_PAR" );
50  status = cre_sem( 1, NULL );
51  assert( status == E_PAR );
52
53  puts( "Init - cre_sem - isemcnt > maxsem returns E_PAR" );
54  pk_csem.isemcnt = 3;
55  pk_csem.maxsem  = 2;
56  status = cre_sem( 1, &pk_csem );
57  assert( status == E_PAR );
58
59  puts( "Init - cre_sem - maxsem of 0 returns E_PAR" );
60  pk_csem.isemcnt = 0;
61  pk_csem.maxsem  = 0;
62  status = cre_sem( 1, &pk_csem );
63  assert( status == E_PAR );
64
65  /*
66   *  Now run through all the bad ID errors
67   */
68
69  pk_csem.isemcnt = 2;
70  pk_csem.maxsem  = 3;
71  puts( "Init - cre_sem - bad id (less than -4) - E_OACV" );
72  status = cre_sem( -5, &pk_csem );
73  assert( status == E_OACV );
74
75  puts( "Init - cre_sem - bad id (between 0 and -4) - E_ID" );
76  status = cre_sem( -4, &pk_csem );
77  assert( status == E_ID );
78
79  puts( "Init - cre_sem - bad id (0) - E_ID" );
80  status = cre_sem( 0, &pk_csem );
81  assert( status == E_ID );
82
83  puts( "Init - cre_sem - bad id (too great) - E_ID" );
84  status = cre_sem( CONFIGURE_MAXIMUM_ITRON_SEMAPHORES + 1, &pk_csem );
85  assert( status == E_ID );
86
87  puts( "Init - cre_sem - create semaphore 1 TA_TFIFO - E_OK" );
88  pk_csem.isemcnt = 2;
89  pk_csem.maxsem  = 3;
90  pk_csem.sematr  = TA_TFIFO;
91  status = cre_sem( 1, &pk_csem );
92  assert( status == E_OK );
93
94  puts( "Init - cre_sem - create semaphore 1 again - E_OBJ" );
95  status = cre_sem( 1, &pk_csem );
96  assert( status == E_OBJ );
97
98  puts( "Init - cre_sem - create semaphore 2 TA_TPRI - E_OK" );
99  pk_csem.isemcnt = 2;
100  pk_csem.maxsem  = 3;
101  pk_csem.sematr  = TA_TPRI;
102  status = cre_sem( 2, &pk_csem );
103  assert( status == E_OK );
104
105  /*
106   *  Generate all the bad id errors for del_sem
107   */
108
109  puts( "Init - del_sem - bad id (less than -4) - E_OACV" );
110  status = del_sem( -5 );
111  assert( status == E_OACV );
112
113  puts( "Init - del_sem - bad id (between 0 and -4) - E_ID" );
114  status = del_sem( -4 );
115  assert( status == E_ID );
116
117  puts( "Init - del_sem - bad id (0) - E_ID" );
118  status = del_sem( 0 );
119  assert( status == E_ID );
120
121  puts( "Init - del_sem - bad id (too great) - E_ID" );
122  status = del_sem( CONFIGURE_MAXIMUM_ITRON_SEMAPHORES + 1 );
123  assert( status == E_ID );
124
125  /*
126   *  Generate all the bad id errors for sig_sem
127   */
128
129  puts( "Init - sig_sem - bad id (less than -4) - E_OACV" );
130  status = sig_sem( -5 );
131  assert( status == E_OACV );
132
133  puts( "Init - sig_sem - bad id (between 0 and -4) - E_ID" );
134  status = sig_sem( -4 );
135  assert( status == E_ID );
136
137  puts( "Init - sig_sem - bad id (0) - E_ID" );
138  status = sig_sem( 0 );
139  assert( status == E_ID );
140
141  puts( "Init - sig_sem - bad id (too great) - E_ID" );
142  status = wai_sem( CONFIGURE_MAXIMUM_ITRON_SEMAPHORES + 1 );
143  assert( status == E_ID );
144
145  /*
146   *  Generate all the bad id errors for preq_sem
147   */
148
149  puts( "Init - preq_sem - bad id (less than -4) - E_OACV" );
150  status = preq_sem( -5 );
151  assert( status == E_OACV ); 
152 
153  puts( "Init - preq_sem - bad id (between 0 and -4) - E_ID" );
154  status = preq_sem( -4 );
155  assert( status == E_ID );
156
157  puts( "Init - preq_sem - bad id (0) - E_ID" );
158  status = preq_sem( 0 );
159  assert( status == E_ID );
160
161  puts( "Init - preq_sem - bad id (too great) - E_ID" );
162  status = preq_sem( CONFIGURE_MAXIMUM_ITRON_SEMAPHORES + 1 );
163  assert( status == E_ID );
164
165  /*
166   *  Generate all the bad id errors for wai_sem
167   */
168
169  puts( "Init - wai_sem - bad id (less than -4) - E_OACV" );
170  status = wai_sem( -5 );
171  assert( status == E_OACV );
172
173  puts( "Init - wai_sem - bad id (between 0 and -4) - E_ID" );
174  status = wai_sem( -4 );
175  assert( status == E_ID );
176
177  puts( "Init - wai_sem - bad id (0) - E_ID" );
178  status = wai_sem( 0 );
179  assert( status == E_ID );
180
181  puts( "Init - wai_sem - bad id (too great) - E_ID" );
182  status = wai_sem( CONFIGURE_MAXIMUM_ITRON_SEMAPHORES + 1 );
183  assert( status == E_ID );
184
185  /*
186   *  Generate all the bad id errors for twai_sem
187   */
188
189  puts( "Init - twai_sem - bad id (less than -4) - E_OACV" );
190  status = twai_sem( -5, 1000 );
191  assert( status == E_OACV );
192
193  puts( "Init - twai_sem - bad id (between 0 and -4) - E_ID" );
194  status = twai_sem( -4, 1000 );
195  assert( status == E_ID );
196
197  puts( "Init - twai_sem - bad id (0) - E_ID" );
198  status = twai_sem( 0, 1000 );
199  assert( status == E_ID );
200
201  puts( "Init - twai_sem - bad id (too great) - E_ID" );
202  status = twai_sem( CONFIGURE_MAXIMUM_ITRON_SEMAPHORES + 1, 1000 );
203  assert( status == E_ID );
204
205  /*
206   *  Generate all the bad id errors for ref_sem
207   */
208
209  puts( "Init - ref_sem - bad id (less than -4) - E_OACV" );
210  status = ref_sem( -5, &pk_rsem );
211  assert( status == E_OACV );
212
213  puts( "Init - ref_sem - bad id (between 0 and -4) - E_ID" );
214  status = ref_sem( -4, &pk_rsem );
215  assert( status == E_ID );
216
217  puts( "Init - ref_sem - bad id (0) - E_ID" );
218  status = ref_sem( 0, &pk_rsem );
219  assert( status == E_ID );
220
221  puts( "Init - ref_sem - bad id (too great) - E_ID" );
222  status = ref_sem( CONFIGURE_MAXIMUM_ITRON_SEMAPHORES + 1, &pk_rsem );
223  assert( status == E_ID );
224
225  /*
226   *  Exercise preq_sem (and sig_sem a little)
227   */
228
229
230  puts( "Init - preq_sem - semaphore 1 available (count --> 1) - E_OK" );
231  status = preq_sem( 1 );
232  assert( status == E_OK );
233
234  puts( "Init - preq_sem - semaphore 1 available (count --> 0) - E_OK" );
235  status = preq_sem( 1 );
236  assert( status == E_OK );
237
238  puts( "Init - preq_sem - semaphore 1 unavailable - E_TMOUT" );
239  status = preq_sem( 1 );
240  assert( status == E_TMOUT );
241
242  puts( "Init - sig_sem - semaphore 1 (count --> 1) - E_OK" );
243  status = sig_sem( 1 );
244  assert( status == E_OK );
245
246  puts("Init - twai_sem(TMO_POL) - semaphore 1 available (count --> 0) - E_OK");
247  status = twai_sem( 1, TMO_POL );
248  assert( status == E_OK );
249
250  puts( "Init - twai_sem(TMO_POL) - semaphore 1 available - E_TMOUT" );
251  status = twai_sem( 1, TMO_POL );
252  assert( status == E_TMOUT );
253
254  /*
255   *  Exercise twai_sem
256   */
257
258  puts( "Init - twai_sem - semaphore 1 unavailable - 1 second E_TMOUT" );
259  put_time( "Init - starting to block at ");
260  status = twai_sem( 1, 1000 );
261  assert( status == E_TMOUT );
262  put_time( "Init - timed out at ");
263  puts( "Init - twai_sem - semaphore 1 unavailable - timeout completed" );
264
265  /*
266   *  Now let's test exceed the maximum count of semaphore 1
267   */
268
269  puts( "Init - sig_sem - semaphore 1 (count --> 1) - E_OK" );
270  status = sig_sem( 1 );
271  assert( status == E_OK );
272
273  puts( "Init - sig_sem - semaphore 1 (count --> 2) - E_OK" );
274  status = sig_sem( 1 );
275  assert( status == E_OK );
276
277  puts( "Init - sig_sem - semaphore 1 (count --> 3) - E_OK" );
278  status = sig_sem( 1 );
279  assert( status == E_OK );
280
281  puts( "Init - sig_sem - semaphore 1 (count > maximum) - E_QOVR" );
282  status = sig_sem( 1 );
283  assert( status == E_OK );
284
285  /*
286   *  Exercise ref_sem
287   */
288
289  puts( "Init - ref_sem - NULL pk_sem returns E_PAR" );
290  status = ref_sem( 1, NULL );
291  assert( status == E_PAR );
292
293  puts( "Init - ref_sem - semaphore 1 - E_OK" );
294  status = ref_sem( 1, &pk_rsem );
295  assert( status == E_OK );
296  printf( "Init - semaphore 1 count = %d\n", pk_rsem.semcnt );
297  printf( "Init - semaphore 1 waiting tasks = %d\n", pk_rsem.wtsk );
298
299  puts( "Init - preq_sem - semaphore 1 (count --> 2) - E_OK" );
300  status = preq_sem( 1 );
301  assert( status == E_OK );
302
303  puts( "Init - ref_sem - semaphore 1 - E_OK" );
304  status = ref_sem( 1, &pk_rsem );
305  assert( status == E_OK );
306  printf( "Init - semaphore 1 count = %d\n", pk_rsem.semcnt );
307  printf( "Init - semaphore 1 waiting tasks = %d\n", pk_rsem.wtsk );
308
309
310  /*
311   *  Exercise del_sem
312   */
313
314  /* XXX really want another task blocking on the semaphore XXX */
315
316  puts( "Init - del_sem - semaphore 1 deleted - E_OK" );
317  status = del_sem( 1 );
318  assert( status == E_OK );
319
320  puts( "Init - XXX need other tasks to complete the test XXX" );
321
322  puts( "Init - dly_tsk - 1 second to let other task run" );
323  status = dly_tsk( 1000 );
324  assert( status == E_OK );
325
326  printf( "*** END OF ITRONSEM01 -- ITRON SEMAPHORE TEST ***\n" );
327  exit( 0 );
328}
Note: See TracBrowser for help on using the repository browser.