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

Subversion Repositories openrisc

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

powered by: WebSVN 2.1.0

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