VirtualBox

Changeset 52111 in vbox


Ignore:
Timestamp:
Jul 21, 2014 1:28:54 PM (11 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
95134
Message:

Storage/testcases: Include the tests scripts into tstVDIo for automated testing

Location:
trunk/src/VBox/Storage/testcase
Files:
1 added
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Storage/testcase/Makefile.kmk

    r50052 r52111  
    5151  PROGRAMS += tstVDIo
    5252
     53  #
     54  # VD I/O test scripts to built in -> .cpp
     55  #
     56  TSTVDIO_BUILTIN_TESTS_FILE = $(tstVDIo_0_OUTDIR)/BuiltinTests.cpp
     57  TSTVDIO_BUILTIN_TESTS := \
     58         tstVDIo=tstVDIo.vd \
     59         tstVDResize=tstVDResize.vd \
     60         tstVDCompact=tstVDCompact.vd \
     61         tstVDCopy=tstVDCopy.vd \
     62         tstVDDiscard=tstVDDiscard.vd \
     63         tstVDShareable=tstVDShareable.vd
     64  TSTVDIO_BUILTIN_TEST_NAMES := $(foreach test,$(TSTVDIO_BUILTIN_TESTS),$(firstword $(subst =,$(SPACE) ,$(test))))
     65  TSTVDIO_PATH_TESTS := $(PATH_SUB_CURRENT)
     66
     67  # 1=name, 2=filter
     68  TSTVDIO_GEN_TEST_MACRO = 'TSTVDIOTESTENTRY const g_a$(1)[] =' '{' \
     69        $(foreach testnm,$(filter $(2),$(TSTVDIO_BUILTIN_TEST_NAMES)), '    TSTVDIOTESTENTRY_GEN(g_ab$(testnm)),') \
     70        '};' 'unsigned const g_c$(1) = RT_ELEMENTS(g_a$(1));' '' ''
     71
     72  $$(TSTVDIO_BUILTIN_TESTS_FILE): $(MAKEFILE_CURRENT) \
     73                $(foreach test,$(TSTVDIO_BUILTIN_TESTS),$(TSTVDIO_PATH_TESTS)/$(lastword $(subst =,$(SPACE) ,$(test)))) \
     74                $(VBOX_BIN2C) \
     75                | $$(dir $$@)
     76        $(QUIET)$(RM) -f -- $@ $@.vd
     77        $(QUIET)$(APPEND) -n "$@" \
     78        '' \
     79        '#include "BuiltinTests.h"' \
     80               ''
     81        $(foreach test,$(TSTVDIO_BUILTIN_TESTS), $(NLTAB)$(VBOX_BIN2C) -ascii --append \
     82                "$(firstword $(subst =,$(SP) ,$(test)))" \
     83                "$(TSTVDIO_PATH_TESTS)/$(lastword $(subst =,$(SP) ,$(test)))" \
     84                "$@")
     85
     86# Generate certificate lists.
     87        $(QUIET)$(APPEND) -n "$@" '' \
     88               $(call TSTVDIO_GEN_TEST_MACRO,VDIoTests,%) \
     89
    5390  tstVDIo_TEMPLATE = VBOXR3TSTEXE
     91  tstVDIo_INCS := $(PATH_SUB_CURRENT)
    5492  tstVDIo_SOURCES  = tstVDIo.cpp \
    5593        VDIoBackend.cpp \
     
    6098        VDScriptAst.cpp \
    6199        VDScriptChecker.cpp \
    62         VDScriptInterp.cpp
     100        VDScriptInterp.cpp \
     101        $(TSTVDIO_BUILTIN_TESTS_FILE)
    63102  tstVDIo_LIBS = \
    64103        $(LIB_DDU) \
  • trunk/src/VBox/Storage/testcase/tstVDIo.cpp

    r46247 r52111  
    3939
    4040#include "VDScript.h"
     41#include "BuiltinTests.h"
    4142
    4243/**
     
    26482649
    26492650/**
     2651 * Executes the given script.
     2652 *
     2653 * @returns nothing.
     2654 * @param   pszScript    The script to execute.
     2655 */
     2656static void tstVDIoScriptExec(const char *pszScript)
     2657{
     2658    int rc = VINF_SUCCESS;
     2659    VDTESTGLOB GlobTest;   /**< Global test data. */
     2660
     2661    memset(&GlobTest, 0, sizeof(VDTESTGLOB));
     2662    RTListInit(&GlobTest.ListFiles);
     2663    RTListInit(&GlobTest.ListDisks);
     2664    RTListInit(&GlobTest.ListPatterns);
     2665    GlobTest.pszIoBackend = RTStrDup("memory");
     2666    if (!GlobTest.pszIoBackend)
     2667    {
     2668        RTPrintf("Out of memory allocating I/O backend string\n");
     2669        return;
     2670    }
     2671
     2672    /* Init global test data. */
     2673    GlobTest.VDIfError.pfnError     = tstVDError;
     2674    GlobTest.VDIfError.pfnMessage   = tstVDMessage;
     2675
     2676    rc = VDInterfaceAdd(&GlobTest.VDIfError.Core, "tstVDIo_VDIError", VDINTERFACETYPE_ERROR,
     2677                        NULL, sizeof(VDINTERFACEERROR), &GlobTest.pInterfacesDisk);
     2678    AssertRC(rc);
     2679
     2680    GlobTest.VDIfIo.pfnOpen                = tstVDIoFileOpen;
     2681    GlobTest.VDIfIo.pfnClose               = tstVDIoFileClose;
     2682    GlobTest.VDIfIo.pfnDelete              = tstVDIoFileDelete;
     2683    GlobTest.VDIfIo.pfnMove                = tstVDIoFileMove;
     2684    GlobTest.VDIfIo.pfnGetFreeSpace        = tstVDIoFileGetFreeSpace;
     2685    GlobTest.VDIfIo.pfnGetModificationTime = tstVDIoFileGetModificationTime;
     2686    GlobTest.VDIfIo.pfnGetSize             = tstVDIoFileGetSize;
     2687    GlobTest.VDIfIo.pfnSetSize             = tstVDIoFileSetSize;
     2688    GlobTest.VDIfIo.pfnWriteSync           = tstVDIoFileWriteSync;
     2689    GlobTest.VDIfIo.pfnReadSync            = tstVDIoFileReadSync;
     2690    GlobTest.VDIfIo.pfnFlushSync           = tstVDIoFileFlushSync;
     2691    GlobTest.VDIfIo.pfnReadAsync           = tstVDIoFileReadAsync;
     2692    GlobTest.VDIfIo.pfnWriteAsync          = tstVDIoFileWriteAsync;
     2693    GlobTest.VDIfIo.pfnFlushAsync          = tstVDIoFileFlushAsync;
     2694
     2695    rc = VDInterfaceAdd(&GlobTest.VDIfIo.Core, "tstVDIo_VDIIo", VDINTERFACETYPE_IO,
     2696                        &GlobTest, sizeof(VDINTERFACEIO), &GlobTest.pInterfacesImages);
     2697    AssertRC(rc);
     2698
     2699    /* Init I/O backend. */
     2700    rc = VDIoBackendCreate(&GlobTest.pIoBackend);
     2701    if (RT_SUCCESS(rc))
     2702    {
     2703        VDSCRIPTCTX hScriptCtx = NULL;
     2704        rc = VDScriptCtxCreate(&hScriptCtx);
     2705        if (RT_SUCCESS(rc))
     2706        {
     2707            rc = VDScriptCtxCallbacksRegister(hScriptCtx, g_aScriptActions, g_cScriptActions, &GlobTest);
     2708            AssertRC(rc);
     2709
     2710            rc = VDScriptCtxLoadScript(hScriptCtx, pszScript);
     2711            if (RT_FAILURE(rc))
     2712            {
     2713                RTPrintf("Loading the script failed rc=%Rrc\n", rc);
     2714            }
     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");
     2723
     2724    RTStrFree(GlobTest.pszIoBackend);
     2725}
     2726
     2727/**
    26502728 * Executes the given I/O script using the new scripting engine.
    26512729 *
     
    26572735{
    26582736    int rc = VINF_SUCCESS;
    2659     VDTESTGLOB GlobTest;   /**< Global test data. */
    26602737    void *pvFile = NULL;
    26612738    size_t cbFile = 0;
    26622739
    2663     memset(&GlobTest, 0, sizeof(VDTESTGLOB));
    2664     RTListInit(&GlobTest.ListFiles);
    2665     RTListInit(&GlobTest.ListDisks);
    2666     RTListInit(&GlobTest.ListPatterns);
    2667     GlobTest.pszIoBackend = RTStrDup("memory");
    2668     if (!GlobTest.pszIoBackend)
    2669     {
    2670         RTPrintf("Out of memory allocating I/O backend string\n");
    2671         return;
    2672     }
    2673 
    26742740    rc = RTFileReadAll(pcszFilename, &pvFile, &cbFile);
    26752741    if (RT_SUCCESS(rc))
     
    26792745
    26802746        AssertPtr(pszScript);
    2681         /* Init global test data. */
    2682         GlobTest.VDIfError.pfnError     = tstVDError;
    2683         GlobTest.VDIfError.pfnMessage   = tstVDMessage;
    2684 
    2685         rc = VDInterfaceAdd(&GlobTest.VDIfError.Core, "tstVDIo_VDIError", VDINTERFACETYPE_ERROR,
    2686                             NULL, sizeof(VDINTERFACEERROR), &GlobTest.pInterfacesDisk);
    2687         AssertRC(rc);
    2688 
    2689         GlobTest.VDIfIo.pfnOpen                = tstVDIoFileOpen;
    2690         GlobTest.VDIfIo.pfnClose               = tstVDIoFileClose;
    2691         GlobTest.VDIfIo.pfnDelete              = tstVDIoFileDelete;
    2692         GlobTest.VDIfIo.pfnMove                = tstVDIoFileMove;
    2693         GlobTest.VDIfIo.pfnGetFreeSpace        = tstVDIoFileGetFreeSpace;
    2694         GlobTest.VDIfIo.pfnGetModificationTime = tstVDIoFileGetModificationTime;
    2695         GlobTest.VDIfIo.pfnGetSize             = tstVDIoFileGetSize;
    2696         GlobTest.VDIfIo.pfnSetSize             = tstVDIoFileSetSize;
    2697         GlobTest.VDIfIo.pfnWriteSync           = tstVDIoFileWriteSync;
    2698         GlobTest.VDIfIo.pfnReadSync            = tstVDIoFileReadSync;
    2699         GlobTest.VDIfIo.pfnFlushSync           = tstVDIoFileFlushSync;
    2700         GlobTest.VDIfIo.pfnReadAsync           = tstVDIoFileReadAsync;
    2701         GlobTest.VDIfIo.pfnWriteAsync          = tstVDIoFileWriteAsync;
    2702         GlobTest.VDIfIo.pfnFlushAsync          = tstVDIoFileFlushAsync;
    2703 
    2704         rc = VDInterfaceAdd(&GlobTest.VDIfIo.Core, "tstVDIo_VDIIo", VDINTERFACETYPE_IO,
    2705                             &GlobTest, sizeof(VDINTERFACEIO), &GlobTest.pInterfacesImages);
    2706         AssertRC(rc);
    2707 
    2708         /* Init I/O backend. */
    2709         rc = VDIoBackendCreate(&GlobTest.pIoBackend);
    2710         if (RT_SUCCESS(rc))
    2711         {
    2712             VDSCRIPTCTX hScriptCtx = NULL;
    2713             rc = VDScriptCtxCreate(&hScriptCtx);
    2714             if (RT_SUCCESS(rc))
    2715             {
    2716                 rc = VDScriptCtxCallbacksRegister(hScriptCtx, g_aScriptActions, g_cScriptActions, &GlobTest);
    2717                 AssertRC(rc);
    2718 
    2719                 rc = VDScriptCtxLoadScript(hScriptCtx, pszScript);
    2720                 if (RT_FAILURE(rc))
    2721                 {
    2722                     RTPrintf("Loading the script failed rc=%Rrc\n", rc);
    2723                 }
    2724                 else
    2725                     rc = VDScriptCtxCallFn(hScriptCtx, "main", NULL, 0);
    2726                 VDScriptCtxDestroy(hScriptCtx);
    2727             }
    2728             VDIoBackendDestroy(GlobTest.pIoBackend);
    2729         }
    2730         else
    2731             RTPrintf("Creating the I/O backend failed rc=%Rrc\n");
    2732     }
    2733     else
    2734         RTPrintf("Opening script failed rc=%Rrc\n", rc);
    2735 
    2736     RTStrFree(GlobTest.pszIoBackend);
     2747        tstVDIoScriptExec(pszScript);
     2748    }
     2749    else
     2750        RTPrintf("Opening the script failed: %Rrc\n", rc);
     2751
     2752}
     2753
     2754/**
     2755 * Run builtin tests.
     2756 *
     2757 * @returns nothing.
     2758 */
     2759static void tstVDIoRunBuiltinTests(void)
     2760{
     2761    for (unsigned i = 0; i < g_cVDIoTests; i++)
     2762    {
     2763        char *pszScript = RTStrDupN((const char *)g_aVDIoTests[i].pch, g_aVDIoTests[i].cb);
     2764
     2765        AssertPtr(pszScript);
     2766        tstVDIoScriptExec(pszScript);
     2767    }
    27372768}
    27382769
     
    27482779static const RTGETOPTDEF g_aOptions[] =
    27492780{
    2750     { "--script",   's', RTGETOPT_REQ_STRING }
     2781    { "--script",   's', RTGETOPT_REQ_STRING },
     2782    { "--help",     'h', RTGETOPT_REQ_NOTHING }
    27512783};
    27522784
     
    27592791    char c;
    27602792
    2761     if (argc != 3)
    2762     {
    2763         printUsage();
    2764         return RTEXITCODE_FAILURE;
    2765     }
    2766 
    27672793    rc = VDInit();
    27682794    if (RT_FAILURE(rc))
    27692795        return RTEXITCODE_FAILURE;
    27702796
     2797    if (argc == 1)
     2798    {
     2799        tstVDIoRunBuiltinTests();
     2800        return RTEXITCODE_SUCCESS;
     2801    }
     2802
    27712803    RTGetOptInit(&GetState, argc, argv, g_aOptions,
    27722804                 RT_ELEMENTS(g_aOptions), 1, RTGETOPTINIT_FLAGS_NO_STD_OPTS);
     
    27802812                tstVDIoScriptRun(ValueUnion.psz);
    27812813                break;
    2782             default:
     2814            case 'h':
    27832815                printUsage();
     2816                break;
     2817            default: /* Default is to run built in tests if no arguments are given (automated testing). */
     2818                tstVDIoRunBuiltinTests();
    27842819        }
    27852820    }
  • trunk/src/VBox/Storage/testcase/tstVDIo.vd

    r44943 r52111  
    3737}
    3838
     39void tstIoUnaligned(string strMessage, string strBackend)
     40{
     41    print(strMessage);
     42    createdisk("test", true);
     43    create("test", "base", "tst.disk", "dynamic", strBackend, 2G, false);
     44    io("test", false, 1, "seq", 512, 3584, 4096, 512, 100, "none");
     45    io("test", false, 1, "seq", 512, 3584, 4096, 512,   0, "none");
     46    destroydisk("test");
     47}
     48
    3949void main()
    4050{
Note: See TracChangeset for help on using the changeset viewer.

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