tstTimerLR.cpp revision a7d199151f468f894181e8d50d3e202c2a010702
d4db54bec4e64c8bc78d59d9f6dd6e4cff8a3559slive * IPRT Testcase - Low Resolution Timers.
5a58787efeb02a1c3f06569d019ad81fd2efa06end * Copyright (C) 2006-2008 Oracle Corporation
5a58787efeb02a1c3f06569d019ad81fd2efa06end * This file is part of VirtualBox Open Source Edition (OSE), as
5a58787efeb02a1c3f06569d019ad81fd2efa06end * available from http://www.virtualbox.org. This file is free software;
d29d9ab4614ff992b0e8de6e2b88d52b6f1f153erbowen * you can redistribute it and/or modify it under the terms of the GNU
2e545ce2450a9953665f701bb05350f0d3f26275nd * General Public License (GPL) as published by the Free Software
d29d9ab4614ff992b0e8de6e2b88d52b6f1f153erbowen * Foundation, in version 2 as it comes in the "COPYING" file of the
d29d9ab4614ff992b0e8de6e2b88d52b6f1f153erbowen * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
5a58787efeb02a1c3f06569d019ad81fd2efa06end * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
af33a4994ae2ff15bc67d19ff1a7feb906745bf8rbowen * The contents of this file may alternatively be used under the terms
3f08db06526d6901aa08c110b5bc7dde6bc39905nd * of the Common Development and Distribution License Version 1.0
5a58787efeb02a1c3f06569d019ad81fd2efa06end * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
5a58787efeb02a1c3f06569d019ad81fd2efa06end * VirtualBox OSE distribution, in which case the provisions of the
5a58787efeb02a1c3f06569d019ad81fd2efa06end * CDDL are applicable instead of those of the GPL.
3b3b7fc78d1f5bfc2769903375050048ff41ff26nd * You may elect to license modified versions of this file under the
a78048ccbdb6256da15e6b0e7e95355e480c2301nd * terms and conditions of either the GPL or the CDDL or both.
3b3b7fc78d1f5bfc2769903375050048ff41ff26nd/*******************************************************************************
3b3b7fc78d1f5bfc2769903375050048ff41ff26nd* Header Files *
d4db54bec4e64c8bc78d59d9f6dd6e4cff8a3559slive*******************************************************************************/
5a58787efeb02a1c3f06569d019ad81fd2efa06end/*******************************************************************************
30471a4650391f57975f60bbb6e4a90be7b284bfhumbedooh* Global Variables *
5a58787efeb02a1c3f06569d019ad81fd2efa06end*******************************************************************************/
5a58787efeb02a1c3f06569d019ad81fd2efa06endstatic volatile unsigned gcTicks;
18b044262d499eb4255fb75026564a3e33b961eandstatic DECLCALLBACK(void) TimerLRCallback(RTTIMERLR hTimerLR, void *pvUser, uint64_t iTick)
d4db54bec4e64c8bc78d59d9f6dd6e4cff8a3559slive * Init runtime
d4db54bec4e64c8bc78d59d9f6dd6e4cff8a3559slive unsigned cErrors = 0;
d4db54bec4e64c8bc78d59d9f6dd6e4cff8a3559slive * Check that the clock is reliable.
d4db54bec4e64c8bc78d59d9f6dd6e4cff8a3559slive RTPrintf("tstTimer: TESTING - RTTimeNanoTS() for 2sec\n");
d4db54bec4e64c8bc78d59d9f6dd6e4cff8a3559slive RTPrintf("tstTimer: FAILURE - RTTimeNanoTS() is unreliable. uTS=%RU64 uTSLast=%RU64\n", uTS, uTSLast);
d4db54bec4e64c8bc78d59d9f6dd6e4cff8a3559slive RTPrintf("tstTimer: FAILURE - RTTimeNanoTS() is unreliable. cIterations=%RU64 uTS=%RU64 uTSBegin=%RU64\n", cIterations, uTS, uTSBegin);
2af5ae0ec81f8ed0b61785ef4e1320b37cf58af1slive RTPrintf("tstTimer: FAILURE - uTSMillies=%RI64 uTSBegin=%RU64 uTSLast=%RU64 uTSDiff=%RU64\n",
d4db54bec4e64c8bc78d59d9f6dd6e4cff8a3559slive static struct
d4db54bec4e64c8bc78d59d9f6dd6e4cff8a3559slive { 1000, 2500, 3, 3 }, /* (keep in mind the immediate first tick) */
d4db54bec4e64c8bc78d59d9f6dd6e4cff8a3559slive unsigned i = 0;
d4db54bec4e64c8bc78d59d9f6dd6e4cff8a3559slive //aTests[i].cLower = (aTests[i].uMilliesWait - aTests[i].uMilliesWait / 10) / aTests[i].uMilliesInterval;
77c77cf89621f21c8e2bbad63058b5eaa5f88d4ajim //aTests[i].cUpper = (aTests[i].uMilliesWait + aTests[i].uMilliesWait / 10) / aTests[i].uMilliesInterval;
62f707ed6864c9606c51b6cf4eddead74d5a1b16kess "tstTimer: TESTING - %d ms interval, %d ms wait, expects %d-%d ticks.\n",
62f707ed6864c9606c51b6cf4eddead74d5a1b16kess aTests[i].uMilliesInterval, aTests[i].uMilliesWait, aTests[i].cLower, aTests[i].cUpper);
d4db54bec4e64c8bc78d59d9f6dd6e4cff8a3559slive * Start timer which ticks every 10ms.
29d1295999773b9df63c15a1895bc5972ed55199takashi rc = RTTimerLRCreateEx(&hTimerLR, aTests[i].uMilliesInterval * (uint64_t)1000000, 0, TimerLRCallback, NULL);
d4db54bec4e64c8bc78d59d9f6dd6e4cff8a3559slive RTPrintf("RTTimerLRCreateEX(,%u*1M,,,) -> %d\n", aTests[i].uMilliesInterval, rc);
f4cbda69df0490c6deaacb8d04f103d200ddd183nd * Start the timer an actively wait for it for the period requested.
d4db54bec4e64c8bc78d59d9f6dd6e4cff8a3559slive RTPrintf("tstTimer: FAILURE - RTTimerLRStart() -> %Rrc\n", rc);
d4db54bec4e64c8bc78d59d9f6dd6e4cff8a3559slive while (RTTimeNanoTS() - uTSBegin < (uint64_t)aTests[i].uMilliesWait * 1000000)
d4db54bec4e64c8bc78d59d9f6dd6e4cff8a3559slive /* nothing */;
d4db54bec4e64c8bc78d59d9f6dd6e4cff8a3559slive /* don't stop it, destroy it because there are potential races in destroying an active timer. */
d4db54bec4e64c8bc78d59d9f6dd6e4cff8a3559slive RTPrintf("tstTimer: FAILURE - RTTimerLRDestroy() -> %d gcTicks=%d\n", rc, gcTicks);
d4db54bec4e64c8bc78d59d9f6dd6e4cff8a3559slive RTPrintf("uTS=%RI64 (%RU64 - %RU64)\n", uTSDiff, uTSBegin, uTSEnd);
d4db54bec4e64c8bc78d59d9f6dd6e4cff8a3559slive /* Check that it really stopped. */
d4db54bec4e64c8bc78d59d9f6dd6e4cff8a3559slive RTPrintf("tstTimer: FAILURE - RTTimerLRDestroy() didn't really stop the timer! gcTicks=%d cTicks=%d\n", gcTicks, cTicks);
d4db54bec4e64c8bc78d59d9f6dd6e4cff8a3559slive * Check the number of ticks.
d4db54bec4e64c8bc78d59d9f6dd6e4cff8a3559slive RTPrintf("tstTimer: FAILURE - Too few ticks gcTicks=%d (expected %d-%d)", gcTicks, aTests[i].cUpper, aTests[i].cLower);
1d980e5489836e977ba59b419e27b0ec875c4bd3takashi RTPrintf("tstTimer: FAILURE - Too many ticks gcTicks=%d (expected %d-%d)", gcTicks, aTests[i].cUpper, aTests[i].cLower);
cc7e1025de9ac63bd4db6fe7f71c158b2cf09fe4humbedooh RTPrintf(" min=%RU64 max=%RU64\n", gu64Min, gu64Max);
0d0ba3a410038e179b695446bb149cce6264e0abnd * Test changing the interval dynamically
ac082aefa89416cbdc9a1836eaf3bed9698201c8humbedooh "tstTimer: Testing dynamic changes of timer interval...\n");
727872d18412fc021f03969b8641810d8896820bhumbedooh rc = RTTimerLRCreateEx(&hTimerLR, aTests[0].uMilliesInterval * (uint64_t)1000000, 0, TimerLRCallback, NULL);
30471a4650391f57975f60bbb6e4a90be7b284bfhumbedooh RTPrintf("RTTimerLRCreateEX(,%u*1M,,,) -> %d\n", aTests[i].uMilliesInterval, rc);
gcTicks = 0;
gu64Max = 0;
gu64Prev = 0;
cErrors++;
cErrors++;
RTPrintf("tstTimer: FAILURE - Too few ticks gcTicks=%d (expected %d-%d)\n", gcTicks, aTests[i].cUpper, aTests[i].cLower);
cErrors++;
RTPrintf("tstTimer: FAILURE - Too many ticks gcTicks=%d (expected %d-%d)\n", gcTicks, aTests[i].cUpper, aTests[i].cLower);
cErrors++;
cErrors++;
if (!cErrors)
return !!cErrors;