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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [packages/] [compat/] [uitron/] [current/] [tests/] [testcx7.cxx] - 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
//      testcx7.cxx
4
//      
5
//      uITRON "C++" test program seven
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, 2009 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-14
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 CYGIMP_UITRON_STRICT_CONFORMANCE // we DO want strict conformance
59
 
60
#ifdef CYGSEM_KERNEL_SCHED_MLQUEUE      // we DO want prioritized threads
61
 
62
#ifdef CYGFUN_KERNEL_THREADS_TIMER      // we DO want timout-able calls
63
 
64
#ifdef CYGVAR_KERNEL_COUNTERS_CLOCK     // we DO want the realtime clock
65
 
66
// we're OK if it's C++ or neither of those two is defined:
67
#if defined( __cplusplus ) || \
68
    (!defined( CYGIMP_UITRON_INLINE_FUNCS ) && \
69
     !defined( CYGIMP_UITRON_CPP_OUTLINE_FUNCS) )
70
 
71
// =================== TEST CONFIGURATION ===================
72
#if \
73
    /* test configuration for enough tasks */                      \
74
    (CYGNUM_UITRON_TASKS >= 4)                                  && \
75
    (CYGNUM_UITRON_TASKS < 90)                                  && \
76
    (CYGNUM_UITRON_START_TASKS == 1)                            && \
77
    ( !defined(CYGPKG_UITRON_TASKS_CREATE_DELETE) ||               \
78
      CYGNUM_UITRON_TASKS_INITIALLY >= 4             )          && \
79
                                                                   \
80
    /* test configuration for enough semaphores */                 \
81
    defined( CYGPKG_UITRON_SEMAS )                              && \
82
    (CYGNUM_UITRON_SEMAS >= 3)                                  && \
83
    (CYGNUM_UITRON_SEMAS < 90)                                  && \
84
    ( !defined(CYGPKG_UITRON_SEMAS_CREATE_DELETE) ||               \
85
      CYGNUM_UITRON_SEMAS_INITIALLY >= 3             )          && \
86
                                                                   \
87
    /* test configuration for enough flag objects */               \
88
    defined( CYGPKG_UITRON_FLAGS )                              && \
89
    (CYGNUM_UITRON_FLAGS >= 3)                                  && \
90
    (CYGNUM_UITRON_FLAGS < 90)                                  && \
91
    ( !defined(CYGPKG_UITRON_FLAGS_CREATE_DELETE) ||               \
92
      CYGNUM_UITRON_FLAGS_INITIALLY >= 3             )          && \
93
                                                                   \
94
    /* test configuration for enough message boxes */              \
95
    defined( CYGPKG_UITRON_MBOXES )                             && \
96
    (CYGNUM_UITRON_MBOXES >= 3)                                 && \
97
    (CYGNUM_UITRON_MBOXES < 90)                                 && \
98
    ( !defined(CYGPKG_UITRON_MBOXES_CREATE_DELETE) ||              \
99
      CYGNUM_UITRON_MBOXES_INITIALLY >= 3            )          && \
100
                                                                   \
101
    /* test configuration for enough fixed memory pools */         \
102
    defined( CYGPKG_UITRON_MEMPOOLFIXED )                       && \
103
    (CYGNUM_UITRON_MEMPOOLFIXED >= 3)                           && \
104
    (CYGNUM_UITRON_MEMPOOLFIXED < 90)                           && \
105
    ( !defined(CYGPKG_UITRON_MEMPOOLFIXED_CREATE_DELETE) ||        \
106
      CYGNUM_UITRON_MEMPOOLFIXED_INITIALLY >= 3       )         && \
107
                                                                   \
108
    /* test configuration for enough variable mempools */          \
109
    defined( CYGPKG_UITRON_MEMPOOLVAR )                         && \
110
    (CYGNUM_UITRON_MEMPOOLVAR >= 3)                             && \
111
    (CYGNUM_UITRON_MEMPOOLVAR < 90)                             && \
112
    ( !defined(CYGPKG_UITRON_MEMPOOLVAR_CREATE_DELETE) ||          \
113
      CYGNUM_UITRON_MEMPOOLVAR_INITIALLY >= 3       )           && \
114
                                                                   \
115
    /* the end of the large #if statement */                       \
116
    1
117
 
118
// ============================ END ============================
119
 
120
#include <cyg/kernel/test/stackmon.h>   // stack analysis tools
121
 
122
#include <cyg/compat/uitron/uit_func.h> // uITRON
123
 
124
externC void
125
cyg_package_start( void )
126
{
127
    CYG_TEST_INIT();
128
    CYG_TEST_INFO( "Calling cyg_uitron_start()" );
129
    cyg_uitron_start();
130
}
131
 
132
 
133
extern "C" {
134
    void task1( unsigned int arg );
135
    void task2( unsigned int arg );
136
    void task3( unsigned int arg );
137
    void task4( unsigned int arg );
138
}
139
 
140
// ========================================================================
141
 
142
enum {
143
    START_WAITOP = 0,
144
    SLEEP = 0,
145
    DELAY,
146
    SEMGET,
147
    FLAGWAIT,
148
    MSGGET,
149
    MEMFIXEDGET,
150
    MEMVARGET,
151
    DONE_WAITOP
152
};
153
typedef int WAITOP;
154
 
155
enum {
156
    START_TYPE = 0,
157
    PLAIN = 0,
158
    TIMED = 1,
159
    DONE_TYPE
160
};
161
typedef int WAITTYPE;
162
 
