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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [packages/] [compat/] [uitron/] [current/] [tests/] [testcx4.cxx] - Blame information for rev 810

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

Line No. Rev Author Line
1 786 skrzyp
//===========================================================================
2
//
3
//      testcx4.cxx
4
//
5
//      uITRON "C++" test program four
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 cyclic handlers */            \
79
    defined( CYGPKG_UITRON_CYCLICS )                            && \
80
    (CYGNUM_UITRON_CYCLICS >= 3)                                && \
81
    (CYGNUM_UITRON_CYCLICS < 90)                                && \
82
                                                                   \
83
    /* test configuration for enough alarm handlers */             \
84
    defined( CYGPKG_UITRON_ALARMS )                             && \
85
    (CYGNUM_UITRON_ALARMS >= 3)                                 && \
86
    (CYGNUM_UITRON_ALARMS < 90)                                 && \
87
                                                                   \
88
    /* the end of the large #if statement */                       \
89
    1
90
 
91
// ============================ END ============================
92
 
93
 
94
 
95
#include <cyg/compat/uitron/uit_func.h> // uITRON
96
 
97
externC void
98
cyg_package_start( void )
99
{
100
    CYG_TEST_INIT();
101
    CYG_TEST_INFO( "Calling cyg_uitron_start()" );
102
    cyg_uitron_start();
103
}
104
 
105
volatile int intercount = 0;
106
INT scratch;
107
 
108
void hand1(void)
109
{
110
    CYG_TEST_INFO("Handler 1 called");
111
    intercount++;
112
}
113
 
114
void hand2(void)
115
{
116
    CYG_TEST_CHECK( 2 == intercount, "handler out of sync" );
117
    CYG_TEST_INFO("Handler 2 called");
118
    intercount++;
119
}
120
 
121
extern "C" {
122
    void task1( unsigned int arg );
123
    void task2( unsigned int arg );
124
    void task3( unsigned int arg );
125
    void task4( unsigned int arg );
126
}
127
 
