OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [ecos-2.0/] [packages/] [compat/] [uitron/] [v2_0/] [tests/] [testcx3.cxx] - Blame information for rev 1765

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1254 phoenix
//===========================================================================
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 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
extern "C" {
108
    void task1( unsigned int arg );
109
    void task2( unsigned int arg );
110
    void task3( unsigned int arg );
111
    void task4( unsigned int arg );
112
}
113
 
114
void task1( unsigned int arg )
115
{
116
    ER ercd;
117
    INT scratch;
118
 
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" );
123
 
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" );
131
 
132
    // now start the test
133
    ercd = slp_tsk();
134
    CYG_TEST_CHECK( E_OK == ercd, "slp_tsk bad ercd" );
135
    CYG_TEST_INFO( "T1 awoken" );
136
    ercd = wai_sem( 1 );
137
    CYG_TEST_CHECK( E_OK == ercd, "wai_sem bad ercd" );
138
    CYG_TEST_INFO( "T1 signalled" );
139
 
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" );
143
 
144
    CYG_TEST_CHECK( t2done, "t2 not done" );
145
    CYG_TEST_CHECK( t3done, "t3 not done" );
146
    CYG_TEST_CHECK( t4done, "t4 not done" );
147
 
148
    CYG_TEST_PASS( "Immediate-dispatch producer/consumer test OK" );
149
 
150
    // all done
151
    CYG_TEST_EXIT( "All done" );
152
    ext_tsk();
153
}
154
 
155
 
156
 
157
void task2( unsigned int arg )
158
{
159
    ER ercd;
160
    INT scratch;
161
 
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" );
166
    if ( 222 != arg )
167
        CYG_TEST_FAIL( "Task 2 arg not 222" );
168
 
169
    // now start the test
170
    ercd = slp_tsk();
171
    CYG_TEST_CHECK( E_OK == ercd, "slp_tsk bad ercd" );
172
    CYG_TEST_INFO( "T2 awoken" );
173
    ercd = sig_sem( 1 );
174
    CYG_TEST_CHECK( E_OK == ercd, "sig_sem bad ercd" );
175
    ercd = wup_tsk( 1 );
176
    CYG_TEST_CHECK( E_OK == ercd, "wup_tsk bad ercd" );
177
 
178
    CYG_TEST_INFO( "T2 completing" );
179
    t2done++;
180
 
181
    ercd = slp_tsk();
182
    CYG_TEST_FAIL( "Task 2 sleep came back" );
183
}
184
 
185
void task3( unsigned int arg )
186
{
187
    ER ercd;
188
    INT scratch;
189
 
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" );
194
    if ( 333 != arg )
195
        CYG_TEST_FAIL( "Task 3 arg not 333" );
196
 
197
    // now start the test
198
    ercd = wai_sem( 1 );
199
    CYG_TEST_CHECK( E_OK == ercd, "wai_sem bad ercd" );
200
    CYG_TEST_INFO( "T3 awoken" );
201
    ercd = sig_sem( 1 );
202
    CYG_TEST_CHECK( E_OK == ercd, "sig_sem bad ercd" );
203
 
204
    CYG_TEST_INFO( "T3 completing" );
205
    t3done++;
206
 
207
    ercd = slp_tsk();
208
    CYG_TEST_FAIL( "Task 3 sleep came back" );
209
}
210
 
211
void task4( unsigned int arg )
212
{
213
    ER ercd;
214
    INT scratch;
215
 
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" );
220
    if ( 444 != arg )
221
        CYG_TEST_FAIL( "Task 4 arg not 444" );
222
 
223
    // now start the test
224
    ercd = wup_tsk( 2 );
225
    CYG_TEST_CHECK( E_OK == ercd, "wup_tsk bad ercd" );
226
 
227
    CYG_TEST_INFO( "T4 completing" );
228
    t4done++;
229
 
230
    ercd = slp_tsk();
231
    CYG_TEST_FAIL( "Task 4 sleep came back" );
232
}
233
 
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
252
 
253
#ifdef N_A_MSG
254
externC void
255
cyg_start( void )
256
{
257
    CYG_TEST_INIT();
258
    CYG_TEST_NA( N_A_MSG );
259
}
260
#endif // N_A_MSG defined ie. we are N/A.
261
 
262
// EOF testcx3.cxx

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.