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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-2.0/] [packages/] [kernel/] [v2_0/] [tests/] [mbox1.cxx] - Blame information for rev 475

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

Line No. Rev Author Line
1 27 unneback
//==========================================================================
2
//
3
//        mbox1.cxx
4
//
5
//        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-05-19
46
// Description:   Tests basic mbox functionality.
47
//####DESCRIPTIONEND####
48
 
49
#include <pkgconf/kernel.h>
50
 
51
#include <cyg/kernel/thread.hxx>        // Cyg_Thread
52
#include <cyg/kernel/thread.inl>
53
#include <cyg/kernel/sched.hxx>         // Cyg_Scheduler::start()
54
 
55
#include <cyg/kernel/mbox.hxx>
56
 
57
#include <cyg/infra/testcase.h>
58
 
59
#include <cyg/kernel/sched.inl>
60
 
61
#include <cyg/kernel/timer.hxx>         // Cyg_Timer
62
#include <cyg/kernel/clock.inl>         // Cyg_Clock
63
 
64
#define NTHREADS 2
65
#include "testaux.hxx"
66
 
67
static Cyg_Mbox m0, m1, m2;
68
 
69
static volatile cyg_atomic q = 0;
70
 
71
#ifndef CYGMTH_MBOX_PUT_CAN_WAIT
72
#define PUT tryput
73
#endif
74
 
