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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [packages/] [compat/] [uitron/] [current/] [tests/] [test5.c] - Blame information for rev 817

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

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

powered by: WebSVN 2.1.0

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