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