VirtualBox

Changeset 89086 in vbox for trunk/src/VBox/ValidationKit


Ignore:
Timestamp:
May 17, 2021 9:57:51 AM (4 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
144426
Message:

ValKit/Audio: Allow common options to be specified after the command. bugref:10008

File:
1 edited

Legend:

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

    r89085 r89086  
    6565#include "../../../Devices/Audio/AudioTest.h"
    6666#include "VBoxDD.h"
     67
     68
     69/*********************************************************************************************************************************
     70*   Defined Constants And Macros                                                                                                 *
     71*********************************************************************************************************************************/
     72/** For use in the option switch to handle common options. */
     73#define AUDIO_TEST_COMMON_OPTION_CASES() \
     74            case 'q': \
     75                g_uVerbosity = 0; \
     76                break; \
     77            \
     78            case 'v': \
     79                g_uVerbosity++; \
     80                break; \
     81            \
     82            case 'V': \
     83                return audioTestVersion(); \
     84            \
     85            case 'h': \
     86                return audioTestUsage(g_pStdOut)
     87
    6788
    6889
     
    16721693 * Main (entry) function for the testing functionality of VKAT.
    16731694 *
    1674  * @returns RTEXITCODE
    1675  * @param   argc                Number of argv arguments.
    1676  * @param   argv                argv arguments.
    1677  */
    1678 static DECLCALLBACK(RTEXITCODE) audioTestMain(int argc, char **argv)
     1695 * @returns Program exit code.
     1696 * @param   pGetState   RTGetOpt state.
     1697 */
     1698static DECLCALLBACK(RTEXITCODE) audioTestMain(PRTGETOPTSTATE pGetState)
    16791699{
    16801700    AUDIOTESTENV TstEnv;
     
    16881708    PCPDMDRVREG pDrvReg    = g_aBackends[0].pDrvReg;
    16891709
    1690     RTGETOPTSTATE GetState;
    1691     int rc = RTGetOptInit(&GetState, argc, argv, g_aCmdTestOptions, RT_ELEMENTS(g_aCmdTestOptions), 1, 0 /*fFlags*/);
    1692     AssertRCReturn(rc, RTEXITCODE_INIT);
    1693 
     1710    int           rc;
    16941711    RTGETOPTUNION ValueUnion;
    1695     while ((rc = RTGetOpt(&GetState, &ValueUnion)))
     1712    while ((rc = RTGetOpt(pGetState, &ValueUnion)))
    16961713    {
    16971714        switch (rc)
     
    17751792                break;
    17761793
    1777             case 'V':
    1778                 return audioTestVersion();
    1779             case 'h':
    1780                 return audioTestUsage(g_pStdOut);
     1794            AUDIO_TEST_COMMON_OPTION_CASES();
    17811795
    17821796            default:
     
    18851899 * Main (entry) function for the verification functionality of VKAT.
    18861900 *
    1887  * @returns RTEXITCODE
    1888  * @param   argc                Number of argv arguments.
    1889  * @param   argv                argv arguments.
    1890  */
    1891 static DECLCALLBACK(RTEXITCODE) audioVerifyMain(int argc, char **argv)
     1901 * @returns Program exit code.
     1902 * @param   pGetState   RTGetOpt state.
     1903 */
     1904static DECLCALLBACK(RTEXITCODE) audioVerifyMain(PRTGETOPTSTATE pGetState)
    18921905{
    18931906    /*
    18941907     * Parse options and process arguments.
    18951908     */
    1896     RTGETOPTSTATE GetState;
    1897     int rc = RTGetOptInit(&GetState, argc, argv, g_aCmdVerifyOptions, RT_ELEMENTS(g_aCmdVerifyOptions),
    1898                           1, RTGETOPTINIT_FLAGS_OPTS_FIRST);
    1899     AssertRCReturn(rc, RTEXITCODE_INIT);
    1900 
    19011909    const char   *pszTag   = NULL; /* Custom tag to use. Can be NULL if not being used. */
    19021910    unsigned      iTestSet = 0;
     1911
     1912    int           rc;
    19031913    RTGETOPTUNION ValueUnion;
    1904     while ((rc = RTGetOpt(&GetState, &ValueUnion)))
     1914    while ((rc = RTGetOpt(pGetState, &ValueUnion)))
    19051915    {
    19061916        switch (rc)
     
    19191929                break;
    19201930
    1921             case 'V':
    1922                 return audioTestVersion();
    1923             case 'h':
    1924                 return audioTestUsage(g_pStdOut);
     1931            AUDIO_TEST_COMMON_OPTION_CASES();
    19251932
    19261933            default:
     
    21122119 *
    21132120 * @returns Program exit code.
    2114  * @param   argc                Number of argv arguments.
    2115  * @param   argv                argv arguments.
    2116  */
    2117 static DECLCALLBACK(RTEXITCODE) audioTestCmdPlayHandler(int argc, char **argv)
     2121 * @param   pGetState   RTGetOpt state.
     2122 */
     2123static DECLCALLBACK(RTEXITCODE) audioTestCmdPlayHandler(PRTGETOPTSTATE pGetState)
    21182124{
    21192125    /* Option values: */
     
    21242130    bool        fWithDrvAudio     = false;
    21252131
    2126     /* Init option state: */
    2127     RTGETOPTSTATE GetState;
    2128     int rc = RTGetOptInit(&GetState, argc, argv, g_aCmdPlayOptions, RT_ELEMENTS(g_aCmdPlayOptions),
    2129                           1 /*iFirst*/, RTGETOPTINIT_FLAGS_OPTS_FIRST);
    2130     AssertRCReturn(rc, RTEXITCODE_INIT);
    2131 
    21322132    /* Argument processing loop: */
     2133    int           rc;
    21332134    RTGETOPTUNION ValueUnion;
    2134     while ((rc = RTGetOpt(&GetState, &ValueUnion)) != 0)
     2135    while ((rc = RTGetOpt(pGetState, &ValueUnion)) != 0)
    21352136    {
    21362137        switch (rc)
     
    21622163            }
    21632164
    2164             case 'V':
    2165                 return audioTestVersion();
    2166             case 'h':
    2167                 return audioTestUsage(g_pStdOut);
     2165            AUDIO_TEST_COMMON_OPTION_CASES();
    21682166
    21692167            default:
     
    21832181    const char     *pszCommand;
    21842182    /** The command handler.   */
    2185     DECLCALLBACKMEMBER(RTEXITCODE, pfnHandler,(int argc, char **argv));
     2183    DECLCALLBACKMEMBER(RTEXITCODE, pfnHandler,(PRTGETOPTSTATE pGetState));
    21862184
    21872185    /** Command description.   */
     
    22912289     * Process common options.
    22922290     */
    2293     RTGETOPTUNION ValueUnion;
    22942291    RTGETOPTSTATE GetState;
    22952292    int rc = RTGetOptInit(&GetState, argc, argv, g_aCmdCommonOptions,
     
    22972294    AssertRCReturn(rc, RTEXITCODE_INIT);
    22982295
     2296    RTGETOPTUNION ValueUnion;
    22992297    while ((rc = RTGetOpt(&GetState, &ValueUnion)) != 0)
    23002298    {
     
    23212319                    if (strcmp(ValueUnion.psz, g_aCommands[i].pszCommand) == 0)
    23222320                    {
    2323                         audioTestShowLogo(g_pStdOut);
    2324                         int32_t iCurArg = GetState.iNext - 1;
    2325                         return g_aCommands[i].pfnHandler(argc - iCurArg, argv + iCurArg);
     2321                        size_t const cCombinedOptions  = g_aCommands[i].cOptions + RT_ELEMENTS(g_aCmdCommonOptions);
     2322                        PRTGETOPTDEF paCombinedOptions = (PRTGETOPTDEF)RTMemAlloc(cCombinedOptions * sizeof(RTGETOPTDEF));
     2323                        if (paCombinedOptions)
     2324                        {
     2325                            memcpy(paCombinedOptions, g_aCmdCommonOptions, sizeof(g_aCmdCommonOptions));
     2326                            memcpy(&paCombinedOptions[RT_ELEMENTS(g_aCmdCommonOptions)],
     2327                                   g_aCommands[i].paOptions, g_aCommands[i].cOptions * sizeof(RTGETOPTDEF));
     2328
     2329                            rc = RTGetOptInit(&GetState, argc, argv, paCombinedOptions, cCombinedOptions,
     2330                                              GetState.iNext /*idxFirst*/, RTGETOPTINIT_FLAGS_OPTS_FIRST);
     2331                            if (RT_SUCCESS(rc))
     2332                            {
     2333
     2334                                rcExit = g_aCommands[i].pfnHandler(&GetState);
     2335                                RTMemFree(paCombinedOptions);
     2336                                return rcExit;
     2337                            }
     2338                            return RTMsgErrorExitFailure("RTGetOptInit failed for '%s': %Rrc", ValueUnion.psz, rc);
     2339                        }
     2340                        return RTMsgErrorExitFailure("Out of memory!");
    23262341                    }
    23272342                RTMsgError("Unknown command '%s'!\n", ValueUnion.psz);
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