source: rtems/c/src/tests/itrontests/itronsem01/init.c @ 9d9a3dd

4.104.114.84.95
Last change on this file since 9d9a3dd was 9d9a3dd, checked in by Jennifer Averett <Jennifer.Averett@…>, on 11/17/99 at 16:47:58

+ Updated copyright information.

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