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

Subversion Repositories openrisc

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

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 786 skrzyp
//===========================================================================
2
//
3
//      test8.c
4
//
5
//      uITRON "C" test program eight
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):   hmt
43
// Contributors:        hmt
44
// Date:        1998-10-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
    /* the end of the large #if statement */                       \
86
    1
87
 
88
// ============================ END ============================
89
 
90
 
91
 
92
#include <cyg/compat/uitron/uit_func.h> // uITRON
93
 
94
externC void
95
cyg_package_start( void )
96
{
97
    CYG_TEST_INIT();
98
    CYG_TEST_INFO( "Calling cyg_uitron_start()" );
99
    cyg_uitron_start();
100
}
101
 
102
volatile int intercount = 0;
103
INT scratch;
104
 
105
void newtask( unsigned int arg );
106
void task2( unsigned int arg );
107
void task3( unsigned int arg );
108
void task4( unsigned int arg );
109
 
110
T_CTSK t_ctsk = { NULL, 0, (FP)&newtask, 1, CYGNUM_UITRON_STACK_SIZE };
111
T_RTSK t_rtsk;
112
 
113
void task1( unsigned int arg )
114
{
115
    ER ercd;
116
 
117
    CYG_TEST_INFO( "Task 1 running" );
118
 
119
    // change us to prio 3 for flexibility
120
    ercd = chg_pri( 0, 3 );
121
    CYG_TEST_CHECK( E_OK == ercd, "chg_pri bad ercd" );
122
 
123
#ifdef CYGPKG_UITRON_TASKS_CREATE_DELETE
124
    // first, check that we can delete a task:
125
#ifdef CYGSEM_UITRON_BAD_PARAMS_RETURN_ERRORS
126
    ercd = del_tsk( -6 );
127
    CYG_TEST_CHECK( E_ID == ercd, "del_tsk bad ercd !E_ID" );
128
    ercd = del_tsk( 99 );
129
    CYG_TEST_CHECK( E_ID == ercd, "del_tsk bad ercd !E_ID" );
130
    ercd = cre_tsk( -6, &t_ctsk );
131
    CYG_TEST_CHECK( E_ID == ercd, "cre_tsk bad ercd !E_ID" );
132
    ercd = cre_tsk( 99, &t_ctsk );
133
    CYG_TEST_CHECK( E_ID == ercd, "cre_tsk bad ercd !E_ID" );
134
#endif // we can test bad param error returns
135
    // try a pre-existing object
136
    ercd = cre_tsk( 2, &t_ctsk );
137
    CYG_TEST_CHECK( E_OBJ == ercd, "cre_tsk bad ercd !E_OBJ" );
138
    // try a pre-existing object - ourselves!
139
    ercd = cre_tsk( 1, &t_ctsk );
140
    CYG_TEST_CHECK( E_OBJ == ercd, "cre_tsk bad ercd !E_OBJ" );
141
    // try deleting an active task
142
    ercd = dis_dsp();
143
    CYG_TEST_CHECK( E_OK == ercd, "dis_dsp bad ercd" );
144
    ercd = sta_tsk( 2, 22222 );
145
    CYG_TEST_CHECK( E_OK == ercd, "sta_tsk bad ercd" );
146
    ercd = chg_pri( 2, 5 );
147
    CYG_TEST_CHECK( E_OK == ercd, "chg_pri bad ercd" );
148
    ercd = ena_dsp();
149
    CYG_TEST_CHECK( E_OK == ercd, "ena_dsp bad ercd" );
150
    // Task 2 is now ready-to-run, lower prio than us
151
    ercd = del_tsk( 2 );
152
    CYG_TEST_CHECK( E_OBJ == ercd, "del_tsk bad ercd !E_OBJ" );
153
    ercd = dly_tsk( 10 );
154
    CYG_TEST_CHECK( E_OK == ercd, "dly_tsk bad ercd" );
155
    // Task 2 is now sleeping
156
    CYG_TEST_CHECK( 1 == intercount, "bad intercount !1" );
157
    ercd = del_tsk( 2 );
158
    CYG_TEST_CHECK( E_OBJ == ercd, "del_tsk bad ercd !E_OBJ" );
159
    // try deleting a running task - ourselves!
160
    ercd = del_tsk( 1 );
161
    CYG_TEST_CHECK( E_OBJ == ercd, "del_tsk bad ercd !E_OBJ" );
162
    // terminate task 2; should then be OK to delete it
163
    ercd = ter_tsk( 2 );
164
    CYG_TEST_CHECK( E_OK == ercd, "ter_tsk bad ercd" );
165
    CYG_TEST_CHECK( 1 == intercount, "bad intercount !1" );
166
    ercd = del_tsk( 2 );
167
    CYG_TEST_CHECK( E_OK == ercd, "del_tsk bad ercd" );
168
    CYG_TEST_CHECK( 1 == intercount, "bad intercount !1" );
169
    // and check it is deleted
170
    ercd = sta_tsk( 2, 99 );
171
    CYG_TEST_CHECK( E_NOEXS == ercd, "sta_tsk bad ercd !E_NOEXS" );
172
    ercd = ter_tsk( 2 );
173
    CYG_TEST_CHECK( E_NOEXS == ercd, "ter_tsk bad ercd !E_NOEXS" );
174
    ercd = chg_pri( 2, 6 );
175
    CYG_TEST_CHECK( E_NOEXS == ercd, "chg_pri bad ercd !E_NOEXS" );
176
    ercd = rel_wai( 2 );
177
    CYG_TEST_CHECK( E_NOEXS == ercd, "rel_wai bad ercd !E_NOEXS" );
178
    ercd = sus_tsk( 2 );
179
    CYG_TEST_CHECK( E_NOEXS == ercd, "sus_tsk bad ercd !E_NOEXS" );
180
    ercd = rsm_tsk( 2 );
181
    CYG_TEST_CHECK( E_NOEXS == ercd, "rsm_tsk bad ercd !E_NOEXS" );
182
    ercd = frsm_tsk( 2 );
183
    CYG_TEST_CHECK( E_NOEXS == ercd, "frsm_tsk bad ercd !E_NOEXS" );
184
    ercd = wup_tsk( 2 );
185
    CYG_TEST_CHECK( E_NOEXS == ercd, "wup_tsk bad ercd !E_NOEXS" );
186
    ercd = can_wup( &scratch, 2 );
187
    CYG_TEST_CHECK( E_NOEXS == ercd, "can_wup bad ercd !E_NOEXS" );
188
    ercd = ref_tsk( &t_rtsk, 2 );
189
    CYG_TEST_CHECK( E_NOEXS == ercd, "ref_tsk bad ercd !E_NOEXS" );
190
    ercd = del_tsk( 2 );
191
    CYG_TEST_CHECK( E_NOEXS == ercd, "del_tsk bad ercd !E_NOEXS" );
192
    // recreate task2, with the same function
193
    t_ctsk.task = (FP)&task2;
194
    t_ctsk.itskpri = 7;
195
    ercd = cre_tsk( 2, &t_ctsk );
196
    CYG_TEST_CHECK( E_OK == ercd, "cre_tsk bad ercd" );
197
    ercd = ref_tsk( &t_rtsk, 2 );
198
    CYG_TEST_CHECK( E_OK == ercd, "ref_tsk bad ercd" );
199
    CYG_TEST_CHECK( 7 == t_rtsk.tskpri, "Bad tskpri in new task2 !7" );
200
    CYG_TEST_CHECK( TTS_DMT == t_rtsk.tskstat,
201
                    "Bad tskstat in new task2 !TTS_DMT" );
202
    CYG_TEST_CHECK( 1 == intercount, "bad intercount !1" );
203
    // now start the task and do the same lot again...
204
    ercd = cre_tsk( 2, &t_ctsk );
205
    CYG_TEST_CHECK( E_OBJ == ercd, "cre_tsk bad ercd !E_OBJ" );
206
    // try deleting an active task
207
    ercd = sta_tsk( 2, 22222 );
208
    CYG_TEST_CHECK( E_OK == ercd, "sta_tsk bad ercd" );
209
    // Task 2 is now ready-to-run, lower prio than us
210
    ercd = del_tsk( 2 );
211
    CYG_TEST_CHECK( E_OBJ == ercd, "del_tsk bad ercd !E_OBJ" );
212
    CYG_TEST_CHECK( 1 == intercount, "bad intercount !1" );
213
    ercd = dly_tsk( 10 );
214
    CYG_TEST_CHECK( E_OK == ercd, "dly_tsk bad ercd" );
215
    CYG_TEST_CHECK( 2 == intercount, "bad intercount !2" );
216
    // Task 2 is now sleeping
217
    ercd = ref_tsk( &t_rtsk, 2 );
218
    CYG_TEST_CHECK( E_OK == ercd, "ref_tsk bad ercd" );
219
    CYG_TEST_CHECK( 7 == t_rtsk.tskpri, "Bad tskpri in new task2 !7" );
220
    CYG_TEST_CHECK( TTS_WAI == t_rtsk.tskstat,
221
                    "Bad tskstat in new task2 !TTS_WAI" );
222
    ercd = del_tsk( 2 );
223
    CYG_TEST_CHECK( E_OBJ == ercd, "del_tsk bad ercd !E_OBJ" );
224
    // up its priority
225
    ercd = chg_pri( 2, 1 );
226
    CYG_TEST_CHECK( E_OK == ercd, "chg_pri bad ercd" );
227
    // awaken task 2; it will then exit-and-delete itself:
228
    CYG_TEST_CHECK( 2 == intercount, "bad intercount !2" );
229
    ercd = wup_tsk( 2 );
230
    CYG_TEST_CHECK( E_OK == ercd, "wup_tsk bad ercd" );
231
    CYG_TEST_CHECK( 3 == intercount, "bad intercount !3" );
232
    // and check it is deleted
233
    ercd = sta_tsk( 2, 99 );
234
    CYG_TEST_CHECK( E_NOEXS == ercd, "sta_tsk bad ercd !E_NOEXS" );
235
    CYG_TEST_CHECK( 3 == intercount, "bad intercount !3" );
236
    ercd = ter_tsk( 2 );
237
    CYG_TEST_CHECK( E_NOEXS == ercd, "ter_tsk bad ercd !E_NOEXS" );
238
    ercd = chg_pri( 2, 1 );
239
    CYG_TEST_CHECK( E_NOEXS == ercd, "chg_pri bad ercd !E_NOEXS" );
240
    ercd = rel_wai( 2 );
241
    CYG_TEST_CHECK( E_NOEXS == ercd, "rel_wai bad ercd !E_NOEXS" );
242
    ercd = sus_tsk( 2 );
243
    CYG_TEST_CHECK( E_NOEXS == ercd, "sus_tsk bad ercd !E_NOEXS" );
244
    ercd = rsm_tsk( 2 );
245
    CYG_TEST_CHECK( E_NOEXS == ercd, "rsm_tsk bad ercd !E_NOEXS" );
246
    ercd = frsm_tsk( 2 );
247
    CYG_TEST_CHECK( E_NOEXS == ercd, "frsm_tsk bad ercd !E_NOEXS" );
248
    ercd = wup_tsk( 2 );
249
    CYG_TEST_CHECK( E_NOEXS == ercd, "wup_tsk bad ercd !E_NOEXS" );
250
    ercd = can_wup( &scratch, 2 );
251
    CYG_TEST_CHECK( E_NOEXS == ercd, "can_wup bad ercd !E_NOEXS" );
252
    ercd = ref_tsk( &t_rtsk, 2 );
253
    CYG_TEST_CHECK( E_NOEXS == ercd, "ref_tsk bad ercd !E_NOEXS" );
254
    CYG_TEST_CHECK( 3 == intercount, "bad intercount !3" );
255
    ercd = del_tsk( 2 );
256
    CYG_TEST_CHECK( E_NOEXS == ercd, "del_tsk bad ercd !E_NOEXS" );
257
#ifdef CYGSEM_UITRON_BAD_PARAMS_RETURN_ERRORS
258
    // now try creating it (badly)
259
#ifndef CYGSEM_UITRON_PARAMS_NULL_IS_GOOD_PTR
260
    ercd = cre_tsk( 2, NULL );
261
    CYG_TEST_CHECK( E_PAR == ercd, "cre_tsk bad ercd !E_PAR" );
262
#endif
263
    ercd = cre_tsk( 2, NADR );
264
    CYG_TEST_CHECK( E_PAR == ercd, "cre_tsk bad ercd !E_PAR" );
265
    t_ctsk.stksz = 0x40000000;
266
    ercd = cre_tsk( 2, &t_ctsk );
267
    CYG_TEST_CHECK( E_NOMEM == ercd, "cre_tsk bad ercd !E_NOMEM" );
268
    t_ctsk.stksz = CYGNUM_UITRON_STACK_SIZE;
269
    CYG_TEST_CHECK( 3 == intercount, "bad intercount !3" );
270
#endif // we can test bad param error returns
271
 
272
    ercd = del_tsk( 3 );
273
    CYG_TEST_CHECK( E_OK == ercd, "del_tsk bad ercd" );
274
    t_ctsk.task = (FP)&task4;
275
    t_ctsk.itskpri = 9;
276
    ercd = cre_tsk( 3, &t_ctsk );
277
    CYG_TEST_CHECK( E_OK == ercd, "cre_tsk bad ercd" );
278
    // check we can delete it again immediately
279
    ercd = del_tsk( 3 );
280
    CYG_TEST_CHECK( E_OK == ercd, "del_tsk bad ercd" );
281
    ercd = ref_tsk( &t_rtsk, 3 );
282
    CYG_TEST_CHECK( E_NOEXS == ercd, "ref_tsk bad ercd !E_NOEXS" );
283
    t_ctsk.task = (FP)&newtask;
284
    t_ctsk.itskpri = 1;
285
    ercd = cre_tsk( 3, &t_ctsk );
286
    CYG_TEST_CHECK( E_OK == ercd, "cre_tsk bad ercd" );
287
    CYG_TEST_CHECK( 3 == intercount, "bad intercount !3" );
288
    ercd = sta_tsk( 3, 999 );
289
    CYG_TEST_CHECK( E_OK == ercd, "cre_tsk bad ercd" );
290
    // it should have run now, and exited
291
    CYG_TEST_CHECK( 5 == intercount, "bad intercount !5" );
292
    ercd = wai_sem( 1 );
293
    CYG_TEST_CHECK( E_OK == ercd, "wai_sem bad ercd" );
294
    // and check that it will just run again...
295
    ercd = sta_tsk( 3, 999 );
296
    CYG_TEST_CHECK( E_OK == ercd, "cre_tsk bad ercd" );
297
    // it should have run now, and exited
298
    CYG_TEST_CHECK( 7 == intercount, "bad intercount !7" );
299
    ercd = wai_sem( 1 );
300
    CYG_TEST_CHECK( E_OK == ercd, "wai_sem bad ercd" );
301
    // all done.
302
 
303
    CYG_TEST_PASS("create/delete tasks");
304
 
305
    // all done
306
    CYG_TEST_EXIT( "All done" );
307
#else // ! CYGPKG_UITRON_TASKS_CREATE_DELETE
308
    CYG_TEST_NA( "Tasks do not have create/delete enabled" );
309
#endif // ! CYGPKG_UITRON_TASKS_CREATE_DELETE
310
    ext_tsk();
311
}
312
 
