Index: /trunk/src/VBox/Runtime/testcase/Makefile.kmk
===================================================================
--- /trunk/src/VBox/Runtime/testcase/Makefile.kmk	(revision 29392)
+++ /trunk/src/VBox/Runtime/testcase/Makefile.kmk	(revision 29393)
@@ -57,6 +57,6 @@
 	tstErrUnique \
 	tstFile \
-	tstFileAio \
-	tstFileAppend-1 \
+	tstRTFileAio \
+	tstRTFileAppend-1 \
 	tstFileLock \
 	tstFork \
@@ -203,9 +203,11 @@
 tstFile_SOURCES = tstFile.cpp
 
-tstFileAppend-1_SOURCES = tstFileAppend-1.cpp
+tstRTFileAio_SOURCES = VBOXR3TSTEXE
+tstRTFileAio_SOURCES = tstRTFileAio.cpp
+
+tstRTFileAppend-1_TEMPLATE = VBOXR3TSTEXE
+tstRTFileAppend-1_SOURCES = tstRTFileAppend-1.cpp
 
 tstFileAppendWin-1_SOURCES = tstFileAppendWin-1.cpp
-
-tstFileAio_SOURCES = tstFileAio.cpp
 
 tstFileLock_SOURCES = tstFileLock.cpp