163
enum {
164
    START_KILLOP = 0,
165
 
166
    // These are the 5 ways out of a wait that we perm
167
    // with other circumstances:
168
    SIGNAL = 0,                         // do the appropriate producer op
169
    TIMEOUT,                            // wait for the timeout to fire
170
    RELEASE,                            // do a rel_wai()
171
    DELETE,                             // delete the object; del_xxx()
172
    KILL,                               // do a ter_tsk() on the waiter
173
 
174
    SUSPEND_SIGNAL_RESUME,
175
    SUSPEND_TIMEOUT_RESUME,
176
    SUSPEND_RELEASE_RESUME,
177
    SUSPEND_DELETE_RESUME,
178
    SUSPEND_KILL,                       // resume not applicable
179
 
180
    SUSPEND_SIGNAL_KILL,
181
    SUSPEND_TIMEOUT_KILL,
182
    SUSPEND_RELEASE_KILL,
183
    SUSPEND_DELETE_KILL,
184
    // SUSPEND_KILL_KILL not applicable
185
 
186
#if 0
187
    // support these later if _really_ keen.
188
    SUSPEND_SIGNAL_DELETE_RESUME,
189
    SUSPEND_TIMEOUT_DELETE_RESUME,
190
    SUSPEND_RELEASE_DELETE_RESUME,
191
    // SUSPEND_DELETE_DELETE_RESUME not applicable
192
    // SUSPEND_KILL_DELETE_RESUME not applicable
193
 
194
    SUSPEND_SIGNAL_DELETE_KILL,
195
    SUSPEND_TIMEOUT_DELETE_KILL,
196
    SUSPEND_RELEASE_DELETE_KILL,
197
    // SUSPEND_DELETE_DELETE_KILL,
198
    SUSPEND_KILL_DELETE                 // 2nd kill not applicable
199
#endif
200
 
201
    DONE_KILLOP
202
};
203
typedef int KILLOP;
204
 
205
// ========================================================================
206
 
207
char * waitstrings[] =
208
{ "Sleep ", "Delay ", "Sema  ", "Flag  ", "Mbox  ", "MemFix", "MemVar" };
209
 
210
char * typestrings[] =
211
{ " (Plain) : ", " (Timed) : " };
212
 
213
char * killstrings[] =
214
{ "Signal",
215
  "Wait-for-timeout",
216
  "Release-wait",
217
  "Delete-object",
218
  "Kill-task",
219
 
220
  "Suspend/Signal/Resume",
221
  "Suspend/Wait-for-timeout/Resume",
222
  "Suspend/Release-wait/Resume",
223
  "Suspend/Delete-object/Resume",
224
  "Suspend/Kill-task",
225
 
226
  "Suspend/Signal/Kill-task",
227
  "Suspend/Wait-for-timeout/Kill-task",
228
  "Suspend/Release-wait/Kill-task",
229
  "Suspend/Delete-object/Kill-task",
230
 
231
 
232
};
233
 
234
// ========================================================================
235
 
236
inline int task2arg( WAITOP wait, WAITTYPE waittype, KILLOP kill )
237
{
238
    return waittype + (wait << 1) + (kill << 8);
239
}
240
 
241
inline void decodearg( int arg, WAITOP *pwait, WAITTYPE *pwaittype, KILLOP *pkill )
242
{
243
    *pwaittype = (arg & 1) ? TIMED : PLAIN;
244
    *pwait  = (arg >> 1) & 0x7f;
245
    *pkill  = (arg >> 8);
246
}
247
 
248
static char *strdog( char *p, char *q )
249
{
250
    while ( 0 != (*p++ = *q++) );
251
    return p - 1;
252
}
253
 
254
static char *
255
makemsg( char *z, WAITOP wait, WAITTYPE waittype, KILLOP kill )
256
{
257
    static char buf[ 1000 ];
258
    char *p = buf;
259
    p = strdog( p, z );
260
    p = strdog( p, waitstrings[ wait ] );
261
    p = strdog( p, typestrings[ waittype ] );
262
    p = strdog( p, killstrings[ kill ] );
263
    *p = 0;
264
    return buf;
265
}
266
 
267
// ========================================================================
268
 
269
volatile int intercom = 0;
270
 
271
// ========================================================================
272
 
273
T_RTSK rtsk;
274
 
275
void
276
do_suspend( void )
277
{
278
    ER ercd;
279
    ercd = ref_tsk( &rtsk, 2 );
280
    CYG_TEST_CHECK( E_OK == ercd, "ref_tsk bad ercd" );
281
    CYG_TEST_CHECK( TTS_WAI == rtsk.tskstat, "bad tskstat !TTS_WAI" );
282
    ercd = sus_tsk( 2 );
283
    CYG_TEST_CHECK( E_OK == ercd, "sus_tsk bad ercd" );
284
    ercd = ref_tsk( &rtsk, 2 );
285
    CYG_TEST_CHECK( E_OK == ercd, "ref_tsk bad ercd" );
286
    CYG_TEST_CHECK( TTS_WAS == rtsk.tskstat, "bad tskstat !TTS_WAS" );
287
}
288
 
289
void
290
do_resume( void )
291
{
292
    ER ercd;
293
    ercd = ref_tsk( &rtsk, 2 );
294
    CYG_TEST_CHECK( E_OK == ercd, "ref_tsk bad ercd" );
295
    CYG_TEST_CHECK( TTS_SUS == rtsk.tskstat, "bad tskstat !TTS_SUS" );
296
    ercd = dis_dsp();
297
    CYG_TEST_CHECK( E_OK == ercd, "dis_dsp bad ercd" );
298
    ercd = rsm_tsk( 2 );
299
    CYG_TEST_CHECK( E_OK == ercd, "rsm_tsk bad ercd" );
300
    ercd = ref_tsk( &rtsk, 2 );
301
    CYG_TEST_CHECK( E_OK == ercd, "ref_tsk bad ercd" );
302
    CYG_TEST_CHECK( TTS_RDY == rtsk.tskstat, "bad tskstat !TTS_RDY" );
303
    ercd = ena_dsp();
304
    CYG_TEST_CHECK( E_OK == ercd, "ena_dsp bad ercd" );
305
}
306
 
