VirtualBox

Changeset 91088 in vbox


Ignore:
Timestamp:
Sep 2, 2021 11:53:54 AM (3 years ago)
Author:
vboxsync
Message:

Audio/Validation Kit: Implemented optional probing for backends (--probe-backends) when using the "enum" command. Needed for checking whether audio is available on the host (testboxes). ​bugref:10008

Location:
trunk/src/VBox/ValidationKit/utils/audio
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/ValidationKit/utils/audio/vkat.cpp

    r91087 r91088  
    7070*********************************************************************************************************************************/
    7171/**
    72  * Backends.
     72 * Backends description table.
    7373 *
    7474 * @note The first backend in the array is the default one for the platform.
    7575 */
    76 struct
    77 {
    78     /** The driver registration structure. */
    79     PCPDMDRVREG pDrvReg;
    80     /** The backend name.
    81      * Aliases are implemented by having multiple entries for the same backend.  */
    82     const char *pszName;
    83 } const g_aBackends[] =
     76AUDIOTESTBACKENDDESC const g_aBackends[] =
    8477{
    8578#ifdef VBOX_WITH_AUDIO_PULSE
     
    116109};
    117110AssertCompile(sizeof(g_aBackends) > 0 /* port me */);
     111/** Number of backends defined. */
     112unsigned g_cBackends = RT_ELEMENTS(g_aBackends);
    118113
    119114/**
     
    206201static const RTGETOPTDEF g_aCmdVerifyOptions[] =
    207202{
    208     { "--tag",              VKAT_VERIFY_OPT_TAG,          RTGETOPT_REQ_STRING  }
     203    { "--tag",              VKAT_VERIFY_OPT_TAG,                RTGETOPT_REQ_STRING  }
    209204};
    210205
     
    926921
    927922    AUDIOTESTDRVSTACK DrvStack;
    928     for (size_t i = 0; i < RT_ELEMENTS(g_aBackends); i++)
    929     {
    930         if (fProbeBackends)
    931         {
    932             pDrvReg = g_aBackends[i].pDrvReg;
    933             RTTestPrintf(g_hTest, RTTESTLVL_ALWAYS, "Probing for backend '%s' ...\n", g_aBackends[i].pszName);
    934         }
     923    if (fProbeBackends)
     924        rc = audioTestDriverStackProbe(&DrvStack, pDrvReg,
     925                                       true /* fEnabledIn */, true /* fEnabledOut */, fWithDrvAudio); /** @todo Make in/out configurable, too. */
     926    else
    935927        rc = audioTestDriverStackInitEx(&DrvStack, pDrvReg,
    936928                                        true /* fEnabledIn */, true /* fEnabledOut */, fWithDrvAudio); /** @todo Make in/out configurable, too. */
    937         if (RT_SUCCESS(rc))
    938         {
    939             if (fProbeBackends)
    940                 RTTestPrintf(g_hTest, RTTESTLVL_ALWAYS, "Probing backend '%s' successful\n", g_aBackends[i].pszName);
    941             break;
    942         }
    943         if (fProbeBackends)
    944         {
    945             RTTestPrintf(g_hTest, RTTESTLVL_ALWAYS, "Probing backend '%s' failed with %Rrc, trying next one\n",
    946                          g_aBackends[i].pszName, rc);
    947             continue;
    948         }
     929    if (RT_FAILURE(rc))
    949930        return RTMsgErrorExit(RTEXITCODE_SYNTAX, "Unable to init driver stack: %Rrc\n", rc);
    950     }
    951 
    952     if (RT_FAILURE(rc))
    953         return RTMsgErrorExit(RTEXITCODE_SYNTAX, "Probing all backends failed, unable to continue\n");
    954931
    955932    PPDMAUDIOHOSTDEV pDev;
  • trunk/src/VBox/ValidationKit/utils/audio/vkatCmdGeneric.cpp

    r90736 r91088  
    4141*********************************************************************************************************************************/
    4242
     43
     44
     45/**
     46 * Long option values for the 'enum' command.
     47 */
     48enum
     49{
     50    VKAT_ENUM_OPT_PROBE_BACKENDS = 900
     51};
     52
    4353/**
    4454 * Options for 'enum'.
     
    4656static const RTGETOPTDEF g_aCmdEnumOptions[] =
    4757{
    48     { "--backend",          'b',                          RTGETOPT_REQ_STRING  },
     58    { "--backend",          'b',                                RTGETOPT_REQ_STRING  },
     59    { "--probe-backends",    VKAT_ENUM_OPT_PROBE_BACKENDS,      RTGETOPT_REQ_NOTHING }
    4960};
    5061
     
    5566    switch (pOpt->iShort)
    5667    {
    57         case 'b': return "The audio backend to use.";
     68        case 'b':                               return "The audio backend to use.";
     69        case VKAT_ENUM_OPT_PROBE_BACKENDS:      return "Specifies whether to probe all (available) backends until a working one is found\n"
     70                                                       "    Default: false";
    5871        default:  return NULL;
    5972    }
    6073}
    61 
    6274
    6375/**
     
    7385     */
    7486    /* Option values: */
    75     PCPDMDRVREG pDrvReg = AudioTestGetDefaultBackend();
     87    PCPDMDRVREG pDrvReg        = AudioTestGetDefaultBackend();
     88    bool        fProbeBackends = false;
    7689
    7790    /* Argument processing loop: */
     
    88101                break;
    89102
     103            case VKAT_ENUM_OPT_PROBE_BACKENDS:
     104                fProbeBackends = ValueUnion.f;
     105                break;
     106
    90107            AUDIO_TEST_COMMON_OPTION_CASES(ValueUnion);
    91108
     
    95112    }
    96113
     114    int rc;
     115
     116    AUDIOTESTDRVSTACK DrvStack;
     117    if (fProbeBackends)
     118        rc = audioTestDriverStackProbe(&DrvStack, pDrvReg,
     119                                       true /* fEnabledIn */, true /* fEnabledOut */, false /* fWithDrvAudio */);
     120    else
     121        rc = audioTestDriverStackInitEx(&DrvStack, pDrvReg,
     122                                        true /* fEnabledIn */, true /* fEnabledOut */, false /* fWithDrvAudio */);
     123    if (RT_FAILURE(rc))
     124        return RTMsgErrorExit(RTEXITCODE_SYNTAX, "Unable to init driver stack: %Rrc\n", rc);
     125
    97126    /*
    98127     * Do the enumeration.
    99128     */
    100     RTEXITCODE          rcExit = RTEXITCODE_FAILURE;
    101     AUDIOTESTDRVSTACK   DrvStack;
    102     int rc = audioTestDriverStackInit(&DrvStack, pDrvReg, false /*fWithDrvAudio*/);
    103     if (RT_SUCCESS(rc))
    104     {
    105         if (DrvStack.pIHostAudio->pfnGetDevices)
     129    RTEXITCODE rcExit = RTEXITCODE_FAILURE;
     130
     131    if (DrvStack.pIHostAudio->pfnGetDevices)
     132    {
     133        PDMAUDIOHOSTENUM Enum;
     134        rc = DrvStack.pIHostAudio->pfnGetDevices(DrvStack.pIHostAudio, &Enum);
     135        if (RT_SUCCESS(rc))
    106136        {
    107             PDMAUDIOHOSTENUM Enum;
    108             rc = DrvStack.pIHostAudio->pfnGetDevices(DrvStack.pIHostAudio, &Enum);
    109             if (RT_SUCCESS(rc))
     137            RTPrintf("Found %u device%s\n", Enum.cDevices, Enum.cDevices != 1 ? "s" : "");
     138
     139            PPDMAUDIOHOSTDEV pHostDev;
     140            RTListForEach(&Enum.LstDevices, pHostDev, PDMAUDIOHOSTDEV, ListEntry)
    110141            {
    111                 RTPrintf("Found %u device%s\n", Enum.cDevices, Enum.cDevices != 1 ? "s" : "");
    112 
    113                 PPDMAUDIOHOSTDEV pHostDev;
    114                 RTListForEach(&Enum.LstDevices, pHostDev, PDMAUDIOHOSTDEV, ListEntry)
    115                 {
    116                     RTPrintf("\nDevice \"%s\":\n", pHostDev->pszName);
    117 
    118                     char szFlags[PDMAUDIOHOSTDEV_MAX_FLAGS_STRING_LEN];
    119                     if (pHostDev->cMaxInputChannels && !pHostDev->cMaxOutputChannels && pHostDev->enmUsage == PDMAUDIODIR_IN)
    120                         RTPrintf("    Input:  max %u channels (%s)\n",
    121                                  pHostDev->cMaxInputChannels, PDMAudioHostDevFlagsToString(szFlags, pHostDev->fFlags));
    122                     else if (!pHostDev->cMaxInputChannels && pHostDev->cMaxOutputChannels && pHostDev->enmUsage == PDMAUDIODIR_OUT)
    123                         RTPrintf("    Output: max %u channels (%s)\n",
    124                                  pHostDev->cMaxOutputChannels, PDMAudioHostDevFlagsToString(szFlags, pHostDev->fFlags));
    125                     else
    126                         RTPrintf("    %s: max %u output channels, max %u input channels (%s)\n",
    127                                  PDMAudioDirGetName(pHostDev->enmUsage), pHostDev->cMaxOutputChannels,
    128                                  pHostDev->cMaxInputChannels, PDMAudioHostDevFlagsToString(szFlags, pHostDev->fFlags));
    129 
    130                     if (pHostDev->pszId && *pHostDev->pszId)
    131                         RTPrintf("    ID:     \"%s\"\n", pHostDev->pszId);
    132                 }
    133 
    134                 PDMAudioHostEnumDelete(&Enum);
     142                RTPrintf("\nDevice \"%s\":\n", pHostDev->pszName);
     143
     144                char szFlags[PDMAUDIOHOSTDEV_MAX_FLAGS_STRING_LEN];
     145                if (pHostDev->cMaxInputChannels && !pHostDev->cMaxOutputChannels && pHostDev->enmUsage == PDMAUDIODIR_IN)
     146                    RTPrintf("    Input:  max %u channels (%s)\n",
     147                             pHostDev->cMaxInputChannels, PDMAudioHostDevFlagsToString(szFlags, pHostDev->fFlags));
     148                else if (!pHostDev->cMaxInputChannels && pHostDev->cMaxOutputChannels && pHostDev->enmUsage == PDMAUDIODIR_OUT)
     149                    RTPrintf("    Output: max %u channels (%s)\n",
     150                             pHostDev->cMaxOutputChannels, PDMAudioHostDevFlagsToString(szFlags, pHostDev->fFlags));
     151                else
     152                    RTPrintf("    %s: max %u output channels, max %u input channels (%s)\n",
     153                             PDMAudioDirGetName(pHostDev->enmUsage), pHostDev->cMaxOutputChannels,
     154                             pHostDev->cMaxInputChannels, PDMAudioHostDevFlagsToString(szFlags, pHostDev->fFlags));
     155
     156                if (pHostDev->pszId && *pHostDev->pszId)
     157                    RTPrintf("    ID:     \"%s\"\n", pHostDev->pszId);
    135158            }
    136             else
    137                 rcExit = RTMsgErrorExitFailure("Enumeration failed: %Rrc\n", rc);
     159
     160            PDMAudioHostEnumDelete(&Enum);
    138161        }
    139162        else
    140             rcExit = RTMsgErrorExitFailure("Enumeration not supported by backend '%s'\n", pDrvReg->szName);
    141         audioTestDriverStackDelete(&DrvStack);
     163            rcExit = RTMsgErrorExitFailure("Enumeration failed: %Rrc\n", rc);
    142164    }
    143165    else
    144         rcExit = RTMsgErrorExitFailure("Driver stack construction failed: %Rrc", rc);
     166        rcExit = RTMsgErrorExitFailure("Enumeration not supported by backend '%s'\n", pDrvReg->szName);
     167    audioTestDriverStackDelete(&DrvStack);
     168
    145169    return RTEXITCODE_SUCCESS;
    146170}
  • trunk/src/VBox/ValidationKit/utils/audio/vkatDriverStack.cpp

    r90868 r91088  
    588588}
    589589
     590/**
     591 * Initializes a driver stack by probing all backends in the order of appearance
     592 * in the backends description table.
     593 *
     594 * @returns VBox status code.
     595 * @param   pDrvStack       The driver stack to initialize.
     596 * @param   pDrvReg         The backend driver to use.
     597 * @param   fEnabledIn      Whether input is enabled or not on creation time.
     598 * @param   fEnabledOut     Whether output is enabled or not on creation time.
     599 * @param   fWithDrvAudio   Whether to include DrvAudio in the stack or not.
     600 */
     601int audioTestDriverStackProbe(PAUDIOTESTDRVSTACK pDrvStack, PCPDMDRVREG pDrvReg, bool fEnabledIn, bool fEnabledOut, bool fWithDrvAudio)
     602{
     603    int rc;
     604
     605    for (size_t i = 0; i < g_cBackends; i++)
     606    {
     607        pDrvReg = g_aBackends[i].pDrvReg;
     608        RTTestPrintf(g_hTest, RTTESTLVL_ALWAYS, "Probing for backend '%s' ...\n", g_aBackends[i].pszName);
     609
     610        rc = audioTestDriverStackInitEx(pDrvStack, pDrvReg, fEnabledIn, fEnabledOut, fWithDrvAudio); /** @todo Make in/out configurable, too. */
     611        if (RT_SUCCESS(rc))
     612        {
     613            RTTestPrintf(g_hTest, RTTESTLVL_ALWAYS, "Probing backend '%s' successful\n", g_aBackends[i].pszName);
     614            return rc;
     615        }
     616
     617        RTTestPrintf(g_hTest, RTTESTLVL_ALWAYS, "Probing backend '%s' failed with %Rrc, trying next one\n",
     618                     g_aBackends[i].pszName, rc);
     619        continue;
     620    }
     621
     622    RTTestPrintf(g_hTest, RTTESTLVL_ALWAYS, "Probing all backends failed\n");
     623    return rc;
     624}
    590625
    591626/**
  • trunk/src/VBox/ValidationKit/utils/audio/vkatInternal.h

    r90918 r91088  
    292292
    293293/**
     294 * Backend description.
     295 */
     296typedef struct AUDIOTESTBACKENDDESC
     297{
     298    /** The driver registration structure. */
     299    PCPDMDRVREG pDrvReg;
     300    /** The backend name.
     301     * Aliases are implemented by having multiple entries for the same backend.  */
     302    const char *pszName;
     303} AUDIOTESTBACKENDDESC;
     304
     305/**
    294306 * VKAT command table entry.
    295307 */
     
    348360extern unsigned         g_cTests;
    349361
     362extern AUDIOTESTBACKENDDESC const g_aBackends[];
     363extern unsigned                   g_cBackends;
     364
    350365
    351366/*********************************************************************************************************************************
     
    365380int         audioTestDriverStackInitEx(PAUDIOTESTDRVSTACK pDrvStack, PCPDMDRVREG pDrvReg, bool fEnabledIn, bool fEnabledOut, bool fWithDrvAudio);
    366381int         audioTestDriverStackInit(PAUDIOTESTDRVSTACK pDrvStack, PCPDMDRVREG pDrvReg, bool fWithDrvAudio);
     382int         audioTestDriverStackProbe(PAUDIOTESTDRVSTACK pDrvStack, PCPDMDRVREG pDrvReg, bool fEnabledIn, bool fEnabledOut, bool fWithDrvAudio);
    367383int         audioTestDriverStackSetDevice(PAUDIOTESTDRVSTACK pDrvStack, PDMAUDIODIR enmDir, const char *pszDevId);
    368384/** @}  */
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