VirtualBox

Changeset 32669 in vbox


Ignore:
Timestamp:
Sep 21, 2010 4:18:22 PM (14 years ago)
Author:
vboxsync
Message:

tstRTR0Timer: Some more tests.

Location:
trunk/src/VBox/Runtime/testcase
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/testcase/tstRTR0Timer.cpp

    r32648 r32669  
    4949    /** The number of shots. */
    5050    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;
    5155} TSTRTR0TIMERS1;
    5256typedef TSTRTR0TIMERS1 *PTSTRTR0TIMERS1;
     
    5458
    5559/**
    56  * Callback which increments restarts a timer once.
     60 * Callback which increments destroy the timer when it fires.
    5761 *
    5862 * @param   pTimer      The timer.
     
    6064 * @param   pvUser      The user argument.
    6165 */
    62 static DECLCALLBACK(void) tstRTR0TimerCallbackRestartOnce(PRTTIMER pTimer, void *pvUser, uint64_t iTick)
     66static DECLCALLBACK(void) tstRTR0TimerCallbackDestroyOnce(PRTTIMER pTimer, void *pvUser, uint64_t iTick)
    6367{
    6468    PTSTRTR0TIMERS1 pState = (PTSTRTR0TIMERS1)pvUser;
     
    6872        pState->aShotNsTSes[iShot - 1] = RTTimeSystemNanoTS();
    6973
    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 */
     86static 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);
    7296}
    7397
     
    165189     * The big switch.
    166190     */
     191    uint32_t const cNsSysHz = RTTimerGetSystemGranularity();
    167192    TSTRTR0TIMERS1 State;
    168193    switch (uOperation)
     
    174199        case TSTRTR0TIMER_ONE_SHOT_BASIC_HIRES:
    175200        {
     201            /* Check that RTTimerGetSystemGranularity works. */
     202            RTR0TESTR0_CHECK_MSG_BREAK(cNsSysHz > UINT32_C(0) && cNsSysHz < UINT32_C(1000000000), ("%u", cNsSysHz));
     203
    176204            /* Create a one-shot timer and take one shot. */
    177205            PRTTIMER        pTimer;
     
    223251            PRTTIMER            pTimer;
    224252            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            }
    237299            break;
    238300        }
     
    267329            break;
    268330        }
     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
    269355    }
    270356
  • trunk/src/VBox/Runtime/testcase/tstRTR0Timer.h

    r32648 r32669  
    4343    TSTRTR0TIMER_ONE_SHOT_RESTART,
    4444    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,
    4549    TSTRTR0TIMER_END
    4650} TSTRTR0TIMER;
  • trunk/src/VBox/Runtime/testcase/tstRTR0TimerDriver.cpp

    r32648 r32669  
    5757        return rcExit;
    5858
     59# if 1
    5960    /*
    6061     * Basic tests, bail out on failure.
    6162     */
    6263    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     */
    6377    RTR3TestR0SimpleTest(TSTRTR0TIMER_ONE_SHOT_BASIC_HIRES, "Basic hires one shot");
    64     RTR3TestR0SimpleTest(TSTRTR0TIMER_PERIODIC_BASIC,       "Basic periodic");
    6578    RTR3TestR0SimpleTest(TSTRTR0TIMER_PERIODIC_BASIC_HIRES, "Basic hires periodic");
    6679    if (RTTestErrorCount(g_hTest) == 0)
    6780    {
    68         RTR3TestR0SimpleTest(TSTRTR0TIMER_ONE_SHOT_RESTART, "Restart one shot from callback");
    6981        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");
    7084    }
    71 
     85# endif
    7286
    7387    /*
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette