tstFileAio.cpp revision be196d173cf52fa33016912e4745dbe1170ac53a
/* $Id$ */
/** @file
* IPRT Testcase - File Async I/O.
*/
/*
* Copyright (C) 2006-2007 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>
/** @todo make configurable through cmd line. */
#define TSTFILEAIO_MAX_REQS_IN_FLIGHT 64
/* Global error counter. */
int cErrors = 0;
void tstFileAioTestReadWriteBasic(RTFILE File, bool fWrite, void *pvTestBuf, size_t cbTestBuf, size_t cbTestFile, uint32_t cMaxReqsInFlight)
{
int rc = VINF_SUCCESS;
if (RT_SUCCESS(rc))
{
int cRun = 0;
/* Allocate request array. */
if (paReqs)
{
/* Allocate array holding pointer to data buffers. */
if (papvBuf)
{
/* Allocate array holding completed requests. */
if (paReqsCompleted)
{
/* Associate file with context.*/
if (RT_SUCCESS(rc))
{
/* Initialize buffers. */
for (unsigned i = 0; i < cMaxReqsInFlight; i++)
{
if (fWrite)
}
/* Initialize requests. */
for (unsigned i = 0; i < cMaxReqsInFlight; i++)
RTFileAioReqCreate(&paReqs[i]);
while (cbLeft)
{
int cReqs = 0;
for (unsigned i = 0; i < cMaxReqsInFlight; i++)
{
if (!cbTransfer)
break;
if (fWrite)
cbTransfer, papvBuf[i]);
else
cbTransfer, papvBuf[i]);
cbLeft -= cbTransfer;
Offset += cbTransfer;
cReqs++;
}
if (RT_FAILURE(rc))
{
cErrors++;
break;
}
/* Wait */
uint32_t cCompleted = 0;
&cCompleted);
if (RT_FAILURE(rc))
{
cErrors++;
break;
}
if (!fWrite)
{
for (uint32_t i = 0; i < cCompleted; i++)
{
/* Compare that we read the right stuff. */
{
RTPrintf("tstFileAio: FATAL ERROR - Request %d failed with rc=%Rrc cbTransfered=%d.\n",
i, rcReq, cbTransfered);
cErrors++;
break;
}
{
RTPrintf("tstFileAio: FATAL ERROR - Unexpected content in memory.\n");
cErrors++;
break;
}
}
}
cRun++;
if (RT_FAILURE(rc))
break;
}
/* Free buffers. */
for (unsigned i = 0; i < cMaxReqsInFlight; i++)
RTMemPageFree(papvBuf[i]);
/* Free requests. */
for (unsigned i = 0; i < cMaxReqsInFlight; i++)
{
if (RT_FAILURE(rc))
{
cErrors++;
}
}
SpeedKBs / 1000,
SpeedKBs % 1000);
}
else
{
RTPrintf("tstFileAio: FATAL ERROR - Failed to asssociate file with async I/O context. rc=%Rrc\n", rc);
cErrors++;
}
}
else
{
RTPrintf("tstFileAio: FATAL ERROR - Failed to allocate memory for completed request array.\n");
cErrors++;
}
}
else
{
RTPrintf("tstFileAio: FATAL ERROR - Failed to allocate memory for buffer array.\n");
cErrors++;
}
}
else
{
RTPrintf("tstFileAio: FATAL ERROR - Failed to allocate memory for request array.\n");
cErrors++;
}
if (RT_FAILURE(rc))
{
cErrors++;
}
}
else
{
cErrors++;
}
}
int main()
{
RTPrintf("tstFileAio: TESTING\n");
RTR3Init();
/* Check if the API is available. */
if (RT_FAILURE(rc))
{
if (rc == VERR_NOT_SUPPORTED)
RTPrintf("tstFileAio: FATAL ERROR - File AIO API not available\n");
else
return 1;
}
rc = RTFileOpen(&File, "tstFileAio#1.tst", RTFILE_O_READWRITE | RTFILE_O_CREATE_REPLACE | RTFILE_O_DENY_NONE | RTFILE_O_ASYNC_IO);
if (RT_FAILURE(rc))
{
return 1;
}
for (unsigned i = 0; i < 64*_1K; i++)
((char *)pvTestBuf)[i] = i % 256;
/* Basic write test. */
RTPrintf("tstFileAio: Preparing test file, this can take some time and needs quite a bit of harddisk\n");
/* Reopen the file. */
rc = RTFileOpen(&File, "tstFileAio#1.tst", RTFILE_O_READWRITE | RTFILE_O_DENY_NONE | RTFILE_O_ASYNC_IO);
if (RT_SUCCESS(rc))
{
}
else
{
cErrors++;
}
/* Cleanup */
RTFileDelete("tstFileAio#1.tst");
/*
* Summary
*/
if (cErrors == 0)
RTPrintf("tstFileAio: SUCCESS\n");
else
return !!cErrors;
}