tstPDMAsyncCompletion.cpp revision a9f41cb889f53e8407561a6155052c441eb0fc5f
3609dfc9f2733f4dc836c6a6bb3745398f280fcevboxsync * PDM Asynchronous Completion Testcase.
3609dfc9f2733f4dc836c6a6bb3745398f280fcevboxsync * This testcase is for testing the async completion interface.
3609dfc9f2733f4dc836c6a6bb3745398f280fcevboxsync * It implements a file copy program which uses the interface to copy the data.
3609dfc9f2733f4dc836c6a6bb3745398f280fcevboxsync * Use: ./tstPDMAsyncCompletion <source> <destination>
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync * Copyright (C) 2008-2010 Sun Microsystems, Inc.
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync * available from http://www.virtualbox.org. This file is free software;
1c94c0a63ba68be1a7b2c640e70d7a06464e4fcavboxsync * you can redistribute it and/or modify it under the terms of the GNU
1c94c0a63ba68be1a7b2c640e70d7a06464e4fcavboxsync * General Public License (GPL) as published by the Free Software
1c94c0a63ba68be1a7b2c640e70d7a06464e4fcavboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
1c94c0a63ba68be1a7b2c640e70d7a06464e4fcavboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
3609dfc9f2733f4dc836c6a6bb3745398f280fcevboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
3609dfc9f2733f4dc836c6a6bb3745398f280fcevboxsync * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
3609dfc9f2733f4dc836c6a6bb3745398f280fcevboxsync * Clara, CA 95054 USA or visit http://www.sun.com if you need
3609dfc9f2733f4dc836c6a6bb3745398f280fcevboxsync * additional information or have any questions.
3609dfc9f2733f4dc836c6a6bb3745398f280fcevboxsync/*******************************************************************************
3609dfc9f2733f4dc836c6a6bb3745398f280fcevboxsync* Header Files *
3609dfc9f2733f4dc836c6a6bb3745398f280fcevboxsync*******************************************************************************/
3609dfc9f2733f4dc836c6a6bb3745398f280fcevboxsync * Number of simultaneous active tasks.
3609dfc9f2733f4dc836c6a6bb3745398f280fcevboxsync/* Buffers to store data in .*/
3609dfc9f2733f4dc836c6a6bb3745398f280fcevboxsyncPPDMASYNCCOMPLETIONTASK g_AsyncCompletionTasks[NR_TASKS];
3609dfc9f2733f4dc836c6a6bb3745398f280fcevboxsyncvoid pfnAsyncTaskCompleted(PVM pVM, void *pvUser, void *pvUser2, int rc)
611910c4ba57eb6db5c0d508ca7b923efd654aecvboxsync LogFlow((TESTCASE ": %s: pVM=%p pvUser=%p pvUser2=%p\n", __FUNCTION__, pVM, pvUser, pvUser2));
611910c4ba57eb6db5c0d508ca7b923efd654aecvboxsync uint32_t cTasksStillLeft = ASMAtomicDecU32(&g_cTasksLeft);
611910c4ba57eb6db5c0d508ca7b923efd654aecvboxsync /* All tasks processed. Wakeup main. */
611910c4ba57eb6db5c0d508ca7b923efd654aecvboxsync PPDMASYNCCOMPLETIONENDPOINT pEndpointSrc, pEndpointDst;
611910c4ba57eb6db5c0d508ca7b923efd654aecvboxsync RTPrintf(TESTCASE ": Usage is ./tstPDMAsyncCompletion <source> <dest>\n");
611910c4ba57eb6db5c0d508ca7b923efd654aecvboxsync * Little hack to avoid the VM_ASSERT_EMT assertion.
611910c4ba57eb6db5c0d508ca7b923efd654aecvboxsync RTTlsSet(pVM->pUVM->vm.s.idxTLS, &pVM->pUVM->aCpus[0]);
611910c4ba57eb6db5c0d508ca7b923efd654aecvboxsync pVM->pUVM->aCpus[0].vm.s.NativeThreadEMT = RTThreadNativeSelf();
611910c4ba57eb6db5c0d508ca7b923efd654aecvboxsync * Create the template.
611910c4ba57eb6db5c0d508ca7b923efd654aecvboxsync rc = PDMR3AsyncCompletionTemplateCreateInternal(pVM, &pTemplate, pfnAsyncTaskCompleted, NULL, "Test");
611910c4ba57eb6db5c0d508ca7b923efd654aecvboxsync RTPrintf(TESTCASE ": Error while creating the template!! rc=%d\n", rc);
611910c4ba57eb6db5c0d508ca7b923efd654aecvboxsync * Create event semaphor.
611910c4ba57eb6db5c0d508ca7b923efd654aecvboxsync * Create the temporary buffers.
611910c4ba57eb6db5c0d508ca7b923efd654aecvboxsync for (unsigned i=0; i < NR_TASKS; i++)
611910c4ba57eb6db5c0d508ca7b923efd654aecvboxsync g_AsyncCompletionTasksBuffer[i] = (uint8_t *)RTMemAllocZ(BUFFER_SIZE);
611910c4ba57eb6db5c0d508ca7b923efd654aecvboxsync /* Create the destination as the async completion API can't do this. */
611910c4ba57eb6db5c0d508ca7b923efd654aecvboxsync rc = RTFileOpen(&FileTmp, argv[2], RTFILE_O_READWRITE | RTFILE_O_OPEN_CREATE | RTFILE_O_DENY_NONE);
50fdc90dae026b2086f85b0f028aa63dd6bbe14evboxsync RTPrintf(TESTCASE ": Error while creating the destination!! rc=%d\n", rc);
611910c4ba57eb6db5c0d508ca7b923efd654aecvboxsync /* Create our file endpoint */
611910c4ba57eb6db5c0d508ca7b923efd654aecvboxsync rc = PDMR3AsyncCompletionEpCreateForFile(&pEndpointSrc, argv[1], 0, pTemplate);
e8ac7dce6d625856c57792a6af738e2fe2667264vboxsync rc = PDMR3AsyncCompletionEpCreateForFile(&pEndpointDst, argv[2], 0, pTemplate);
611910c4ba57eb6db5c0d508ca7b923efd654aecvboxsync /* Wait for all threads to finish initialization. */
6f516ad9911d9037a18778742caa955fe362f8ffvboxsync rc = PDMR3AsyncCompletionEpGetSize(pEndpointSrc, &cbSrc);
6f516ad9911d9037a18778742caa955fe362f8ffvboxsync /* Copy the data. */
6f516ad9911d9037a18778742caa955fe362f8ffvboxsync cTasksUsed = (BUFFER_SIZE * NR_TASKS) <= (cbSrc - offSrc)
6f516ad9911d9037a18778742caa955fe362f8ffvboxsync size_t cbRead = ((size_t)offSrc + BUFFER_SIZE) <= cbSrc ? BUFFER_SIZE : cbSrc - offSrc;
&g_AsyncCompletionTasks[i]);
&g_AsyncCompletionTasks[i]);
else if (fReadPass)
fReadPass = false;
cTasksUsed = 0;
fReadPass = true;
rcRet++;
rcRet++;
return rcRet;