tstRTMemPool.cpp revision c7814cf6e1240a519cbec0441e033d0e2470ed00
/* $Id$ */
/** @file
* IPRT Testcase - MemPool.
*/
/*
* 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 <iprt/initterm.h>
/*******************************************************************************
* Global Variables *
*******************************************************************************/
/** The test handle */
/** Memory pool for tst4. */
static RTMEMPOOL g_hMemPool4;
/**
* Basic API checks.
* We'll return if any of these fails.
*/
{
void *pv;
/* Normal alloc. */
/* Zeroed allocation. */
for (uint32_t i = 0; i < 512; i++)
{
}
/* Duped allocation. */
static const char szTest[] = "test string abcdef";
for (uint32_t i = 0; i < 512; i++)
{
}
/* Reallocation */
/* Free (a bit hard to test) */
/* Memory referencing. */
{
void *pv2;
RTTESTI_CHECK_MSG_RETV((pv2 = ASMMemIsAll8(pv, i, 'a')) == NULL, ("i=%#x pv=%p off=%#x\n", i, pv, (uintptr_t)pv2 - (uintptr_t)pv));
RTTESTI_CHECK_MSG_RETV((pv2 = ASMMemIsAll8(pv, i, 'a')) == NULL, ("i=%#x pv=%p off=%#x\n", i, pv, (uintptr_t)pv2 - (uintptr_t)pv));
RTTESTI_CHECK_MSG_RETV((pv2 = ASMMemIsAll8(pv, i, 'a')) == NULL, ("i=%#x pv=%p off=%#x\n", i, pv, (uintptr_t)pv2 - (uintptr_t)pv));
RTTESTI_CHECK_MSG_RETV((pv2 = ASMMemIsAll8(pv, i, 'a')) == NULL, ("i=%#x pv=%p off=%#x\n", i, pv, (uintptr_t)pv2 - (uintptr_t)pv));
{
if (cRefs == 0)
break;
RTTESTI_CHECK_MSG_RETV((pv2 = ASMMemIsAll8(pv, i, 'a')) == NULL, ("i=%#x pv=%p off=%#x cRefs=%d\n", i, pv, (uintptr_t)pv2 - (uintptr_t)pv, cRefs));
for (uint32_t j = 0; j < 42; j++)
{
RTTESTI_CHECK_MSG_RETV((pv2 = ASMMemIsAll8(pv, i, 'a')) == NULL, ("i=%#x pv=%p off=%#x cRefs=%d\n", i, pv, (uintptr_t)pv2 - (uintptr_t)pv, cRefs));
}
}
}
}
/**
* Test automatic cleanup upon destruction.
*/
static void tst3(void)
{
RTTestISub("Destroy non-empty pool");
/*
* Nothing freed.
*/
/*
* Pseudo random freeing to test list maintenance.
*/
for (uint32_t i = 0; i < 10; i++)
{
void *apvHistory[256];
uint32_t j;
{
cBlocks++;
{
}
}
}
}
/** Thread function for tst4. */
{
// uint32_t iThread = (uint32_t)(uintptr_t)pvArg;
/* setup. */
/* wait for the kick-off */
/* do the work. */
for (uint32_t i = 0; i < 1024; i++)
{
void *apvHistory[256];
uint32_t j;
{
apvHistory[k] = NULL;
}
while (j-- > 0)
}
return VINF_SUCCESS;
}
/** sub test */
{
if (pahThreads)
{
/* start them. */
{
if (RT_FAILURE(rc))
pahThreads[i] = NIL_RTTHREAD;
}
/* kick them off. */
if (pahThreads[i] != NIL_RTTHREAD)
/* wait for them. */
if (pahThreads[i] != NIL_RTTHREAD)
{
}
}
}
/**
* Starts a bunch of threads beating on a pool to test serialization.
*/
static void tst4(void)
{
/*
* Test it with a few different thread counts.
*/
tst4Sub(1);
tst4Sub(2);
tst4Sub(3);
tst4Sub(4);
tst4Sub(8);
tst4Sub(16);
}
int main()
{
if (rc)
return rc;
/*
* Smoke tests using first the default and then a custom pool.
*/
if (RT_SUCCESS(rc))
if (RT_SUCCESS(rc))
{
}
/*
* Further tests.
*/
tst3();
tst4();
/*
* Summary.
*/
return RTTestSummaryAndDestroy(hTest);
}