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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [packages/] [kernel/] [current/] [tests/] [kflag1.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
//        kflag1.cxx
4
//
5
//        Kernel C API 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:  hmt
44
// Date:          1998-10-19
45
// Description:   Tests basic flag 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
 
60
#define NTHREADS 3
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_flag_t f0, f1;
69
#ifdef CYGFUN_KERNEL_THREADS_TIMER
70
static cyg_flag_t f2;
71
#endif
72
 
73
static volatile cyg_ucount8 q = 0;
74
#define FIRST_THREAD_WAIT_TIME   5
75
#define SECOND_THREAD_WAIT_TIME 10
76
#define THIRD_THREAD_WAIT_TIME  20
77
 
78
static void entry0( cyg_addrword_t data )
79
{
80
    CYG_TEST_INFO("Testing cyg_flag_setbits() and cyg_flag_maskbits()");
81
    CYG_TEST_CHECK(0==cyg_flag_peek( &f0 ), "flag not initialized properly");
82
    cyg_flag_setbits( &f0, 0x1);
83
    CYG_TEST_CHECK(1==cyg_flag_peek( &f0 ), "setbits");
84
    cyg_flag_setbits( &f0, 0x3);
85
    CYG_TEST_CHECK(3==cyg_flag_peek( &f0 ), "setbits");
86
    cyg_flag_maskbits( &f0, ~0x5);
87
    CYG_TEST_CHECK(2==cyg_flag_peek( &f0 ), "maskbits");
88
    cyg_flag_setbits( &f0, ~0 );
89
    CYG_TEST_CHECK(~0u==cyg_flag_peek( &f0 ), "setbits all set");
90
    cyg_flag_maskbits( &f0, 0 );
91
    CYG_TEST_CHECK(0==cyg_flag_peek( &f0 ), "maskbits all clear");
92
    CYG_TEST_CHECK(0==q++, "bad synchronization");
93
 
94
    CYG_TEST_INFO("Testing cyg_flag_wait()");
95
    cyg_flag_setbits( &f1, 0x4);
96
    CYG_TEST_CHECK(0x4==cyg_flag_peek( &f1 ), "setbits");
97
    CYG_TEST_CHECK(1==q++, "bad synchronization");
98
    cyg_flag_setbits( &f1, 0x18);                   // wake t1
99
    cyg_flag_wait( &f1, 0x11, CYG_FLAG_WAITMODE_AND | CYG_FLAG_WAITMODE_CLR);
100
    CYG_TEST_CHECK(0==cyg_flag_peek( &f1 ), "flag value wrong");
101
    CYG_TEST_CHECK(3==q++, "bad synchronization");
102
    cyg_flag_setbits( &f0, 0x2);                    // wake t1
103
    cyg_flag_wait( &f1, 0x10, CYG_FLAG_WAITMODE_AND );
104
    cyg_flag_setbits( &f0, 0x1);                    // wake t1
105
 
106
    cyg_flag_wait( &f1, 0x11, CYG_FLAG_WAITMODE_AND | CYG_FLAG_WAITMODE_CLR);
107
 
108
#ifdef CYGFUN_KERNEL_THREADS_TIMER
109
    cyg_flag_wait( &f2, 0x2, CYG_FLAG_WAITMODE_OR);
110
    CYG_TEST_CHECK(20==q,"bad synchronization");
111
    cyg_flag_timed_wait( &f2, 0x10, CYG_FLAG_WAITMODE_AND,
112
                         cyg_current_time()+THIRD_THREAD_WAIT_TIME);
113
    CYG_TEST_CHECK(21==q++,"bad synchronization");
114
#endif
115
    cyg_flag_wait( &f0, 1, CYG_FLAG_WAITMODE_OR);
116
 
117
    CYG_TEST_FAIL_FINISH("Not reached");
118
}
119
 
120
static void entry1( cyg_addrword_t data )
121
{
122
    cyg_flag_wait( &f1, 0xc, CYG_FLAG_WAITMODE_AND);
123
    CYG_TEST_CHECK(2==q++, "bad synchronization");
124
    CYG_TEST_CHECK(0x1c==cyg_flag_peek( &f1 ), "flag value wrong");
125
    cyg_flag_setbits( &f1, 0x1);                    // wake t0
126
    cyg_flag_wait( &f0, 0x3, CYG_FLAG_WAITMODE_OR);
127
    CYG_TEST_CHECK(4==q++, "bad synchronization");
128
    CYG_TEST_CHECK(2==cyg_flag_peek( &f0 ), "flag value wrong");
129
 
130
    cyg_flag_setbits( &f1, 0xf0);                   // wake t0,t2
131
    cyg_flag_wait( &f0, 0x5, CYG_FLAG_WAITMODE_AND | CYG_FLAG_WAITMODE_CLR);
132
    CYG_TEST_CHECK(0==cyg_flag_peek( &f0 ), "flag value wrong");
133
    CYG_TEST_CHECK(0xf0==cyg_flag_peek( &f1 ), "flag value wrong");
134
    CYG_TEST_CHECK(5==q++, "bad synchronization");
135
    cyg_flag_maskbits( &f1, 0 );
136
    CYG_TEST_CHECK(0==cyg_flag_peek( &f1 ), "flag value wrong");
137
 
138
    CYG_TEST_INFO("Testing cyg_flag_poll()");
139
    cyg_flag_setbits( &f0, 0x55);
140
    CYG_TEST_CHECK(0x55==cyg_flag_peek( &f0 ), "flag value wrong");
141
    CYG_TEST_CHECK(0x55==cyg_flag_poll( &f0, 0x3, CYG_FLAG_WAITMODE_OR),"bad poll() return");
142
    CYG_TEST_CHECK(0==cyg_flag_poll( &f0, 0xf, CYG_FLAG_WAITMODE_AND),"poll()");
143
    CYG_TEST_CHECK(0==cyg_flag_poll( &f0, 0xa, CYG_FLAG_WAITMODE_OR),"poll()");
144
    CYG_TEST_CHECK(0x55==cyg_flag_peek( &f0 ), "flag value wrong");
145
    CYG_TEST_CHECK(0x55==cyg_flag_poll( &f0, 0xf, CYG_FLAG_WAITMODE_OR | CYG_FLAG_WAITMODE_CLR),"poll");
146
    CYG_TEST_CHECK(0x0==cyg_flag_peek( &f0 ), "flag value wrong");
147
    cyg_flag_setbits( &f0, 0x50);
148
    CYG_TEST_CHECK(0x50==cyg_flag_poll( &f0, 0x10, CYG_FLAG_WAITMODE_AND | CYG_FLAG_WAITMODE_CLR),"poll");
149
    CYG_TEST_CHECK(0x0==cyg_flag_peek( &f0 ), "flag value wrong");
150
 
151
    CYG_TEST_INFO("Testing cyg_flag_waiting()");
152
    cyg_flag_maskbits( &f0, 0 );
153
    CYG_TEST_CHECK(!cyg_flag_waiting( &f0 ), "waiting()");
154
 
155
#ifdef CYGFUN_KERNEL_THREADS_TIMER
156
    cyg_thread_delay( 10 ); // allow other threads to reach wait on f1
157
    CYG_TEST_CHECK(cyg_flag_waiting( &f1 ), "waiting() not true");
158
    cyg_flag_setbits( &f1, ~0 );                   // wake one of t0,t2
159
    CYG_TEST_CHECK(cyg_flag_waiting( &f1 ),"waiting() not true");
160
#else
161
    cyg_flag_setbits( &f1, 0x11);                   // wake one of t0,t2
162
#endif
163
    cyg_flag_setbits( &f1, 0x11);                   // wake other of t0,t2    
164
    CYG_TEST_CHECK(!cyg_flag_waiting( &f1 ),"waiting not false");
165
    CYG_TEST_CHECK(0x0==cyg_flag_peek( &f1 ), "flag value wrong");
166
 
167
#ifdef CYGFUN_KERNEL_THREADS_TIMER
168
    CYG_TEST_INFO("Testing cyg_flag_timed_wait()");
169
    q=20;
170
    cyg_flag_setbits( &f2, 0x2);                    // synchronize with t0,t2
171
    CYG_TEST_CHECK(20==q,"bad synchronization");
172
    cyg_flag_timed_wait( &f2, 0x20, CYG_FLAG_WAITMODE_AND,
173
                         cyg_current_time()+SECOND_THREAD_WAIT_TIME);
174
    CYG_TEST_CHECK(22==q++,"bad synchronization");
175
#endif
176
 
177
    CYG_TEST_PASS_FINISH("Kernel C API Flag 1 OK");
178
}
179
 
180
static void entry2( cyg_addrword_t data )
181
{
182
    cyg_flag_wait( &f1, 0x60, CYG_FLAG_WAITMODE_OR);
183
    cyg_flag_setbits( &f0, 0x4);
184
 
185
    cyg_flag_wait( &f1, 0x11, CYG_FLAG_WAITMODE_AND | CYG_FLAG_WAITMODE_CLR);
186
#ifdef CYGFUN_KERNEL_THREADS_TIMER
187
    cyg_flag_wait( &f2, 0x2, CYG_FLAG_WAITMODE_OR);
188
    CYG_TEST_CHECK(20==q,"bad synchronization");
189
    CYG_TEST_CHECK(0==cyg_flag_timed_wait( &f2, 0x40, CYG_FLAG_WAITMODE_AND,
190
                                           cyg_current_time()+FIRST_THREAD_WAIT_TIME),
191
                   "timed wait() wrong");
192
    CYG_TEST_CHECK(20==q++,"bad synchronization");
193
    // Now wake t0 before it times out
194
    cyg_flag_setbits( &f2, 0x10);
195
#endif
196
    cyg_flag_wait( &f0, 1, CYG_FLAG_WAITMODE_OR);
197
 
198
    CYG_TEST_FAIL_FINISH("Not reached");
199
}
200
 
201
void kflag1_main( void )
202
{
203
    CYG_TEST_INIT();
204
 
205
    cyg_flag_init( &f0 );
206
    cyg_flag_init( &f1 );
207
#ifdef CYGFUN_KERNEL_THREADS_TIMER
208
    cyg_flag_init( &f2 );
209
#endif
210
 
211
    cyg_thread_create( 1, entry0 , (cyg_addrword_t)0, "kflag1-0",
212
        (void *)stack[0], STACKSIZE, &thread[0], &thread_obj[0]);
213
    cyg_thread_resume(thread[0]);
214
 
215
    cyg_thread_create( 1, entry1 , (cyg_addrword_t)1, "kflag1-1",
216
        (void *)stack[1], STACKSIZE, &thread[1], &thread_obj[1]);
217
    cyg_thread_resume(thread[1]);
218
 
219
    cyg_thread_create( 1, entry2 , (cyg_addrword_t)2, "kflag1-2",
220
        (void *)stack[2], STACKSIZE, &thread[2], &thread_obj[2]);
221
    cyg_thread_resume(thread[2]);
222
 
223
    cyg_scheduler_start();
224
 
225
    CYG_TEST_FAIL_FINISH("Not reached");
226
}
227
 
228
externC void
229
cyg_start( void )
230
{
231
    kflag1_main();
232
}
233
 
234
#else /* def CYGFUN_KERNEL_API_C */
235
externC void
236
cyg_start( void )
237
{
238
    CYG_TEST_INIT();
239
    CYG_TEST_NA("Kernel C API layer disabled");
240
}
241
#endif /* def CYGFUN_KERNEL_API_C */
242
 
243
// EOF flag1.cxx

powered by: WebSVN 2.1.0

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