comparison packages/kernel/current/tests/klock.c @ 132:0ae0bc38e387 ecos-sw-2000-10-31

Merge from eCos master repository on 2000-10-31-00:30:36-GMT
author jlarmour
date Tue, 31 Oct 2000 20:53:09 +0000
parents 0ec04793409a
children 51b34619b677
comparison
equal deleted inserted replaced
131:8461114e4f19 132:0ae0bc38e387
1 /*================================================================= 1 /*=================================================================
2 // 2 //
3 // kthread1.c 3 // klock.c
4 // 4 //
5 // Kernel C API Thread test 1 5 // Kernel lock test
6 // 6 //
7 //========================================================================== 7 //==========================================================================
8 //####COPYRIGHTBEGIN#### 8 //####COPYRIGHTBEGIN####
9 // 9 //
10 // ------------------------------------------- 10 // -------------------------------------------
45 45
46 //========================================================================== 46 //==========================================================================
47 47
48 #ifdef CYGFUN_KERNEL_API_C 48 #ifdef CYGFUN_KERNEL_API_C
49 49
50 #if (CYGINT_KERNEL_SCHEDULER_UNIQUE_PRIORITIES == 0)
51
50 //========================================================================== 52 //==========================================================================
51 53
52 #include "testaux.h" 54 #include "testaux.h"
53 55
54 #include <cyg/hal/hal_arch.h> // for CYGNUM_HAL_STACK_SIZE_TYPICAL 56 #include <cyg/hal/hal_arch.h> // for CYGNUM_HAL_STACK_SIZE_TYPICAL
81 83
82 //========================================================================== 84 //==========================================================================
83 85
84 static void entry0( cyg_addrword_t data ) 86 static void entry0( cyg_addrword_t data )
85 { 87 {
86 void *mbret;
87
88 CHECK( 222 == (int)data ); 88 CHECK( 222 == (int)data );
89 89
90 // Do everything with the scheduler locked. 90 // Do everything with the scheduler locked.
91 cyg_scheduler_lock(); 91 cyg_scheduler_lock();
92 92
98 98
99 // Get thread 2 running. 99 // Get thread 2 running.
100 cyg_thread_resume(pt1); 100 cyg_thread_resume(pt1);
101 thread0_state = 2; 101 thread0_state = 2;
102 102
103 #ifdef CYGMFN_KERNEL_SYNCH_CONDVAR_TIMED_WAIT
103 cyg_cond_wait( &cv ); 104 cyg_cond_wait( &cv );
104 thread0_state = 3; 105 thread0_state = 3;
105 106
106 while( thread1_state < 2 ) cyg_thread_yield(); 107 while( thread1_state < 2 ) cyg_thread_yield();
107 108
108 cyg_cond_broadcast( &cv ); 109 cyg_cond_broadcast( &cv );
109 thread0_state = 4; 110 thread0_state = 4;
111 #endif
110 112
111 cyg_mutex_unlock( &mx ); 113 cyg_mutex_unlock( &mx );
112 thread0_state = 5; 114 thread0_state = 5;
113 115
116
114 // -------------------------------------------------- 117 // --------------------------------------------------
115 // Semaphore test 118 // Semaphore test
116 119
117 cyg_semaphore_wait( &sem ); 120 cyg_semaphore_wait( &sem );
118 thread0_state = 6; 121 thread0_state = 6;
132 thread0_state = 9; 135 thread0_state = 9;
133 136
134 // -------------------------------------------------- 137 // --------------------------------------------------
135 // Message box test 138 // Message box test
136 139
137 mbret = cyg_mbox_get( mbh ); 140 #ifdef CYGMFN_KERNEL_SYNCH_MBOXT_PUT_CAN_WAIT
138 CYG_TEST_CHECK( mbret == (void *)0xAAAAAAAA , "bad result from cyg_mbox_timed_get()"); 141 {
139 thread0_state = 10; 142 void *mbret;
140 143
141 cyg_mbox_put( mbh, (void *)0xBBBBBBBB ); 144 mbret = cyg_mbox_get( mbh );
142 thread0_state = 11; 145 CYG_TEST_CHECK( mbret == (void *)0xAAAAAAAA , "bad result from cyg_mbox_timed_get()");
143 146 thread0_state = 10;
147
148 cyg_mbox_put( mbh, (void *)0xBBBBBBBB );
149 thread0_state = 11;
150 }
151 #endif
144 // -------------------------------------------------- 152 // --------------------------------------------------
145 153
146 thread0_state = 999; 154 thread0_state = 999;
147 155
148 cyg_thread_yield(); 156 cyg_thread_yield();
149 cyg_thread_yield(); 157 cyg_thread_yield();
150 cyg_thread_yield(); 158 cyg_thread_yield();
151 159
152 CYG_TEST_CHECK( thread0_state == 999, "thread 0 not in exit state"); 160 CYG_TEST_CHECK( thread0_state == 999, "thread 0 not in exit state");
153 CYG_TEST_CHECK( thread1_state == 999, "thread 1 not in exit state"); 161 CYG_TEST_CHECK( thread1_state == 999, "thread 1 not in exit state");
154 CYG_TEST_PASS_FINISH("Kernel C API Thread 1 OK"); 162 CYG_TEST_PASS_FINISH("Kernel lock test OK");
155 } 163 }
156 164
157 //========================================================================== 165 //==========================================================================
158 166
159 static void entry1( cyg_addrword_t data ) 167 static void entry1( cyg_addrword_t data )
160 { 168 {
161 cyg_bool res; 169 cyg_bool res;
162 void *mbret;
163 170
164 CHECK( 333 == (int)data ); 171 CHECK( 333 == (int)data );
165 172
166 // Do everything with the scheduler locked. 173 // Do everything with the scheduler locked.
167 cyg_scheduler_lock(); 174 cyg_scheduler_lock();
168 175
169 // -------------------------------------------------- 176 // --------------------------------------------------
170 // Mutex test 177 // Mutex test
171 178 #ifdef CYGMFN_KERNEL_SYNCH_CONDVAR_TIMED_WAIT
172 cyg_mutex_lock( &mx ); 179 cyg_mutex_lock( &mx );
173 thread1_state = 1; 180 thread1_state = 1;
174 181
175 while( thread0_state < 2 ) cyg_thread_yield(); 182 while( thread0_state < 2 ) cyg_thread_yield();
176 183
181 CYG_TEST_CHECK( res , "FALSE result from cyg_cond_timed_wait()" ); 188 CYG_TEST_CHECK( res , "FALSE result from cyg_cond_timed_wait()" );
182 thread1_state = 3; 189 thread1_state = 3;
183 190
184 cyg_mutex_unlock( &mx ); 191 cyg_mutex_unlock( &mx );
185 thread1_state = 4; 192 thread1_state = 4;
193 #endif
186 194
187 // -------------------------------------------------- 195 // --------------------------------------------------
188 // Semaphore test 196 // Semaphore test
189 197
190 while( thread0_state < 5 ) cyg_thread_yield(); 198 while( thread0_state < 5 ) cyg_thread_yield();
209 cyg_current_time()+10 ); 217 cyg_current_time()+10 );
210 thread1_state = 9; 218 thread1_state = 9;
211 219
212 // -------------------------------------------------- 220 // --------------------------------------------------
213 // Message box test 221 // Message box test
214 222 #ifdef CYGMFN_KERNEL_SYNCH_MBOXT_PUT_CAN_WAIT
215 cyg_mbox_timed_put( mbh, (void *)0xAAAAAAAA, cyg_current_time()+10 ); 223 {
216 thread1_state = 10; 224 void *mbret;
217 225 cyg_mbox_timed_put( mbh, (void *)0xAAAAAAAA, cyg_current_time()+10 );
218 mbret = cyg_mbox_timed_get( mbh, cyg_current_time()+10); 226 thread1_state = 10;
219 CYG_TEST_CHECK( mbret == (void *)0xBBBBBBBB , "bad result from cyg_mbox_timed_get()"); 227
220 thread1_state = 9; 228 mbret = cyg_mbox_timed_get( mbh, cyg_current_time()+10);
221 229 CYG_TEST_CHECK( mbret == (void *)0xBBBBBBBB , "bad result from cyg_mbox_timed_get()");
230 thread1_state = 9;
231 }
232 #endif
222 // -------------------------------------------------- 233 // --------------------------------------------------
223 234
224 thread1_state = 999; 235 thread1_state = 999;
225 cyg_thread_exit(); 236 cyg_thread_exit();
226 } 237 }
259 kthread1_main(); 270 kthread1_main();
260 } 271 }
261 272
262 //========================================================================== 273 //==========================================================================
263 274
275 #else /* CYGINT_KERNEL_SCHEDULER_UNIQUE_PRIORITIES == 0 */
276 # define NA_MSG "Schedule has unique priorities"
277 #endif
278
264 #else /* def CYGFUN_KERNEL_API_C */ 279 #else /* def CYGFUN_KERNEL_API_C */
265 280 # define NA_MSG "Kernel C API layer disabled"
266 //========================================================================== 281 #endif
267 282
283 #ifdef NA_MSG
268 externC void 284 externC void
269 cyg_start( void ) 285 cyg_start( void )
270 { 286 {
271 CYG_TEST_INIT(); 287 CYG_TEST_INIT();
272 CYG_TEST_NA("Kernel C API layer disabled"); 288 CYG_TEST_NA(NA_MSG);
273 } 289 }
274 290 #endif
275 //========================================================================== 291
276 292 //==========================================================================
277 #endif /* def CYGFUN_KERNEL_API_C */ 293 /* EOF klock.c */
278
279 //==========================================================================
280 /* EOF kthread1.c */