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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-2.0/] [packages/] [compat/] [uitron/] [v2_0/] [tests/] [testcx5.cxx] - Blame information for rev 773

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 27 unneback
//===========================================================================
2
//
3
//      testcx5.cxx
4
//
5
//      uITRON "C++" test program five
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):   dsm
44
// Contributors:        dsm
45
// Date:        1998-06-12
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
 
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
volatile int intercount = 0;
132
 
133
UINT scratch;
134
T_MSG *t_msg;
135
VP vp;
136
 
137
 
138
extern "C" {
139
    void task1( unsigned int arg );
140
    void task2( unsigned int arg );
141
    void task3( unsigned int arg );
142
    void task4( unsigned int arg );
143
}
144
 
145
 
146
void task1( unsigned int arg )
147
{
148
    ER ercd;
149
    int i;
150
    T_RSYS rsys;
151
 
152
    CYG_TEST_INFO( "Task 1 running" );
153
 
154
    // check initial state
155
    ercd = ref_sys( &rsys );
156
    CYG_TEST_CHECK( E_OK == ercd, "ref_sys bad ercd" );
157
    CYG_TEST_CHECK( TSS_TSK == rsys.sysstat, "system state not TSS_TSK" );
158
    // disable intrs and check state
159
    ercd = loc_cpu();
160
    CYG_TEST_CHECK( E_OK == ercd, "loc_cpu bad ercd" );
161
    ercd = ref_sys( &rsys );
162
    CYG_TEST_CHECK( E_OK == ercd, "ref_sys bad ercd" );
163
    CYG_TEST_CHECK( TSS_LOC == rsys.sysstat, "system state not TSS_LOC" );
164
#ifdef CYGSEM_UITRON_BAD_PARAMS_RETURN_ERRORS
165
    // try an illegal op
166
    ercd = dly_tsk( 10 );
167
    CYG_TEST_CHECK( E_CTX == ercd, "dly_tsk bad ercd !E_CTX" );
168
#endif // CYGSEM_UITRON_BAD_PARAMS_RETURN_ERRORS
169
    // enable intrs and check state and a legal sleep
170
    ercd = unl_cpu();
171
    CYG_TEST_CHECK( E_OK == ercd, "unl_cpu bad ercd" );
172
    ercd = ref_sys( &rsys );
173
    CYG_TEST_CHECK( E_OK == ercd, "ref_sys bad ercd" );
174
    CYG_TEST_CHECK( TSS_TSK == rsys.sysstat, "system state not TSS_TSK" );
175
    ercd = dly_tsk( 1 );
176
    CYG_TEST_CHECK( E_OK == ercd, "dly_tsk bad ercd" );
177
    // disable intrs and try scheduler illegal ops
178
    ercd = loc_cpu();
179
    CYG_TEST_CHECK( E_OK == ercd, "loc_cpu bad ercd" );
180
    ercd = ref_sys( &rsys );
181
    CYG_TEST_CHECK( E_OK == ercd, "ref_sys bad ercd" );
182
    CYG_TEST_CHECK( TSS_LOC == rsys.sysstat, "system state not TSS_LOC" );
183
#ifdef CYGSEM_UITRON_BAD_PARAMS_RETURN_ERRORS
184
    ercd = dis_dsp();
185
    CYG_TEST_CHECK( E_CTX == ercd, "dis_dsp bad ercd !E_CTX" );
186
    ercd = ena_dsp();
187
    CYG_TEST_CHECK( E_CTX == ercd, "ena_dsp bad ercd !E_CTX" );
188
#endif // CYGSEM_UITRON_BAD_PARAMS_RETURN_ERRORS
189
    // enable again and check state
190
    ercd = unl_cpu();
191
    CYG_TEST_CHECK( E_OK == ercd, "unl_cpu bad ercd" );
192
    ercd = ref_sys( &rsys );
193
    CYG_TEST_CHECK( E_OK == ercd, "ref_sys bad ercd" );
194
    CYG_TEST_CHECK( TSS_TSK == rsys.sysstat, "system state not TSS_TSK" );
195
    // disable the scheduler and check state
196
    ercd = dis_dsp();
197
    CYG_TEST_CHECK( E_OK == ercd, "dis_dsp bad ercd" );
198
    ercd = ref_sys( &rsys );
199
    CYG_TEST_CHECK( E_OK == ercd, "ref_sys bad ercd" );
200
    CYG_TEST_CHECK( TSS_DDSP == rsys.sysstat, "system state not TSS_DDSP" );
201
    // disable intrs and check state
202
    ercd = loc_cpu();
203
    CYG_TEST_CHECK( E_OK == ercd, "loc_cpu bad ercd" );
204
    ercd = ref_sys( &rsys );
205
    CYG_TEST_CHECK( E_OK == ercd, "ref_sys bad ercd" );
206
    CYG_TEST_CHECK( TSS_LOC == rsys.sysstat, "system state not TSS_LOC" );
207
    // then unlock and check state
208
    ercd = unl_cpu();
209
    CYG_TEST_CHECK( E_OK == ercd, "unl_cpu bad ercd" );
210
    ercd = ref_sys( &rsys );
211
    CYG_TEST_CHECK( E_OK == ercd, "ref_sys bad ercd" );
212
    CYG_TEST_CHECK( TSS_TSK == rsys.sysstat, "system state not TSS_TSK" );
213
 
214
    CYG_TEST_PASS( "Interrupt dis/enabling and interactions" );
215
 
216
    // and now we can do the rest of the test
217
 
218
#ifdef CYGSEM_UITRON_BAD_PARAMS_RETURN_ERRORS
219
    ercd = rel_wai( 2 );
220
    CYG_TEST_CHECK( E_OBJ == ercd, "rel_wai bad ercd !E_OBJ" );
221
    ercd = rel_wai( 1 );
222
    CYG_TEST_CHECK( E_OBJ == ercd, "rel_wai(me) bad ercd !E_OBJ" );
223
    ercd = rel_wai( -6 );
224
    CYG_TEST_CHECK( E_ID == ercd, "rel_wai bad ercd !E_ID" );
225
    ercd = rel_wai( 99 );
226
    CYG_TEST_CHECK( E_ID == ercd, "rel_wai bad ercd !E_ID" );
227
#endif // we can test bad param error returns
228
 
229
    ercd = dis_dsp();
230
    CYG_TEST_CHECK( E_OK == ercd, "dis_dsp bad ercd" );
231
    ercd = sta_tsk( 2, 22222 );
232
    CYG_TEST_CHECK( E_OK == ercd, "sta_tsk bad ercd" );
233
    ercd = chg_pri( 2, 5 );
234
    CYG_TEST_CHECK( E_OK == ercd, "chg_pri bad ercd" );
235
    ercd = ena_dsp();
236
    CYG_TEST_CHECK( E_OK == ercd, "ena_dsp bad ercd" );
237
 
238
#ifdef CYGSEM_UITRON_BAD_PARAMS_RETURN_ERRORS
239
    ercd = rel_wai( 2 );
240
    CYG_TEST_CHECK( E_OBJ == ercd, "rel_wai bad ercd !E_OBJ" );
241
    ercd = rel_wai( 1 );
242
    CYG_TEST_CHECK( E_OBJ == ercd, "rel_wai(me) bad ercd !E_OBJ" );
243
#endif // we can test bad param error returns
244
 
245
    ercd = wai_sem( 1 );
246
    CYG_TEST_CHECK( E_RLWAI == ercd, "wai_sem bad ercd !E_RLWAI" );
247
 
248
    ercd = twai_sem( 1, 20 );
249
    CYG_TEST_CHECK( E_RLWAI == ercd, "twai_sem bad ercd !E_RLWAI" );
250
 
251
    ercd = wai_flg( &scratch, 1, 9999, 0 );
252
    CYG_TEST_CHECK( E_RLWAI == ercd, "wai_flg bad ercd !E_RLWAI" );
253
 
254
    ercd = twai_flg( &scratch, 1, 9999, 0, 10 );
255
    CYG_TEST_CHECK( E_RLWAI == ercd, "twai_flg bad ercd !E_RLWAI" );
256
 
257
    ercd = rcv_msg( &t_msg, 1 );
258
    CYG_TEST_CHECK( E_RLWAI == ercd, "rcv_msg bad ercd !E_RLWAI" );
259
 
260
    ercd = trcv_msg( &t_msg, 1, 10 );
261
    CYG_TEST_CHECK( E_RLWAI == ercd, "trcv_msg bad ercd !E_RLWAI" );
262
 
263
    // these are loops so as to consume the whole of the mempool
264
    // in order to wait at the end
265
    for ( i = 0; i < 10; i++ )
266
        if ( E_OK != (ercd = get_blf( &vp, 3 ) ) )
267
            break;
268
    CYG_TEST_CHECK( E_RLWAI == ercd, "get_blf bad ercd !E_RLWAI" );
269
 
270
    for ( i = 0; i < 10; i++ )
271
        if ( E_OK != (ercd = tget_blf( &vp, 3, 10 ) ) )
272
            break;
273
    CYG_TEST_CHECK( E_RLWAI == ercd, "tget_blf bad ercd !E_RLWAI" );
274
 
275
    for ( i = 0; i < 10; i++ )
276
        if ( E_OK != (ercd = get_blk( &vp, 1, 1000 ) ) )
277
            break;
278
    CYG_TEST_CHECK( E_RLWAI == ercd, "get_blk bad ercd !E_RLWAI" );
279
 
280
    for ( i = 0; i < 10; i++ )
281
        if ( E_OK != (ercd = tget_blk( &vp, 1, 1000, 10 ) ) )
282
            break;
283
    CYG_TEST_CHECK( E_RLWAI == ercd, "tget_blk bad ercd !E_RLWAI" );
284
 
285
    ercd = dly_tsk( 10 );
286
    CYG_TEST_CHECK( E_RLWAI == ercd, "dly_tsk bad ercd !E_RLWAI" );
287
 
288
    ercd = tslp_tsk( 10 );
289
    CYG_TEST_CHECK( E_RLWAI == ercd, "tslp_tsk bad ercd !E_RLWAI" );
290
 
291
    ercd = slp_tsk();
292
    CYG_TEST_CHECK( E_RLWAI == ercd, "slp_tsk bad ercd !E_RLWAI" );
293
 
294
    ercd = ter_tsk( 2 );
295
    CYG_TEST_CHECK( E_OK == ercd, "ter_tsk bad ercd" );
296
    ercd = dly_tsk( 10 );
297
    CYG_TEST_CHECK( E_OK == ercd, "dly_tsk bad ercd" );
298
 
299
    CYG_TEST_PASS("release wait: various waiting calls");
300
 
301
    // all done
302
    CYG_TEST_EXIT( "All done" );
303
    ext_tsk();
304
}
305
 
