1 |
27 |
unneback |
//===========================================================================
|
2 |
|
|
//
|
3 |
|
|
// test3.c
|
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 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-03-13
|
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 |
|
|
/* the end of the large #if statement */ \
|
87 |
|
|
1
|
88 |
|
|
|
89 |
|
|
// ============================ END ============================
|
90 |
|
|
|
91 |
|
|
|
92 |
|
|
|
93 |
|
|
#include <cyg/compat/uitron/uit_func.h> // uITRON
|
94 |
|
|
|
95 |
|
|
int t2done = 0;
|
96 |
|
|
int t3done = 0;
|
97 |
|
|
int t4done = 0;
|
98 |
|
|
|
99 |
|
|
externC void
|
100 |
|
|
cyg_package_start( void )
|
101 |
|
|
{
|
102 |
|
|
CYG_TEST_INIT();
|
103 |
|
|
CYG_TEST_INFO( "Calling cyg_uitron_start()" );
|
104 |
|
|
cyg_uitron_start();
|
105 |
|
|
}
|
106 |
|
|
|
107 |
|
|
void task1( unsigned int arg )
|
108 |
|
|
{
|
109 |
|
|
ER ercd;
|
110 |
|
|
INT scratch;
|
111 |
|
|
|
112 |
|
|
CYG_TEST_INFO( "Task 1 running" );
|
113 |
|
|
ercd = get_tid( &scratch );
|
114 |
|
|
CYG_TEST_CHECK( E_OK == ercd, "get_tid bad ercd" );
|
115 |
|
|
CYG_TEST_CHECK( 1 == scratch, "tid not 1" );
|
116 |
|
|
|
117 |
|
|
// start lower prio tasks to interact with
|
118 |
|
|
ercd = sta_tsk( 2, 222 );
|
119 |
|
|
CYG_TEST_CHECK( E_OK == ercd, "sta_tsk bad ercd" );
|
120 |
|
|
ercd = sta_tsk( 3, 333 );
|
121 |
|
|
CYG_TEST_CHECK( E_OK == ercd, "sta_tsk bad ercd" );
|
122 |
|
|
ercd = sta_tsk( 4, 444 );
|
123 |
|
|
CYG_TEST_CHECK( E_OK == ercd, "sta_tsk bad ercd" );
|
124 |
|
|
|
125 |
|
|
// now start the test
|
126 |
|
|
ercd = slp_tsk();
|
127 |
|
|
CYG_TEST_CHECK( E_OK == ercd, "slp_tsk bad ercd" );
|
128 |
|
|
CYG_TEST_INFO( "T1 awoken" );
|
129 |
|
|
ercd = wai_sem( 1 );
|
130 |
|
|
CYG_TEST_CHECK( E_OK == ercd, "wai_sem bad ercd" );
|
131 |
|
|
CYG_TEST_INFO( "T1 signalled" );
|
132 |
|
|
|
133 |
|
|
// let the others complete, so we get the status back
|
134 |
|
|
ercd = dly_tsk( 50 );
|
135 |
|
|
CYG_TEST_CHECK( E_OK == ercd, "dly_tsk bad ercd" );
|
136 |
|
|
|
137 |
|
|
CYG_TEST_CHECK( t2done, "t2 not done" );
|
138 |
|
|
CYG_TEST_CHECK( t3done, "t3 not done" );
|
139 |
|
|
CYG_TEST_CHECK( t4done, "t4 not done" );
|
140 |
|
|
|
141 |
|
|
CYG_TEST_PASS( "Immediate-dispatch producer/consumer test OK" );
|
142 |
|
|
|
143 |
|
|
// all done
|
144 |
|
|
CYG_TEST_EXIT( "All done" );
|
145 |
|
|
ext_tsk();
|
146 |
|
|
}
|
147 |
|
|
|
148 |
|
|
|
149 |
|
|
|
150 |
|
|
void task2( unsigned int arg )
|
151 |
|
|
{
|
152 |
|
|
ER ercd;
|
153 |
|
|
INT scratch;
|
154 |
|
|
|
155 |
|
|
CYG_TEST_INFO( "Task 2 running" );
|
156 |
|
|
ercd = get_tid( &scratch );
|
157 |
|
|
CYG_TEST_CHECK( E_OK == ercd, "get_tid bad ercd" );
|
158 |
|
|
CYG_TEST_CHECK( 2 == scratch, "tid not 2" );
|
159 |
|
|
if ( 222 != arg )
|
160 |
|
|
CYG_TEST_FAIL( "Task 2 arg not 222" );
|
161 |
|
|
|
162 |
|
|
// now start the test
|
163 |
|
|
ercd = slp_tsk();
|
164 |
|
|
CYG_TEST_CHECK( E_OK == ercd, "slp_tsk bad ercd" );
|
165 |
|
|
CYG_TEST_INFO( "T2 awoken" );
|
166 |
|
|
ercd = sig_sem( 1 );
|
167 |
|
|
CYG_TEST_CHECK( E_OK == ercd, "sig_sem bad ercd" );
|
168 |
|
|
ercd = wup_tsk( 1 );
|
169 |
|
|
CYG_TEST_CHECK( E_OK == ercd, "wup_tsk bad ercd" );
|
170 |
|
|
|
171 |
|
|
CYG_TEST_INFO( "T2 completing" );
|
172 |
|
|
t2done++;
|
173 |
|
|
|
174 |
|
|
ercd = slp_tsk();
|
175 |
|
|
CYG_TEST_FAIL( "Task 2 sleep came back" );
|
176 |
|
|
}
|
177 |
|
|
|
178 |
|
|
void task3( unsigned int arg )
|
179 |
|
|
{
|
180 |
|
|
ER ercd;
|
181 |
|
|
INT scratch;
|
182 |
|
|
|
183 |
|
|
CYG_TEST_INFO( "Task 3 running" );
|
184 |
|
|
ercd = get_tid( &scratch );
|
185 |
|
|
CYG_TEST_CHECK( E_OK == ercd, "get_tid bad ercd" );
|
186 |
|
|
CYG_TEST_CHECK( 3 == scratch, "tid not 3" );
|
187 |
|
|
if ( 333 != arg )
|
188 |
|
|
CYG_TEST_FAIL( "Task 3 arg not 333" );
|
189 |
|
|
|
190 |
|
|
// now start the test
|
191 |
|
|
ercd = wai_sem( 1 );
|
192 |
|
|
CYG_TEST_CHECK( E_OK == ercd, "wai_sem bad ercd" );
|
193 |
|
|
CYG_TEST_INFO( "T3 awoken" );
|
194 |
|
|
ercd = sig_sem( 1 );
|
195 |
|
|
CYG_TEST_CHECK( E_OK == ercd, "sig_sem bad ercd" );
|
196 |
|
|
|
197 |
|
|
CYG_TEST_INFO( "T3 completing" );
|
198 |
|
|
t3done++;
|
199 |
|
|
|
200 |
|
|
ercd = slp_tsk();
|
201 |
|
|
CYG_TEST_FAIL( "Task 3 sleep came back" );
|
202 |
|
|
}
|
203 |
|
|
|
204 |
|
|
void task4( unsigned int arg )
|
205 |
|
|
{
|
206 |
|
|
ER ercd;
|
207 |
|
|
INT scratch;
|
208 |
|
|
|
209 |
|
|
CYG_TEST_INFO( "Task 4 running" );
|
210 |
|
|
ercd = get_tid( &scratch );
|
211 |
|
|
CYG_TEST_CHECK( E_OK == ercd, "get_tid bad ercd" );
|
212 |
|
|
CYG_TEST_CHECK( 4 == scratch, "tid not 4" );
|
213 |
|
|
if ( 444 != arg )
|
214 |
|
|
CYG_TEST_FAIL( "Task 4 arg not 444" );
|
215 |
|
|
|
216 |
|
|
// now start the test
|
217 |
|
|
ercd = wup_tsk( 2 );
|
218 |
|
|
CYG_TEST_CHECK( E_OK == ercd, "wup_tsk bad ercd" );
|
219 |
|
|
|
220 |
|
|
CYG_TEST_INFO( "T4 completing" );
|
221 |
|
|
t4done++;
|
222 |
|
|
|
223 |
|
|
ercd = slp_tsk();
|
224 |
|
|
CYG_TEST_FAIL( "Task 4 sleep came back" );
|
225 |
|
|
}
|
226 |
|
|
|
227 |
|
|
#else // not enough (or too many) uITRON objects configured in
|
228 |
|
|
#define N_A_MSG "not enough uITRON objects to run test"
|
229 |
|
|
#endif // not enough (or too many) uITRON objects configured in
|
230 |
|
|
#else // not C++ and some C++ specific options enabled
|
231 |
|
|
#define N_A_MSG "C++ specific options selected but this is C"
|
232 |
|
|
#endif // not C++ and some C++ specific options enabled
|
233 |
|
|
#else // ! CYGVAR_KERNEL_COUNTERS_CLOCK - can't test without it
|
234 |
|
|
#define N_A_MSG "no CYGVAR_KERNEL_COUNTERS_CLOCK"
|
235 |
|
|
#endif // ! CYGVAR_KERNEL_COUNTERS_CLOCK - can't test without it
|
236 |
|
|
#else // ! CYGFUN_KERNEL_THREADS_TIMER - can't test without it
|
237 |
|
|
#define N_A_MSG "no CYGFUN_KERNEL_THREADS_TIMER"
|
238 |
|
|
#endif // ! CYGFUN_KERNEL_THREADS_TIMER - can't test without it
|
239 |
|
|
#else // ! CYGIMP_THREAD_PRIORITY - can't test without it
|
240 |
|
|
#define N_A_MSG "no CYGSEM_KERNEL_SCHED_MLQUEUE"
|
241 |
|
|
#endif // ! CYGSEM_KERNEL_SCHED_MLQUEUE - can't test without it
|
242 |
|
|
#else // ! CYGPKG_UITRON
|
243 |
|
|
#define N_A_MSG "uITRON Compatibility layer disabled"
|
244 |
|
|
#endif // CYGPKG_UITRON
|
245 |
|
|
|
246 |
|
|
#ifdef N_A_MSG
|
247 |
|
|
void
|
248 |
|
|
cyg_start( void )
|
249 |
|
|
{
|
250 |
|
|
CYG_TEST_INIT();
|
251 |
|
|
CYG_TEST_NA( N_A_MSG );
|
252 |
|
|
}
|
253 |
|
|
#endif // N_A_MSG defined ie. we are N/A.
|
254 |
|
|
|
255 |
|
|
// EOF test3.c
|