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

Subversion Repositories openrisc

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

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

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

powered by: WebSVN 2.1.0

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