307
// ========================================================================
308
 
309
#define T1_WAIT (7)
310
#define T2_WAIT (5)
311
 
312
#define T1_MALLOC (110)
313
#ifdef CYGSEM_KERNEL_MEMORY_COALESCE
314
#define T2_MALLOC (100)
315
#else
316
#define T2_MALLOC T1_MALLOC
317
#endif
318
 
319
VP vptmp;
320
VP vp = NULL;
321
VP vp1 = NULL;
322
VP t2vp = NULL;
323
VP t2vp_backup = NULL;
324
 
325
UINT scratch;
326
 
327
T_MSG *msg = (T_MSG *)&scratch;
328
T_MSG *msg1;
329
 
330
void
331
do_prep( WAITOP wait )
332
{
333
    ER ercd;
334
    switch ( wait ) {
335
    case SLEEP:
336
    case DELAY:
337
    case SEMGET:
338
    case FLAGWAIT:
339
    case MSGGET:
340
        // do nothing for all of those
341
        break;
342
    case MEMFIXEDGET:
343
        // allocate all the memory in the pool; remember a couple
344
        // for freeing as the signalling operation:
345
        t2vp = NULL;
346
        vp = vptmp = NULL;
347
        do {
348
            vp1 = vptmp;
349
            vptmp = vp;
350
            ercd = pget_blf( &vp, 1 );
351
        } while ( E_OK == ercd );
352
        CYG_TEST_CHECK( E_TMOUT == ercd, "get_blf bad ercd" );
353
        CYG_TEST_CHECK( NULL != vp,  "no allocated block to free" );
354
        CYG_TEST_CHECK( NULL != vp1, "no allocated block to free1" );
355
        break;
356
    case MEMVARGET:
357
        // allocate all the memory in the pool; remember a couple
358
        // for freeing as the signalling operation:
359
        t2vp = NULL;
360
        vp = vptmp = NULL;
361
        do {
362
            vp1 = vptmp;
363
            vptmp = vp;
364
            ercd = pget_blk( &vp, 1, T1_MALLOC );
365
        } while ( E_OK == ercd );
366
        CYG_TEST_CHECK( E_TMOUT == ercd, "get_blk bad ercd" );
367
        CYG_TEST_CHECK( NULL != vp,  "no allocated block to free" );
368
        CYG_TEST_CHECK( NULL != vp1, "no allocated block to free1" );
369
        break;
370
    default:
371
        CYG_TEST_FAIL( "bad switch" );
372
        break;
373
    }
374
}
375
 
376
void
377
do_tidyup( WAITOP wait )
378
{
379
    ER ercd;
380
    switch ( wait ) {
381
    case SLEEP:
382
    case DELAY:
383
    case SEMGET:
384
    case MSGGET:
385
        // do nothing for all of those
386
        break;
387
    case FLAGWAIT:
388
        // clear the flag variable
389
        ercd = clr_flg( 1, 0 );
390
        CYG_TEST_CHECK( E_OK == ercd, "clr_flg bad ercd, tidy vp" );
391
        break;
392
    case MEMFIXEDGET:
393
        if ( NULL != vp ) {
394
            ercd = rel_blf( 1, vp );
395
            CYG_TEST_CHECK( E_OK == ercd, "rel_blf bad ercd, tidy vp" );
396
        }
397
        if ( NULL != vp1 ) {
398
            ercd = rel_blf( 1, vp1 );
399
            CYG_TEST_CHECK( E_OK == ercd, "rel_blf bad ercd, tidy vp1" );
400
        }
401
        if ( NULL != t2vp ) {
402
            ercd = rel_blf( 1, t2vp );
403
            CYG_TEST_CHECK( E_OK == ercd, "rel_blf bad ercd, tidy t2vp" );
404
        }
405
        break;
406
    case MEMVARGET:
407
        if ( NULL != vp ) {
408
            ercd = rel_blk( 1, vp );
409
            CYG_TEST_CHECK( E_OK == ercd, "rel_blk bad ercd, tidy vp" );
410
        }
411
        if ( NULL != vp1 ) {
412
            ercd = rel_blk( 1, vp1 );
413
            CYG_TEST_CHECK( E_OK == ercd, "rel_blk bad ercd, tidy vp1" );
414
        }
415
        if ( NULL != t2vp ) {
416
            ercd = rel_blk( 1, t2vp );
417
            CYG_TEST_CHECK( E_OK == ercd, "rel_blk bad ercd, tidy t2vp" );
418
        }
419
        break;
420
    default:
421
        CYG_TEST_FAIL( "bad switch" );
422
        break;
423
    }
424
}
425
 
