tstRTFileAio.cpp revision 10d739d22a5d5a13803f7e34de34de010099270c
/* $Id$ */
/** @file
* IPRT Testcase - File Async I/O.
*/
/*
* Copyright (C) 2006-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 *
*******************************************************************************/
/*******************************************************************************
* Defined Constants And Macros *
*******************************************************************************/
/** @todo make configurable through cmd line. */
#define TSTFILEAIO_MAX_REQS_IN_FLIGHT 64
/*******************************************************************************
* Global Variables *
*******************************************************************************/
{
/* Allocate request array. */
/* Allocate array holding pointer to data buffers. */
/* Allocate the buffers*/
for (unsigned i = 0; i < cMaxReqsInFlight; i++)
{
RTTESTI_CHECK_RC_OK_RETV(RTTestGuardedAlloc(g_hTest, cbTestBuf, PAGE_SIZE, true /*fHead*/, &papvBuf[i]));
if (fWrite)
if (fWrite)
else
}
/* Allocate array holding completed requests. */
paReqsCompleted = (PRTFILEAIOREQ)RTTestGuardedAllocHead(g_hTest, cMaxReqsInFlight * sizeof(RTFILEAIOREQ));
/* Create a context and associate the file handle with it. */
RTTESTI_CHECK_RC_RETV(RTFileAioCtxCreate(&hAioContext, cMaxReqsInFlight, 0 /* fFlags */), VINF_SUCCESS);
/* Initialize requests. */
for (unsigned i = 0; i < cMaxReqsInFlight; i++)
RTFileAioReqCreate(&paReqs[i]);
int cRuns = 0;
while (cbLeft)
{
int rc;
int cReqs = 0;
for (unsigned i = 0; i < cMaxReqsInFlight; i++)
{
if (!cbTransfer)
break;
if (fWrite)
cbTransfer, papvBuf[i]);
else
cbTransfer, papvBuf[i]);
cbLeft -= cbTransfer;
off += cbTransfer;
cReqs++;
}
RTTESTI_CHECK_MSG(rc == VINF_SUCCESS, ("Failed to submit tasks after %d runs. rc=%Rrc\n", cRuns, rc));
if (rc != VINF_SUCCESS)
break;
/* Wait */
uint32_t cCompleted = 0;
if (rc != VINF_SUCCESS)
break;
if (!fWrite)
{
for (uint32_t i = 0; i < cCompleted; i++)
{
/* Compare that we read the right stuff. */
if (rc != VINF_SUCCESS)
break;
RTTESTI_CHECK_RC_OK(rc = (memcmp(pvBuf, pvTestBuf, cbTestBuf) == 0 ? VINF_SUCCESS : VERR_BAD_EXE_FORMAT));
if (rc != VINF_SUCCESS)
break;
}
}
cRuns++;
if (RT_FAILURE(rc))
break;
}
/* cleanup */
for (unsigned i = 0; i < cMaxReqsInFlight; i++)
for (unsigned i = 0; i < cMaxReqsInFlight; i++)
}
int main()
{
if (rc)
return rc;
/* Check if the API is available. */
if (RT_SUCCESS(rc))
{
if (RT_SUCCESS(rc))
{
for (unsigned i = 0; i < TSTFILEAIO_BUFFER_SIZE; i++)
pbTestBuf[i] = i % 256;
/* Basic write test. */
RTTestIPrintf(RTTESTLVL_ALWAYS, "Preparing test file, this can take some time and needs quite a bit of harddisk space...\n");
tstFileAioTestReadWriteBasic(hFile, true /*fWrite*/, pbTestBuf, TSTFILEAIO_BUFFER_SIZE, 100*_1M, cReqsMax);
/* Reopen the file before doing the next test. */
if (RTTestErrorCount(g_hTest) == 0)
{
if (RT_SUCCESS(rc))
{
tstFileAioTestReadWriteBasic(hFile, false /*fWrite*/, pbTestBuf, TSTFILEAIO_BUFFER_SIZE, 100*_1M, cReqsMax);
}
}
/* Cleanup */
RTFileDelete("tstFileAio#1.tst");
}
}
/*
* Summary
*/
return RTTestSummaryAndDestroy(g_hTest);
}