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

Subversion Repositories openrisc_me

[/] [openrisc/] [trunk/] [rtos/] [ecos-2.0/] [packages/] [compat/] [uitron/] [v2_0/] [tests/] [test7.c] - Blame information for rev 174

Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

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