VirtualBox

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

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

Audio/ValKit: Added a debug message to the test command to conveniently reproduce the verification process with gdb. bugref:10008

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 44.0 KB
Line 
1/* $Id: vkat.cpp 90044 2021-07-06 08:59:11Z 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 = 4;
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 = RTRandU32Ex(50, 2500);
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 PAUDIOTESTTONEPARMS const pToneParms = &pTstParms->TestTone;
289
290 RTTestPrintf(g_hTest, RTTESTLVL_ALWAYS, "Test #%RU32/%RU16: Playing test tone (%RU16Hz, %RU32ms)\n",
291 pTstParms->idxCurrent, i, (uint16_t)pToneParms->dbFreqHz, pToneParms->msDuration);
292
293 /*
294 * 1. Arm the (host) ValKit ATS with the recording parameters.
295 */
296 rc = AudioTestSvcClientToneRecord(&pTstEnv->u.Host.AtsClValKit, pToneParms);
297 if (RT_SUCCESS(rc))
298 {
299 /*
300 * 2. Tell the guest ATS to start playback.
301 */
302 rc = AudioTestSvcClientTonePlay(&pTstEnv->u.Host.AtsClGuest, pToneParms);
303 }
304
305 if (RT_SUCCESS(rc))
306 {
307 if (pTstParms->cIterations)
308 RTThreadSleep(RTRandU32Ex(2000, 5000));
309 }
310 else
311 RTTestFailed(g_hTest, "Test #%RU32/%RU16: Playing tone failed\n", pTstParms->idxCurrent, i);
312 }
313
314 return rc;
315}
316
317/**
318 * @copydoc FNAUDIOTESTDESTROY
319 */
320static DECLCALLBACK(int) audioTestPlayToneDestroy(PAUDIOTESTENV pTstEnv, void *pvCtx)
321{
322 RT_NOREF(pTstEnv, pvCtx);
323
324 return VINF_SUCCESS;
325}
326
327/**
328 * @copydoc FNAUDIOTESTSETUP
329 */
330static DECLCALLBACK(int) audioTestRecordToneSetup(PAUDIOTESTENV pTstEnv, PAUDIOTESTDESC pTstDesc, PAUDIOTESTPARMS pTstParmsAcq, void **ppvCtx)
331{
332 RT_NOREF(pTstDesc, ppvCtx);
333
334 int rc = VINF_SUCCESS;
335
336 if (strlen(pTstEnv->szDev))
337 {
338 rc = audioTestDriverStackSetDevice(&pTstEnv->DrvStack, PDMAUDIODIR_IN, pTstEnv->szDev);
339 if (RT_FAILURE(rc))
340 return rc;
341 }
342
343 pTstParmsAcq->enmType = AUDIOTESTTYPE_TESTTONE_RECORD;
344 pTstParmsAcq->Props = pTstEnv->Props;
345 pTstParmsAcq->enmDir = PDMAUDIODIR_IN;
346#ifdef DEBUG
347 pTstParmsAcq->cIterations = 4;
348#else
349 pTstParmsAcq->cIterations = RTRandU32Ex(1, 10);
350#endif
351 pTstParmsAcq->idxCurrent = 0;
352
353 PAUDIOTESTTONEPARMS pToneParms = &pTstParmsAcq->TestTone;
354
355 pToneParms->Props = pTstParmsAcq->Props;
356 pToneParms->dbFreqHz = AudioTestToneGetRandomFreq();
357 pToneParms->msPrequel = 0; /** @todo Implement analyzing this first! */
358 pToneParms->Props = pTstParmsAcq->Props;
359#ifdef DEBUG_andy
360 pToneParms->msDuration = RTRandU32Ex(50 /* ms */, 2500);
361#else
362 pToneParms->msDuration = RTRandU32Ex(50 /* ms */, RT_MS_30SEC); /** @todo Record even longer? */
363#endif
364 pToneParms->msSequel = 0; /** @todo Implement analyzing this first! */
365 pToneParms->uVolumePercent = 100; /** @todo Implement analyzing this first! */
366
367 return rc;
368}
369
370/**
371 * @copydoc FNAUDIOTESTEXEC
372 */
373static DECLCALLBACK(int) audioTestRecordToneExec(PAUDIOTESTENV pTstEnv, void *pvCtx, PAUDIOTESTPARMS pTstParms)
374{
375 RT_NOREF(pvCtx);
376
377 int rc = VINF_SUCCESS;
378
379 for (uint32_t i = 0; i < pTstParms->cIterations; i++)
380 {
381 PAUDIOTESTTONEPARMS const pToneParms = &pTstParms->TestTone;
382
383 RTTestPrintf(g_hTest, RTTESTLVL_ALWAYS, "Test #%RU32/%RU16: Recording test tone (%RU16Hz, %RU32ms)\n",
384 pTstParms->idxCurrent, i, (uint16_t)pToneParms->dbFreqHz, pToneParms->msDuration);
385
386 /*
387 * 1. Arm the (host) ValKit ATS with the playback parameters.
388 */
389 rc = AudioTestSvcClientTonePlay(&pTstEnv->u.Host.AtsClValKit, &pTstParms->TestTone);
390 if (RT_SUCCESS(rc))
391 {
392 /*
393 * 2. Tell the guest ATS to start recording.
394 */
395 rc = AudioTestSvcClientToneRecord(&pTstEnv->u.Host.AtsClGuest, &pTstParms->TestTone);
396 }
397
398 if (RT_FAILURE(rc))
399 RTTestFailed(g_hTest, "Test #%RU32/%RU16: Recording tone failed\n", pTstParms->idxCurrent, i);
400
401 /* Wait a bit to let the left over audio bits being processed. */
402 if (pTstParms->cIterations)
403 RTThreadSleep(RTRandU32Ex(2000, 5000));
404 }
405
406 return rc;
407}
408
409/**
410 * @copydoc FNAUDIOTESTDESTROY
411 */
412static DECLCALLBACK(int) audioTestRecordToneDestroy(PAUDIOTESTENV pTstEnv, void *pvCtx)
413{
414 RT_NOREF(pTstEnv, pvCtx);
415
416 return VINF_SUCCESS;
417}
418
419
420/*********************************************************************************************************************************
421* Test execution *
422*********************************************************************************************************************************/
423
424/** Test definition table. */
425AUDIOTESTDESC g_aTests[] =
426{
427 /* pszTest fExcluded pfnSetup */
428 { "PlayTone", false, audioTestPlayToneSetup, audioTestPlayToneExec, audioTestPlayToneDestroy },
429 { "RecordTone", false, audioTestRecordToneSetup, audioTestRecordToneExec, audioTestRecordToneDestroy }
430};
431/** Number of tests defined. */
432unsigned g_cTests = RT_ELEMENTS(g_aTests);
433
434/**
435 * Runs one specific audio test.
436 *
437 * @returns VBox status code.
438 * @param pTstEnv Test environment to use for running the test.
439 * @param pTstDesc Test to run.
440 * @param uSeq Test sequence # in case there are more tests.
441 */
442static int audioTestOne(PAUDIOTESTENV pTstEnv, PAUDIOTESTDESC pTstDesc, unsigned uSeq)
443{
444 RT_NOREF(uSeq);
445
446 int rc;
447
448 AUDIOTESTPARMS TstParms;
449 audioTestParmsInit(&TstParms);
450
451 RTTestSub(g_hTest, pTstDesc->pszName);
452
453 if (pTstDesc->fExcluded)
454 {
455 RTTestSkipped(g_hTest, "Test #%u is excluded from list, skipping", uSeq);
456 return VINF_SUCCESS;
457 }
458
459 void *pvCtx = NULL; /* Test-specific opaque context. Optional and can be NULL. */
460
461 if (pTstDesc->pfnSetup)
462 {
463 rc = pTstDesc->pfnSetup(pTstEnv, pTstDesc, &TstParms, &pvCtx);
464 if (RT_FAILURE(rc))
465 {
466 RTTestFailed(g_hTest, "Test #%u setup failed with %Rrc\n", uSeq, rc);
467 return rc;
468 }
469 }
470
471 RTTestPrintf(g_hTest, RTTESTLVL_ALWAYS, "Test #%u (%RU32 iterations total)\n", uSeq, TstParms.cIterations);
472
473 AssertPtr(pTstDesc->pfnExec);
474 rc = pTstDesc->pfnExec(pTstEnv, pvCtx, &TstParms);
475 if (RT_FAILURE(rc))
476 RTTestFailed(g_hTest, "Test #%u failed with %Rrc\n", uSeq, rc);
477
478 RTTestSubDone(g_hTest);
479
480 if (pTstDesc->pfnDestroy)
481 {
482 int rc2 = pTstDesc->pfnDestroy(pTstEnv, pvCtx);
483 if (RT_SUCCESS(rc))
484 rc = rc2;
485
486 if (RT_FAILURE(rc2))
487 RTTestFailed(g_hTest, "Test #%u destruction failed with %Rrc\n", uSeq, rc2);
488 }
489
490 audioTestParmsDestroy(&TstParms);
491
492 return rc;
493}
494
495/**
496 * Runs all specified tests in a row.
497 *
498 * @returns VBox status code.
499 * @param pTstEnv Test environment to use for running all tests.
500 */
501int audioTestWorker(PAUDIOTESTENV pTstEnv)
502{
503 int rc = VINF_SUCCESS;
504
505 if (pTstEnv->enmMode == AUDIOTESTMODE_GUEST)
506 {
507 RTTestPrintf(g_hTest, RTTESTLVL_ALWAYS, "Guest ATS running\n");
508
509 while (!g_fTerminate)
510 RTThreadSleep(100);
511
512 RTTestPrintf(g_hTest, RTTESTLVL_ALWAYS, "Shutting down guest ATS ...\n");
513
514 int rc2 = AudioTestSvcShutdown(&pTstEnv->u.Guest.Srv);
515 if (RT_SUCCESS(rc))
516 rc = rc2;
517
518 RTTestPrintf(g_hTest, RTTESTLVL_ALWAYS, "Guest ATS shutdown complete\n");
519 }
520 else if (pTstEnv->enmMode == AUDIOTESTMODE_HOST)
521 {
522 RTTestPrintf(g_hTest, RTTESTLVL_DEBUG, "Using tag '%s'\n", pTstEnv->szTag);
523
524 rc = AudioTestSvcClientTestSetBegin(&pTstEnv->u.Host.AtsClValKit, pTstEnv->szTag);
525 if (RT_SUCCESS(rc))
526 rc = AudioTestSvcClientTestSetBegin(&pTstEnv->u.Host.AtsClGuest, pTstEnv->szTag);
527
528 if (RT_SUCCESS(rc))
529 {
530 unsigned uSeq = 0;
531 for (unsigned i = 0; i < RT_ELEMENTS(g_aTests); i++)
532 {
533 int rc2 = audioTestOne(pTstEnv, &g_aTests[i], uSeq);
534 if (RT_SUCCESS(rc))
535 rc = rc2;
536
537 if (!g_aTests[i].fExcluded)
538 uSeq++;
539
540 if (g_fTerminate)
541 break;
542 }
543
544 int rc2 = AudioTestSvcClientTestSetEnd(&pTstEnv->u.Host.AtsClGuest, pTstEnv->szTag);
545 if (RT_SUCCESS(rc))
546 rc = rc2;
547
548 rc2 = AudioTestSvcClientTestSetEnd(&pTstEnv->u.Host.AtsClValKit, pTstEnv->szTag);
549 if (RT_SUCCESS(rc))
550 rc = rc2;
551
552 if (RT_SUCCESS(rc))
553 {
554 /*
555 * Download guest + Validation Kit audio driver test sets to our output directory.
556 */
557 char szFileName[RTPATH_MAX];
558 if (RTStrPrintf2(szFileName, sizeof(szFileName), "%s-guest.tar.gz", pTstEnv->szTag))
559 {
560 rc = RTPathJoin(pTstEnv->u.Host.szPathTestSetGuest, sizeof(pTstEnv->u.Host.szPathTestSetGuest),
561 pTstEnv->szPathOut, szFileName);
562 if (RT_SUCCESS(rc))
563 {
564 if (RTStrPrintf2(szFileName, sizeof(szFileName), "%s-host.tar.gz", pTstEnv->szTag))
565 {
566 rc = RTPathJoin(pTstEnv->u.Host.szPathTestSetValKit, sizeof(pTstEnv->u.Host.szPathTestSetValKit),
567 pTstEnv->szPathOut, szFileName);
568 }
569 else
570 rc = VERR_BUFFER_OVERFLOW;
571 }
572 else
573 rc = VERR_BUFFER_OVERFLOW;
574
575 if (RT_SUCCESS(rc))
576 {
577 RTTestPrintf(g_hTest, RTTESTLVL_ALWAYS, "Downloading guest test set to '%s'\n",
578 pTstEnv->u.Host.szPathTestSetGuest);
579 rc = AudioTestSvcClientTestSetDownload(&pTstEnv->u.Host.AtsClGuest,
580 pTstEnv->szTag, pTstEnv->u.Host.szPathTestSetGuest);
581 }
582
583 if (RT_SUCCESS(rc))
584 {
585 RTTestPrintf(g_hTest, RTTESTLVL_ALWAYS, "Downloading host test set to '%s'\n",
586 pTstEnv->u.Host.szPathTestSetValKit);
587 rc = AudioTestSvcClientTestSetDownload(&pTstEnv->u.Host.AtsClValKit,
588 pTstEnv->szTag, pTstEnv->u.Host.szPathTestSetValKit);
589 }
590 }
591 else
592 rc = VERR_BUFFER_OVERFLOW;
593
594 if ( RT_SUCCESS(rc)
595 && !pTstEnv->fSkipVerify)
596 {
597 rc = audioVerifyOne(pTstEnv->u.Host.szPathTestSetGuest, pTstEnv->u.Host.szPathTestSetValKit);
598 }
599 else
600 RTTestPrintf(g_hTest, RTTESTLVL_ALWAYS, "Verification skipped\n");
601
602 RTFileDelete(pTstEnv->u.Host.szPathTestSetGuest);
603 RTFileDelete(pTstEnv->u.Host.szPathTestSetValKit);
604 }
605 }
606 }
607 else
608 AssertFailed();
609
610 /* Clean up. */
611 RTDirRemove(pTstEnv->szPathTemp);
612 RTDirRemove(pTstEnv->szPathOut);
613
614 if (RT_FAILURE(rc))
615 RTTestFailed(g_hTest, "Test worker failed with %Rrc", rc);
616
617 return rc;
618}
619
620/** Option help for the 'test' command. */
621static DECLCALLBACK(const char *) audioTestCmdTestHelp(PCRTGETOPTDEF pOpt)
622{
623 switch (pOpt->iShort)
624 {
625 case 'a': return "Exclude all tests from the list (useful to enable single tests later with --include)";
626 case 'b': return "The audio backend to use";
627 case 'd': return "Go via DrvAudio instead of directly interfacing with the backend";
628 case 'e': return "Exclude the given test id from the list";
629 case 'i': return "Include the given test id in the list";
630 case VKAT_TEST_OPT_DEV: return "Use the specified audio device";
631 case VKAT_TEST_OPT_GUEST_ATS_ADDR: return "Address of guest ATS to connect to";
632 case VKAT_TEST_OPT_GUEST_ATS_PORT: return "Port of guest ATS to connect to [6042]";
633 case VKAT_TEST_OPT_HOST_ATS_ADDR: return "Address of host ATS to connect to";
634 case VKAT_TEST_OPT_HOST_ATS_PORT: return "Port of host ATS to connect to [6052]";
635 case VKAT_TEST_OPT_MODE: return "Specifies the test mode to use when running the tests";
636 case VKAT_TEST_OPT_NO_VERIFY: return "Skips the verification step";
637 case VKAT_TEST_OPT_OUTDIR: return "Specifies the output directory to use";
638 case VKAT_TEST_OPT_PAUSE: return "Not yet implemented";
639 case VKAT_TEST_OPT_PCM_HZ: return "Specifies the PCM Hetz (Hz) rate to use [44100]";
640 case VKAT_TEST_OPT_PCM_BIT: return "Specifies the PCM sample bits (i.e. 16) to use [16]";
641 case VKAT_TEST_OPT_PCM_CHAN: return "Specifies the number of PCM channels to use [2]";
642 case VKAT_TEST_OPT_PCM_SIGNED: return "Specifies whether to use signed (true) or unsigned (false) samples [true]";
643 case VKAT_TEST_OPT_TAG: return "Specifies the test set tag to use";
644 case VKAT_TEST_OPT_TEMPDIR: return "Specifies the temporary directory to use";
645 case VKAT_TEST_OPT_VOL: return "Specifies the audio volume (in percent, 0-100) to use";
646 default:
647 break;
648 }
649 return NULL;
650}
651
652/**
653 * Main (entry) function for the testing functionality of VKAT.
654 *
655 * @returns Program exit code.
656 * @param pGetState RTGetOpt state.
657 */
658static DECLCALLBACK(RTEXITCODE) audioTestMain(PRTGETOPTSTATE pGetState)
659{
660 AUDIOTESTENV TstEnv;
661 RT_ZERO(TstEnv);
662
663 int rc = AudioTestSvcCreate(&TstEnv.u.Guest.Srv);
664
665 const char *pszDevice = NULL; /* Custom device to use. Can be NULL if not being used. */
666 const char *pszTag = NULL; /* Custom tag to use. Can be NULL if not being used. */
667 PCPDMDRVREG pDrvReg = AudioTestGetDefaultBackend();
668 bool fWithDrvAudio = false;
669 uint8_t cPcmSampleBit = 0;
670 uint8_t cPcmChannels = 0;
671 uint32_t uPcmHz = 0;
672 bool fPcmSigned = true;
673
674 const char *pszGuestTcpAddr = NULL;
675 uint16_t uGuestTcpPort = ATS_TCP_DEF_BIND_PORT_GUEST;
676 const char *pszValKitTcpAddr = NULL;
677 uint16_t uValKitTcpPort = ATS_TCP_DEF_BIND_PORT_VALKIT;
678
679 int ch;
680 RTGETOPTUNION ValueUnion;
681 while ((ch = RTGetOpt(pGetState, &ValueUnion)))
682 {
683 switch (ch)
684 {
685 case 'a':
686 for (unsigned i = 0; i < RT_ELEMENTS(g_aTests); i++)
687 g_aTests[i].fExcluded = true;
688 break;
689
690 case 'b':
691 pDrvReg = AudioTestFindBackendOpt(ValueUnion.psz);
692 if (pDrvReg == NULL)
693 return RTEXITCODE_SYNTAX;
694 break;
695
696 case 'd':
697 fWithDrvAudio = true;
698 break;
699
700 case 'e':
701 if (ValueUnion.u32 >= RT_ELEMENTS(g_aTests))
702 return RTMsgErrorExit(RTEXITCODE_SYNTAX, "Invalid test number %u passed to --exclude", ValueUnion.u32);
703 g_aTests[ValueUnion.u32].fExcluded = true;
704 break;
705
706 case VKAT_TEST_OPT_GUEST_ATS_ADDR:
707 pszGuestTcpAddr = ValueUnion.psz;
708 break;
709
710 case VKAT_TEST_OPT_GUEST_ATS_PORT:
711 uGuestTcpPort = ValueUnion.u32;
712 break;
713
714 case VKAT_TEST_OPT_HOST_ATS_ADDR:
715 pszValKitTcpAddr = ValueUnion.psz;
716 break;
717
718 case VKAT_TEST_OPT_HOST_ATS_PORT:
719 uValKitTcpPort = ValueUnion.u32;
720 break;
721
722 case VKAT_TEST_OPT_MODE:
723 if (TstEnv.enmMode != AUDIOTESTMODE_UNKNOWN)
724 return RTMsgErrorExit(RTEXITCODE_SYNTAX, "Test mode (guest / host) already specified");
725 TstEnv.enmMode = RTStrICmp(ValueUnion.psz, "guest") == 0 ? AUDIOTESTMODE_GUEST : AUDIOTESTMODE_HOST;
726 break;
727
728 case VKAT_TEST_OPT_NO_VERIFY:
729 TstEnv.fSkipVerify = true;
730 break;
731
732 case 'i':
733 if (ValueUnion.u32 >= RT_ELEMENTS(g_aTests))
734 return RTMsgErrorExit(RTEXITCODE_SYNTAX, "Invalid test number %u passed to --include", ValueUnion.u32);
735 g_aTests[ValueUnion.u32].fExcluded = false;
736 break;
737
738 case VKAT_TEST_OPT_COUNT:
739 return RTMsgErrorExitFailure("Not yet implemented!");
740
741 case VKAT_TEST_OPT_DEV:
742 pszDevice = ValueUnion.psz;
743 break;
744
745 case VKAT_TEST_OPT_PAUSE:
746 return RTMsgErrorExitFailure("Not yet implemented!");
747
748 case VKAT_TEST_OPT_OUTDIR:
749 rc = RTStrCopy(TstEnv.szPathOut, sizeof(TstEnv.szPathOut), ValueUnion.psz);
750 if (RT_FAILURE(rc))
751 return RTMsgErrorExitFailure("Failed to copy out directory: %Rrc", rc);
752 break;
753
754 case VKAT_TEST_OPT_PCM_BIT:
755 cPcmSampleBit = ValueUnion.u8;
756 break;
757
758 case VKAT_TEST_OPT_PCM_CHAN:
759 cPcmChannels = ValueUnion.u8;
760 break;
761
762 case VKAT_TEST_OPT_PCM_HZ:
763 uPcmHz = ValueUnion.u32;
764 break;
765
766 case VKAT_TEST_OPT_PCM_SIGNED:
767 fPcmSigned = ValueUnion.f;
768 break;
769
770 case VKAT_TEST_OPT_TAG:
771 pszTag = ValueUnion.psz;
772 break;
773
774 case VKAT_TEST_OPT_TEMPDIR:
775 rc = RTStrCopy(TstEnv.szPathTemp, sizeof(TstEnv.szPathTemp), ValueUnion.psz);
776 if (RT_FAILURE(rc))
777 return RTMsgErrorExit(RTEXITCODE_FAILURE, "Temp dir invalid, rc=%Rrc", rc);
778 break;
779
780 case VKAT_TEST_OPT_VOL:
781 TstEnv.uVolumePercent = ValueUnion.u8;
782 break;
783
784 AUDIO_TEST_COMMON_OPTION_CASES(ValueUnion);
785
786 default:
787 rc = AudioTestSvcHandleOption(&TstEnv.u.Guest.Srv, ch, &ValueUnion);
788 if (RT_FAILURE(rc))
789 return RTGetOptPrintError(rc, &ValueUnion);
790 }
791 }
792
793 /*
794 * Start testing.
795 */
796 RTTestBanner(g_hTest);
797
798 /* Initialize the custom test parameters with sensible defaults if nothing else is given. */
799 PDMAudioPropsInit(&TstEnv.Props,
800 cPcmSampleBit ? cPcmSampleBit / 8 : 2 /* 16-bit */, fPcmSigned, cPcmChannels ? cPcmChannels : 2,
801 uPcmHz ? uPcmHz : 44100);
802
803 if (TstEnv.enmMode == AUDIOTESTMODE_UNKNOWN)
804 return RTMsgErrorExit(RTEXITCODE_SYNTAX, "No test mode (--mode) specified!\n");
805
806 /* For now all tests have the same test environment. */
807 rc = audioTestEnvInit(&TstEnv, pDrvReg, fWithDrvAudio);
808 if (RT_SUCCESS(rc))
809 rc = audioTestWorker(&TstEnv);
810
811 audioTestEnvDestroy(&TstEnv);
812
813 if (RT_FAILURE(rc)) /* Let us know that something went wrong in case we forgot to mention it. */
814 RTTestFailed(g_hTest, "Testing failed with %Rrc\n", rc);
815
816 /*
817 * Print summary and exit.
818 */
819 return RTTestSummaryAndDestroy(g_hTest);
820}
821
822
823const VKATCMD g_CmdTest =
824{
825 "test",
826 audioTestMain,
827 "Runs audio tests and creates an audio test set.",
828 g_aCmdTestOptions,
829 RT_ELEMENTS(g_aCmdTestOptions),
830 audioTestCmdTestHelp,
831 true /* fNeedsTransport */
832};
833
834
835/*********************************************************************************************************************************
836* Command: verify *
837*********************************************************************************************************************************/
838
839static int audioVerifyOpenTestSet(const char *pszPathSet, PAUDIOTESTSET pSet)
840{
841 int rc;
842
843 char szPathExtracted[RTPATH_MAX];
844
845 RTTestPrintf(g_hTest, RTTESTLVL_ALWAYS, "Opening test set '%s'\n", pszPathSet);
846
847 const bool fPacked = AudioTestSetIsPacked(pszPathSet);
848 if (fPacked)
849 {
850 RTTestPrintf(g_hTest, RTTESTLVL_ALWAYS, "Test set is an archive and needs to be unpacked\n");
851
852 char szPathTemp[RTPATH_MAX];
853 rc = RTPathTemp(szPathTemp, sizeof(szPathTemp));
854 if (RT_SUCCESS(rc))
855 {
856 RTTestPrintf(g_hTest, RTTESTLVL_ALWAYS, "Using temporary directory '%s'\n", szPathTemp);
857
858 rc = RTPathJoin(szPathExtracted, sizeof(szPathExtracted), szPathTemp, "vkat-testset-XXXX");
859 if (RT_SUCCESS(rc))
860 {
861 rc = RTDirCreateTemp(szPathExtracted, 0755);
862 if (RT_SUCCESS(rc))
863 {
864 RTTestPrintf(g_hTest, RTTESTLVL_ALWAYS, "Unpacking archive to '%s'\n", szPathExtracted);
865 rc = AudioTestSetUnpack(pszPathSet, szPathExtracted);
866 if (RT_SUCCESS(rc))
867 RTTestPrintf(g_hTest, RTTESTLVL_ALWAYS, "Archive successfully unpacked\n");
868 }
869 }
870 }
871 }
872 else
873 rc = VINF_SUCCESS;
874
875 if (RT_SUCCESS(rc))
876 rc = AudioTestSetOpen(pSet, fPacked ? szPathExtracted : pszPathSet);
877
878 if (RT_FAILURE(rc))
879 RTTestFailed(g_hTest, "Unable to open / unpack test set archive: %Rrc", rc);
880
881 return rc;
882}
883
884/**
885 * Verifies one test set pair.
886 *
887 * @returns VBox status code.
888 * @param pszPathSetA Absolute path to test set A.
889 * @param pszPathSetB Absolute path to test set B.
890 */
891static int audioVerifyOne(const char *pszPathSetA, const char *pszPathSetB)
892{
893 RTTestSubF(g_hTest, "Verifying");
894 RTTestPrintf(g_hTest, RTTESTLVL_ALWAYS, "Verifying test set '%s' with test set '%s'\n", pszPathSetA, pszPathSetB);
895
896 AUDIOTESTSET SetA, SetB;
897 int rc = audioVerifyOpenTestSet(pszPathSetA, &SetA);
898 if (RT_SUCCESS(rc))
899 {
900 rc = audioVerifyOpenTestSet(pszPathSetB, &SetB);
901 if (RT_SUCCESS(rc))
902 {
903 AUDIOTESTERRORDESC errDesc;
904 rc = AudioTestSetVerify(&SetA, &SetB, &errDesc);
905 if (RT_SUCCESS(rc))
906 {
907 uint32_t const cErr = AudioTestErrorDescCount(&errDesc);
908 RTTestPrintf(g_hTest, RTTESTLVL_ALWAYS, "%RU32 errors occurred while verifying\n", cErr);
909
910 /** @todo Use some AudioTestErrorXXX API for enumeration here later. */
911 PAUDIOTESTERRORENTRY pErrEntry;
912 RTListForEach(&errDesc.List, pErrEntry, AUDIOTESTERRORENTRY, Node)
913 {
914 if (RT_FAILURE(pErrEntry->rc))
915 RTTestFailed(g_hTest, "%s\n", pErrEntry->szDesc);
916 else
917 RTTestPrintf(g_hTest, RTTESTLVL_ALWAYS, "%s\n", pErrEntry->szDesc);
918 }
919
920 if (cErr == 0)
921 RTTestPrintf(g_hTest, RTTESTLVL_ALWAYS, "Verification successful\n");
922
923 AudioTestErrorDescDestroy(&errDesc);
924 }
925 else
926 RTTestFailed(g_hTest, "Verification failed with %Rrc", rc);
927
928#ifdef DEBUG
929 if (g_fDrvAudioDebug)
930 RTTestPrintf(g_hTest, RTTESTLVL_ALWAYS,
931 "\n"
932 "Use the following command line to re-run verification in the debugger:\n"
933 "gdb --args ./VBoxAudioTest -vvvv --debug-audio verify \"%s\" \"%s\"\n",
934 SetA.szPathAbs, SetB.szPathAbs);
935#endif
936 if (!g_fDrvAudioDebug) /* Don't wipe stuff when debugging. Can be useful for introspecting data. */
937 AudioTestSetWipe(&SetB);
938 AudioTestSetClose(&SetB);
939 }
940
941 if (!g_fDrvAudioDebug) /* Ditto. */
942 AudioTestSetWipe(&SetA);
943 AudioTestSetClose(&SetA);
944 }
945
946 RTTestSubDone(g_hTest);
947
948 return rc;
949}
950
951/**
952 * Main (entry) function for the verification functionality of VKAT.
953 *
954 * @returns Program exit code.
955 * @param pGetState RTGetOpt state.
956 */
957static DECLCALLBACK(RTEXITCODE) audioVerifyMain(PRTGETOPTSTATE pGetState)
958{
959 /*
960 * Parse options and process arguments.
961 */
962 const char *apszSets[2] = { NULL, NULL };
963 unsigned iTestSet = 0;
964
965 int rc;
966 RTGETOPTUNION ValueUnion;
967 while ((rc = RTGetOpt(pGetState, &ValueUnion)))
968 {
969 switch (rc)
970 {
971 case VKAT_VERIFY_OPT_TAG:
972 break;
973
974 case VINF_GETOPT_NOT_OPTION:
975 if (iTestSet == 0)
976 RTTestBanner(g_hTest);
977 if (iTestSet >= RT_ELEMENTS(apszSets))
978 return RTMsgErrorExitFailure("Only two test sets can be verified at one time");
979 apszSets[iTestSet++] = ValueUnion.psz;
980 break;
981
982 AUDIO_TEST_COMMON_OPTION_CASES(ValueUnion);
983
984 default:
985 return RTGetOptPrintError(rc, &ValueUnion);
986 }
987 }
988
989 if (!iTestSet)
990 return RTMsgErrorExitFailure("At least one test set must be specified");
991
992 /*
993 * If only test set A is given, default to the current directory
994 * for test set B.
995 */
996 char szDirCur[RTPATH_MAX];
997 if (iTestSet == 1)
998 {
999 rc = RTPathGetCurrent(szDirCur, sizeof(szDirCur));
1000 if (RT_SUCCESS(rc))
1001 apszSets[1] = szDirCur;
1002 else
1003 RTTestFailed(g_hTest, "Failed to retrieve current directory: %Rrc", rc);
1004 }
1005
1006 if (RT_SUCCESS(rc))
1007 audioVerifyOne(apszSets[0], apszSets[1]);
1008
1009 /*
1010 * Print summary and exit.
1011 */
1012 return RTTestSummaryAndDestroy(g_hTest);
1013}
1014
1015
1016const VKATCMD g_CmdVerify =
1017{
1018 "verify",
1019 audioVerifyMain,
1020 "Verifies a formerly created audio test set.",
1021 g_aCmdVerifyOptions,
1022 RT_ELEMENTS(g_aCmdVerifyOptions),
1023 NULL,
1024 false /* fNeedsTransport */
1025};
1026
1027
1028/*********************************************************************************************************************************
1029* Main *
1030*********************************************************************************************************************************/
1031
1032/**
1033 * Ctrl-C signal handler.
1034 *
1035 * This just sets g_fTerminate and hope it will be noticed soon. It restores
1036 * the SIGINT action to default, so that a second Ctrl-C will have the normal
1037 * effect (just in case the code doesn't respond to g_fTerminate).
1038 */
1039static void audioTestSignalHandler(int iSig) RT_NOEXCEPT
1040{
1041 Assert(iSig == SIGINT); RT_NOREF(iSig);
1042 RTPrintf("Ctrl-C!\n");
1043 ASMAtomicWriteBool(&g_fTerminate, true);
1044 signal(SIGINT, SIG_DFL);
1045}
1046
1047/**
1048 * Commands.
1049 */
1050const VKATCMD *g_apCommands[] =
1051{
1052 &g_CmdTest,
1053 &g_CmdVerify,
1054 &g_CmdEnum,
1055 &g_CmdPlay,
1056 &g_CmdRec,
1057 &g_CmdSelfTest
1058};
1059
1060/**
1061 * Shows tool usage text.
1062 */
1063RTEXITCODE audioTestUsage(PRTSTREAM pStrm)
1064{
1065 RTStrmPrintf(pStrm, "usage: %s [global options] <command> [command-options]\n",
1066 RTPathFilename(RTProcExecutablePath()));
1067 RTStrmPrintf(pStrm,
1068 "\n"
1069 "Global Options:\n"
1070 " --debug-audio\n"
1071 " Enables (DrvAudio) debugging.\n"
1072 " --debug-audio-path=<path>\n"
1073 " Tells DrvAudio where to put its debug output (wav-files).\n"
1074 " -q, --quiet\n"
1075 " Sets verbosity to zero.\n"
1076 " -v, --verbose\n"
1077 " Increase verbosity.\n"
1078 " -V, --version\n"
1079 " Displays version.\n"
1080 " -h, -?, --help\n"
1081 " Displays help.\n"
1082 );
1083
1084 for (uintptr_t iCmd = 0; iCmd < RT_ELEMENTS(g_apCommands); iCmd++)
1085 {
1086 PCVKATCMD const pCmd = g_apCommands[iCmd];
1087 RTStrmPrintf(pStrm,
1088 "\n"
1089 "Command '%s':\n"
1090 " %s\n"
1091 "Options for '%s':\n",
1092 pCmd->pszCommand, pCmd->pszDesc, pCmd->pszCommand);
1093 PCRTGETOPTDEF const paOptions = pCmd->paOptions;
1094 for (unsigned i = 0; i < pCmd->cOptions; i++)
1095 {
1096 if (RT_C_IS_PRINT(paOptions[i].iShort))
1097 RTStrmPrintf(pStrm, " -%c, %s\n", paOptions[i].iShort, paOptions[i].pszLong);
1098 else
1099 RTStrmPrintf(pStrm, " %s\n", paOptions[i].pszLong);
1100
1101 const char *pszHelp = NULL;
1102 if (pCmd->pfnOptionHelp)
1103 pszHelp = pCmd->pfnOptionHelp(&paOptions[i]);
1104 if (pszHelp)
1105 RTStrmPrintf(pStrm, " %s\n", pszHelp);
1106 }
1107
1108 if (pCmd->fNeedsTransport)
1109 {
1110 for (uintptr_t iTx = 0; iTx < g_cTransports; iTx++)
1111 g_apTransports[iTx]->pfnUsage(pStrm);
1112 }
1113 }
1114
1115 RTStrmPrintf(pStrm, "\nDefault values for an option are displayed in [] if available.\n");
1116
1117 return RTEXITCODE_SUCCESS;
1118}
1119
1120/**
1121 * Shows tool version.
1122 */
1123RTEXITCODE audioTestVersion(void)
1124{
1125 RTPrintf("%s\n", RTBldCfgRevisionStr());
1126 return RTEXITCODE_SUCCESS;
1127}
1128
1129/**
1130 * Shows the logo.
1131 *
1132 * @param pStream Output stream to show logo on.
1133 */
1134void audioTestShowLogo(PRTSTREAM pStream)
1135{
1136 RTStrmPrintf(pStream, VBOX_PRODUCT " VKAT (Validation Kit Audio Test) Version " VBOX_VERSION_STRING " - r%s\n"
1137 "(C) " VBOX_C_YEAR " " VBOX_VENDOR "\n"
1138 "All rights reserved.\n\n", RTBldCfgRevisionStr());
1139}
1140
1141int main(int argc, char **argv)
1142{
1143 /*
1144 * Init IPRT and globals.
1145 */
1146 RTEXITCODE rcExit = RTTestInitAndCreate("AudioTest", &g_hTest);
1147 if (rcExit != RTEXITCODE_SUCCESS)
1148 return rcExit;
1149
1150#ifdef RT_OS_WINDOWS
1151 HRESULT hrc = CoInitializeEx(NULL /*pReserved*/, COINIT_MULTITHREADED | COINIT_SPEED_OVER_MEMORY | COINIT_DISABLE_OLE1DDE);
1152 if (FAILED(hrc))
1153 RTMsgWarning("CoInitializeEx failed: %#x", hrc);
1154#endif
1155
1156 /*
1157 * Configure release logging to go to stderr.
1158 */
1159 static const char * const g_apszLogGroups[] = VBOX_LOGGROUP_NAMES;
1160 int rc = RTLogCreate(&g_pRelLogger, RTLOGFLAGS_PREFIX_THREAD, "all.e.l", "VKAT_RELEASE_LOG",
1161 RT_ELEMENTS(g_apszLogGroups), g_apszLogGroups, RTLOGDEST_STDERR, NULL /*"vkat-release.log"*/);
1162 if (RT_SUCCESS(rc))
1163 RTLogRelSetDefaultInstance(g_pRelLogger);
1164 else
1165 RTMsgWarning("Failed to create release logger: %Rrc", rc);
1166
1167 /*
1168 * Install a Ctrl-C signal handler.
1169 */
1170#ifdef RT_OS_WINDOWS
1171 signal(SIGINT, audioTestSignalHandler);
1172#else
1173 struct sigaction sa;
1174 RT_ZERO(sa);
1175 sa.sa_handler = audioTestSignalHandler;
1176 sigaction(SIGINT, &sa, NULL);
1177#endif
1178
1179 /*
1180 * Process common options.
1181 */
1182 RTGETOPTSTATE GetState;
1183 rc = RTGetOptInit(&GetState, argc, argv, g_aCmdCommonOptions,
1184 RT_ELEMENTS(g_aCmdCommonOptions), 1 /*idxFirst*/, 0 /*fFlags - must not sort! */);
1185 AssertRCReturn(rc, RTEXITCODE_INIT);
1186
1187 RTGETOPTUNION ValueUnion;
1188 while ((rc = RTGetOpt(&GetState, &ValueUnion)) != 0)
1189 {
1190 switch (rc)
1191 {
1192 AUDIO_TEST_COMMON_OPTION_CASES(ValueUnion);
1193
1194 case VINF_GETOPT_NOT_OPTION:
1195 {
1196 for (uintptr_t iCmd = 0; iCmd < RT_ELEMENTS(g_apCommands); iCmd++)
1197 {
1198 PCVKATCMD const pCmd = g_apCommands[iCmd];
1199 if (strcmp(ValueUnion.psz, pCmd->pszCommand) == 0)
1200 {
1201 size_t cCombinedOptions = pCmd->cOptions + RT_ELEMENTS(g_aCmdCommonOptions);
1202 if (pCmd->fNeedsTransport)
1203 {
1204 for (uintptr_t iTx = 0; iTx < g_cTransports; iTx++)
1205 cCombinedOptions += g_apTransports[iTx]->cOpts;
1206 }
1207 PRTGETOPTDEF paCombinedOptions = (PRTGETOPTDEF)RTMemAlloc(cCombinedOptions * sizeof(RTGETOPTDEF));
1208 if (paCombinedOptions)
1209 {
1210 uint32_t idxOpts = 0;
1211 memcpy(paCombinedOptions, g_aCmdCommonOptions, sizeof(g_aCmdCommonOptions));
1212 idxOpts += RT_ELEMENTS(g_aCmdCommonOptions);
1213 memcpy(&paCombinedOptions[idxOpts], pCmd->paOptions, pCmd->cOptions * sizeof(RTGETOPTDEF));
1214 idxOpts += (uint32_t)pCmd->cOptions;
1215 if (pCmd->fNeedsTransport)
1216 {
1217 for (uintptr_t iTx = 0; iTx < g_cTransports; iTx++)
1218 {
1219 memcpy(&paCombinedOptions[idxOpts],
1220 g_apTransports[iTx]->paOpts, g_apTransports[iTx]->cOpts * sizeof(RTGETOPTDEF));
1221 idxOpts += (uint32_t)g_apTransports[iTx]->cOpts;
1222 }
1223 }
1224
1225 rc = RTGetOptInit(&GetState, argc, argv, paCombinedOptions, cCombinedOptions,
1226 GetState.iNext /*idxFirst*/, RTGETOPTINIT_FLAGS_OPTS_FIRST);
1227 if (RT_SUCCESS(rc))
1228 {
1229
1230 rcExit = pCmd->pfnHandler(&GetState);
1231 RTMemFree(paCombinedOptions);
1232 return rcExit;
1233 }
1234 return RTMsgErrorExitFailure("RTGetOptInit failed for '%s': %Rrc", ValueUnion.psz, rc);
1235 }
1236 return RTMsgErrorExitFailure("Out of memory!");
1237 }
1238 }
1239 RTMsgError("Unknown command '%s'!\n", ValueUnion.psz);
1240 audioTestUsage(g_pStdErr);
1241 return RTEXITCODE_SYNTAX;
1242 }
1243
1244 default:
1245 return RTGetOptPrintError(rc, &ValueUnion);
1246 }
1247 }
1248
1249 RTMsgError("No command specified!\n");
1250 audioTestUsage(g_pStdErr);
1251 return RTEXITCODE_SYNTAX;
1252}
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