Changeset 96607 in vbox
- Timestamp:
- Sep 5, 2022 10:30:23 PM (2 years ago)
- Location:
- trunk/src/VBox/ValidationKit/utils/audio
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/ValidationKit/utils/audio/vkat.cpp
r96473 r96607 926 926 break; 927 927 928 AUDIO_TEST_COMMON_OPTION_CASES(ValueUnion );928 AUDIO_TEST_COMMON_OPTION_CASES(ValueUnion, &g_CmdTest); 929 929 930 930 default: … … 1218 1218 break; 1219 1219 1220 AUDIO_TEST_COMMON_OPTION_CASES(ValueUnion );1220 AUDIO_TEST_COMMON_OPTION_CASES(ValueUnion, &g_CmdVerify); 1221 1221 1222 1222 default: … … 1309 1309 &g_CmdTest, 1310 1310 &g_CmdVerify, 1311 &g_CmdBackends, 1311 1312 &g_CmdEnum, 1312 1313 &g_CmdPlay, … … 1318 1319 * Shows tool usage text. 1319 1320 */ 1320 RTEXITCODE audioTestUsage(PRTSTREAM pStrm) 1321 { 1322 RTStrmPrintf(pStrm, "usage: %s [global options] <command> [command-options]\n", 1323 RTPathFilename(RTProcExecutablePath())); 1321 RTEXITCODE audioTestUsage(PRTSTREAM pStrm, PCVKATCMD pOnlyCmd) 1322 { 1323 RTStrmPrintf(pStrm, "usage: %s [global options] <command> [command-options]\n", RTProcShortName()); 1324 1324 RTStrmPrintf(pStrm, 1325 1325 "\n" … … 1342 1342 { 1343 1343 PCVKATCMD const pCmd = g_apCommands[iCmd]; 1344 RTStrmPrintf(pStrm, 1345 "\n" 1346 "Command '%s':\n" 1347 " %s\n" 1348 "Options for '%s':\n", 1349 pCmd->pszCommand, pCmd->pszDesc, pCmd->pszCommand); 1350 PCRTGETOPTDEF const paOptions = pCmd->paOptions; 1351 for (unsigned i = 0; i < pCmd->cOptions; i++) 1344 if (!pOnlyCmd || pCmd == pOnlyCmd) 1352 1345 { 1353 if (RT_C_IS_PRINT(paOptions[i].iShort)) 1354 RTStrmPrintf(pStrm, " -%c, %s\n", paOptions[i].iShort, paOptions[i].pszLong); 1355 else 1356 RTStrmPrintf(pStrm, " %s\n", paOptions[i].pszLong); 1357 1358 const char *pszHelp = NULL; 1359 if (pCmd->pfnOptionHelp) 1360 pszHelp = pCmd->pfnOptionHelp(&paOptions[i]); 1361 if (pszHelp) 1362 RTStrmPrintf(pStrm, " %s\n", pszHelp); 1346 RTStrmPrintf(pStrm, 1347 "\n" 1348 "Command '%s':\n" 1349 " %s\n" 1350 "Options for '%s':\n", 1351 pCmd->pszCommand, pCmd->pszDesc, pCmd->pszCommand); 1352 PCRTGETOPTDEF const paOptions = pCmd->paOptions; 1353 for (unsigned i = 0; i < pCmd->cOptions; i++) 1354 { 1355 if (RT_C_IS_PRINT(paOptions[i].iShort)) 1356 RTStrmPrintf(pStrm, " -%c, %s\n", paOptions[i].iShort, paOptions[i].pszLong); 1357 else 1358 RTStrmPrintf(pStrm, " %s\n", paOptions[i].pszLong); 1359 1360 const char *pszHelp = NULL; 1361 if (pCmd->pfnOptionHelp) 1362 pszHelp = pCmd->pfnOptionHelp(&paOptions[i]); 1363 if (pszHelp) 1364 RTStrmPrintf(pStrm, " %s\n", pszHelp); 1365 } 1366 1367 if (pCmd->fNeedsTransport) 1368 for (uintptr_t iTx = 0; iTx < g_cTransports; iTx++) 1369 g_apTransports[iTx]->pfnUsage(pStrm); 1363 1370 } 1364 1365 if (pCmd->fNeedsTransport) 1366 { 1367 for (uintptr_t iTx = 0; iTx < g_cTransports; iTx++) 1368 g_apTransports[iTx]->pfnUsage(pStrm); 1369 } 1370 } 1371 1371 } 1372 1373 return RTEXITCODE_SUCCESS; 1374 } 1375 1376 /** 1377 * Lists the commands and their descriptions. 1378 */ 1379 static RTEXITCODE audioTestListCommands(PRTSTREAM pStrm) 1380 { 1381 RTStrmPrintf(pStrm, "Commands:\n"); 1382 for (uintptr_t iCmd = 0; iCmd < RT_ELEMENTS(g_apCommands); iCmd++) 1383 RTStrmPrintf(pStrm, "%8s - %s\n", g_apCommands[iCmd]->pszCommand, g_apCommands[iCmd]->pszDesc); 1372 1384 return RTEXITCODE_SUCCESS; 1373 1385 } … … 1406 1418 * everything else. 1407 1419 */ 1420 /** @todo r=bird: this isn't at all syntactically sane, because you don't know 1421 * how to parse past the command (can almost be done safely thought, since 1422 * you've got the option definitions for every command at hand). So, if someone 1423 * wants to play a file named "-v.wav", you'll incorrectly take that as two 'v' 1424 * options. The parsing has to stop when you get to the command, i.e. first 1425 * VINF_GETOPT_NOT_OPTION or anything that isn't a common option. Daemonizing 1426 * when for instance encountering an invalid command, is not correct. 1427 * 1428 * Btw. you MUST however process the 'q' option in parallel to 'v' here, they 1429 * are oposites. For instance '-vqvvv' is supposed to give you level 3 logging, 1430 * not quiet! So, either you process both 'v' and 'q' here, or you pospone them 1431 * (better option). 1432 */ 1433 /** @todo r=bird: Is the daemonizing needed? The testcase doesn't seem to use 1434 * it... If you don't need it, drop it as it make the parsing complex 1435 * and illogical. The --daemonized / --damonize options should be 1436 * required to before the command, then okay. */ 1408 1437 bool fDaemonize = false; 1409 1438 bool fDaemonized = false; … … 1439 1468 } 1440 1469 1470 /** @todo add something to suppress this stuff. */ 1441 1471 audioTestShowLogo(g_pStdOut); 1442 1472 … … 1544 1574 switch (ch) 1545 1575 { 1546 AUDIO_TEST_COMMON_OPTION_CASES(ValueUnion );1576 AUDIO_TEST_COMMON_OPTION_CASES(ValueUnion, NULL); 1547 1577 1548 1578 case VINF_GETOPT_NOT_OPTION: … … 1553 1583 if (strcmp(ValueUnion.psz, pCmd->pszCommand) == 0) 1554 1584 { 1585 /* Count the combined option definitions: */ 1555 1586 size_t cCombinedOptions = pCmd->cOptions + RT_ELEMENTS(g_aCmdCommonOptions); 1556 1587 if (pCmd->fNeedsTransport) 1557 {1558 1588 for (uintptr_t iTx = 0; iTx < g_cTransports; iTx++) 1559 1589 cCombinedOptions += g_apTransports[iTx]->cOpts; 1560 } 1590 1591 /* Combine the option definitions: */ 1561 1592 PRTGETOPTDEF paCombinedOptions = (PRTGETOPTDEF)RTMemAlloc(cCombinedOptions * sizeof(RTGETOPTDEF)); 1562 1593 if (paCombinedOptions) … … 1565 1596 memcpy(paCombinedOptions, g_aCmdCommonOptions, sizeof(g_aCmdCommonOptions)); 1566 1597 idxOpts += RT_ELEMENTS(g_aCmdCommonOptions); 1598 1567 1599 memcpy(&paCombinedOptions[idxOpts], pCmd->paOptions, pCmd->cOptions * sizeof(RTGETOPTDEF)); 1568 1600 idxOpts += (uint32_t)pCmd->cOptions; 1601 1569 1602 if (pCmd->fNeedsTransport) 1570 {1571 1603 for (uintptr_t iTx = 0; iTx < g_cTransports; iTx++) 1572 1604 { … … 1575 1607 idxOpts += (uint32_t)g_apTransports[iTx]->cOpts; 1576 1608 } 1577 } 1578 1609 1610 /* Re-initialize the option getter state and pass it to the command handler. */ 1579 1611 rc = RTGetOptInit(&GetState, argc, argv, paCombinedOptions, cCombinedOptions, 1580 1612 GetState.iNext /*idxFirst*/, RTGETOPTINIT_FLAGS_OPTS_FIRST); … … 1585 1617 return rcExit; 1586 1618 } 1619 RTMemFree(paCombinedOptions); 1587 1620 return RTMsgErrorExitFailure("RTGetOptInit failed for '%s': %Rrc", ValueUnion.psz, rc); 1588 1621 } … … 1591 1624 } 1592 1625 RTMsgError("Unknown command '%s'!\n", ValueUnion.psz); 1593 audioTest Usage(g_pStdErr);1626 audioTestListCommands(g_pStdErr); 1594 1627 return RTEXITCODE_SYNTAX; 1595 1628 } … … 1601 1634 1602 1635 RTMsgError("No command specified!\n"); 1603 audioTest Usage(g_pStdErr);1636 audioTestListCommands(g_pStdErr); 1604 1637 return RTEXITCODE_SYNTAX; 1605 1638 } -
trunk/src/VBox/ValidationKit/utils/audio/vkatCmdGeneric.cpp
r96407 r96607 48 48 49 49 /********************************************************************************************************************************* 50 * Command: backends * 51 *********************************************************************************************************************************/ 52 53 /** 54 * Options for 'backends'. 55 */ 56 static const RTGETOPTDEF g_aCmdBackendsOptions[] = 57 { 58 { "--dummy", 'd', RTGETOPT_REQ_NOTHING }, /* just a placeholder */ 59 }; 60 61 62 /** The 'backends' command option help. */ 63 static DECLCALLBACK(const char *) audioTestCmdBackendsHelp(PCRTGETOPTDEF pOpt) 64 { 65 RT_NOREF(pOpt); 66 return NULL; 67 } 68 69 /** 70 * The 'backends' command handler. 71 * 72 * @returns Program exit code. 73 * @param pGetState RTGetOpt state. 74 */ 75 static DECLCALLBACK(RTEXITCODE) audioTestCmdBackendsHandler(PRTGETOPTSTATE pGetState) 76 { 77 /* 78 * Parse options. 79 */ 80 int ch; 81 RTGETOPTUNION ValueUnion; 82 while ((ch = RTGetOpt(pGetState, &ValueUnion)) != 0) 83 { 84 switch (ch) 85 { 86 AUDIO_TEST_COMMON_OPTION_CASES(ValueUnion, &g_CmdBackends); 87 88 default: 89 return RTGetOptPrintError(ch, &ValueUnion); 90 } 91 } 92 93 /* 94 * List the backends. 95 */ 96 RTPrintf("Backends (%u):\n", g_cBackends); 97 for (size_t i = 0; i < g_cBackends; i++) 98 RTPrintf(" %12s - %s\n", g_aBackends[i].pszName, g_aBackends[i].pDrvReg->pszDescription); 99 100 return RTEXITCODE_SUCCESS; 101 } 102 103 104 /** 105 * Command table entry for 'backends'. 106 */ 107 const VKATCMD g_CmdBackends = 108 { 109 /* .pszCommand = */ "backends", 110 /* .pfnHandler = */ audioTestCmdBackendsHandler, 111 /* .pszDesc = */ "Lists the compiled in audio backends.", 112 /* .paOptions = */ g_aCmdBackendsOptions, 113 /* .cOptions = */ 0 /*RT_ELEMENTS(g_aCmdBackendsOptions)*/, 114 /* .pfnOptionHelp = */ audioTestCmdBackendsHelp, 115 /* .fNeedsTransport = */ false 116 }; 117 118 119 /********************************************************************************************************************************* 50 120 * Command: enum * 51 121 *********************************************************************************************************************************/ … … 114 184 break; 115 185 116 AUDIO_TEST_COMMON_OPTION_CASES(ValueUnion );186 AUDIO_TEST_COMMON_OPTION_CASES(ValueUnion, &g_CmdEnum); 117 187 118 188 default: … … 673 743 } 674 744 675 AUDIO_TEST_COMMON_OPTION_CASES(ValueUnion );745 AUDIO_TEST_COMMON_OPTION_CASES(ValueUnion, &g_CmdPlay); 676 746 677 747 default: … … 1074 1144 } 1075 1145 1076 AUDIO_TEST_COMMON_OPTION_CASES(ValueUnion );1146 AUDIO_TEST_COMMON_OPTION_CASES(ValueUnion, &g_CmdRec); 1077 1147 1078 1148 default: -
trunk/src/VBox/ValidationKit/utils/audio/vkatCmdSelfTest.cpp
r96407 r96607 415 415 break; 416 416 417 AUDIO_TEST_COMMON_OPTION_CASES(ValueUnion );417 AUDIO_TEST_COMMON_OPTION_CASES(ValueUnion, &g_CmdSelfTest); 418 418 419 419 default: -
trunk/src/VBox/ValidationKit/utils/audio/vkatInternal.h
r96407 r96607 378 378 extern const char *g_pszDrvAudioDebug; 379 379 380 extern const VKATCMD g_CmdTest; 381 extern const VKATCMD g_CmdVerify; 382 extern const VKATCMD g_CmdBackends; 380 383 extern const VKATCMD g_CmdEnum; 381 384 extern const VKATCMD g_CmdPlay; … … 383 386 extern const VKATCMD g_CmdSelfTest; 384 387 388 385 389 extern AUDIOTESTDESC g_aTests[]; 386 390 extern unsigned g_cTests; … … 396 400 /** @name Command line handlers 397 401 * @{ */ 398 RTEXITCODE audioTestUsage(PRTSTREAM pStrm );402 RTEXITCODE audioTestUsage(PRTSTREAM pStrm, PCVKATCMD pOnlyCmd); 399 403 RTEXITCODE audioTestVersion(void); 400 404 void audioTestShowLogo(PRTSTREAM pStream); … … 494 498 void audioTestIoOptsInitDefaults(PAUDIOTESTIOOPTS pIoOpts); 495 499 500 496 501 /********************************************************************************************************************************* 497 502 * Common command line stuff * … … 510 515 511 516 /** For use in the option switch to handle common options. */ 512 #define AUDIO_TEST_COMMON_OPTION_CASES(a_ValueUnion ) \517 #define AUDIO_TEST_COMMON_OPTION_CASES(a_ValueUnion, a_pCmd) \ 513 518 case 'q': \ 514 519 g_uVerbosity = 0; \ … … 518 523 \ 519 524 case 'v': \ 520 /* No-op here, has been handled by main() already. */ \525 /* No-op here, has been handled by main() already. */ /** @todo r-bird: -q works, so -v must too! */ \ 521 526 break; \ 522 527 \ … … 525 530 \ 526 531 case 'h': \ 527 return audioTestUsage(g_pStdOut ); \532 return audioTestUsage(g_pStdOut, a_pCmd); \ 528 533 \ 529 534 case AUDIO_TEST_OPT_CMN_DEBUG_AUDIO_ENABLE: \
Note:
See TracChangeset
for help on using the changeset viewer.