tstRTPrfIO.cpp revision 577af8ad2e80ab546ca4efcf024ed53e5155a73d
/* $Id$ */
/** @file
* IPRT Testcase - Profile IPRT I/O APIs.
*/
/*
* Copyright (C) 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 *
*******************************************************************************/
/*******************************************************************************
* Global Variables *
*******************************************************************************/
/** The test instance handle. */
/** The max number of nanoseconds to benchmark an operation. */
/** The max operation count. */
/** The path to the test directory. */
static const char *g_pszTestDir = ".";
/** The path to the primary test file. */
static char g_szTestFile1[RTPATH_MAX];
/** The path to the primary test directory. */
static char g_szTestDir1[RTPATH_MAX];
/** The path to a nonexistent file in an existing directory. */
static char g_szNotExitingFile[RTPATH_MAX];
/** The path to a nonexistent directory. */
static char g_szNotExitingDir[RTPATH_MAX];
/** The path to a nonexistent file in a nonexistent directory. */
static char g_szNotExitingDirFile[RTPATH_MAX];
/*******************************************************************************
* Defined Constants And Macros *
*******************************************************************************/
/**
* Benchmark an operation.
* @param stmt Statement to benchmark.
* @param what String litteral describing what's being benchmarked..
*/
do \
{ \
/* warm-up */ \
stmt; \
stmt; \
\
/* the real thing */ \
uint64_t cNsElapsed = 0; \
for (;;) \
{ \
stmt; \
cOps++; \
{ \
break; \
} \
} \
RTTestValue(g_hTest, what " cps", UINT64_C(10000000000) / (cNsElapsed * 10 / cOps), RTTESTUNIT_CALLS_PER_SEC); \
} while (0)
static void benchmarkPathQueryInfo(void)
{
RTTESTI_CHECK_RC_RETV(RTPathQueryInfo(g_szNotExitingFile, &ObjInfo, RTFSOBJATTRADD_NOTHING), VERR_FILE_NOT_FOUND);
TIME_OP(RTPathQueryInfo(g_szNotExitingFile, &ObjInfo, RTFSOBJATTRADD_NOTHING), "RTPathQueryInfo(g_szNotExitingFile)");
TIME_OP(RTPathQueryInfo(g_szNotExitingDirFile, &ObjInfo, RTFSOBJATTRADD_NOTHING), "RTPathQueryInfo(g_szNotExitingDirFile)");
RTTESTI_CHECK_RC_RETV(RTPathQueryInfo(g_pszTestDir, &ObjInfo, RTFSOBJATTRADD_NOTHING), VINF_SUCCESS);
TIME_OP(RTPathQueryInfo(g_pszTestDir, &ObjInfo, RTFSOBJATTRADD_NOTHING), "RTPathQueryInfo(g_pszTestDir)");
TIME_OP(RTPathQueryInfo(g_pszTestDir, &ObjInfo, RTFSOBJATTRADD_UNIX), "RTPathQueryInfo(g_pszTestDir,UNIX)");
}
{
if (RT_SUCCESS(rc))
return rc;
}
static void benchmarkFileOpenClose(void)
{
}
static void benchmarkFileWriteByte(void)
{
| (0655 << RTFILE_O_CREATE_MODE_SHIFT)),
static const char s_szContent[] = "0123456789abcdef";
uint32_t offContent = 0;
int rc;;
RTTESTI_CHECK_RC(rc = RTFileWrite(hFile, &s_szContent[offContent++ % RT_ELEMENTS(s_szContent)], 1, NULL), VINF_SUCCESS);
if (RT_SUCCESS(rc))
{
TIME_OP(RTFileWrite(hFile, &s_szContent[offContent++ % RT_ELEMENTS(s_szContent)], 1, NULL), "RTFileWrite(byte)");
}
}
{
if (rcExit != RTEXITCODE_SUCCESS)
return rcExit;
/*
* Parse arguments
*/
static const RTGETOPTDEF s_aOptions[] =
{
};
bool fFileOpenCloseTest = true;
bool fFileWriteByteTest = true;
bool fPathQueryInfoTest = true;
//bool fFileTests = true;
//bool fDirTests = true;
int ch;
{
switch (ch)
{
case 'd':
break;
case 'V':
return RTTestSummaryAndDestroy(g_hTest);
case 'h':
return RTTestSummaryAndDestroy(g_hTest);
default:
return RTTestSummaryAndDestroy(g_hTest);
}
}
/*
* Set up and check the prerequisites.
*/
RTTESTI_CHECK_RC(RTPathJoin(g_szTestFile1, sizeof(g_szTestFile1), g_pszTestDir, "tstRTPrfIO-TestFile1"), VINF_SUCCESS);
RTTESTI_CHECK_RC(RTPathJoin(g_szTestDir1, sizeof(g_szTestDir1), g_pszTestDir, "tstRTPrfIO-TestDir1"), VINF_SUCCESS);
RTTESTI_CHECK_RC(RTPathJoin(g_szNotExitingFile, sizeof(g_szNotExitingFile), g_pszTestDir, "tstRTPrfIO-nonexistent-file"), VINF_SUCCESS);
RTTESTI_CHECK_RC(RTPathJoin(g_szNotExitingDir, sizeof(g_szNotExitingDir), g_pszTestDir, "tstRTPrfIO-nonexistent-dir"), VINF_SUCCESS);
RTTESTI_CHECK_RC(RTPathJoin(g_szNotExitingDirFile, sizeof(g_szNotExitingDirFile), g_szNotExitingDir, "nonexistent-file"), VINF_SUCCESS);
if (RTPathExists(g_szTestDir1))
RTTestFailed(g_hTest, "The primary test directory (%s) already exist, please remove it", g_szTestDir1);
if (RTPathExists(g_szTestFile1))
/*
* Do the testing.
*/
if (RTTestIErrorCount() == 0)
{
#if 1
if (fPathQueryInfoTest)
if (fFileOpenCloseTest)
#endif
if (fFileWriteByteTest)
//if (fFileTests)
// benchmarkFile();
//if (fDirTests)
// benchmarkDir();
/*
* Cleanup.
*/
}
return RTTestSummaryAndDestroy(g_hTest);
}