128
void task1( unsigned int arg )
129
{
130
    ER ercd;
131
 
132
    T_DCYC dcyc;
133
    T_DALM dalm;
134
    T_RCYC rcyc;
135
    T_RALM ralm;
136
 
137
    unsigned int tm;
138
 
139
    static char foo[] = "Test message";
140
    VP info = (VP)foo;
141
 
142
    // Increase times when running on HW since overhead of GDB packet
143
    // acknowledgements may cause tests of timing to fail.
144
    if (cyg_test_is_simulator)
145
        tm = 1;
146
    else
147
        tm = 4;
148
 
149
    CYG_TEST_INFO( "Task 1 running" );
150
    ercd = get_tid( &scratch );
151
    CYG_TEST_CHECK( E_OK == ercd, "get_tid bad ercd" );
152
    CYG_TEST_CHECK( 1 == scratch, "tid not 1" );
153
 
154
    dcyc.exinf  = (VP)info;
155
    dcyc.cycatr = TA_HLNG;
156
    dcyc.cychdr = (FP)&hand1;
157
    dcyc.cycact = TCY_INI;              // bad
158
    dcyc.cyctim = 2;
159
 
160
#ifdef CYGSEM_UITRON_BAD_PARAMS_RETURN_ERRORS
161
    ercd = def_cyc(3, &dcyc);
162
    CYG_TEST_CHECK( E_PAR == ercd, "def_cyc bad ercd !E_PAR" );
163
#endif // we can test bad param error returns
164
 
165
    dcyc.cycact = TCY_OFF;              // make good
166
    dcyc.cyctim = 0;                    // bad
167
 
168
#ifdef CYGSEM_UITRON_BAD_PARAMS_RETURN_ERRORS
169
    ercd = def_cyc(3, &dcyc);
170
    CYG_TEST_CHECK( E_PAR == ercd, "def_cyc bad ercd !E_PAR" );
171
#endif // we can test bad param error returns
172
 
173
    dcyc.cyctim = 1;                    // make good
174
 
175
    ercd = def_cyc(3, &dcyc);
176
    CYG_TEST_CHECK( E_OK == ercd, "def_cyc bad ercd" );
177
 
178
#ifdef CYGSEM_UITRON_BAD_PARAMS_RETURN_ERRORS
179
    ercd = def_cyc(-6, &dcyc);
180
    CYG_TEST_CHECK( E_PAR == ercd, "def_cyc bad ercd !E_PAR" );
181
    ercd = def_cyc(99, &dcyc);
182
    CYG_TEST_CHECK( E_PAR == ercd, "def_cyc bad ercd !E_PAR" );
183
 
184
    ercd = act_cyc(-6, TCY_OFF);
185
    CYG_TEST_CHECK( E_PAR == ercd, "act_cyc bad ercd !E_PAR" );
186
    ercd = act_cyc(99, TCY_OFF);
187
    CYG_TEST_CHECK( E_PAR == ercd, "act_cyc bad ercd !E_PAR" );
188
    ercd = act_cyc( 3, ~0);
189
    CYG_TEST_CHECK( E_PAR == ercd, "act_cyc bad ercd !E_PAR" );
190
 
191
    ercd = ref_cyc(&rcyc, -6);
192
    CYG_TEST_CHECK( E_PAR == ercd, "ref_cyc bad ercd !E_PAR" );
193
    ercd = ref_cyc(&rcyc, 99);
194
    CYG_TEST_CHECK( E_PAR == ercd, "ref_cyc bad ercd !E_PAR" );
195
#ifndef CYGSEM_UITRON_PARAMS_NULL_IS_GOOD_PTR
196
    ercd = ref_cyc(NULL,  3);
197
    CYG_TEST_CHECK( E_PAR == ercd, "ref_cyc bad ercd !E_PAR" );
198
#endif
199
#endif // we can test bad param error returns
200
 
201
    ercd = def_cyc(3, (T_DCYC *)NADR);
202
    CYG_TEST_CHECK( E_OK == ercd, "def_cyc bad ercd" );
203
#ifdef CYGSEM_UITRON_BAD_PARAMS_RETURN_ERRORS
204
    ercd = ref_cyc(&rcyc,  3);
205
    CYG_TEST_CHECK( E_NOEXS == ercd, "ref_cyc bad ercd !E_NOEXS" );
206
#endif // we can test bad param error returns
207
 
208
    CYG_TEST_PASS( "bad calls: def_cyc, act_cyc, ref_cyc" );
209
 
210
    dalm.exinf  = (VP)info;
211
    dalm.almatr = TA_HLNG;
212
    dalm.almhdr = (FP)&hand2;
213
    dalm.tmmode = ~0;                   // bad
214
    dalm.almtim = 20;
215
 
216
#ifdef CYGSEM_UITRON_BAD_PARAMS_RETURN_ERRORS
217
    ercd = def_alm(3, &dalm);
218
    CYG_TEST_CHECK( E_PAR == ercd, "def_alm bad ercd !E_PAR" );
219
#endif // we can test bad param error returns
220
 
221
    dalm.tmmode = TTM_REL;              // make good
222
    dalm.almtim = 0;                    // bad
223
 
224
#ifdef CYGSEM_UITRON_BAD_PARAMS_RETURN_ERRORS
225
    ercd = def_alm(3, &dalm);
226
    CYG_TEST_CHECK( E_PAR == ercd, "def_alm bad ercd !E_PAR" );
227
#endif // we can test bad param error returns
228
 
229
    dalm.almtim = 1000;                 // make good
230
 
231
    ercd = def_alm(3, &dalm);
232
    CYG_TEST_CHECK( E_OK == ercd, "def_alm bad ercd" );
233
 
234
#ifdef CYGSEM_UITRON_BAD_PARAMS_RETURN_ERRORS
235
    ercd = ref_alm(&ralm, -6);
236
    CYG_TEST_CHECK( E_PAR == ercd, "ref_alm bad ercd !E_PAR" );
237
    ercd = ref_alm(&ralm, 99);
238
    CYG_TEST_CHECK( E_PAR == ercd, "ref_alm bad ercd !E_PAR" );
239
#ifndef CYGSEM_UITRON_PARAMS_NULL_IS_GOOD_PTR
240
    ercd = ref_alm(NULL,  3);
241
    CYG_TEST_CHECK( E_PAR == ercd, "ref_alm bad ercd !E_PAR" );
242
#endif
243
 
244
#endif // we can test bad param error returns
245
    ercd = def_alm(3, (T_DALM *)NADR);
246
    CYG_TEST_CHECK( E_OK == ercd, "def_cyc bad ercd" );
247
#ifdef CYGSEM_UITRON_BAD_PARAMS_RETURN_ERRORS
248
    ercd = ref_alm(&ralm,  3);
249
    CYG_TEST_CHECK( E_NOEXS == ercd, "ref_cyc bad ercd !E_NOEXS" );
250
#endif // we can test bad param error returns
251
 
252
    CYG_TEST_PASS( "bad calls: def_alm, act_alm, ref_alm" );
253
 
254
    dcyc.exinf  = (VP)info;
255
    dcyc.cycatr = TA_HLNG;
256
    dcyc.cychdr = (FP)&hand1;
257
    dcyc.cycact = TCY_ON;
258
    dcyc.cyctim = 50*tm;
259
 
260
    ercd = def_cyc(3, &dcyc);
261
    CYG_TEST_CHECK( E_OK == ercd, "ref_cyc bad ercd" );
262
    ercd = ref_cyc(&rcyc, 3);
263
    CYG_TEST_CHECK( E_OK == ercd, "ref_cyc bad ercd" );
264
    CYG_TEST_CHECK( info == rcyc.exinf, "rcyc.exinf should be info" );
265
    CYG_TEST_CHECK( 45*tm < rcyc.lfttim, "rcyc.lfttim too small" );
266
    CYG_TEST_CHECK( rcyc.lfttim <= 50*tm, "rcyc.lfttim too big" );
267
    CYG_TEST_CHECK( TCY_ON == rcyc.cycact, "rcyc.cycact should be TCY_ON" );
268
    ercd = act_cyc(3, TCY_OFF);
269
    CYG_TEST_CHECK( E_OK == ercd, "act_cyc bad ercd" );
270
    ercd = ref_cyc(&rcyc, 3);
271
    CYG_TEST_CHECK( E_OK == ercd, "ref_cyc bad ercd" );
272
    CYG_TEST_CHECK( info == rcyc.exinf, "rcyc.exinf should be info" );
273
    CYG_TEST_CHECK( 45*tm < rcyc.lfttim, "rcyc.lfttim too small" );
274
    CYG_TEST_CHECK( rcyc.lfttim <= 50*tm, "rcyc.lfttim too big" );
275
    CYG_TEST_CHECK( TCY_OFF == rcyc.cycact, "rcyc.cycact should be TCY_OFF" );
276
    ercd = act_cyc(3, TCY_ON);
277
    CYG_TEST_CHECK( E_OK == ercd, "act_cyc bad ercd" );
278
 
279
    CYG_TEST_PASS("good calls: def_cyc, act_cyc, ref_cyc");
280
 
281
    dalm.exinf  = (VP)info;
282
    dalm.almatr = TA_HLNG;
283
    dalm.almhdr = (FP)&hand2;
284
    dalm.tmmode = TTM_REL;
285
    dalm.almtim = 120*tm;
286
 
287
    ercd = def_alm(3, &dalm);
288
    CYG_TEST_CHECK( E_OK == ercd, "def_alm bad ercd" );
289
    ercd = ref_alm(&ralm, 3);
290
    CYG_TEST_CHECK( E_OK == ercd, "ref_alm bad ercd" );
291
    CYG_TEST_CHECK( info == ralm.exinf, "ralm.exinf should be info" );
292
    CYG_TEST_CHECK( 115*tm < ralm.lfttim, "ralm.lfttim too small" );
293
    CYG_TEST_CHECK( ralm.lfttim <= 120*tm, "ralm.lfttim too big" );
294
 
295
    // Expect handlers to be called at approximate times
296
    // time           intercount
297
    // tm*50  hand1   0
298
    // tm*100 hand1   1
299
    // tm*120 hand2   2
300
    // tm*150 hand1   3
301
 
302
    ercd = dly_tsk(160*tm);
303
    CYG_TEST_CHECK( E_OK == ercd, "dly_tsk bad ercd" );
304
    CYG_TEST_CHECK( 4 == intercount, "handlers not both called" );
305
 
306
    ercd = act_cyc(3, TCY_OFF);
307
    CYG_TEST_CHECK( E_OK == ercd, "act_cyc(off) bad ercd" );
308
 
309
    ercd = dly_tsk(60*tm);              // enough for at least one tick
310
    CYG_TEST_CHECK( E_OK == ercd, "dly_tsk bad ercd" );
311
    CYG_TEST_CHECK( 4 == intercount, "cyclic not disabled" );
312
 
313
    // approx time now 220, so we expect a cycle in about 30 ticks
314
    ercd = act_cyc(3, TCY_ON);
315
    CYG_TEST_CHECK( E_OK == ercd, "act_cyc(on) bad ercd" );
316
    ercd = ref_cyc(&rcyc, 3);
317
    CYG_TEST_CHECK( E_OK == ercd, "ref_cyc bad ercd" );
318
    CYG_TEST_CHECK( info == rcyc.exinf, "rcyc.exinf should be info" );
319
    CYG_TEST_CHECK( 25*tm < rcyc.lfttim, "rcyc.lfttim too small" );
320
    CYG_TEST_CHECK( rcyc.lfttim <= 35*tm, "rcyc.lfttim too big" );
321
    CYG_TEST_CHECK( TCY_ON == rcyc.cycact, "rcyc.cycact should be TCY_ON" );
322
 
323
    // now resynchronize with right now:
324
    ercd = act_cyc(3, TCY_ON|TCY_INI);
325
    CYG_TEST_CHECK( E_OK == ercd, "act_cyc(on) bad ercd" );
326
    ercd = ref_cyc(&rcyc, 3);
327
    CYG_TEST_CHECK( E_OK == ercd, "ref_cyc bad ercd" );
328
    CYG_TEST_CHECK( info == rcyc.exinf, "rcyc.exinf should be info" );
329
    CYG_TEST_CHECK( 45*tm < rcyc.lfttim, "rcyc.lfttim too small" );
330
    CYG_TEST_CHECK( rcyc.lfttim <= 50*tm, "rcyc.lfttim too big" );
331
    CYG_TEST_CHECK( TCY_ON == rcyc.cycact, "rcyc.cycact should be TCY_ON" );
332
 
333
    // wait a bit and check that time marches on, or even down
334
    ercd = dly_tsk(10*tm);
335
    CYG_TEST_CHECK( E_OK == ercd, "dly_tsk bad ercd" );
336
    ercd = ref_cyc(&rcyc, 3);
337
    CYG_TEST_CHECK( E_OK == ercd, "ref_cyc bad ercd" );
338
    CYG_TEST_CHECK( info == rcyc.exinf, "rcyc.exinf should be info" );
339
    CYG_TEST_CHECK( 35*tm < rcyc.lfttim, "rcyc.lfttim too small" );
340
    CYG_TEST_CHECK( rcyc.lfttim <= 45*tm, "rcyc.lfttim too big" );
341
    CYG_TEST_CHECK( TCY_ON == rcyc.cycact, "rcyc.cycact should be TCY_ON" );
342
 
343
    // now turn it off and re-synch with right now:
344
    ercd = act_cyc(3, TCY_OFF|TCY_INI);
345
    CYG_TEST_CHECK( E_OK == ercd, "act_cyc(on) bad ercd" );
346
    ercd = ref_cyc(&rcyc, 3);
347
    CYG_TEST_CHECK( E_OK == ercd, "ref_cyc bad ercd" );
348
    CYG_TEST_CHECK( info == rcyc.exinf, "rcyc.exinf should be info" );
349
    CYG_TEST_CHECK( 45*tm < rcyc.lfttim, "rcyc.lfttim too small" );
350
    CYG_TEST_CHECK( rcyc.lfttim <= 50*tm, "rcyc.lfttim too big" );
351
    CYG_TEST_CHECK( TCY_OFF == rcyc.cycact, "rcyc.cycact should be TCY_OFF" );
352
 
353
    ercd = act_cyc(3, TCY_OFF);
354
    CYG_TEST_CHECK( E_OK == ercd, "act_cyc(on) bad ercd" );
355
 
356
    CYG_TEST_PASS("good calls: def_cyc, act_cyc, ref_cyc, def_alm, ref_alm");
357
 
358
    // all done
359
    CYG_TEST_EXIT( "All done" );
360
    ext_tsk();
361
}
362
 