75
static void entry0( CYG_ADDRWORD data )
76
{
77
    cyg_count8 u,i;
78
 
79
    CYG_TEST_INFO("Testing put() and tryput() without wakeup");
80
    CYG_TEST_CHECK(!m0.waiting_to_get(), "mbox not initialized properly");
81
    CYG_TEST_CHECK(0==m0.peek(), "mbox not initialized properly");
82
    CYG_TEST_CHECK(NULL==m0.peek_item(), "mbox not initialized properly");
83
    m0.PUT((void *)55);
84
    CYG_TEST_CHECK(1==m0.peek(), "peek() wrong");
85
    CYG_TEST_CHECK(55==(cyg_count8)m0.peek_item(), "peek_item() wrong");
86
    for(u=1; m0.tryput((void*)u); u++) {
87
        CYG_TEST_CHECK(55==(cyg_count8)m0.peek_item(), "peek_item() wrong");
88
        CYG_TEST_CHECK(u+1==m0.peek(), "peek() wrong");
89
    }
90
    CYG_TEST_CHECK(u == CYGNUM_KERNEL_SYNCH_MBOX_QUEUE_SIZE, "mbox not configured size");
91
 
92
    // m0 now contains ( 55 1 2 .. u-1 )
93
    CYG_TEST_CHECK(u==m0.peek(), "peek() wrong");
94
    CYG_TEST_CHECK(55==(cyg_count8)m0.peek_item(), "peek_item() wrong");
95
 
96
    CYG_TEST_INFO("Testing get(), tryget()");
97
 
98
    i = (cyg_count8)m0.tryget();
99
    CYG_TEST_CHECK( 55 == i, "Got wrong message" );
100
    for(cyg_count8 j=1; j<u;j++) {
101
        CYG_TEST_CHECK( j == (cyg_count8)m0.peek_item(), "peek_item()" );
102
        CYG_TEST_CHECK( m0.peek() == u - j, "peek() wrong" );
103
        i = (cyg_count8)m0.get();
104
        CYG_TEST_CHECK( j == i, "Got wrong message" );
105
    }
106
 
107
    CYG_TEST_CHECK( NULL == m0.peek_item(), "peek_item()" );
108
    CYG_TEST_CHECK( 0 == m0.peek(), "peek()");
109
 
110
    // m0 now empty
111
 
112
    CYG_TEST_CHECK(!m0.waiting_to_put(), "waiting_to_put()");
113
    CYG_TEST_CHECK(!m0.waiting_to_get(), "waiting_to_get()");
114
 
115
    CYG_TEST_INFO("Testing get(), blocking");
116
 
117
    CYG_TEST_CHECK(0==q++, "bad synchronization");
118
    m1.PUT((void*)99);                  // wakes t1
119
    i = (cyg_count8)m0.get();          // sent by t1
120
    CYG_TEST_CHECK(3==i, "Recieved wrong message");
121
    CYG_TEST_CHECK(2==q++, "bad synchronization");
122
 
123
#ifdef CYGFUN_KERNEL_THREADS_TIMER
124
    CYG_TEST_CHECK(NULL==m0.get(
125
        Cyg_Clock::real_time_clock->current_value() + 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(m0.waiting_to_get(), "waiting_to_get()");
131
 
132
    m0.PUT((void*)7);                   // wake t1 from timed get
133
#ifdef CYGMTH_MBOX_PUT_CAN_WAIT
134
    q=10;
135
    while(m0.tryput((void*)6))          // fill m0's queue
136
        ;
137
    // m0 now contains ( 6 ... 6 )
138
    CYG_TEST_CHECK(10==q++, "bad synchronization");
139
    m1.put((void*)4);                   // wake t1
140
    CYG_TEST_CHECK(!m0.put((void*)8, 2), "timed put() unexpectedly worked");
141
    CYG_TEST_CHECK(12==q++, "bad synchronization");
142
    // m0 still contains ( 6 ... 6 )
143
    m0.put((void*)9);
144
    CYG_TEST_CHECK(13==q++, "bad synchronization");
145
#endif
146
#endif
147
    i=(cyg_count8)m2.get();
148
    CYG_TEST_FAIL_FINISH("Not reached");
149
}
150
 
151
static void entry1( CYG_ADDRWORD data )
152
{
153
    cyg_count8 i;
154
    i = (cyg_count8)m1.get();
155
    CYG_TEST_CHECK(1==q++, "bad synchronization");
156
    m0.PUT((void *)3);                  // wake t0
157
 
158
#ifdef CYGFUN_KERNEL_THREADS_TIMER
159
    CYG_TEST_INFO("Testing timed functions");
160
    CYG_TEST_CHECK(7==(cyg_count8)m0.get(
161
        Cyg_Clock::real_time_clock->current_value() + 20), "timed get()");
162
    CYG_TEST_CHECK(4==q++, "bad synchronization");
163
#ifdef CYGMTH_MBOX_PUT_CAN_WAIT
164
    CYG_TEST_CHECK(4==(cyg_count8)m1.get());
165
 
166
    CYG_TEST_CHECK(11==q++, "bad synchronization");
167
    thread[0]->delay(20);    // allow t0 to reach put on m1
168
    CYG_TEST_CHECK(14==q++, "bad synchronization");
169
    CYG_TEST_CHECK(m0.waiting_to_put(), "waiting_to_put()");
170
    do {
171
        // after first get m0 contains ( 6 .. 6 9 )
172
        i=(cyg_count8)m0.tryget();
173
    } while(6==i);
174
    CYG_TEST_CHECK(9==i,"put gone awry");
175
#endif
176
#endif
177
    CYG_TEST_PASS_FINISH("Mbox 1 OK");
178
}
179
 
180
void mbox1_main( void )
181
{
182
    CYG_TEST_INIT();
183
 
184
    new_thread(entry0, 0);
185
    new_thread(entry1, 1);
186
 
187
    Cyg_Scheduler::start();
188
 
189
    CYG_TEST_FAIL_FINISH("Not reached");
190
}
191
 
192
externC void
193
cyg_start( void )
194
{
195
#ifdef CYGSEM_HAL_STOP_CONSTRUCTORS_ON_FLAG
196
    cyg_hal_invoke_constructors();
197
#endif
198
    mbox1_main();
199
}
200
 
201
// EOF mbox1.cxx

powered by: WebSVN 2.1.0

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