Index: /trunk/src/VBox/Runtime/testcase/tstFileAio.cpp
===================================================================
--- /trunk/src/VBox/Runtime/testcase/tstFileAio.cpp	(revision 29391)
+++ /trunk/src/VBox/Runtime/testcase/tstFileAio.cpp	(revision 29392)
@@ -5,5 +5,5 @@
 
 /*
- * Copyright (C) 2006-2007 Oracle Corporation
+ * Copyright (C) 2006-2010 Oracle Corporation
  *
  * This file is part of VirtualBox Open Source Edition (OSE), as
@@ -30,267 +30,200 @@
 *******************************************************************************/
 #include <iprt/file.h>
-#include <iprt/types.h>
+
 #include <iprt/err.h>
+#include <iprt/mem.h>
+#include <iprt/param.h>
 #include <iprt/string.h>
-#include <iprt/stream.h>
-#include <iprt/mem.h>
-#include <iprt/initterm.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 error counter. */
-int         cErrors = 0;
-
-void tstFileAioTestReadWriteBasic(RTFILE File, bool fWrite, void *pvTestBuf, size_t cbTestBuf, size_t cbTestFile, uint32_t cMaxReqsInFlight)
+#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)
 {
-    int rc = VINF_SUCCESS;
+    /* 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;
-    uint64_t NanoTS = RTTimeNanoTS();
-
-    RTPrintf("tstFileAio: Starting simple %s test...\n", fWrite ? "write" : "read");
-
-    rc = RTFileAioCtxCreate(&hAioContext, cMaxReqsInFlight);
+    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))
     {
-        RTFILEAIOREQ    *paReqs  = NULL;
-        void           **papvBuf = NULL;
-        RTFOFF           Offset = 0;
-        size_t           cbLeft = cbTestFile;
-        int cRun = 0;
-
-        /* Allocate request array. */
-        paReqs = (PRTFILEAIOREQ)RTMemAllocZ(cMaxReqsInFlight * sizeof(RTFILEAIOREQ));
-        if (paReqs)
+        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))
         {
-            /* Allocate array holding pointer to data buffers. */
-            papvBuf = (void **)RTMemAllocZ(cMaxReqsInFlight * sizeof(void *));
-            if (papvBuf)
+            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)
             {
-                /* Allocate array holding completed requests. */
-                RTFILEAIOREQ *paReqsCompleted = NULL;
-                paReqsCompleted = (PRTFILEAIOREQ)RTMemAllocZ(cMaxReqsInFlight * sizeof(RTFILEAIOREQ));
-                if (paReqsCompleted)
+                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))
                 {
-                    /* Associate file with context.*/
-                    rc = RTFileAioCtxAssociateWithFile(hAioContext, File);
-                    if (RT_SUCCESS(rc))
-                    {
-                        /* Initialize buffers. */
-                        for (unsigned i = 0; i < cMaxReqsInFlight; i++)
-                        {
-                            papvBuf[i] = RTMemPageAllocZ(cbTestBuf);
-
-                            if (fWrite)
-                                memcpy(papvBuf[i], pvTestBuf, cbTestBuf);
-                        }
-
-                        /* Initialize requests. */
-                        for (unsigned i = 0; i < cMaxReqsInFlight; i++)
-                            RTFileAioReqCreate(&paReqs[i]);
-
-                        while (cbLeft)
-                        {
-                            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, Offset, papvBuf[i],
-                                                                  cbTransfer, papvBuf[i]);
-                                else
-                                    rc = RTFileAioReqPrepareRead(paReqs[i], File, Offset, papvBuf[i],
-                                                                 cbTransfer, papvBuf[i]);
-
-                                cbLeft -= cbTransfer;
-                                Offset += cbTransfer;
-                                cReqs++;
-                            }
-
-                            rc = RTFileAioCtxSubmit(hAioContext, paReqs, cReqs);
-                            if (RT_FAILURE(rc))
-                            {
-                                RTPrintf("tstFileAio: FATAL ERROR - Failed to submit tasks after %d runs. rc=%Rrc\n", cRun, rc);
-                                cErrors++;
-                                break;
-                            }
-
-                            /* Wait */
-                            uint32_t cCompleted = 0;
-                            rc = RTFileAioCtxWait(hAioContext, cReqs, RT_INDEFINITE_WAIT,
-                                                  paReqsCompleted, cMaxReqsInFlight,
-                                                  &cCompleted);
-                            if (RT_FAILURE(rc))
-                            {
-                                RTPrintf("tstFileAio: FATAL ERROR - Waiting failed. rc=%Rrc\n", rc);
-                                cErrors++;
-                                break;
-                            }
-
-                            if (!fWrite)
-                            {
-                                for (uint32_t i = 0; i < cCompleted; i++)
-                                {
-                                    /* Compare that we read the right stuff. */
-                                    void *pvBuf = RTFileAioReqGetUser(paReqsCompleted[i]);
-
-                                    size_t cbTransfered;
-                                    int rcReq = RTFileAioReqGetRC(paReqsCompleted[i], &cbTransfered);
-                                    if (RT_FAILURE(rcReq) || (cbTransfered != cbTestBuf))
-                                    {
-                                        RTPrintf("tstFileAio: FATAL ERROR - Request %d failed with rc=%Rrc cbTransfered=%d.\n",
-                                                 i, rcReq, cbTransfered);
-                                        cErrors++;
-                                        rc = rcReq;
-                                        break;
-                                    }
-
-                                    if (memcmp(pvBuf, pvTestBuf, cbTestBuf) != 0)
-                                    {
-                                        RTPrintf("tstFileAio: FATAL ERROR - Unexpected content in memory.\n");
-                                        cErrors++;
-                                        break;
-                                    }
-                                    memset(pvBuf, 0, cbTestBuf);
-                                }
-                            }
-                            cRun++;
-                            if (RT_FAILURE(rc))
-                                break;
-                        }
-
-                        /* Free buffers. */
-                        for (unsigned i = 0; i < cMaxReqsInFlight; i++)
-                            RTMemPageFree(papvBuf[i], cbTestBuf);
-
-                        /* Free requests. */
-                        for (unsigned i = 0; i < cMaxReqsInFlight; i++)
-                        {
-                            rc = RTFileAioReqDestroy(paReqs[i]);
-                            if (RT_FAILURE(rc))
-                            {
-                                RTPrintf("tstFileAio: ERROR - Failed to destroy request %d. rc=%Rrc\n", i, rc);
-                                cErrors++;
-                            }
-                        }
-
-                        NanoTS = RTTimeNanoTS() - NanoTS;
-                        unsigned SpeedKBs = (unsigned)(cbTestFile / (NanoTS / 1000000000.0) / 1024);
-
-                        RTPrintf("tstFileAio: Completed simple %s test: %d.%03d MB/sec\n",
-                                 fWrite ? "write" : "read",
-                                 SpeedKBs / 1000,
-                                 SpeedKBs % 1000);
-                    }
-                    else
-                    {
-                        RTPrintf("tstFileAio: FATAL ERROR - Failed to asssociate file with async I/O context. rc=%Rrc\n", rc);
-                        cErrors++;
-                    }
+                    tstFileAioTestReadWriteBasic(hFile, false /*fWrite*/, pbTestBuf, TSTFILEAIO_BUFFER_SIZE, 100*_1M, cReqsMax);
+                    RTFileClose(hFile);
                 }
