VirtualBox

Changeset 89711 in vbox


Ignore:
Timestamp:
Jun 15, 2021 3:08:23 PM (3 years ago)
Author:
vboxsync
Message:

Audio/ValKit: More validation code. bugref:10008

Location:
trunk/src/VBox
Files:
3 edited

Legend:

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

    r89541 r89711  
    6767*   Structures and Typedefs                                                                                                      *
    6868*********************************************************************************************************************************/
     69/**
     70 * Structure for keeping an audio test verification job.
     71 */
     72typedef struct AUDIOTESTVERIFYJOB
     73{
     74    /** Pointer to set A. */
     75    PAUDIOTESTSET       pSetA;
     76    /** Pointer to set B. */
     77    PAUDIOTESTSET       pSetB;
     78    /** Pointer to the error description to use. */
     79    PAUDIOTESTERRORDESC pErr;
     80    /** Zero-based index of current test being verified. */
     81    uint32_t            idxTest;
     82    /** Flag indicating whether to keep going after an error has occurred. */
     83    bool                fKeepGoing;
     84} AUDIOTESTVERIFYJOB;
     85/** Pointer to an audio test verification job. */
     86typedef AUDIOTESTVERIFYJOB *PAUDIOTESTVERIFYJOB;
    6987
    7088
     
    516534
    517535/**
     536 * Returns the the number of errors of an audio test error description.
     537 *
     538 * @returns Error count.
     539 * @param   pErr                Test error description to return error count for.
     540 */
     541uint32_t AudioTestErrorDescCount(PCAUDIOTESTERRORDESC pErr)
     542{
     543    return pErr->cErrors;
     544}
     545
     546/**
    518547 * Returns if an audio test error description contains any errors or not.
    519548 *
    520549 * @returns \c true if it contains errors, or \c false if not.
    521  *
    522550 * @param   pErr                Test error description to return error status for.
    523551 */
    524 bool AudioTestErrorDescFailed(PAUDIOTESTERRORDESC pErr)
     552bool AudioTestErrorDescFailed(PCAUDIOTESTERRORDESC pErr)
    525553{
    526554    if (pErr->cErrors)
     
    538566 * @returns VBox status code.
    539567 * @param   pErr                Test error description to add entry for.
     568 * @param   idxTest             Index of failing test (zero-based).
    540569 * @param   rc                  Result code of entry to add.
    541570 * @param   pszDesc             Error description format string to add.
    542571 * @param   args                Optional format arguments of \a pszDesc to add.
    543572 */
    544 static int audioTestErrorDescAddV(PAUDIOTESTERRORDESC pErr, int rc, const char *pszDesc, va_list args)
     573static int audioTestErrorDescAddV(PAUDIOTESTERRORDESC pErr, uint32_t idxTest, int rc, const char *pszDesc, va_list args)
    545574{
    546575    PAUDIOTESTERRORENTRY pEntry = (PAUDIOTESTERRORENTRY)RTMemAlloc(sizeof(AUDIOTESTERRORENTRY));
    547576    AssertPtrReturn(pEntry, VERR_NO_MEMORY);
    548577
    549     if (RTStrPrintf2V(pEntry->szDesc, sizeof(pEntry->szDesc), pszDesc, args) < 0)
    550         AssertFailedReturn(VERR_BUFFER_OVERFLOW);
     578    char *pszDescTmp;
     579    if (RTStrAPrintf(&pszDescTmp, pszDesc, args) < 0)
     580        AssertFailedReturn(VERR_NO_MEMORY);
     581
     582    const ssize_t cch = RTStrPrintf2(pEntry->szDesc, sizeof(pEntry->szDesc), "Test #%RU32 failed: %s", idxTest, pszDescTmp);
     583    RTStrFree(pszDescTmp);
     584    AssertReturn(cch > 0, VERR_BUFFER_OVERFLOW);
    551585
    552586    pEntry->rc = rc;
     
    564598 * @returns VBox status code.
    565599 * @param   pErr                Test error description to add entry for.
     600 * @param   idxTest             Index of failing test (zero-based).
    566601 * @param   pszDesc             Error description format string to add.
    567602 * @param   ...                 Optional format arguments of \a pszDesc to add.
    568603 */
    569 static int audioTestErrorDescAdd(PAUDIOTESTERRORDESC pErr, const char *pszDesc, ...)
     604static int audioTestErrorDescAdd(PAUDIOTESTERRORDESC pErr, uint32_t idxTest, const char *pszDesc, ...)
    570605{
    571606    va_list va;
    572607    va_start(va, pszDesc);
    573608
    574     int rc = audioTestErrorDescAddV(pErr, VERR_GENERAL_FAILURE /** @todo Fudge! */, pszDesc, va);
     609    int rc = audioTestErrorDescAddV(pErr, idxTest, VERR_GENERAL_FAILURE /** @todo Fudge! */, pszDesc, va);
    575610
    576611    va_end(va);
     
    13831418}
    13841419
    1385 static int audioTestVerifyIniValue(PAUDIOTESTSET pSetA, PAUDIOTESTSET pSetB,
    1386                                    const char *pszSec, const char *pszKey, const char *pszVal)
    1387 {
     1420/**
     1421 * Gets a value as string.
     1422 *
     1423 * @returns VBox status code.
     1424 * @param   pSet                Test set to get value from.
     1425 * @param   pszSec              Section to get value from.
     1426 * @param   pszKey              Key to get value from.
     1427 * @param   pszVal              Where to return the value on success.
     1428 * @param   cbVal               Size (in bytes) of \a pszVal.
     1429 */
     1430static int audioTestGetValueStr(PAUDIOTESTSET pSet,
     1431                                const char *pszSec, const char *pszKey, char *pszVal, size_t cbVal)
     1432{
     1433    return RTIniFileQueryValue(pSet->f.hIniFile, pszSec, pszKey, pszVal, cbVal, NULL);
     1434}
     1435
     1436/**
     1437 * Gets a value as uint32_t.
     1438 *
     1439 * @returns VBox status code.
     1440 * @param   pSet                Test set to get value from.
     1441 * @param   pszSec              Section to get value from.
     1442 * @param   pszKey              Key to get value from.
     1443 * @param   puVal               Where to return the value on success.
     1444 */
     1445static int audioTestGetValueUInt32(PAUDIOTESTSET pSet,
     1446                                   const char *pszSec, const char *pszKey, uint32_t *puVal)
     1447{
     1448    char szVal[_1K];
     1449    int rc = audioTestGetValueStr(pSet, pszSec, pszKey, szVal, sizeof(szVal));
     1450    if (RT_SUCCESS(rc))
     1451        *puVal = RTStrToUInt32(szVal);
     1452
     1453    return rc;
     1454}
     1455
     1456/**
     1457 * Verifies a value of a test verification job.
     1458 *
     1459 * @returns VBox status code.
     1460 * @returns Error if the verification failed and test verification job has fKeepGoing not set.
     1461 * @param   pVerify             Verification job to verify value for.
     1462 * @param   pszSec              Section of key / value to verify.
     1463 * @param   pszKey              Key to verify.
     1464 * @param   pszVal              Value to verify.
     1465 * @param   pszErrFmt           Error format string in case the verification failed.
     1466 * @param   ...                 Variable aruments for error format string.
     1467 */
     1468static int audioTestVerifyValue(PAUDIOTESTVERIFYJOB pVerify,
     1469                                const char *pszSec, const char *pszKey, const char *pszVal, const char *pszErrFmt, ...)
     1470{
     1471    va_list va;
     1472    va_start(va, pszErrFmt);
     1473
    13881474    char szValA[_1K];
    1389     int rc = RTIniFileQueryValue(pSetA->f.hIniFile, pszSec, pszKey, szValA, sizeof(szValA), NULL);
     1475    int rc = audioTestGetValueStr(pVerify->pSetA, pszSec, pszKey, szValA, sizeof(szValA));
     1476    if (RT_SUCCESS(rc))
     1477    {
     1478        char szValB[_1K];
     1479        rc = audioTestGetValueStr(pVerify->pSetB, pszSec, pszKey, szValB, sizeof(szValB));
     1480        if (RT_SUCCESS(rc))
     1481        {
     1482            if (RTStrCmp(szValA, szValB))
     1483                rc = VERR_WRONG_TYPE; /** @todo Fudge! */
     1484
     1485            if (pszVal)
     1486            {
     1487                if (RTStrCmp(szValA, pszVal))
     1488                    rc = VERR_WRONG_TYPE; /** @todo Fudge! */
     1489            }
     1490        }
     1491    }
     1492
    13901493    if (RT_FAILURE(rc))
    1391         return rc;
    1392     char szValB[_1K];
    1393     rc = RTIniFileQueryValue(pSetB->f.hIniFile, pszSec, pszKey, szValB, sizeof(szValB), NULL);
    1394     if (RT_FAILURE(rc))
    1395         return rc;
    1396 
    1397     if (RTStrCmp(szValA, szValB))
    1398         return VERR_WRONG_TYPE; /** @todo Fudge! */
    1399 
    1400     if (pszVal)
    1401     {
    1402         if (RTStrCmp(szValA, pszVal))
    1403             return VERR_WRONG_TYPE; /** @todo Fudge! */
    1404     }
    1405 
    1406     return rc;
     1494    {
     1495        int rc2 = audioTestErrorDescAddV(pVerify->pErr, pVerify->idxTest, rc, pszErrFmt, va);
     1496        AssertRC(rc2);
     1497    }
     1498
     1499    va_end(va);
     1500
     1501    return pVerify->fKeepGoing ? VINF_SUCCESS : rc;
     1502}
     1503
     1504/**
     1505 * Verifies a test tone test.
     1506 *
     1507 * @returns VBox status code.
     1508 * @returns Error if the verification failed and test verification job has fKeepGoing not set.
     1509 * @retval  VERR_
     1510 * @param   pVerify             Verification job to verify test tone for.
     1511 * @param   pszSec              Section of test tone to verify.
     1512 * @param   pSetPlay            Test set which did the playing part.
     1513 * @param   pSetRecord          Test set which did the recording part.
     1514 */
     1515static int audioTestVerifyTestTone(PAUDIOTESTVERIFYJOB pVerify, const char *pszSec, PAUDIOTESTSET pSetPlay, PAUDIOTESTSET pSetRecord)
     1516{
     1517    RT_NOREF(pSetPlay, pSetRecord);
     1518
     1519    int rc;
     1520
     1521    /*
     1522     * Verify test parameters.
     1523     * More important items have precedence.
     1524     */
     1525    rc = audioTestVerifyValue(pVerify, pszSec, "error_rc", "0", "Test was reported as failed");
     1526    AssertRCReturn(rc, rc);
     1527    rc = audioTestVerifyValue(pVerify, pszSec, "obj_count", NULL, "Object counts don't match");
     1528    AssertRCReturn(rc, rc);
     1529    rc = audioTestVerifyValue(pVerify, pszSec, "tone_freq_hz", NULL, "Tone frequency doesn't match");
     1530    AssertRCReturn(rc, rc);
     1531    rc = audioTestVerifyValue(pVerify, pszSec, "tone_prequel_ms", NULL, "Tone prequel (ms) doesn't match");
     1532    AssertRCReturn(rc, rc);
     1533    rc = audioTestVerifyValue(pVerify, pszSec, "tone_duration_ms", NULL, "Tone duration (ms) doesn't match");
     1534    AssertRCReturn(rc, rc);
     1535    rc = audioTestVerifyValue(pVerify, pszSec, "tone_sequel_ms", NULL, "Tone sequel (ms) doesn't match");
     1536    AssertRCReturn(rc, rc);
     1537    rc = audioTestVerifyValue(pVerify, pszSec, "tone_volume_percent", NULL, "Tone volume (percent) doesn't match");
     1538    AssertRCReturn(rc, rc);
     1539    rc = audioTestVerifyValue(pVerify, pszSec, "tone_pcm_hz", NULL, "Tone PCM Hz doesn't match");
     1540    AssertRCReturn(rc, rc);
     1541    rc = audioTestVerifyValue(pVerify, pszSec, "tone_pcm_channels", NULL, "Tone PCM channels don't match");
     1542    AssertRCReturn(rc, rc);
     1543    rc = audioTestVerifyValue(pVerify, pszSec, "tone_pcm_bits", NULL, "Tone PCM bits don't match");
     1544    AssertRCReturn(rc, rc);
     1545    rc = audioTestVerifyValue(pVerify, pszSec, "tone_pcm_is_signed", NULL, "Tone PCM signed bit doesn't match");
     1546    AssertRCReturn(rc, rc);
     1547
     1548    return VINF_SUCCESS;
    14071549}
    14081550
     
    14261568    audioTestErrorDescInit(pErrDesc);
    14271569
     1570    AUDIOTESTVERIFYJOB VerJob;
     1571    RT_ZERO(VerJob);
     1572    VerJob.pErr       = pErrDesc;
     1573    VerJob.pSetA      = pSetA;
     1574    VerJob.pSetB      = pSetB;
     1575    VerJob.fKeepGoing = true;
     1576
    14281577    int rc;
    1429 
    1430 #define VERIFY_VALUE(a_Sec, a_Key, a_Val, ...) \
    1431     rc = audioTestVerifyIniValue(pSetA, pSetB, a_Sec, a_Key, a_Val); \
    1432     if (RT_FAILURE(rc)) \
    1433         return audioTestErrorDescAdd(pErrDesc, (__VA_ARGS__));
    14341578
    14351579    /*
    14361580     * Compare obvious values first.
    14371581     */
    1438     VERIFY_VALUE("header",   "magic",        "vkat_ini",    "Manifest magic wrong");
    1439     VERIFY_VALUE("header",   "ver",          "1"       ,    "Manifest version wrong");
    1440     VERIFY_VALUE("header",   "tag",          NULL,          "Manifest tags don't match");
    1441     VERIFY_VALUE("header",   "test_count",   NULL,          "Test counts don't match");
    1442     VERIFY_VALUE("header",   "obj_count",    NULL,          "Object counts don't match");
     1582    rc = audioTestVerifyValue(&VerJob, "header",   "magic",        "vkat_ini",    "Manifest magic wrong");
     1583    AssertRCReturn(rc, rc);
     1584    rc = audioTestVerifyValue(&VerJob, "header",   "ver",          "1"       ,    "Manifest version wrong");
     1585    AssertRCReturn(rc, rc);
     1586    rc = audioTestVerifyValue(&VerJob, "header",   "tag",          NULL,          "Manifest tags don't match");
     1587    AssertRCReturn(rc, rc);
     1588    rc = audioTestVerifyValue(&VerJob, "header",   "test_count",   NULL,          "Test counts don't match");
     1589    AssertRCReturn(rc, rc);
     1590    rc = audioTestVerifyValue(&VerJob, "header",   "obj_count",    NULL,          "Object counts don't match");
     1591    AssertRCReturn(rc, rc);
     1592
     1593    if (   pErrDesc->cErrors
     1594        && !VerJob.fKeepGoing)
     1595        return VINF_SUCCESS;
     1596
     1597    /*
     1598     * Compare ran tests.
     1599     */
     1600    uint32_t cTests;
     1601    rc = audioTestGetValueUInt32(VerJob.pSetA, "header", "test_count", &cTests);
     1602    AssertRCReturn(rc, rc);
     1603
     1604    for (uint32_t i = 0; i < cTests; i++)
     1605    {
     1606        VerJob.idxTest = i;
     1607
     1608        char szSec[64];
     1609        RTStrPrintf(szSec, sizeof(szSec), "test_%04RU32", i);
     1610
     1611        AUDIOTESTTYPE enmTestTypeA;
     1612        audioTestGetValueUInt32(VerJob.pSetA, szSec, "test_type", (uint32_t *)&enmTestTypeA);
     1613        AUDIOTESTTYPE enmTestTypeB;
     1614        audioTestGetValueUInt32(VerJob.pSetB, szSec, "test_type", (uint32_t *)&enmTestTypeB);
     1615
     1616        switch (enmTestTypeA)
     1617        {
     1618            case AUDIOTESTTYPE_TESTTONE_PLAY:
     1619            {
     1620                if (enmTestTypeB == AUDIOTESTTYPE_TESTTONE_RECORD)
     1621                {
     1622                    rc = audioTestVerifyTestTone(&VerJob, szSec, VerJob.pSetA, VerJob.pSetB);
     1623                }
     1624                else
     1625                    rc = audioTestErrorDescAdd(pErrDesc, i, "Playback test types don't match (set A=%#x, set B=%#x)",
     1626                                               enmTestTypeA, enmTestTypeB);
     1627                break;
     1628            }
     1629
     1630            case AUDIOTESTTYPE_TESTTONE_RECORD:
     1631            {
     1632                if (enmTestTypeB != AUDIOTESTTYPE_TESTTONE_PLAY)
     1633                {
     1634                    rc = audioTestVerifyTestTone(&VerJob, szSec, VerJob.pSetB, VerJob.pSetA);
     1635                }
     1636                else
     1637                    rc = audioTestErrorDescAdd(pErrDesc, i, "Recording test types don't match (set A=%#x, set B=%#x)",
     1638                                               enmTestTypeA, enmTestTypeB);
     1639                break;
     1640            }
     1641
     1642            case AUDIOTESTTYPE_INVALID:
     1643                rc = VERR_INVALID_PARAMETER;
     1644                break;
     1645
     1646            default:
     1647                rc = VERR_NOT_IMPLEMENTED;
     1648                break;
     1649        }
     1650
     1651        AssertRC(rc);
     1652    }
    14431653
    14441654#undef VERIFY_VALUE
  • trunk/src/VBox/Devices/Audio/AudioTest.h

    r89541 r89711  
    335335/** Pointer to an audio test error description. */
    336336typedef AUDIOTESTERRORDESC *PAUDIOTESTERRORDESC;
     337/** Const pointer to an audio test error description. */
     338typedef AUDIOTESTERRORDESC const *PCAUDIOTESTERRORDESC;
    337339
    338340double AudioTestToneInit(PAUDIOTESTTONE pTone, PPDMAUDIOPCMPROPS pProps, double dbFreq);
     
    368370int    AudioTestSetVerify(PAUDIOTESTSET pSetA, PAUDIOTESTSET pSetB, PAUDIOTESTERRORDESC pErrDesc);
    369371
    370 bool   AudioTestErrorDescFailed(PAUDIOTESTERRORDESC pErr);
     372uint32_t AudioTestErrorDescCount(PCAUDIOTESTERRORDESC pErr);
     373bool   AudioTestErrorDescFailed(PCAUDIOTESTERRORDESC pErr);
     374
    371375void   AudioTestErrorDescDestroy(PAUDIOTESTERRORDESC pErr);
    372376
  • trunk/src/VBox/ValidationKit/utils/audio/vkat.cpp

    r89686 r89711  
    489489    else if (pTstEnv->enmMode == AUDIOTESTMODE_HOST)
    490490    {
    491         /* Generate tags for the host and guest side. */
    492         char szTagHost [AUDIOTEST_TAG_MAX];
    493         char szTagGuest[AUDIOTEST_TAG_MAX];
    494 
    495         rc = RTStrPrintf2(szTagHost, sizeof(szTagHost),   "%s-host",  pTstEnv->szTag);
    496         AssertRCReturn(rc, rc);
    497         rc = RTStrPrintf2(szTagGuest, sizeof(szTagGuest), "%s-guest", pTstEnv->szTag);
    498         AssertRCReturn(rc, rc);
    499 
    500         RTTestPrintf(g_hTest, RTTESTLVL_DEBUG, "Guest test set tag is '%s'\n", szTagGuest);
    501         RTTestPrintf(g_hTest, RTTESTLVL_DEBUG, "Host test set tag is '%s'\n", szTagHost);
    502 
    503         rc = AudioTestSvcClientTestSetBegin(&pTstEnv->u.Host.AtsClValKit, szTagHost);
     491        RTTestPrintf(g_hTest, RTTESTLVL_DEBUG, "Using tag '%s'\n", pTstEnv->szTag);
     492
     493        rc = AudioTestSvcClientTestSetBegin(&pTstEnv->u.Host.AtsClValKit, pTstEnv->szTag);
    504494        if (RT_SUCCESS(rc))
    505             rc = AudioTestSvcClientTestSetBegin(&pTstEnv->u.Host.AtsClGuest, szTagGuest);
     495            rc = AudioTestSvcClientTestSetBegin(&pTstEnv->u.Host.AtsClGuest, pTstEnv->szTag);
    506496
    507497        if (RT_SUCCESS(rc))
     
    521511            }
    522512
    523             int rc2 = AudioTestSvcClientTestSetEnd(&pTstEnv->u.Host.AtsClGuest, szTagGuest);
     513            int rc2 = AudioTestSvcClientTestSetEnd(&pTstEnv->u.Host.AtsClGuest, pTstEnv->szTag);
    524514            if (RT_SUCCESS(rc))
    525515                rc = rc2;
    526516
    527             rc2 = AudioTestSvcClientTestSetEnd(&pTstEnv->u.Host.AtsClValKit, szTagHost);
     517            rc2 = AudioTestSvcClientTestSetEnd(&pTstEnv->u.Host.AtsClValKit, pTstEnv->szTag);
    528518            if (RT_SUCCESS(rc))
    529519                rc = rc2;
     
    535525                 */
    536526                char szFileName[RTPATH_MAX];
    537                 if (RTStrPrintf2(szFileName, sizeof(szFileName), "%s.tar.gz", szTagGuest))
     527                if (RTStrPrintf2(szFileName, sizeof(szFileName), "%s-guest.tar.gz", pTstEnv->szTag))
    538528                {
    539529                    rc = RTPathJoin(pTstEnv->u.Host.szPathTestSetGuest, sizeof(pTstEnv->u.Host.szPathTestSetGuest),
     
    541531                    if (RT_SUCCESS(rc))
    542532                    {
    543                         if (RTStrPrintf2(szFileName, sizeof(szFileName), "%s.tar.gz", szTagHost))
     533                        if (RTStrPrintf2(szFileName, sizeof(szFileName), "%s-host.tar.gz", pTstEnv->szTag))
    544534                        {
    545535                            rc = RTPathJoin(pTstEnv->u.Host.szPathTestSetValKit, sizeof(pTstEnv->u.Host.szPathTestSetValKit),
     
    557547                                     pTstEnv->u.Host.szPathTestSetGuest);
    558548                        rc = AudioTestSvcClientTestSetDownload(&pTstEnv->u.Host.AtsClGuest,
    559                                                                szTagGuest, pTstEnv->u.Host.szPathTestSetGuest);
     549                                                               pTstEnv->szTag, pTstEnv->u.Host.szPathTestSetGuest);
    560550                    }
    561551
     
    565555                                     pTstEnv->u.Host.szPathTestSetValKit);
    566556                        rc = AudioTestSvcClientTestSetDownload(&pTstEnv->u.Host.AtsClValKit,
    567                                                                szTagHost, pTstEnv->u.Host.szPathTestSetValKit);
     557                                                               pTstEnv->szTag, pTstEnv->u.Host.szPathTestSetValKit);
    568558                    }
    569559                }
     
    874864        if (RT_SUCCESS(rc))
    875865        {
     866            RTTestPrintf(g_hTest, RTTESTLVL_ALWAYS, "%RU32 errors occurred while verifying\n", AudioTestErrorDescCount(&errDesc));
    876867            if (AudioTestErrorDescFailed(&errDesc))
    877868            {
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