Index: unk/src/VBox/Runtime/testcase/tstFileAio.cpp
===================================================================
--- /trunk/src/VBox/Runtime/testcase/tstFileAio.cpp	(revision 29392)
+++ 	(revision )
@@ -1,229 +1,0 @@
-/* $Id$ */
-/** @file
- * IPRT Testcase - File Async I/O.
- */
-
-/*
- * Copyright (C) 2006-2010 Oracle Corporation
- *
- * This file is part of VirtualBox Open Source Edition (OSE), as
- * available from http://www.virtualbox.org. This file is free software;
- * you can redistribute it and/or modify it under the terms of the GNU
- * 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.
- */
-
-
-/*******************************************************************************
-*   Header Files                                                               *
-*******************************************************************************/
-#include <iprt/file.h>
-
-#include <iprt/err.h>
-#include <iprt/mem.h>
-#include <iprt/param.h>
-#include <iprt/string.h>
-#include <iprt/test.h>
-
-
-/*******************************************************************************
-*   Defined Constants And Macros                                               *
-*******************************************************************************/
-/** @todo make configurable through cmd line. */
-#define TSTFILEAIO_MAX_REQS_IN_FLIGHT   64
-#define TSTFILEAIO_BUFFER_SIZE          (64*_1K)
-
-
-/*******************************************************************************
-*   Global Variables                                                           *
-*******************************************************************************/
-static RTTEST g_hTest = NIL_RTTEST;
-
-
-void tstFileAioTestReadWriteBasic(RTFILE File, bool fWrite, void *pvTestBuf,
-                                  size_t cbTestBuf, size_t cbTestFile, uint32_t cMaxReqsInFlight)
-{
-    /* Allocate request array. */
-    RTFILEAIOREQ *paReqs;
-    paReqs = (PRTFILEAIOREQ)RTTestGuardedAllocHead(g_hTest, cMaxReqsInFlight * sizeof(RTFILEAIOREQ));
-    RTTESTI_CHECK_RETV(paReqs);
-    RT_BZERO(paReqs, sizeof(cMaxReqsInFlight * sizeof(RTFILEAIOREQ)));
-
-    /* Allocate array holding pointer to data buffers. */
-    void **papvBuf = (void **)RTTestGuardedAllocHead(g_hTest, cMaxReqsInFlight * sizeof(void *));
-    RTTESTI_CHECK_RETV(papvBuf);
-
-    /* Allocate the buffers*/
-    for (unsigned i = 0; i < cMaxReqsInFlight; i++)
-    {
-        RTTESTI_CHECK_RC_OK_RETV(RTTestGuardedAlloc(g_hTest, cbTestBuf, PAGE_SIZE, true /*fHead*/, &papvBuf[i]));
-        if (fWrite)
-            memcpy(papvBuf[i], pvTestBuf, cbTestBuf);
-        if (fWrite)
-            memcpy(papvBuf[i], pvTestBuf, cbTestBuf);
-        else
-            RT_BZERO(papvBuf[i], cbTestBuf);
-    }
-
-    /* Allocate array holding completed requests. */
-    RTFILEAIOREQ *paReqsCompleted;
-    paReqsCompleted = (PRTFILEAIOREQ)RTTestGuardedAllocHead(g_hTest, cMaxReqsInFlight * sizeof(RTFILEAIOREQ));
-    RTTESTI_CHECK_RETV(paReqsCompleted);
-    RT_BZERO(paReqsCompleted, cMaxReqsInFlight * sizeof(RTFILEAIOREQ));
-
-    /* Create a context and associate the file handle with it. */
-    RTFILEAIOCTX hAioContext;
-    RTTESTI_CHECK_RC_RETV(RTFileAioCtxCreate(&hAioContext, cMaxReqsInFlight), VINF_SUCCESS);
-    RTTESTI_CHECK_RC_RETV(RTFileAioCtxAssociateWithFile(hAioContext, File), VINF_SUCCESS);
-
-    /* Initialize requests. */
-    for (unsigned i = 0; i < cMaxReqsInFlight; i++)
-        RTFileAioReqCreate(&paReqs[i]);
-
-    RTFOFF      off    = 0;
-    int         cRuns  = 0;
-    uint64_t    NanoTS = RTTimeNanoTS();
-    size_t      cbLeft = cbTestFile;
-    while (cbLeft)
-    {
-        int rc;
-        int cReqs = 0;
-        for (unsigned i = 0; i < cMaxReqsInFlight; i++)
-        {
-            size_t cbTransfer = cbLeft < cbTestBuf ? cbLeft : cbTestBuf;
-            if (!cbTransfer)
-                break;
-
-            if (fWrite)
-                rc = RTFileAioReqPrepareWrite(paReqs[i], File, off, papvBuf[i],
-                                              cbTransfer, papvBuf[i]);
-            else
-                rc = RTFileAioReqPrepareRead(paReqs[i], File, off, papvBuf[i],
-                                             cbTransfer, papvBuf[i]);
-            RTTESTI_CHECK_RC(rc, VINF_SUCCESS);
-
-            cbLeft -= cbTransfer;
-            off    += cbTransfer;
-            cReqs++;
-        }
-
-        rc = RTFileAioCtxSubmit(hAioContext, paReqs, cReqs);
-        RTTESTI_CHECK_MSG(rc == VINF_SUCCESS, ("Failed to submit tasks after %d runs. rc=%Rrc\n", cRuns, rc));
-        if (rc != VINF_SUCCESS)
-            break;
-
-        /* Wait */
-        uint32_t cCompleted = 0;
-        RTTESTI_CHECK_RC(rc = RTFileAioCtxWait(hAioContext, cReqs, RT_INDEFINITE_WAIT,
-                                               paReqsCompleted, cMaxReqsInFlight, &cCompleted),
-                         VINF_SUCCESS);
-        if (rc != VINF_SUCCESS)
-            break;
-
-        if (!fWrite)
-        {
-            for (uint32_t i = 0; i < cCompleted; i++)
-            {
-                /* Compare that we read the right stuff. */
-                void *pvBuf = RTFileAioReqGetUser(paReqsCompleted[i]);
-                RTTESTI_CHECK(pvBuf);
-
-                size_t cbTransfered;
-                RTTESTI_CHECK_RC(rc = RTFileAioReqGetRC(paReqsCompleted[i], &cbTransfered), VINF_SUCCESS);
-                if (rc != VINF_SUCCESS)
-                    break;
-                RTTESTI_CHECK_MSG(cbTransfered == cbTestBuf, ("cbTransfered=%zd\n", cbTransfered));
-                RTTESTI_CHECK_RC_OK(rc = (memcmp(pvBuf, pvTestBuf, cbTestBuf) == 0 ? VINF_SUCCESS : VERR_BAD_EXE_FORMAT));
-                if (rc != VINF_SUCCESS)
-                    break;
-                memset(pvBuf, 0, cbTestBuf);
-            }
-        }
-        cRuns++;
-        if (RT_FAILURE(rc))
-            break;
-    }
-
-    NanoTS = RTTimeNanoTS() - NanoTS;
-    uint64_t SpeedKBs = (uint64_t)(cbTestFile / (NanoTS / 1000000000.0) / 1024);
-    RTTestValue(g_hTest, "Throughput", SpeedKBs, RTTESTUNIT_KILOBYTES_PER_SEC);
-
-    /* cleanup */
-    for (unsigned i = 0; i < cMaxReqsInFlight; i++)
-        RTTestGuardedFree(g_hTest, papvBuf[i]);
-    RTTestGuardedFree(g_hTest, papvBuf);
-    for (unsigned i = 0; i < cMaxReqsInFlight; i++)
-        RTTESTI_CHECK_RC(RTFileAioReqDestroy(paReqs[i]), VINF_SUCCESS);
-    RTTESTI_CHECK_RC(RTFileAioCtxDestroy(hAioContext), VINF_SUCCESS);
-    RTTestGuardedFree(g_hTest, paReqs);
-}
-
-int main()
-{
-    int rc = RTTestInitAndCreate("tstRTFileAio", &g_hTest);
-    if (rc)
-        return rc;
-
-    /* Check if the API is available. */
-    RTTestSub(g_hTest, "RTFileAioGetLimits");
-    RTFILEAIOLIMITS AioLimits;
-    RT_ZERO(AioLimits);
-    RTTESTI_CHECK_RC(rc = RTFileAioGetLimits(&AioLimits), VINF_SUCCESS);
-    if (RT_SUCCESS(rc))
-    {
-        RTTestSub(g_hTest, "Write");
-        RTFILE hFile;
-        RTTESTI_CHECK_RC(rc = RTFileOpen(&hFile, "tstFileAio#1.tst",
-                                         RTFILE_O_READWRITE | RTFILE_O_CREATE_REPLACE | RTFILE_O_DENY_NONE | RTFILE_O_ASYNC_IO),
-                         VINF_SUCCESS);
-        if (RT_SUCCESS(rc))
-        {
-            uint8_t *pbTestBuf = (uint8_t *)RTTestGuardedAllocTail(g_hTest, TSTFILEAIO_BUFFER_SIZE);
-            for (unsigned i = 0; i < TSTFILEAIO_BUFFER_SIZE; i++)
-                pbTestBuf[i] = i % 256;
-
-            uint32_t cReqsMax = AioLimits.cReqsOutstandingMax < TSTFILEAIO_MAX_REQS_IN_FLIGHT
-                              ? AioLimits.cReqsOutstandingMax
-                              : TSTFILEAIO_MAX_REQS_IN_FLIGHT;
-
-            /* Basic write test. */
-            RTTestIPrintf(RTTESTLVL_ALWAYS, "Preparing test file, this can take some time and needs quite a bit of harddisk space...\n");
-            tstFileAioTestReadWriteBasic(hFile, true /*fWrite*/, pbTestBuf, TSTFILEAIO_BUFFER_SIZE, 100*_1M, cReqsMax);
-
-            /* Reopen the file before doing the next test. */
-            RTTESTI_CHECK_RC(RTFileClose(hFile), VINF_SUCCESS);
-            if (RTTestErrorCount(g_hTest) == 0)
-            {
-                RTTestSub(g_hTest, "Read/Write");
-                RTTESTI_CHECK_RC(rc = RTFileOpen(&hFile, "tstFileAio#1.tst",
-                                                 RTFILE_O_READWRITE | RTFILE_O_OPEN | RTFILE_O_DENY_NONE | RTFILE_O_ASYNC_IO),
-                                 VINF_SUCCESS);
-                if (RT_SUCCESS(rc))
-                {
-                    tstFileAioTestReadWriteBasic(hFile, false /*fWrite*/, pbTestBuf, TSTFILEAIO_BUFFER_SIZE, 100*_1M, cReqsMax);
-                    RTFileClose(hFile);
-                }
-            }
-
-            /* Cleanup */
-            RTFileDelete("tstFileAio#1.tst");
-        }
-    }
-
-    /*
-     * Summary
-     */
-    return RTTestSummaryAndDestroy(g_hTest);
-}
-
Index: unk/src/VBox/Runtime/testcase/tstFileAppend-1.cpp
===================================================================
--- /trunk/src/VBox/Runtime/testcase/tstFileAppend-1.cpp	(revision 29392)
+++ 	(revision )
@@ -1,209 +1,0 @@
-/* $Id$ */
-/** @file
- * IPRT Testcase - File Appending.
- */
-
-/*
- * Copyright (C) 2009-2010 Oracle Corporation
- *
- * This file is part of VirtualBox Open Source Edition (OSE), as
- * available from http://www.virtualbox.org. This file is free software;
- * you can redistribute it and/or modify it under the terms of the GNU
- * 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.
- */
-
-
-/*******************************************************************************
-*   Header Files                                                               *
-*******************************************************************************/
-#include <iprt/file.h>
-
-#include <iprt/err.h>
-#include <iprt/string.h>
-#include <iprt/test.h>
-
-
-void tstFileAppend1(RTTEST hTest)
-{
-    /*
-     * Open it write only and do some appending.
-     * Checking that read fails and that the file position changes after the write.
-     */
-    RTTestSub(hTest, "Basic 1");
-    RTFileDelete("tstFileAppend-1.tst");
-    RTFILE hFile = NIL_RTFILE;
-    int rc = RTFileOpen(&hFile,
-                        "tstFileAppend-1.tst",
-                        RTFILE_O_WRITE
-                        | RTFILE_O_APPEND
-                        | RTFILE_O_OPEN_CREATE
-                        | RTFILE_O_DENY_NONE
-                        | (0644 << RTFILE_O_CREATE_MODE_SHIFT)
-                        );
-    RTTESTI_CHECK_RC_RETV(rc, VINF_SUCCESS);
-
-    uint64_t offActual = 42;
-    uint64_t off       = 0;
-    RTTESTI_CHECK_RC(rc = RTFileSeek(hFile, off, RTFILE_SEEK_CURRENT, &offActual), VINF_SUCCESS);
-    RTTESTI_CHECK_MSG(offActual == 0 || RT_FAILURE(rc), ("offActual=%llu", offActual));
-
-    RTTESTI_CHECK_RC(RTFileWrite(hFile, "0123456789", 10, NULL), VINF_SUCCESS);
-
-    offActual = 99;
-    off = 0;
-    RTTESTI_CHECK_RC(rc = RTFileSeek(hFile, off, RTFILE_SEEK_CURRENT, &offActual), VINF_SUCCESS);
-    RTTESTI_CHECK_MSG(offActual == 10 || RT_FAILURE(rc), ("offActual=%llu", offActual));
-    RTTestIPrintf(RTTESTLVL_INFO, "off=%llu after first write\n", offActual);
-
-    size_t  cb = 4;
-    char    szBuf[256];
-    rc = RTFileRead(hFile, szBuf, 1, &cb);
-    RTTESTI_CHECK_MSG(rc == VERR_ACCESS_DENIED || rc == VERR_INVALID_HANDLE, ("rc=%Rrc\n", rc));
-
-    offActual = 999;
-    off = 5;
-    RTTESTI_CHECK_RC(rc = RTFileSeek(hFile, off, RTFILE_SEEK_BEGIN, &offActual), VINF_SUCCESS);
-    RTTESTI_CHECK_MSG(offActual == 5 || RT_FAILURE(rc), ("offActual=%llu", offActual));
-
-    RTTESTI_CHECK_RC(RTFileClose(hFile), VINF_SUCCESS);
-
-
-    /*
-     * Open it write only and do some more appending.
-     * Checking the initial position and that it changes after the write.
-     */
-    RTTestSub(hTest, "Basic 2");
-    rc = RTFileOpen(&hFile,
-                    "tstFileAppend-1.tst",
-                      RTFILE_O_WRITE
-                    | RTFILE_O_APPEND
-                    | RTFILE_O_OPEN
-                    | RTFILE_O_DENY_NONE
-                   );
-    RTTESTI_CHECK_RC_RETV(rc, VINF_SUCCESS);
-
-    offActual = 99;
-    off = 0;
-    RTTESTI_CHECK_RC(rc = RTFileSeek(hFile, off, RTFILE_SEEK_CURRENT, &offActual), VINF_SUCCESS);
-    RTTESTI_CHECK_MSG(offActual == 0 || RT_FAILURE(rc), ("offActual=%llu", offActual));
-    RTTestIPrintf(RTTESTLVL_INFO, "off=%llu on 2nd open\n", offActual);
-
-    RTTESTI_CHECK_RC(rc = RTFileWrite(hFile, "abcdefghij", 10, &cb), VINF_SUCCESS);
-
-    offActual = 999;
-    off = 0;
-    RTTESTI_CHECK_RC(rc = RTFileSeek(hFile, off, RTFILE_SEEK_CURRENT, &offActual), VINF_SUCCESS);
-    RTTESTI_CHECK_MSG(offActual == 20 || RT_FAILURE(rc), ("offActual=%llu", offActual));
-    RTTestIPrintf(RTTESTLVL_INFO, "off=%llu after 2nd write\n", offActual);
-
-    RTTESTI_CHECK_RC(RTFileClose(hFile), VINF_SUCCESS);
-
-    /*
-     * Open it read/write.
-     * Check the initial position and read stuff. Then append some more and
-     * check the new position and see that read returns 0/EOF. Finally,
-     * do some seeking and read from a new position.
-     */
-    RTTestSub(hTest, "Basic 3");
-    rc = RTFileOpen(&hFile,
-                    "tstFileAppend-1.tst",
-                      RTFILE_O_READWRITE
-                    | RTFILE_O_APPEND
-                    | RTFILE_O_OPEN
-                    | RTFILE_O_DENY_NONE
-                   );
-    RTTESTI_CHECK_RC_RETV(rc, VINF_SUCCESS);
-
-    offActual = 9;
-    off = 0;
-    RTTESTI_CHECK_RC(rc = RTFileSeek(hFile, off, RTFILE_SEEK_CURRENT, &offActual), VINF_SUCCESS);
-    RTTESTI_CHECK_MSG(offActual == 0 || RT_FAILURE(rc), ("offActual=%llu", offActual));
-    RTTestIPrintf(RTTESTLVL_INFO, "off=%llu on 3rd open\n", offActual);
-
-    cb = 99;
-    RTTESTI_CHECK_RC(rc = RTFileRead(hFile, szBuf, 10, &cb), VINF_SUCCESS);
-    RTTESTI_CHECK(RT_FAILURE(rc) || cb == 10);
-    RTTESTI_CHECK_MSG(RT_FAILURE(rc) || !memcmp(szBuf, "0123456789", 10), ("read the wrong stuff: %.10s - expected 0123456789\n", szBuf));
-
-    offActual = 999;
-    off = 0;
-    RTTESTI_CHECK_RC(rc = RTFileSeek(hFile, off, RTFILE_SEEK_CURRENT, &offActual), VINF_SUCCESS);
-    RTTESTI_CHECK_MSG(offActual == 10 || RT_FAILURE(rc), ("offActual=%llu", offActual));
-    RTTestIPrintf(RTTESTLVL_INFO, "off=%llu on 1st open\n", offActual);
-
-    RTTESTI_CHECK_RC(RTFileWrite(hFile, "klmnopqrst", 10, NULL), VINF_SUCCESS);
-
-    offActual = 9999;
-    off = 0;
-    RTTESTI_CHECK_RC(rc = RTFileSeek(hFile, off, RTFILE_SEEK_CURRENT, &offActual), VINF_SUCCESS);
-    RTTESTI_CHECK_MSG(offActual == 30 || RT_FAILURE(rc), ("offActual=%llu", offActual));
-    RTTestIPrintf(RTTESTLVL_INFO, "off=%llu after 3rd write\n", offActual);
-
-    RTTESTI_CHECK_RC(rc = RTFileRead(hFile, szBuf, 1, NULL), VERR_EOF);
-    cb = 99;
-    RTTESTI_CHECK_RC(rc = RTFileRead(hFile, szBuf, 1, &cb), VINF_SUCCESS);
-    RTTESTI_CHECK(cb == 0);
-
-
-    offActual = 99999;
-    off = 15;
-    RTTESTI_CHECK_RC(rc = RTFileSeek(hFile, off, RTFILE_SEEK_BEGIN, &offActual), VINF_SUCCESS);
-    RTTESTI_CHECK_MSG(offActual == 15 || RT_FAILURE(rc), ("offActual=%llu", offActual));
-    if (RT_SUCCESS(rc) && offActual == 15)
-    {
-        RTTESTI_CHECK_RC(rc = RTFileRead(hFile, szBuf, 10, NULL), VINF_SUCCESS);
-        RTTESTI_CHECK_MSG(RT_FAILURE(rc) || !memcmp(szBuf, "fghijklmno", 10), ("read the wrong stuff: %.10s - expected fghijklmno\n", szBuf));
-
-        offActual = 9999999;
-        off = 0;
-        RTTESTI_CHECK_RC(rc = RTFileSeek(hFile, off, RTFILE_SEEK_CURRENT, &offActual), VINF_SUCCESS);
-        RTTESTI_CHECK_MSG(offActual == 25 || RT_FAILURE(rc), ("offActual=%llu", offActual));
-        RTTestIPrintf(RTTESTLVL_INFO, "off=%llu after 2nd read\n", offActual);
-    }
-
-    RTTESTI_CHECK_RC(RTFileClose(hFile), VINF_SUCCESS);
-
-    /*
-     * Open it read only + append and check that we cannot write to it.
-     */
-    RTTestSub(hTest, "Basic 4");
-    rc = RTFileOpen(&hFile,
-                    "tstFileAppend-1.tst",
-                      RTFILE_O_READ
-                    | RTFILE_O_APPEND
-                    | RTFILE_O_OPEN
-                    | RTFILE_O_DENY_NONE);
-    RTTESTI_CHECK_RC_RETV(rc, VINF_SUCCESS);
-
-    rc = RTFileWrite(hFile, "pqrstuvwx", 10, &cb);
-    RTTESTI_CHECK_MSG(rc == VERR_ACCESS_DENIED || rc == VERR_INVALID_HANDLE, ("rc=%Rrc\n", rc));
-
-    RTTESTI_CHECK_RC(RTFileClose(hFile), VINF_SUCCESS);
-    RTTESTI_CHECK_RC(RTFileDelete("tstFileAppend-1.tst"), VINF_SUCCESS);
-}
-
-
-int main()
-{
-    RTTEST hTest;
-    int rc = RTTestInitAndCreate("tstRTFileAppend-1", &hTest);
-    if (rc)
-        return rc;
-    RTTestBanner(hTest);
-    tstFileAppend1(hTest);
-    RTFileDelete("tstFileAppend-1.tst");
-    return RTTestSummaryAndDestroy(hTest);
-}
-
Index: /trunk/src/VBox/Runtime/testcase/tstRTFileAio.cpp
===================================================================
--- /trunk/src/VBox/Runtime/testcase/tstRTFileAio.cpp	(revision 29393)
+++ /trunk/src/VBox/Runtime/testcase/tstRTFileAio.cpp	(revision 29393)
@@ -0,0 +1,229 @@
+/* $Id$ */
+/** @file
+ * IPRT Testcase - File Async I/O.
+ */
+
+/*
+ * Copyright (C) 2006-2010 Oracle Corporation
+ *
+ * This file is part of VirtualBox Open Source Edition (OSE), as
+ * available from http://www.virtualbox.org. This file is free software;
+ * you can redistribute it and/or modify it under the terms of the GNU
+ * 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.
+ */
+
+
+/*******************************************************************************
+*   Header Files                                                               *
+*******************************************************************************/
+#include <iprt/file.h>
+
+#include <iprt/err.h>
+#include <iprt/mem.h>
+#include <iprt/param.h>
+#include <iprt/string.h>
+#include <iprt/test.h>
+
+
+/*******************************************************************************
+*   Defined Constants And Macros                                               *
+*******************************************************************************/
+/** @todo make configurable through cmd line. */
+#define TSTFILEAIO_MAX_REQS_IN_FLIGHT   64
+#define TSTFILEAIO_BUFFER_SIZE          (64*_1K)
+
+
+/*******************************************************************************
+*   Global Variables                                                           *
+*******************************************************************************/
+static RTTEST g_hTest = NIL_RTTEST;
+
+
+void tstFileAioTestReadWriteBasic(RTFILE File, bool fWrite, void *pvTestBuf,
+                                  size_t cbTestBuf, size_t cbTestFile, uint32_t cMaxReqsInFlight)
+{
+    /* Allocate request array. */
+    RTFILEAIOREQ *paReqs;
+    paReqs = (PRTFILEAIOREQ)RTTestGuardedAllocHead(g_hTest, cMaxReqsInFlight * sizeof(RTFILEAIOREQ));
+    RTTESTI_CHECK_RETV(paReqs);
+    RT_BZERO(paReqs, sizeof(cMaxReqsInFlight * sizeof(RTFILEAIOREQ)));
+
+    /* Allocate array holding pointer to data buffers. */
+    void **papvBuf = (void **)RTTestGuardedAllocHead(g_hTest, cMaxReqsInFlight * sizeof(void *));
+    RTTESTI_CHECK_RETV(papvBuf);
+
+    /* Allocate the buffers*/
+    for (unsigned i = 0; i < cMaxReqsInFlight; i++)
+    {
+        RTTESTI_CHECK_RC_OK_RETV(RTTestGuardedAlloc(g_hTest, cbTestBuf, PAGE_SIZE, true /*fHead*/, &papvBuf[i]));
+        if (fWrite)
+            memcpy(papvBuf[i], pvTestBuf, cbTestBuf);
+        if (fWrite)
+            memcpy(papvBuf[i], pvTestBuf, cbTestBuf);
+        else
+            RT_BZERO(papvBuf[i], cbTestBuf);
+    }
+
+    /* Allocate array holding completed requests. */
+    RTFILEAIOREQ *paReqsCompleted;
+    paReqsCompleted = (PRTFILEAIOREQ)RTTestGuardedAllocHead(g_hTest, cMaxReqsInFlight * sizeof(RTFILEAIOREQ));
+    RTTESTI_CHECK_RETV(paReqsCompleted);
+    RT_BZERO(paReqsCompleted, cMaxReqsInFlight * sizeof(RTFILEAIOREQ));
+
+    /* Create a context and associate the file handle with it. */
+    RTFILEAIOCTX hAioContext;
+    RTTESTI_CHECK_RC_RETV(RTFileAioCtxCreate(&hAioContext, cMaxReqsInFlight), VINF_SUCCESS);
+    RTTESTI_CHECK_RC_RETV(RTFileAioCtxAssociateWithFile(hAioContext, File), VINF_SUCCESS);
+
+    /* Initialize requests. */
+    for (unsigned i = 0; i < cMaxReqsInFlight; i++)
+        RTFileAioReqCreate(&paReqs[i]);
+
+    RTFOFF      off    = 0;
+    int         cRuns  = 0;
+    uint64_t    NanoTS = RTTimeNanoTS();
+    size_t      cbLeft = cbTestFile;
+    while (cbLeft)
+    {
+        int rc;
+        int cReqs = 0;
+        for (unsigned i = 0; i < cMaxReqsInFlight; i++)
+        {
+            size_t cbTransfer = cbLeft < cbTestBuf ? cbLeft : cbTestBuf;
+            if (!cbTransfer)
+                break;
+
+            if (fWrite)
+                rc = RTFileAioReqPrepareWrite(paReqs[i], File, off, papvBuf[i],
+                                              cbTransfer, papvBuf[i]);
+            else
+                rc = RTFileAioReqPrepareRead(paReqs[i], File, off, papvBuf[i],
+                                             cbTransfer, papvBuf[i]);
+            RTTESTI_CHECK_RC(rc, VINF_SUCCESS);
+
+            cbLeft -= cbTransfer;
+            off    += cbTransfer;
+            cReqs++;
+        }
+
+        rc = RTFileAioCtxSubmit(hAioContext, paReqs, cReqs);
+        RTTESTI_CHECK_MSG(rc == VINF_SUCCESS, ("Failed to submit tasks after %d runs. rc=%Rrc\n", cRuns, rc));
+        if (rc != VINF_SUCCESS)
+            break;
+
+        /* Wait */
+        uint32_t cCompleted = 0;
+        RTTESTI_CHECK_RC(rc = RTFileAioCtxWait(hAioContext, cReqs, RT_INDEFINITE_WAIT,
+                                               paReqsCompleted, cMaxReqsInFlight, &cCompleted),
+                         VINF_SUCCESS);
+        if (rc != VINF_SUCCESS)
+            break;
+
+        if (!fWrite)
+        {
+            for (uint32_t i = 0; i < cCompleted; i++)
+            {
+                /* Compare that we read the right stuff. */
+                void *pvBuf = RTFileAioReqGetUser(paReqsCompleted[i]);
+                RTTESTI_CHECK(pvBuf);
+
+                size_t cbTransfered;
+                RTTESTI_CHECK_RC(rc = RTFileAioReqGetRC(paReqsCompleted[i], &cbTransfered), VINF_SUCCESS);
+                if (rc != VINF_SUCCESS)
+                    break;
+                RTTESTI_CHECK_MSG(cbTransfered == cbTestBuf, ("cbTransfered=%zd\n", cbTransfered));
+                RTTESTI_CHECK_RC_OK(rc = (memcmp(pvBuf, pvTestBuf, cbTestBuf) == 0 ? VINF_SUCCESS : VERR_BAD_EXE_FORMAT));
+                if (rc != VINF_SUCCESS)
+                    break;
+                memset(pvBuf, 0, cbTestBuf);
+            }
+        }
+        cRuns++;
+        if (RT_FAILURE(rc))
+            break;
+    }
+
+    NanoTS = RTTimeNanoTS() - NanoTS;
+    uint64_t SpeedKBs = (uint64_t)(cbTestFile / (NanoTS / 1000000000.0) / 1024);
+    RTTestValue(g_hTest, "Throughput", SpeedKBs, RTTESTUNIT_KILOBYTES_PER_SEC);
+
+    /* cleanup */
+    for (unsigned i = 0; i < cMaxReqsInFlight; i++)
+        RTTestGuardedFree(g_hTest, papvBuf[i]);
+    RTTestGuardedFree(g_hTest, papvBuf);
+    for (unsigned i = 0; i < cMaxReqsInFlight; i++)
+        RTTESTI_CHECK_RC(RTFileAioReqDestroy(paReqs[i]), VINF_SUCCESS);
+    RTTESTI_CHECK_RC(RTFileAioCtxDestroy(hAioContext), VINF_SUCCESS);
+    RTTestGuardedFree(g_hTest, paReqs);
+}
+
+int main()
+{
+    int rc = RTTestInitAndCreate("tstRTFileAio", &g_hTest);
+    if (rc)
+        return rc;
+
+    /* Check if the API is available. */
+    RTTestSub(g_hTest, "RTFileAioGetLimits");
+    RTFILEAIOLIMITS AioLimits;
+    RT_ZERO(AioLimits);
+    RTTESTI_CHECK_RC(rc = RTFileAioGetLimits(&AioLimits), VINF_SUCCESS);
+    if (RT_SUCCESS(rc))
+    {
+        RTTestSub(g_hTest, "Write");
+        RTFILE hFile;
+        RTTESTI_CHECK_RC(rc = RTFileOpen(&hFile, "tstFileAio#1.tst",
+                                         RTFILE_O_READWRITE | RTFILE_O_CREATE_REPLACE | RTFILE_O_DENY_NONE | RTFILE_O_ASYNC_IO),
+                         VINF_SUCCESS);
+        if (RT_SUCCESS(rc))
+        {
+            uint8_t *pbTestBuf = (uint8_t *)RTTestGuardedAllocTail(g_hTest, TSTFILEAIO_BUFFER_SIZE);
+            for (unsigned i = 0; i < TSTFILEAIO_BUFFER_SIZE; i++)
+                pbTestBuf[i] = i % 256;
+
+            uint32_t cReqsMax = AioLimits.cReqsOutstandingMax < TSTFILEAIO_MAX_REQS_IN_FLIGHT
+                              ? AioLimits.cReqsOutstandingMax
+                              : TSTFILEAIO_MAX_REQS_IN_FLIGHT;
+
+            /* Basic write test. */
+            RTTestIPrintf(RTTESTLVL_ALWAYS, "Preparing test file, this can take some time and needs quite a bit of harddisk space...\n");
+            tstFileAioTestReadWriteBasic(hFile, true /*fWrite*/, pbTestBuf, TSTFILEAIO_BUFFER_SIZE, 100*_1M, cReqsMax);
+
+            /* Reopen the file before doing the next test. */
+            RTTESTI_CHECK_RC(RTFileClose(hFile), VINF_SUCCESS);
+            if (RTTestErrorCount(g_hTest) == 0)
+            {
+                RTTestSub(g_hTest, "Read/Write");
+                RTTESTI_CHECK_RC(rc = RTFileOpen(&hFile, "tstFileAio#1.tst",
+                                                 RTFILE_O_READWRITE | RTFILE_O_OPEN | RTFILE_O_DENY_NONE | RTFILE_O_ASYNC_IO),
+                                 VINF_SUCCESS);
+                if (RT_SUCCESS(rc))
+                {
+                    tstFileAioTestReadWriteBasic(hFile, false /*fWrite*/, pbTestBuf, TSTFILEAIO_BUFFER_SIZE, 100*_1M, cReqsMax);
+                    RTFileClose(hFile);
+                }
+            }
+
+            /* Cleanup */
+            RTFileDelete("tstFileAio#1.tst");
+        }
+    }
+
+    /*
+     * Summary
+     */
+    return RTTestSummaryAndDestroy(g_hTest);
+}
+
Index: /trunk/src/VBox/Runtime/testcase/tstRTFileAppend-1.cpp
===================================================================
--- /trunk/src/VBox/Runtime/testcase/tstRTFileAppend-1.cpp	(revision 29393)
+++ /trunk/src/VBox/Runtime/testcase/tstRTFileAppend-1.cpp	(revision 29393)
@@ -0,0 +1,209 @@
+/* $Id$ */
+/** @file
+ * IPRT Testcase - File Appending.
+ */
+
+/*
+ * Copyright (C) 2009-2010 Oracle Corporation
+ *
+ * This file is part of VirtualBox Open Source Edition (OSE), as
+ * available from http://www.virtualbox.org. This file is free software;
+ * you can redistribute it and/or modify it under the terms of the GNU
+ * 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.
+ */
+
+
+/*******************************************************************************
+*   Header Files                                                               *
+*******************************************************************************/
+#include <iprt/file.h>
+
+#include <iprt/err.h>
+#include <iprt/string.h>
+#include <iprt/test.h>
+
+
+void tstFileAppend1(RTTEST hTest)
+{
+    /*
+     * Open it write only and do some appending.
+     * Checking that read fails and that the file position changes after the write.
+     */
+    RTTestSub(hTest, "Basic 1");
+    RTFileDelete("tstFileAppend-1.tst");
+    RTFILE hFile = NIL_RTFILE;
+    int rc = RTFileOpen(&hFile,
+                        "tstFileAppend-1.tst",
+                        RTFILE_O_WRITE
+                        | RTFILE_O_APPEND
+                        | RTFILE_O_OPEN_CREATE
+                        | RTFILE_O_DENY_NONE
+                        | (0644 << RTFILE_O_CREATE_MODE_SHIFT)
+                        );
+    RTTESTI_CHECK_RC_RETV(rc, VINF_SUCCESS);
+
+    uint64_t offActual = 42;
+    uint64_t off       = 0;
+    RTTESTI_CHECK_RC(rc = RTFileSeek(hFile, off, RTFILE_SEEK_CURRENT, &offActual), VINF_SUCCESS);
+    RTTESTI_CHECK_MSG(offActual == 0 || RT_FAILURE(rc), ("offActual=%llu", offActual));
+
+    RTTESTI_CHECK_RC(RTFileWrite(hFile, "0123456789", 10, NULL), VINF_SUCCESS);
+
+    offActual = 99;
+    off = 0;
+    RTTESTI_CHECK_RC(rc = RTFileSeek(hFile, off, RTFILE_SEEK_CURRENT, &offActual), VINF_SUCCESS);
+    RTTESTI_CHECK_MSG(offActual == 10 || RT_FAILURE(rc), ("offActual=%llu", offActual));
+    RTTestIPrintf(RTTESTLVL_INFO, "off=%llu after first write\n", offActual);
+
+    size_t  cb = 4;
+    char    szBuf[256];
+    rc = RTFileRead(hFile, szBuf, 1, &cb);
+    RTTESTI_CHECK_MSG(rc == VERR_ACCESS_DENIED || rc == VERR_INVALID_HANDLE, ("rc=%Rrc\n", rc));
+
+    offActual = 999;
+    off = 5;
+    RTTESTI_CHECK_RC(rc = RTFileSeek(hFile, off, RTFILE_SEEK_BEGIN, &offActual), VINF_SUCCESS);
+    RTTESTI_CHECK_MSG(offActual == 5 || RT_FAILURE(rc), ("offActual=%llu", offActual));
+
+    RTTESTI_CHECK_RC(RTFileClose(hFile), VINF_SUCCESS);
+
+
+    /*
+     * Open it write only and do some more appending.
+     * Checking the initial position and that it changes after the write.
+     */
+    RTTestSub(hTest, "Basic 2");
+    rc = RTFileOpen(&hFile,
+                    "tstFileAppend-1.tst",
+                      RTFILE_O_WRITE
+                    | RTFILE_O_APPEND
+                    | RTFILE_O_OPEN
+                    | RTFILE_O_DENY_NONE
+                   );
+    RTTESTI_CHECK_RC_RETV(rc, VINF_SUCCESS);
+
+    offActual = 99;
+    off = 0;
+    RTTESTI_CHECK_RC(rc = RTFileSeek(hFile, off, RTFILE_SEEK_CURRENT, &offActual), VINF_SUCCESS);
+    RTTESTI_CHECK_MSG(offActual == 0 || RT_FAILURE(rc), ("offActual=%llu", offActual));
+    RTTestIPrintf(RTTESTLVL_INFO, "off=%llu on 2nd open\n", offActual);
+
+    RTTESTI_CHECK_RC(rc = RTFileWrite(hFile, "abcdefghij", 10, &cb), VINF_SUCCESS);
+
+    offActual = 999;
+    off = 0;
+    RTTESTI_CHECK_RC(rc = RTFileSeek(hFile, off, RTFILE_SEEK_CURRENT, &offActual), VINF_SUCCESS);
+    RTTESTI_CHECK_MSG(offActual == 20 || RT_FAILURE(rc), ("offActual=%llu", offActual));
+    RTTestIPrintf(RTTESTLVL_INFO, "off=%llu after 2nd write\n", offActual);
+
+    RTTESTI_CHECK_RC(RTFileClose(hFile), VINF_SUCCESS);
+
+    /*
+     * Open it read/write.
+     * Check the initial position and read stuff. Then append some more and
+     * check the new position and see that read returns 0/EOF. Finally,
+     * do some seeking and read from a new position.
+     */
+    RTTestSub(hTest, "Basic 3");
+    rc = RTFileOpen(&hFile,
+                    "tstFileAppend-1.tst",
+                      RTFILE_O_READWRITE
+                    | RTFILE_O_APPEND
+                    | RTFILE_O_OPEN
+                    | RTFILE_O_DENY_NONE
+                   );
+    RTTESTI_CHECK_RC_RETV(rc, VINF_SUCCESS);
+
+    offActual = 9;
+    off = 0;
+    RTTESTI_CHECK_RC(rc = RTFileSeek(hFile, off, RTFILE_SEEK_CURRENT, &offActual), VINF_SUCCESS);
+    RTTESTI_CHECK_MSG(offActual == 0 || RT_FAILURE(rc), ("offActual=%llu", offActual));
+    RTTestIPrintf(RTTESTLVL_INFO, "off=%llu on 3rd open\n", offActual);
+
+    cb = 99;
+    RTTESTI_CHECK_RC(rc = RTFileRead(hFile, szBuf, 10, &cb), VINF_SUCCESS);
+    RTTESTI_CHECK(RT_FAILURE(rc) || cb == 10);
+    RTTESTI_CHECK_MSG(RT_FAILURE(rc) || !memcmp(szBuf, "0123456789", 10), ("read the wrong stuff: %.10s - expected 0123456789\n", szBuf));
+
+    offActual = 999;
+    off = 0;
+    RTTESTI_CHECK_RC(rc = RTFileSeek(hFile, off, RTFILE_SEEK_CURRENT, &offActual), VINF_SUCCESS);
+    RTTESTI_CHECK_MSG(offActual == 10 || RT_FAILURE(rc), ("offActual=%llu", offActual));
+    RTTestIPrintf(RTTESTLVL_INFO, "off=%llu on 1st open\n", offActual);
+
+    RTTESTI_CHECK_RC(RTFileWrite(hFile, "klmnopqrst", 10, NULL), VINF_SUCCESS);
+
+    offActual = 9999;
+    off = 0;
+    RTTESTI_CHECK_RC(rc = RTFileSeek(hFile, off, RTFILE_SEEK_CURRENT, &offActual), VINF_SUCCESS);
+    RTTESTI_CHECK_MSG(offActual == 30 || RT_FAILURE(rc), ("offActual=%llu", offActual));
+    RTTestIPrintf(RTTESTLVL_INFO, "off=%llu after 3rd write\n", offActual);
+
+    RTTESTI_CHECK_RC(rc = RTFileRead(hFile, szBuf, 1, NULL), VERR_EOF);
+    cb = 99;
+    RTTESTI_CHECK_RC(rc = RTFileRead(hFile, szBuf, 1, &cb), VINF_SUCCESS);
+    RTTESTI_CHECK(cb == 0);
+
+
+    offActual = 99999;
+    off = 15;
+    RTTESTI_CHECK_RC(rc = RTFileSeek(hFile, off, RTFILE_SEEK_BEGIN, &offActual), VINF_SUCCESS);
+    RTTESTI_CHECK_MSG(offActual == 15 || RT_FAILURE(rc), ("offActual=%llu", offActual));
+    if (RT_SUCCESS(rc) && offActual == 15)
+    {
+        RTTESTI_CHECK_RC(rc = RTFileRead(hFile, szBuf, 10, NULL), VINF_SUCCESS);
+        RTTESTI_CHECK_MSG(RT_FAILURE(rc) || !memcmp(szBuf, "fghijklmno", 10), ("read the wrong stuff: %.10s - expected fghijklmno\n", szBuf));
+
+        offActual = 9999999;
+        off = 0;
+        RTTESTI_CHECK_RC(rc = RTFileSeek(hFile, off, RTFILE_SEEK_CURRENT, &offActual), VINF_SUCCESS);
+        RTTESTI_CHECK_MSG(offActual == 25 || RT_FAILURE(rc), ("offActual=%llu", offActual));
+        RTTestIPrintf(RTTESTLVL_INFO, "off=%llu after 2nd read\n", offActual);
+    }
+
+    RTTESTI_CHECK_RC(RTFileClose(hFile), VINF_SUCCESS);
+
+    /*
+     * Open it read only + append and check that we cannot write to it.
+     */
+    RTTestSub(hTest, "Basic 4");
+    rc = RTFileOpen(&hFile,
+                    "tstFileAppend-1.tst",
+                      RTFILE_O_READ
+                    | RTFILE_O_APPEND
+                    | RTFILE_O_OPEN
+                    | RTFILE_O_DENY_NONE);
+    RTTESTI_CHECK_RC_RETV(rc, VINF_SUCCESS);
+
+    rc = RTFileWrite(hFile, "pqrstuvwx", 10, &cb);
+    RTTESTI_CHECK_MSG(rc == VERR_ACCESS_DENIED || rc == VERR_INVALID_HANDLE, ("rc=%Rrc\n", rc));
+
+    RTTESTI_CHECK_RC(RTFileClose(hFile), VINF_SUCCESS);
+    RTTESTI_CHECK_RC(RTFileDelete("tstFileAppend-1.tst"), VINF_SUCCESS);
+}
+
+
+int main()
+{
+    RTTEST hTest;
+    int rc = RTTestInitAndCreate("tstRTFileAppend-1", &hTest);
+    if (rc)
+        return rc;
+    RTTestBanner(hTest);
+    tstFileAppend1(hTest);
+    RTFileDelete("tstFileAppend-1.tst");
+    return RTTestSummaryAndDestroy(hTest);
+}
+
