tstPDMAsyncCompletion.cpp revision 632b4638bd18092c6b8edb4e1028c9be112f5076
/* $Id$ */
/** @file
* Async completion Testcase.
*/
/*
* Copyright (C) 2008 Sun Microsystems, Inc.
*
* Sun Microsystems, Inc. confidential
* All rights reserved
*/
/*
* This testcase is for testing the async completion interface.
* It implements a file copy program which uses the interface to copy the data.
*
* Use: ./tstPDMAsyncCompletion <source> <destination>
*/
/*******************************************************************************
* Header Files *
*******************************************************************************/
#include "../VMInternal.h" /* UVM */
#include <VBox/pdmasynccompletion.h>
#include <iprt/initterm.h>
#include <iprt/semaphore.h>
#define TESTCASE "tstPDMAsyncCompletion"
/*
* Number of simultaneous active tasks.
*/
#define NR_TASKS 80
/* Buffers to store data in .*/
volatile uint32_t g_cTasksLeft;
{
if (!cTasksStillLeft)
{
/* All tasks processed. Wakeup main. */
}
}
{
int rcRet = 0; /* error count */
int rc = VINF_SUCCESS;
if (argc != 3)
{
rcRet++;
return rcRet;
}
if (RT_SUCCESS(rc))
{
/*
* Little hack to avoid the VM_ASSERT_EMT assertion.
*/
/*
* Create the template.
*/
rc = PDMR3AsyncCompletionTemplateCreateInternal(pVM, &pTemplate, pfnAsyncTaskCompleted, NULL, "Test");
if (RT_FAILURE(rc))
{
rcRet++;
return rcRet;
}
/*
* Create event semaphor.
*/
/*
* Create the temporary buffers.
*/
int i;
for (i=0; i < NR_TASKS; i++)
{
if (!g_AsyncCompletionTasksBuffer[i])
{
rcRet++;
return rcRet;
}
}
/* Create the destination as the async completion API can't do this. */
if (RT_FAILURE(rc))
{
rcRet++;
return rcRet;
}
/* Create our file endpoint */
if (RT_SUCCESS(rc))
{
if (RT_SUCCESS(rc))
{
/* Wait for all threads to finish initialization. */
RTThreadSleep(100);
int fReadPass = true;
size_t uOffsetSrc = 0;
size_t uOffsetDst = 0;
uint32_t cTasksUsed = 0;
if (RT_SUCCESS(rc))
{
/* Copy the data. */
for (;;)
{
if (fReadPass)
{
? NR_TASKS
? 1
: 0;
for (unsigned i = 0; i < cTasksUsed; i++)
{
&g_AsyncCompletionTasks[i]);
uOffsetSrc += cbRead;
if (uOffsetSrc == cbSrc)
break;
}
}
else
{
for (unsigned i = 0; i < cTasksUsed; i++)
{
&g_AsyncCompletionTasks[i]);
uOffsetDst += cbWrite;
if (uOffsetDst == cbSrc)
break;
}
}
break;
else if (fReadPass)
fReadPass = false;
else
{
cTasksUsed = 0;
fReadPass = true;
}
}
}
else
{
rcRet++;
}
}
}
/*
* Clean up.
*/
{
}
}
else
{
rcRet++;
}
return rcRet;
}