313
 
314
 
315
void newtask( unsigned int arg )
316
{
317
    ER ercd;
318
    int i;
319
    CYG_TEST_INFO( "Newtask running" );
320
    CYG_TEST_CHECK( 999 == arg, "Bad arg to newtask() !999" );
321
    ercd = get_tid( &i );
322
    CYG_TEST_CHECK( E_OK == ercd, "get_tid bad ercd" );
323
    CYG_TEST_CHECK( 3 == i, "tid not 3" );
324
    intercount++;
325
    ercd = sig_sem( 1 );
326
    CYG_TEST_CHECK( E_OK == ercd, "sig_sem bad ercd" );
327
    intercount++;
328
    // and just return
329
}
330
 
331
void task2( unsigned int arg )
332
{
333
    ER ercd;
334
    int i;
335
    CYG_TEST_INFO( "Task 2 running" );
336
    ercd = get_tid( &i );
337
    CYG_TEST_CHECK( E_OK == ercd, "get_tid bad ercd" );
338
    CYG_TEST_CHECK( 2 == i, "tid not 2" );
339
    if ( 22222 != arg )
340
        CYG_TEST_FAIL( "Task 2 arg not 22222" );
341
 
342
    intercount++;
343
 
344
    ercd = slp_tsk();
345
    CYG_TEST_CHECK( E_OK == ercd, "slp_tsk bad ercd" );
346
 
347
    intercount++;
348
 
349
    exd_tsk(); // if we are not killed first
350
 
351
    intercount++; // shouldn't happen
352
}
353
 
