1 |
1026 |
ivang |
/* 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 |
|
|
* init.c,v 1.4 2002/08/02 00:53:37 joel Exp
|
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 |
|
|
|
40 |
|
|
void 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.sematr = 0;
|
58 |
|
|
pk_csem.isemcnt = 3;
|
59 |
|
|
pk_csem.maxsem = 2;
|
60 |
|
|
status = cre_sem( 1, &pk_csem );
|
61 |
|
|
assert( status == E_PAR );
|
62 |
|
|
|
63 |
|
|
puts( "Init - cre_sem - maxsem of 0 returns E_PAR" );
|
64 |
|
|
pk_csem.isemcnt = 0;
|
65 |
|
|
pk_csem.maxsem = 0;
|
66 |
|
|
status = cre_sem( 1, &pk_csem );
|
67 |
|
|
assert( status == E_PAR );
|
68 |
|
|
|
69 |
|
|
/*
|
70 |
|
|
* Now run through all the bad ID errors
|
71 |
|
|
*/
|
72 |
|
|
|
73 |
|
|
pk_csem.isemcnt = 2;
|
74 |
|
|
pk_csem.maxsem = 3;
|
75 |
|
|
puts( "Init - cre_sem - bad id (less than -4) - E_OACV" );
|
76 |
|
|
status = cre_sem( -5, &pk_csem );
|
77 |
|
|
assert( status == E_OACV );
|
78 |
|
|
|
79 |
|
|
puts( "Init - cre_sem - bad id (between 0 and -4) - E_ID" );
|
80 |
|
|
status = cre_sem( -4, &pk_csem );
|
81 |
|
|
assert( status == E_ID );
|
82 |
|
|
|
83 |
|
|
puts( "Init - cre_sem - bad id (0) - E_ID" );
|
84 |
|
|
status = cre_sem( 0, &pk_csem );
|
85 |
|
|
assert( status == E_ID );
|
86 |
|
|
|
87 |
|
|
puts( "Init - cre_sem - bad id (too great) - E_ID" );
|
88 |
|
|
status = cre_sem( CONFIGURE_MAXIMUM_ITRON_SEMAPHORES + 1, &pk_csem );
|
89 |
|
|
assert( status == E_ID );
|
90 |
|
|
|
91 |
|
|
puts( "Init - cre_sem - create semaphore 1 TA_TFIFO - E_OK" );
|
92 |
|
|
pk_csem.isemcnt = 2;
|
93 |
|
|
pk_csem.maxsem = 3;
|
94 |
|
|
pk_csem.sematr = TA_TFIFO;
|
95 |
|
|
status = cre_sem( 1, &pk_csem );
|
96 |
|
|
assert( status == E_OK );
|
97 |
|
|
|
98 |
|
|
puts( "Init - cre_sem - create semaphore 1 again - E_OBJ" );
|
99 |
|
|
status = cre_sem( 1, &pk_csem );
|
100 |
|
|
assert( status == E_OBJ );
|
101 |
|
|
|
102 |
|
|
puts( "Init - cre_sem - create semaphore 2 TA_TPRI - E_OK" );
|
103 |
|
|
pk_csem.isemcnt = 2;
|
104 |
|
|
pk_csem.maxsem = 3;
|
105 |
|
|
pk_csem.sematr = TA_TPRI;
|
106 |
|
|
status = cre_sem( 2, &pk_csem );
|
107 |
|
|
assert( status == E_OK );
|
108 |
|
|
|
109 |
|
|
/*
|
110 |
|
|
* Generate all the bad id errors for del_sem
|
111 |
|
|
*/
|
112 |
|
|
|
113 |
|
|
puts( "Init - del_sem - bad id (less than -4) - E_OACV" );
|
114 |
|
|
status = del_sem( -5 );
|
115 |
|
|
assert( status == E_OACV );
|
116 |
|
|
|
117 |
|
|
puts( "Init - del_sem - bad id (between 0 and -4) - E_ID" );
|
118 |
|
|
status = del_sem( -4 );
|
119 |
|
|
assert( status == E_ID );
|
120 |
|
|
|
121 |
|
|
puts( "Init - del_sem - bad id (0) - E_ID" );
|
122 |
|
|
status = del_sem( 0 );
|
123 |
|
|
assert( status == E_ID );
|
124 |
|
|
|
125 |
|
|
puts( "Init - del_sem - bad id (too great) - E_ID" );
|
126 |
|
|
status = del_sem( CONFIGURE_MAXIMUM_ITRON_SEMAPHORES + 1 );
|
127 |
|
|
assert( status == E_ID );
|
128 |
|
|
|
129 |
|
|
/*
|
130 |
|
|
* Generate all the bad id errors for sig_sem
|
131 |
|
|
*/
|
132 |
|
|
|
133 |
|
|
puts( "Init - sig_sem - bad id (less than -4) - E_OACV" );
|
134 |
|
|
status = sig_sem( -5 );
|
135 |
|
|
assert( status == E_OACV );
|
136 |
|
|
|
137 |
|
|
puts( "Init - sig_sem - bad id (between 0 and -4) - E_ID" );
|
138 |
|
|
status = sig_sem( -4 );
|
139 |
|
|
assert( status == E_ID );
|
140 |
|
|
|
141 |
|
|
puts( "Init - sig_sem - bad id (0) - E_ID" );
|
142 |
|
|
status = sig_sem( 0 );
|
143 |
|
|
assert( status == E_ID );
|
144 |
|
|
|
145 |
|
|
puts( "Init - sig_sem - bad id (too great) - E_ID" );
|
146 |
|
|
status = wai_sem( CONFIGURE_MAXIMUM_ITRON_SEMAPHORES + 1 );
|
147 |
|
|
assert( status == E_ID );
|
148 |
|
|
|
149 |
|
|
/*
|
150 |
|
|
* Generate all the bad id errors for preq_sem
|
151 |
|
|
*/
|
152 |
|
|
|
153 |
|
|
puts( "Init - preq_sem - bad id (less than -4) - E_OACV" );
|
154 |
|
|
status = preq_sem( -5 );
|
155 |
|
|
assert( status == E_OACV );
|
156 |
|
|
|
157 |
|
|
puts( "Init - preq_sem - bad id (between 0 and -4) - E_ID" );
|
158 |
|
|
status = preq_sem( -4 );
|
159 |
|
|
assert( status == E_ID );
|
160 |
|
|
|
161 |
|
|
puts( "Init - preq_sem - bad id (0) - E_ID" );
|
162 |
|
|
status = preq_sem( 0 );
|
163 |
|
|
assert( status == E_ID );
|
164 |
|
|
|
165 |
|
|
puts( "Init - preq_sem - bad id (too great) - E_ID" );
|
166 |
|
|
status = preq_sem( CONFIGURE_MAXIMUM_ITRON_SEMAPHORES + 1 );
|
167 |
|
|
assert( status == E_ID );
|
168 |
|
|
|
169 |
|
|
/*
|
170 |
|
|
* Generate all the bad id errors for wai_sem
|
171 |
|
|
*/
|
172 |
|
|
|
173 |
|
|
puts( "Init - wai_sem - bad id (less than -4) - E_OACV" );
|
174 |
|
|
status = wai_sem( -5 );
|
175 |
|
|
assert( status == E_OACV );
|
176 |
|
|
|
177 |
|
|
puts( "Init - wai_sem - bad id (between 0 and -4) - E_ID" );
|
178 |
|
|
status = wai_sem( -4 );
|
179 |
|
|
assert( status == E_ID );
|
180 |
|
|
|
181 |
|
|
puts( "Init - wai_sem - bad id (0) - E_ID" );
|
182 |
|
|
status = wai_sem( 0 );
|
183 |
|
|
assert( status == E_ID );
|
184 |
|
|
|
185 |
|
|
puts( "Init - wai_sem - bad id (too great) - E_ID" );
|
186 |
|
|
status = wai_sem( CONFIGURE_MAXIMUM_ITRON_SEMAPHORES + 1 );
|
187 |
|
|
assert( status == E_ID );
|
188 |
|
|
|
189 |
|
|
/*
|
190 |
|
|
* Generate all the bad id errors for twai_sem
|
191 |
|
|
*/
|
192 |
|
|
|
193 |
|
|
puts( "Init - twai_sem - bad id (less than -4) - E_OACV" );
|
194 |
|
|
status = twai_sem( -5, 1000 );
|
195 |
|
|
assert( status == E_OACV );
|
196 |
|
|
|
197 |
|
|
puts( "Init - twai_sem - bad id (between 0 and -4) - E_ID" );
|
198 |
|
|
status = twai_sem( -4, 1000 );
|
199 |
|
|
assert( status == E_ID );
|
200 |
|
|
|
201 |
|
|
puts( "Init - twai_sem - bad id (0) - E_ID" );
|
202 |
|
|
status = twai_sem( 0, 1000 );
|
203 |
|
|
assert( status == E_ID );
|
204 |
|
|
|
205 |
|
|
puts( "Init - twai_sem - bad id (too great) - E_ID" );
|
206 |
|
|
status = twai_sem( CONFIGURE_MAXIMUM_ITRON_SEMAPHORES + 1, 1000 );
|
207 |
|
|
assert( status == E_ID );
|
208 |
|
|
|
209 |
|
|
/*
|
210 |
|
|
* Generate all the bad id errors for ref_sem
|
211 |
|
|
*/
|
212 |
|
|
|
213 |
|
|
puts( "Init - ref_sem - bad id (less than -4) - E_OACV" );
|
214 |
|
|
status = ref_sem( -5, &pk_rsem );
|
215 |
|
|
assert( status == E_OACV );
|
216 |
|
|
|
217 |
|
|
puts( "Init - ref_sem - bad id (between 0 and -4) - E_ID" );
|
218 |
|
|
status = ref_sem( -4, &pk_rsem );
|
219 |
|
|
assert( status == E_ID );
|
220 |
|
|
|
221 |
|
|
puts( "Init - ref_sem - bad id (0) - E_ID" );
|
222 |
|
|
status = ref_sem( 0, &pk_rsem );
|
223 |
|
|
assert( status == E_ID );
|
224 |
|
|
|
225 |
|
|
puts( "Init - ref_sem - bad id (too great) - E_ID" );
|
226 |
|
|
status = ref_sem( CONFIGURE_MAXIMUM_ITRON_SEMAPHORES + 1, &pk_rsem );
|
227 |
|
|
assert( status == E_ID );
|
228 |
|
|
|
229 |
|
|
/*
|
230 |
|
|
* Exercise preq_sem (and sig_sem a little)
|
231 |
|
|
*/
|
232 |
|
|
|
233 |
|
|
|
234 |
|
|
puts( "Init - preq_sem - semaphore 1 available (count --> 1) - E_OK" );
|
235 |
|
|
status = preq_sem( 1 );
|
236 |
|
|
assert( status == E_OK );
|
237 |
|
|
|
238 |
|
|
puts( "Init - preq_sem - semaphore 1 available (count --> 0) - E_OK" );
|
239 |
|
|
status = preq_sem( 1 );
|
240 |
|
|
assert( status == E_OK );
|
241 |
|
|
|
242 |
|
|
puts( "Init - preq_sem - semaphore 1 unavailable - E_TMOUT" );
|
243 |
|
|
status = preq_sem( 1 );
|
244 |
|
|
assert( status == E_TMOUT );
|
245 |
|
|
|
246 |
|
|
puts( "Init - sig_sem - semaphore 1 (count --> 1) - E_OK" );
|
247 |
|
|
status = sig_sem( 1 );
|
248 |
|
|
assert( status == E_OK );
|
249 |
|
|
|
250 |
|
|
puts("Init - twai_sem(TMO_POL) - semaphore 1 available (count --> 0) - E_OK");
|
251 |
|
|
status = twai_sem( 1, TMO_POL );
|
252 |
|
|
assert( status == E_OK );
|
253 |
|
|
|
254 |
|
|
puts( "Init - twai_sem(TMO_POL) - semaphore 1 available - E_TMOUT" );
|
255 |
|
|
status = twai_sem( 1, TMO_POL );
|
256 |
|
|
assert( status == E_TMOUT );
|
257 |
|
|
|
258 |
|
|
/*
|
259 |
|
|
* Exercise twai_sem
|
260 |
|
|
*/
|
261 |
|
|
|
262 |
|
|
puts( "Init - twai_sem - semaphore 1 unavailable - 1 second E_TMOUT" );
|
263 |
|
|
put_time( "Init - starting to block at ");
|
264 |
|
|
status = twai_sem( 1, 1000 );
|
265 |
|
|
assert( status == E_TMOUT );
|
266 |
|
|
put_time( "Init - timed out at ");
|
267 |
|
|
puts( "Init - twai_sem - semaphore 1 unavailable - timeout completed" );
|
268 |
|
|
|
269 |
|
|
/*
|
270 |
|
|
* Now let's test exceed the maximum count of semaphore 1
|
271 |
|
|
*/
|
272 |
|
|
|
273 |
|
|
puts( "Init - sig_sem - semaphore 1 (count --> 1) - E_OK" );
|
274 |
|
|
status = sig_sem( 1 );
|
275 |
|
|
assert( status == E_OK );
|
276 |
|
|
|
277 |
|
|
puts( "Init - sig_sem - semaphore 1 (count --> 2) - E_OK" );
|
278 |
|
|
status = sig_sem( 1 );
|
279 |
|
|
assert( status == E_OK );
|
280 |
|
|
|
281 |
|
|
puts( "Init - sig_sem - semaphore 1 (count --> 3) - E_OK" );
|
282 |
|
|
status = sig_sem( 1 );
|
283 |
|
|
assert( status == E_OK );
|
284 |
|
|
|
285 |
|
|
puts( "Init - sig_sem - semaphore 1 (count > maximum) - E_QOVR" );
|
286 |
|
|
status = sig_sem( 1 );
|
287 |
|
|
assert( status == E_OK );
|
288 |
|
|
|
289 |
|
|
/*
|
290 |
|
|
* Exercise ref_sem
|
291 |
|
|
*/
|
292 |
|
|
|
293 |
|
|
puts( "Init - ref_sem - NULL pk_sem returns E_PAR" );
|
294 |
|
|
status = ref_sem( 1, NULL );
|
295 |
|
|
assert( status == E_PAR );
|
296 |
|
|
|
297 |
|
|
puts( "Init - ref_sem - semaphore 1 - E_OK" );
|
298 |
|
|
status = ref_sem( 1, &pk_rsem );
|
299 |
|
|
assert( status == E_OK );
|
300 |
|
|
printf( "Init - semaphore 1 count = %d\n", pk_rsem.semcnt );
|
301 |
|
|
printf( "Init - semaphore 1 waiting tasks = %d\n", pk_rsem.wtsk );
|
302 |
|
|
|
303 |
|
|
puts( "Init - preq_sem - semaphore 1 (count --> 2) - E_OK" );
|
304 |
|
|
status = preq_sem( 1 );
|
305 |
|
|
assert( status == E_OK );
|
306 |
|
|
|
307 |
|
|
puts( "Init - ref_sem - semaphore 1 - E_OK" );
|
308 |
|
|
status = ref_sem( 1, &pk_rsem );
|
309 |
|
|
assert( status == E_OK );
|
310 |
|
|
printf( "Init - semaphore 1 count = %d\n", pk_rsem.semcnt );
|
311 |
|
|
printf( "Init - semaphore 1 waiting tasks = %d\n", pk_rsem.wtsk );
|
312 |
|
|
|
313 |
|
|
|
314 |
|
|
/*
|
315 |
|
|
* Exercise del_sem
|
316 |
|
|
*/
|
317 |
|
|
|
318 |
|
|
/* XXX really want another task blocking on the semaphore XXX */
|
319 |
|
|
|
320 |
|
|
puts( "Init - del_sem - semaphore 1 deleted - E_OK" );
|
321 |
|
|
status = del_sem( 1 );
|
322 |
|
|
assert( status == E_OK );
|
323 |
|
|
|
324 |
|
|
puts( "Init - XXX need other tasks to complete the test XXX" );
|
325 |
|
|
|
326 |
|
|
puts( "Init - dly_tsk - 1 second to let other task run" );
|
327 |
|
|
status = dly_tsk( 1000 );
|
328 |
|
|
assert( status == E_OK );
|
329 |
|
|
|
330 |
|
|
printf( "*** END OF ITRONSEM01 -- ITRON SEMAPHORE TEST ***\n" );
|
331 |
|
|
rtems_test_exit( 0 );
|
332 |
|
|
}
|