tstPDMAsyncCompletion.cpp revision b4fc07ae3f394595370fc5ed6ab1c353a87259db
/* $Id$ */
/** @file
* PDM Asynchronous Completion Testcase.
*
* 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>
*/
/*
* Copyright (C) 2008-2009 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.
*
* 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 "../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)
{
return 1;
}
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))
{
return 1;
}
/*
* Create event semaphor.
*/
/*
* Create the temporary buffers.
*/
for (unsigned i=0; i < NR_TASKS; i++)
{
if (!g_AsyncCompletionTasksBuffer[i])
{
return ++rcRet;
}
}
/* Create the destination as the async completion API can't do this. */
if (RT_FAILURE(rc))
{
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;
uint32_t cTasksUsed = 0;
if (RT_SUCCESS(rc))
{
/* Copy the data. */
for (;;)
{
if (fReadPass)
{
? NR_TASKS
? 1
: 0;
for (uint32_t i = 0; i < cTasksUsed; i++)
{
&g_AsyncCompletionTasks[i]);
break;
}
}
else
{
for (uint32_t i = 0; i < cTasksUsed; i++)
{
&g_AsyncCompletionTasks[i]);
break;
}
}
break;
else if (fReadPass)
fReadPass = false;
else
{
cTasksUsed = 0;
fReadPass = true;
}
}
}
else
{
rcRet++;
}
}
}
/*
* Clean up.
*/
{
}
}
else
{
rcRet++;
}
return rcRet;
}