306
 
307
 
308
void task2( unsigned int arg )
309
{
310
    ER ercd;
311
    int i;
312
    CYG_TEST_INFO( "Task 2 running" );
313
    ercd = get_tid( &i );
314
    CYG_TEST_CHECK( E_OK == ercd, "get_tid bad ercd" );
315
    CYG_TEST_CHECK( 2 == i, "tid not 2" );
316
    if ( 22222 != arg )
317
        CYG_TEST_FAIL( "Task 2 arg not 22222" );
318
 
319
    for ( i = 0 ; i < 100; i++ ) {
320
        ercd = rel_wai( 1 );
321
        CYG_TEST_CHECK( E_OK == ercd, "rel_wai bad ercd" );
322
    }
323
    // we expect task2 to be killed here
324
    CYG_TEST_FAIL( "Task 2 ran to completion!" );
325
}
326
 
327
void task3( unsigned int arg )
328
{
329
}
330
 
331
void task4( unsigned int arg )
332
{
333
}
334
 
335
#else // not enough (or too many) uITRON objects configured in
336
#define N_A_MSG "not enough uITRON objects to run test"
337
#endif // not enough (or too many) uITRON objects configured in
338
#else  // not C++ and some C++ specific options enabled
339
#define N_A_MSG "C++ specific options selected but this is C"
340
#endif  // not C++ and some C++ specific options enabled
341
#else // ! CYGVAR_KERNEL_COUNTERS_CLOCK   - can't test without it
342
#define N_A_MSG "no CYGVAR_KERNEL_COUNTERS_CLOCK"
343
#endif // ! CYGVAR_KERNEL_COUNTERS_CLOCK  - can't test without it
344
#else  // ! CYGFUN_KERNEL_THREADS_TIMER   - can't test without it
345
#define N_A_MSG "no CYGFUN_KERNEL_THREADS_TIMER"
346
#endif // ! CYGFUN_KERNEL_THREADS_TIMER   - can't test without it
347
#else  // ! CYGIMP_THREAD_PRIORITY        - can't test without it
348
#define N_A_MSG "no CYGSEM_KERNEL_SCHED_MLQUEUE"
349
#endif // ! CYGSEM_KERNEL_SCHED_MLQUEUE   - can't test without it
350
#else  // ! CYGPKG_UITRON
351
#define N_A_MSG "uITRON Compatibility layer disabled"
352
#endif // CYGPKG_UITRON
353
 
354
#ifdef N_A_MSG
355
externC void
356
cyg_start( void )
357
{
358
    CYG_TEST_INIT();
359
    CYG_TEST_NA( N_A_MSG );
360
}
361
#endif // N_A_MSG defined ie. we are N/A.
362
 
363
// EOF testcx5.cxx

powered by: WebSVN 2.1.0

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