VirtualBox

Changeset 10944 in vbox for trunk/src/VBox/Runtime/testcase


Ignore:
Timestamp:
Jul 29, 2008 6:08:58 PM (17 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
33809
Message:

iprt: RTTimerLR - low resolution timer API (< 10 Hz).

Location:
trunk/src/VBox/Runtime/testcase
Files:
1 edited
1 copied

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/testcase/Makefile.kmk

    r10940 r10944  
    8787        tstTime-4 \
    8888        tstTimer \
     89        tstTimerLR \
    8990        tstTimeSpec \
    9091        tstTSC \
     
    297298tstTimer_SOURCES = tstTimer.cpp
    298299
     300tstTimerLR_SOURCES = tstTimerLR.cpp
     301
    299302tstTimeSpec_SOURCES = tstTimeSpec.cpp
    300303
  • trunk/src/VBox/Runtime/testcase/tstTimerLR.cpp

    r10941 r10944  
    11/* $Id$ */
    22/** @file
    3  * IPRT Testcase - Timers.
     3 * IPRT Testcase - Low Resolution Timers.
    44 */
    55
    66/*
    7  * Copyright (C) 2006-2007 Sun Microsystems, Inc.
     7 * Copyright (C) 2006-2008 Sun Microsystems, Inc.
    88 *
    99 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    4949static volatile uint64_t gu64Prev;
    5050
    51 static DECLCALLBACK(void) TimerCallback(PRTTIMER pTimer, void *pvUser, uint64_t iTick)
     51static DECLCALLBACK(void) TimerLRCallback(RTTIMERLR hTimerLR, void *pvUser, uint64_t iTick)
    5252{
    5353    gcTicks++;
     
    126126    } aTests[] =
    127127    {
    128         { 32, 2000, 0, 0 },
    129         { 20, 2000, 0, 0 },
    130         { 10, 2000, 0, 0 },
    131         { 8,  2000, 0, 0 },
    132         { 2,  2000, 0, 0 },
    133         { 1,  2000, 0, 0 }
     128        { 1000, 2500, 3,   3 }, /* (keep in mind the immediate first tick) */
     129        {  250, 2000, 6,  10 },
     130        {  100, 2000, 17, 23 },
    134131    };
    135132
     
    137134    for (i = 0; i < ELEMENTS(aTests); i++)
    138135    {
    139         aTests[i].cLower = (aTests[i].uMilliesWait - aTests[i].uMilliesWait / 10) / aTests[i].uMilliesInterval;
    140         aTests[i].cUpper = (aTests[i].uMilliesWait + aTests[i].uMilliesWait / 10) / aTests[i].uMilliesInterval;
     136        //aTests[i].cLower = (aTests[i].uMilliesWait - aTests[i].uMilliesWait / 10) / aTests[i].uMilliesInterval;
     137        //aTests[i].cUpper = (aTests[i].uMilliesWait + aTests[i].uMilliesWait / 10) / aTests[i].uMilliesInterval;
    141138
    142139        RTPrintf("\n"
     
    148145         */
    149146        gcTicks = 0;
    150         PRTTIMER pTimer;
     147        RTTIMERLR hTimerLR;
    151148        gu64Max = 0;
    152149        gu64Min = UINT64_MAX;
    153150        gu64Prev = 0;
    154         rc = RTTimerCreate(&pTimer, aTests[i].uMilliesInterval, TimerCallback, NULL);
     151        rc = RTTimerLRCreateEx(&hTimerLR, aTests[i].uMilliesInterval * (uint64_t)1000000, 0, TimerLRCallback, NULL);
    155152        if (RT_FAILURE(rc))
    156153        {
    157             RTPrintf("RTTimerCreate(,%d,) -> %d\n", aTests[i].uMilliesInterval, rc);
     154            RTPrintf("RTTimerLRCreateEX(,%u*1M,,,) -> %d\n", aTests[i].uMilliesInterval, rc);
    158155            cErrors++;
    159156            continue;
     
    161158
    162159        /*
    163          * Active waiting for 2 seconds and then destroy it.
     160         * Start the timer an actively wait for it for the period requested.
    164161         */
    165162        uint64_t uTSBegin = RTTimeNanoTS();
     163        rc = RTTimerLRStart(hTimerLR, 0);
     164        if (RT_FAILURE(rc))
     165        {
     166            RTPrintf("tstTimer: FAILURE - RTTimerLRStart() -> %Rrc\n", rc);
     167            cErrors++;
     168        }
     169
    166170        while (RTTimeNanoTS() - uTSBegin < (uint64_t)aTests[i].uMilliesWait * 1000000)
    167171            /* nothing */;
     172
     173        /* don't stop it, destroy it because there are potential races in destroying an active timer. */
     174        rc = RTTimerLRDestroy(hTimerLR);
     175        if (RT_FAILURE(rc))
     176        {
     177            RTPrintf("tstTimer: FAILURE - RTTimerLRDestroy() -> %d gcTicks=%d\n", rc, gcTicks);
     178            cErrors++;
     179        }
     180
    168181        uint64_t uTSEnd = RTTimeNanoTS();
    169182        uint64_t uTSDiff = uTSEnd - uTSBegin;
    170183        RTPrintf("uTS=%RI64 (%RU64 - %RU64)\n", uTSDiff, uTSBegin, uTSEnd);
    171         if (RT_FAILURE(rc))
    172             RTPrintf("warning: RTThreadSleep ended prematurely with %d\n", rc);
    173         rc = RTTimerDestroy(pTimer);
    174         if (RT_FAILURE(rc))
    175         {
    176             RTPrintf("tstTimer: FAILURE - RTTimerDestroy() -> %d gcTicks=%d\n", rc, gcTicks);
    177             cErrors++;
    178             continue;
    179         }
     184
     185        /* Check that it really stopped. */
    180186        unsigned cTicks = gcTicks;
    181         RTThreadSleep(100);
     187        RTThreadSleep(aTests[i].uMilliesInterval * 2);
    182188        if (gcTicks != cTicks)
    183189        {
    184             RTPrintf("tstTimer: FAILURE - RTTimerDestroy() didn't really stop the timer! gcTicks=%d cTicks=%d\n", gcTicks, cTicks);
     190            RTPrintf("tstTimer: FAILURE - RTTimerLRDestroy() didn't really stop the timer! gcTicks=%d cTicks=%d\n", gcTicks, cTicks);
    185191            cErrors++;
    186192            continue;
     
    204210        RTPrintf(" min=%RU64 max=%RU64\n", gu64Min, gu64Max);
    205211    }
     212
     213    /*
     214     * Test multiple timers running at once.
     215     */
     216    /** @todo multiple LR timer testcase. */
    206217
    207218    /*
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