426
void
427
do_recreate( WAITOP wait )
428
{
429
#ifdef CYGPKG_UITRON_SEMAS_CREATE_DELETE
430
    static T_CSEM t_csem = { NULL, 0, 0 };
431
#endif
432
#ifdef CYGPKG_UITRON_MBOXES_CREATE_DELETE
433
    static T_CMBX t_cmbx = { NULL, 0 };
434
#endif
435
#ifdef CYGPKG_UITRON_FLAGS_CREATE_DELETE
436
    static T_CFLG t_cflg = { NULL, 0, 0 };
437
#endif
438
#ifdef CYGPKG_UITRON_MEMPOOLFIXED_CREATE_DELETE
439
    static T_CMPF t_cmpf = { NULL, 0, 20, 95 };
440
#endif
441
#ifdef CYGPKG_UITRON_MEMPOOLVAR_CREATE_DELETE
442
    static T_CMPL t_cmpl = { NULL, 0, 2000 };
443
#endif
444
    ER ercd = E_OK;
445
    switch ( wait ) {
446
    case SLEEP:
447
    case DELAY:
448
        // do nothing for all of those
449
        break;
450
    case SEMGET:
451
#ifdef CYGPKG_UITRON_SEMAS_CREATE_DELETE
452
        // create the semaphore
453
        ercd = cre_sem( 1, &t_csem );
454
        CYG_TEST_CHECK( E_OK == ercd, "cre_sem bad ercd" );
455
#else
456
        CYG_TEST_FAIL( "bad call to do_recreate SEMGET" );
457
#endif
458
        break;
459
    case FLAGWAIT:
460
#ifdef CYGPKG_UITRON_FLAGS_CREATE_DELETE
461
        // create the flag
462
        ercd = cre_flg( 1, &t_cflg );
463
        CYG_TEST_CHECK( E_OK == ercd, "cre_sem bad ercd" );
464
#else
465
        CYG_TEST_FAIL( "bad call to do_recreate FLAGWAIT" );
466
#endif
467
        break;
468
    case MSGGET:
469
#ifdef CYGPKG_UITRON_MBOXES_CREATE_DELETE
470
        // create the mbox
471
        ercd = cre_mbx( 1, &t_cmbx );
472
        CYG_TEST_CHECK( E_OK == ercd, "cre_sem bad ercd" );
473
#else
474
        CYG_TEST_FAIL( "bad call to do_recreate MSGGET" );
475
#endif
476
        break;
477
    case MEMFIXEDGET:
478
#ifdef CYGPKG_UITRON_MEMPOOLFIXED_CREATE_DELETE
479
        // create the mempool
480
        ercd = cre_mpf( 1, &t_cmpf );
481
        CYG_TEST_CHECK( E_OK == ercd, "cre_sem bad ercd" );
482
#else
483
        CYG_TEST_FAIL( "bad call to do_recreate MEMFIXEDGET" );
484
#endif
485
        break;
486
    case MEMVARGET:
487
#ifdef CYGPKG_UITRON_MEMPOOLVAR_CREATE_DELETE
488
        // create the mempool
489
        ercd = cre_mpl( 1, &t_cmpl );
490
        CYG_TEST_CHECK( E_OK == ercd, "cre_sem bad ercd" );
491
#else
492
        CYG_TEST_FAIL( "bad call to do_recreate MEMVARGET" );
493
#endif
494
        break;
495
    default:
496
        CYG_TEST_FAIL( "bad switch" );
497
        break;
498
    }
499
    // this is just to use ercd to prevent warnings
500
    CYG_TEST_CHECK( E_OK == ercd, "<blank> bad ercd" );
501
}
502
 
503
 
504
 
505
void
506
do_signal( WAITOP wait )
507
{
508
    ER ercd;
509
    switch ( wait ) {
510
    case SLEEP:
511
        // send a wakeup
512
        ercd = wup_tsk( 2 );
513
        CYG_TEST_CHECK( E_OK == ercd, "wup_tsk bad ercd" );
514
        break;
515
    case DELAY:
516
        // simply wait for task 2's delay to complete
517
        ercd = dly_tsk( T1_WAIT );
518
        CYG_TEST_CHECK( E_OK == ercd, "dly_tsk bad ercd" );
519
        break;
520
    case SEMGET:
521
        // signal the semaphore
522
        ercd = sig_sem( 1 );
523
        CYG_TEST_CHECK( E_OK == ercd, "sig_sem bad ercd" );
524
        break;
525
    case FLAGWAIT:
526
        // set the flag bits
527
        ercd = set_flg( 1, 0xff );
528
        CYG_TEST_CHECK( E_OK == ercd, "set_flg bad ercd" );
529
        break;
530
    case MSGGET:
531
        // send a message
532
        ercd = snd_msg( 1, msg );
533
        CYG_TEST_CHECK( E_OK == ercd, "snd_msg bad ercd" );
534
        break;
535
    case MEMFIXEDGET:
536
        // release a couple of blocks we allocated earlier.  I hope.
537
        CYG_TEST_CHECK( NULL != vp,  "no allocated block to free" );
538
        CYG_TEST_CHECK( NULL != vp1, "no allocated block to free1" );
539
        ercd = rel_blf( 1, vp );
540
        CYG_TEST_CHECK( E_OK == ercd, "rel_blf bad ercd" );
541
        vp = NULL;
542
        ercd = rel_blf( 1, vp1 );
543
        CYG_TEST_CHECK( E_OK == ercd, "rel_blf bad ercd1" );
544
        vp1 = NULL;
545
        break;
546
    case MEMVARGET:
547
        // release a couple of blocks we allocated earlier.  I hope.
548
        CYG_TEST_CHECK( NULL != vp,  "no allocated block to free" );
549
        CYG_TEST_CHECK( NULL != vp1, "no allocated block to free1" );
550
        ercd = rel_blk( 1, vp );
551
        CYG_TEST_CHECK( E_OK == ercd, "rel_blk bad ercd" );
552
        vp = NULL;
553
        ercd = rel_blk( 1, vp1 );
554
        CYG_TEST_CHECK( E_OK == ercd, "rel_blk bad ercd1" );
555
        vp1 = NULL;
556
        break;
557
    default:
558
        CYG_TEST_FAIL( "bad switch" );
559
        break;
560
    }
561
}
562
 
