tstMMHyperHeap.cpp revision 9d805e5fdc5c2254d518988f5c12532b8cd00d14
/* $Id$ */
/** @file
* MM Hypervisor Heap testcase.
*/
/*
* Copyright (C) 2006-2007 innotek 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.
*/
/*******************************************************************************
* Header Files *
*******************************************************************************/
{
/*
* Init runtime.
*/
RTR3Init();
/*
* Create empty VM structure and call MMR3Init().
*/
if (VBOX_SUCCESS(rc))
if (VBOX_FAILURE(rc))
{
return 1;
}
if (VBOX_FAILURE(rc))
{
return 1;
}
if (VBOX_FAILURE(rc))
{
return 1;
}
/*
* Try allocate.
*/
static struct
{
unsigned uAlignment;
void *pvAlloc;
unsigned iFreeOrder;
} aOps[] =
{
{ 16, 0, NULL, 0 },
};
unsigned i;
#ifdef DEBUG
#endif
static char szFill[] = "01234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
/* allocate */
{
if (VBOX_FAILURE(rc))
{
return 1;
}
{
RTPrintf("Failure: MMHyperAlloc(, %#x, %#x,) -> %p, invalid alignment!\n", aOps[i].cb, aOps[i].uAlignment, aOps[i].pvAlloc);
return 1;
}
}
/* free and allocate the same node again. */
{
continue;
//size_t cbBeforeSub = MMHyperHeapGetFreeSize(pVM);
if (VBOX_FAILURE(rc))
{
return 1;
}
//RTPrintf("debug: i=%d cbBeforeSub=%d now=%d\n", i, cbBeforeSub, MMHyperHeapGetFreeSize(pVM));
void *pv;
if (VBOX_FAILURE(rc))
{
return 1;
}
{
RTPrintf("Failure: Free+Alloc returned different address. new=%p old=%p i=%d (doesn't work with delayed free)\n", pv, aOps[i].pvAlloc, i);
//return 1;
}
#if 0 /* won't work :/ */
if (cbBeforeSub != cbAfterSub)
{
return 1;
}
#endif
}
/* free it in a specific order. */
int cFreed = 0;
{
unsigned j;
{
if ( aOps[j].iFreeOrder != i
continue;
RTPrintf("j=%d i=%d free=%d cb=%d pv=%p\n", j, i, MMHyperHeapGetFreeSize(pVM), aOps[j].cb, aOps[j].pvAlloc);
else
{
if (VBOX_FAILURE(rc))
{
return 1;
}
}
cFreed++;
}
}
/* check that we're back at the right amount of free memory. */
{
RTPrintf("Warning: Either we've split out an alignment chunk at the start, or we've got\n"
#ifdef DEBUG
#endif
}
RTPrintf("tstMMHyperHeap: Success\n");
#ifdef LOG_ENABLED
#endif
return 0;
}