tstRTR0Timer.cpp revision f5bed9e0fb53936fc0ff58a29ecf7293f107b5aa
/* $Id$ */
/** @file
* IPRT R0 Testcase - Timers.
*/
/*
* Copyright (C) 2009-2010 Oracle Corporation
*
* 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 (GPL) 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.
*
* The contents of this file may alternatively be used under the terms
* of the Common Development and Distribution License Version 1.0
* (CDDL) only, as it comes in the "COPYING.CDDL" file of the
* VirtualBox OSE distribution, in which case the provisions of the
* CDDL are applicable instead of those of the GPL.
*
* You may elect to license modified versions of this file under the
* terms and conditions of either the GPL or the CDDL or both.
*/
/*******************************************************************************
* Header Files *
*******************************************************************************/
#include "tstRTR0Timer.h"
#include "tstRTR0Common.h"
/*******************************************************************************
* Structures and Typedefs *
*******************************************************************************/
typedef struct
{
/** Array of nano second timestamp of the first few shots. */
/** The number of shots. */
/** The shot at which action is to be taken. */
/** The RC of whatever operation performed in the handler. */
int volatile rc;
typedef TSTRTR0TIMERS1 *PTSTRTR0TIMERS1;
/**
* Callback which increments destroy the timer when it fires.
*
* @param pTimer The timer.
* @param iTick The current tick.
* @param pvUser The user argument.
*/
static DECLCALLBACK(void) tstRTR0TimerCallbackDestroyOnce(PRTTIMER pTimer, void *pvUser, uint64_t iTick)
{
}
/**
* Callback which increments restarts a timer once.
*
* @param pTimer The timer.
* @param iTick The current tick.
* @param pvUser The user argument.
*/
static DECLCALLBACK(void) tstRTR0TimerCallbackRestartOnce(PRTTIMER pTimer, void *pvUser, uint64_t iTick)
{
}
/**
* Callback which increments a 32-bit counter.
*
* @param pTimer The timer.
* @param iTick The current tick.
* @param pvUser The user argument.
*/
static DECLCALLBACK(void) tstRTR0TimerCallbackU32Counter(PRTTIMER pTimer, void *pvUser, uint64_t iTick)
{
}
/**
* Checks that the interval between two timer shots are within the specified
* range.
*
* @returns 0 if ok, 1 if bad.
* @param iShot The shot number (for bitching).
* @param uPrevTS The time stamp of the previous shot (ns).
* @param uThisTS The timer stamp of this shot (ns).
* @param uMin The minimum interval (ns).
* @param uMax The maximum interval (ns).
*/
static int tstRTR0TimerCheckShotInterval(uint32_t iShot, uint64_t uPrevTS, uint64_t uThisTS, uint32_t uMin, uint32_t uMax)
{
RTR0TESTR0_CHECK_MSG_RET(uDelta >= uMin, ("iShot=%u uDelta=%lld uMin=%u\n", iShot, uDelta, uMin), 1);
RTR0TESTR0_CHECK_MSG_RET(uDelta <= uMax, ("iShot=%u uDelta=%lld uMax=%u\n", iShot, uDelta, uMax), 1);
return 0;
}
/**
* Checks that the interval between timer shots are within a certain range.
*
* @returns Number of violations (i.e. 0 is ok).
* @param pState The state.
* @param uStartNsTS The start time stamp (ns).
* @param uMin The minimum interval (ns).
* @param uMax The maximum interval (ns).
*/
static int tstRTR0TimerCheckShotIntervals(PTSTRTR0TIMERS1 pState, uint64_t uStartNsTS, uint32_t uMin, uint32_t uMax)
{
{
}
return cBadShots;
}
/**
* Service request callback function.
*
* @returns VBox status code.
* @param pSession The caller's session.
* @param u64Arg 64-bit integer argument.
* @param pReqHdr The request header. Input / Output. Optional.
*/
{
if (u64Arg)
return VERR_INVALID_PARAMETER;
/*
* The big switch.
*/
switch (uOperation)
{
{
/* Check that RTTimerGetSystemGranularity works. */
RTR0TESTR0_CHECK_MSG_BREAK(cNsSysHz > UINT32_C(0) && cNsSysHz < UINT32_C(1000000000), ("%u", cNsSysHz));
/* Create a one-shot timer and take one shot. */
RTR0TESTR0_CHECK_RC_BREAK(RTTimerCreateEx(&pTimer, 0, fFlags, tstRTR0TimerCallbackU32Counter, &State),
do /* break loop */
{
RTThreadSleep(5);
/* check that it is restartable. */
RTThreadSleep(5);
/* check that it respects the timeout value and can be cancelled. */
RTThreadSleep(1);
/* Check some double starts and stops (shall not assert). */
RTThreadSleep(1);
} while (0);
break;
}
#if 1 /* might have to disable this for some host... */
{
/* Create a one-shot timer and restart it in the callback handler. */
{
RTR0TESTR0_CHECK_RC_BREAK(RTTimerCreateEx(&pTimer, 0, fFlags, tstRTR0TimerCallbackRestartOnce, &State),
State.iActionShot = 0;
do /* break loop */
{
RTThreadSleep(5);
} while (0);
}
break;
}
#endif
#if 1 /* might have to disable this for some host... */
{
/* Create a one-shot timer and destroy it in the callback handler. */
{
RTR0TESTR0_CHECK_RC_BREAK(RTTimerCreateEx(&pTimer, 0, fFlags, tstRTR0TimerCallbackDestroyOnce, &State),
State.iActionShot = 0;
do /* break loop */
{
RTThreadSleep(5);
} while (0);
}
break;
}
#endif
{
/* Create a periodic timer running at 10 HZ. */
RTR0TESTR0_CHECK_RC_BREAK(RTTimerCreateEx(&pTimer, u10HzAsNs, fFlags, tstRTR0TimerCallbackU32Counter, &State),
{
RTThreadSleep(10);
break;
}
break;
}
{
/* create, start, stop & destroy high res timers a number of times. */
uint32_t fFlags = uOperation != TSTRTR0TIMER_PERIODIC_CSSD_LOOPS_HIRES ? RTTIMER_FLAGS_HIGH_RES : 0;
for (uint32_t i = 0; i < 40; i++)
{
RTR0TESTR0_CHECK_RC_BREAK(RTTimerCreateEx(&pTimer, cNsSysHz, fFlags, tstRTR0TimerCallbackU32Counter, &State),
for (uint32_t j = 0; j < 10; j++)
{
RTThreadSleep(1);
}
}
break;
}
}
/* The error indicator is the '!' in the message buffer. */
return VINF_SUCCESS;
}