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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [packages/] [kernel/] [current/] [tests/] [flag1.cxx] - Blame information for rev 786

Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

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