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

Subversion Repositories openrisc

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

powered by: WebSVN 2.1.0

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