Changeset 32669 in vbox
- Timestamp:
- Sep 21, 2010 4:18:22 PM (14 years ago)
- Location:
- trunk/src/VBox/Runtime/testcase
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/testcase/tstRTR0Timer.cpp
r32648 r32669 49 49 /** The number of shots. */ 50 50 uint32_t volatile cShots; 51 /** The shot at which action is to be taken. */ 52 uint32_t iActionShot; 53 /** The RC of whatever operation performed in the handler. */ 54 int volatile rc; 51 55 } TSTRTR0TIMERS1; 52 56 typedef TSTRTR0TIMERS1 *PTSTRTR0TIMERS1; … … 54 58 55 59 /** 56 * Callback which increments restarts a timer once.60 * Callback which increments destroy the timer when it fires. 57 61 * 58 62 * @param pTimer The timer. … … 60 64 * @param pvUser The user argument. 61 65 */ 62 static DECLCALLBACK(void) tstRTR0TimerCallback RestartOnce(PRTTIMER pTimer, void *pvUser, uint64_t iTick)66 static DECLCALLBACK(void) tstRTR0TimerCallbackDestroyOnce(PRTTIMER pTimer, void *pvUser, uint64_t iTick) 63 67 { 64 68 PTSTRTR0TIMERS1 pState = (PTSTRTR0TIMERS1)pvUser; … … 68 72 pState->aShotNsTSes[iShot - 1] = RTTimeSystemNanoTS(); 69 73 70 if (iShot == 1) 71 RTR0TESTR0_CHECK_RC(RTTimerStart(pTimer, 10000000 /* 10ms */), VINF_SUCCESS); 74 if (iShot == pState->iActionShot + 1) 75 RTR0TESTR0_CHECK_RC(pState->rc = RTTimerDestroy(pTimer), VINF_SUCCESS); 76 } 77 78 79 /** 80 * Callback which increments restarts a timer once. 81 * 82 * @param pTimer The timer. 83 * @param iTick The current tick. 84 * @param pvUser The user argument. 85 */ 86 static DECLCALLBACK(void) tstRTR0TimerCallbackRestartOnce(PRTTIMER pTimer, void *pvUser, uint64_t iTick) 87 { 88 PTSTRTR0TIMERS1 pState = (PTSTRTR0TIMERS1)pvUser; 89 uint32_t iShot = ASMAtomicIncU32(&pState->cShots); 90 91 if (iShot <= RT_ELEMENTS(pState->aShotNsTSes)) 92 pState->aShotNsTSes[iShot - 1] = RTTimeSystemNanoTS(); 93 94 if (iShot == pState->iActionShot + 1) 95 RTR0TESTR0_CHECK_RC(pState->rc = RTTimerStart(pTimer, 10000000 /* 10ms */), VINF_SUCCESS); 72 96 } 73 97 … … 165 189 * The big switch. 166 190 */ 191 uint32_t const cNsSysHz = RTTimerGetSystemGranularity(); 167 192 TSTRTR0TIMERS1 State; 168 193 switch (uOperation) … … 174 199 case TSTRTR0TIMER_ONE_SHOT_BASIC_HIRES: 175 200 { 201 /* Check that RTTimerGetSystemGranularity works. */ 202 RTR0TESTR0_CHECK_MSG_BREAK(cNsSysHz > UINT32_C(0) && cNsSysHz < UINT32_C(1000000000), ("%u", cNsSysHz)); 203 176 204 /* Create a one-shot timer and take one shot. */ 177 205 PRTTIMER pTimer; … … 223 251 PRTTIMER pTimer; 224 252 uint32_t fFlags = uOperation != TSTRTR0TIMER_ONE_SHOT_RESTART_HIRES ? RTTIMER_FLAGS_HIGH_RES : 0; 225 RTR0TESTR0_CHECK_RC_BREAK(RTTimerCreateEx(&pTimer, 0, fFlags, tstRTR0TimerCallbackRestartOnce, &State), 226 VINF_SUCCESS); 227 228 do /* break loop */ 229 { 230 RT_ZERO(State); 231 RTR0TESTR0_CHECK_RC_BREAK(RTTimerStart(pTimer, 0), VINF_SUCCESS); 232 for (uint32_t i = 0; i < 1000 && ASMAtomicUoReadU32(&State.cShots) < 2; i++) 233 RTThreadSleep(5); 234 RTR0TESTR0_CHECK_MSG_BREAK(ASMAtomicUoReadU32(&State.cShots) == 2, ("cShots=%u\n", State.cShots)); 235 } while (0); 236 RTR0TESTR0_CHECK_RC(RTTimerDestroy(pTimer), VINF_SUCCESS); 253 for (uint32_t iTest = 0; iTest < 2; iTest++) 254 { 255 RTR0TESTR0_CHECK_RC_BREAK(RTTimerCreateEx(&pTimer, 0, fFlags, tstRTR0TimerCallbackRestartOnce, &State), 256 VINF_SUCCESS); 257 258 RT_ZERO(State); 259 State.iActionShot = 0; 260 do /* break loop */ 261 { 262 RTR0TESTR0_CHECK_RC_BREAK(RTTimerStart(pTimer, cNsSysHz * iTest), VINF_SUCCESS); 263 for (uint32_t i = 0; i < 1000 && ASMAtomicUoReadU32(&State.cShots) < 2; i++) 264 RTThreadSleep(5); 265 RTR0TESTR0_CHECK_MSG_BREAK(ASMAtomicUoReadU32(&State.cShots) == 2, ("cShots=%u\n", State.cShots)); 266 } while (0); 267 RTR0TESTR0_CHECK_RC(RTTimerDestroy(pTimer), VINF_SUCCESS); 268 } 269 break; 270 } 271 #endif 272 273 #if 1 /* might have to disable this for some host... */ 274 case TSTRTR0TIMER_ONE_SHOT_DESTROY: 275 case TSTRTR0TIMER_ONE_SHOT_DESTROY_HIRES: 276 { 277 /* Create a one-shot timer and destroy it in the callback handler. */ 278 PRTTIMER pTimer; 279 uint32_t fFlags = uOperation != TSTRTR0TIMER_ONE_SHOT_DESTROY_HIRES ? RTTIMER_FLAGS_HIGH_RES : 0; 280 for (uint32_t iTest = 0; iTest < 2; iTest++) 281 { 282 RTR0TESTR0_CHECK_RC_BREAK(RTTimerCreateEx(&pTimer, 0, fFlags, tstRTR0TimerCallbackDestroyOnce, &State), 283 VINF_SUCCESS); 284 285 RT_ZERO(State); 286 State.rc = VERR_IPE_UNINITIALIZED_STATUS; 287 State.iActionShot = 0; 288 do /* break loop */ 289 { 290 RTR0TESTR0_CHECK_RC_BREAK(RTTimerStart(pTimer, cNsSysHz * iTest), VINF_SUCCESS); 291 for (uint32_t i = 0; i < 1000 && ASMAtomicUoReadU32(&State.cShots) < 1; i++) 292 RTThreadSleep(5); 293 RTR0TESTR0_CHECK_MSG_BREAK(ASMAtomicReadU32(&State.cShots) == 1, ("cShots=%u\n", State.cShots)); 294 RTR0TESTR0_CHECK_MSG_BREAK(State.rc == VINF_SUCCESS, ("rc=%Rrc\n", State.rc)); 295 } while (0); 296 if (RT_FAILURE(State.rc)) 297 RTR0TESTR0_CHECK_RC(RTTimerDestroy(pTimer), VINF_SUCCESS); 298 } 237 299 break; 238 300 } … … 267 329 break; 268 330 } 331 332 case TSTRTR0TIMER_PERIODIC_CSSD_LOOPS: 333 case TSTRTR0TIMER_PERIODIC_CSSD_LOOPS_HIRES: 334 { 335 /* create, start, stop & destroy high res timers a number of times. */ 336 uint32_t fFlags = uOperation != TSTRTR0TIMER_PERIODIC_CSSD_LOOPS_HIRES ? RTTIMER_FLAGS_HIGH_RES : 0; 337 for (uint32_t i = 0; i < 40; i++) 338 { 339 PRTTIMER pTimer; 340 RTR0TESTR0_CHECK_RC_BREAK(RTTimerCreateEx(&pTimer, cNsSysHz, fFlags, tstRTR0TimerCallbackU32Counter, &State), 341 VINF_SUCCESS); 342 for (uint32_t j = 0; j < 10; j++) 343 { 344 RT_ZERO(State); 345 RTR0TESTR0_CHECK_RC_BREAK(RTTimerStart(pTimer, i < 20 ? 0 : cNsSysHz), VINF_SUCCESS); 346 for (uint32_t k = 0; k < 1000 && ASMAtomicUoReadU32(&State.cShots) < 2; k++) 347 RTThreadSleep(1); 348 RTR0TESTR0_CHECK_RC_BREAK(RTTimerStop(pTimer), VINF_SUCCESS); 349 } 350 RTR0TESTR0_CHECK_RC(RTTimerDestroy(pTimer), VINF_SUCCESS); 351 } 352 break; 353 } 354 269 355 } 270 356 -
trunk/src/VBox/Runtime/testcase/tstRTR0Timer.h
r32648 r32669 43 43 TSTRTR0TIMER_ONE_SHOT_RESTART, 44 44 TSTRTR0TIMER_ONE_SHOT_RESTART_HIRES, 45 TSTRTR0TIMER_ONE_SHOT_DESTROY, 46 TSTRTR0TIMER_ONE_SHOT_DESTROY_HIRES, 47 TSTRTR0TIMER_PERIODIC_CSSD_LOOPS, 48 TSTRTR0TIMER_PERIODIC_CSSD_LOOPS_HIRES, 45 49 TSTRTR0TIMER_END 46 50 } TSTRTR0TIMER; -
trunk/src/VBox/Runtime/testcase/tstRTR0TimerDriver.cpp
r32648 r32669 57 57 return rcExit; 58 58 59 # if 1 59 60 /* 60 61 * Basic tests, bail out on failure. 61 62 */ 62 63 RTR3TestR0SimpleTest(TSTRTR0TIMER_ONE_SHOT_BASIC, "Basic one shot"); 64 RTR3TestR0SimpleTest(TSTRTR0TIMER_PERIODIC_BASIC, "Basic periodic"); 65 if (RTTestErrorCount(g_hTest) == 0) 66 { 67 RTR3TestR0SimpleTest(TSTRTR0TIMER_ONE_SHOT_RESTART, "Restart one shot from callback"); 68 RTR3TestR0SimpleTest(TSTRTR0TIMER_ONE_SHOT_DESTROY, "Destroy one shot from callback"); 69 RTR3TestR0SimpleTest(TSTRTR0TIMER_PERIODIC_CSSD_LOOPS, "Create-start-stop-destroy loops"); 70 } 71 # endif 72 73 # if 1 74 /* 75 * High resolution timers. 76 */ 63 77 RTR3TestR0SimpleTest(TSTRTR0TIMER_ONE_SHOT_BASIC_HIRES, "Basic hires one shot"); 64 RTR3TestR0SimpleTest(TSTRTR0TIMER_PERIODIC_BASIC, "Basic periodic");65 78 RTR3TestR0SimpleTest(TSTRTR0TIMER_PERIODIC_BASIC_HIRES, "Basic hires periodic"); 66 79 if (RTTestErrorCount(g_hTest) == 0) 67 80 { 68 RTR3TestR0SimpleTest(TSTRTR0TIMER_ONE_SHOT_RESTART, "Restart one shot from callback");69 81 RTR3TestR0SimpleTest(TSTRTR0TIMER_ONE_SHOT_RESTART_HIRES, "Restart hires one shot from callback"); 82 RTR3TestR0SimpleTest(TSTRTR0TIMER_ONE_SHOT_DESTROY_HIRES, "Destroy hires one shot from callback"); 83 RTR3TestR0SimpleTest(TSTRTR0TIMER_PERIODIC_CSSD_LOOPS_HIRES, "Create-start-stop-destroy loops, hires"); 70 84 } 71 85 # endif 72 86 73 87 /*
Note:
See TracChangeset
for help on using the changeset viewer.