Changeset 80665 in vbox for trunk/src/VBox/Runtime/testcase
- Timestamp:
- Sep 9, 2019 10:43:23 AM (5 years ago)
- Location:
- trunk/src/VBox/Runtime/testcase
- Files:
-
- 1 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/testcase/Makefile.kmk
r80585 r80665 141 141 tstTime-4 \ 142 142 tstTimer \ 143 tst TimerLR \143 tstRTTimerLR \ 144 144 tstRTTimeSpec \ 145 145 tstRTUdp-1 \ … … 698 698 tstTimer_SOURCES = tstTimer.cpp 699 699 700 tst TimerLR_TEMPLATE = VBOXR3TSTEXE701 tst TimerLR_SOURCES = tstTimerLR.cpp700 tstRTTimerLR_TEMPLATE = VBOXR3TSTEXE 701 tstRTTimerLR_SOURCES = tstRTTimerLR.cpp 702 702 703 703 tstRTTimeSpec_TEMPLATE = VBOXR3TSTEXE -
trunk/src/VBox/Runtime/testcase/tstRTTimerLR.cpp
r80664 r80665 30 30 *********************************************************************************************************************************/ 31 31 #include <iprt/timer.h> 32 #include <iprt/time.h> 33 #include <iprt/thread.h> 34 #include <iprt/initterm.h> 32 33 #include <iprt/errcore.h> 35 34 #include <iprt/message.h> 36 35 #include <iprt/stream.h> 37 #include <iprt/errcore.h> 38 36 #include <iprt/test.h> 37 #include <iprt/thread.h> 38 #include <iprt/time.h> 39 39 40 40 … … 46 46 static volatile uint64_t gu64Max; 47 47 static volatile uint64_t gu64Prev; 48 48 49 49 50 static DECLCALLBACK(void) TimerLRCallback(RTTIMERLR hTimerLR, void *pvUser, uint64_t iTick) … … 71 72 * Init runtime 72 73 */ 73 unsigned cErrors = 0;74 int rc = RTR3InitExeNoArguments(0);75 if ( RT_FAILURE(rc))76 return RTMsgInitFailure(rc);74 RTTEST hTest; 75 RTEXITCODE rcExit = RTTestInitAndCreate("tstRTTimerLR", &hTest); 76 if (rcExit != RTEXITCODE_SUCCESS) 77 return rcExit; 77 78 78 79 /* 79 80 * Check that the clock is reliable. 80 81 */ 81 RT Printf("tstTimer: TESTING - RTTimeNanoTS() for 2sec\n");82 RTTestSub(hTest, "RTTimeNanoTS() for 2sec"); 82 83 uint64_t uTSMillies = RTTimeMilliTS(); 83 84 uint64_t uTSBegin = RTTimeNanoTS(); … … 90 91 uint64_t uTS = RTTimeNanoTS(); 91 92 if (uTS < uTSLast) 92 { 93 RTPrintf("tstTimer: FAILURE - RTTimeNanoTS() is unreliable. uTS=%RU64 uTSLast=%RU64\n", uTS, uTSLast); 94 cErrors++; 95 } 96 if (++cIterations > (2*1000*1000*1000)) 97 { 98 RTPrintf("tstTimer: FAILURE - RTTimeNanoTS() is unreliable. cIterations=%RU64 uTS=%RU64 uTSBegin=%RU64\n", cIterations, uTS, uTSBegin); 99 return 1; 93 RTTestFailed(hTest, "RTTimeNanoTS() is unreliable. uTS=%RU64 uTSLast=%RU64", uTS, uTSLast); 94 if (++cIterations > 2*1000*1000*1000) 95 { 96 RTTestFailed(hTest, "RTTimeNanoTS() is unreliable. cIterations=%RU64 uTS=%RU64 uTSBegin=%RU64", 97 cIterations, uTS, uTSBegin); 98 return RTTestSummaryAndDestroy(hTest); 100 99 } 101 100 uTSLast = uTS; … … 104 103 uTSMillies = RTTimeMilliTS() - uTSMillies; 105 104 if (uTSMillies >= 2500 || uTSMillies <= 1500) 106 { 107 RTPrintf("tstTimer: FAILURE - uTSMillies=%RI64 uTSBegin=%RU64 uTSLast=%RU64 uTSDiff=%RU64\n", 108 uTSMillies, uTSBegin, uTSLast, uTSDiff); 109 cErrors++; 110 } 111 if (!cErrors) 112 RTPrintf("tstTimer: OK - RTTimeNanoTS()\n"); 105 RTTestFailed(hTest, "uTSMillies=%RI64 uTSBegin=%RU64 uTSLast=%RU64 uTSDiff=%RU64", 106 uTSMillies, uTSBegin, uTSLast, uTSDiff); 113 107 114 108 /* … … 128 122 }; 129 123 124 int rc; 130 125 unsigned i = 0; 131 126 for (i = 0; i < RT_ELEMENTS(aTests); i++) … … 134 129 //aTests[i].cUpper = (aTests[i].uMilliesWait + aTests[i].uMilliesWait / 10) / aTests[i].uMilliesInterval; 135 130 136 RTPrintf("\n" 137 "tstTimer: TESTING - %d ms interval, %d ms wait, expects %d-%d ticks.\n", 138 aTests[i].uMilliesInterval, aTests[i].uMilliesWait, aTests[i].cLower, aTests[i].cUpper); 131 RTTestSubF(hTest, "%d ms interval, %d ms wait, expects %d-%d ticks", 132 aTests[i].uMilliesInterval, aTests[i].uMilliesWait, aTests[i].cLower, aTests[i].cUpper); 139 133 140 134 /* … … 149 143 if (RT_FAILURE(rc)) 150 144 { 151 RTPrintf("RTTimerLRCreateEX(,%u*1M,,,) -> %d\n", aTests[i].uMilliesInterval, rc); 152 cErrors++; 145 RTTestFailed(hTest, "RTTimerLRCreateEX(,%u*1M,,,) -> %Rrc", aTests[i].uMilliesInterval, rc); 153 146 continue; 154 147 } … … 160 153 rc = RTTimerLRStart(hTimerLR, 0); 161 154 if (RT_FAILURE(rc)) 162 { 163 RTPrintf("tstTimer: FAILURE - RTTimerLRStart() -> %Rrc\n", rc); 164 cErrors++; 165 } 155 RTTestFailed(hTest, "RTTimerLRStart() -> %Rrc", rc); 166 156 167 157 while (RTTimeNanoTS() - uTSBegin < (uint64_t)aTests[i].uMilliesWait * 1000000) 168 /* nothing */;158 RTThreadSleep(1); 169 159 170 160 /* don't stop it, destroy it because there are potential races in destroying an active timer. */ 171 161 rc = RTTimerLRDestroy(hTimerLR); 172 162 if (RT_FAILURE(rc)) 173 { 174 RTPrintf("tstTimer: FAILURE - RTTimerLRDestroy() -> %d gcTicks=%d\n", rc, gcTicks); 175 cErrors++; 176 } 163 RTTestFailed(hTest, "RTTimerLRDestroy() -> %Rrc gcTicks=%d", rc, gcTicks); 177 164 178 165 uint64_t uTSEnd = RTTimeNanoTS(); 179 166 uTSDiff = uTSEnd - uTSBegin; 180 RTPrintf("uTS=%RI64 (%RU64 - %RU64)\n", uTSDiff, uTSBegin, uTSEnd); 167 RTTestPrintf(hTest, RTTESTLVL_ALWAYS, "uTS=%'RI64 (%'RU64 - %'RU64) gcTicks=%u min=%'RU64 max=%'RU64\n", 168 uTSDiff, uTSBegin, uTSEnd, gcTicks, gu64Min, gu64Max); 181 169 182 170 /* Check that it really stopped. */ … … 185 173 if (gcTicks != cTicks) 186 174 { 187 RTPrintf("tstTimer: FAILURE - RTTimerLRDestroy() didn't really stop the timer! gcTicks=%d cTicks=%d\n", gcTicks, cTicks); 188 cErrors++; 175 RTTestFailed(hTest, "RTTimerLRDestroy() didn't really stop the timer! gcTicks=%d cTicks=%d", gcTicks, cTicks); 189 176 continue; 190 177 } … … 194 181 */ 195 182 if (gcTicks < aTests[i].cLower) 196 { 197 RTPrintf("tstTimer: FAILURE - Too few ticks gcTicks=%d (expected %d-%d)", gcTicks, aTests[i].cUpper, aTests[i].cLower); 198 cErrors++; 199 } 183 RTTestFailed(hTest, "Too few ticks gcTicks=%d (expected %d-%d)", gcTicks, aTests[i].cUpper, aTests[i].cLower); 200 184 else if (gcTicks > aTests[i].cUpper) 201 { 202 RTPrintf("tstTimer: FAILURE - Too many ticks gcTicks=%d (expected %d-%d)", gcTicks, aTests[i].cUpper, aTests[i].cLower); 203 cErrors++; 204 } 205 else 206 RTPrintf("tstTimer: OK - gcTicks=%d", gcTicks); 207 RTPrintf(" min=%RU64 max=%RU64\n", gu64Min, gu64Max); 185 RTTestFailed(hTest, "Too many ticks gcTicks=%d (expected %d-%d)", gcTicks, aTests[i].cUpper, aTests[i].cLower); 208 186 } 209 187 … … 211 189 * Test changing the interval dynamically 212 190 */ 213 RTPrintf("\n" 214 "tstTimer: Testing dynamic changes of timer interval...\n"); 191 RTTestSub(hTest, "RTTimerLRChangeInterval"); 215 192 do 216 193 { … … 219 196 if (RT_FAILURE(rc)) 220 197 { 221 RTPrintf("RTTimerLRCreateEX(,%u*1M,,,) -> %d\n", aTests[0].uMilliesInterval, rc); 222 cErrors++; 223 continue; 198 RTTestFailed(hTest, "RTTimerLRCreateEX(,%u*1M,,,) -> %Rrc", aTests[0].uMilliesInterval, rc); 199 break; 224 200 } 225 201 226 202 for (i = 0; i < RT_ELEMENTS(aTests); i++) 227 203 { 228 RTPrintf("\n" 229 "tstTimer: TESTING - %d ms interval, %d ms wait, expects %d-%d ticks.\n", 230 aTests[i].uMilliesInterval, aTests[i].uMilliesWait, aTests[i].cLower, aTests[i].cUpper); 204 RTTestPrintf(hTest, RTTESTLVL_ALWAYS, "%d ms interval, %d ms wait, expects %d-%d ticks.\n", 205 aTests[i].uMilliesInterval, aTests[i].uMilliesWait, aTests[i].cLower, aTests[i].cUpper); 231 206 232 207 gcTicks = 0; … … 234 209 gu64Min = UINT64_MAX; 235 210 gu64Prev = 0; 211 236 212 /* 237 213 * Start the timer an actively wait for it for the period requested. … … 242 218 rc = RTTimerLRStart(hTimerLR, 0); 243 219 if (RT_FAILURE(rc)) 244 { 245 RTPrintf("tstTimer: FAILURE - RTTimerLRStart() -> %Rrc\n", rc); 246 cErrors++; 247 } 220 RTTestFailed(hTest, "RTTimerLRStart() -> %Rrc", rc); 248 221 } 249 222 else 250 223 { 251 rc = RTTimerLRChangeInterval(hTimerLR, aTests[i].uMilliesInterval * (uint64_t)1000000);224 rc = RTTimerLRChangeInterval(hTimerLR, aTests[i].uMilliesInterval * RT_NS_1MS_64); 252 225 if (RT_FAILURE(rc)) 253 { 254 RTPrintf("tstTimer: FAILURE - RTTimerLRChangeInterval() -> %d gcTicks=%d\n", rc, gcTicks); 255 cErrors++; 256 } 226 RTTestFailed(hTest, "RTTimerLRChangeInterval() -> %d gcTicks=%d", rc, gcTicks); 257 227 } 258 228 259 while (RTTimeNanoTS() - uTSBegin < (uint64_t)aTests[i].uMilliesWait * 1000000)260 /* nothing */;229 while (RTTimeNanoTS() - uTSBegin < (uint64_t)aTests[i].uMilliesWait * RT_NS_1MS_64) 230 RTThreadSleep(1); 261 231 262 232 uint64_t uTSEnd = RTTimeNanoTS(); 263 233 uTSDiff = uTSEnd - uTSBegin; 264 RTPrintf("uTS=%RI64 (%RU64 - %RU64)\n", uTSDiff, uTSBegin, uTSEnd); 234 RTTestPrintf(hTest, RTTESTLVL_ALWAYS, "uTS=%'RI64 (%'RU64 - %'RU64) gcTicks=%u min=%'RU64 max=%'RU64\n", 235 uTSDiff, uTSBegin, uTSEnd, gcTicks, gu64Min, gu64Max); 265 236 266 237 /* … … 268 239 */ 269 240 if (gcTicks < aTests[i].cLower) 270 { 271 RTPrintf("tstTimer: FAILURE - Too few ticks gcTicks=%d (expected %d-%d)\n", gcTicks, aTests[i].cUpper, aTests[i].cLower); 272 cErrors++; 273 } 241 RTTestFailed(hTest, "Too few ticks gcTicks=%d (expected %d-%d)", gcTicks, aTests[i].cUpper, aTests[i].cLower); 274 242 else if (gcTicks > aTests[i].cUpper) 275 { 276 RTPrintf("tstTimer: FAILURE - Too many ticks gcTicks=%d (expected %d-%d)\n", gcTicks, aTests[i].cUpper, aTests[i].cLower); 277 cErrors++; 278 } 279 else 280 RTPrintf("tstTimer: OK - gcTicks=%d\n", gcTicks); 281 // RTPrintf(" min=%RU64 max=%RU64\n", gu64Min, gu64Max); 282 } 243 RTTestFailed(hTest, "Too many ticks gcTicks=%d (expected %d-%d)", gcTicks, aTests[i].cUpper, aTests[i].cLower); 244 } 245 283 246 /* don't stop it, destroy it because there are potential races in destroying an active timer. */ 284 247 rc = RTTimerLRDestroy(hTimerLR); 285 248 if (RT_FAILURE(rc)) 286 { 287 RTPrintf("tstTimer: FAILURE - RTTimerLRDestroy() -> %d gcTicks=%d\n", rc, gcTicks); 288 cErrors++; 289 } 249 RTTestFailed(hTest, "RTTimerLRDestroy() -> %d gcTicks=%d", rc, gcTicks); 290 250 } while (0); 291 251 … … 298 258 * Summary. 299 259 */ 300 if (!cErrors) 301 RTPrintf("tstTimer: SUCCESS\n"); 302 else 303 RTPrintf("tstTimer: FAILURE %d errors\n", cErrors); 304 return !!cErrors; 260 return RTTestSummaryAndDestroy(hTest); 305 261 } 306 262
Note:
See TracChangeset
for help on using the changeset viewer.