-                else
-                {
-                    RTPrintf("tstFileAio: FATAL ERROR - Failed to allocate memory for completed request array.\n");
-                    cErrors++;
-                }
-                RTMemFree(papvBuf);
             }
-            else
-            {
-                RTPrintf("tstFileAio: FATAL ERROR - Failed to allocate memory for buffer array.\n");
-                cErrors++;
-            }
-            RTMemFree(paReqs);
-        }
-        else
-        {
-            RTPrintf("tstFileAio: FATAL ERROR - Failed to allocate memory for request array.\n");
-            cErrors++;
-        }
-
-        rc = RTFileAioCtxDestroy(hAioContext);
-        if (RT_FAILURE(rc))
-        {
-            RTPrintf("tstFileAio: FATAL ERROR - Failed to destroy async I/O context. rc=%Rrc\n", rc);
-            cErrors++;
+
+            /* Cleanup */
+            RTFileDelete("tstFileAio#1.tst");
         }
     }
-    else
-    {
-        RTPrintf("tstFileAio: FATAL ERROR - Failed to create async I/O context. rc=%Rrc\n", rc);
-        cErrors++;
-    }
-}
-
-int main()
-{
-    RTPrintf("tstFileAio: TESTING\n");
-    RTR3Init();
-
-    /* Check if the API is available. */
-    RTFILEAIOLIMITS AioLimits;
-
-    memset(&AioLimits, 0, sizeof(AioLimits));
-    int rc = RTFileAioGetLimits(&AioLimits);
-    if (RT_FAILURE(rc))
-    {
-        if (rc == VERR_NOT_SUPPORTED)
-            RTPrintf("tstFileAio: FATAL ERROR - File AIO API not available\n");
-        else
-            RTPrintf("tstFileAio: FATAL ERROR - Unexpected error rc=%Rrc\n", rc);
-        return 1;
-    }
-
-    RTFILE    File;
-    void *pvTestBuf = NULL;
-    rc = RTFileOpen(&File, "tstFileAio#1.tst", RTFILE_O_READWRITE | RTFILE_O_CREATE_REPLACE | RTFILE_O_DENY_NONE | RTFILE_O_ASYNC_IO);
-    if (RT_FAILURE(rc))
-    {
-        RTPrintf("tstFileAio: FATAL ERROR - Failed to open file #1. rc=%Rrc\n", rc);
-        return 1;
-    }
-
-    pvTestBuf = RTMemAllocZ(64 * _1K);
-    for (unsigned i = 0; i < 64*_1K; i++)
-        ((char *)pvTestBuf)[i] = i % 256;
-
-    uint32_t cReqsMax =   AioLimits.cReqsOutstandingMax < TSTFILEAIO_MAX_REQS_IN_FLIGHT
-                        ? AioLimits.cReqsOutstandingMax
-                        : TSTFILEAIO_MAX_REQS_IN_FLIGHT;
-
-    /* Basic write test. */
-    RTPrintf("tstFileAio: Preparing test file, this can take some time and needs quite a bit of harddisk\n");
-    tstFileAioTestReadWriteBasic(File, true, pvTestBuf, 64*_1K, 100*_1M, cReqsMax);
-    /* Reopen the file. */
-    RTFileClose(File);
-    rc = RTFileOpen(&File, "tstFileAio#1.tst", RTFILE_O_READWRITE | RTFILE_O_OPEN | RTFILE_O_DENY_NONE | RTFILE_O_ASYNC_IO);
-    if (RT_SUCCESS(rc))
-    {
-        tstFileAioTestReadWriteBasic(File, false, pvTestBuf, 64*_1K, 100*_1M, cReqsMax);
-        RTFileClose(File);
-    }
-    else
-    {
-        RTPrintf("tstFileAio: FATAL ERROR - Failed to open file #1. rc=%Rrc\n", rc);
-        cErrors++;
-    }
-
-    /* Cleanup */
-    RTMemFree(pvTestBuf);
-    RTFileDelete("tstFileAio#1.tst");
+
     /*
      * Summary
      */
-    if (cErrors == 0)
-        RTPrintf("tstFileAio: SUCCESS\n");
-    else
-        RTPrintf("tstFileAio: FAILURE - %d errors\n", cErrors);
-    return !!cErrors;
+    return RTTestSummaryAndDestroy(g_hTest);
 }
 