354
void task3( unsigned int arg )
355
{
356
    CYG_TEST_FAIL( "How come I'm being run?" );
357
}
358
 
359
void task4( unsigned int arg )
360
{
361
    CYG_TEST_FAIL( "How come I'm being run?" );
362
}
363
 
364
#else // not enough (or too many) uITRON objects configured in
365
#define N_A_MSG "not enough uITRON objects to run test"
366
#endif // not enough (or too many) uITRON objects configured in
367
#else  // not C++ and some C++ specific options enabled
368
#define N_A_MSG "C++ specific options selected but this is C"
369
#endif  // not C++ and some C++ specific options enabled
370
#else // ! CYGVAR_KERNEL_COUNTERS_CLOCK   - can't test without it
371
#define N_A_MSG "no CYGVAR_KERNEL_COUNTERS_CLOCK"
372
#endif // ! CYGVAR_KERNEL_COUNTERS_CLOCK  - can't test without it
373
#else  // ! CYGFUN_KERNEL_THREADS_TIMER   - can't test without it
374
#define N_A_MSG "no CYGFUN_KERNEL_THREADS_TIMER"
375
#endif // ! CYGFUN_KERNEL_THREADS_TIMER   - can't test without it
376
#else  // ! CYGIMP_THREAD_PRIORITY        - can't test without it
377
#define N_A_MSG "no CYGSEM_KERNEL_SCHED_MLQUEUE"
378
#endif // ! CYGSEM_KERNEL_SCHED_MLQUEUE   - can't test without it
379
#else  // ! CYGPKG_UITRON
380
#define N_A_MSG "uITRON Compatibility layer disabled"
381
#endif // CYGPKG_UITRON
382
 
383
#ifdef N_A_MSG
384
void
385
cyg_start( void )
386
{
387
    CYG_TEST_INIT();
388
    CYG_TEST_NA( N_A_MSG );
389
}
390
#endif // N_A_MSG defined ie. we are N/A.
391
 
392
// EOF test8.c

powered by: WebSVN 2.1.0

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