563
void
564
do_delete( WAITOP wait )
565
{
566
    ER ercd = E_OK;
567
    switch ( wait ) {
568
    case SLEEP:
569
    case DELAY:
570
        CYG_TEST_FAIL( "bad call to do_delete( SLEEP or DELAY )" );
571
        break;
572
    case SEMGET:
573
#ifdef CYGPKG_UITRON_SEMAS_CREATE_DELETE
574
        // delete the semaphore
575
        ercd = del_sem( 1 );
576
        CYG_TEST_CHECK( E_OK == ercd, "del_sem bad ercd" );
577
#else
578
        CYG_TEST_FAIL( "bad call to do_delete( SEMGET )" );
579
#endif
580
        break;
581
    case FLAGWAIT:
582
#ifdef CYGPKG_UITRON_FLAGS_CREATE_DELETE
583
        // delete the flag
584
        ercd = del_flg( 1 );
585
        CYG_TEST_CHECK( E_OK == ercd, "del_flg bad ercd" );
586
#else
587
        CYG_TEST_FAIL( "bad call to do_delete( FLAGWAIT )" );
588
#endif
589
        break;
590
    case MSGGET:
591
#ifdef CYGPKG_UITRON_MBOXES_CREATE_DELETE
592
        // delete the mbox
593
        ercd = del_mbx( 1 );
594
        CYG_TEST_CHECK( E_OK == ercd, "del_mbx bad ercd" );
595
#else
596
        CYG_TEST_FAIL( "bad call to do_delete( MSGGET )" );
597
#endif
598
        break;
599
    case MEMFIXEDGET:
600
#ifdef CYGPKG_UITRON_MEMPOOLFIXED_CREATE_DELETE
601
        // delete the mempool
602
        ercd = del_mpf( 1 );
603
        CYG_TEST_CHECK( E_OK == ercd, "del_mpf bad ercd" );
604
#else
605
        CYG_TEST_FAIL( "bad call to do_delete( MEMFIXEDGET )" );
606
#endif
607
        break;
608
    case MEMVARGET:
609
#ifdef CYGPKG_UITRON_MEMPOOLVAR_CREATE_DELETE
610
        // delete the mempool
611
        ercd = del_mpl( 1 );
612
        CYG_TEST_CHECK( E_OK == ercd, "del_mpl bad ercd" );
613
#else
614
        CYG_TEST_FAIL( "bad call to do_delete( MEMVARGET )" );
615
#endif
616
        break;
617
    default:
618
        CYG_TEST_FAIL( "bad switch" );
619
        break;
620
    }
621
    // this is just to use ercd to prevent warnings
622
    CYG_TEST_CHECK( E_OK == ercd, "<blank> bad ercd" );
623
}
624
 
625
 
626
 
627
ER
628
do_wait( WAITOP wait, WAITTYPE type )
629
{
630
    switch ( wait ) {
631
    case SLEEP:
632
        return ( PLAIN == type ) ? slp_tsk() : tslp_tsk( T2_WAIT );
633
    case DELAY:
634
        return dly_tsk( T2_WAIT );      // forget the type
635
    case SEMGET:
636
        return ( PLAIN == type ) ? wai_sem( 1 ) : twai_sem( 1, T2_WAIT );
637
    case FLAGWAIT:
638
        return ( PLAIN == type ) ?
639
            wai_flg( &scratch, 1, 0x55, TWF_ANDW ) :
640
           twai_flg( &scratch, 1, 0xaa, TWF_ANDW, T2_WAIT );
641
    case MSGGET:
642
        return ( PLAIN == type ) ?
643
            rcv_msg( &msg1, 1 ) :
644
           trcv_msg( &msg1, 1, T2_WAIT );
645
    case MEMFIXEDGET:
646
        return ( PLAIN == type ) ?
647
            get_blf( &t2vp, 1 ) :
648
           tget_blf( &t2vp, 1, T2_WAIT );
649
    case MEMVARGET:
650
        return ( PLAIN == type ) ?
651
            get_blk( &t2vp, 1, T2_MALLOC ) :
652
           tget_blk( &t2vp, 1, T2_MALLOC, T2_WAIT );
653
    default:
654
        CYG_TEST_FAIL( "bad switch" );
655
        break;
656
    }
657
    CYG_TEST_FAIL( "Bad wait in do_wait" );
658
    return E_SYS;
659
}
660
 
661
void
662
check_waitstate( WAITOP wait, int waiting )
663
{
664
    ER ercd;
665
    int waity = 0;
666
    switch ( wait ) {
667
    case SLEEP:
668
    case DELAY:
669
        return;                         // do nothing for these
670
    case SEMGET: {
671
        T_RSEM rsem;
672
        ercd = ref_sem( &rsem, 1 );
673
        waity = rsem.wtsk;
674
        break;
675
    }
676
    case FLAGWAIT: {
677
        T_RFLG rflg;
678
        ercd = ref_flg( &rflg, 1 );
679
        waity = rflg.wtsk;
680
        break;
681
    }
682
    case MSGGET: {
683
        T_RMBX rmbx;
684
        ercd = ref_mbx( &rmbx, 1 );
685
        waity = rmbx.wtsk;
686
        break;
687
    }
688
    case MEMFIXEDGET: {
689
        T_RMPF rmpf;
690
        ercd = ref_mpf( &rmpf, 1 );
691
        waity = rmpf.wtsk;
692
        break;
693
    }
694
    case MEMVARGET: {
695
        T_RMPL rmpl;
696
        ercd = ref_mpl( &rmpl, 1 );
697
        waity = rmpl.wtsk;
698
        break;
699
    }
700
    default:
701
        CYG_TEST_FAIL( "bad switch" );
702
        break;
703
    }
704
    if ( waiting )
705
        CYG_TEST_CHECK( waity, "Object has no task waiting!" );
706
    else
707
        CYG_TEST_CHECK( !waity, "Object had a task waiting!" );
708
}
709
 
710
// ========================================================================
711
void task1( unsigned int arg )
712
{
713
    ER ercd;
714
    WAITOP wait;
715
    WAITTYPE type;
716
    KILLOP kill;
717
 
718
    CYG_TEST_INFO( "Task 1 running" );
719
 
720
    {
721
        extern Cyg_Thread cyg_uitron_TASKS[];
722
        cyg_test_dump_thread_stack_stats(
723
            "Startup, task1", &cyg_uitron_TASKS[ 0 ] );
724
        cyg_test_dump_thread_stack_stats(
725
            "Startup, task2", &cyg_uitron_TASKS[ 1 ] );
726
        cyg_test_dump_interrupt_stack_stats( "Startup" );
727
        cyg_test_dump_idlethread_stack_stats( "Startup" );
728
        cyg_test_clear_interrupt_stack();
729
    }
730
 
731
    ercd = chg_pri( 1, 8 );
732
    CYG_TEST_CHECK( E_OK == ercd, "chg_pri bad ercd" );
733
 
734
    for ( wait = START_WAITOP; wait < DONE_WAITOP ; wait++) {
735
        for ( type = START_TYPE; type < DONE_TYPE   ; type++ ) {
736
            for ( kill = START_KILLOP; kill < DONE_KILLOP ; kill++ ) {
737
 
738
                // These clauses deal with a couple of special cases:
739
                // [doing it this way helps keep the rest of the code
740
                //  nicely general and orthogonal]
741
                // 
742
                // 1) DELAY: dly_tsk(): when this times out, the retcode is
743
                // E_OK rather than E_TMOUT, and it always times out.  The
744
                // "signalling" method here is just to wait yourself.  So we
745
                // do not test DELAY with TIMED type.
746
                //
747
                // 2) PLAIN tests with TIMEOUT kill operations: a PLAIN test
748
                // will not time out, it'll wait forever, so waiting for it
749
                // so to do is pointless; further, we would check for the
750
                // wrong error code.  So we do not test PLAIN tests with
751
                // TIMOUT kill operations.
752
                //
753
                // 3) SLEEP or DELAY tests with DELETE operations: there is
754
                // no synchronization to delete in those cases.
755
                // 3a) Individual object types are tested for delete support,
756
                // and if there is none, the test is skipped.
757
 
758
                if ( DELAY == wait && TIMED == type )
759
                    continue;
760
 
761
                if ( PLAIN == type &&
762
                     ( (        TIMEOUT        == kill) ||
763
                       (SUSPEND_TIMEOUT_RESUME == kill) ||
764
                       (SUSPEND_TIMEOUT_KILL   == kill) ) )
765
                    continue;
766
 
767
                if ( (
768
#ifndef CYGPKG_UITRON_SEMAS_CREATE_DELETE
769
                    (SEMGET      == wait) ||
770
#endif
771
#ifndef CYGPKG_UITRON_FLAGS_CREATE_DELETE
772
                    (FLAGWAIT    == wait) ||
773
#endif
774
#ifndef CYGPKG_UITRON_MBOXES_CREATE_DELETE
775
                    (MSGGET      == wait) ||
776
#endif
777
#ifndef CYGPKG_UITRON_MEMPOOLFIXED_CREATE_DELETE
778
                    (MEMFIXEDGET == wait) ||
779
#endif
780
#ifndef CYGPKG_UITRON_MEMPOOLVAR_CREATE_DELETE
781
                    (MEMVARGET   == wait) ||
782
#endif
783
                    (SLEEP       == wait) ||
784
                    (DELAY       == wait)
785
                    ) &&
786
                     ((DELETE                == kill) ||
787
                      (SUSPEND_DELETE_RESUME == kill) ||
788
                      (SUSPEND_DELETE_KILL   == kill)) )
789
                    continue;
790
 
791
 
792
                CYG_TEST_INFO( makemsg( "T1: ", wait, type, kill ) );
793
 
794
                intercom = 0;
795
 
796
                // prepare the synchronization objects
797
                // (actually, just empty the mempools)
798
                do_prep( wait );
799
 
800
                // start task 2 at a higher priority than myself
801
                ercd = dis_dsp();
802
                CYG_TEST_CHECK( E_OK == ercd, "dis_dsp bad ercd" );
803
                ercd = sta_tsk( 2, task2arg( wait, type, kill ) );
804
                CYG_TEST_CHECK( E_OK == ercd, "sta_tsk bad ercd" );
805
                ercd = chg_pri( 2, 5 );
806
                CYG_TEST_CHECK( E_OK == ercd, "chg_pri bad ercd" );
807
                ercd = ena_dsp();
808
                CYG_TEST_CHECK( E_OK == ercd, "ena_dsp bad ercd" );
809
                // task 2 should run now, until it waits.
810
 
811
                ercd = ref_tsk( &rtsk, 2 );
812
                CYG_TEST_CHECK( E_OK == ercd, "ref_tsk bad ercd" );
813
                CYG_TEST_CHECK( TTS_WAI == rtsk.tskstat, "bad tskstat" );
814
                CYG_TEST_CHECK( 5 == rtsk.tskpri, "bad tskpri" );
815
 
816
                switch ( kill ) {
817
                case SIGNAL:
818
                    // signal the task appropriately
819
                    do_signal( wait );
820
                    // it should now have run to completion
821
                    break;
822
                case TIMEOUT:
823
                    check_waitstate( wait, 1 );
824
                    // wait for the timeout to occur
825
                    ercd = dly_tsk( T1_WAIT );
826
                    CYG_TEST_CHECK( E_OK == ercd, "dly_tsk bad ercd" );
827
                    check_waitstate( wait, 0 );
828
                    // it should now have run to completion
829
                    break;
830
                case RELEASE:
831
                    // hit the task with a release-wait
832
                    ercd = rel_wai( 2 );
833
                    CYG_TEST_CHECK( E_OK == ercd, "rel_wai bad ercd" );
834
                    // it should now have run to completion
835
                    break;
836
                case DELETE:
837
                    // delete the object appropriately
838
                    do_delete( wait );
839
                    // it should now have run to completion
840
                    break;
841
                case KILL:
842
                    // kill the task
843
                    ercd = ter_tsk( 2 );
844
                    CYG_TEST_CHECK( E_OK == ercd, "ter_tsk bad ercd" );
845
                    // it should now have terminated without running
846
                    break;
847
                case SUSPEND_SIGNAL_RESUME:
848
                    // suspend the task
849
                    do_suspend();
850
                    // signal the task appropriately
851
                    do_signal( wait );
852
                    // resume the task
853
                    do_resume();
854
                    // it should now have run to completion
855
                    break;
856
                case SUSPEND_TIMEOUT_RESUME:
857
                    check_waitstate( wait, 1 );
858
                    // suspend the task
859
                    do_suspend();
860
                    check_waitstate( wait, 1 );
861
                    // wait for the timeout to occur
862
                    ercd = dly_tsk( T1_WAIT );
863
                    CYG_TEST_CHECK( E_OK == ercd, "dly_tsk bad ercd" );
864
                    check_waitstate( wait, 0 );
865
                    // resume the task
866
                    do_resume();
867
                    // it should now have run to completion
868
                    break;
869
                case SUSPEND_RELEASE_RESUME:
870
                    // suspend the task
871
                    do_suspend();
872
                    // hit the task with a release-wait
873
                    ercd = rel_wai( 2 );
874
                    CYG_TEST_CHECK( E_OK == ercd, "rel_wai bad ercd" );
875
                    // resume the task
876
                    do_resume();
877
                    // it should now have run to completion
878
                    break;
879
                case SUSPEND_DELETE_RESUME:
880
                    // suspend the task
881
                    do_suspend();
882
                    // delete the object appropriately
883
                    do_delete( wait );
884
                    // resume the task
885
                    do_resume();
886
                    // it should now have run to completion
887
                    break;
888
                case SUSPEND_KILL:
889
                    // suspend the task
890
                    do_suspend();
891
                    // kill the task
892
                    ercd = ter_tsk( 2 );
893
                    CYG_TEST_CHECK( E_OK == ercd, "ter_tsk bad ercd" );
894
                    // it should now have terminated without running
895
                    break;
896
                case SUSPEND_SIGNAL_KILL:
897
                    // suspend the task
898
                    do_suspend();
899
                    // signal the task appropriately
900
                    do_signal( wait );
901
                    // kill the task
902
                    ercd = ter_tsk( 2 );
903
                    CYG_TEST_CHECK( E_OK == ercd, "ter_tsk bad ercd" );
904
                    // it should now have terminated without running
905
                    break;
906
                case SUSPEND_TIMEOUT_KILL:
907
                    check_waitstate( wait, 1 );
908
                    // suspend the task
909
                    do_suspend();
910
                    check_waitstate( wait, 1 );
911
                    // wait for the timeout to occur
912
                    ercd = dly_tsk( T1_WAIT );
913
                    CYG_TEST_CHECK( E_OK == ercd, "dly_tsk bad ercd" );
914
                    check_waitstate( wait, 0 );
915
                    // kill the task
916
                    ercd = ter_tsk( 2 );
917
                    CYG_TEST_CHECK( E_OK == ercd, "ter_tsk bad ercd" );
918
                    // it should now have terminated without running
919
                    break;
920
                case SUSPEND_RELEASE_KILL:
921
                    // suspend the task
922
                    do_suspend();
923
                    // hit the task with a release-wait
924
                    ercd = rel_wai( 2 );
925
                    CYG_TEST_CHECK( E_OK == ercd, "rel_wai bad ercd" );
926
                     // kill the task
927
                    ercd = ter_tsk( 2 );
928
                    CYG_TEST_CHECK( E_OK == ercd, "ter_tsk bad ercd" );
929
                    // it should now have terminated without running
930
                    break;
931
                case SUSPEND_DELETE_KILL:
932
                    // suspend the task
933
                    do_suspend();
934
                    // delete the object appropriately
935
                    do_delete( wait );
936
                    // kill the task
937
                    ercd = ter_tsk( 2 );
938
                    CYG_TEST_CHECK( E_OK == ercd, "ter_tsk bad ercd" );
939
                    // it should now have terminated without running
940
                    break;
941
                default:
942
                    CYG_TEST_FAIL( "bad switch" );
943
                    break;
944
                }
945
 
946
                // task 2 should be dormant now, however it got there
947
                ercd = ref_tsk( &rtsk, 2 );
948
                CYG_TEST_CHECK( E_OK == ercd, "ref_tsk bad ercd" );
949
                CYG_TEST_CHECK( TTS_DMT == rtsk.tskstat, "bad tskstat" );
950
 
951
                if ( (SUSPEND_SIGNAL_KILL == kill) &&
952
                     ((MEMFIXEDGET == wait) || (MEMVARGET == wait)) ) {
953
                    // it was a killed successful memory alloc, so we have
954
                    // lost the pointer to memory allocated; there is an
955
                    // implicit storeleak problem when the task trying
956
                    // to allocate is signalled then killed.
957
                    // Recreate the pointer from an old version:
958
                    CYG_TEST_CHECK( NULL == t2vp, "t2vp WAS allocated!" );
959
                    t2vp = t2vp_backup;
960
                }
961
 
962
                switch ( kill ) {
963
                case KILL:
964
                case SUSPEND_KILL:
965
                case SUSPEND_SIGNAL_KILL:
966
                case SUSPEND_TIMEOUT_KILL:
967
                case SUSPEND_RELEASE_KILL:
968
                case SUSPEND_DELETE_KILL:
969
                    // if task 2 was killed, expect only one increment
970
                    CYG_TEST_CHECK( 1 == intercom, "intercom bad value !1" );
971
                    break;
972
                default:
973
                    // otherwise expect two increments
974
                    CYG_TEST_CHECK( 2 == intercom, "intercom bad value !2" );
975
                    break;
976
                }
977
 
978
                // tidy up or recreate the synchronization objects
979
                if ( (DELETE                == kill) ||
980
                     (SUSPEND_DELETE_RESUME == kill) ||
981
                     (SUSPEND_DELETE_KILL   == kill) )
982
                    do_recreate( wait );
983
                else
984
                    do_tidyup( wait );
985
            }
986
        }
987
    }
988
    CYG_TEST_PASS("synchronization interaction tests");
989
 
990
    {
991
        extern Cyg_Thread cyg_uitron_TASKS[];
992
        cyg_test_dump_thread_stack_stats(
993
            "All done, task1", &cyg_uitron_TASKS[ 0 ] );
994
        cyg_test_dump_thread_stack_stats(
995
            "All done, task2", &cyg_uitron_TASKS[ 1 ] );
996
        cyg_test_dump_interrupt_stack_stats( "All done" );
997
        cyg_test_dump_idlethread_stack_stats( "All done" );
998
    }
999
    // all done
1000
    CYG_TEST_EXIT( "All done" );
1001
    ext_tsk();
1002
}
1003
 
