OpenCores
URL https://opencores.org/ocsvn/openrisc_2011-10-31/openrisc_2011-10-31/trunk

Subversion Repositories openrisc_2011-10-31

[/] [openrisc/] [trunk/] [rtos/] [ecos-2.0/] [packages/] [kernel/] [v2_0/] [tests/] [kmbox1.c] - Blame information for rev 369

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

Line No. Rev Author Line
1 27 unneback
/*==========================================================================
2
//
3
//        kmbox1.cxx
4
//
5
//        Kernel Mbox test 1
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:        dsm
44
// Contributors:    dsm
45
// Date:          1998-06-02
46
// Description:   Tests basic mbox functionality.
47
//####DESCRIPTIONEND####
48
*/
49
 
50
#include <cyg/hal/hal_arch.h>           // CYGNUM_HAL_STACK_SIZE_TYPICAL
51
 
52
#include <cyg/kernel/kapi.h>
53
 
54
#include <cyg/infra/testcase.h>
55
 
56
#ifdef CYGFUN_KERNEL_API_C
57
 
58
#include "testaux.h"
59
 
60
#define NTHREADS 2
61
#define STACKSIZE CYGNUM_HAL_STACK_SIZE_TYPICAL
62
 
63
static cyg_handle_t thread[NTHREADS];
64
 
65
static cyg_thread thread_obj[NTHREADS];
66
static char stack[NTHREADS][STACKSIZE];
67
 
68
static cyg_handle_t m0, m1, m2;
69
static cyg_mbox mbox0, mbox1, mbox2;
70
 
71
static cyg_atomic q = 0;
72
 
73
#ifndef CYGMTH_MBOX_PUT_CAN_WAIT
74
#define cyg_mbox_PUT cyg_mbox_tryput
75
#endif
76
 
77
static void entry0( cyg_addrword_t data )
78
{
79
    cyg_count8 u,i,j;
80
 
81
    CYG_TEST_INFO("Testing put() and tryput() without wakeup");
82
    CYG_TEST_CHECK(!cyg_mbox_waiting_to_get(m0), "mbox not initialized properly");
83
    CYG_TEST_CHECK(0==cyg_mbox_peek(m0), "mbox not initialized properly");
84
    CYG_TEST_CHECK(NULL==cyg_mbox_peek_item(m0), "mbox not initialized properly");
85
    cyg_mbox_PUT(m0, (void *)55);
86
    CYG_TEST_CHECK(1==cyg_mbox_peek(m0), "peek() wrong");
87
    CYG_TEST_CHECK(55==(cyg_count8)cyg_mbox_peek_item(m0), "peek_item() wrong");
88
    for(u=1; cyg_mbox_tryput(m0, (void*)u); u++) {
89
        CYG_TEST_CHECK(55==(cyg_count8)cyg_mbox_peek_item(m0), "peek_item() wrong");
90
        CYG_TEST_CHECK(u+1==cyg_mbox_peek(m0), "peek() wrong");
91
    }
92
    CYG_TEST_CHECK(u == CYGNUM_KERNEL_SYNCH_MBOX_QUEUE_SIZE, "mbox not configured size");
93
 
94
    // m0 now contains ( 55 1 2 .. u-1 )
95
    CYG_TEST_CHECK(u==cyg_mbox_peek(m0), "peek() wrong");
96
    CYG_TEST_CHECK(55==(cyg_count8)cyg_mbox_peek_item(m0), "peek_item() wrong");
97
 
98
    CYG_TEST_INFO("Testing get(), tryget()");
99
 
100
    i = (cyg_count8)cyg_mbox_tryget(m0);
101
    CYG_TEST_CHECK( 55 == i, "Got wrong message" );
102
    for(j=1; j<u;j++) {
103
        CYG_TEST_CHECK( j == (cyg_count8)cyg_mbox_peek_item(m0), "peek_item()" );
104
        CYG_TEST_CHECK( cyg_mbox_peek(m0) == u - j, "peek() wrong" );
105
        i = (cyg_count8)cyg_mbox_get(m0);
106
        CYG_TEST_CHECK( j == i, "Got wrong message" );
107
    }
108
 
109
    CYG_TEST_CHECK( NULL == cyg_mbox_peek_item(m0), "peek_item()" );
110
    CYG_TEST_CHECK( 0 == cyg_mbox_peek(m0), "peek()");
111
 
112
    // m0 now empty
113
 
114
    CYG_TEST_CHECK(!cyg_mbox_waiting_to_put(m0), "waiting_to_put()");
115
    CYG_TEST_CHECK(!cyg_mbox_waiting_to_get(m0), "waiting_to_get()");
116
 
117
    CYG_TEST_INFO("Testing get(), blocking");
118
 
119
    CYG_TEST_CHECK(0==q++, "bad synchronization");
120
    cyg_mbox_PUT(m1, (void*)99);                  // wakes t1
121
    i = (cyg_count8)cyg_mbox_get(m0);          // sent by t1
122
    CYG_TEST_CHECK(3==i, "Recieved wrong message");
123
    CYG_TEST_CHECK(2==q++, "bad synchronization");
124
 
125
#ifdef CYGFUN_KERNEL_THREADS_TIMER
126
    CYG_TEST_CHECK(NULL==cyg_mbox_timed_get(m0, cyg_current_time()+10),
127
                   "unexpectedly found message");
128
    CYG_TEST_CHECK(3==q++, "bad synchronization");
129
    // Allow t1 to run as this get times out
130
    // t1 must not be waiting...
131
    CYG_TEST_CHECK(cyg_mbox_waiting_to_get(m0), "waiting_to_get()");
132
 
133
    cyg_mbox_PUT(m0, (void*)7);                   // wake t1 from timed get
134
#ifdef CYGMTH_MBOX_PUT_CAN_WAIT
135
    q=10;
136
    while(cyg_mbox_tryput(m0, (void*)6))          // fill m0's queue
137
        ;
138
    // m0 now contains ( 6 ... 6 )
139
    CYG_TEST_CHECK(10==q++, "bad synchronization");
140
    cyg_mbox_put(m1, (void*)4);                   // wake t1
141
    CYG_TEST_CHECK(!cyg_mbox_timed_put(m0, (void*)8, cyg_current_time()+10),
142
                   "timed put() unexpectedly worked");
143
    CYG_TEST_CHECK(12==q++, "bad synchronization");
144
    // m0 still contains ( 6 ... 6 )
145
    cyg_mbox_put(m0, (void*)9);
146
    CYG_TEST_CHECK(13==q++, "bad synchronization");
147
#endif
148
#endif
149
    i=(cyg_count8)cyg_mbox_get(m2);
150
    CYG_TEST_FAIL_FINISH("Not reached");
151
}
152
 
