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

Subversion Repositories openrisc

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

powered by: WebSVN 2.1.0

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