VMMDevTesting.cpp revision dc31047bffe0f7c2dda50da6efe001e0cbf9a0a7
/* $Id$ */
/** @file
* VMMDev - Testing Extensions.
*
* To enable: VBoxManage setextradata vmname VBoxInternal/Devices/VMMDev/0/Config/TestingEnabled 1
*/
/*
* Copyright (C) 2010-2012 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.
*/
/*******************************************************************************
* Header Files *
*******************************************************************************/
#define LOG_GROUP LOG_GROUP_DEV_VMM
#ifdef IN_RING3
#endif
#include "VMMDevState.h"
#include "VMMDevTesting.h"
#ifndef VBOX_WITHOUT_TESTING_FEATURES
#define VMMDEV_TESTING_OUTPUT(a) \
do \
{ \
LogAlways(a);\
LogRel(a);\
RTPrintf a; \
} while (0)
/**
* @callback_method_impl{FNIOMMMIOWRITE}
*/
PDMBOTHCBDECL(int) vmmdevTestingMmioWrite(PPDMDEVINS pDevIns, void *pvUser, RTGCPHYS GCPhysAddr, void const *pv, unsigned cb)
{
switch (GCPhysAddr)
{
case VMMDEV_TESTING_MMIO_NOP:
switch (cb)
{
case 8:
case 4:
case 2:
case 1:
break;
default:
AssertFailed();
return VERR_INTERNAL_ERROR_5;
}
return VINF_SUCCESS;
default:
break;
}
return VINF_SUCCESS;
}
/**
* @callback_method_impl{FNIOMMMIOREAD}
*/
PDMBOTHCBDECL(int) vmmdevTestingMmioRead(PPDMDEVINS pDevIns, void *pvUser, RTGCPHYS GCPhysAddr, void *pv, unsigned cb)
{
switch (GCPhysAddr)
{
case VMMDEV_TESTING_MMIO_NOP:
switch (cb)
{
case 8:
break;
case 4:
break;
case 2:
break;
case 1:
break;
default:
AssertFailed();
return VERR_INTERNAL_ERROR_5;
}
return VINF_SUCCESS;
default:
break;
}
return VINF_IOM_MMIO_UNUSED_FF;
}
#ifdef IN_RING3
/**
* Executes the VMMDEV_TESTING_CMD_VALUE_REG command when the data is ready.
*
* @param pDevIns The PDM device instance.
* @param pThis The instance VMMDev data.
*/
{
if (pszRegNm)
{
*pszRegNm++ = '\0';
}
{
if (RT_SUCCESS(rc2))
{
#if 1 /*!RTTestValue format*/
if (RT_SUCCESS(rc2))
VMMDEV_TESTING_OUTPUT(("testing: VALUE '%s'%*s: %16s {reg=%s}%s\n",
else
#endif
VMMDEV_TESTING_OUTPUT(("testing: VALUE '%s'%*s: %'9llu (%#llx) [0] {reg=%s}%s\n",
}
else
VMMDEV_TESTING_OUTPUT(("testing: error querying register '%s' for value '%s': %Rrc\n",
}
else
}
#endif /* IN_RING3 */
/**
* @callback_method_impl{FNIOMIOPORTOUT}
*/
PDMBOTHCBDECL(int) vmmdevTestingIoWrite(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT Port, uint32_t u32, unsigned cb)
{
switch (Port)
{
/*
* The NOP I/O ports are used for performance measurements.
*/
switch (cb)
{
case 4:
case 2:
case 1:
break;
default:
AssertFailed();
return VERR_INTERNAL_ERROR_2;
}
return VINF_SUCCESS;
/* The timestamp I/O ports are read-only. */
break;
/*
* The command port (DWORD write only).
*/
if (cb == 4)
{
pThis->offTestingData = 0;
return VINF_SUCCESS;
}
break;
/*
* The data port. Used of providing data for a command.
*/
{
switch (uCmd)
{
case VMMDEV_TESTING_CMD_INIT:
&& cb == 1)
{
if (u32)
{
}
else
{
#ifdef IN_RING3
switch (uCmd)
{
case VMMDEV_TESTING_CMD_INIT:
VMMDEV_TESTING_OUTPUT(("testing: INIT '%.*s'\n",
break;
VMMDEV_TESTING_OUTPUT(("testing: SUB_NEW '%.*s'\n",
break;
VMMDEV_TESTING_OUTPUT(("testing: FAILED '%.*s'\n",
break;
VMMDEV_TESTING_OUTPUT(("testing: SKIPPED '%.*s'\n",
break;
}
#else
return VINF_IOM_R3_IOPORT_WRITE;
#endif
}
return VINF_SUCCESS;
}
break;
case VMMDEV_TESTING_CMD_TERM:
if ( off == 0
&& cb == 4)
{
#ifdef IN_RING3
if (uCmd == VMMDEV_TESTING_CMD_TERM)
else
return VINF_SUCCESS;
#else
return VINF_IOM_R3_IOPORT_WRITE;
#endif
}
break;
case VMMDEV_TESTING_CMD_VALUE:
if (cb == 4)
{
if (off == 0)
else if (off == 4)
else if (off == 8)
else
break;
return VINF_SUCCESS;
}
if ( off >= 12
&& cb == 1
{
if (u32)
{
}
else
{
#ifdef IN_RING3
VMMDEV_TESTING_OUTPUT(("testing: VALUE '%.*s'%*s: %'9llu (%#llx) [%u]\n",
#else
return VINF_IOM_R3_IOPORT_WRITE;
#endif
}
return VINF_SUCCESS;
#ifdef IN_RING3
if (uCmd == VMMDEV_TESTING_CMD_TERM)
else
return VINF_SUCCESS;
#else
return VINF_IOM_R3_IOPORT_WRITE;
#endif
}
break;
/*
* RTTestValue with the return from DBGFR3RegNmQuery.
*/
{
&& cb == 1)
{
if (u32)
else
#ifdef IN_RING3
#else
return VINF_IOM_R3_IOPORT_WRITE;
#endif
return VINF_SUCCESS;
}
break;
}
default:
break;
}
Log(("VMMDEV_TESTING_IOPORT_CMD: bad access; cmd=%#x off=%#x cb=%#x u32=%#x\n", uCmd, off, cb, u32));
return VINF_SUCCESS;
}
default:
break;
}
return VERR_IOM_IOPORT_UNUSED;
}
/**
* @callback_method_impl{FNIOMIOPORTIN}
*/
PDMBOTHCBDECL(int) vmmdevTestingIoRead(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT Port, uint32_t *pu32, unsigned cb)
{
switch (Port)
{
/*
* The NOP I/O ports are used for performance measurements.
*/
switch (cb)
{
case 4:
case 2:
case 1:
break;
default:
AssertFailed();
return VERR_INTERNAL_ERROR_2;
}
return VINF_SUCCESS;
/*
* The timestamp I/O ports are obviously used for getting a good fix
* on the current time (as seen by the host?).
*
* The high word is latched when reading the low, so reading low + high
* gives you a 64-bit timestamp value.
*/
if (cb == 4)
{
return VINF_SUCCESS;
}
break;
if (cb == 4)
{
return VINF_SUCCESS;
}
break;
/*
* The command and data registers are write-only.
*/
break;
default:
break;
}
return VERR_IOM_IOPORT_UNUSED;
}
#ifdef IN_RING3
/**
* Initializes the testing part of the VMMDev if enabled.
*
* @returns VBox status code.
* @param pDevIns The VMMDev device instance.
*/
{
if (!pThis->fTestingEnabled)
return VINF_SUCCESS;
/*
* Register a chunk of MMIO memory that we'll use for various
* tests interfaces.
*/
int rc = PDMDevHlpMMIORegister(pDevIns, VMMDEV_TESTING_MMIO_BASE, VMMDEV_TESTING_MMIO_SIZE, NULL /*pvUser*/,
if (pThis->fRZEnabled)
{
rc = PDMDevHlpMMIORegisterR0(pDevIns, VMMDEV_TESTING_MMIO_BASE, VMMDEV_TESTING_MMIO_SIZE, NIL_RTR0PTR /*pvUser*/,
"vmmdevTestingMmioWrite", "vmmdevTestingMmioRead");
rc = PDMDevHlpMMIORegisterRC(pDevIns, VMMDEV_TESTING_MMIO_BASE, VMMDEV_TESTING_MMIO_SIZE, NIL_RTRCPTR /*pvUser*/,
"vmmdevTestingMmioWrite", "vmmdevTestingMmioRead");
}
/*
* Register the I/O ports used for testing.
*/
rc = PDMDevHlpIOPortRegister(pDevIns, VMMDEV_TESTING_IOPORT_BASE, VMMDEV_TESTING_IOPORT_COUNT, NULL,
NULL /*pfnOutStr*/,
NULL /*pfnInStr*/,
"VMMDev Testing");
if (pThis->fRZEnabled)
{
rc = PDMDevHlpIOPortRegisterR0(pDevIns, VMMDEV_TESTING_IOPORT_BASE, VMMDEV_TESTING_IOPORT_COUNT, NIL_RTR0PTR /*pvUser*/,
"vmmdevTestingIoWrite",
"vmmdevTestingIoRead",
NULL /*pszOutStr*/,
NULL /*pszInStr*/,
"VMMDev Testing");
rc = PDMDevHlpIOPortRegisterRC(pDevIns, VMMDEV_TESTING_IOPORT_BASE, VMMDEV_TESTING_IOPORT_COUNT, NIL_RTRCPTR /*pvUser*/,
"vmmdevTestingIoWrite",
"vmmdevTestingIoRead",
NULL /*pszOutStr*/,
NULL /*pszInStr*/,
"VMMDev Testing");
}
return VINF_SUCCESS;
}
#endif /* IN_RING3 */
#endif /* !VBOX_WITHOUT_TESTING_FEATURES */