153
static void entry1( cyg_addrword_t data )
154
{
155
    cyg_count8 i;
156
    i = (cyg_count8)cyg_mbox_get(m1);
157
    CYG_TEST_CHECK(1==q++, "bad synchronization");
158
    cyg_mbox_PUT(m0, (void *)3);                  // wake t0
159
 
160
#if defined(CYGFUN_KERNEL_THREADS_TIMER)
161
    CYG_TEST_INFO("Testing timed functions");
162
    CYG_TEST_CHECK(7==(cyg_count8)cyg_mbox_timed_get(m0,cyg_current_time()+20),
163
                   "timed get()");
164
    CYG_TEST_CHECK(4==q++, "bad synchronization");
165
#ifdef CYGMTH_MBOX_PUT_CAN_WAIT
166
    CYG_TEST_CHECK(4==(cyg_count8)cyg_mbox_get(m1));
167
 
168
    CYG_TEST_CHECK(11==q++, "bad synchronization");
169
    thread[0]->delay(20);    // allow t0 to reach put on m1
170
    CYG_TEST_CHECK(14==q++, "bad synchronization");
171
    CYG_TEST_CHECK(cyg_mbox_waiting_to_put(m0), "waiting_to_put()");
172
    do {
173
        // after first get m0 contains ( 6 .. 6 9 )
174
        i=(cyg_count8)cyg_mbox_tryget(m0);
175
    } while(6==i);
176
    CYG_TEST_CHECK(9==i,"put gone awry");
177
#endif
178
#endif
179
    CYG_TEST_PASS_FINISH("Kernel C API Mbox 1 OK");
180
}
181
 
182
void kmbox1_main( void )
183
{
184
    CYG_TEST_INIT();
185
 
186
    cyg_thread_create(4, entry0 , (cyg_addrword_t)0, "kmbox1-0",
187
        (void *)stack[0], STACKSIZE, &thread[0], &thread_obj[0]);
188
    cyg_thread_resume(thread[0]);
189
 
190
    cyg_thread_create(4, entry1 , (cyg_addrword_t)1, "kmbox1-1",
191
        (void *)stack[1], STACKSIZE, &thread[1], &thread_obj[1]);
192
    cyg_thread_resume(thread[1]);
193
 
194
    cyg_mbox_create( &m0, &mbox0 );
195
    cyg_mbox_create( &m1, &mbox1 );
196
    cyg_mbox_create( &m2, &mbox2 );
197
 
198
    cyg_scheduler_start();
199
 
200
    CYG_TEST_FAIL_FINISH("Not reached");
201
}
202
 
203
externC void
204
cyg_start( void )
205
{
206
    kmbox1_main();
207
}
208
#else /* def CYGFUN_KERNEL_API_C */
209
externC void
210
cyg_start( void )
211
{
212
    CYG_TEST_INIT();
213
    CYG_TEST_NA("Kernel C API layer disabled");
214
}
215
#endif /* def CYGFUN_KERNEL_API_C */
216
 
217
/* EOF kmbox1.c */

powered by: WebSVN 2.1.0

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