Mercurial > flash_v2
comparison packages/kernel/current/tests/kflag1.c @ 0:3111d98ba7b3 ecos-v1_1-release
Initial commit of eCos version 1.1
| author | jlarmour |
|---|---|
| date | Tue, 11 May 1999 11:16:07 +0000 |
| parents | |
| children | 443894e2e912 |
comparison
equal
deleted
inserted
replaced
| -1:000000000000 | 0:3111d98ba7b3 |
|---|---|
| 1 /*========================================================================== | |
| 2 // | |
| 3 // kflag1.cxx | |
| 4 // | |
| 5 // Kernel C API Flag test 1 | |
| 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: dsm | |
| 33 // Contributors: hmt | |
| 34 // Date: 1998-10-19 | |
| 35 // Description: Tests basic flag functionality. | |
| 36 //####DESCRIPTIONEND#### | |
| 37 */ | |
| 38 | |
| 39 #include <cyg/kernel/kapi.h> | |
| 40 | |
| 41 #include <cyg/infra/testcase.h> | |
| 42 | |
| 43 #ifdef CYGFUN_KERNEL_API_C | |
| 44 | |
| 45 #include "testaux.h" | |
| 46 | |
| 47 | |
| 48 #define NTHREADS 3 | |
| 49 #define STACKSIZE 4096 | |
| 50 | |
| 51 static cyg_handle_t thread[NTHREADS]; | |
| 52 | |
| 53 static cyg_thread thread_obj[NTHREADS]; | |
| 54 static char stack[NTHREADS][STACKSIZE]; | |
| 55 | |
| 56 static cyg_flag_t f0, f1; | |
| 57 #ifdef CYGFUN_KERNEL_THREADS_TIMER | |
| 58 static cyg_flag_t f2; | |
| 59 #endif | |
| 60 | |
| 61 static volatile cyg_ucount8 q = 0; | |
| 62 | |
| 63 static void entry0( cyg_addrword_t data ) | |
| 64 { | |
| 65 CYG_TEST_INFO("Testing cyg_flag_setbits() and cyg_flag_maskbits()"); | |
| 66 CYG_TEST_CHECK(0==cyg_flag_peek( &f0 ), "flag not initialized properly"); | |
| 67 cyg_flag_setbits( &f0, 0x1); | |
| 68 CYG_TEST_CHECK(1==cyg_flag_peek( &f0 ), "setbits"); | |
| 69 cyg_flag_setbits( &f0, 0x3); | |
| 70 CYG_TEST_CHECK(3==cyg_flag_peek( &f0 ), "setbits"); | |
| 71 cyg_flag_maskbits( &f0, ~0x5); | |
| 72 CYG_TEST_CHECK(2==cyg_flag_peek( &f0 ), "maskbits"); | |
| 73 cyg_flag_setbits( &f0, ~0 ); | |
| 74 CYG_TEST_CHECK(~0u==cyg_flag_peek( &f0 ), "setbits all set"); | |
| 75 cyg_flag_maskbits( &f0, 0 ); | |
| 76 CYG_TEST_CHECK(0==cyg_flag_peek( &f0 ), "maskbits all clear"); | |
| 77 CYG_TEST_CHECK(0==q++, "bad synchronization"); | |
| 78 | |
| 79 CYG_TEST_INFO("Testing cyg_flag_wait()"); | |
| 80 cyg_flag_setbits( &f1, 0x4); | |
| 81 CYG_TEST_CHECK(0x4==cyg_flag_peek( &f1 ), "setbits"); | |
| 82 CYG_TEST_CHECK(1==q++, "bad synchronization"); | |
| 83 cyg_flag_setbits( &f1, 0x18); // wake t1 | |
| 84 cyg_flag_wait( &f1, 0x11, CYG_FLAG_WAITMODE_AND | CYG_FLAG_WAITMODE_CLR); | |
| 85 CYG_TEST_CHECK(0==cyg_flag_peek( &f1 ), "flag value wrong"); | |
| 86 CYG_TEST_CHECK(3==q++, "bad synchronization"); | |
| 87 cyg_flag_setbits( &f0, 0x2); // wake t1 | |
| 88 cyg_flag_wait( &f1, 0x10, CYG_FLAG_WAITMODE_AND ); | |
| 89 cyg_flag_setbits( &f0, 0x1); // wake t1 | |
| 90 | |
| 91 cyg_flag_wait( &f1, 0x11, CYG_FLAG_WAITMODE_AND | CYG_FLAG_WAITMODE_CLR); | |
| 92 | |
| 93 #ifdef CYGFUN_KERNEL_THREADS_TIMER | |
| 94 cyg_flag_wait( &f2, 0x2, CYG_FLAG_WAITMODE_OR); | |
| 95 CYG_TEST_CHECK(20==q,"bad synchronization"); | |
| 96 cyg_flag_timed_wait( &f2, 0x10, CYG_FLAG_WAITMODE_AND, | |
| 97 cyg_current_time()+20); | |
| 98 CYG_TEST_CHECK(21==q++,"bad synchronization"); | |
| 99 #endif | |
| 100 cyg_flag_wait( &f0, 1, CYG_FLAG_WAITMODE_OR); | |
| 101 | |
| 102 CYG_TEST_FAIL_FINISH("Not reached"); | |
| 103 } | |
| 104 | |
| 105 static void entry1( cyg_addrword_t data ) | |
| 106 { | |
| 107 cyg_flag_wait( &f1, 0xc, CYG_FLAG_WAITMODE_AND); | |
| 108 CYG_TEST_CHECK(2==q++, "bad synchronization"); | |
| 109 CYG_TEST_CHECK(0x1c==cyg_flag_peek( &f1 ), "flag value wrong"); | |
| 110 cyg_flag_setbits( &f1, 0x1); // wake t0 | |
| 111 cyg_flag_wait( &f0, 0x3, CYG_FLAG_WAITMODE_OR); | |
| 112 CYG_TEST_CHECK(4==q++, "bad synchronization"); | |
| 113 CYG_TEST_CHECK(2==cyg_flag_peek( &f0 ), "flag value wrong"); | |
| 114 | |
| 115 cyg_flag_setbits( &f1, 0xf0); // wake t0,t2 | |
| 116 cyg_flag_wait( &f0, 0x5, CYG_FLAG_WAITMODE_AND | CYG_FLAG_WAITMODE_CLR); | |
| 117 CYG_TEST_CHECK(0==cyg_flag_peek( &f0 ), "flag value wrong"); | |
| 118 CYG_TEST_CHECK(0xf0==cyg_flag_peek( &f1 ), "flag value wrong"); | |
| 119 CYG_TEST_CHECK(5==q++, "bad synchronization"); | |
| 120 cyg_flag_maskbits( &f1, 0 ); | |
| 121 CYG_TEST_CHECK(0==cyg_flag_peek( &f1 ), "flag value wrong"); | |
| 122 | |
| 123 CYG_TEST_INFO("Testing cyg_flag_poll()"); | |
| 124 cyg_flag_setbits( &f0, 0x55); | |
| 125 CYG_TEST_CHECK(0x55==cyg_flag_peek( &f0 ), "flag value wrong"); | |
| 126 CYG_TEST_CHECK(0x55==cyg_flag_poll( &f0, 0x3, CYG_FLAG_WAITMODE_OR),"bad poll() return"); | |
| 127 CYG_TEST_CHECK(0==cyg_flag_poll( &f0, 0xf, CYG_FLAG_WAITMODE_AND),"poll()"); | |
| 128 CYG_TEST_CHECK(0==cyg_flag_poll( &f0, 0xa, CYG_FLAG_WAITMODE_OR),"poll()"); | |
| 129 CYG_TEST_CHECK(0x55==cyg_flag_peek( &f0 ), "flag value wrong"); | |
| 130 CYG_TEST_CHECK(0x55==cyg_flag_poll( &f0, 0xf, CYG_FLAG_WAITMODE_OR | CYG_FLAG_WAITMODE_CLR),"poll"); | |
| 131 CYG_TEST_CHECK(0x0==cyg_flag_peek( &f0 ), "flag value wrong"); | |
| 132 cyg_flag_setbits( &f0, 0x50); | |
| 133 CYG_TEST_CHECK(0x50==cyg_flag_poll( &f0, 0x10, CYG_FLAG_WAITMODE_AND | CYG_FLAG_WAITMODE_CLR),"poll"); | |
| 134 CYG_TEST_CHECK(0x0==cyg_flag_peek( &f0 ), "flag value wrong"); | |
| 135 | |
| 136 CYG_TEST_INFO("Testing cyg_flag_waiting()"); | |
| 137 cyg_flag_maskbits( &f0, 0 ); | |
| 138 CYG_TEST_CHECK(!cyg_flag_waiting( &f0 ), "waiting()"); | |
| 139 | |
| 140 #ifdef CYGFUN_KERNEL_THREADS_TIMER | |
| 141 cyg_thread_delay( 10 ); // allow other threads to reach wait on f1 | |
| 142 CYG_TEST_CHECK(cyg_flag_waiting( &f1 ), "waiting() not true"); | |
| 143 cyg_flag_setbits( &f1, ~0 ); // wake one of t0,t2 | |
| 144 CYG_TEST_CHECK(cyg_flag_waiting( &f1 ),"waiting() not true"); | |
| 145 #else | |
| 146 cyg_flag_setbits( &f1, 0x11); // wake one of t0,t2 | |
| 147 #endif | |
| 148 cyg_flag_setbits( &f1, 0x11); // wake other of t0,t2 | |
| 149 CYG_TEST_CHECK(!cyg_flag_waiting( &f1 ),"waiting not false"); | |
| 150 CYG_TEST_CHECK(0x0==cyg_flag_peek( &f1 ), "flag value wrong"); | |
| 151 | |
| 152 #ifdef CYGFUN_KERNEL_THREADS_TIMER | |
| 153 CYG_TEST_INFO("Testing cyg_flag_timed_wait()"); | |
| 154 q=20; | |
| 155 cyg_flag_setbits( &f2, 0x2); // synchronize with t0,t2 | |
| 156 CYG_TEST_CHECK(20==q,"bad synchronization"); | |
| 157 cyg_flag_timed_wait( &f2, 0x20, CYG_FLAG_WAITMODE_AND, | |
| 158 cyg_current_time()+10); | |
| 159 CYG_TEST_CHECK(22==q++,"bad synchronization"); | |
| 160 #endif | |
| 161 | |
| 162 CYG_TEST_PASS_FINISH("Kernel C API Flag 1 OK"); | |
| 163 } | |
| 164 | |
| 165 static void entry2( cyg_addrword_t data ) | |
| 166 { | |
| 167 cyg_flag_wait( &f1, 0x60, CYG_FLAG_WAITMODE_OR); | |
| 168 cyg_flag_setbits( &f0, 0x4); | |
| 169 | |
| 170 cyg_flag_wait( &f1, 0x11, CYG_FLAG_WAITMODE_AND | CYG_FLAG_WAITMODE_CLR); | |
| 171 #ifdef CYGFUN_KERNEL_THREADS_TIMER | |
| 172 cyg_flag_wait( &f2, 0x2, CYG_FLAG_WAITMODE_OR); | |
| 173 CYG_TEST_CHECK(20==q,"bad synchronization"); | |
| 174 CYG_TEST_CHECK(0==cyg_flag_timed_wait( &f2, 0x40, CYG_FLAG_WAITMODE_AND, | |
| 175 cyg_current_time()+2), | |
| 176 "timed wait() wrong"); | |
| 177 CYG_TEST_CHECK(20==q++,"bad synchronization"); | |
| 178 // Now wake t0 before it times out | |
| 179 cyg_flag_setbits( &f2, 0x10); | |
| 180 #endif | |
| 181 cyg_flag_wait( &f0, 1, CYG_FLAG_WAITMODE_OR); | |
| 182 | |
| 183 CYG_TEST_FAIL_FINISH("Not reached"); | |
| 184 } | |
| 185 | |
| 186 void kflag1_main( void ) | |
| 187 { | |
| 188 CYG_TEST_INIT(); | |
| 189 | |
| 190 cyg_flag_init( &f0 ); | |
| 191 cyg_flag_init( &f1 ); | |
| 192 #ifdef CYGFUN_KERNEL_THREADS_TIMER | |
| 193 cyg_flag_init( &f2 ); | |
| 194 #endif | |
| 195 | |
| 196 cyg_thread_create( 1, entry0 , (cyg_addrword_t)0, "kflag1-0", | |
| 197 (void *)stack[0], STACKSIZE, &thread[0], &thread_obj[0]); | |
| 198 cyg_thread_resume(thread[0]); | |
| 199 | |
| 200 cyg_thread_create( 1, entry1 , (cyg_addrword_t)1, "kflag1-1", | |
| 201 (void *)stack[1], STACKSIZE, &thread[1], &thread_obj[1]); | |
| 202 cyg_thread_resume(thread[1]); | |
| 203 | |
| 204 cyg_thread_create( 1, entry2 , (cyg_addrword_t)2, "kflag1-2", | |
| 205 (void *)stack[2], STACKSIZE, &thread[2], &thread_obj[2]); | |
| 206 cyg_thread_resume(thread[2]); | |
| 207 | |
| 208 cyg_scheduler_start(); | |
| 209 | |
| 210 CYG_TEST_FAIL_FINISH("Not reached"); | |
| 211 } | |
| 212 | |
| 213 externC void | |
| 214 cyg_start( void ) | |
| 215 { | |
| 216 kflag1_main(); | |
| 217 } | |
| 218 | |
| 219 #else /* def CYGFUN_KERNEL_API_C */ | |
| 220 externC void | |
| 221 cyg_start( void ) | |
| 222 { | |
| 223 CYG_TEST_INIT(); | |
| 224 CYG_TEST_PASS_FINISH("Kernel C API layer disabled"); | |
| 225 } | |
| 226 #endif /* def CYGFUN_KERNEL_API_C */ | |
| 227 | |
| 228 // EOF flag1.cxx |
