VirtualBox

Ignore:
Timestamp:
Aug 13, 2014 7:00:27 PM (11 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
95511
Message:

Storage/tstVDIo: Plug leaks, modifications and start turning it into a proper testcase for unit tests

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Storage/testcase/tstVDIo.cpp

    r52111 r52371  
    66
    77/*
    8  * Copyright (C) 2011-2013 Oracle Corporation
     8 * Copyright (C) 2011-2014 Oracle Corporation
    99 *
    1010 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    3333#include <iprt/rand.h>
    3434#include <iprt/critsect.h>
     35#include <iprt/test.h>
    3536
    3637#include "VDMemDisk.h"
     
    4041#include "VDScript.h"
    4142#include "BuiltinTests.h"
     43
     44/** forward declaration for the global test data pointer. */
     45typedef struct VDTESTGLOB *PVDTESTGLOB;
    4246
    4347/**
     
    100104    /** Logical CHS geometry. */
    101105    VDGEOMETRY     LogicalGeom;
     106    /** Global test data. */
     107    PVDTESTGLOB    pTestGlob;
    102108} VDDISK, *PVDDISK;
    103109
     
    142148    /** Current storage backend to use. */
    143149    char            *pszIoBackend;
    144 } VDTESTGLOB, *PVDTESTGLOB;
     150    /** Testcase handle. */
     151    RTTEST           hTest;
     152} VDTESTGLOB;
    145153
    146154/**
     
    256264    VDSCRIPTTYPE_STRING,
    257265    VDSCRIPTTYPE_UINT64,
     266    VDSCRIPTTYPE_BOOL,
    258267    VDSCRIPTTYPE_BOOL
    259268};
     
    269278    VDSCRIPTTYPE_BOOL,   /* readonly */
    270279    VDSCRIPTTYPE_BOOL,   /* discard */
    271     VDSCRIPTTYPE_BOOL    /* ignoreflush */
     280    VDSCRIPTTYPE_BOOL,   /* ignoreflush */
     281    VDSCRIPTTYPE_BOOL,   /* honorsame */
    272282};
    273283
     
    533543    bool fDynamic = true;
    534544    bool fIgnoreFlush = false;
     545    bool fHonorSame = false;
    535546    PVDIOBACKEND pIoBackend = NULL;
    536547
     
    558569    cbSize = paScriptArgs[5].u64;
    559570    fIgnoreFlush = paScriptArgs[6].f;
     571    fHonorSame = paScriptArgs[7].f;
    560572
    561573    if (RT_SUCCESS(rc))
     
    572584            if (fIgnoreFlush)
    573585                fOpenFlags |= VD_OPEN_FLAGS_IGNORE_FLUSH;
     586
     587            if (fHonorSame)
     588                fOpenFlags |= VD_OPEN_FLAGS_HONOR_SAME;
    574589
    575590            if (fBase)
     
    601616    bool fDiscard  = false;
    602617    bool fIgnoreFlush = false;
     618    bool fHonorSame = false;
    603619
    604620    pcszDisk = paScriptArgs[0].psz;
     
    609625    fAsyncIo = paScriptArgs[5].f;
    610626    fDiscard = paScriptArgs[6].f;
     627    fIgnoreFlush = paScriptArgs[7].f;
     628    fHonorSame = paScriptArgs[8].f;
    611629
    612630    if (RT_SUCCESS(rc))
     
    627645            if (fIgnoreFlush)
    628646                fOpenFlags |= VD_OPEN_FLAGS_IGNORE_FLUSH;
     647            if (fHonorSame)
     648                fOpenFlags |= VD_OPEN_FLAGS_HONOR_SAME;
    629649
    630650            rc = VDOpen(pDisk->pVD, pcszBackend, pcszImage, fOpenFlags, pGlob->pInterfacesImages);
     
    713733        VDIOTEST IoTest;
    714734
     735        RTTestSub(pGlob->hTest, "Basic I/O");
    715736        rc = tstVDIoTestInit(&IoTest, pGlob, fRandomAcc, cbIo, cbBlkSize, offStart, offEnd, uWriteChance, pPattern);
    716737        if (RT_SUCCESS(rc))
     
    771792                                                if (VDMemDiskCmp(pDisk->pMemDiskVerify, paIoReq[idx].off, paIoReq[idx].cbReq, &SgBuf))
    772793                                                {
    773                                                     RTPrintf("Corrupted disk at offset %llu!\n", paIoReq[idx].off);
     794                                                    RTTestFailed(pGlob->hTest, "Corrupted disk at offset %llu!\n", paIoReq[idx].off);
    774795                                                    rc = VERR_INVALID_STATE;
    775796                                                }
     
    850871                                                                     &paIoReq[idx].SgBuf))
    851872                                                    {
    852                                                         RTPrintf("Corrupted disk at offset %llu!\n", paIoReq[idx].off);
     873                                                        RTTestFailed(pGlob->hTest, "Corrupted disk at offset %llu!\n", paIoReq[idx].off);
    853874                                                        rc = VERR_INVALID_STATE;
    854875                                                    }
     
    924945                NanoTS = RTTimeNanoTS() - NanoTS;
    925946                uint64_t SpeedKBs = (uint64_t)(cbIo / (NanoTS / 1000000000.0) / 1024);
    926                 RTPrintf("I/O Test: Throughput %lld kb/s\n", SpeedKBs);
     947                RTTestValue(pGlob->hTest, "Throughput", SpeedKBs, RTTESTUNIT_KILOBYTES_PER_SEC);
     948
     949                for (unsigned i = 0; i < cMaxTasksOutstanding; i++)
     950                {
     951                    if (paIoReq[i].pvBufRead)
     952                        RTMemFree(paIoReq[i].pvBufRead);
     953                }
    927954
    928955                RTSemEventDestroy(EventSem);
     
    17461773        if (pDisk)
    17471774        {
     1775            pDisk->pTestGlob = pGlob;
    17481776            pDisk->pszName = RTStrDup(pcszDisk);
    17491777            if (pDisk->pszName)
     
    18461874            cbDisk2 = VDGetSize(pDisk2->pVD, VD_LAST_IMAGE);
    18471875
     1876            RTTestSub(pGlob->hTest, "Comparing two disks for equal content");
    18481877            if (cbDisk1 != cbDisk2)
    1849                 RTPrintf("Disks differ in size %llu vs %llu\n", cbDisk1, cbDisk2);
     1878                RTTestFailed(pGlob->hTest, "Disks differ in size %llu vs %llu\n", cbDisk1, cbDisk2);
    18501879            else
    18511880            {
     
    18621891                        if (memcmp(pbBuf1, pbBuf2, cbRead))
    18631892                        {
    1864                             RTPrintf("Disks differ at offset %llu\n", uOffCur);
     1893                            RTTestFailed(pGlob->hTest, "Disks differ at offset %llu\n", uOffCur);
    18651894                            rc = VERR_DEV_IO_ERROR;
    18661895                            break;
     
    18691898                    else
    18701899                    {
    1871                         RTPrintf("Reading one disk at offset %llu failed\n", uOffCur);
     1900                        RTTestFailed(pGlob->hTest, "Reading one disk at offset %llu failed\n", uOffCur);
    18721901                        break;
    18731902                    }
     
    25172546                if (VDMemDiskCmp(pDisk->pMemDiskVerify, pIoReq->off, pIoReq->cbReq,
    25182547                                 &pIoReq->SgBuf))
    2519                     RTPrintf("Corrupted disk at offset %llu!\n", pIoReq->off);
     2548                    RTTestFailed(pDisk->pTestGlob->hTest, "Corrupted disk at offset %llu!\n", pIoReq->off);
    25202549                RTCritSectLeave(&pDisk->CritSectVerify);
    25212550            }
     
    26972726    AssertRC(rc);
    26982727
    2699     /* Init I/O backend. */
    2700     rc = VDIoBackendCreate(&GlobTest.pIoBackend);
     2728    rc = RTTestCreate("tstVDIo", &GlobTest.hTest);
    27012729    if (RT_SUCCESS(rc))
    27022730    {
    2703         VDSCRIPTCTX hScriptCtx = NULL;
    2704         rc = VDScriptCtxCreate(&hScriptCtx);
     2731        /* Init I/O backend. */
     2732        rc = VDIoBackendCreate(&GlobTest.pIoBackend);
    27052733        if (RT_SUCCESS(rc))
    27062734        {
    2707             rc = VDScriptCtxCallbacksRegister(hScriptCtx, g_aScriptActions, g_cScriptActions, &GlobTest);
    2708             AssertRC(rc);
    2709 
    2710             rc = VDScriptCtxLoadScript(hScriptCtx, pszScript);
    2711             if (RT_FAILURE(rc))
     2735            VDSCRIPTCTX hScriptCtx = NULL;
     2736            rc = VDScriptCtxCreate(&hScriptCtx);
     2737            if (RT_SUCCESS(rc))
    27122738            {
    2713                 RTPrintf("Loading the script failed rc=%Rrc\n", rc);
     2739                RTTEST_CHECK_RC_OK(GlobTest.hTest,
     2740                                   VDScriptCtxCallbacksRegister(hScriptCtx, g_aScriptActions, g_cScriptActions, &GlobTest));
     2741
     2742                RTTestBanner(GlobTest.hTest);
     2743                rc = VDScriptCtxLoadScript(hScriptCtx, pszScript);
     2744                if (RT_FAILURE(rc))
     2745                {
     2746                    RTPrintf("Loading the script failed rc=%Rrc\n", rc);
     2747                }
     2748                else
     2749                    rc = VDScriptCtxCallFn(hScriptCtx, "main", NULL, 0);
     2750                VDScriptCtxDestroy(hScriptCtx);
    27142751            }
    2715             else
    2716                 rc = VDScriptCtxCallFn(hScriptCtx, "main", NULL, 0);
    2717             VDScriptCtxDestroy(hScriptCtx);
    2718         }
    2719         VDIoBackendDestroy(GlobTest.pIoBackend);
    2720     }
    2721     else
    2722         RTPrintf("Creating the I/O backend failed rc=%Rrc\n");
     2752            VDIoBackendDestroy(GlobTest.pIoBackend);
     2753        }
     2754        else
     2755            RTPrintf("Creating the I/O backend failed rc=%Rrc\n");
     2756
     2757        RTTestSummaryAndDestroy(GlobTest.hTest);
     2758    }
     2759    else
     2760        RTStrmPrintf(g_pStdErr, "tstVDIo: fatal error: RTTestCreate failed with rc=%Rrc\n", rc);
    27232761
    27242762    RTStrFree(GlobTest.pszIoBackend);
     
    27462784        AssertPtr(pszScript);
    27472785        tstVDIoScriptExec(pszScript);
     2786        RTStrFree(pszScript);
    27482787    }
    27492788    else
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette