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