tstRTStrCache.cpp revision e00b7e275dee70ffbd9e00a3e3e3e8513287e2b2
/* $Id$ */
/** @file
* IPRT Testcase - StrCache.
*/
/*
* 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/strcache.h>
#include <iprt/initterm.h>
{
if (cbStrings == UINT32_MAX)
{
return;
}
RTTestIValue("Memory overhead", (uint64_t)(cbChunks + cbBigEntries - cbStrings) * 100 / cbStrings, RTTESTUNIT_PCT);
if (cHashInserts > 0)
{
}
RTTestIPrintf(RTTESTLVL_ALWAYS, "cHashInserts=%u cHashCollisions=%u cHashCollisions2=%u cRehashes=%u\n",
RTTestIPrintf(RTTESTLVL_ALWAYS, "cbChunks=%zu cbBigEntries=%zu cbStrings=%zu\n", cbChunks, cbBigEntries, cbStrings);
}
/**
* Check hash and memory performance.
*/
static void tst2(void)
{
RTTestISub("Hash performance");
/*
* Generate test strings using a specific pseudo random generator.
*/
char *apszTests[8192];
for (uint32_t i = 0; i < 8192; i++)
{
char szBuf[8192];
{
b &= 0x7f;
if (!b || b == 0x7f)
b = ' ';
b += 0x30;
}
}
/*
* Test new insertion first time around.
*/
/*
* Insert existing strings.
*/
nsTsStart = RTTimeNanoTS();
for (uint32_t i = 0; i < 8192; i++)
}
/**
* Basic API checks.
* We'll return if any of these fails.
*/
{
const char *psz;
/* Simple string entering and length. */
/* Unterminated strings. */
/* String referencing. */
{
void *pv2;
RTTESTI_CHECK_MSG_RETV((pv2 = ASMMemIsAll8(psz, i, 'a')) == NULL && !psz[i], ("i=%#x psz=%p off=%#x\n", i, psz, (uintptr_t)pv2 - (uintptr_t)psz));
RTTESTI_CHECK_MSG_RETV((pv2 = ASMMemIsAll8(psz, i, 'a')) == NULL && !psz[i], ("i=%#x psz=%p off=%#x\n", i, psz, (uintptr_t)pv2 - (uintptr_t)psz));
RTTESTI_CHECK_MSG_RETV((pv2 = ASMMemIsAll8(psz, i, 'a')) == NULL && !psz[i], ("i=%#x psz=%p off=%#x\n", i, psz, (uintptr_t)pv2 - (uintptr_t)psz));
RTTESTI_CHECK_MSG_RETV((pv2 = ASMMemIsAll8(psz, i, 'a')) == NULL && !psz[i], ("i=%#x psz=%p off=%#x\n", i, psz, (uintptr_t)pv2 - (uintptr_t)psz));
{
if (cRefs == 0)
break;
RTTESTI_CHECK_MSG_RETV((pv2 = ASMMemIsAll8(psz, i, 'a')) == NULL && !psz[i], ("i=%#x psz=%p off=%#x cRefs=%d\n", i, psz, (uintptr_t)pv2 - (uintptr_t)psz, cRefs));
for (uint32_t j = 0; j < 42; j++)
{
const char *psz2;
RTTESTI_CHECK_MSG_RETV((pv2 = ASMMemIsAll8(psz, i, 'a')) == NULL && !psz[i], ("i=%#x psz=%p off=%#x cRefs=%d\n", i, psz, (uintptr_t)pv2 - (uintptr_t)psz, cRefs));
}
}
}
/* Lots of allocations. */
{
}
if (RTStrCacheIsRealImpl())
{
{
RTTESTI_CHECK_MSG((cRefs = RTStrCacheRelease(hStrCache, psz1)) == 1, ("cRefs=%#x i=%#x\n", cRefs, i));
RTTESTI_CHECK_MSG((cRefs = RTStrCacheRelease(hStrCache, psz2)) == 1, ("cRefs=%#x i=%#x\n", cRefs, i));
}
}
{
RTTESTI_CHECK_MSG((cRefs = RTStrCacheRelease(hStrCache, pszTest1Rets[i])) == 0, ("cRefs=%#x i=%#x\n", cRefs, i));
RTTESTI_CHECK_MSG((cRefs = RTStrCacheRelease(hStrCache, pszTest2Rets[i])) == 0, ("cRefs=%#x i=%#x\n", cRefs, i));
}
}
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))
{
}
/*
* Cache performance on relatively real world examples.
*/
tst2();
/*
* Summary.
*/
return RTTestSummaryAndDestroy(hTest);
}