tstRand.cpp revision 804eb59e2e0ce9f35874edada7e5c643647193d4
/* $Id$ */
/** @file
* IPRT - Testcase for the RTRand API.
*/
/*
* Copyright (C) 2008 Sun Microsystems, Inc.
*
* 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.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
* Clara, CA 95054 USA or visit http://www.sun.com if you need
* additional information or have any questions.
*/
/*******************************************************************************
* Header Files *
*******************************************************************************/
#include <iprt/initterm.h>
/*******************************************************************************
* Structures and Typedefs *
*******************************************************************************/
typedef struct TSTMEMAUTOPTRSTRUCT
{
uint32_t a;
uint32_t b;
uint32_t c;
/*******************************************************************************
* Defined Constants And Macros *
*******************************************************************************/
#define CHECK_EXPR(expr) \
do { bool const f = !!(expr); if (RT_UNLIKELY(!f)) { RTPrintf("tstRand(%d): %s!\n", __LINE__, #expr); g_cErrors++; } } while (0)
do { \
bool const f = !!(expr); \
if (RT_UNLIKELY(!f)) { \
RTPrintf("tstRand: "); \
} \
} while (0)
#define TST_RAND_SAMPLE_RANGES 16
/*******************************************************************************
* Global Variables *
*******************************************************************************/
static unsigned g_cErrors = 0;
{
RTPrintf("tstRand:");
{
}
RTPrintf(" min=%RX32 (%%%d) max=%RX32 (%%%d) calc avg=%RX32 [test=%d]\n",
iAvg,
iTest);
}
int main()
{
RTR3Init(false);
RTPrintf("tstRand: TESTING...\n");
/*
* Do some smoke tests first?
*/
/** @todo RTRand smoke testing. */
/*
* Test distribution.
*/
#if 1
/* unsigned 32-bit */
static const struct
{
} s_aU32Tests[] =
{
{ 0, UINT32_MAX },
{ 0, UINT32_MAX / 2 },
{ 0, TST_RAND_SAMPLE_RANGES - 1 },
};
{
RTPrintf("tstRand: TESTING RTRandU32Ex(%#RX32, %#RX32) distribution... [div=%#RX32 range=%#RX32]\n", uFirst, uLast, uDivisor, uRange);
{
}
}
#endif
#if 1
/* unsigned 64-bit */
static const struct
{
} s_aU64Tests[] =
{
{ 0, UINT64_MAX },
{ 0, UINT64_MAX / 2 },
{ 0, UINT32_MAX },
{ 0, UINT32_MAX / 2 },
{ 0, TST_RAND_SAMPLE_RANGES - 1 },
};
{
RTPrintf("tstRand: TESTING RTRandU64Ex(%#RX64, %#RX64) distribution... [div=%#RX64 range=%#RX64]\n", uFirst, uLast, uDivisor, uRange);
{
}
}
#endif
#if 1
/* signed 32-bit */
static const struct
{
} s_aS32Tests[] =
{
{ -429496729, 429496729 },
{ -0x20000000, INT32_MAX },
{ -0x10000000, INT32_MAX },
{ -0x080000000, INT32_MAX },
{ -0x008000000, INT32_MAX },
{ -0x000800000, INT32_MAX },
{ -0x000080000, INT32_MAX },
{ -0x000008000, INT32_MAX },
{ 0, TST_RAND_SAMPLE_RANGES - 1 },
};
{
RTPrintf("tstRand: TESTING RTRandS32Ex(%#RI32, %#RI32) distribution... [div=%#RX32 range=%#RX32]\n", iFirst, iLast, uDivisor, uRange);
{
}
}
#endif
#if 1
/* signed 64-bit */
static const struct
{
} s_aS64Tests[] =
{
{ -0x20000000, INT32_MAX },
{ -0x10000000, INT32_MAX },
{ -0x7f000000, INT32_MAX },
{ -0x08000000, INT32_MAX },
{ -0x00800000, INT32_MAX },
{ -0x00080000, INT32_MAX },
{ -0x00008000, INT32_MAX },
{ 0, TST_RAND_SAMPLE_RANGES - 1 },
};
{
RTPrintf("tstRand: TESTING RTRandS64Ex(%#RI64, %#RI64) distribution... [div=%#RX64 range=%#016RX64]\n", iFirst, iLast, uDivisor, uRange);
{
}
}
#endif
/*
* Summary.
*/
if (!g_cErrors)
RTPrintf("tstRand: SUCCESS\n");
else
return !!g_cErrors;
}