1 //===========================================================================
5 // uITRON "C++" test program three
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.
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.
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
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.
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.
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.
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####
46 // Purpose: uITRON API testing
49 //####DESCRIPTIONEND####
51 //===========================================================================
53 #include <pkgconf/uitron.h> // uITRON setup CYGNUM_UITRON_SEMAS
54 // CYGPKG_UITRON et al
55 #include <cyg/infra/testcase.h> // testing infrastructure
57 #ifdef CYGPKG_UITRON // we DO want the uITRON package
59 #ifdef CYGSEM_KERNEL_SCHED_MLQUEUE // we DO want prioritized threads
61 #ifdef CYGFUN_KERNEL_THREADS_TIMER // we DO want timout-able calls
63 #ifdef CYGVAR_KERNEL_COUNTERS_CLOCK // we DO want the realtime clock
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) )
70 // =================== TEST CONFIGURATION ===================
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 ) && \
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 ) && \
86 /* the end of the large #if statement */ \
89 // ============================ END ============================
93 #include <cyg/compat/uitron/uit_func.h> // uITRON
100 cyg_package_start( void )
103 CYG_TEST_INFO( "Calling cyg_uitron_start()" );
108 void task1( unsigned int arg );
109 void task2( unsigned int arg );
110 void task3( unsigned int arg );
111 void task4( unsigned int arg );
114 void task1( unsigned int arg )
119 CYG_TEST_INFO( "Task 1 running" );
120 ercd = get_tid( &scratch );
121 CYG_TEST_CHECK( E_OK == ercd, "get_tid bad ercd" );
122 CYG_TEST_CHECK( 1 == scratch, "tid not 1" );
124 // start lower prio tasks to interact with
125 ercd = sta_tsk( 2, 222 );
126 CYG_TEST_CHECK( E_OK == ercd, "sta_tsk bad ercd" );
127 ercd = sta_tsk( 3, 333 );
128 CYG_TEST_CHECK( E_OK == ercd, "sta_tsk bad ercd" );
129 ercd = sta_tsk( 4, 444 );
130 CYG_TEST_CHECK( E_OK == ercd, "sta_tsk bad ercd" );
132 // now start the test
134 CYG_TEST_CHECK( E_OK == ercd, "slp_tsk bad ercd" );
135 CYG_TEST_INFO( "T1 awoken" );
137 CYG_TEST_CHECK( E_OK == ercd, "wai_sem bad ercd" );
138 CYG_TEST_INFO( "T1 signalled" );
140 // let the others complete, so we get the status back
141 ercd = dly_tsk( 50 );
142 CYG_TEST_CHECK( E_OK == ercd, "dly_tsk bad ercd" );
144 CYG_TEST_CHECK( t2done, "t2 not done" );
145 CYG_TEST_CHECK( t3done, "t3 not done" );
146 CYG_TEST_CHECK( t4done, "t4 not done" );
148 CYG_TEST_PASS( "Immediate-dispatch producer/consumer test OK" );
151 CYG_TEST_EXIT( "All done" );
157 void task2( unsigned int arg )
162 CYG_TEST_INFO( "Task 2 running" );
163 ercd = get_tid( &scratch );
164 CYG_TEST_CHECK( E_OK == ercd, "get_tid bad ercd" );
165 CYG_TEST_CHECK( 2 == scratch, "tid not 2" );
167 CYG_TEST_FAIL( "Task 2 arg not 222" );
169 // now start the test
171 CYG_TEST_CHECK( E_OK == ercd, "slp_tsk bad ercd" );
172 CYG_TEST_INFO( "T2 awoken" );
174 CYG_TEST_CHECK( E_OK == ercd, "sig_sem bad ercd" );
176 CYG_TEST_CHECK( E_OK == ercd, "wup_tsk bad ercd" );
178 CYG_TEST_INFO( "T2 completing" );
182 CYG_TEST_FAIL( "Task 2 sleep came back" );
185 void task3( unsigned int arg )
190 CYG_TEST_INFO( "Task 3 running" );
191 ercd = get_tid( &scratch );
192 CYG_TEST_CHECK( E_OK == ercd, "get_tid bad ercd" );
193 CYG_TEST_CHECK( 3 == scratch, "tid not 3" );
195 CYG_TEST_FAIL( "Task 3 arg not 333" );
197 // now start the test
199 CYG_TEST_CHECK( E_OK == ercd, "wai_sem bad ercd" );
200 CYG_TEST_INFO( "T3 awoken" );
202 CYG_TEST_CHECK( E_OK == ercd, "sig_sem bad ercd" );
204 CYG_TEST_INFO( "T3 completing" );
208 CYG_TEST_FAIL( "Task 3 sleep came back" );
211 void task4( unsigned int arg )
216 CYG_TEST_INFO( "Task 4 running" );
217 ercd = get_tid( &scratch );
218 CYG_TEST_CHECK( E_OK == ercd, "get_tid bad ercd" );
219 CYG_TEST_CHECK( 4 == scratch, "tid not 4" );
221 CYG_TEST_FAIL( "Task 4 arg not 444" );
223 // now start the test
225 CYG_TEST_CHECK( E_OK == ercd, "wup_tsk bad ercd" );
227 CYG_TEST_INFO( "T4 completing" );
231 CYG_TEST_FAIL( "Task 4 sleep came back" );
234 #else // not enough (or too many) uITRON objects configured in
235 #define N_A_MSG "not enough uITRON objects to run test"
236 #endif // not enough (or too many) uITRON objects configured in
237 #else // not C++ and some C++ specific options enabled
238 #define N_A_MSG "C++ specific options selected but this is C"
239 #endif // not C++ and some C++ specific options enabled
240 #else // ! CYGVAR_KERNEL_COUNTERS_CLOCK - can't test without it
241 #define N_A_MSG "no CYGVAR_KERNEL_COUNTERS_CLOCK"
242 #endif // ! CYGVAR_KERNEL_COUNTERS_CLOCK - can't test without it
243 #else // ! CYGFUN_KERNEL_THREADS_TIMER - can't test without it
244 #define N_A_MSG "no CYGFUN_KERNEL_THREADS_TIMER"
245 #endif // ! CYGFUN_KERNEL_THREADS_TIMER - can't test without it
246 #else // ! CYGIMP_THREAD_PRIORITY - can't test without it
247 #define N_A_MSG "no CYGSEM_KERNEL_SCHED_MLQUEUE"
248 #endif // ! CYGSEM_KERNEL_SCHED_MLQUEUE - can't test without it
249 #else // ! CYGPKG_UITRON
250 #define N_A_MSG "uITRON Compatibility layer disabled"
251 #endif // CYGPKG_UITRON
258 CYG_TEST_NA( N_A_MSG );
260 #endif // N_A_MSG defined ie. we are N/A.