Mercurial > ecos
comparison packages/kernel/current/tests/clock0.cxx @ 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 // clock0.cxx | |
| 4 // | |
| 5 // Clock test 0 | |
| 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): dsm | |
| 33 // Contributors: dsm | |
| 34 // Date: 1998-02-13 | |
| 35 // Description: Tests some basic clock functions. | |
| 36 // Omissions: Doesn't test likely boundary conditions for | |
| 37 // CYGNUM_KERNEL_COUNTERS_MULTI_LIST_SIZE | |
| 38 // Real Time Clock Testing is limited | |
| 39 // Options: | |
| 40 // CYGIMP_KERNEL_COUNTERS_SINGLE_LIST | |
| 41 // CYGIMP_KERNEL_COUNTERS_MULTI_LIST | |
| 42 // CYGVAR_KERNEL_COUNTERS_CLOCK | |
| 43 // CYGNUM_KERNEL_COUNTERS_MULTI_LIST_SIZE | |
| 44 // Assumptions: This assumes we have long long support and | |
| 45 // that counters are 64 bits. | |
| 46 //####DESCRIPTIONEND#### | |
| 47 | |
| 48 #include <pkgconf/kernel.h> | |
| 49 | |
| 50 #include <cyg/kernel/clock.hxx> | |
| 51 | |
| 52 #include <cyg/infra/testcase.h> | |
| 53 | |
| 54 #include <cyg/kernel/clock.inl> | |
| 55 | |
| 56 #include "testaux.hxx" | |
| 57 | |
| 58 #ifdef CYGVAR_KERNEL_COUNTERS_CLOCK | |
| 59 | |
| 60 cyg_alarm_fn call_me; | |
| 61 | |
| 62 bool flash( void ) | |
| 63 { | |
| 64 Cyg_Counter counter0 = Cyg_Counter(); | |
| 65 Cyg_Counter counter1 = Cyg_Counter(723); | |
| 66 | |
| 67 CYG_ASSERTCLASSO( counter0, "error" ); | |
| 68 CYG_ASSERTCLASSO( counter1, "error" ); | |
| 69 | |
| 70 Cyg_Alarm alarm0 = Cyg_Alarm(&counter0, call_me, 12); | |
| 71 | |
| 72 CYG_ASSERTCLASSO( alarm0, "error" ); | |
| 73 | |
| 74 Cyg_Clock::cyg_resolution res = {1,2}; | |
| 75 | |
| 76 Cyg_Clock clock0(res); | |
| 77 | |
| 78 CYG_ASSERTCLASSO( clock0, "error" ); | |
| 79 | |
| 80 return true; | |
| 81 } | |
| 82 | |
| 83 // Testing alarms | |
| 84 // | |
| 85 // call_me is a function that will be called when an alarm is | |
| 86 // triggered. It updates a global variable called which is CHECKed | |
| 87 // explicitly to see if the approriate alarms have been called. | |
| 88 | |
| 89 cyg_uint16 called = 0x0; | |
| 90 | |
| 91 void call_me(Cyg_Alarm *alarm, CYG_ADDRWORD data) | |
| 92 { | |
| 93 called ^= data; | |
| 94 } | |
| 95 | |
| 96 void call_me2(Cyg_Alarm *alarm, CYG_ADDRWORD data) | |
| 97 { | |
| 98 call_me(alarm, data^0x10); | |
| 99 } | |
| 100 | |
| 101 | |
| 102 void clock0_main(void) | |
| 103 { | |
| 104 CYG_TEST_INIT(); | |
| 105 | |
| 106 CHECK(flash()); | |
| 107 CHECK(flash()); | |
| 108 | |
| 109 const cyg_uint32 big_number = 3333222111u; | |
| 110 Cyg_Counter counter0 = Cyg_Counter(); | |
| 111 | |
| 112 CHECK( 0 == counter0.current_value() ); | |
| 113 CHECK( 0 == counter0.current_value_lo() ); | |
| 114 CHECK( 0 == counter0.current_value_hi() ); | |
| 115 | |
| 116 counter0.tick(); | |
| 117 | |
| 118 CHECK( 1 == counter0.current_value() ); | |
| 119 CHECK( 1 == counter0.current_value_lo() ); | |
| 120 CHECK( 0 == counter0.current_value_hi() ); | |
| 121 | |
| 122 counter0.tick(6); | |
| 123 | |
| 124 CHECK( 7 == counter0.current_value() ); | |
| 125 CHECK( 7 == counter0.current_value_lo() ); | |
| 126 CHECK( 0 == counter0.current_value_hi() ); | |
| 127 | |
| 128 counter0.set_value( 0xfffffffc ); | |
| 129 | |
| 130 CHECK( 0xfffffffc == counter0.current_value() ); | |
| 131 CHECK( 0xfffffffc == counter0.current_value_lo() ); | |
| 132 CHECK( 0 == counter0.current_value_hi() ); | |
| 133 | |
| 134 counter0.tick( 0x13 ); // Overflows 32 bits | |
| 135 | |
| 136 CHECK( 0x10000000fULL == counter0.current_value() ); | |
| 137 CHECK( 0xf == counter0.current_value_lo() ); | |
| 138 CHECK( 0x1 == counter0.current_value_hi() ); | |
| 139 | |
| 140 | |
| 141 Cyg_Counter counter1 = Cyg_Counter(big_number); | |
| 142 | |
| 143 CHECK( 0 == counter1.current_value() ); | |
| 144 CHECK( 0 == counter1.current_value_lo() ); | |
| 145 CHECK( 0 == counter1.current_value_hi() ); | |
| 146 | |
| 147 counter1.tick(2); | |
| 148 | |
| 149 CHECK( 2ll*big_number == counter1.current_value() ); | |
| 150 CHECK( ((2ll*big_number) & 0xffffffff) == | |
| 151 counter1.current_value_lo() ); | |
| 152 CHECK( ((2ll*big_number) >> 32) == counter1.current_value_hi() ); | |
| 153 | |
| 154 counter1.tick(); | |
| 155 | |
| 156 CHECK( 3ll*big_number == counter1.current_value() ); | |
| 157 CHECK( ((3ll*big_number) & 0xffffffff) == | |
| 158 counter1.current_value_lo() ); | |
| 159 CHECK( ((3ll*big_number) >> 32) == counter1.current_value_hi() ); | |
| 160 | |
| 161 counter1.tick(); | |
| 162 | |
| 163 CHECK( 4ll*big_number == counter1.current_value() ); | |
| 164 CHECK( ((4ll*big_number) & 0xffffffff) == | |
| 165 counter1.current_value_lo() ); | |
| 166 CHECK( ((4ll*big_number) >> 32) == counter1.current_value_hi() ); | |
| 167 | |
| 168 counter1.set_value(1222333444555ll); | |
| 169 CHECK( 1222333444555ll == counter1.current_value() ); | |
| 170 | |
| 171 counter0.set_value(11); | |
| 172 CHECK( 11 == counter0.current_value() ); | |
| 173 | |
| 174 // the call_me functions cause the "called" bits to toggle | |
| 175 // CHECKing the value of called TEST_CHECKs the parity of # of calls | |
| 176 // made by each alarm. | |
| 177 | |
| 178 Cyg_Alarm alarm0 = Cyg_Alarm(&counter0, call_me, 0x1); | |
| 179 Cyg_Alarm alarm1 = Cyg_Alarm(&counter0, call_me, 0x2); | |
| 180 Cyg_Alarm alarm2 = Cyg_Alarm(&counter0, call_me2, 0x4); | |
| 181 | |
| 182 CHECK( 0x00 == called ); | |
| 183 alarm0.initialize(12,3); | |
| 184 alarm2.initialize(21,2); | |
| 185 CHECK( 0x00 == called ); | |
| 186 | |
| 187 counter0.tick(); // 12 a0 | |
| 188 CHECK( 0x01 == called ); | |
| 189 | |
| 190 alarm1.initialize(13,0); | |
| 191 counter0.tick(); // 13 a1 | |
| 192 CHECK( 0x03 == called ); | |
| 193 | |
| 194 alarm1.initialize(17,0); | |
| 195 counter0.tick(); // 14 | |
| 196 CHECK( 0x03 == called ); | |
| 197 | |
| 198 counter0.tick(); // 15 a0 | |
| 199 CHECK( 0x02 == called ); | |
| 200 | |
| 201 counter0.tick(2); // 17 a1 | |
| 202 CHECK( 0x00 == called ); | |
| 203 | |
| 204 counter0.tick(); // 18 a0 | |
| 205 CHECK( 0x01 == called ); | |
| 206 | |
| 207 counter0.tick(3); // 21 a0 a2 | |
| 208 CHECK( 0x14 == called ); | |
| 209 | |
| 210 counter0.tick(2); // 23 a2 | |
| 211 CHECK( 0x00 == called ); | |
| 212 | |
| 213 alarm2.disable(); | |
| 214 | |
| 215 counter0.tick(2); // 25 a0(24) | |
| 216 CHECK( 0x01 == called ); | |
| 217 | |
| 218 alarm2.enable(); // a2 (enabled at 25) | |
| 219 CHECK( 0x15 == called ); | |
| 220 | |
| 221 counter0.tick(); // 26 | |
| 222 CHECK( 0x15 == called ); | |
| 223 | |
| 224 counter0.tick(2); // 28 a0(27) a2(27) | |
| 225 CHECK( 0x00 == called ); | |
| 226 | |
| 227 counter0.tick(3); // 31 a0(30) a2(29 31) | |
| 228 CHECK( 0x01 == called ); | |
| 229 | |
| 230 Cyg_Clock::cyg_resolution res0; | |
| 231 | |
| 232 res0.dividend = 100; | |
| 233 res0.divisor = 3; | |
| 234 | |
| 235 Cyg_Clock::cyg_resolution res1; | |
| 236 | |
| 237 Cyg_Clock clock0 = Cyg_Clock(res0); | |
| 238 | |
| 239 res1 = clock0.get_resolution(); | |
| 240 CHECK( res0.dividend == res1.dividend ); | |
| 241 CHECK( res0.divisor == res1.divisor ); | |
| 242 | |
| 243 res1.dividend = 12; | |
| 244 res1.divisor = 25; | |
| 245 | |
| 246 clock0.set_resolution(res1); | |
| 247 res0 = clock0.get_resolution(); | |
| 248 CHECK( res0.dividend == res1.dividend ); | |
| 249 CHECK( res0.divisor == res1.divisor ); | |
| 250 | |
| 251 res0 = Cyg_Clock::real_time_clock->get_resolution(); | |
| 252 | |
| 253 CYG_TEST_PASS_FINISH("Clock 0 OK"); | |
| 254 } | |
| 255 | |
| 256 externC void | |
| 257 cyg_start( void ) | |
| 258 { | |
| 259 clock0_main(); | |
| 260 } | |
| 261 | |
| 262 #else // def CYGVAR_KERNEL_COUNTERS_CLOCK | |
| 263 | |
| 264 externC void | |
| 265 cyg_start( void ) | |
| 266 { | |
| 267 CYG_TEST_INIT(); | |
| 268 CYG_TEST_PASS_FINISH( "N/A: Kernel real-time clock disabled"); | |
| 269 } | |
| 270 | |
| 271 #endif // def CYGVAR_KERNEL_COUNTERS_CLOCK | |
| 272 // EOF clock0.cxx |