1004
 
1005
 
1006
void task2( unsigned int arg )
1007
{
1008
    ER ercd;
1009
    WAITOP wait;
1010
    WAITTYPE waittype;
1011
    KILLOP kill;
1012
 
1013
    decodearg( arg, &wait, &waittype, &kill );
1014
 
1015
//    CYG_TEST_INFO( makemsg( " 2: ", wait, waittype, kill ) );
1016
 
1017
    intercom++;
1018
    ercd = do_wait( wait, waittype );
1019
    intercom++;
1020
 
1021
    switch ( kill ) {
1022
    case SIGNAL:
1023
    case SUSPEND_SIGNAL_RESUME:
1024
        // we expect to have been signalled correctly
1025
        CYG_TEST_CHECK( E_OK == ercd, "T2 wait bad ercd" );
1026
        // here we know that the op completed OK
1027
        if ( (MEMFIXEDGET == wait) || (MEMVARGET == wait) ) {
1028
            // it was a successful memory alloc of whichever type,
1029
            // so we can save away a copy of t2vp for working round an
1030
            // implicit storeleak problem when the task trying to allocate
1031
            // is signalled then killed:
1032
            CYG_TEST_CHECK( NULL != t2vp, "No t2vp allocated!" );
1033
            t2vp_backup = t2vp;
1034
        }
1035
        break;
1036
    case TIMEOUT:
1037
    case SUSPEND_TIMEOUT_RESUME:
1038
        // we expect to have timed out - if it's a timeout op.
1039
        CYG_TEST_CHECK( E_TMOUT == ercd, "T2 timeout bad ercd, !E_TMOUT" );
1040
        break;
1041
    case RELEASE:
1042
    case SUSPEND_RELEASE_RESUME:
1043
        // we expect to have suffered a release wait.
1044
        CYG_TEST_CHECK( E_RLWAI == ercd, "T2 release bad ercd, !E_RLWAI" );
1045
        break;
1046
    case DELETE:
1047
    case SUSPEND_DELETE_RESUME:
1048
        // we expect to be told the object is gone
1049
        CYG_TEST_CHECK( E_DLT == ercd, "T2 release bad ercd, !E_DLT" );
1050
        break;
1051
    case KILL:
1052
    case SUSPEND_KILL:
1053
    case SUSPEND_SIGNAL_KILL:
1054
    case SUSPEND_TIMEOUT_KILL:
1055
    case SUSPEND_RELEASE_KILL:
1056
    case SUSPEND_DELETE_KILL:
1057
        // we expect to have been killed here, ie. this won't execute!
1058
        CYG_TEST_FAIL( "Task 2 ran to completion!" );
1059
        break;
1060
    default:
1061
        CYG_TEST_FAIL( "bad switch" );
1062
        break;
1063
    }
1064
}
1065
 