Index: /trunk/src/VBox/Runtime/testcase/tstFileAppend-1.cpp
===================================================================
--- /trunk/src/VBox/Runtime/testcase/tstFileAppend-1.cpp	(revision 29391)
+++ /trunk/src/VBox/Runtime/testcase/tstFileAppend-1.cpp	(revision 29392)
@@ -5,5 +5,5 @@
 
 /*
- * Copyright (C) 2009 Oracle Corporation
+ * Copyright (C) 2009-2010 Oracle Corporation
  *
  * This file is part of VirtualBox Open Source Edition (OSE), as
@@ -30,102 +30,53 @@
 *******************************************************************************/
 #include <iprt/file.h>
+
 #include <iprt/err.h>
-#include <iprt/initterm.h>
-#include <iprt/stream.h>
 #include <iprt/string.h>
-
-
-/*******************************************************************************
-*   Global Variables                                                           *
-*******************************************************************************/
-static int g_cErrors = 0;
-
-
-static int MyFailure(const char *pszFormat, ...)
+#include <iprt/test.h>
+
+
+void tstFileAppend1(RTTEST hTest)
 {
-    va_list va;
-
-    RTPrintf("tstFileAppend-1: FATAL: ");
-    va_start(va, pszFormat);
-    RTPrintfV(pszFormat, va);
-    va_end(va);
-    g_cErrors++;
-    return 1;
-}
-
-
-void MyError(const char *pszFormat, ...)
-{
-    va_list va;
-
-    RTPrintf("tstFileAppend-1: ERROR: ");
-    va_start(va, pszFormat);
-    RTPrintfV(pszFormat, va);
-    va_end(va);
-    g_cErrors++;
-}
-
-int main()
-{
-    int rc;
-    RTFILE File;
-    int64_t off;
-    uint64_t offActual;
-    size_t cb;
-    char szBuf[256];
-
-
-    RTPrintf("tstFileAppend-1: TESTING...\n");
-
-    RTR3Init();
-
     /*
      * 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");
-    rc = RTFileOpen(&File,
-                    "tstFileAppend-1.tst",
-                      RTFILE_O_WRITE
-                    | RTFILE_O_APPEND
-                    | RTFILE_O_OPEN_CREATE
-                    | RTFILE_O_DENY_NONE
-                    | (0644 << RTFILE_O_CREATE_MODE_SHIFT)
-                   );
-    if (RT_FAILURE(rc))
-        return MyFailure("1st RTFileOpen: %Rrc\n", rc);
-
-    off = 0;
-    rc = RTFileSeek(File, off, RTFILE_SEEK_CURRENT, &offActual);
-    if (RT_FAILURE(rc))
-        MyError("1st RTFileSeek failed: %Rrc\n", rc);
-    else if (offActual != 0)
-        MyError("unexpected position on 1st open: %llu - expected 0\n", offActual);
-
-    rc = RTFileWrite(File, "0123456789", 10, &cb);
-    if (RT_FAILURE(rc))
-        MyError("1st write fail: %Rrc\n", rc);
-
-    off = 0;
-    rc = RTFileSeek(File, off, RTFILE_SEEK_CURRENT, &offActual);
-    if (RT_FAILURE(rc))
-        MyError("2nd RTFileSeek failed: %Rrc\n", rc);
-    else if (offActual != 10)
-        MyError("unexpected position after 1st write: %llu - expected 10\n", offActual);
-    else
-        RTPrintf("tstFileAppend-1: off=%llu after first write\n", offActual);
-
-    rc = RTFileRead(File, szBuf, 1, &cb);
-    if (RT_SUCCESS(rc))
-        MyError("read didn't fail! cb=%#lx\n", (long)cb);
-
+    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;
-    rc = RTFileSeek(File, off, RTFILE_SEEK_BEGIN, &offActual);
-    if (RT_FAILURE(rc))
-        MyError("3rd RTFileSeek failed: %Rrc\n", rc);
-    else if (offActual != 5)
-        MyError("unexpected position after 3rd set file pointer: %llu - expected 5\n", offActual);
-
-    RTFileClose(File);
+    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);
 
 
@@ -134,5 +85,6 @@
      * Checking the initial position and that it changes after the write.
      */
-    rc = RTFileOpen(&File,
+    RTTestSub(hTest, "Basic 2");
+    rc = RTFileOpen(&hFile,
                     "tstFileAppend-1.tst",
                       RTFILE_O_WRITE
@@ -141,30 +93,21 @@
                     | RTFILE_O_DENY_NONE
                    );
-    if (RT_FAILURE(rc))
-        return MyFailure("2nd RTFileOpen: %Rrc\n", rc);
-
-    off = 0;
-    rc = RTFileSeek(File, off, RTFILE_SEEK_CURRENT, &offActual);
-    if (RT_FAILURE(rc))
-        MyError("4th RTFileSeek failed: %Rrc\n", rc);
-    else if (offActual != 0)
-        MyError("unexpected position on 2nd open: %llu - expected 0\n", offActual);
-    else
-        RTPrintf("tstFileAppend-1: off=%llu on 2nd open\n", offActual);
-
-    rc = RTFileWrite(File, "abcdefghij", 10, &cb);
-    if (RT_FAILURE(rc))
-        MyError("2nd write fail: %Rrc\n", rc);
-
-    off = 0;
-    rc = RTFileSeek(File, off, RTFILE_SEEK_CURRENT, &offActual);
-    if (RT_FAILURE(rc))
-        MyError("5th RTFileSeek failed: %Rrc\n", rc);
-    else if (offActual != 20)
-        MyError("unexpected position after 2nd write: %llu - expected 20\n", offActual);
-    else
-        RTPrintf("tstFileAppend-1: off=%llu after 2nd write\n", offActual);
-
-    RTFileClose(File);
+    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);
 
     /*
@@ -174,5 +117,6 @@
      * do some seeking and read from a new position.
      */
-    rc = RTFileOpen(&File,
+    RTTestSub(hTest, "Basic 3");
+    rc = RTFileOpen(&hFile,
                     "tstFileAppend-1.tst",
                       RTFILE_O_READWRITE
@@ -181,99 +125,85 @@
                     | RTFILE_O_DENY_NONE
                    );
-    if (RT_FAILURE(rc))
-        return MyFailure("3rd RTFileOpen: %Rrc\n", rc);
-
-    off = 0;
-    rc = RTFileSeek(File, off, RTFILE_SEEK_CURRENT, &offActual);
-    if (RT_FAILURE(rc))
-        MyError("6th RTFileSeek failed: %Rrc\n", rc);
-    else if (offActual != 0)
-        MyError("unexpected position on 3rd open: %llu - expected 0\n", offActual);
-    else
-        RTPrintf("tstFileAppend-1: off=%llu on 3rd open\n", offActual);
-
-    rc = RTFileRead(File, szBuf, 10, &cb);
-    if (RT_FAILURE(rc) || cb != 10)
-        MyError("1st RTFileRead failed: %Rrc\n", rc);
-    else if (memcmp(szBuf, "0123456789", 10))
-        MyError("read the wrong stuff: %.10s - expected 0123456789\n", szBuf);
-
-    off = 0;
-    rc = RTFileSeek(File, off, RTFILE_SEEK_CURRENT, &offActual);
-    if (RT_FAILURE(rc))
-        MyError("7th RTFileSeek failed: %Rrc\n", rc);
-    else if (offActual != 10)
-        MyError("unexpected position after 1st read: %llu - expected 10\n", offActual);
-    else
-        RTPrintf("tstFileAppend-1: off=%llu on 1st open\n", offActual);
-
-    rc = RTFileWrite(File, "klmnopqrst", 10, &cb);
-    if (RT_FAILURE(rc))
-        MyError("3rd write fail: %Rrc\n", rc);
-
-    off = 0;
-    rc = RTFileSeek(File, off, RTFILE_SEEK_CURRENT, &offActual);
-    if (RT_FAILURE(rc))
-        MyError("8th RTFileSeek failed: %Rrc\n", rc);
-    else if (offActual != 30)
-        MyError("unexpected position after 3rd write: %llu - expected 30\n", offActual);
-    else
-        RTPrintf("tstFileAppend-1: off=%llu after 3rd write\n", offActual);
-
-    rc = RTFileRead(File, szBuf, 1, &cb);
-    if (RT_SUCCESS(rc) && cb != 0)
-        MyError("read after write didn't fail! cb=%#lx\n", (long)cb);
-
+    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;
-    rc = RTFileSeek(File, off, RTFILE_SEEK_BEGIN, &offActual);
-    if (RT_FAILURE(rc))
-        MyError("9th RTFileSeek failed: %Rrc\n", rc);
-    else if (offActual != 15)
-        MyError("unexpected position after 9th seek: %llu - expected 15\n", offActual);
-    else
+    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)
     {
-        rc = RTFileRead(File, szBuf, 10, &cb);
-        if (RT_FAILURE(rc) || cb != 10)
-            MyError("2nd RTFileRead failed: %Rrc\n", rc);
-        else if (memcmp(szBuf, "fghijklmno", 10))
-            MyError("read the wrong stuff: %.10s - expected fghijklmno\n", szBuf);
-
+        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;
-        rc = RTFileSeek(File, off, RTFILE_SEEK_CURRENT, &offActual);
-        if (RT_FAILURE(rc))
-            MyError("10th RTFileSeek failed: %Rrc\n", rc);
-        else if (offActual != 25)
-            MyError("unexpected position after 2nd read: %llu - expected 25\n", offActual);
-        else
-            RTPrintf("tstFileAppend-1: off=%llu after 2nd read\n", offActual);
+        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);
     }
 
-    RTFileClose(File);
+    RTTESTI_CHECK_RC(RTFileClose(hFile), VINF_SUCCESS);
 
     /*
      * Open it read only + append and check that we cannot write to it.
      */
-    rc = RTFileOpen(&File,
+    RTTestSub(hTest, "Basic 4");
+    rc = RTFileOpen(&hFile,
                     "tstFileAppend-1.tst",
                       RTFILE_O_READ
                     | RTFILE_O_APPEND
                     | RTFILE_O_OPEN
-                    | RTFILE_O_DENY_NONE
-                   );
-    if (RT_FAILURE(rc))
-        return MyFailure("4th RTFileOpen: %Rrc\n", rc);
-
-    rc = RTFileWrite(File, "pqrstuvwx", 10, &cb);
-    if (RT_SUCCESS(rc))
-        MyError("write didn't fail on read-only+append open: cb=%#lx\n", (long)cb);
-
-    RTFileClose(File);
+                    | 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");
-
-    if (g_cErrors)
-        RTPrintf("tstFileAppend-1: FAILED\n");
-    else
-        RTPrintf("tstFileAppend-1: SUCCESS\n");
-    return g_cErrors ? 1 : 0;
+    return RTTestSummaryAndDestroy(hTest);
 }
 
