tstTimer.cpp revision 677833bc953b6cb418c701facbdcf4aa18d6c44e
/* $Id$ */
/** @file
* InnoTek Portable Runtime Testcase - Timers.
*/
/*
* Copyright (C) 2006 InnoTek Systemberatung GmbH
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* General Public License as published by the Free Software Foundation,
* in version 2 as it comes in the "COPYING" file of the VirtualBox OSE
* distribution. VirtualBox OSE is distributed in the hope that it will
* be useful, but WITHOUT ANY WARRANTY of any kind.
*
* If you received this file as part of a commercial VirtualBox
* distribution, then only the terms of your commercial VirtualBox
* license agreement apply instead of the previous paragraph.
*/
/*******************************************************************************
* Header Files *
*******************************************************************************/
/*******************************************************************************
* Global Variables *
*******************************************************************************/
static volatile unsigned gcTicks;
{
gcTicks++;
}
int main()
{
/*
* Init runtime
*/
unsigned cErrors = 0;
if (RT_FAILURE(rc))
{
return 1;
}
/*
* Check that the clock is reliable.
*/
RTPrintf("tstTimer: TESTING - RTTimeNanoTS() for 2sec\n");
uint64_t cIterations = 0;
do
{
{
RTPrintf("tstTimer: FAILURE - RTTimeNanoTS() is unreliable. uTS=%RU64 uTSLast=%RU64\n", uTS, uTSLast);
cErrors++;
}
{
RTPrintf("tstTimer: FAILURE - RTTimeNanoTS() is unreliable. cIterations=%RU64 uTS=%RU64 uTSBegin=%RU64\n", cIterations, uTS, uTSBegin);
return 1;
}
{
RTPrintf("tstTimer: FAILURE - uTSMillies=%RI64 uTSBegin=%RU64 uTSLast=%RU64 uTSDiff=%RU64\n",
cErrors++;
}
if (!cErrors)
RTPrintf("tstTimer: OK - RTTimeNanoTS()\n");
/*
* Tests.
*/
static struct
{
unsigned uMilliesInterval;
unsigned uMilliesWait;
unsigned cLower;
unsigned cUpper;
} aTests[] =
{
{ 32, 2000, 0, 0 },
{ 20, 2000, 0, 0 },
{ 10, 2000, 0, 0 },
{ 8, 2000, 0, 0 },
{ 2, 2000, 0, 0 },
{ 1, 2000, 0, 0 }
};
unsigned i = 0;
{
aTests[i].cLower = (aTests[i].uMilliesWait - aTests[i].uMilliesWait / 10) / aTests[i].uMilliesInterval;
aTests[i].cUpper = (aTests[i].uMilliesWait + aTests[i].uMilliesWait / 10) / aTests[i].uMilliesInterval;
RTPrintf("tstTimer: TESTING - %d ms interval, %d ms wait, expects %d-%d ticks.\n",
/*
* Start timer which ticks every 10ms.
*/
gcTicks = 0;
if (RT_FAILURE(rc))
{
cErrors++;
continue;
}
/*
* Sleep for a while and then kill it.
*/
#if 1
/* nothing */;
#else
#endif
if (RT_FAILURE(rc))
if (RT_FAILURE(rc))
{
cErrors++;
continue;
}
RTThreadSleep(100);
{
RTPrintf("tstTimer: FAILURE - RTTimerDestroy() didn't really stop the timer! gcTicks=%d cTicks=%d\n", gcTicks, cTicks);
cErrors++;
continue;
}
/*
* Check the number of ticks.
*/
{
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++;
}
else
}
/*
* Summary.
*/
if (!cErrors)
RTPrintf("tstTimer: SUCCESS\n");
else
return !!cErrors;
}