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

Subversion Repositories openrisc_me

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

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

Line No. Rev Author Line
1 27 unneback
//==========================================================================
2
//
3
//        flag1.cxx
4
//
5
//        Flag 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-11
46
// Description:   Tests basic flag 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/flag.hxx>
56
 
57
#include <cyg/infra/testcase.h>
58
 
59
#include <cyg/kernel/sched.inl>
60
 
61
 
62
#define NTHREADS 3
63
#include "testaux.hxx"
64
 
65
static Cyg_Flag f0, f1;
66
#ifdef CYGFUN_KERNEL_THREADS_TIMER
67
static Cyg_Flag f2;
68
#endif
69
 
70
static volatile cyg_atomic q = 0;
71
#define FIRST_THREAD_WAIT_TIME   5
72
#define SECOND_THREAD_WAIT_TIME 10
73
#define THIRD_THREAD_WAIT_TIME  20
74
 
75
static void entry0( CYG_ADDRWORD data )
76
{
77
    CYG_TEST_INFO("Testing setbits() and maskbits()");
78
    CYG_TEST_CHECK(0==f0.peek(), "flag not initialized properly");
79
    f0.setbits(0x1);
80
    CYG_TEST_CHECK(1==f0.peek(), "setbits");
81
    f0.setbits(0x3);
82
    CYG_TEST_CHECK(3==f0.peek(), "setbits");
83
    f0.maskbits(~0x5);
84
    CYG_TEST_CHECK(2==f0.peek(), "maskbits");
85
    f0.setbits();
86
    CYG_TEST_CHECK(~0u==f0.peek(), "setbits no arg");
87
    f0.maskbits();
88
    CYG_TEST_CHECK(0==f0.peek(), "maskbits no arg");
89
    CYG_TEST_CHECK(0==q++, "bad synchronization");
90
 
91
    CYG_TEST_INFO("Testing wait()");
92
    f1.setbits(0x4);
93
    CYG_TEST_CHECK(0x4==f1.peek(), "maskbits no arg");
94
    CYG_TEST_CHECK(1==q++, "bad synchronization");
95
    f1.setbits(0x18);                   // wake t1
96
    f1.wait(0x11, Cyg_Flag::AND | Cyg_Flag::CLR);
97
    CYG_TEST_CHECK(0==f1.peek(), "flag value wrong");
98
    CYG_TEST_CHECK(3==q++, "bad synchronization");
99
    f0.setbits(0x2);                    // wake t1
100
    f1.wait(0x10, Cyg_Flag::AND );
101
    f0.setbits(0x1);                    // wake t1
102
 
103
    f1.wait(0x11, Cyg_Flag::AND | Cyg_Flag::CLR);
104
 
105
#ifdef CYGFUN_KERNEL_THREADS_TIMER
106
    f2.wait(0x2, Cyg_Flag::OR);
107
    CYG_TEST_CHECK(20==q,"bad synchronization");
108
    f2.wait(0x10, Cyg_Flag::AND,
109
            Cyg_Clock::real_time_clock->current_value()+THIRD_THREAD_WAIT_TIME);
110
    CYG_TEST_CHECK(21==q++,"bad synchronization");
111
#endif
112
    f0.wait(1, Cyg_Flag::OR);
113
 
114
    CYG_TEST_FAIL_FINISH("Not reached");
115
}
116
 
