VirtualBox

source: vbox/trunk/src/VBox/ValidationKit/utils/audio/vkat.cpp@ 89964

Last change on this file since 89964 was 89964, checked in by vboxsync, 4 years ago

Audio/ValKit: Closing fixes for audioVerifyOne(). bugref:10008

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 42.1 KB
Line 
1/* $Id: vkat.cpp 89964 2021-06-30 07:57:43Z vboxsync $ */
2/** @file
3 * Validation Kit Audio Test (VKAT) utility for testing and validating the audio stack.
4 */
5
6/*
7 * Copyright (C) 2021 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 *
17 * The contents of this file may alternatively be used under the terms
18 * of the Common Development and Distribution License Version 1.0
19 * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
20 * VirtualBox OSE distribution, in which case the provisions of the
21 * CDDL are applicable instead of those of the GPL.
22 *
23 * You may elect to license modified versions of this file under the
24 * terms and conditions of either the GPL or the CDDL or both.
25 */
26
27
28/*********************************************************************************************************************************
29* Header Files *
30*********************************************************************************************************************************/
31#include <iprt/buildconfig.h>
32#include <iprt/ctype.h>
33#include <iprt/dir.h>
34#include <iprt/errcore.h>
35#include <iprt/file.h>
36#include <iprt/initterm.h>
37#include <iprt/getopt.h>
38#include <iprt/message.h>
39#include <iprt/path.h>
40#include <iprt/process.h>
41#include <iprt/rand.h>
42#include <iprt/stream.h>
43#include <iprt/string.h>
44#include <iprt/test.h>
45
46#include <package-generated.h>
47#include "product-generated.h"
48
49#include <VBox/version.h>
50#include <VBox/log.h>
51
52#ifdef RT_OS_WINDOWS
53# include <iprt/win/windows.h> /* for CoInitializeEx */
54#endif
55#include <signal.h>
56
57#include "vkatInternal.h"
58
59
60/*********************************************************************************************************************************
61* Internal Functions *
62*********************************************************************************************************************************/
63static int audioVerifyOne(const char *pszPathSetA, const char *pszPathSetB);
64
65
66/*********************************************************************************************************************************
67* Global Variables *
68*********************************************************************************************************************************/
69/**
70 * Backends.
71 *
72 * @note The first backend in the array is the default one for the platform.
73 */
74struct
75{
76 /** The driver registration structure. */
77 PCPDMDRVREG pDrvReg;
78 /** The backend name.
79 * Aliases are implemented by having multiple entries for the same backend. */
80 const char *pszName;
81} const g_aBackends[] =
82{
83#if defined(VBOX_WITH_AUDIO_ALSA) && defined(RT_OS_LINUX)
84 { &g_DrvHostALSAAudio, "alsa" },
85#endif
86#ifdef VBOX_WITH_AUDIO_PULSE
87 { &g_DrvHostPulseAudio, "pulseaudio" },
88 { &g_DrvHostPulseAudio, "pulse" },
89 { &g_DrvHostPulseAudio, "pa" },
90#endif
91#ifdef VBOX_WITH_AUDIO_OSS
92 { &g_DrvHostOSSAudio, "oss" },
93#endif
94#if defined(RT_OS_DARWIN)
95 { &g_DrvHostCoreAudio, "coreaudio" },
96 { &g_DrvHostCoreAudio, "core" },
97 { &g_DrvHostCoreAudio, "ca" },
98#endif
99#if defined(RT_OS_WINDOWS)
100 { &g_DrvHostAudioWas, "wasapi" },
101 { &g_DrvHostAudioWas, "was" },
102 { &g_DrvHostDSound, "directsound" },
103 { &g_DrvHostDSound, "dsound" },
104 { &g_DrvHostDSound, "ds" },
105#endif
106 { &g_DrvHostValidationKitAudio, "valkit" }
107};
108AssertCompile(sizeof(g_aBackends) > 0 /* port me */);
109
110/**
111 * Long option values for the 'test' command.
112 */
113enum
114{
115 VKAT_TEST_OPT_COUNT = 900,
116 VKAT_TEST_OPT_DEV,
117 VKAT_TEST_OPT_GUEST_ATS_ADDR,
118 VKAT_TEST_OPT_GUEST_ATS_PORT,
119 VKAT_TEST_OPT_HOST_ATS_ADDR,
120 VKAT_TEST_OPT_HOST_ATS_PORT,
121 VKAT_TEST_OPT_MODE,
122 VKAT_TEST_OPT_NO_VERIFY,
123 VKAT_TEST_OPT_OUTDIR,
124 VKAT_TEST_OPT_PAUSE,
125 VKAT_TEST_OPT_PCM_HZ,
126 VKAT_TEST_OPT_PCM_BIT,
127 VKAT_TEST_OPT_PCM_CHAN,
128 VKAT_TEST_OPT_PCM_SIGNED,
129 VKAT_TEST_OPT_TAG,
130 VKAT_TEST_OPT_TEMPDIR,
131 VKAT_TEST_OPT_VOL
132};
133
134/**
135 * Long option values for the 'verify' command.
136 */
137enum
138{
139 VKAT_VERIFY_OPT_TAG = 900
140};
141
142/**
143 * Common command line parameters.
144 */
145static const RTGETOPTDEF g_aCmdCommonOptions[] =
146{
147 { "--quiet", 'q', RTGETOPT_REQ_NOTHING },
148 { "--verbose", 'v', RTGETOPT_REQ_NOTHING },
149 { "--debug-audio", AUDIO_TEST_OPT_CMN_DEBUG_AUDIO_ENABLE, RTGETOPT_REQ_NOTHING },
150 { "--debug-audio-path", AUDIO_TEST_OPT_CMN_DEBUG_AUDIO_PATH, RTGETOPT_REQ_STRING },
151};
152
153/**
154 * Command line parameters for test mode.
155 */
156static const RTGETOPTDEF g_aCmdTestOptions[] =
157{
158 { "--backend", 'b', RTGETOPT_REQ_STRING },
159 { "--drvaudio", 'd', RTGETOPT_REQ_NOTHING },
160 { "--exclude", 'e', RTGETOPT_REQ_UINT32 },
161 { "--exclude-all", 'a', RTGETOPT_REQ_NOTHING },
162 { "--guest-ats-addr", VKAT_TEST_OPT_GUEST_ATS_ADDR, RTGETOPT_REQ_STRING },
163 { "--guest-ats-port", VKAT_TEST_OPT_GUEST_ATS_PORT, RTGETOPT_REQ_UINT32 },
164 { "--host-ats-address", VKAT_TEST_OPT_HOST_ATS_ADDR, RTGETOPT_REQ_STRING },
165 { "--host-ats-port", VKAT_TEST_OPT_HOST_ATS_PORT, RTGETOPT_REQ_UINT32 },
166 { "--include", 'i', RTGETOPT_REQ_UINT32 },
167 { "--outdir", VKAT_TEST_OPT_OUTDIR, RTGETOPT_REQ_STRING },
168 { "--count", VKAT_TEST_OPT_COUNT, RTGETOPT_REQ_UINT32 },
169 { "--device", VKAT_TEST_OPT_DEV, RTGETOPT_REQ_STRING },
170 { "--pause", VKAT_TEST_OPT_PAUSE, RTGETOPT_REQ_UINT32 },
171 { "--pcm-bit", VKAT_TEST_OPT_PCM_BIT, RTGETOPT_REQ_UINT8 },
172 { "--pcm-chan", VKAT_TEST_OPT_PCM_CHAN, RTGETOPT_REQ_UINT8 },
173 { "--pcm-hz", VKAT_TEST_OPT_PCM_HZ, RTGETOPT_REQ_UINT16 },
174 { "--pcm-signed", VKAT_TEST_OPT_PCM_SIGNED, RTGETOPT_REQ_BOOL },
175 { "--mode", VKAT_TEST_OPT_MODE, RTGETOPT_REQ_STRING },
176 { "--no-verify", VKAT_TEST_OPT_NO_VERIFY, RTGETOPT_REQ_NOTHING },
177 { "--tag", VKAT_TEST_OPT_TAG, RTGETOPT_REQ_STRING },
178 { "--tempdir", VKAT_TEST_OPT_TEMPDIR, RTGETOPT_REQ_STRING },
179 { "--volume", VKAT_TEST_OPT_VOL, RTGETOPT_REQ_UINT8 }
180};
181
182/**
183 * Command line parameters for verification mode.
184 */
185static const RTGETOPTDEF g_aCmdVerifyOptions[] =
186{
187 { "--tag", VKAT_VERIFY_OPT_TAG, RTGETOPT_REQ_STRING }
188};
189
190/** Terminate ASAP if set. Set on Ctrl-C. */
191bool volatile g_fTerminate = false;
192/** The release logger. */
193PRTLOGGER g_pRelLogger = NULL;
194/** The test handle. */
195RTTEST g_hTest;
196/** The current verbosity level. */
197unsigned g_uVerbosity = 0;
198/** DrvAudio: Enable debug (or not). */
199bool g_fDrvAudioDebug = false;
200/** DrvAudio: The debug output path. */
201const char *g_pszDrvAudioDebug = NULL;
202
203
204/**
205 * Get default backend.
206 */
207PCPDMDRVREG AudioTestGetDefaultBackend(void)
208{
209 return g_aBackends[0].pDrvReg;
210}
211
212
213/**
214 * Helper for handling --backend options.
215 *
216 * @returns Pointer to the specified backend, NULL if not found (error
217 * displayed).
218 * @param pszBackend The backend option value.
219 */
220PCPDMDRVREG AudioTestFindBackendOpt(const char *pszBackend)
221{
222 for (uintptr_t i = 0; i < RT_ELEMENTS(g_aBackends); i++)
223 if ( strcmp(pszBackend, g_aBackends[i].pszName) == 0
224 || strcmp(pszBackend, g_aBackends[i].pDrvReg->szName) == 0)
225 return g_aBackends[i].pDrvReg;
226 RTMsgError("Unknown backend: '%s'", pszBackend);
227 return NULL;
228}
229
230
231/*********************************************************************************************************************************
232* Test callbacks *
233*********************************************************************************************************************************/
234
235/**
236 * @copydoc FNAUDIOTESTSETUP
237 */
238static DECLCALLBACK(int) audioTestPlayToneSetup(PAUDIOTESTENV pTstEnv, PAUDIOTESTDESC pTstDesc, PAUDIOTESTPARMS pTstParmsAcq, void **ppvCtx)
239{
240 RT_NOREF(pTstDesc, ppvCtx);
241
242 int rc = VINF_SUCCESS;
243
244 if (strlen(pTstEnv->szDev))
245 {
246 rc = audioTestDriverStackSetDevice(&pTstEnv->DrvStack, PDMAUDIODIR_OUT, pTstEnv->szDev);
247 if (RT_FAILURE(rc))
248 return rc;
249 }
250
251 pTstParmsAcq->enmType = AUDIOTESTTYPE_TESTTONE_PLAY;
252 pTstParmsAcq->Props = pTstEnv->Props;
253 pTstParmsAcq->enmDir = PDMAUDIODIR_OUT;
254#ifdef DEBUG
255 pTstParmsAcq->cIterations = 1;
256#else
257 pTstParmsAcq->cIterations = RTRandU32Ex(1, 10);
258#endif
259 pTstParmsAcq->idxCurrent = 0;
260
261 PAUDIOTESTTONEPARMS pToneParms = &pTstParmsAcq->TestTone;
262
263 pToneParms->Props = pTstParmsAcq->Props;
264 pToneParms->dbFreqHz = AudioTestToneGetRandomFreq();
265 pToneParms->msPrequel = 0; /** @todo Implement analyzing this first! */
266#ifdef DEBUG_andy
267 pToneParms->msDuration = 2000;
268#else
269 pToneParms->msDuration = RTRandU32Ex(0, RT_MS_10SEC); /** @todo Probably a bit too long, but let's see. */
270#endif
271 pToneParms->msSequel = 0; /** @todo Implement analyzing this first! */
272 pToneParms->uVolumePercent = 100; /** @todo Implement analyzing this first! */
273
274 return rc;
275}
276
277/**
278 * @copydoc FNAUDIOTESTEXEC
279 */
280static DECLCALLBACK(int) audioTestPlayToneExec(PAUDIOTESTENV pTstEnv, void *pvCtx, PAUDIOTESTPARMS pTstParms)
281{
282 RT_NOREF(pvCtx);
283
284 int rc = VINF_SUCCESS;
285
286 for (uint32_t i = 0; i < pTstParms->cIterations; i++)
287 {
288 /*
289 * 1. Arm the (host) ValKit ATS with the recording parameters.
290 */
291 PAUDIOTESTTONEPARMS const pToneParms = &pTstParms->TestTone;
292 rc = AudioTestSvcClientToneRecord(&pTstEnv->u.Host.AtsClValKit, pToneParms);
293 if (RT_SUCCESS(rc))
294 {
295 /*
296 * 2. Tell the guest ATS to start playback.
297 */
298 rc = AudioTestSvcClientTonePlay(&pTstEnv->u.Host.AtsClGuest, pToneParms);
299 }
300
301 if (RT_FAILURE(rc))
302 RTTestFailed(g_hTest, "Playing tone failed\n");
303 }
304
305 return rc;
306}
307
308/**
309 * @copydoc FNAUDIOTESTDESTROY
310 */
311static DECLCALLBACK(int) audioTestPlayToneDestroy(PAUDIOTESTENV pTstEnv, void *pvCtx)
312{
313 RT_NOREF(pTstEnv, pvCtx);
314
315 return VINF_SUCCESS;
316}
317
318/**
319 * @copydoc FNAUDIOTESTSETUP
320 */
321static DECLCALLBACK(int) audioTestRecordToneSetup(PAUDIOTESTENV pTstEnv, PAUDIOTESTDESC pTstDesc, PAUDIOTESTPARMS pTstParmsAcq, void **ppvCtx)
322{
323 RT_NOREF(pTstDesc, ppvCtx);
324
325 int rc = VINF_SUCCESS;
326
327 if (strlen(pTstEnv->szDev))
328 {
329 rc = audioTestDriverStackSetDevice(&pTstEnv->DrvStack, PDMAUDIODIR_IN, pTstEnv->szDev);
330 if (RT_FAILURE(rc))
331 return rc;
332 }
333
334 pTstParmsAcq->enmType = AUDIOTESTTYPE_TESTTONE_RECORD;
335 pTstParmsAcq->Props = pTstEnv->Props;
336 pTstParmsAcq->enmDir = PDMAUDIODIR_IN;
337#ifdef DEBUG
338 pTstParmsAcq->cIterations = 1;
339#else
340 pTstParmsAcq->cIterations = RTRandU32Ex(1, 10);
341#endif
342 pTstParmsAcq->idxCurrent = 0;
343
344 return rc;
345}
346
347/**
348 * @copydoc FNAUDIOTESTEXEC
349 */
350static DECLCALLBACK(int) audioTestRecordToneExec(PAUDIOTESTENV pTstEnv, void *pvCtx, PAUDIOTESTPARMS pTstParms)
351{
352 RT_NOREF(pvCtx);
353
354 int rc = VINF_SUCCESS;
355
356 for (uint32_t i = 0; i < pTstParms->cIterations; i++)
357 {
358 pTstParms->TestTone.Props = pTstParms->Props;
359#ifdef DEBUG_andy
360 pTstParms->TestTone.msDuration = RTRandU32Ex(50 /* ms */, 2000);
361#else
362 pTstParms->TestTone.msDuration = RTRandU32Ex(50 /* ms */, RT_MS_30SEC); /** @todo Record even longer? */
363#endif
364 /*
365 * 1. Arm the (host) ValKit ATS with the playback parameters.
366 */
367 rc = AudioTestSvcClientTonePlay(&pTstEnv->u.Host.AtsClValKit, &pTstParms->TestTone);
368 if (RT_SUCCESS(rc))
369 {
370 /*
371 * 2. Tell the guest ATS to start recording.
372 */
373 rc = AudioTestSvcClientToneRecord(&pTstEnv->u.Host.AtsClGuest, &pTstParms->TestTone);
374 }
375
376 if (RT_FAILURE(rc))
377 RTTestFailed(g_hTest, "Recording tone failed\n");
378 }
379
380 return rc;
381}
382
383/**
384 * @copydoc FNAUDIOTESTDESTROY
385 */
386static DECLCALLBACK(int) audioTestRecordToneDestroy(PAUDIOTESTENV pTstEnv, void *pvCtx)
387{
388 RT_NOREF(pTstEnv, pvCtx);
389
390 return VINF_SUCCESS;
391}
392
393
394/*********************************************************************************************************************************
395* Test execution *
396*********************************************************************************************************************************/
397
398/** Test definition table. */
399AUDIOTESTDESC g_aTests[] =
400{
401 /* pszTest fExcluded pfnSetup */
402 { "PlayTone", false, audioTestPlayToneSetup, audioTestPlayToneExec, audioTestPlayToneDestroy },
403 { "RecordTone", false, audioTestRecordToneSetup, audioTestRecordToneExec, audioTestRecordToneDestroy }
404};
405/** Number of tests defined. */
406unsigned g_cTests = RT_ELEMENTS(g_aTests);
407
408/**
409 * Runs one specific audio test.
410 *
411 * @returns VBox status code.
412 * @param pTstEnv Test environment to use for running the test.
413 * @param pTstDesc Test to run.
414 * @param uSeq Test sequence # in case there are more tests.
415 */
416static int audioTestOne(PAUDIOTESTENV pTstEnv, PAUDIOTESTDESC pTstDesc, unsigned uSeq)
417{
418 RT_NOREF(uSeq);
419
420 int rc;
421
422 AUDIOTESTPARMS TstParms;
423 audioTestParmsInit(&TstParms);
424
425 RTTestSub(g_hTest, pTstDesc->pszName);
426
427 if (pTstDesc->fExcluded)
428 {
429 RTTestSkipped(g_hTest, "Excluded from list");
430 return VINF_SUCCESS;
431 }
432
433 void *pvCtx = NULL; /* Test-specific opaque context. Optional and can be NULL. */
434
435 if (pTstDesc->pfnSetup)
436 {
437 rc = pTstDesc->pfnSetup(pTstEnv, pTstDesc, &TstParms, &pvCtx);
438 if (RT_FAILURE(rc))
439 {
440 RTTestFailed(g_hTest, "Test setup failed with %Rrc\n", rc);
441 return rc;
442 }
443 }
444
445 RTTestPrintf(g_hTest, RTTESTLVL_ALWAYS, "Test #%u: %RU32 iterations\n", uSeq, TstParms.cIterations);
446
447 AssertPtr(pTstDesc->pfnExec);
448 rc = pTstDesc->pfnExec(pTstEnv, pvCtx, &TstParms);
449 if (RT_FAILURE(rc))
450 RTTestFailed(g_hTest, "Test failed with %Rrc\n", rc);
451
452 RTTestSubDone(g_hTest);
453
454 if (pTstDesc->pfnDestroy)
455 {
456 int rc2 = pTstDesc->pfnDestroy(pTstEnv, pvCtx);
457 if (RT_SUCCESS(rc))
458 rc = rc2;
459
460 if (RT_FAILURE(rc2))
461 RTTestFailed(g_hTest, "Test destruction failed with %Rrc\n", rc2);
462 }
463
464 audioTestParmsDestroy(&TstParms);
465
466 return rc;
467}
468
469/**
470 * Runs all specified tests in a row.
471 *
472 * @returns VBox status code.
473 * @param pTstEnv Test environment to use for running all tests.
474 */
475int audioTestWorker(PAUDIOTESTENV pTstEnv)
476{
477 int rc = VINF_SUCCESS;
478
479 if (pTstEnv->enmMode == AUDIOTESTMODE_GUEST)
480 {
481 RTTestPrintf(g_hTest, RTTESTLVL_ALWAYS, "Guest ATS running\n");
482
483 while (!g_fTerminate)
484 RTThreadSleep(100);
485
486 RTTestPrintf(g_hTest, RTTESTLVL_ALWAYS, "Shutting down guest ATS ...\n");
487
488 int rc2 = AudioTestSvcShutdown(&pTstEnv->u.Guest.Srv);
489 if (RT_SUCCESS(rc))
490 rc = rc2;
491
492 RTTestPrintf(g_hTest, RTTESTLVL_ALWAYS, "Guest ATS shutdown complete\n");
493 }
494 else if (pTstEnv->enmMode == AUDIOTESTMODE_HOST)
495 {
496 RTTestPrintf(g_hTest, RTTESTLVL_DEBUG, "Using tag '%s'\n", pTstEnv->szTag);
497
498 rc = AudioTestSvcClientTestSetBegin(&pTstEnv->u.Host.AtsClValKit, pTstEnv->szTag);
499 if (RT_SUCCESS(rc))
500 rc = AudioTestSvcClientTestSetBegin(&pTstEnv->u.Host.AtsClGuest, pTstEnv->szTag);
501
502 if (RT_SUCCESS(rc))
503 {
504 unsigned uSeq = 0;
505 for (unsigned i = 0; i < RT_ELEMENTS(g_aTests); i++)
506 {
507 int rc2 = audioTestOne(pTstEnv, &g_aTests[i], uSeq);
508 if (RT_SUCCESS(rc))
509 rc = rc2;
510
511 if (!g_aTests[i].fExcluded)
512 uSeq++;
513
514 if (g_fTerminate)
515 break;
516 }
517
518 int rc2 = AudioTestSvcClientTestSetEnd(&pTstEnv->u.Host.AtsClGuest, pTstEnv->szTag);
519 if (RT_SUCCESS(rc))
520 rc = rc2;
521
522 rc2 = AudioTestSvcClientTestSetEnd(&pTstEnv->u.Host.AtsClValKit, pTstEnv->szTag);
523 if (RT_SUCCESS(rc))
524 rc = rc2;
525
526 if (RT_SUCCESS(rc))
527 {
528 /*
529 * Download guest + Validation Kit audio driver test sets to our output directory.
530 */
531 char szFileName[RTPATH_MAX];
532 if (RTStrPrintf2(szFileName, sizeof(szFileName), "%s-guest.tar.gz", pTstEnv->szTag))
533 {
534 rc = RTPathJoin(pTstEnv->u.Host.szPathTestSetGuest, sizeof(pTstEnv->u.Host.szPathTestSetGuest),
535 pTstEnv->szPathOut, szFileName);
536 if (RT_SUCCESS(rc))
537 {
538 if (RTStrPrintf2(szFileName, sizeof(szFileName), "%s-host.tar.gz", pTstEnv->szTag))
539 {
540 rc = RTPathJoin(pTstEnv->u.Host.szPathTestSetValKit, sizeof(pTstEnv->u.Host.szPathTestSetValKit),
541 pTstEnv->szPathOut, szFileName);
542 }
543 else
544 rc = VERR_BUFFER_OVERFLOW;
545 }
546 else
547 rc = VERR_BUFFER_OVERFLOW;
548
549 if (RT_SUCCESS(rc))
550 {
551 RTTestPrintf(g_hTest, RTTESTLVL_ALWAYS, "Downloading guest test set to '%s'\n",
552 pTstEnv->u.Host.szPathTestSetGuest);
553 rc = AudioTestSvcClientTestSetDownload(&pTstEnv->u.Host.AtsClGuest,
554 pTstEnv->szTag, pTstEnv->u.Host.szPathTestSetGuest);
555 }
556
557 if (RT_SUCCESS(rc))
558 {
559 RTTestPrintf(g_hTest, RTTESTLVL_ALWAYS, "Downloading host test set to '%s'\n",
560 pTstEnv->u.Host.szPathTestSetValKit);
561 rc = AudioTestSvcClientTestSetDownload(&pTstEnv->u.Host.AtsClValKit,
562 pTstEnv->szTag, pTstEnv->u.Host.szPathTestSetValKit);
563 }
564 }
565 else
566 rc = VERR_BUFFER_OVERFLOW;
567
568 if ( RT_SUCCESS(rc)
569 && !pTstEnv->fSkipVerify)
570 {
571 rc = audioVerifyOne(pTstEnv->u.Host.szPathTestSetGuest, pTstEnv->u.Host.szPathTestSetValKit);
572 }
573 else
574 RTTestPrintf(g_hTest, RTTESTLVL_ALWAYS, "Verification skipped\n");
575
576 RTFileDelete(pTstEnv->u.Host.szPathTestSetGuest);
577 RTFileDelete(pTstEnv->u.Host.szPathTestSetValKit);
578 }
579 }
580 }
581 else
582 AssertFailed();
583
584 /* Clean up. */
585 RTDirRemove(pTstEnv->szPathTemp);
586 RTDirRemove(pTstEnv->szPathOut);
587
588 if (RT_FAILURE(rc))
589 RTTestFailed(g_hTest, "Test worker failed with %Rrc", rc);
590
591 return rc;
592}
593
594/** Option help for the 'test' command. */
595static DECLCALLBACK(const char *) audioTestCmdTestHelp(PCRTGETOPTDEF pOpt)
596{
597 switch (pOpt->iShort)
598 {
599 case 'a': return "Exclude all tests from the list (useful to enable single tests later with --include)";
600 case 'b': return "The audio backend to use";
601 case 'd': return "Go via DrvAudio instead of directly interfacing with the backend";
602 case 'e': return "Exclude the given test id from the list";
603 case 'i': return "Include the given test id in the list";
604 case VKAT_TEST_OPT_DEV: return "Use the specified audio device";
605 case VKAT_TEST_OPT_GUEST_ATS_ADDR: return "Address of guest ATS to connect to";
606 case VKAT_TEST_OPT_GUEST_ATS_PORT: return "Port of guest ATS to connect to [6042]";
607 case VKAT_TEST_OPT_HOST_ATS_ADDR: return "Address of host ATS to connect to";
608 case VKAT_TEST_OPT_HOST_ATS_PORT: return "Port of host ATS to connect to [6052]";
609 case VKAT_TEST_OPT_MODE: return "Specifies the test mode to use when running the tests";
610 case VKAT_TEST_OPT_NO_VERIFY: return "Skips the verification step";
611 case VKAT_TEST_OPT_OUTDIR: return "Specifies the output directory to use";
612 case VKAT_TEST_OPT_PAUSE: return "Not yet implemented";
613 case VKAT_TEST_OPT_PCM_HZ: return "Specifies the PCM Hetz (Hz) rate to use [44100]";
614 case VKAT_TEST_OPT_PCM_BIT: return "Specifies the PCM sample bits (i.e. 16) to use [16]";
615 case VKAT_TEST_OPT_PCM_CHAN: return "Specifies the number of PCM channels to use [2]";
616 case VKAT_TEST_OPT_PCM_SIGNED: return "Specifies whether to use signed (true) or unsigned (false) samples [true]";
617 case VKAT_TEST_OPT_TAG: return "Specifies the test set tag to use";
618 case VKAT_TEST_OPT_TEMPDIR: return "Specifies the temporary directory to use";
619 case VKAT_TEST_OPT_VOL: return "Specifies the audio volume (in percent, 0-100) to use";
620 default:
621 break;
622 }
623 return NULL;
624}
625
626/**
627 * Main (entry) function for the testing functionality of VKAT.
628 *
629 * @returns Program exit code.
630 * @param pGetState RTGetOpt state.
631 */
632static DECLCALLBACK(RTEXITCODE) audioTestMain(PRTGETOPTSTATE pGetState)
633{
634 AUDIOTESTENV TstEnv;
635 RT_ZERO(TstEnv);
636
637 int rc = AudioTestSvcCreate(&TstEnv.u.Guest.Srv);
638
639 const char *pszDevice = NULL; /* Custom device to use. Can be NULL if not being used. */
640 const char *pszTag = NULL; /* Custom tag to use. Can be NULL if not being used. */
641 PCPDMDRVREG pDrvReg = AudioTestGetDefaultBackend();
642 bool fWithDrvAudio = false;
643 uint8_t cPcmSampleBit = 0;
644 uint8_t cPcmChannels = 0;
645 uint32_t uPcmHz = 0;
646 bool fPcmSigned = true;
647
648 const char *pszGuestTcpAddr = NULL;
649 uint16_t uGuestTcpPort = ATS_TCP_DEF_BIND_PORT_GUEST;
650 const char *pszValKitTcpAddr = NULL;
651 uint16_t uValKitTcpPort = ATS_TCP_DEF_BIND_PORT_VALKIT;
652
653 int ch;
654 RTGETOPTUNION ValueUnion;
655 while ((ch = RTGetOpt(pGetState, &ValueUnion)))
656 {
657 switch (ch)
658 {
659 case 'a':
660 for (unsigned i = 0; i < RT_ELEMENTS(g_aTests); i++)
661 g_aTests[i].fExcluded = true;
662 break;
663
664 case 'b':
665 pDrvReg = AudioTestFindBackendOpt(ValueUnion.psz);
666 if (pDrvReg == NULL)
667 return RTEXITCODE_SYNTAX;
668 break;
669
670 case 'd':
671 fWithDrvAudio = true;
672 break;
673
674 case 'e':
675 if (ValueUnion.u32 >= RT_ELEMENTS(g_aTests))
676 return RTMsgErrorExit(RTEXITCODE_SYNTAX, "Invalid test number %u passed to --exclude", ValueUnion.u32);
677 g_aTests[ValueUnion.u32].fExcluded = true;
678 break;
679
680 case VKAT_TEST_OPT_GUEST_ATS_ADDR:
681 pszGuestTcpAddr = ValueUnion.psz;
682 break;
683
684 case VKAT_TEST_OPT_GUEST_ATS_PORT:
685 uGuestTcpPort = ValueUnion.u32;
686 break;
687
688 case VKAT_TEST_OPT_HOST_ATS_ADDR:
689 pszValKitTcpAddr = ValueUnion.psz;
690 break;
691
692 case VKAT_TEST_OPT_HOST_ATS_PORT:
693 uValKitTcpPort = ValueUnion.u32;
694 break;
695
696 case VKAT_TEST_OPT_MODE:
697 if (TstEnv.enmMode != AUDIOTESTMODE_UNKNOWN)
698 return RTMsgErrorExit(RTEXITCODE_SYNTAX, "Test mode (guest / host) already specified");
699 TstEnv.enmMode = RTStrICmp(ValueUnion.psz, "guest") == 0 ? AUDIOTESTMODE_GUEST : AUDIOTESTMODE_HOST;
700 break;
701
702 case VKAT_TEST_OPT_NO_VERIFY:
703 TstEnv.fSkipVerify = true;
704 break;
705
706 case 'i':
707 if (ValueUnion.u32 >= RT_ELEMENTS(g_aTests))
708 return RTMsgErrorExit(RTEXITCODE_SYNTAX, "Invalid test number %u passed to --include", ValueUnion.u32);
709 g_aTests[ValueUnion.u32].fExcluded = false;
710 break;
711
712 case VKAT_TEST_OPT_COUNT:
713 return RTMsgErrorExitFailure("Not yet implemented!");
714
715 case VKAT_TEST_OPT_DEV:
716 pszDevice = ValueUnion.psz;
717 break;
718
719 case VKAT_TEST_OPT_PAUSE:
720 return RTMsgErrorExitFailure("Not yet implemented!");
721
722 case VKAT_TEST_OPT_OUTDIR:
723 rc = RTStrCopy(TstEnv.szPathOut, sizeof(TstEnv.szPathOut), ValueUnion.psz);
724 if (RT_FAILURE(rc))
725 return RTMsgErrorExitFailure("Failed to copy out directory: %Rrc", rc);
726 break;
727
728 case VKAT_TEST_OPT_PCM_BIT:
729 cPcmSampleBit = ValueUnion.u8;
730 break;
731
732 case VKAT_TEST_OPT_PCM_CHAN:
733 cPcmChannels = ValueUnion.u8;
734 break;
735
736 case VKAT_TEST_OPT_PCM_HZ:
737 uPcmHz = ValueUnion.u32;
738 break;
739
740 case VKAT_TEST_OPT_PCM_SIGNED:
741 fPcmSigned = ValueUnion.f;
742 break;
743
744 case VKAT_TEST_OPT_TAG:
745 pszTag = ValueUnion.psz;
746 break;
747
748 case VKAT_TEST_OPT_TEMPDIR:
749 rc = RTStrCopy(TstEnv.szPathTemp, sizeof(TstEnv.szPathTemp), ValueUnion.psz);
750 if (RT_FAILURE(rc))
751 return RTMsgErrorExit(RTEXITCODE_FAILURE, "Temp dir invalid, rc=%Rrc", rc);
752 break;
753
754 case VKAT_TEST_OPT_VOL:
755 TstEnv.uVolumePercent = ValueUnion.u8;
756 break;
757
758 AUDIO_TEST_COMMON_OPTION_CASES(ValueUnion);
759
760 default:
761 rc = AudioTestSvcHandleOption(&TstEnv.u.Guest.Srv, ch, &ValueUnion);
762 if (RT_FAILURE(rc))
763 return RTGetOptPrintError(rc, &ValueUnion);
764 }
765 }
766
767 /*
768 * Start testing.
769 */
770 RTTestBanner(g_hTest);
771
772 /* Initialize the custom test parameters with sensible defaults if nothing else is given. */
773 PDMAudioPropsInit(&TstEnv.Props,
774 cPcmSampleBit ? cPcmSampleBit / 8 : 2 /* 16-bit */, fPcmSigned, cPcmChannels ? cPcmChannels : 2,
775 uPcmHz ? uPcmHz : 44100);
776
777 if (TstEnv.enmMode == AUDIOTESTMODE_UNKNOWN)
778 return RTMsgErrorExit(RTEXITCODE_SYNTAX, "No test mode (--mode) specified!\n");
779
780 /* For now all tests have the same test environment. */
781 rc = audioTestEnvInit(&TstEnv, pDrvReg, fWithDrvAudio);
782 if (RT_SUCCESS(rc))
783 rc = audioTestWorker(&TstEnv);
784
785 audioTestEnvDestroy(&TstEnv);
786
787 if (RT_FAILURE(rc)) /* Let us know that something went wrong in case we forgot to mention it. */
788 RTTestFailed(g_hTest, "Testing failed with %Rrc\n", rc);
789
790 /*
791 * Print summary and exit.
792 */
793 return RTTestSummaryAndDestroy(g_hTest);
794}
795
796
797const VKATCMD g_CmdTest =
798{
799 "test",
800 audioTestMain,
801 "Runs audio tests and creates an audio test set.",
802 g_aCmdTestOptions,
803 RT_ELEMENTS(g_aCmdTestOptions),
804 audioTestCmdTestHelp,
805 true /* fNeedsTransport */
806};
807
808
809/*********************************************************************************************************************************
810* Command: verify *
811*********************************************************************************************************************************/
812
813static int audioVerifyOpenTestSet(const char *pszPathSet, PAUDIOTESTSET pSet)
814{
815 int rc;
816
817 char szPathExtracted[RTPATH_MAX];
818
819 RTTestPrintf(g_hTest, RTTESTLVL_ALWAYS, "Opening test set '%s'\n", pszPathSet);
820
821 const bool fPacked = AudioTestSetIsPacked(pszPathSet);
822 if (fPacked)
823 {
824 RTTestPrintf(g_hTest, RTTESTLVL_ALWAYS, "Test set is an archive and needs to be unpacked\n");
825
826 char szPathTemp[RTPATH_MAX];
827 rc = RTPathTemp(szPathTemp, sizeof(szPathTemp));
828 if (RT_SUCCESS(rc))
829 {
830 RTTestPrintf(g_hTest, RTTESTLVL_ALWAYS, "Using temporary directory '%s'\n", szPathTemp);
831
832 rc = RTPathJoin(szPathExtracted, sizeof(szPathExtracted), szPathTemp, "vkat-testset-XXXX");
833 if (RT_SUCCESS(rc))
834 {
835 rc = RTDirCreateTemp(szPathExtracted, 0755);
836 if (RT_SUCCESS(rc))
837 {
838 RTTestPrintf(g_hTest, RTTESTLVL_ALWAYS, "Unpacking archive to '%s'\n", szPathExtracted);
839 rc = AudioTestSetUnpack(pszPathSet, szPathExtracted);
840 if (RT_SUCCESS(rc))
841 RTTestPrintf(g_hTest, RTTESTLVL_ALWAYS, "Archive successfully unpacked\n");
842 }
843 }
844 }
845 }
846 else
847 rc = VINF_SUCCESS;
848
849 if (RT_SUCCESS(rc))
850 rc = AudioTestSetOpen(pSet, fPacked ? szPathExtracted : pszPathSet);
851
852 if (RT_FAILURE(rc))
853 RTTestFailed(g_hTest, "Unable to open / unpack test set archive: %Rrc", rc);
854
855 return rc;
856}
857
858/**
859 * Verifies one test set pair.
860 *
861 * @returns VBox status code.
862 * @param pszPathSetA Absolute path to test set A.
863 * @param pszPathSetB Absolute path to test set B.
864 */
865static int audioVerifyOne(const char *pszPathSetA, const char *pszPathSetB)
866{
867 RTTestSubF(g_hTest, "Verifying");
868 RTTestPrintf(g_hTest, RTTESTLVL_ALWAYS, "Verifying test set '%s' with test set '%s'\n", pszPathSetA, pszPathSetB);
869
870 AUDIOTESTSET SetA, SetB;
871 int rc = audioVerifyOpenTestSet(pszPathSetA, &SetA);
872 if (RT_SUCCESS(rc))
873 {
874 rc = audioVerifyOpenTestSet(pszPathSetB, &SetB);
875 if (RT_SUCCESS(rc))
876 {
877 AUDIOTESTERRORDESC errDesc;
878 rc = AudioTestSetVerify(&SetA, &SetB, &errDesc);
879 if (RT_SUCCESS(rc))
880 {
881 RTTestPrintf(g_hTest, RTTESTLVL_ALWAYS, "%RU32 errors occurred while verifying\n", AudioTestErrorDescCount(&errDesc));
882 if (AudioTestErrorDescFailed(&errDesc))
883 {
884 /** @todo Use some AudioTestErrorXXX API for enumeration here later. */
885 PAUDIOTESTERRORENTRY pErrEntry;
886 RTListForEach(&errDesc.List, pErrEntry, AUDIOTESTERRORENTRY, Node)
887 RTTestFailed(g_hTest, pErrEntry->szDesc);
888 }
889 else
890 RTTestPrintf(g_hTest, RTTESTLVL_ALWAYS, "Verification successful\n");
891
892 AudioTestErrorDescDestroy(&errDesc);
893 }
894 else
895 RTTestFailed(g_hTest, "Verification failed with %Rrc", rc);
896
897 if (!g_fDrvAudioDebug) /* Don't wipe stuff when debugging. Can be useful for introspecting data. */
898 AudioTestSetWipe(&SetB);
899 AudioTestSetClose(&SetB);
900 }
901
902 if (!g_fDrvAudioDebug) /* Ditto. */
903 AudioTestSetWipe(&SetA);
904 AudioTestSetClose(&SetA);
905 }
906
907 RTTestSubDone(g_hTest);
908
909 return rc;
910}
911
912/**
913 * Main (entry) function for the verification functionality of VKAT.
914 *
915 * @returns Program exit code.
916 * @param pGetState RTGetOpt state.
917 */
918static DECLCALLBACK(RTEXITCODE) audioVerifyMain(PRTGETOPTSTATE pGetState)
919{
920 /*
921 * Parse options and process arguments.
922 */
923 const char *apszSets[2] = { NULL, NULL };
924 unsigned iTestSet = 0;
925
926 int rc;
927 RTGETOPTUNION ValueUnion;
928 while ((rc = RTGetOpt(pGetState, &ValueUnion)))
929 {
930 switch (rc)
931 {
932 case VKAT_VERIFY_OPT_TAG:
933 break;
934
935 case VINF_GETOPT_NOT_OPTION:
936 if (iTestSet == 0)
937 RTTestBanner(g_hTest);
938 if (iTestSet >= RT_ELEMENTS(apszSets))
939 return RTMsgErrorExitFailure("Only two test sets can be verified at one time");
940 apszSets[iTestSet++] = ValueUnion.psz;
941 break;
942
943 AUDIO_TEST_COMMON_OPTION_CASES(ValueUnion);
944
945 default:
946 return RTGetOptPrintError(rc, &ValueUnion);
947 }
948 }
949
950 if (!iTestSet)
951 return RTMsgErrorExitFailure("At least one test set must be specified");
952
953 /*
954 * If only test set A is given, default to the current directory
955 * for test set B.
956 */
957 char szDirCur[RTPATH_MAX];
958 if (iTestSet == 1)
959 {
960 rc = RTPathGetCurrent(szDirCur, sizeof(szDirCur));
961 if (RT_SUCCESS(rc))
962 apszSets[1] = szDirCur;
963 else
964 RTTestFailed(g_hTest, "Failed to retrieve current directory: %Rrc", rc);
965 }
966
967 if (RT_SUCCESS(rc))
968 audioVerifyOne(apszSets[0], apszSets[1]);
969
970 /*
971 * Print summary and exit.
972 */
973 return RTTestSummaryAndDestroy(g_hTest);
974}
975
976
977const VKATCMD g_CmdVerify =
978{
979 "verify",
980 audioVerifyMain,
981 "Verifies a formerly created audio test set.",
982 g_aCmdVerifyOptions,
983 RT_ELEMENTS(g_aCmdVerifyOptions),
984 NULL,
985 false /* fNeedsTransport */
986};
987
988
989/*********************************************************************************************************************************
990* Main *
991*********************************************************************************************************************************/
992
993/**
994 * Ctrl-C signal handler.
995 *
996 * This just sets g_fTerminate and hope it will be noticed soon. It restores
997 * the SIGINT action to default, so that a second Ctrl-C will have the normal
998 * effect (just in case the code doesn't respond to g_fTerminate).
999 */
1000static void audioTestSignalHandler(int iSig) RT_NOEXCEPT
1001{
1002 Assert(iSig == SIGINT); RT_NOREF(iSig);
1003 RTPrintf("Ctrl-C!\n");
1004 ASMAtomicWriteBool(&g_fTerminate, true);
1005 signal(SIGINT, SIG_DFL);
1006}
1007
1008/**
1009 * Commands.
1010 */
1011const VKATCMD *g_apCommands[] =
1012{
1013 &g_CmdTest,
1014 &g_CmdVerify,
1015 &g_CmdEnum,
1016 &g_CmdPlay,
1017 &g_CmdRec,
1018 &g_CmdSelfTest
1019};
1020
1021/**
1022 * Shows tool usage text.
1023 */
1024RTEXITCODE audioTestUsage(PRTSTREAM pStrm)
1025{
1026 RTStrmPrintf(pStrm, "usage: %s [global options] <command> [command-options]\n",
1027 RTPathFilename(RTProcExecutablePath()));
1028 RTStrmPrintf(pStrm,
1029 "\n"
1030 "Global Options:\n"
1031 " --debug-audio\n"
1032 " Enables (DrvAudio) debugging.\n"
1033 " --debug-audio-path=<path>\n"
1034 " Tells DrvAudio where to put its debug output (wav-files).\n"
1035 " -q, --quiet\n"
1036 " Sets verbosity to zero.\n"
1037 " -v, --verbose\n"
1038 " Increase verbosity.\n"
1039 " -V, --version\n"
1040 " Displays version.\n"
1041 " -h, -?, --help\n"
1042 " Displays help.\n"
1043 );
1044
1045 for (uintptr_t iCmd = 0; iCmd < RT_ELEMENTS(g_apCommands); iCmd++)
1046 {
1047 PCVKATCMD const pCmd = g_apCommands[iCmd];
1048 RTStrmPrintf(pStrm,
1049 "\n"
1050 "Command '%s':\n"
1051 " %s\n"
1052 "Options for '%s':\n",
1053 pCmd->pszCommand, pCmd->pszDesc, pCmd->pszCommand);
1054 PCRTGETOPTDEF const paOptions = pCmd->paOptions;
1055 for (unsigned i = 0; i < pCmd->cOptions; i++)
1056 {
1057 if (RT_C_IS_PRINT(paOptions[i].iShort))
1058 RTStrmPrintf(pStrm, " -%c, %s\n", paOptions[i].iShort, paOptions[i].pszLong);
1059 else
1060 RTStrmPrintf(pStrm, " %s\n", paOptions[i].pszLong);
1061
1062 const char *pszHelp = NULL;
1063 if (pCmd->pfnOptionHelp)
1064 pszHelp = pCmd->pfnOptionHelp(&paOptions[i]);
1065 if (pszHelp)
1066 RTStrmPrintf(pStrm, " %s\n", pszHelp);
1067 }
1068
1069 if (pCmd->fNeedsTransport)
1070 {
1071 for (uintptr_t iTx = 0; iTx < g_cTransports; iTx++)
1072 g_apTransports[iTx]->pfnUsage(pStrm);
1073 }
1074 }
1075
1076 RTStrmPrintf(pStrm, "\nDefault values for an option are displayed in [] if available.\n");
1077
1078 return RTEXITCODE_SUCCESS;
1079}
1080
1081/**
1082 * Shows tool version.
1083 */
1084RTEXITCODE audioTestVersion(void)
1085{
1086 RTPrintf("%s\n", RTBldCfgRevisionStr());
1087 return RTEXITCODE_SUCCESS;
1088}
1089
1090/**
1091 * Shows the logo.
1092 *
1093 * @param pStream Output stream to show logo on.
1094 */
1095void audioTestShowLogo(PRTSTREAM pStream)
1096{
1097 RTStrmPrintf(pStream, VBOX_PRODUCT " VKAT (Validation Kit Audio Test) Version " VBOX_VERSION_STRING " - r%s\n"
1098 "(C) " VBOX_C_YEAR " " VBOX_VENDOR "\n"
1099 "All rights reserved.\n\n", RTBldCfgRevisionStr());
1100}
1101
1102int main(int argc, char **argv)
1103{
1104 /*
1105 * Init IPRT and globals.
1106 */
1107 RTEXITCODE rcExit = RTTestInitAndCreate("AudioTest", &g_hTest);
1108 if (rcExit != RTEXITCODE_SUCCESS)
1109 return rcExit;
1110
1111#ifdef RT_OS_WINDOWS
1112 HRESULT hrc = CoInitializeEx(NULL /*pReserved*/, COINIT_MULTITHREADED | COINIT_SPEED_OVER_MEMORY | COINIT_DISABLE_OLE1DDE);
1113 if (FAILED(hrc))
1114 RTMsgWarning("CoInitializeEx failed: %#x", hrc);
1115#endif
1116
1117 /*
1118 * Configure release logging to go to stderr.
1119 */
1120 static const char * const g_apszLogGroups[] = VBOX_LOGGROUP_NAMES;
1121 int rc = RTLogCreate(&g_pRelLogger, RTLOGFLAGS_PREFIX_THREAD, "all.e.l", "VKAT_RELEASE_LOG",
1122 RT_ELEMENTS(g_apszLogGroups), g_apszLogGroups, RTLOGDEST_STDERR, NULL /*"vkat-release.log"*/);
1123 if (RT_SUCCESS(rc))
1124 RTLogRelSetDefaultInstance(g_pRelLogger);
1125 else
1126 RTMsgWarning("Failed to create release logger: %Rrc", rc);
1127
1128 /*
1129 * Install a Ctrl-C signal handler.
1130 */
1131#ifdef RT_OS_WINDOWS
1132 signal(SIGINT, audioTestSignalHandler);
1133#else
1134 struct sigaction sa;
1135 RT_ZERO(sa);
1136 sa.sa_handler = audioTestSignalHandler;
1137 sigaction(SIGINT, &sa, NULL);
1138#endif
1139
1140 /*
1141 * Process common options.
1142 */
1143 RTGETOPTSTATE GetState;
1144 rc = RTGetOptInit(&GetState, argc, argv, g_aCmdCommonOptions,
1145 RT_ELEMENTS(g_aCmdCommonOptions), 1 /*idxFirst*/, 0 /*fFlags - must not sort! */);
1146 AssertRCReturn(rc, RTEXITCODE_INIT);
1147
1148 RTGETOPTUNION ValueUnion;
1149 while ((rc = RTGetOpt(&GetState, &ValueUnion)) != 0)
1150 {
1151 switch (rc)
1152 {
1153 AUDIO_TEST_COMMON_OPTION_CASES(ValueUnion);
1154
1155 case VINF_GETOPT_NOT_OPTION:
1156 {
1157 for (uintptr_t iCmd = 0; iCmd < RT_ELEMENTS(g_apCommands); iCmd++)
1158 {
1159 PCVKATCMD const pCmd = g_apCommands[iCmd];
1160 if (strcmp(ValueUnion.psz, pCmd->pszCommand) == 0)
1161 {
1162 size_t cCombinedOptions = pCmd->cOptions + RT_ELEMENTS(g_aCmdCommonOptions);
1163 if (pCmd->fNeedsTransport)
1164 {
1165 for (uintptr_t iTx = 0; iTx < g_cTransports; iTx++)
1166 cCombinedOptions += g_apTransports[iTx]->cOpts;
1167 }
1168 PRTGETOPTDEF paCombinedOptions = (PRTGETOPTDEF)RTMemAlloc(cCombinedOptions * sizeof(RTGETOPTDEF));
1169 if (paCombinedOptions)
1170 {
1171 uint32_t idxOpts = 0;
1172 memcpy(paCombinedOptions, g_aCmdCommonOptions, sizeof(g_aCmdCommonOptions));
1173 idxOpts += RT_ELEMENTS(g_aCmdCommonOptions);
1174 memcpy(&paCombinedOptions[idxOpts], pCmd->paOptions, pCmd->cOptions * sizeof(RTGETOPTDEF));
1175 idxOpts += (uint32_t)pCmd->cOptions;
1176 if (pCmd->fNeedsTransport)
1177 {
1178 for (uintptr_t iTx = 0; iTx < g_cTransports; iTx++)
1179 {
1180 memcpy(&paCombinedOptions[idxOpts],
1181 g_apTransports[iTx]->paOpts, g_apTransports[iTx]->cOpts * sizeof(RTGETOPTDEF));
1182 idxOpts += (uint32_t)g_apTransports[iTx]->cOpts;
1183 }
1184 }
1185
1186 rc = RTGetOptInit(&GetState, argc, argv, paCombinedOptions, cCombinedOptions,
1187 GetState.iNext /*idxFirst*/, RTGETOPTINIT_FLAGS_OPTS_FIRST);
1188 if (RT_SUCCESS(rc))
1189 {
1190
1191 rcExit = pCmd->pfnHandler(&GetState);
1192 RTMemFree(paCombinedOptions);
1193 return rcExit;
1194 }
1195 return RTMsgErrorExitFailure("RTGetOptInit failed for '%s': %Rrc", ValueUnion.psz, rc);
1196 }
1197 return RTMsgErrorExitFailure("Out of memory!");
1198 }
1199 }
1200 RTMsgError("Unknown command '%s'!\n", ValueUnion.psz);
1201 audioTestUsage(g_pStdErr);
1202 return RTEXITCODE_SYNTAX;
1203 }
1204
1205 default:
1206 return RTGetOptPrintError(rc, &ValueUnion);
1207 }
1208 }
1209
1210 RTMsgError("No command specified!\n");
1211 audioTestUsage(g_pStdErr);
1212 return RTEXITCODE_SYNTAX;
1213}
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette