1 |
1254 |
phoenix |
//===========================================================================
|
2 |
|
|
//
|
3 |
|
|
// testcx7.cxx
|
4 |
|
|
//
|
5 |
|
|
// uITRON "C++" test program seven
|
6 |
|
|
//
|
7 |
|
|
//===========================================================================
|
8 |
|
|
//####ECOSGPLCOPYRIGHTBEGIN####
|
9 |
|
|
// -------------------------------------------
|
10 |
|
|
// This file is part of eCos, the Embedded Configurable Operating System.
|
11 |
|
|
// Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
|
12 |
|
|
//
|
13 |
|
|
// eCos is free software; you can redistribute it and/or modify it under
|
14 |
|
|
// the terms of the GNU General Public License as published by the Free
|
15 |
|
|
// Software Foundation; either version 2 or (at your option) any later version.
|
16 |
|
|
//
|
17 |
|
|
// eCos is distributed in the hope that it will be useful, but WITHOUT ANY
|
18 |
|
|
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
19 |
|
|
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
20 |
|
|
// for more details.
|
21 |
|
|
//
|
22 |
|
|
// You should have received a copy of the GNU General Public License along
|
23 |
|
|
// with eCos; if not, write to the Free Software Foundation, Inc.,
|
24 |
|
|
// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
|
25 |
|
|
//
|
26 |
|
|
// As a special exception, if other files instantiate templates or use macros
|
27 |
|
|
// or inline functions from this file, or you compile this file and link it
|
28 |
|
|
// with other works to produce a work based on this file, this file does not
|
29 |
|
|
// by itself cause the resulting work to be covered by the GNU General Public
|
30 |
|
|
// License. However the source code for this file must still be made available
|
31 |
|
|
// in accordance with section (3) of the GNU General Public License.
|
32 |
|
|
//
|
33 |
|
|
// This exception does not invalidate any other reasons why a work based on
|
34 |
|
|
// this file might be covered by the GNU General Public License.
|
35 |
|
|
//
|
36 |
|
|
// Alternative licenses for eCos may be arranged by contacting Red Hat, Inc.
|
37 |
|
|
// at http://sources.redhat.com/ecos/ecos-license/
|
38 |
|
|
// -------------------------------------------
|
39 |
|
|
//####ECOSGPLCOPYRIGHTEND####
|
40 |
|
|
//===========================================================================
|
41 |
|
|
//#####DESCRIPTIONBEGIN####
|
42 |
|
|
//
|
43 |
|
|
// Author(s): hmt
|
44 |
|
|
// Contributors: hmt
|
45 |
|
|
// Date: 1998-10-14
|
46 |
|
|
// Purpose: uITRON API testing
|
47 |
|
|
// Description:
|
48 |
|
|
//
|
49 |
|
|
//####DESCRIPTIONEND####
|
50 |
|
|
//
|
51 |
|
|
//===========================================================================
|
52 |
|
|
|
53 |
|
|
#include <pkgconf/uitron.h> // uITRON setup CYGNUM_UITRON_SEMAS
|
54 |
|
|
// CYGPKG_UITRON et al
|
55 |
|
|
#include <cyg/infra/testcase.h> // testing infrastructure
|
56 |
|
|
|
57 |
|
|
#ifdef CYGPKG_UITRON // we DO want the uITRON package
|
58 |
|
|
|
59 |
|
|
#ifdef CYGSEM_KERNEL_SCHED_MLQUEUE // we DO want prioritized threads
|
60 |
|
|
|
61 |
|
|
#ifdef CYGFUN_KERNEL_THREADS_TIMER // we DO want timout-able calls
|
62 |
|
|
|
63 |
|
|
#ifdef CYGVAR_KERNEL_COUNTERS_CLOCK // we DO want the realtime clock
|
64 |
|
|
|
65 |
|
|
// we're OK if it's C++ or neither of those two is defined:
|
66 |
|
|
#if defined( __cplusplus ) || \
|
67 |
|
|
(!defined( CYGIMP_UITRON_INLINE_FUNCS ) && \
|
68 |
|
|
!defined( CYGIMP_UITRON_CPP_OUTLINE_FUNCS) )
|
69 |
|
|
|
70 |
|
|
// =================== TEST CONFIGURATION ===================
|
71 |
|
|
#if \
|
72 |
|
|
/* test configuration for enough tasks */ \
|
73 |
|
|
(CYGNUM_UITRON_TASKS >= 4) && \
|
74 |
|
|
(CYGNUM_UITRON_TASKS < 90) && \
|
75 |
|
|
(CYGNUM_UITRON_START_TASKS == 1) && \
|
76 |
|
|
( !defined(CYGPKG_UITRON_TASKS_CREATE_DELETE) || \
|
77 |
|
|
CYGNUM_UITRON_TASKS_INITIALLY >= 4 ) && \
|
78 |
|
|
\
|
79 |
|
|
/* test configuration for enough semaphores */ \
|
80 |
|
|
defined( CYGPKG_UITRON_SEMAS ) && \
|
81 |
|
|
(CYGNUM_UITRON_SEMAS >= 3) && \
|
82 |
|
|
(CYGNUM_UITRON_SEMAS < 90) && \
|
83 |
|
|
( !defined(CYGPKG_UITRON_SEMAS_CREATE_DELETE) || \
|
84 |
|
|
CYGNUM_UITRON_SEMAS_INITIALLY >= 3 ) && \
|
85 |
|
|
\
|
86 |
|
|
/* test configuration for enough flag objects */ \
|
87 |
|
|
defined( CYGPKG_UITRON_FLAGS ) && \
|
88 |
|
|
(CYGNUM_UITRON_FLAGS >= 3) && \
|
89 |
|
|
(CYGNUM_UITRON_FLAGS < 90) && \
|
90 |
|
|
( !defined(CYGPKG_UITRON_FLAGS_CREATE_DELETE) || \
|
91 |
|
|
CYGNUM_UITRON_FLAGS_INITIALLY >= 3 ) && \
|
92 |
|
|
\
|
93 |
|
|
/* test configuration for enough message boxes */ \
|
94 |
|
|
defined( CYGPKG_UITRON_MBOXES ) && \
|
95 |
|
|
(CYGNUM_UITRON_MBOXES >= 3) && \
|
96 |
|
|
(CYGNUM_UITRON_MBOXES < 90) && \
|
97 |
|
|
( !defined(CYGPKG_UITRON_MBOXES_CREATE_DELETE) || \
|
98 |
|
|
CYGNUM_UITRON_MBOXES_INITIALLY >= 3 ) && \
|
99 |
|
|
\
|
100 |
|
|
/* test configuration for enough fixed memory pools */ \
|
101 |
|
|
defined( CYGPKG_UITRON_MEMPOOLFIXED ) && \
|
102 |
|
|
(CYGNUM_UITRON_MEMPOOLFIXED >= 3) && \
|
103 |
|
|
(CYGNUM_UITRON_MEMPOOLFIXED < 90) && \
|
104 |
|
|
( !defined(CYGPKG_UITRON_MEMPOOLFIXED_CREATE_DELETE) || \
|
105 |
|
|
CYGNUM_UITRON_MEMPOOLFIXED_INITIALLY >= 3 ) && \
|
106 |
|
|
\
|
107 |
|
|
/* test configuration for enough variable mempools */ \
|
108 |
|
|
defined( CYGPKG_UITRON_MEMPOOLVAR ) && \
|
109 |
|
|
(CYGNUM_UITRON_MEMPOOLVAR >= 3) && \
|
110 |
|
|
(CYGNUM_UITRON_MEMPOOLVAR < 90) && \
|
111 |
|
|
( !defined(CYGPKG_UITRON_MEMPOOLVAR_CREATE_DELETE) || \
|
112 |
|
|
CYGNUM_UITRON_MEMPOOLVAR_INITIALLY >= 3 ) && \
|
113 |
|
|
\
|
114 |
|
|
/* the end of the large #if statement */ \
|
115 |
|
|
1
|
116 |
|
|
|
117 |
|
|
// ============================ END ============================
|
118 |
|
|
|
119 |
|
|
#include <cyg/kernel/test/stackmon.h> // stack analysis tools
|
120 |
|
|
|
121 |
|
|
#include <cyg/compat/uitron/uit_func.h> // uITRON
|
122 |
|
|
|
123 |
|
|
externC void
|
124 |
|
|
cyg_package_start( void )
|
125 |
|
|
{
|
126 |
|
|
CYG_TEST_INIT();
|
127 |
|
|
CYG_TEST_INFO( "Calling cyg_uitron_start()" );
|
128 |
|
|
cyg_uitron_start();
|
129 |
|
|
}
|
130 |
|
|
|
131 |
|
|
|
132 |
|
|
extern "C" {
|
133 |
|
|
void task1( unsigned int arg );
|
134 |
|
|
void task2( unsigned int arg );
|
135 |
|
|
void task3( unsigned int arg );
|
136 |
|
|
void task4( unsigned int arg );
|
137 |
|
|
}
|
138 |
|
|
|
139 |
|
|
// ========================================================================
|
140 |
|
|
|
141 |
|
|
enum {
|
142 |
|
|
START_WAITOP = 0,
|
143 |
|
|
SLEEP = 0,
|
144 |
|
|
DELAY,
|
145 |
|
|
SEMGET,
|
146 |
|
|
FLAGWAIT,
|
147 |
|
|
MSGGET,
|
148 |
|
|
MEMFIXEDGET,
|
149 |
|
|
MEMVARGET,
|
150 |
|
|
DONE_WAITOP
|
151 |
|
|
};
|
152 |
|
|
typedef int WAITOP;
|
153 |
|
|
|
154 |
|
|
enum {
|
155 |
|
|
START_TYPE = 0,
|
156 |
|
|
PLAIN = 0,
|
157 |
|
|
TIMED = 1,
|
158 |
|
|
DONE_TYPE
|
159 |
|
|
};
|
160 |
|
|
typedef int WAITTYPE;
|
161 |
|
|
|
162 |
|
|
enum {
|
163 |
|
|
START_KILLOP = 0,
|
164 |
|
|
|
165 |
|
|
// These are the 5 ways out of a wait that we perm
|
166 |
|
|
// with other circumstances:
|
167 |
|
|
SIGNAL = 0, // do the appropriate producer op
|
168 |
|
|
TIMEOUT, // wait for the timeout to fire
|
169 |
|
|
RELEASE, // do a rel_wai()
|
170 |
|
|
DELETE, // delete the object; del_xxx()
|
171 |
|
|
KILL, // do a ter_tsk() on the waiter
|
172 |
|
|
|
173 |
|
|
SUSPEND_SIGNAL_RESUME,
|
174 |
|
|
SUSPEND_TIMEOUT_RESUME,
|
175 |
|
|
SUSPEND_RELEASE_RESUME,
|
176 |
|
|
SUSPEND_DELETE_RESUME,
|
177 |
|
|
SUSPEND_KILL, // resume not applicable
|
178 |
|
|
|
179 |
|
|
SUSPEND_SIGNAL_KILL,
|
180 |
|
|
SUSPEND_TIMEOUT_KILL,
|
181 |
|
|
SUSPEND_RELEASE_KILL,
|
182 |
|
|
SUSPEND_DELETE_KILL,
|
183 |
|
|
// SUSPEND_KILL_KILL not applicable
|
184 |
|
|
|
185 |
|
|
#if 0
|
186 |
|
|
// support these later if _really_ keen.
|
187 |
|
|
SUSPEND_SIGNAL_DELETE_RESUME,
|
188 |
|
|
SUSPEND_TIMEOUT_DELETE_RESUME,
|
189 |
|
|
SUSPEND_RELEASE_DELETE_RESUME,
|
190 |
|
|
// SUSPEND_DELETE_DELETE_RESUME not applicable
|
191 |
|
|
// SUSPEND_KILL_DELETE_RESUME not applicable
|
192 |
|
|
|
193 |
|
|
SUSPEND_SIGNAL_DELETE_KILL,
|
194 |
|
|
SUSPEND_TIMEOUT_DELETE_KILL,
|
195 |
|
|
SUSPEND_RELEASE_DELETE_KILL,
|
196 |
|
|
// SUSPEND_DELETE_DELETE_KILL,
|
197 |
|
|
SUSPEND_KILL_DELETE // 2nd kill not applicable
|
198 |
|
|
#endif
|
199 |
|
|
|
200 |
|
|
DONE_KILLOP
|
201 |
|
|
};
|
202 |
|
|
typedef int KILLOP;
|
203 |
|
|
|
204 |
|
|
// ========================================================================
|
205 |
|
|
|
206 |
|
|
char * waitstrings[] =
|
207 |
|
|
{ "Sleep ", "Delay ", "Sema ", "Flag ", "Mbox ", "MemFix", "MemVar" };
|
208 |
|
|
|
209 |
|
|
char * typestrings[] =
|
210 |
|
|
{ " (Plain) : ", " (Timed) : " };
|
211 |
|
|
|
212 |
|
|
char * killstrings[] =
|
213 |
|
|
{ "Signal",
|
214 |
|
|
"Wait-for-timeout",
|
215 |
|
|
"Release-wait",
|
216 |
|
|
"Delete-object",
|
217 |
|
|
"Kill-task",
|
218 |
|
|
|
219 |
|
|
"Suspend/Signal/Resume",
|
220 |
|
|
"Suspend/Wait-for-timeout/Resume",
|
221 |
|
|
"Suspend/Release-wait/Resume",
|
222 |
|
|
"Suspend/Delete-object/Resume",
|
223 |
|
|
"Suspend/Kill-task",
|
224 |
|
|
|
225 |
|
|
"Suspend/Signal/Kill-task",
|
226 |
|
|
"Suspend/Wait-for-timeout/Kill-task",
|
227 |
|
|
"Suspend/Release-wait/Kill-task",
|
228 |
|
|
"Suspend/Delete-object/Kill-task",
|
229 |
|
|
|
230 |
|
|
|
231 |
|
|
};
|
232 |
|
|
|
233 |
|
|
// ========================================================================
|
234 |
|
|
|
235 |
|
|
inline int task2arg( WAITOP wait, WAITTYPE waittype, KILLOP kill )
|
236 |
|
|
{
|
237 |
|
|
return waittype + (wait << 1) + (kill << 8);
|
238 |
|
|
}
|
239 |
|
|
|
240 |
|
|
inline void decodearg( int arg, WAITOP *pwait, WAITTYPE *pwaittype, KILLOP *pkill )
|
241 |
|
|
{
|
242 |
|
|
*pwaittype = (arg & 1) ? TIMED : PLAIN;
|
243 |
|
|
*pwait = (arg >> 1) & 0x7f;
|
244 |
|
|
*pkill = (arg >> 8);
|
245 |
|
|
}
|
246 |
|
|
|
247 |
|
|
static char *strdog( char *p, char *q )
|
248 |
|
|
{
|
249 |
|
|
while ( 0 != (*p++ = *q++) );
|
250 |
|
|
return p - 1;
|
251 |
|
|
}
|
252 |
|
|
|
253 |
|
|
static char *
|
254 |
|
|
makemsg( char *z, WAITOP wait, WAITTYPE waittype, KILLOP kill )
|
255 |
|
|
{
|
256 |
|
|
static char buf[ 1000 ];
|
257 |
|
|
char *p = buf;
|
258 |
|
|
p = strdog( p, z );
|
259 |
|
|
p = strdog( p, waitstrings[ wait ] );
|
260 |
|
|
p = strdog( p, typestrings[ waittype ] );
|
261 |
|
|
p = strdog( p, killstrings[ kill ] );
|
262 |
|
|
*p = 0;
|
263 |
|
|
return buf;
|
264 |
|
|
}
|
265 |
|
|
|
266 |
|
|
// ========================================================================
|
267 |
|
|
|
268 |
|
|
volatile int intercom = 0;
|
269 |
|
|
|
270 |
|
|
// ========================================================================
|
271 |
|
|
|
272 |
|
|
T_RTSK rtsk;
|
273 |
|
|
|
274 |
|
|
void
|
275 |
|
|
do_suspend( void )
|
276 |
|
|
{
|
277 |
|
|
ER ercd;
|
278 |
|
|
ercd = ref_tsk( &rtsk, 2 );
|
279 |
|
|
CYG_TEST_CHECK( E_OK == ercd, "ref_tsk bad ercd" );
|
280 |
|
|
CYG_TEST_CHECK( TTS_WAI == rtsk.tskstat, "bad tskstat !TTS_WAI" );
|
281 |
|
|
ercd = sus_tsk( 2 );
|
282 |
|
|
CYG_TEST_CHECK( E_OK == ercd, "sus_tsk bad ercd" );
|
283 |
|
|
ercd = ref_tsk( &rtsk, 2 );
|
284 |
|
|
CYG_TEST_CHECK( E_OK == ercd, "ref_tsk bad ercd" );
|
285 |
|
|
CYG_TEST_CHECK( TTS_WAS == rtsk.tskstat, "bad tskstat !TTS_WAS" );
|
286 |
|
|
}
|
287 |
|
|
|
288 |
|
|
void
|
289 |
|
|
do_resume( void )
|
290 |
|
|
{
|
291 |
|
|
ER ercd;
|
292 |
|
|
ercd = ref_tsk( &rtsk, 2 );
|
293 |
|
|
CYG_TEST_CHECK( E_OK == ercd, "ref_tsk bad ercd" );
|
294 |
|
|
CYG_TEST_CHECK( TTS_SUS == rtsk.tskstat, "bad tskstat !TTS_SUS" );
|
295 |
|
|
ercd = dis_dsp();
|
296 |
|
|
CYG_TEST_CHECK( E_OK == ercd, "dis_dsp bad ercd" );
|
297 |
|
|
ercd = rsm_tsk( 2 );
|
298 |
|
|
CYG_TEST_CHECK( E_OK == ercd, "rsm_tsk bad ercd" );
|
299 |
|
|
ercd = ref_tsk( &rtsk, 2 );
|
300 |
|
|
CYG_TEST_CHECK( E_OK == ercd, "ref_tsk bad ercd" );
|
301 |
|
|
CYG_TEST_CHECK( TTS_RDY == rtsk.tskstat, "bad tskstat !TTS_RDY" );
|
302 |
|
|
ercd = ena_dsp();
|
303 |
|
|
CYG_TEST_CHECK( E_OK == ercd, "ena_dsp bad ercd" );
|
304 |
|
|
}
|
305 |
|
|
|
306 |
|
|
// ========================================================================
|
307 |
|
|
|
308 |
|
|
#define T1_WAIT (7)
|
309 |
|
|
#define T2_WAIT (5)
|
310 |
|
|
|
311 |
|
|
#define T1_MALLOC (110)
|
312 |
|
|
#ifdef CYGSEM_KERNEL_MEMORY_COALESCE
|
313 |
|
|
#define T2_MALLOC (100)
|
314 |
|
|
#else
|
315 |
|
|
#define T2_MALLOC T1_MALLOC
|
316 |
|
|
#endif
|
317 |
|
|
|
318 |
|
|
VP vptmp;
|
319 |
|
|
VP vp = NULL;
|
320 |
|
|
VP vp1 = NULL;
|
321 |
|
|
VP t2vp = NULL;
|
322 |
|
|
VP t2vp_backup = NULL;
|
323 |
|
|
|
324 |
|
|
UINT scratch;
|
325 |
|
|
|
326 |
|
|
T_MSG *msg = (T_MSG *)&scratch;
|
327 |
|
|
T_MSG *msg1;
|
328 |
|
|
|
329 |
|
|
void
|
330 |
|
|
do_prep( WAITOP wait )
|
331 |
|
|
{
|
332 |
|
|
ER ercd;
|
333 |
|
|
switch ( wait ) {
|
334 |
|
|
case SLEEP:
|
335 |
|
|
case DELAY:
|
336 |
|
|
case SEMGET:
|
337 |
|
|
case FLAGWAIT:
|
338 |
|
|
case MSGGET:
|
339 |
|
|
// do nothing for all of those
|
340 |
|
|
break;
|
341 |
|
|
case MEMFIXEDGET:
|
342 |
|
|
// allocate all the memory in the pool; remember a couple
|
343 |
|
|
// for freeing as the signalling operation:
|
344 |
|
|
t2vp = NULL;
|
345 |
|
|
vp = vptmp = NULL;
|
346 |
|
|
do {
|
347 |
|
|
vp1 = vptmp;
|
348 |
|
|
vptmp = vp;
|
349 |
|
|
ercd = pget_blf( &vp, 1 );
|
350 |
|
|
} while ( E_OK == ercd );
|
351 |
|
|
CYG_TEST_CHECK( E_TMOUT == ercd, "get_blf bad ercd" );
|
352 |
|
|
CYG_TEST_CHECK( NULL != vp, "no allocated block to free" );
|
353 |
|
|
CYG_TEST_CHECK( NULL != vp1, "no allocated block to free1" );
|
354 |
|
|
break;
|
355 |
|
|
case MEMVARGET:
|
356 |
|
|
// allocate all the memory in the pool; remember a couple
|
357 |
|
|
// for freeing as the signalling operation:
|
358 |
|
|
t2vp = NULL;
|
359 |
|
|
vp = vptmp = NULL;
|
360 |
|
|
do {
|
361 |
|
|
vp1 = vptmp;
|
362 |
|
|
vptmp = vp;
|
363 |
|
|
ercd = pget_blk( &vp, 1, T1_MALLOC );
|
364 |
|
|
} while ( E_OK == ercd );
|
365 |
|
|
CYG_TEST_CHECK( E_TMOUT == ercd, "get_blk bad ercd" );
|
366 |
|
|
CYG_TEST_CHECK( NULL != vp, "no allocated block to free" );
|
367 |
|
|
CYG_TEST_CHECK( NULL != vp1, "no allocated block to free1" );
|
368 |
|
|
break;
|
369 |
|
|
default:
|
370 |
|
|
CYG_TEST_FAIL( "bad switch" );
|
371 |
|
|
break;
|
372 |
|
|
}
|
373 |
|
|
}
|
374 |
|
|
|
375 |
|
|
void
|
376 |
|
|
do_tidyup( WAITOP wait )
|
377 |
|
|
{
|
378 |
|
|
ER ercd;
|
379 |
|
|
switch ( wait ) {
|
380 |
|
|
case SLEEP:
|
381 |
|
|
case DELAY:
|
382 |
|
|
case SEMGET:
|
383 |
|
|
case MSGGET:
|
384 |
|
|
// do nothing for all of those
|
385 |
|
|
break;
|
386 |
|
|
case FLAGWAIT:
|
387 |
|
|
// clear the flag variable
|
388 |
|
|
ercd = clr_flg( 1, 0 );
|
389 |
|
|
CYG_TEST_CHECK( E_OK == ercd, "clr_flg bad ercd, tidy vp" );
|
390 |
|
|
break;
|
391 |
|
|
case MEMFIXEDGET:
|
392 |
|
|
if ( NULL != vp ) {
|
393 |
|
|
ercd = rel_blf( 1, vp );
|
394 |
|
|
CYG_TEST_CHECK( E_OK == ercd, "rel_blf bad ercd, tidy vp" );
|
395 |
|
|
}
|
396 |
|
|
if ( NULL != vp1 ) {
|
397 |
|
|
ercd = rel_blf( 1, vp1 );
|
398 |
|
|
CYG_TEST_CHECK( E_OK == ercd, "rel_blf bad ercd, tidy vp1" );
|
399 |
|
|
}
|
400 |
|
|
if ( NULL != t2vp ) {
|
401 |
|
|
ercd = rel_blf( 1, t2vp );
|
402 |
|
|
CYG_TEST_CHECK( E_OK == ercd, "rel_blf bad ercd, tidy t2vp" );
|
403 |
|
|
}
|
404 |
|
|
break;
|
405 |
|
|
case MEMVARGET:
|
406 |
|
|
if ( NULL != vp ) {
|
407 |
|
|
ercd = rel_blk( 1, vp );
|
408 |
|
|
CYG_TEST_CHECK( E_OK == ercd, "rel_blk bad ercd, tidy vp" );
|
409 |
|
|
}
|
410 |
|
|
if ( NULL != vp1 ) {
|
411 |
|
|
ercd = rel_blk( 1, vp1 );
|
412 |
|
|
CYG_TEST_CHECK( E_OK == ercd, "rel_blk bad ercd, tidy vp1" );
|
413 |
|
|
}
|
414 |
|
|
if ( NULL != t2vp ) {
|
415 |
|
|
ercd = rel_blk( 1, t2vp );
|
416 |
|
|
CYG_TEST_CHECK( E_OK == ercd, "rel_blk bad ercd, tidy t2vp" );
|
417 |
|
|
}
|
418 |
|
|
break;
|
419 |
|
|
default:
|
420 |
|
|
CYG_TEST_FAIL( "bad switch" );
|
421 |
|
|
break;
|
422 |
|
|
}
|
423 |
|
|
}
|
424 |
|
|
|
425 |
|
|
void
|
426 |
|
|
do_recreate( WAITOP wait )
|
427 |
|
|
{
|
428 |
|
|
#ifdef CYGPKG_UITRON_SEMAS_CREATE_DELETE
|
429 |
|
|
static T_CSEM t_csem = { NULL, 0, 0 };
|
430 |
|
|
#endif
|
431 |
|
|
#ifdef CYGPKG_UITRON_MBOXES_CREATE_DELETE
|
432 |
|
|
static T_CMBX t_cmbx = { NULL, 0 };
|
433 |
|
|
#endif
|
434 |
|
|
#ifdef CYGPKG_UITRON_FLAGS_CREATE_DELETE
|
435 |
|
|
static T_CFLG t_cflg = { NULL, 0, 0 };
|
436 |
|
|
#endif
|
437 |
|
|
#ifdef CYGPKG_UITRON_MEMPOOLFIXED_CREATE_DELETE
|
438 |
|
|
static T_CMPF t_cmpf = { NULL, 0, 20, 95 };
|
439 |
|
|
#endif
|
440 |
|
|
#ifdef CYGPKG_UITRON_MEMPOOLVAR_CREATE_DELETE
|
441 |
|
|
static T_CMPL t_cmpl = { NULL, 0, 2000 };
|
442 |
|
|
#endif
|
443 |
|
|
ER ercd = E_OK;
|
444 |
|
|
switch ( wait ) {
|
445 |
|
|
case SLEEP:
|
446 |
|
|
case DELAY:
|
447 |
|
|
// do nothing for all of those
|
448 |
|
|
break;
|
449 |
|
|
case SEMGET:
|
450 |
|
|
#ifdef CYGPKG_UITRON_SEMAS_CREATE_DELETE
|
451 |
|
|
// create the semaphore
|
452 |
|
|
ercd = cre_sem( 1, &t_csem );
|
453 |
|
|
CYG_TEST_CHECK( E_OK == ercd, "cre_sem bad ercd" );
|
454 |
|
|
#else
|
455 |
|
|
CYG_TEST_FAIL( "bad call to do_recreate SEMGET" );
|
456 |
|
|
#endif
|
457 |
|
|
break;
|
458 |
|
|
case FLAGWAIT:
|
459 |
|
|
#ifdef CYGPKG_UITRON_FLAGS_CREATE_DELETE
|
460 |
|
|
// create the flag
|
461 |
|
|
ercd = cre_flg( 1, &t_cflg );
|
462 |
|
|
CYG_TEST_CHECK( E_OK == ercd, "cre_sem bad ercd" );
|
463 |
|
|
#else
|
464 |
|
|
CYG_TEST_FAIL( "bad call to do_recreate FLAGWAIT" );
|
465 |
|
|
#endif
|
466 |
|
|
break;
|
467 |
|
|
case MSGGET:
|
468 |
|
|
#ifdef CYGPKG_UITRON_MBOXES_CREATE_DELETE
|
469 |
|
|
// create the mbox
|
470 |
|
|
ercd = cre_mbx( 1, &t_cmbx );
|
471 |
|
|
CYG_TEST_CHECK( E_OK == ercd, "cre_sem bad ercd" );
|
472 |
|
|
#else
|
473 |
|
|
CYG_TEST_FAIL( "bad call to do_recreate MSGGET" );
|
474 |
|
|
#endif
|
475 |
|
|
break;
|
476 |
|
|
case MEMFIXEDGET:
|
477 |
|
|
#ifdef CYGPKG_UITRON_MEMPOOLFIXED_CREATE_DELETE
|
478 |
|
|
// create the mempool
|
479 |
|
|
ercd = cre_mpf( 1, &t_cmpf );
|
480 |
|
|
CYG_TEST_CHECK( E_OK == ercd, "cre_sem bad ercd" );
|
481 |
|
|
#else
|
482 |
|
|
CYG_TEST_FAIL( "bad call to do_recreate MEMFIXEDGET" );
|
483 |
|
|
#endif
|
484 |
|
|
break;
|
485 |
|
|
case MEMVARGET:
|
486 |
|
|
#ifdef CYGPKG_UITRON_MEMPOOLVAR_CREATE_DELETE
|
487 |
|
|
// create the mempool
|
488 |
|
|
ercd = cre_mpl( 1, &t_cmpl );
|
489 |
|
|
CYG_TEST_CHECK( E_OK == ercd, "cre_sem bad ercd" );
|
490 |
|
|
#else
|
491 |
|
|
CYG_TEST_FAIL( "bad call to do_recreate MEMVARGET" );
|
492 |
|
|
#endif
|
493 |
|
|
break;
|
494 |
|
|
default:
|
495 |
|
|
CYG_TEST_FAIL( "bad switch" );
|
496 |
|
|
break;
|
497 |
|
|
}
|
498 |
|
|
// this is just to use ercd to prevent warnings
|
499 |
|
|
CYG_TEST_CHECK( E_OK == ercd, "<blank> bad ercd" );
|
500 |
|
|
}
|
501 |
|
|
|
502 |
|
|
|
503 |
|
|
|
504 |
|
|
void
|
505 |
|
|
do_signal( WAITOP wait )
|
506 |
|
|
{
|
507 |
|
|
ER ercd;
|
508 |
|
|
switch ( wait ) {
|
509 |
|
|
case SLEEP:
|
510 |
|
|
// send a wakeup
|
511 |
|
|
ercd = wup_tsk( 2 );
|
512 |
|
|
CYG_TEST_CHECK( E_OK == ercd, "wup_tsk bad ercd" );
|
513 |
|
|
break;
|
514 |
|
|
case DELAY:
|
515 |
|
|
// simply wait for task 2's delay to complete
|
516 |
|
|
ercd = dly_tsk( T1_WAIT );
|
517 |
|
|
CYG_TEST_CHECK( E_OK == ercd, "dly_tsk bad ercd" );
|
518 |
|
|
break;
|
519 |
|
|
case SEMGET:
|
520 |
|
|
// signal the semaphore
|
521 |
|
|
ercd = sig_sem( 1 );
|
522 |
|
|
CYG_TEST_CHECK( E_OK == ercd, "sig_sem bad ercd" );
|
523 |
|
|
break;
|
524 |
|
|
case FLAGWAIT:
|
525 |
|
|
// set the flag bits
|
526 |
|
|
ercd = set_flg( 1, 0xff );
|
527 |
|
|
CYG_TEST_CHECK( E_OK == ercd, "set_flg bad ercd" );
|
528 |
|
|
break;
|
529 |
|
|
case MSGGET:
|
530 |
|
|
// send a message
|
531 |
|
|
ercd = snd_msg( 1, msg );
|
532 |
|
|
CYG_TEST_CHECK( E_OK == ercd, "snd_msg bad ercd" );
|
533 |
|
|
break;
|
534 |
|
|
case MEMFIXEDGET:
|
535 |
|
|
// release a couple of blocks we allocated earlier. I hope.
|
536 |
|
|
CYG_TEST_CHECK( NULL != vp, "no allocated block to free" );
|
537 |
|
|
CYG_TEST_CHECK( NULL != vp1, "no allocated block to free1" );
|
538 |
|
|
ercd = rel_blf( 1, vp );
|
539 |
|
|
CYG_TEST_CHECK( E_OK == ercd, "rel_blf bad ercd" );
|
540 |
|
|
vp = NULL;
|
541 |
|
|
ercd = rel_blf( 1, vp1 );
|
542 |
|
|
CYG_TEST_CHECK( E_OK == ercd, "rel_blf bad ercd1" );
|
543 |
|
|
vp1 = NULL;
|
544 |
|
|
break;
|
545 |
|
|
case MEMVARGET:
|
546 |
|
|
// release a couple of blocks we allocated earlier. I hope.
|
547 |
|
|
CYG_TEST_CHECK( NULL != vp, "no allocated block to free" );
|
548 |
|
|
CYG_TEST_CHECK( NULL != vp1, "no allocated block to free1" );
|
549 |
|
|
ercd = rel_blk( 1, vp );
|
550 |
|
|
CYG_TEST_CHECK( E_OK == ercd, "rel_blk bad ercd" );
|
551 |
|
|
vp = NULL;
|
552 |
|
|
ercd = rel_blk( 1, vp1 );
|
553 |
|
|
CYG_TEST_CHECK( E_OK == ercd, "rel_blk bad ercd1" );
|
554 |
|
|
vp1 = NULL;
|
555 |
|
|
break;
|
556 |
|
|
default:
|
557 |
|
|
CYG_TEST_FAIL( "bad switch" );
|
558 |
|
|
break;
|
559 |
|
|
}
|
560 |
|
|
}
|
561 |
|
|
|
562 |
|
|
void
|
563 |
|
|
do_delete( WAITOP wait )
|
564 |
|
|
{
|
565 |
|
|
ER ercd = E_OK;
|
566 |
|
|
switch ( wait ) {
|
567 |
|
|
case SLEEP:
|
568 |
|
|
case DELAY:
|
569 |
|
|
CYG_TEST_FAIL( "bad call to do_delete( SLEEP or DELAY )" );
|
570 |
|
|
break;
|
571 |
|
|
case SEMGET:
|
572 |
|
|
#ifdef CYGPKG_UITRON_SEMAS_CREATE_DELETE
|
573 |
|
|
// delete the semaphore
|
574 |
|
|
ercd = del_sem( 1 );
|
575 |
|
|
CYG_TEST_CHECK( E_OK == ercd, "del_sem bad ercd" );
|
576 |
|
|
#else
|
577 |
|
|
CYG_TEST_FAIL( "bad call to do_delete( SEMGET )" );
|
578 |
|
|
#endif
|
579 |
|
|
break;
|
580 |
|
|
case FLAGWAIT:
|
581 |
|
|
#ifdef CYGPKG_UITRON_FLAGS_CREATE_DELETE
|
582 |
|
|
// delete the flag
|
583 |
|
|
ercd = del_flg( 1 );
|
584 |
|
|
CYG_TEST_CHECK( E_OK == ercd, "del_flg bad ercd" );
|
585 |
|
|
#else
|
586 |
|
|
CYG_TEST_FAIL( "bad call to do_delete( FLAGWAIT )" );
|
587 |
|
|
#endif
|
588 |
|
|
break;
|
589 |
|
|
case MSGGET:
|
590 |
|
|
#ifdef CYGPKG_UITRON_MBOXES_CREATE_DELETE
|
591 |
|
|
// delete the mbox
|
592 |
|
|
ercd = del_mbx( 1 );
|
593 |
|
|
CYG_TEST_CHECK( E_OK == ercd, "del_mbx bad ercd" );
|
594 |
|
|
#else
|
595 |
|
|
CYG_TEST_FAIL( "bad call to do_delete( MSGGET )" );
|
596 |
|
|
#endif
|
597 |
|
|
break;
|
598 |
|
|
case MEMFIXEDGET:
|
599 |
|
|
#ifdef CYGPKG_UITRON_MEMPOOLFIXED_CREATE_DELETE
|
600 |
|
|
// delete the mempool
|
601 |
|
|
ercd = del_mpf( 1 );
|
602 |
|
|
CYG_TEST_CHECK( E_OK == ercd, "del_mpf bad ercd" );
|
603 |
|
|
#else
|
604 |
|
|
CYG_TEST_FAIL( "bad call to do_delete( MEMFIXEDGET )" );
|
605 |
|
|
#endif
|
606 |
|
|
break;
|
607 |
|
|
case MEMVARGET:
|
608 |
|
|
#ifdef CYGPKG_UITRON_MEMPOOLVAR_CREATE_DELETE
|
609 |
|
|
// delete the mempool
|
610 |
|
|
ercd = del_mpl( 1 );
|
611 |
|
|
CYG_TEST_CHECK( E_OK == ercd, "del_mpl bad ercd" );
|
612 |
|
|
#else
|
613 |
|
|
CYG_TEST_FAIL( "bad call to do_delete( MEMVARGET )" );
|
614 |
|
|
#endif
|
615 |
|
|
break;
|
616 |
|
|
default:
|
617 |
|
|
CYG_TEST_FAIL( "bad switch" );
|
618 |
|
|
break;
|
619 |
|
|
}
|
620 |
|
|
// this is just to use ercd to prevent warnings
|
621 |
|
|
CYG_TEST_CHECK( E_OK == ercd, "<blank> bad ercd" );
|
622 |
|
|
}
|
623 |
|
|
|
624 |
|
|
|
625 |
|
|
|
626 |
|
|
ER
|
627 |
|
|
do_wait( WAITOP wait, WAITTYPE type )
|
628 |
|
|
{
|
629 |
|
|
switch ( wait ) {
|
630 |
|
|
case SLEEP:
|
631 |
|
|
return ( PLAIN == type ) ? slp_tsk() : tslp_tsk( T2_WAIT );
|
632 |
|
|
case DELAY:
|
633 |
|
|
return dly_tsk( T2_WAIT ); // forget the type
|
634 |
|
|
case SEMGET:
|
635 |
|
|
return ( PLAIN == type ) ? wai_sem( 1 ) : twai_sem( 1, T2_WAIT );
|
636 |
|
|
case FLAGWAIT:
|
637 |
|
|
return ( PLAIN == type ) ?
|
638 |
|
|
wai_flg( &scratch, 1, 0x55, TWF_ANDW ) :
|
639 |
|
|
twai_flg( &scratch, 1, 0xaa, TWF_ANDW, T2_WAIT );
|
640 |
|
|
case MSGGET:
|
641 |
|
|
return ( PLAIN == type ) ?
|
642 |
|
|
rcv_msg( &msg1, 1 ) :
|
643 |
|
|
trcv_msg( &msg1, 1, T2_WAIT );
|
644 |
|
|
case MEMFIXEDGET:
|
645 |
|
|
return ( PLAIN == type ) ?
|
646 |
|
|
get_blf( &t2vp, 1 ) :
|
647 |
|
|
tget_blf( &t2vp, 1, T2_WAIT );
|
648 |
|
|
case MEMVARGET:
|
649 |
|
|
return ( PLAIN == type ) ?
|
650 |
|
|
get_blk( &t2vp, 1, T2_MALLOC ) :
|
651 |
|
|
tget_blk( &t2vp, 1, T2_MALLOC, T2_WAIT );
|
652 |
|
|
default:
|
653 |
|
|
CYG_TEST_FAIL( "bad switch" );
|
654 |
|
|
break;
|
655 |
|
|
}
|
656 |
|
|
CYG_TEST_FAIL( "Bad wait in do_wait" );
|
657 |
|
|
return E_SYS;
|
658 |
|
|
}
|
659 |
|
|
|
660 |
|
|
void
|
661 |
|
|
check_waitstate( WAITOP wait, int waiting )
|
662 |
|
|
{
|
663 |
|
|
ER ercd;
|
664 |
|
|
int waity = 0;
|
665 |
|
|
switch ( wait ) {
|
666 |
|
|
case SLEEP:
|
667 |
|
|
case DELAY:
|
668 |
|
|
return; // do nothing for these
|
669 |
|
|
case SEMGET: {
|
670 |
|
|
T_RSEM rsem;
|
671 |
|
|
ercd = ref_sem( &rsem, 1 );
|
672 |
|
|
waity = rsem.wtsk;
|
673 |
|
|
break;
|
674 |
|
|
}
|
675 |
|
|
case FLAGWAIT: {
|
676 |
|
|
T_RFLG rflg;
|
677 |
|
|
ercd = ref_flg( &rflg, 1 );
|
678 |
|
|
waity = rflg.wtsk;
|
679 |
|
|
break;
|
680 |
|
|
}
|
681 |
|
|
case MSGGET: {
|
682 |
|
|
T_RMBX rmbx;
|
683 |
|
|
ercd = ref_mbx( &rmbx, 1 );
|
684 |
|
|
waity = rmbx.wtsk;
|
685 |
|
|
break;
|
686 |
|
|
}
|
687 |
|
|
case MEMFIXEDGET: {
|
688 |
|
|
T_RMPF rmpf;
|
689 |
|
|
ercd = ref_mpf( &rmpf, 1 );
|
690 |
|
|
waity = rmpf.wtsk;
|
691 |
|
|
break;
|
692 |
|
|
}
|
693 |
|
|
case MEMVARGET: {
|
694 |
|
|
T_RMPL rmpl;
|
695 |
|
|
ercd = ref_mpl( &rmpl, 1 );
|
696 |
|
|
waity = rmpl.wtsk;
|
697 |
|
|
break;
|
698 |
|
|
}
|
699 |
|
|
default:
|
700 |
|
|
CYG_TEST_FAIL( "bad switch" );
|
701 |
|
|
break;
|
702 |
|
|
}
|
703 |
|
|
if ( waiting )
|
704 |
|
|
CYG_TEST_CHECK( waity, "Object has no task waiting!" );
|
705 |
|
|
else
|
706 |
|
|
CYG_TEST_CHECK( !waity, "Object had a task waiting!" );
|
707 |
|
|
}
|
708 |
|
|
|
709 |
|
|
// ========================================================================
|
710 |
|
|
void task1( unsigned int arg )
|
711 |
|
|
{
|
712 |
|
|
ER ercd;
|
713 |
|
|
WAITOP wait;
|
714 |
|
|
WAITTYPE type;
|
715 |
|
|
KILLOP kill;
|
716 |
|
|
|
717 |
|
|
CYG_TEST_INFO( "Task 1 running" );
|
718 |
|
|
|
719 |
|
|
{
|
720 |
|
|
extern Cyg_Thread cyg_uitron_TASKS[];
|
721 |
|
|
cyg_test_dump_thread_stack_stats(
|
722 |
|
|
"Startup, task1", &cyg_uitron_TASKS[ 0 ] );
|
723 |
|
|
cyg_test_dump_thread_stack_stats(
|
724 |
|
|
"Startup, task2", &cyg_uitron_TASKS[ 1 ] );
|
725 |
|
|
cyg_test_dump_interrupt_stack_stats( "Startup" );
|
726 |
|
|
cyg_test_dump_idlethread_stack_stats( "Startup" );
|
727 |
|
|
cyg_test_clear_interrupt_stack();
|
728 |
|
|
}
|
729 |
|
|
|
730 |
|
|
ercd = chg_pri( 1, 8 );
|
731 |
|
|
CYG_TEST_CHECK( E_OK == ercd, "chg_pri bad ercd" );
|
732 |
|
|
|
733 |
|
|
for ( wait = START_WAITOP; wait < DONE_WAITOP ; wait++) {
|
734 |
|
|
for ( type = START_TYPE; type < DONE_TYPE ; type++ ) {
|
735 |
|
|
for ( kill = START_KILLOP; kill < DONE_KILLOP ; kill++ ) {
|
736 |
|
|
|
737 |
|
|
// These clauses deal with a couple of special cases:
|
738 |
|
|
// [doing it this way helps keep the rest of the code
|
739 |
|
|
// nicely general and orthogonal]
|
740 |
|
|
//
|
741 |
|
|
// 1) DELAY: dly_tsk(): when this times out, the retcode is
|
742 |
|
|
// E_OK rather than E_TMOUT, and it always times out. The
|
743 |
|
|
// "signalling" method here is just to wait yourself. So we
|
744 |
|
|
// do not test DELAY with TIMED type.
|
745 |
|
|
//
|
746 |
|
|
// 2) PLAIN tests with TIMEOUT kill operations: a PLAIN test
|
747 |
|
|
// will not time out, it'll wait forever, so waiting for it
|
748 |
|
|
// so to do is pointless; further, we would check for the
|
749 |
|
|
// wrong error code. So we do not test PLAIN tests with
|
750 |
|
|
// TIMOUT kill operations.
|
751 |
|
|
//
|
752 |
|
|
// 3) SLEEP or DELAY tests with DELETE operations: there is
|
753 |
|
|
// no synchronization to delete in those cases.
|
754 |
|
|
// 3a) Individual object types are tested for delete support,
|
755 |
|
|
// and if there is none, the test is skipped.
|
756 |
|
|
|
757 |
|
|
if ( DELAY == wait && TIMED == type )
|
758 |
|
|
continue;
|
759 |
|
|
|
760 |
|
|
if ( PLAIN == type &&
|
761 |
|
|
( ( TIMEOUT == kill) ||
|
762 |
|
|
(SUSPEND_TIMEOUT_RESUME == kill) ||
|
763 |
|
|
(SUSPEND_TIMEOUT_KILL == kill) ) )
|
764 |
|
|
continue;
|
765 |
|
|
|
766 |
|
|
if ( (
|
767 |
|
|
#ifndef CYGPKG_UITRON_SEMAS_CREATE_DELETE
|
768 |
|
|
(SEMGET == wait) ||
|
769 |
|
|
#endif
|
770 |
|
|
#ifndef CYGPKG_UITRON_FLAGS_CREATE_DELETE
|
771 |
|
|
(FLAGWAIT == wait) ||
|
772 |
|
|
#endif
|
773 |
|
|
#ifndef CYGPKG_UITRON_MBOXES_CREATE_DELETE
|
774 |
|
|
(MSGGET == wait) ||
|
775 |
|
|
#endif
|
776 |
|
|
#ifndef CYGPKG_UITRON_MEMPOOLFIXED_CREATE_DELETE
|
777 |
|
|
(MEMFIXEDGET == wait) ||
|
778 |
|
|
#endif
|
779 |
|
|
#ifndef CYGPKG_UITRON_MEMPOOLVAR_CREATE_DELETE
|
780 |
|
|
(MEMVARGET == wait) ||
|
781 |
|
|
#endif
|
782 |
|
|
(SLEEP == wait) ||
|
783 |
|
|
(DELAY == wait)
|
784 |
|
|
) &&
|
785 |
|
|
((DELETE == kill) ||
|
786 |
|
|
(SUSPEND_DELETE_RESUME == kill) ||
|
787 |
|
|
(SUSPEND_DELETE_KILL == kill)) )
|
788 |
|
|
continue;
|
789 |
|
|
|
790 |
|
|
|
791 |
|
|
CYG_TEST_INFO( makemsg( "T1: ", wait, type, kill ) );
|
792 |
|
|
|
793 |
|
|
intercom = 0;
|
794 |
|
|
|
795 |
|
|
// prepare the synchronization objects
|
796 |
|
|
// (actually, just empty the mempools)
|
797 |
|
|
do_prep( wait );
|
798 |
|
|
|
799 |
|
|
// start task 2 at a higher priority than myself
|
800 |
|
|
ercd = dis_dsp();
|
801 |
|
|
CYG_TEST_CHECK( E_OK == ercd, "dis_dsp bad ercd" );
|
802 |
|
|
ercd = sta_tsk( 2, task2arg( wait, type, kill ) );
|
803 |
|
|
CYG_TEST_CHECK( E_OK == ercd, "sta_tsk bad ercd" );
|
804 |
|
|
ercd = chg_pri( 2, 5 );
|
805 |
|
|
CYG_TEST_CHECK( E_OK == ercd, "chg_pri bad ercd" );
|
806 |
|
|
ercd = ena_dsp();
|
807 |
|
|
CYG_TEST_CHECK( E_OK == ercd, "ena_dsp bad ercd" );
|
808 |
|
|
// task 2 should run now, until it waits.
|
809 |
|
|
|
810 |
|
|
ercd = ref_tsk( &rtsk, 2 );
|
811 |
|
|
CYG_TEST_CHECK( E_OK == ercd, "ref_tsk bad ercd" );
|
812 |
|
|
CYG_TEST_CHECK( TTS_WAI == rtsk.tskstat, "bad tskstat" );
|
813 |
|
|
CYG_TEST_CHECK( 5 == rtsk.tskpri, "bad tskpri" );
|
814 |
|
|
|
815 |
|
|
switch ( kill ) {
|
816 |
|
|
case SIGNAL:
|
817 |
|
|
// signal the task appropriately
|
818 |
|
|
do_signal( wait );
|
819 |
|
|
// it should now have run to completion
|
820 |
|
|
break;
|
821 |
|
|
case TIMEOUT:
|
822 |
|
|
check_waitstate( wait, 1 );
|
823 |
|
|
// wait for the timeout to occur
|
824 |
|
|
ercd = dly_tsk( T1_WAIT );
|
825 |
|
|
CYG_TEST_CHECK( E_OK == ercd, "dly_tsk bad ercd" );
|
826 |
|
|
check_waitstate( wait, 0 );
|
827 |
|
|
// it should now have run to completion
|
828 |
|
|
break;
|
829 |
|
|
case RELEASE:
|
830 |
|
|
// hit the task with a release-wait
|
831 |
|
|
ercd = rel_wai( 2 );
|
832 |
|
|
CYG_TEST_CHECK( E_OK == ercd, "rel_wai bad ercd" );
|
833 |
|
|
// it should now have run to completion
|
834 |
|
|
break;
|
835 |
|
|
case DELETE:
|
836 |
|
|
// delete the object appropriately
|
837 |
|
|
do_delete( wait );
|
838 |
|
|
// it should now have run to completion
|
839 |
|
|
break;
|
840 |
|
|
case KILL:
|
841 |
|
|
// kill the task
|
842 |
|
|
ercd = ter_tsk( 2 );
|
843 |
|
|
CYG_TEST_CHECK( E_OK == ercd, "ter_tsk bad ercd" );
|
844 |
|
|
// it should now have terminated without running
|
845 |
|
|
break;
|
846 |
|
|
case SUSPEND_SIGNAL_RESUME:
|
847 |
|
|
// suspend the task
|
848 |
|
|
do_suspend();
|
849 |
|
|
// signal the task appropriately
|
850 |
|
|
do_signal( wait );
|
851 |
|
|
// resume the task
|
852 |
|
|
do_resume();
|
853 |
|
|
// it should now have run to completion
|
854 |
|
|
break;
|
855 |
|
|
case SUSPEND_TIMEOUT_RESUME:
|
856 |
|
|
check_waitstate( wait, 1 );
|
857 |
|
|
// suspend the task
|
858 |
|
|
do_suspend();
|
859 |
|
|
check_waitstate( wait, 1 );
|
860 |
|
|
// wait for the timeout to occur
|
861 |
|
|
ercd = dly_tsk( T1_WAIT );
|
862 |
|
|
CYG_TEST_CHECK( E_OK == ercd, "dly_tsk bad ercd" );
|
863 |
|
|
check_waitstate( wait, 0 );
|
864 |
|
|
// resume the task
|
865 |
|
|
do_resume();
|
866 |
|
|
// it should now have run to completion
|
867 |
|
|
break;
|
868 |
|
|
case SUSPEND_RELEASE_RESUME:
|
869 |
|
|
// suspend the task
|
870 |
|
|
do_suspend();
|
871 |
|
|
// hit the task with a release-wait
|
872 |
|
|
ercd = rel_wai( 2 );
|
873 |
|
|
CYG_TEST_CHECK( E_OK == ercd, "rel_wai bad ercd" );
|
874 |
|
|
// resume the task
|
875 |
|
|
do_resume();
|
876 |
|
|
// it should now have run to completion
|
877 |
|
|
break;
|
878 |
|
|
case SUSPEND_DELETE_RESUME:
|
879 |
|
|
// suspend the task
|
880 |
|
|
do_suspend();
|
881 |
|
|
// delete the object appropriately
|
882 |
|
|
do_delete( wait );
|
883 |
|
|
// resume the task
|
884 |
|
|
do_resume();
|
885 |
|
|
// it should now have run to completion
|
886 |
|
|
break;
|
887 |
|
|
case SUSPEND_KILL:
|
888 |
|
|
// suspend the task
|
889 |
|
|
do_suspend();
|
890 |
|
|
// kill the task
|
891 |
|
|
ercd = ter_tsk( 2 );
|
892 |
|
|
CYG_TEST_CHECK( E_OK == ercd, "ter_tsk bad ercd" );
|
893 |
|
|
// it should now have terminated without running
|
894 |
|
|
break;
|
895 |
|
|
case SUSPEND_SIGNAL_KILL:
|
896 |
|
|
// suspend the task
|
897 |
|
|
do_suspend();
|
898 |
|
|
// signal the task appropriately
|
899 |
|
|
do_signal( wait );
|
900 |
|
|
// kill the task
|
901 |
|
|
ercd = ter_tsk( 2 );
|
902 |
|
|
CYG_TEST_CHECK( E_OK == ercd, "ter_tsk bad ercd" );
|
903 |
|
|
// it should now have terminated without running
|
904 |
|
|
break;
|
905 |
|
|
case SUSPEND_TIMEOUT_KILL:
|
906 |
|
|
check_waitstate( wait, 1 );
|
907 |
|
|
// suspend the task
|
908 |
|
|
do_suspend();
|
909 |
|
|
check_waitstate( wait, 1 );
|
910 |
|
|
// wait for the timeout to occur
|
911 |
|
|
ercd = dly_tsk( T1_WAIT );
|
912 |
|
|
CYG_TEST_CHECK( E_OK == ercd, "dly_tsk bad ercd" );
|
913 |
|
|
check_waitstate( wait, 0 );
|
914 |
|
|
// kill the task
|
915 |
|
|
ercd = ter_tsk( 2 );
|
916 |
|
|
CYG_TEST_CHECK( E_OK == ercd, "ter_tsk bad ercd" );
|
917 |
|
|
// it should now have terminated without running
|
918 |
|
|
break;
|
919 |
|
|
case SUSPEND_RELEASE_KILL:
|
920 |
|
|
// suspend the task
|
921 |
|
|
do_suspend();
|
922 |
|
|
// hit the task with a release-wait
|
923 |
|
|
ercd = rel_wai( 2 );
|
924 |
|
|
CYG_TEST_CHECK( E_OK == ercd, "rel_wai bad ercd" );
|
925 |
|
|
// kill the task
|
926 |
|
|
ercd = ter_tsk( 2 );
|
927 |
|
|
CYG_TEST_CHECK( E_OK == ercd, "ter_tsk bad ercd" );
|
928 |
|
|
// it should now have terminated without running
|
929 |
|
|
break;
|
930 |
|
|
case SUSPEND_DELETE_KILL:
|
931 |
|
|
// suspend the task
|
932 |
|
|
do_suspend();
|
933 |
|
|
// delete the object appropriately
|
934 |
|
|
do_delete( wait );
|
935 |
|
|
// kill the task
|
936 |
|
|
ercd = ter_tsk( 2 );
|
937 |
|
|
CYG_TEST_CHECK( E_OK == ercd, "ter_tsk bad ercd" );
|
938 |
|
|
// it should now have terminated without running
|
939 |
|
|
break;
|
940 |
|
|
default:
|
941 |
|
|
CYG_TEST_FAIL( "bad switch" );
|
942 |
|
|
break;
|
943 |
|
|
}
|
944 |
|
|
|
945 |
|
|
// task 2 should be dormant now, however it got there
|
946 |
|
|
ercd = ref_tsk( &rtsk, 2 );
|
947 |
|
|
CYG_TEST_CHECK( E_OK == ercd, "ref_tsk bad ercd" );
|
948 |
|
|
CYG_TEST_CHECK( TTS_DMT == rtsk.tskstat, "bad tskstat" );
|
949 |
|
|
|
950 |
|
|
if ( (SUSPEND_SIGNAL_KILL == kill) &&
|
951 |
|
|
((MEMFIXEDGET == wait) || (MEMVARGET == wait)) ) {
|
952 |
|
|
// it was a killed successful memory alloc, so we have
|
953 |
|
|
// lost the pointer to memory allocated; there is an
|
954 |
|
|
// implicit storeleak problem when the task trying
|
955 |
|
|
// to allocate is signalled then killed.
|
956 |
|
|
// Recreate the pointer from an old version:
|
957 |
|
|
CYG_TEST_CHECK( NULL == t2vp, "t2vp WAS allocated!" );
|
958 |
|
|
t2vp = t2vp_backup;
|
959 |
|
|
}
|
960 |
|
|
|
961 |
|
|
switch ( kill ) {
|
962 |
|
|
case KILL:
|
963 |
|
|
case SUSPEND_KILL:
|
964 |
|
|
case SUSPEND_SIGNAL_KILL:
|
965 |
|
|
case SUSPEND_TIMEOUT_KILL:
|
966 |
|
|
case SUSPEND_RELEASE_KILL:
|
967 |
|
|
case SUSPEND_DELETE_KILL:
|
968 |
|
|
// if task 2 was killed, expect only one increment
|
969 |
|
|
CYG_TEST_CHECK( 1 == intercom, "intercom bad value !1" );
|
970 |
|
|
break;
|
971 |
|
|
default:
|
972 |
|
|
// otherwise expect two increments
|
973 |
|
|
CYG_TEST_CHECK( 2 == intercom, "intercom bad value !2" );
|
974 |
|
|
break;
|
975 |
|
|
}
|
976 |
|
|
|
977 |
|
|
// tidy up or recreate the synchronization objects
|
978 |
|
|
if ( (DELETE == kill) ||
|
979 |
|
|
(SUSPEND_DELETE_RESUME == kill) ||
|
980 |
|
|
(SUSPEND_DELETE_KILL == kill) )
|
981 |
|
|
do_recreate( wait );
|
982 |
|
|
else
|
983 |
|
|
do_tidyup( wait );
|
984 |
|
|
}
|
985 |
|
|
}
|
986 |
|
|
}
|
987 |
|
|
CYG_TEST_PASS("synchronization interaction tests");
|
988 |
|
|
|
989 |
|
|
{
|
990 |
|
|
extern Cyg_Thread cyg_uitron_TASKS[];
|
991 |
|
|
cyg_test_dump_thread_stack_stats(
|
992 |
|
|
"All done, task1", &cyg_uitron_TASKS[ 0 ] );
|
993 |
|
|
cyg_test_dump_thread_stack_stats(
|
994 |
|
|
"All done, task2", &cyg_uitron_TASKS[ 1 ] );
|
995 |
|
|
cyg_test_dump_interrupt_stack_stats( "All done" );
|
996 |
|
|
cyg_test_dump_idlethread_stack_stats( "All done" );
|
997 |
|
|
}
|
998 |
|
|
// all done
|
999 |
|
|
CYG_TEST_EXIT( "All done" );
|
1000 |
|
|
ext_tsk();
|
1001 |
|
|
}
|
1002 |
|
|
|
1003 |
|
|
|
1004 |
|
|
|
1005 |
|
|
void task2( unsigned int arg )
|
1006 |
|
|
{
|
1007 |
|
|
ER ercd;
|
1008 |
|
|
WAITOP wait;
|
1009 |
|
|
WAITTYPE waittype;
|
1010 |
|
|
KILLOP kill;
|
1011 |
|
|
|
1012 |
|
|
decodearg( arg, &wait, &waittype, &kill );
|
1013 |
|
|
|
1014 |
|
|
// CYG_TEST_INFO( makemsg( " 2: ", wait, waittype, kill ) );
|
1015 |
|
|
|
1016 |
|
|
intercom++;
|
1017 |
|
|
ercd = do_wait( wait, waittype );
|
1018 |
|
|
intercom++;
|
1019 |
|
|
|
1020 |
|
|
switch ( kill ) {
|
1021 |
|
|
case SIGNAL:
|
1022 |
|
|
case SUSPEND_SIGNAL_RESUME:
|
1023 |
|
|
// we expect to have been signalled correctly
|
1024 |
|
|
CYG_TEST_CHECK( E_OK == ercd, "T2 wait bad ercd" );
|
1025 |
|
|
// here we know that the op completed OK
|
1026 |
|
|
if ( (MEMFIXEDGET == wait) || (MEMVARGET == wait) ) {
|
1027 |
|
|
// it was a successful memory alloc of whichever type,
|
1028 |
|
|
// so we can save away a copy of t2vp for working round an
|
1029 |
|
|
// implicit storeleak problem when the task trying to allocate
|
1030 |
|
|
// is signalled then killed:
|
1031 |
|
|
CYG_TEST_CHECK( NULL != t2vp, "No t2vp allocated!" );
|
1032 |
|
|
t2vp_backup = t2vp;
|
1033 |
|
|
}
|
1034 |
|
|
break;
|
1035 |
|
|
case TIMEOUT:
|
1036 |
|
|
case SUSPEND_TIMEOUT_RESUME:
|
1037 |
|
|
// we expect to have timed out - if it's a timeout op.
|
1038 |
|
|
CYG_TEST_CHECK( E_TMOUT == ercd, "T2 timeout bad ercd, !E_TMOUT" );
|
1039 |
|
|
break;
|
1040 |
|
|
case RELEASE:
|
1041 |
|
|
case SUSPEND_RELEASE_RESUME:
|
1042 |
|
|
// we expect to have suffered a release wait.
|
1043 |
|
|
CYG_TEST_CHECK( E_RLWAI == ercd, "T2 release bad ercd, !E_RLWAI" );
|
1044 |
|
|
break;
|
1045 |
|
|
case DELETE:
|
1046 |
|
|
case SUSPEND_DELETE_RESUME:
|
1047 |
|
|
// we expect to be told the object is gone
|
1048 |
|
|
CYG_TEST_CHECK( E_DLT == ercd, "T2 release bad ercd, !E_DLT" );
|
1049 |
|
|
break;
|
1050 |
|
|
case KILL:
|
1051 |
|
|
case SUSPEND_KILL:
|
1052 |
|
|
case SUSPEND_SIGNAL_KILL:
|
1053 |
|
|
case SUSPEND_TIMEOUT_KILL:
|
1054 |
|
|
case SUSPEND_RELEASE_KILL:
|
1055 |
|
|
case SUSPEND_DELETE_KILL:
|
1056 |
|
|
// we expect to have been killed here, ie. this won't execute!
|
1057 |
|
|
CYG_TEST_FAIL( "Task 2 ran to completion!" );
|
1058 |
|
|
break;
|
1059 |
|
|
default:
|
1060 |
|
|
CYG_TEST_FAIL( "bad switch" );
|
1061 |
|
|
break;
|
1062 |
|
|
}
|
1063 |
|
|
}
|
1064 |
|
|
|
1065 |
|
|
void task3( unsigned int arg )
|
1066 |
|
|
{
|
1067 |
|
|
}
|
1068 |
|
|
|
1069 |
|
|
void task4( unsigned int arg )
|
1070 |
|
|
{
|
1071 |
|
|
}
|
1072 |
|
|
|
1073 |
|
|
#else // not enough (or too many) uITRON objects configured in
|
1074 |
|
|
#define N_A_MSG "not enough uITRON objects to run test"
|
1075 |
|
|
#endif // not enough (or too many) uITRON objects configured in
|
1076 |
|
|
#else // not C++ and some C++ specific options enabled
|
1077 |
|
|
#define N_A_MSG "C++ specific options selected but this is C"
|
1078 |
|
|
#endif // not C++ and some C++ specific options enabled
|
1079 |
|
|
#else // ! CYGVAR_KERNEL_COUNTERS_CLOCK - can't test without it
|
1080 |
|
|
#define N_A_MSG "no CYGVAR_KERNEL_COUNTERS_CLOCK"
|
1081 |
|
|
#endif // ! CYGVAR_KERNEL_COUNTERS_CLOCK - can't test without it
|
1082 |
|
|
#else // ! CYGFUN_KERNEL_THREADS_TIMER - can't test without it
|
1083 |
|
|
#define N_A_MSG "no CYGFUN_KERNEL_THREADS_TIMER"
|
1084 |
|
|
#endif // ! CYGFUN_KERNEL_THREADS_TIMER - can't test without it
|
1085 |
|
|
#else // ! CYGIMP_THREAD_PRIORITY - can't test without it
|
1086 |
|
|
#define N_A_MSG "no CYGSEM_KERNEL_SCHED_MLQUEUE"
|
1087 |
|
|
#endif // ! CYGSEM_KERNEL_SCHED_MLQUEUE - can't test without it
|
1088 |
|
|
#else // ! CYGPKG_UITRON
|
1089 |
|
|
#define N_A_MSG "uITRON Compatibility layer disabled"
|
1090 |
|
|
#endif // CYGPKG_UITRON
|
1091 |
|
|
|
1092 |
|
|
#ifdef N_A_MSG
|
1093 |
|
|
externC void
|
1094 |
|
|
cyg_start( void )
|
1095 |
|
|
{
|
1096 |
|
|
CYG_TEST_INIT();
|
1097 |
|
|
CYG_TEST_NA( N_A_MSG );
|
1098 |
|
|
}
|
1099 |
|
|
#endif // N_A_MSG defined ie. we are N/A.
|
1100 |
|
|
|
1101 |
|
|
// EOF testcx7.cxx
|