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

Subversion Repositories openrisc

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

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 786 skrzyp
//==========================================================================
2
//
3
//        kill.cxx
4
//
5
//        Thread kill test
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):     nickg
43
// Contributors:  nickg
44
// Date:          1998-04-24
45
// Description:   Tests the functionality of thread kill() and
46
//                reinitalize().
47
//####DESCRIPTIONEND####
48
 
49
#include <pkgconf/kernel.h>
50
 
51
#include <cyg/kernel/thread.hxx>
52
#include <cyg/kernel/thread.inl>
53
#include <cyg/kernel/sched.hxx>
54
#include <cyg/kernel/mutex.hxx>
55
#include <cyg/kernel/sema.hxx>
56
 
57
#include <cyg/infra/testcase.h>
58
 
59
#ifdef CYGFUN_KERNEL_THREADS_TIMER
60
 
61
#include <cyg/kernel/sched.inl>
62
 
63
#define NTHREADS 3
64
 
65
#include "testaux.hxx"
66
 
67
// In general, this delay has to be long enough to account for slow targets
68
// and potential problems on e.g. the linux synthetic target to avoid
69
// potential problems due to timing inaccuracy and scheduling of Linux
70
// tasks. It is decreased further below for simulators.
71
int delay_ticks = 5;
72
 
73
 
74
static Cyg_Binary_Semaphore s0, s1;
75
 
76
volatile cyg_atomic thread0_state;
77
volatile cyg_atomic thread1_state;
78
volatile cyg_atomic thread2_state;
79
 
80
static void entry0( CYG_ADDRWORD data )
81
{
82
    Cyg_Thread *self = Cyg_Thread::self();
83
 
84
    thread0_state = 1;
85
 
86
    s0.wait();
87
 
88
    thread0_state = 2;
89
 
90
    CYG_TEST_FAIL_FINISH("Thread not killed");
91
 
92
    self->exit();
93
}
94
 
95
 
96
static void entry1( CYG_ADDRWORD data )
97
{
98
    Cyg_Thread *self = Cyg_Thread::self();
99
 
100
    thread1_state = 1;
101
 
102
    self->delay(delay_ticks);
103
 
104
    if( thread2_state != 1 )
105
        CYG_TEST_FAIL_FINISH("Thread2 in wrong state");
106
 
107
    thread1_state = 2;
108
 
109
    thread[0]->kill();
110
 
111
    thread1_state = 3;
112
 
113
    thread[2]->kill();
114
 
115
    thread1_state = 4;
116
 
117
    self->delay(delay_ticks);
118
 
119
    thread1_state = 5;
120
    thread2_state = 0;
121
 
122
    thread[2]->reinitialize();
123
    thread[2]->resume();
124
 
125
    self->delay(delay_ticks);
126
 
127
    if( thread2_state != 1 )
128
        CYG_TEST_FAIL_FINISH("Thread2 in wrong state");
129
 
130
    thread1_state = 6;
131
 
132
    self->delay(delay_ticks);
133
 
134
    if( thread2_state != 2 )
135
        CYG_TEST_FAIL_FINISH("Thread2 in wrong state");
136
 
137
    thread[2]->kill();
138
 
139
    thread1_state = 7;
140
 
141
    CYG_TEST_PASS_FINISH("Kill OK");
142
 
143
    Cyg_Thread::self()->exit();
144
}
145
 
146
static void entry2( CYG_ADDRWORD data )
147
{
148
    thread2_state = 1;
149
 
150
    while( thread1_state != 6 ) continue;
151
 
152
    thread2_state = 2;
153
 
154
    for(;;) continue;
155
 
156
}
157
 
158
void release_main(void)
159
{
160
    CYG_TEST_INIT();
161
 
162
    if (cyg_test_is_simulator)
163
        delay_ticks = 2;
164
 
165
    new_thread( entry0, 0);
166
    new_thread( entry1, 1);
167
    new_thread( entry2, 2);
168
 
169
    thread[0]->set_priority(5);
170
    thread[1]->set_priority(6);
171
    thread[2]->set_priority(7);
172
 
173
    Cyg_Scheduler::start();
174
 
175
    CYG_TEST_FAIL_FINISH("Not reached");
176
}
177
 
178
externC void
179
cyg_start( void )
180
{
181
#ifdef CYGSEM_HAL_STOP_CONSTRUCTORS_ON_FLAG
182
    cyg_hal_invoke_constructors();
183
#endif
184
    release_main();
185
}
186
 
187
#else // ifdef CYGFUN_KERNEL_THREADS_TIMER
188
 
189
externC void
190
cyg_start( void )
191
{
192
    CYG_TEST_INIT();
193
    CYG_TEST_NA("Kernel threads timer disabled");
194
}
195
 
196
#endif // ifdef CYGFUN_KERNEL_THREADS_TIMER
197
 
198
// EOF kill.cxx

powered by: WebSVN 2.1.0

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