VirtualBox

Changeset 89135 in vbox for trunk/src/VBox


Ignore:
Timestamp:
May 18, 2021 10:38:17 AM (4 years ago)
Author:
vboxsync
Message:

Audio/ValKit: More code for testing infrastructure. bugref:10008

Location:
trunk/src/VBox
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Devices/Audio/AudioTest.cpp

    r89125 r89135  
    315315}
    316316
     317DECLINLINE(int) audioTestManifestWriteData(PAUDIOTESTSET pSet, const void *pvData, size_t cbData)
     318{
     319    /** @todo Use RTIniFileWrite once its implemented. */
     320    return RTFileWrite(pSet->f.hFile, pvData, cbData, NULL);
     321}
     322
    317323/**
    318324 * Writes string data to a test set manifest.
     
    326332{
    327333    char *psz = NULL;
    328     RTStrAPrintfV(&psz, pszFormat, args);
    329     AssertPtr(psz);
    330 
    331     /** @todo Use RTIniFileWrite once its implemented. */
    332     int rc = RTFileWrite(pSet->f.hFile, psz, strlen(psz), NULL);
     334    if (RTStrAPrintfV(&psz, pszFormat, args) == -1)
     335        return VERR_NO_MEMORY;
     336    AssertPtrReturn(psz, VERR_NO_MEMORY);
     337
     338    int rc = audioTestManifestWriteData(pSet, psz, strlen(psz));
    333339    AssertRC(rc);
    334340
     
    339345
    340346/**
    341  * Writes a terminated string line to a test set manifest.
     347 * Writes a string to a test set manifest.
    342348 * Convenience function.
    343349 *
     
    347353 * @param   ...                 Variable arguments for \a pszFormat. Optional.
    348354 */
    349 static int audioTestManifestWriteLn(PAUDIOTESTSET pSet, const char *pszFormat, ...)
     355static int audioTestManifestWrite(PAUDIOTESTSET pSet, const char *pszFormat, ...)
    350356{
    351357    va_list va;
     
    357363    va_end(va);
    358364
    359     /** @todo Keep it as simple as possible for now. Improve this later. */
    360     rc = RTFileWrite(pSet->f.hFile, "\n", strlen("\n"), NULL);
    361     AssertRC(rc);
    362 
    363     return rc;
    364 }
    365 
    366 /**
    367  * Writes a section entry to a test set manifest.
     365    return rc;
     366}
     367
     368/**
     369 * Returns the current read/write offset (in bytes) of the opened manifest file.
     370 *
     371 * @returns Current read/write offset (in bytes).
     372 * @param   pSet                Set to return offset for.
     373 *                              Must have an opened manifest file.
     374 */
     375DECLINLINE(uint64_t) audioTestManifestGetOffsetAbs(PAUDIOTESTSET pSet)
     376{
     377    AssertReturn(RTFileIsValid(pSet->f.hFile), 0);
     378    return RTFileTell(pSet->f.hFile);
     379}
     380
     381/**
     382 * Writes a section header to a test set manifest.
    368383 *
    369384 * @returns VBox status code.
     
    372387 * @param   ...                 Variable arguments for \a pszSection. Optional.
    373388 */
    374 static int audioTestManifestWriteSection(PAUDIOTESTSET pSet, const char *pszSection, ...)
     389static int audioTestManifestWriteSectionHdr(PAUDIOTESTSET pSet, const char *pszSection, ...)
    375390{
    376391    va_list va;
     
    378393
    379394    /** @todo Keep it as simple as possible for now. Improve this later. */
    380     int rc = RTFileWrite(pSet->f.hFile, "[", strlen("["), NULL);
     395    int rc = audioTestManifestWrite(pSet, "[");
    381396    AssertRC(rc);
    382397
     
    384399    AssertRC(rc);
    385400
    386     rc = RTFileWrite(pSet->f.hFile, "]\n", strlen("]\n"), NULL);
     401    rc = audioTestManifestWrite(pSet, "]\n");
    387402    AssertRC(rc);
    388403
     
    394409/**
    395410 * Initializes an audio test set, internal function.
     411 *
    396412 * @param   pSet                Test set to initialize.
    397413 */
     
    401417
    402418    RTListInit(&pSet->lstObj);
     419    pSet->cObj = 0;
     420
     421    RTListInit(&pSet->lstTest);
     422    pSet->cTests        = 0;
     423    pSet->cTestsRunning = 0;
     424    pSet->offTestCount  = 0;
     425
     426    pSet->cTotalFailures = 0;
    403427}
    404428
     
    612636        AssertRCReturn(rc, rc);
    613637
    614         rc = audioTestManifestWriteSection(pSet, "header");
    615         AssertRCReturn(rc, rc);
    616 
    617         rc = audioTestManifestWriteLn(pSet, "magic=vkat_ini"); /* VKAT Manifest, .INI-style. */
    618         AssertRCReturn(rc, rc);
    619         rc = audioTestManifestWriteLn(pSet, "ver=%d", AUDIOTEST_MANIFEST_VER);
    620         AssertRCReturn(rc, rc);
    621         rc = audioTestManifestWriteLn(pSet, "tag=%s", pSet->szTag);
     638        rc = audioTestManifestWriteSectionHdr(pSet, "header");
     639        AssertRCReturn(rc, rc);
     640
     641        rc = audioTestManifestWrite(pSet, "magic=vkat_ini\n"); /* VKAT Manifest, .INI-style. */
     642        AssertRCReturn(rc, rc);
     643        rc = audioTestManifestWrite(pSet, "ver=%d\n", AUDIOTEST_MANIFEST_VER);
     644        AssertRCReturn(rc, rc);
     645        rc = audioTestManifestWrite(pSet, "tag=%s\n", pSet->szTag);
    622646        AssertRCReturn(rc, rc);
    623647
     
    627651            AssertFailedReturn(VERR_BUFFER_OVERFLOW);
    628652
    629         rc = audioTestManifestWriteLn(pSet, "date_created=%s", szVal);
     653        rc = audioTestManifestWrite(pSet, "date_created=%s\n", szVal);
    630654        AssertRCReturn(rc, rc);
    631655
    632656        rc = RTSystemQueryOSInfo(RTSYSOSINFO_PRODUCT, szVal, sizeof(szVal));
    633657        AssertRCReturn(rc, rc);
    634         rc = audioTestManifestWriteLn(pSet, "os_product=%s", szVal);
     658        rc = audioTestManifestWrite(pSet, "os_product=%s\n", szVal);
    635659        AssertRCReturn(rc, rc);
    636660        rc = RTSystemQueryOSInfo(RTSYSOSINFO_RELEASE, szVal, sizeof(szVal));
    637661        AssertRCReturn(rc, rc);
    638         rc = audioTestManifestWriteLn(pSet, "os_rel=%s", szVal);
     662        rc = audioTestManifestWrite(pSet, "os_rel=%s\n", szVal);
    639663        AssertRCReturn(rc, rc);
    640664        rc = RTSystemQueryOSInfo(RTSYSOSINFO_VERSION, szVal, sizeof(szVal));
    641665        AssertRCReturn(rc, rc);
    642         rc = audioTestManifestWriteLn(pSet, "os_ver=%s", szVal);
    643         AssertRCReturn(rc, rc);
    644 
    645         rc = audioTestManifestWriteLn(pSet, "vbox_ver=%s r%u %s (%s %s)",
     666        rc = audioTestManifestWrite(pSet, "os_ver=%s\n", szVal);
     667        AssertRCReturn(rc, rc);
     668        rc = audioTestManifestWrite(pSet, "vbox_ver=%s r%u %s (%s %s)\n",
    646669                                      VBOX_VERSION_STRING, RTBldCfgRevision(),
    647670                                      RTBldCfgTargetDotArch(), __DATE__, __TIME__);
    648671        AssertRCReturn(rc, rc);
    649672
     673        rc = audioTestManifestWrite(pSet, "test_count=");
     674        AssertRCReturn(rc, rc);
     675        pSet->offTestCount = audioTestManifestGetOffsetAbs(pSet);
     676        rc = audioTestManifestWrite(pSet, "0000\n"); /* A bit messy, but does the trick for now. */
     677        AssertRCReturn(rc, rc);
     678
    650679        pSet->enmMode = AUDIOTESTSETMODE_TEST;
    651680    }
     
    665694        return VINF_SUCCESS;
    666695
    667     int rc = VINF_SUCCESS;
     696    AssertReturn(pSet->cTestsRunning == 0, VERR_WRONG_ORDER); /* Make sure no tests sill are running. */
     697
     698    int rc = AudioTestSetClose(pSet);
     699    if (RT_FAILURE(rc))
     700        return rc;
    668701
    669702    PAUDIOTESTOBJ pObj, pObjNext;
     
    688721    Assert(pSet->cObj == 0);
    689722
    690     if (RTFileIsValid(pSet->f.hFile))
    691     {
    692         RTFileClose(pSet->f.hFile);
    693         pSet->f.hFile = NIL_RTFILE;
    694     }
     723    PAUDIOTESTENTRY pEntry, pEntryNext;
     724    RTListForEachSafe(&pSet->lstTest, pEntry, pEntryNext, AUDIOTESTENTRY, Node)
     725    {
     726        RTListNodeRemove(&pEntry->Node);
     727        RTMemFree(pEntry);
     728
     729        Assert(pSet->cTests);
     730        pSet->cTests--;
     731    }
     732
     733    if (RT_FAILURE(rc))
     734        return rc;
     735
     736    Assert(pSet->cTests == 0);
    695737
    696738    return rc;
     
    729771 * Closes an opened audio test set.
    730772 *
     773 * @returns VBox status code.
    731774 * @param   pSet                Test set to close.
    732775 */
    733 void AudioTestSetClose(PAUDIOTESTSET pSet)
    734 {
    735     AudioTestSetDestroy(pSet);
     776int AudioTestSetClose(PAUDIOTESTSET pSet)
     777{
     778    if (!pSet)
     779        return VINF_SUCCESS;
     780
     781    /* Update number of ran tests. */
     782    int rc = RTFileSeek(pSet->f.hFile, pSet->offTestCount, RTFILE_SEEK_BEGIN, NULL);
     783    AssertRCReturn(rc, rc);
     784    rc = audioTestManifestWrite(pSet, "%04RU32", pSet->cTests);
     785    AssertRCReturn(rc, rc);
     786
     787    if (RTFileIsValid(pSet->f.hFile))
     788    {
     789        RTFileClose(pSet->f.hFile);
     790        pSet->f.hFile = NIL_RTFILE;
     791    }
     792
     793    return rc;
    736794}
    737795
     
    860918
    861919    return rc;
     920}
     921
     922int AudioTestSetTestBegin(PAUDIOTESTSET pSet, const char *pszDesc, PAUDIOTESTPARMS pParms, PAUDIOTESTENTRY *ppEntry)
     923{
     924    AssertReturn(pSet->cTestsRunning == 0, VERR_WRONG_ORDER); /* No test nesting allowed. */
     925
     926    PAUDIOTESTENTRY pEntry = (PAUDIOTESTENTRY)RTMemAllocZ(sizeof(AUDIOTESTENTRY));
     927    AssertPtrReturn(pEntry, VERR_NO_MEMORY);
     928
     929    int rc = RTStrCopy(pEntry->szDesc, sizeof(pEntry->szDesc), pszDesc);
     930    AssertRCReturn(rc, rc);
     931
     932    memcpy(&pEntry->Parms, pParms, sizeof(AUDIOTESTPARMS));
     933    pEntry->pParent = pSet;
     934
     935    rc = audioTestManifestWrite(pSet, "\n");
     936    AssertRCReturn(rc, rc);
     937
     938    rc = audioTestManifestWriteSectionHdr(pSet, "test%04RU32", pSet->cTests);
     939    AssertRCReturn(rc, rc);
     940
     941    rc = audioTestManifestWrite(pSet, "desc=%s\n", pszDesc);
     942    AssertRCReturn(rc, rc);
     943
     944    RTListAppend(&pSet->lstTest, &pEntry->Node);
     945    pSet->cTests++;
     946    pSet->cTestsRunning++;
     947
     948    *ppEntry = pEntry;
     949
     950    return rc;
     951}
     952
     953int AudioTestSetTestFailed(PAUDIOTESTENTRY pEntry, int rc, const char *pszErr)
     954{
     955    AssertReturn(pEntry->pParent->cTestsRunning == 1,            VERR_WRONG_ORDER); /* No test nesting allowed. */
     956    AssertReturn(pEntry->rc                     == VINF_SUCCESS, VERR_WRONG_ORDER);
     957
     958    pEntry->rc = rc;
     959
     960    int rc2 = audioTestManifestWrite(pEntry->pParent, "error_rc=%RI32\n", rc);
     961    AssertRCReturn(rc2, rc2);
     962    rc2 = audioTestManifestWrite(pEntry->pParent, "error_desc=%s", pszErr);
     963    AssertRCReturn(rc2, rc2);
     964
     965    pEntry->pParent->cTestsRunning--;
     966
     967    return rc2;
     968}
     969
     970int AudioTestSetTestDone(PAUDIOTESTENTRY pEntry)
     971{
     972    AssertReturn(pEntry->pParent->cTestsRunning == 1,            VERR_WRONG_ORDER); /* No test nesting allowed. */
     973    AssertReturn(pEntry->rc                     == VINF_SUCCESS, VERR_WRONG_ORDER);
     974
     975    int rc2 = audioTestManifestWrite(pEntry->pParent, "error_rc=%RI32\n", VINF_SUCCESS);
     976    AssertRCReturn(rc2, rc2);
     977
     978    pEntry->pParent->cTestsRunning--;
     979
     980    return rc2;
    862981}
    863982
  • trunk/src/VBox/Devices/Audio/AudioTest.h

    r89115 r89135  
    158158typedef AUDIOTESTPARMS *PAUDIOTESTPARMS;
    159159
     160/**
     161 * Enumeration for an audio test object type.
     162 */
    160163typedef enum AUDIOTESTOBJTYPE
    161164{
     165    /** Unknown / invalid, do not use. */
    162166    AUDIOTESTOBJTYPE_UNKNOWN = 0,
     167    /** The test object is a file. */
    163168    AUDIOTESTOBJTYPE_FILE,
    164169    /** The usual 32-bit hack. */
     
    166171} AUDIOTESTOBJTYPE;
    167172
     173/**
     174 * Structure for keeping an audio test object file.
     175 */
    168176typedef struct AUDIOTESTOBJFILE
    169177{
    170178    RTFILE hFile;
    171179} AUDIOTESTOBJFILE;
    172 
     180/** Pointer to an audio test object file. */
     181typedef AUDIOTESTOBJFILE *PAUDIOTESTOBJFILE;
     182
     183/**
     184 * Structure for keeping a single audio test object.
     185 *
     186 * A test object is data which is needed in order to perform and verify one or
     187 * more audio test case(s).
     188 */
    173189typedef struct AUDIOTESTOBJ
    174190{
     191    /** List node. */
    175192    RTLISTNODE           Node;
     193    /** Name of the test object.
     194     *  Must not contain a path and has to be able to serialize to disk. */
    176195    char                 szName[64];
     196    /** The object type. */
    177197    AUDIOTESTOBJTYPE     enmType;
     198    /** Union for holding the object type-specific data. */
    178199    union
    179200    {
     
    183204/** Pointer to an audio test object. */
    184205typedef AUDIOTESTOBJ *PAUDIOTESTOBJ;
     206
     207struct AUDIOTESTSET;
     208
     209typedef struct AUDIOTESTENTRY
     210{
     211    /** List node. */
     212    RTLISTNODE           Node;
     213    AUDIOTESTSET        *pParent;
     214    char                 szDesc[64];
     215    AUDIOTESTPARMS       Parms;
     216    int                  rc;
     217} AUDIOTESTENTRY;
     218/** Pointer to an audio test entry. */
     219typedef AUDIOTESTENTRY *PAUDIOTESTENTRY;
    185220
    186221/**
     
    200235        RTINIFILE    hIniFile;
    201236    } f;
     237    /** Number of test objects in lstObj. */
    202238    uint32_t         cObj;
     239    /** List containing PAUDIOTESTOBJ test object entries. */
    203240    RTLISTANCHOR     lstObj;
     241    /** Number of performed tests.
     242     *  Not necessarily bound to the test object entries above. */
     243    uint32_t         cTests;
     244    /** Absolute offset (in bytes) where to write the "test_count" value later. */
     245    uint64_t         offTestCount;
     246    /** List containing PAUDIOTESTENTRY test entries. */
     247    RTLISTANCHOR     lstTest;
     248    /** Number of tests currently running. */
     249    uint32_t         cTestsRunning;
     250    /** Number of total (test) failures. */
     251    uint32_t         cTotalFailures;
    204252} AUDIOTESTSET;
    205253/** Pointer to an audio test set. */
     
    267315int    AudioTestSetObjClose(PAUDIOTESTOBJ pObj);
    268316
     317int    AudioTestSetTestBegin(PAUDIOTESTSET pSet, const char *pszDesc, PAUDIOTESTPARMS pParms, PAUDIOTESTENTRY *ppEntry);
     318int    AudioTestSetTestFailed(PAUDIOTESTENTRY pEntry, int rc, const char *pszErr);
     319int    AudioTestSetTestDone(PAUDIOTESTENTRY pEntry);
     320
    269321int    AudioTestSetCreate(PAUDIOTESTSET pSet, const char *pszPath, const char *pszTag);
    270322int    AudioTestSetDestroy(PAUDIOTESTSET pSet);
    271323int    AudioTestSetOpen(PAUDIOTESTSET pSet, const char *pszPath);
    272 void   AudioTestSetClose(PAUDIOTESTSET pSet);
     324int    AudioTestSetClose(PAUDIOTESTSET pSet);
    273325int    AudioTestSetWipe(PAUDIOTESTSET pSet);
    274326int    AudioTestSetPack(PAUDIOTESTSET pSet, const char *pszOutDir, char *pszFileName, size_t cbFileName);
  • trunk/src/VBox/ValidationKit/utils/audio/vkat.cpp

    r89127 r89135  
    12151215
    12161216/*********************************************************************************************************************************
    1217 *   Implementation of Something                                                                                                  *
     1217*   Implementation of audio test environment handling                                                                            *
    12181218*********************************************************************************************************************************/
    12191219
     
    13111311
    13121312/*********************************************************************************************************************************
    1313 *   Some other stuff, you name it.                                                                                               *
     1313*   Device enumeration + handling.                                                                                               *
    13141314*********************************************************************************************************************************/
    13151315
     
    16131613    for (uint32_t i = 0; i < pTstParms->cIterations; i++)
    16141614    {
    1615         AudioTestToneParamsInitRandom(&pTstParms->TestTone, &pTstParms->TestTone.Props);
    1616         rc = audioTestCreateStreamDefaultOut(pTstEnv, pStream, &pTstParms->TestTone.Props);
     1615        PAUDIOTESTENTRY pTst;
     1616        rc = AudioTestSetTestBegin(&pTstEnv->Set, "Playing test tone", pTstParms, &pTst);
    16171617        if (RT_SUCCESS(rc))
    1618             rc = audioTestPlayTone(pTstEnv, pStream, &pTstParms->TestTone);
    1619 
    1620         int rc2 = audioTestStreamDestroy(pTstEnv, pStream);
    1621         if (RT_SUCCESS(rc))
    1622             rc = rc2;
     1618        {
     1619            AudioTestToneParamsInitRandom(&pTstParms->TestTone, &pTstParms->TestTone.Props);
     1620            rc = audioTestCreateStreamDefaultOut(pTstEnv, pStream, &pTstParms->TestTone.Props);
     1621            if (RT_SUCCESS(rc))
     1622            {
     1623                rc = audioTestPlayTone(pTstEnv, pStream, &pTstParms->TestTone);
     1624            }
     1625
     1626            int rc2 = audioTestStreamDestroy(pTstEnv, pStream);
     1627            if (RT_SUCCESS(rc))
     1628                rc = rc2;
     1629
     1630            if (RT_SUCCESS(rc))
     1631            {
     1632               AudioTestSetTestDone(pTst);
     1633            }
     1634            else
     1635                AudioTestSetTestFailed(pTst, rc, "Playing test tone failed");
     1636        }
     1637
     1638        if (RT_FAILURE(rc))
     1639            RTTestFailed(g_hTest, "Playing tone failed\n");
    16231640    }
    16241641
     
    18891906            RTTestPrintf(g_hTest, RTTESTLVL_ALWAYS, "Test set packed up to '%s'\n", szFileOut);
    18901907
     1908#ifndef DEBUG_andy
    18911909        /* Clean up. */
    18921910        int rc2 = AudioTestSetWipe(&TstEnv.Set);
    18931911        AssertRC(rc2); /* Annoying, but not test-critical. */
    1894 
     1912#endif
    18951913        audioTestEnvDestroy(&TstEnv);
    18961914    }
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