|
0
|
1 //========================================================================== |
|
|
2 // |
|
|
3 // kill.cxx |
|
|
4 // |
|
|
5 // Thread kill test |
|
|
6 // |
|
|
7 //========================================================================== |
|
|
8 //####COPYRIGHTBEGIN#### |
|
|
9 // |
|
|
10 // ------------------------------------------- |
|
|
11 // The contents of this file are subject to the Cygnus eCos Public License |
|
|
12 // Version 1.0 (the "License"); you may not use this file except in |
|
|
13 // compliance with the License. You may obtain a copy of the License at |
|
|
14 // http://sourceware.cygnus.com/ecos |
|
|
15 // |
|
|
16 // Software distributed under the License is distributed on an "AS IS" |
|
|
17 // basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the |
|
|
18 // License for the specific language governing rights and limitations under |
|
|
19 // the License. |
|
|
20 // |
|
|
21 // The Original Code is eCos - Embedded Cygnus Operating System, released |
|
|
22 // September 30, 1998. |
|
|
23 // |
|
|
24 // The Initial Developer of the Original Code is Cygnus. Portions created |
|
2
|
25 // by Cygnus are Copyright (C) 1998,1999 Cygnus Solutions. All Rights Reserved. |
|
0
|
26 // ------------------------------------------- |
|
|
27 // |
|
|
28 //####COPYRIGHTEND#### |
|
|
29 //========================================================================== |
|
|
30 //#####DESCRIPTIONBEGIN#### |
|
|
31 // |
|
|
32 // Author(s): nickg |
|
2
|
33 // Contributors: nickg |
|
0
|
34 // Date: 1998-04-24 |
|
|
35 // Description: Tests the functionality of thread kill() and |
|
|
36 // reinitalize(). |
|
|
37 //####DESCRIPTIONEND#### |
|
|
38 |
|
|
39 #include <pkgconf/kernel.h> |
|
|
40 |
|
|
41 #include <cyg/kernel/thread.hxx> |
|
|
42 #include <cyg/kernel/thread.inl> |
|
|
43 #include <cyg/kernel/sched.hxx> |
|
|
44 #include <cyg/kernel/mutex.hxx> |
|
|
45 #include <cyg/kernel/sema.hxx> |
|
|
46 |
|
|
47 #include <cyg/infra/testcase.h> |
|
|
48 |
|
2
|
49 #ifdef CYGFUN_KERNEL_THREADS_TIMER |
|
|
50 |
|
0
|
51 #include <cyg/kernel/sched.inl> |
|
|
52 |
|
|
53 #define NTHREADS 3 |
|
|
54 |
|
|
55 #include "testaux.hxx" |
|
|
56 |
|
2
|
57 #ifdef CYGPKG_HAL_I386_LINUX |
|
|
58 // On the synthetic target the delay needs to be a bit bigger to avoid |
|
|
59 // potential problems due to timing inaccuracy and scheduling of Linux |
|
|
60 // tasks. |
|
|
61 int delay_ticks = 5; |
|
|
62 #else |
|
|
63 // if we delayed for just one tick, there's a good chance the clock may |
|
|
64 // roll over immediately, giving a negligible practical delay. So always use |
|
|
65 // a value greater than 1 |
|
|
66 int delay_ticks = 2; |
|
|
67 #endif |
|
|
68 |
|
|
69 |
|
|
70 |
|
0
|
71 static Cyg_Binary_Semaphore s0, s1; |
|
|
72 |
|
|
73 volatile cyg_atomic thread0_state; |
|
|
74 volatile cyg_atomic thread1_state; |
|
|
75 volatile cyg_atomic thread2_state; |
|
|
76 |
|
|
77 static void entry0( CYG_ADDRWORD data ) |
|
|
78 { |
|
|
79 Cyg_Thread *self = Cyg_Thread::self(); |
|
|
80 |
|
|
81 thread0_state = 1; |
|
|
82 |
|
|
83 s0.wait(); |
|
|
84 |
|
|
85 thread0_state = 2; |
|
|
86 |
|
|
87 CYG_TEST_FAIL_FINISH("Thread not killed"); |
|
|
88 |
|
|
89 self->exit(); |
|
|
90 } |
|
|
91 |
|
|
92 |
|
|
93 static void entry1( CYG_ADDRWORD data ) |
|
|
94 { |
|
|
95 Cyg_Thread *self = Cyg_Thread::self(); |
|
|
96 |
|
|
97 thread1_state = 1; |
|
|
98 |
|
2
|
99 self->delay(delay_ticks); |
|
0
|
100 |
|
|
101 if( thread2_state != 1 ) |
|
|
102 CYG_TEST_FAIL_FINISH("Thread2 in wrong state"); |
|
|
103 |
|
|
104 thread1_state = 2; |
|
|
105 |
|
|
106 thread[0]->kill(); |
|
|
107 |
|
|
108 thread1_state = 3; |
|
|
109 |
|
|
110 thread[2]->kill(); |
|
|
111 |
|
|
112 thread1_state = 4; |
|
|
113 |
|
2
|
114 self->delay(delay_ticks); |
|
0
|
115 |
|
|
116 thread1_state = 5; |
|
|
117 thread2_state = 0; |
|
|
118 |
|
|
119 thread[2]->reinitialize(); |
|
|
120 thread[2]->resume(); |
|
|
121 |
|
2
|
122 self->delay(delay_ticks); |
|
0
|
123 |
|
|
124 if( thread2_state != 1 ) |
|
|
125 CYG_TEST_FAIL_FINISH("Thread2 in wrong state"); |
|
|
126 |
|
|
127 thread1_state = 6; |
|
|
128 |
|
2
|
129 self->delay(delay_ticks); |
|
0
|
130 |
|
|
131 if( thread2_state != 2 ) |
|
|
132 CYG_TEST_FAIL_FINISH("Thread2 in wrong state"); |
|
|
133 |
|
|
134 thread[2]->kill(); |
|
|
135 |
|
|
136 thread1_state = 7; |
|
|
137 |
|
|
138 CYG_TEST_PASS_FINISH("Kill OK"); |
|
|
139 |
|
|
140 Cyg_Thread::self()->exit(); |
|
|
141 } |
|
|
142 |
|
|
143 static void entry2( CYG_ADDRWORD data ) |
|
|
144 { |
|
|
145 thread2_state = 1; |
|
|
146 |
|
|
147 while( thread1_state != 6 ) continue; |
|
|
148 |
|
|
149 thread2_state = 2; |
|
|
150 |
|
|
151 for(;;) continue; |
|
|
152 |
|
|
153 } |
|
|
154 |
|
|
155 void release_main(void) |
|
|
156 { |
|
|
157 CYG_TEST_INIT(); |
|
|
158 |
|
|
159 new_thread( entry0, 0); |
|
|
160 new_thread( entry1, 1); |
|
|
161 new_thread( entry2, 2); |
|
|
162 |
|
|
163 thread[0]->set_priority(5); |
|
|
164 thread[1]->set_priority(6); |
|
|
165 thread[2]->set_priority(7); |
|
|
166 |
|
|
167 Cyg_Scheduler::start(); |
|
|
168 |
|
|
169 CYG_TEST_FAIL_FINISH("Not reached"); |
|
|
170 } |
|
|
171 |
|
|
172 externC void |
|
|
173 cyg_start( void ) |
|
|
174 { |
|
|
175 release_main(); |
|
|
176 } |
|
2
|
177 |
|
|
178 #else // ifdef CYGFUN_KERNEL_THREADS_TIMER |
|
|
179 |
|
|
180 externC void |
|
|
181 cyg_start( void ) |
|
|
182 { |
|
|
183 CYG_TEST_INIT(); |
|
|
184 CYG_TEST_NA("Kernel threads timer disabled"); |
|
|
185 } |
|
|
186 |
|
|
187 #endif // ifdef CYGFUN_KERNEL_THREADS_TIMER |
|
0
|
188 |
|
|
189 // EOF kill.cxx |