|
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 |
|
|
25 // by Cygnus are Copyright (C) 1998 Cygnus Solutions. All Rights Reserved. |
|
|
26 // ------------------------------------------- |
|
|
27 // |
|
|
28 //####COPYRIGHTEND#### |
|
|
29 //========================================================================== |
|
|
30 //#####DESCRIPTIONBEGIN#### |
|
|
31 // |
|
|
32 // Author(s): nickg |
|
|
33 // Contributors: nickg |
|
|
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 |
|
|
49 #include <cyg/kernel/sched.inl> |
|
|
50 |
|
|
51 #define NTHREADS 3 |
|
|
52 |
|
|
53 #include "testaux.hxx" |
|
|
54 |
|
|
55 static Cyg_Binary_Semaphore s0, s1; |
|
|
56 |
|
|
57 volatile cyg_atomic thread0_state; |
|
|
58 volatile cyg_atomic thread1_state; |
|
|
59 volatile cyg_atomic thread2_state; |
|
|
60 |
|
|
61 static void entry0( CYG_ADDRWORD data ) |
|
|
62 { |
|
|
63 Cyg_Thread *self = Cyg_Thread::self(); |
|
|
64 |
|
|
65 thread0_state = 1; |
|
|
66 |
|
|
67 s0.wait(); |
|
|
68 |
|
|
69 thread0_state = 2; |
|
|
70 |
|
|
71 CYG_TEST_FAIL_FINISH("Thread not killed"); |
|
|
72 |
|
|
73 self->exit(); |
|
|
74 } |
|
|
75 |
|
|
76 |
|
|
77 static void entry1( CYG_ADDRWORD data ) |
|
|
78 { |
|
|
79 Cyg_Thread *self = Cyg_Thread::self(); |
|
|
80 |
|
|
81 thread1_state = 1; |
|
|
82 |
|
|
83 self->delay(1); |
|
|
84 |
|
|
85 if( thread2_state != 1 ) |
|
|
86 CYG_TEST_FAIL_FINISH("Thread2 in wrong state"); |
|
|
87 |
|
|
88 thread1_state = 2; |
|
|
89 |
|
|
90 thread[0]->kill(); |
|
|
91 |
|
|
92 thread1_state = 3; |
|
|
93 |
|
|
94 thread[2]->kill(); |
|
|
95 |
|
|
96 thread1_state = 4; |
|
|
97 |
|
|
98 self->delay(1); |
|
|
99 |
|
|
100 thread1_state = 5; |
|
|
101 thread2_state = 0; |
|
|
102 |
|
|
103 thread[2]->reinitialize(); |
|
|
104 thread[2]->resume(); |
|
|
105 |
|
|
106 self->delay(1); |
|
|
107 |
|
|
108 if( thread2_state != 1 ) |
|
|
109 CYG_TEST_FAIL_FINISH("Thread2 in wrong state"); |
|
|
110 |
|
|
111 thread1_state = 6; |
|
|
112 |
|
|
113 self->delay(1); |
|
|
114 |
|
|
115 if( thread2_state != 2 ) |
|
|
116 CYG_TEST_FAIL_FINISH("Thread2 in wrong state"); |
|
|
117 |
|
|
118 thread[2]->kill(); |
|
|
119 |
|
|
120 thread1_state = 7; |
|
|
121 |
|
|
122 CYG_TEST_PASS_FINISH("Kill OK"); |
|
|
123 |
|
|
124 Cyg_Thread::self()->exit(); |
|
|
125 } |
|
|
126 |
|
|
127 static void entry2( CYG_ADDRWORD data ) |
|
|
128 { |
|
|
129 thread2_state = 1; |
|
|
130 |
|
|
131 while( thread1_state != 6 ) continue; |
|
|
132 |
|
|
133 thread2_state = 2; |
|
|
134 |
|
|
135 for(;;) continue; |
|
|
136 |
|
|
137 } |
|
|
138 |
|
|
139 void release_main(void) |
|
|
140 { |
|
|
141 CYG_TEST_INIT(); |
|
|
142 |
|
|
143 new_thread( entry0, 0); |
|
|
144 new_thread( entry1, 1); |
|
|
145 new_thread( entry2, 2); |
|
|
146 |
|
|
147 thread[0]->set_priority(5); |
|
|
148 thread[1]->set_priority(6); |
|
|
149 thread[2]->set_priority(7); |
|
|
150 |
|
|
151 Cyg_Scheduler::start(); |
|
|
152 |
|
|
153 CYG_TEST_FAIL_FINISH("Not reached"); |
|
|
154 } |
|
|
155 |
|
|
156 externC void |
|
|
157 cyg_start( void ) |
|
|
158 { |
|
|
159 release_main(); |
|
|
160 } |
|
|
161 |
|
|
162 // EOF kill.cxx |