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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-2.0/] [packages/] [kernel/] [v2_0/] [tests/] [kflag1.c] - Blame information for rev 530

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

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

powered by: WebSVN 2.1.0

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