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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [packages/] [kernel/] [current/] [tests/] [thread2.cxx] - 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
//        thread2.cxx
4
//
5
//        Thread test 2
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(s):     dsm
43
// Contributors:    dsm
44
// Date:          1998-02-19
45
// Description:
46
//    tests scheduler & threads & priorities
47
//    + create multiple threads with various priorities
48
//    + check highest priority running thread is always running
49
//    + check next highest runs when highest suspended
50
//    + check several threads of equal priority share time
51
//      (only !CYGINT_KERNEL_SCHEDULER_UNIQUE_PRIORITIES)
52
//    + check other threads are starved
53
//    + check setting priority dynamically causes a thread to
54
//      become/stay current/non-current
55
// Omissions:
56
//     check yield
57
//     check can set threads with min and max priority
58
// Options:
59
//    CYGINT_KERNEL_SCHEDULER_UNIQUE_PRIORITIES
60
//    CYGIMP_THREAD_PRIORITY
61
//    CYGNUM_KERNEL_SCHED_PRIORITIES
62
//    CYGSEM_KERNEL_SCHED_BITMAP
63
//    CYGSEM_KERNEL_SCHED_MLQUEUE
64
//####DESCRIPTIONEND####
65
//==========================================================================
66
 
67
#include <pkgconf/kernel.h>
68
 
69
#include <cyg/kernel/thread.hxx>
70
#include <cyg/kernel/thread.inl>
71
#include <cyg/kernel/sched.hxx>
72
#include <cyg/kernel/mutex.hxx>
73
#include <cyg/kernel/sema.hxx>
74
 
75
#include <cyg/infra/testcase.h>
76
 
77
#include <cyg/kernel/sched.inl>
78
 
79
// ------------------------------------------------------------------------
80
 
81
#if defined(CYGIMP_THREAD_PRIORITY) && \
82
    !defined(CYGPKG_KERNEL_SMP_SUPPORT)
83
 
84
// ------------------------------------------------------------------------
85
 
86
static Cyg_Counting_Semaphore s0, s1, s2;
87
 
88
static volatile cyg_ucount8 q = 0;
89
 
90
static Cyg_Thread *thread0, *thread1, *thread2;
91
 
92
#define NTHREADS 3
93
#include "testaux.hxx"
94
 
95
// ------------------------------------------------------------------------
96
 
97
static void entry0( CYG_ADDRWORD data )
98
{
99
    CHECK(  0 == q++ );
100
    s0.wait();
101
    CHECK(  3 == q++ );
102
    s1.post();
103
    CHECK(  4 == q++ );
104
    s0.wait();
105
    s0.wait();
106
    CYG_TEST_PASS_FINISH("Thread 2 OK");
107
}
108
 
109
// ------------------------------------------------------------------------
110
 
111
static void entry1( CYG_ADDRWORD data )
112
{
113
    CHECK(  1 == q++ );
114
    s1.wait();
115
    CHECK(  5 == q++ );
116
    thread0->set_priority(9);
117
    s0.post();
118
    CHECK(  6 == q++ );
119
    thread2->set_priority(3);
120
    CHECK(  8 == q++ );
121
    s2.post();
122
    CHECK( 12 == q++ );
123
    CHECK( 9 == thread0->get_priority() );
124
    CHECK( 6 == thread1->get_priority() );
125
    CHECK( 7 == thread2->get_priority() );
126
    q = 100;
127
#if !(CYGINT_KERNEL_SCHEDULER_UNIQUE_PRIORITIES) \
128
    && defined(CYGSEM_KERNEL_SCHED_TIMESLICE)
129
    thread2->set_priority(6);
130
    CHECK( 6 == thread1->get_priority() );
131
    CHECK( 6 == thread2->get_priority() );
132
 
133
    while ( 100 == q )
134
        ;
135
    CHECK( 101 == q++ );
136
    s1.wait();
137
    CHECK( 103 == q++ );
138
#endif
139
    s0.post();
140
    s1.wait();
141
}
142
 
143
// ------------------------------------------------------------------------
144
 
145
static void entry2( CYG_ADDRWORD data )
146
{
147
    CHECK(  2 == q++ );
148
    s0.post();
149
    CHECK(  7 == q++ );
150
    s2.wait();
151
    CHECK(  9 == q++ );
152
    thread1->set_priority(6);
153
    CHECK( 10 == q++ );
154
    thread2->set_priority(2);
155
    CHECK( 11 == q++ );
156
    thread2->set_priority(7);
157
 
158
#if !(CYGINT_KERNEL_SCHEDULER_UNIQUE_PRIORITIES) \
159
    && defined(CYGSEM_KERNEL_SCHED_TIMESLICE)
160
    CHECK( 6 == thread1->get_priority() );
161
    CHECK( 6 == thread2->get_priority() );
162
 
163
    CHECK( 100 == q++ );
164
    while ( 101 == q )
165
        ;
166
    CHECK( 102 == q++ );
167
    s1.post();
168
#endif
169
    s0.post();
170
    s2.wait();
171
}
172
 
173
 
174
// ------------------------------------------------------------------------
175
 
176
void thread2_main( void )
177
{
178
    CYG_TEST_INIT();
179
 
180
    thread0 = new_thread( entry0, 0 );
181
    thread1 = new_thread( entry1, 1 );
182
    thread2 = new_thread( entry2, 2 );
183
 
184
    thread0->resume();
185
    thread1->resume();
186
    thread2->resume();
187
 
188
    thread0->set_priority(5);
189
    thread1->set_priority(6);
190
    thread2->set_priority(7);
191
 
192
    if( 9 >= CYG_THREAD_MIN_PRIORITY )
193
        CYG_TEST_FAIL_FINISH("Test requires priorities up to 9");
194
 
195
    if( 2 <= CYG_THREAD_MAX_PRIORITY )
196
        CYG_TEST_FAIL_FINISH("Test requires priorities as low as 2");
197
 
198
    Cyg_Scheduler::start();
199
 
200
    CYG_TEST_FAIL_FINISH("Unresolved");
201
}
202
 
203
// ------------------------------------------------------------------------
204
 
205
externC void
206
cyg_start( void )
207
{
208
#ifdef CYGSEM_HAL_STOP_CONSTRUCTORS_ON_FLAG
209
    cyg_hal_invoke_constructors();
210
#endif
211
    thread2_main();
212
}
213
// ------------------------------------------------------------------------
214
 
215
 
216
#else // CYGPKG_KERNEL_SMP_SUPPORT etc
217
 
218
// ------------------------------------------------------------------------
219
 
220
externC void
221
cyg_start( void )
222
{
223
    CYG_TEST_INIT();
224
    CYG_TEST_INFO("Thread2 test requires:\n"
225
                         "defined(CYGIMP_THREAD_PRIORITY) &&\n"
226
                         "!defined(CYGPKG_KERNEL_SMP_SUPPORT)\n");
227
    CYG_TEST_NA("Thread2 test requirements");
228
}
229
 
230
// ------------------------------------------------------------------------
231
 
232
#endif // CYGPKG_KERNEL_SMP_SUPPORT etc
233
 
234
// ------------------------------------------------------------------------
235
// EOF thread2.cxx

powered by: WebSVN 2.1.0

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