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