363
 
364
 
365
void task2( unsigned int arg )
366
{
367
}
368
 
369
void task3( unsigned int arg )
370
{
371
}
372
 
373
void task4( unsigned int arg )
374
{
375
}
376
 
377
#else // not enough (or too many) uITRON objects configured in
378
#define N_A_MSG "not enough uITRON objects to run test"
379
#endif // not enough (or too many) uITRON objects configured in
380
#else  // not C++ and some C++ specific options enabled
381
#define N_A_MSG "C++ specific options selected but this is C"
382
#endif  // not C++ and some C++ specific options enabled
383
#else // ! CYGVAR_KERNEL_COUNTERS_CLOCK   - can't test without it
384
#define N_A_MSG "no CYGVAR_KERNEL_COUNTERS_CLOCK"
385
#endif // ! CYGVAR_KERNEL_COUNTERS_CLOCK  - can't test without it
386
#else  // ! CYGFUN_KERNEL_THREADS_TIMER   - can't test without it
387
#define N_A_MSG "no CYGFUN_KERNEL_THREADS_TIMER"
388
#endif // ! CYGFUN_KERNEL_THREADS_TIMER   - can't test without it
389
#else  // ! CYGIMP_THREAD_PRIORITY        - can't test without it
390
#define N_A_MSG "no CYGSEM_KERNEL_SCHED_MLQUEUE"
391
#endif // ! CYGSEM_KERNEL_SCHED_MLQUEUE   - can't test without it
392
#else  // ! CYGPKG_UITRON
393
#define N_A_MSG "uITRON Compatibility layer disabled"
394
#endif // CYGPKG_UITRON
395
 
396
#ifdef N_A_MSG
397
externC void
398
cyg_start( void )
399
{
400
    CYG_TEST_INIT();
401
    CYG_TEST_NA( N_A_MSG );
402
}
403
#endif // N_A_MSG defined ie. we are N/A.
404
 
405
// EOF testcx4.cxx

powered by: WebSVN 2.1.0

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