1 |
786 |
skrzyp |
//===========================================================================
|
2 |
|
|
//
|
3 |
|
|
// testcx3.cxx
|
4 |
|
|
//
|
5 |
|
|
// uITRON "C++" test program three
|
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 Free Software Foundation, 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
|
16 |
|
|
// version.
|
17 |
|
|
//
|
18 |
|
|
// eCos is distributed in the hope that it will be useful, but WITHOUT
|
19 |
|
|
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
20 |
|
|
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
21 |
|
|
// for more details.
|
22 |
|
|
//
|
23 |
|
|
// You should have received a copy of the GNU General Public License
|
24 |
|
|
// along with eCos; if not, write to the Free Software Foundation, Inc.,
|
25 |
|
|
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
26 |
|
|
//
|
27 |
|
|
// As a special exception, if other files instantiate templates or use
|
28 |
|
|
// macros or inline functions from this file, or you compile this file
|
29 |
|
|
// and link it with other works to produce a work based on this file,
|
30 |
|
|
// this file does not by itself cause the resulting work to be covered by
|
31 |
|
|
// the GNU General Public License. However the source code for this file
|
32 |
|
|
// must still be made available in accordance with section (3) of the GNU
|
33 |
|
|
// General Public License v2.
|
34 |
|
|
//
|
35 |
|
|
// This exception does not invalidate any other reasons why a work based
|
36 |
|
|
// on this file might be covered by the GNU General Public License.
|
37 |
|
|
// -------------------------------------------
|
38 |
|
|
// ####ECOSGPLCOPYRIGHTEND####
|
39 |
|
|
//===========================================================================
|
40 |
|
|
//#####DESCRIPTIONBEGIN####
|
41 |
|
|
//
|
42 |
|
|
// Author(s): hmt
|
43 |
|
|
// Contributors: hmt
|
44 |
|
|
// Date: 1998-03-13
|
45 |
|
|
// Purpose: uITRON API testing
|
46 |
|
|
// Description:
|
47 |
|
|
//
|
48 |
|
|
//####DESCRIPTIONEND####
|
49 |
|
|
//
|
50 |
|
|
//===========================================================================
|
51 |
|
|
|
52 |
|
|
#include <pkgconf/uitron.h> // uITRON setup CYGNUM_UITRON_SEMAS
|
53 |
|
|
// CYGPKG_UITRON et al
|
54 |
|
|
#include <cyg/infra/testcase.h> // testing infrastructure
|
55 |
|
|
|
56 |
|
|
#ifdef CYGPKG_UITRON // we DO want the uITRON package
|
57 |
|
|
|
58 |
|
|
#ifdef CYGSEM_KERNEL_SCHED_MLQUEUE // we DO want prioritized threads
|
59 |
|
|
|
60 |
|
|
#ifdef CYGFUN_KERNEL_THREADS_TIMER // we DO want timout-able calls
|
61 |
|
|
|
62 |
|
|
#ifdef CYGVAR_KERNEL_COUNTERS_CLOCK // we DO want the realtime clock
|
63 |
|
|
|
64 |
|
|
// we're OK if it's C++ or neither of those two is defined:
|
65 |
|
|
#if defined( __cplusplus ) || \
|
66 |
|
|
(!defined( CYGIMP_UITRON_INLINE_FUNCS ) && \
|
67 |
|
|
!defined( CYGIMP_UITRON_CPP_OUTLINE_FUNCS) )
|
68 |
|
|
|
69 |
|
|
// =================== TEST CONFIGURATION ===================
|
70 |
|
|
#if \
|
71 |
|
|
/* test configuration for enough tasks */ \
|
72 |
|
|
(CYGNUM_UITRON_TASKS >= 4) && \
|
73 |
|
|
(CYGNUM_UITRON_TASKS < 90) && \
|
74 |
|
|
(CYGNUM_UITRON_START_TASKS == 1) && \
|
75 |
|
|
( !defined(CYGPKG_UITRON_TASKS_CREATE_DELETE) || \
|
76 |
|
|
CYGNUM_UITRON_TASKS_INITIALLY >= 4 ) && \
|
77 |
|
|
\
|
78 |
|
|
/* test configuration for enough semaphores */ \
|
79 |
|
|
defined( CYGPKG_UITRON_SEMAS ) && \
|
80 |
|
|
(CYGNUM_UITRON_SEMAS >= 3) && \
|
81 |
|
|
(CYGNUM_UITRON_SEMAS < 90) && \
|
82 |
|
|
( !defined(CYGPKG_UITRON_SEMAS_CREATE_DELETE) || \
|
83 |
|
|
CYGNUM_UITRON_SEMAS_INITIALLY >= 3 ) && \
|
84 |
|
|
\
|
85 |
|
|
/* the end of the large #if statement */ \
|
86 |
|
|
1
|
87 |
|
|
|
88 |
|
|
// ============================ END ============================
|
89 |
|
|
|
90 |
|
|
|
91 |
|
|
|
92 |
|
|
#include <cyg/compat/uitron/uit_func.h> // uITRON
|
93 |
|
|
|
94 |
|
|
int t2done = 0;
|
95 |
|
|
int t3done = 0;
|
96 |
|
|
int t4done = 0;
|
97 |
|
|
|
98 |
|
|
externC void
|
99 |
|
|
cyg_package_start( void )
|
100 |
|
|
{
|
101 |
|
|
CYG_TEST_INIT();
|
102 |
|
|
CYG_TEST_INFO( "Calling cyg_uitron_start()" );
|
103 |
|
|
cyg_uitron_start();
|
104 |
|
|
}
|
105 |
|
|
|
106 |
|
|
extern "C" {
|
107 |
|
|
void task1( unsigned int arg );
|
108 |
|
|
void task2( unsigned int arg );
|
109 |
|
|
void task3( unsigned int arg );
|
110 |
|
|
void task4( unsigned int arg );
|
111 |
|
|
}
|
112 |
|
|
|
113 |
|
|
void task1( unsigned int arg )
|
114 |
|
|
{
|
115 |
|
|
ER ercd;
|
116 |
|
|
INT scratch;
|
117 |
|
|
|
118 |
|
|
CYG_TEST_INFO( "Task 1 running" );
|
119 |
|
|
ercd = get_tid( &scratch );
|
120 |
|
|
CYG_TEST_CHECK( E_OK == ercd, "get_tid bad ercd" );
|
121 |
|
|
CYG_TEST_CHECK( 1 == scratch, "tid not 1" );
|
122 |
|
|
|
123 |
|
|
// start lower prio tasks to interact with
|
124 |
|
|
ercd = sta_tsk( 2, 222 );
|
125 |
|
|
CYG_TEST_CHECK( E_OK == ercd, "sta_tsk bad ercd" );
|
126 |
|
|
ercd = sta_tsk( 3, 333 );
|
127 |
|
|
CYG_TEST_CHECK( E_OK == ercd, "sta_tsk bad ercd" );
|
128 |
|
|
ercd = sta_tsk( 4, 444 );
|
129 |
|
|
CYG_TEST_CHECK( E_OK == ercd, "sta_tsk bad ercd" );
|
130 |
|
|
|
131 |
|
|
// now start the test
|
132 |
|
|
ercd = slp_tsk();
|
133 |
|
|
CYG_TEST_CHECK( E_OK == ercd, "slp_tsk bad ercd" );
|
134 |
|
|
CYG_TEST_INFO( "T1 awoken" );
|
135 |
|
|
ercd = wai_sem( 1 );
|
136 |
|
|
CYG_TEST_CHECK( E_OK == ercd, "wai_sem bad ercd" );
|
137 |
|
|
CYG_TEST_INFO( "T1 signalled" );
|
138 |
|
|
|
139 |
|
|
// let the others complete, so we get the status back
|
140 |
|
|
ercd = dly_tsk( 50 );
|
141 |
|
|
CYG_TEST_CHECK( E_OK == ercd, "dly_tsk bad ercd" );
|
142 |
|
|
|
143 |
|
|
CYG_TEST_CHECK( t2done, "t2 not done" );
|
144 |
|
|
CYG_TEST_CHECK( t3done, "t3 not done" );
|
145 |
|
|
CYG_TEST_CHECK( t4done, "t4 not done" );
|
146 |
|
|
|
147 |
|
|
CYG_TEST_PASS( "Immediate-dispatch producer/consumer test OK" );
|
148 |
|
|
|
149 |
|
|
// all done
|
150 |
|
|
CYG_TEST_EXIT( "All done" );
|
151 |
|
|
ext_tsk();
|
152 |
|
|
}
|
153 |
|
|
|
154 |
|
|
|
155 |
|
|
|
156 |
|
|
void task2( unsigned int arg )
|
157 |
|
|
{
|
158 |
|
|
ER ercd;
|
159 |
|
|
INT scratch;
|
160 |
|
|
|
161 |
|
|
CYG_TEST_INFO( "Task 2 running" );
|
162 |
|
|
ercd = get_tid( &scratch );
|
163 |
|
|
CYG_TEST_CHECK( E_OK == ercd, "get_tid bad ercd" );
|
164 |
|
|
CYG_TEST_CHECK( 2 == scratch, "tid not 2" );
|
165 |
|
|
if ( 222 != arg )
|
166 |
|
|
CYG_TEST_FAIL( "Task 2 arg not 222" );
|
167 |
|
|
|
168 |
|
|
// now start the test
|
169 |
|
|
ercd = slp_tsk();
|
170 |
|
|
CYG_TEST_CHECK( E_OK == ercd, "slp_tsk bad ercd" );
|
171 |
|
|
CYG_TEST_INFO( "T2 awoken" );
|
172 |
|
|
ercd = sig_sem( 1 );
|
173 |
|
|
CYG_TEST_CHECK( E_OK == ercd, "sig_sem bad ercd" );
|
174 |
|
|
ercd = wup_tsk( 1 );
|
175 |
|
|
CYG_TEST_CHECK( E_OK == ercd, "wup_tsk bad ercd" );
|
176 |
|
|
|
177 |
|
|
CYG_TEST_INFO( "T2 completing" );
|
178 |
|
|
t2done++;
|
179 |
|
|
|
180 |
|
|
ercd = slp_tsk();
|
181 |
|
|
CYG_TEST_FAIL( "Task 2 sleep came back" );
|
182 |
|
|
}
|
183 |
|
|
|
184 |
|
|
void task3( unsigned int arg )
|
185 |
|
|
{
|
186 |
|
|
ER ercd;
|
187 |
|
|
INT scratch;
|
188 |
|
|
|
189 |
|
|
CYG_TEST_INFO( "Task 3 running" );
|
190 |
|
|
ercd = get_tid( &scratch );
|
191 |
|
|
CYG_TEST_CHECK( E_OK == ercd, "get_tid bad ercd" );
|
192 |
|
|
CYG_TEST_CHECK( 3 == scratch, "tid not 3" );
|
193 |
|
|
if ( 333 != arg )
|
194 |
|
|
CYG_TEST_FAIL( "Task 3 arg not 333" );
|
195 |
|
|
|
196 |
|
|
// now start the test
|
197 |
|
|
ercd = wai_sem( 1 );
|
198 |
|
|
CYG_TEST_CHECK( E_OK == ercd, "wai_sem bad ercd" );
|
199 |
|
|
CYG_TEST_INFO( "T3 awoken" );
|
200 |
|
|
ercd = sig_sem( 1 );
|
201 |
|
|
CYG_TEST_CHECK( E_OK == ercd, "sig_sem bad ercd" );
|
202 |
|
|
|
203 |
|
|
CYG_TEST_INFO( "T3 completing" );
|
204 |
|
|
t3done++;
|
205 |
|
|
|
206 |
|
|
ercd = slp_tsk();
|
207 |
|
|
CYG_TEST_FAIL( "Task 3 sleep came back" );
|
208 |
|
|
}
|
209 |
|
|
|
210 |
|
|
void task4( unsigned int arg )
|
211 |
|
|
{
|
212 |
|
|
ER ercd;
|
213 |
|
|
INT scratch;
|
214 |
|
|
|
215 |
|
|
CYG_TEST_INFO( "Task 4 running" );
|
216 |
|
|
ercd = get_tid( &scratch );
|
217 |
|
|
CYG_TEST_CHECK( E_OK == ercd, "get_tid bad ercd" );
|
218 |
|
|
CYG_TEST_CHECK( 4 == scratch, "tid not 4" );
|
219 |
|
|
if ( 444 != arg )
|
220 |
|
|
CYG_TEST_FAIL( "Task 4 arg not 444" );
|
221 |
|
|
|
222 |
|
|
// now start the test
|
223 |
|
|
ercd = wup_tsk( 2 );
|
224 |
|
|
CYG_TEST_CHECK( E_OK == ercd, "wup_tsk bad ercd" );
|
225 |
|
|
|
226 |
|
|
CYG_TEST_INFO( "T4 completing" );
|
227 |
|
|
t4done++;
|
228 |
|
|
|
229 |
|
|
ercd = slp_tsk();
|
230 |
|
|
CYG_TEST_FAIL( "Task 4 sleep came back" );
|
231 |
|
|
}
|
232 |
|
|
|
233 |
|
|
#else // not enough (or too many) uITRON objects configured in
|
234 |
|
|
#define N_A_MSG "not enough uITRON objects to run test"
|
235 |
|
|
#endif // not enough (or too many) uITRON objects configured in
|
236 |
|
|
#else // not C++ and some C++ specific options enabled
|
237 |
|
|
#define N_A_MSG "C++ specific options selected but this is C"
|
238 |
|
|
#endif // not C++ and some C++ specific options enabled
|
239 |
|
|
#else // ! CYGVAR_KERNEL_COUNTERS_CLOCK - can't test without it
|
240 |
|
|
#define N_A_MSG "no CYGVAR_KERNEL_COUNTERS_CLOCK"
|
241 |
|
|
#endif // ! CYGVAR_KERNEL_COUNTERS_CLOCK - can't test without it
|
242 |
|
|
#else // ! CYGFUN_KERNEL_THREADS_TIMER - can't test without it
|
243 |
|
|
#define N_A_MSG "no CYGFUN_KERNEL_THREADS_TIMER"
|
244 |
|
|
#endif // ! CYGFUN_KERNEL_THREADS_TIMER - can't test without it
|
245 |
|
|
#else // ! CYGIMP_THREAD_PRIORITY - can't test without it
|
246 |
|
|
#define N_A_MSG "no CYGSEM_KERNEL_SCHED_MLQUEUE"
|
247 |
|
|
#endif // ! CYGSEM_KERNEL_SCHED_MLQUEUE - can't test without it
|
248 |
|
|
#else // ! CYGPKG_UITRON
|
249 |
|
|
#define N_A_MSG "uITRON Compatibility layer disabled"
|
250 |
|
|
#endif // CYGPKG_UITRON
|
251 |
|
|
|
252 |
|
|
#ifdef N_A_MSG
|
253 |
|
|
externC void
|
254 |
|
|
cyg_start( void )
|
255 |
|
|
{
|
256 |
|
|
CYG_TEST_INIT();
|
257 |
|
|
CYG_TEST_NA( N_A_MSG );
|
258 |
|
|
}
|
259 |
|
|
#endif // N_A_MSG defined ie. we are N/A.
|
260 |
|
|
|
261 |
|
|
// EOF testcx3.cxx
|