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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [packages/] [kernel/] [current/] [tests/] [kmbox1.c] - Blame information for rev 851

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

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

powered by: WebSVN 2.1.0

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