tstRTR0Timer.cpp revision 9c9e7c794214b652d4bc5e3a5035466cee2fd1cc
f131ef75fa02edc15fdbfbc2a411af571378bbb8jeff.schenk * IPRT R0 Testcase - Timers.
f131ef75fa02edc15fdbfbc2a411af571378bbb8jeff.schenk * Copyright (C) 2009-2010 Oracle Corporation
f131ef75fa02edc15fdbfbc2a411af571378bbb8jeff.schenk * This file is part of VirtualBox Open Source Edition (OSE), as
2aae7e94be9f6416f608cf440caa9d20f78e415cjeff.schenk * available from http://www.virtualbox.org. This file is free software;
2aae7e94be9f6416f608cf440caa9d20f78e415cjeff.schenk * you can redistribute it and/or modify it under the terms of the GNU
f131ef75fa02edc15fdbfbc2a411af571378bbb8jeff.schenk * General Public License (GPL) as published by the Free Software
2aae7e94be9f6416f608cf440caa9d20f78e415cjeff.schenk * Foundation, in version 2 as it comes in the "COPYING" file of the
2aae7e94be9f6416f608cf440caa9d20f78e415cjeff.schenk * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
f131ef75fa02edc15fdbfbc2a411af571378bbb8jeff.schenk * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
ecea4eb851b7bf19e9ef392650522a12eec40a2bjeff.schenk * The contents of this file may alternatively be used under the terms
ecea4eb851b7bf19e9ef392650522a12eec40a2bjeff.schenk * of the Common Development and Distribution License Version 1.0
a80372a94915b87ad91eae67a48214b8a04fb95djeff.schenk * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
4737d44107f8f497c938801238d1d5269b30ea59jeff.schenk * VirtualBox OSE distribution, in which case the provisions of the
f131ef75fa02edc15fdbfbc2a411af571378bbb8jeff.schenk * CDDL are applicable instead of those of the GPL.
#include "tstRTR0Timer.h"
#include "tstRTR0Common.h"
int volatile rc;
bool fPeriodic;
bool fDirection;
} ChgInt;
bool fFailed;
} Specific;
typedef struct TSTRTR0TIMEROMNI1
RTR0TESTR0_CHECK_MSG(iCountedTick == 1, ("iCountedTick=%u iCpu=%d idCpu=%u\n", iCountedTick, iCpu, idCpu));
static DECLCALLBACK(void) tstRTR0TimerCallbackSpecific(PRTTIMER pTimer, void *pvUser, uint64_t iTick)
RTR0TESTR0_CHECK_MSG(pState->u.Specific.idCpu == idCpu, ("idCpu=%u, expected %u\n", idCpu, pState->u.Specific.idCpu));
static DECLCALLBACK(void) tstRTR0TimerCallbackChangeInterval(PRTTIMER pTimer, void *pvUser, uint64_t iTick)
static DECLCALLBACK(void) tstRTR0TimerCallbackDestroyOnce(PRTTIMER pTimer, void *pvUser, uint64_t iTick)
static DECLCALLBACK(void) tstRTR0TimerCallbackRestartOnce(PRTTIMER pTimer, void *pvUser, uint64_t iTick)
static DECLCALLBACK(void) tstRTR0TimerCallbackU32Counter(PRTTIMER pTimer, void *pvUser, uint64_t iTick)
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);
static int tstRTR0TimerCheckShotIntervals(PTSTRTR0TIMERS1 pState, uint64_t uStartNsTS, uint32_t uMin, uint32_t uMax)
return cBadShots;
RTR0TESTR0_CHECK_MSG(cNsSysHz > UINT32_C(1000) && cNsSysHz < UINT32_C(1000000000), ("%u", cNsSysHz));
RTR0TESTR0_CHECK_MSG(cNsMaxHighResHz > UINT32_C(1) && cNsMaxHighResHz < UINT32_C(1000000000), ("%u", cNsMaxHighResHz));
return VINF_SUCCESS;
switch (uOperation)
RTR0TESTR0_CHECK_RC_BREAK(RTTimerCreateEx(&pTimer, 0, fFlags, tstRTR0TimerCallbackU32Counter, &State),
RTR0TESTR0_CHECK_RC_BREAK(RTTimerCreateEx(&pTimer, 0, fFlags, tstRTR0TimerCallbackRestartOnce, &State),
RTR0TESTR0_CHECK_RC_BREAK(RTTimerCreateEx(&pTimer, 0, fFlags, tstRTR0TimerCallbackDestroyOnce, &State),
RTR0TESTR0_CHECK_RC_BREAK(RTTimerStart(pTimer, (i & 2 ? cNsSysHz : cNsSysHz / 2) * (i & 1)), VINF_SUCCESS);
if (RTR0TestR0HaveErrors())
RTR0TESTR0_CHECK_RC_BREAK(RTTimerCreateEx(&pTimer, u10HzAsNs, fFlags, tstRTR0TimerCallbackU32Counter, &State),
RTR0TESTR0_CHECK_RC_BREAK(RTTimerCreateEx(&pTimer, cNsSysHz, fFlags, tstRTR0TimerCallbackU32Counter, &State),
State.u.ChgInt.cNsChangeStep = (State.u.ChgInt.cNsMaxInterval - State.u.ChgInt.cNsMinInterval) / 10;
RTR0TESTR0_CHECK_MSG_BREAK(State.u.ChgInt.cNsMinInterval > 1000, ("%u\n", State.u.ChgInt.cNsMinInterval));
RTR0TESTR0_CHECK_MSG_BREAK(State.u.ChgInt.cNsMaxInterval > State.u.ChgInt.cNsMinInterval, ("max=%u min=%u\n", State.u.ChgInt.cNsMaxInterval, State.u.ChgInt.cNsMinInterval));
RTR0TESTR0_CHECK_RC_BREAK(RTTimerCreateEx(&pTimer, cNsSysHz, fFlags, tstRTR0TimerCallbackChangeInterval, &State),
RTR0TESTR0_CHECK_RC_BREAK(RTTimerStart(pTimer, u64Arg & 2 ? State.u.ChgInt.cNsCurInterval : 0), VINF_SUCCESS);
for (uint32_t k = 0;
RTR0TESTR0_CHECK_MSG_BREAK(rc == VERR_TIMER_SUSPENDED || rc == VINF_SUCCESS, ("rc = %Rrc (RTTimerStop)\n", rc));
RTR0TESTR0_CHECK_RC_BREAK(RTTimerStart(pTimer, (i & 2 ? cNsSysHz : cNsSysHz / 2) * (i & 1)), VINF_SUCCESS);
if (RTR0TestR0HaveErrors())
PTSTRTR0TIMEROMNI1 paStates = (PTSTRTR0TIMEROMNI1)RTMemAllocZ(sizeof(paStates[0]) * RTCPUSET_MAX_CPUS);
RTR0TESTR0_CHECK_RC_BREAK(RTTimerCreateEx(&pTimer, cNsInterval, fFlags, tstRTR0TimerCallbackOmni, paStates),
return VINF_SUCCESS;