117
static void entry1( CYG_ADDRWORD data )
118
{
119
    f1.wait(0xc, Cyg_Flag::AND);
120
    CYG_TEST_CHECK(2==q++, "bad synchronization");
121
    CYG_TEST_CHECK(0x1c==f1.peek(), "flag value wrong");
122
    f1.setbits(0x1);                    // wake t0
123
    f0.wait(0x3, Cyg_Flag::OR);
124
    CYG_TEST_CHECK(4==q++, "bad synchronization");
125
    CYG_TEST_CHECK(2==f0.peek(), "flag value wrong");
126
 
127
    f1.setbits(0xf0);                   // wake t0,t2
128
    f0.wait(0x5, Cyg_Flag::AND | Cyg_Flag::CLR); // wait for t0 & t2
129
    CYG_TEST_CHECK(0==f0.peek(), "flag value wrong");
130
    CYG_TEST_CHECK(0xf0==f1.peek(), "flag value wrong");
131
    CYG_TEST_CHECK(5==q++, "bad synchronization");
132
    f1.maskbits();
133
    CYG_TEST_CHECK(0==f1.peek(), "flag value wrong");
134
 
135
    CYG_TEST_INFO("Testing poll()");
136
    f0.setbits(0x55);
137
    CYG_TEST_CHECK(0x55==f0.peek(), "flag value wrong");
138
    CYG_TEST_CHECK(0x55==f0.poll(0x3, Cyg_Flag::OR),"bad poll() return");
139
    CYG_TEST_CHECK(0==f0.poll(0xf, Cyg_Flag::AND),"poll()");
140
    CYG_TEST_CHECK(0==f0.poll(0xa, Cyg_Flag::OR),"poll()");
141
    CYG_TEST_CHECK(0x55==f0.peek(), "flag value wrong");
142
    CYG_TEST_CHECK(0x55==f0.poll(0xf, Cyg_Flag::OR | Cyg_Flag::CLR),"poll");
143
    CYG_TEST_CHECK(0x0==f0.peek(), "flag value wrong");
144
    f0.setbits(0x50);
145
    CYG_TEST_CHECK(0x50==f0.poll(0x10, Cyg_Flag::AND | Cyg_Flag::CLR),"poll");
146
    CYG_TEST_CHECK(0x0==f0.peek(), "flag value wrong");
147
 
148
    CYG_TEST_INFO("Testing waiting()");
149
    f0.maskbits();
150
    CYG_TEST_CHECK(!f0.waiting(), "waiting()");
151
 
152
#ifdef CYGFUN_KERNEL_THREADS_TIMER
153
    thread[1]->delay( 10 ); // allow other threads to reach wait on f1
154
    CYG_TEST_CHECK(f1.waiting(), "waiting() not true");
155
    f1.setbits();                       // wake one of t0,t2
156
    CYG_TEST_CHECK(f1.waiting(), "waiting() not true");
157
#else
158
    f1.setbits(0x11);                   // wake one of t0,t2
159
#endif
160
    f1.setbits(0x11);                   // wake other of t0,t2    
161
    CYG_TEST_CHECK(!f1.waiting(), "waiting not false");
162
 
163
#ifdef CYGFUN_KERNEL_THREADS_TIMER
164
    CYG_TEST_INFO("Testing wait() with timeout");
165
    q=20;
166
    f2.setbits(0x2);                    // synchronize with t0,t2
167
    CYG_TEST_CHECK(20==q,"bad synchronization");
168
    f2.wait(0x20, Cyg_Flag::AND,
169
            Cyg_Clock::real_time_clock->current_value()+SECOND_THREAD_WAIT_TIME);
170
    CYG_TEST_CHECK(22==q++,"bad synchronization");
171
#endif
172
 
173
    CYG_TEST_PASS_FINISH("Flag 1 OK");
174
}
175
 
176
static void entry2( CYG_ADDRWORD data )
177
{
178
    f1.wait(0x60, Cyg_Flag::OR);
179
    f0.setbits(0x4);
180
 
181
    f1.wait(0x11, Cyg_Flag::AND | Cyg_Flag::CLR);
182
#ifdef CYGFUN_KERNEL_THREADS_TIMER
183
    f2.wait(0x2, Cyg_Flag::OR);
184
    CYG_TEST_CHECK(20==q,"bad synchronization");
185
    CYG_TEST_CHECK(0==f2.wait(0x40, Cyg_Flag::AND,
186
                              Cyg_Clock::real_time_clock->current_value()+FIRST_THREAD_WAIT_TIME),
187
                   "timed wait() wrong");
188
    CYG_TEST_CHECK(20==q++,"bad synchronization");
189
    // Now wake t0 before it times out
190
    f2.setbits(0x10);
191
#endif
192
    f0.wait(1, Cyg_Flag::OR);
193
 
194
    CYG_TEST_FAIL_FINISH("Not reached");
195
}
196
 
197
void flag1_main( void )
198
{
199
    CYG_TEST_INIT();
200
 
201
    new_thread(entry0, 0);
202
    new_thread(entry1, 1);
203
    new_thread(entry2, 2);
204
 
205
    Cyg_Scheduler::start();
206
 
207
    CYG_TEST_FAIL_FINISH("Not reached");
208
}
209
 
210
externC void
211
cyg_start( void )
212
{
213
#ifdef CYGSEM_HAL_STOP_CONSTRUCTORS_ON_FLAG
214
    cyg_hal_invoke_constructors();
215
#endif
216
    flag1_main();
217
}
218
 
219
// EOF flag1.cxx

powered by: WebSVN 2.1.0

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