1066
void task3( unsigned int arg )
1067
{
1068
}
1069
 
1070
void task4( unsigned int arg )
1071
{
1072
}
1073
 
1074
#else // not enough (or too many) uITRON objects configured in
1075
#define N_A_MSG "not enough uITRON objects to run test"
1076
#endif // not enough (or too many) uITRON objects configured in
1077
#else  // not C++ and some C++ specific options enabled
1078
#define N_A_MSG "C++ specific options selected but this is C"
1079
#endif  // not C++ and some C++ specific options enabled
1080
#else // ! CYGVAR_KERNEL_COUNTERS_CLOCK   - can't test without it
1081
#define N_A_MSG "no CYGVAR_KERNEL_COUNTERS_CLOCK"
1082
#endif // ! CYGVAR_KERNEL_COUNTERS_CLOCK  - can't test without it
1083
#else  // ! CYGFUN_KERNEL_THREADS_TIMER   - can't test without it
1084
#define N_A_MSG "no CYGFUN_KERNEL_THREADS_TIMER"
1085
#endif // ! CYGFUN_KERNEL_THREADS_TIMER   - can't test without it
1086
#else  // ! CYGIMP_THREAD_PRIORITY        - can't test without it
1087
#define N_A_MSG "no CYGSEM_KERNEL_SCHED_MLQUEUE"
1088
#endif // ! CYGSEM_KERNEL_SCHED_MLQUEUE   - can't test without it
1089
#else  // ! CYGIMP_UITRON_STRICT_CONFORMANCE - can't test without it
1090
#define N_A_MSG "no CYGIMP_UITRON_STRICT_CONFORMANCE"
1091
#endif // ! CYGIMP_UITRON_STRICT_CONFORMANCE - can't test without it
1092
#else  // ! CYGPKG_UITRON
1093
#define N_A_MSG "uITRON Compatibility layer disabled"
1094
#endif // CYGPKG_UITRON
1095
 
1096
#ifdef N_A_MSG
1097
externC void
1098
cyg_start( void )
1099
{
1100
    CYG_TEST_INIT();
1101
    CYG_TEST_NA( N_A_MSG );
1102
}
1103
#endif // N_A_MSG defined ie. we are N/A.
1104
 
1105
// EOF testcx7.cxx

powered by: WebSVN 2.1.0

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