VirtualBox

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

Last change on this file since 98103 was 98103, checked in by vboxsync, 2 years ago

Copyright year updates by scm.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 61.8 KB
Line 
1/* $Id: vkat.cpp 98103 2023-01-17 14:15:46Z vboxsync $ */
2/** @file
3 * Validation Kit Audio Test (VKAT) utility for testing and validating the audio stack.
4 */
5
6/*
7 * Copyright (C) 2021-2023 Oracle and/or its affiliates.
8 *
9 * This file is part of VirtualBox base platform packages, as
10 * available from https://www.virtualbox.org.
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation, in version 3 of the
15 * License.
16 *
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, see <https://www.gnu.org/licenses>.
24 *
25 * The contents of this file may alternatively be used under the terms
26 * of the Common Development and Distribution License Version 1.0
27 * (CDDL), a copy of it is provided in the "COPYING.CDDL" file included
28 * in the VirtualBox distribution, in which case the provisions of the
29 * CDDL are applicable instead of those of the GPL.
30 *
31 * You may elect to license modified versions of this file under the
32 * terms and conditions of either the GPL or the CDDL or both.
33 *
34 * SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0
35 */
36
37
38/*********************************************************************************************************************************
39* Header Files *
40*********************************************************************************************************************************/
41#define LOG_GROUP LOG_GROUP_AUDIO_TEST
42
43#include <iprt/buildconfig.h>
44#include <iprt/ctype.h>
45#include <iprt/dir.h>
46#include <iprt/errcore.h>
47#include <iprt/file.h>
48#include <iprt/initterm.h>
49#include <iprt/getopt.h>
50#include <iprt/message.h>
51#include <iprt/path.h>
52#include <iprt/process.h>
53#include <iprt/rand.h>
54#include <iprt/stream.h>
55#include <iprt/string.h>
56#include <iprt/test.h>
57
58#include <package-generated.h>
59#include "product-generated.h"
60
61#include <VBox/version.h>
62#include <VBox/log.h>
63
64#ifdef RT_OS_WINDOWS
65# include <iprt/win/windows.h> /* for CoInitializeEx and SetConsoleCtrlHandler */
66#else
67# include <signal.h>
68#endif
69
70#include "vkatInternal.h"
71
72
73/*********************************************************************************************************************************
74* Internal Functions *
75*********************************************************************************************************************************/
76static int audioVerifyOne(const char *pszPathSetA, const char *pszPathSetB, PAUDIOTESTVERIFYOPTS pOpts);
77
78
79/*********************************************************************************************************************************
80* Global Variables *
81*********************************************************************************************************************************/
82/**
83 * Backends description table.
84 *
85 * @note The first backend in the array is the default one for the platform.
86 */
87AUDIOTESTBACKENDDESC const g_aBackends[] =
88{
89#ifdef VBOX_WITH_AUDIO_PULSE
90 { &g_DrvHostPulseAudio, "pulseaudio" },
91 { &g_DrvHostPulseAudio, "pulse" },
92 { &g_DrvHostPulseAudio, "pa" },
93#endif
94/*
95 * Note: ALSA has to come second so that PulseAudio above always is the default on Linux-y OSes
96 * -- most distros are using an ALSA plugin for PulseAudio nowadays.
97 * However, some of these configurations do not seem to work by default (can't create audio streams).
98 *
99 * If PulseAudio is not available, the (optional) probing ("--probe-backends") will choose the "pure" ALSA stack instead then.
100 */
101#if defined(VBOX_WITH_AUDIO_ALSA) && defined(RT_OS_LINUX)
102 { &g_DrvHostALSAAudio, "alsa" },
103#endif
104#ifdef VBOX_WITH_AUDIO_OSS
105 { &g_DrvHostOSSAudio, "oss" },
106#endif
107#if defined(RT_OS_DARWIN)
108 { &g_DrvHostCoreAudio, "coreaudio" },
109 { &g_DrvHostCoreAudio, "core" },
110 { &g_DrvHostCoreAudio, "ca" },
111#endif
112#if defined(RT_OS_WINDOWS)
113 { &g_DrvHostAudioWas, "wasapi" },
114 { &g_DrvHostAudioWas, "was" },
115 { &g_DrvHostDSound, "directsound" },
116 { &g_DrvHostDSound, "dsound" },
117 { &g_DrvHostDSound, "ds" },
118#endif
119#ifdef VBOX_WITH_AUDIO_DEBUG
120 { &g_DrvHostDebugAudio, "debug" },
121#endif
122 { &g_DrvHostValidationKitAudio, "valkit" }
123};
124AssertCompile(sizeof(g_aBackends) > 0 /* port me */);
125/** Number of backends defined. */
126unsigned g_cBackends = RT_ELEMENTS(g_aBackends);
127
128/**
129 * Long option values for the 'test' command.
130 */
131enum
132{
133 VKAT_TEST_OPT_COUNT = 900,
134 VKAT_TEST_OPT_DEV,
135 VKAT_TEST_OPT_GUEST_ATS_ADDR,
136 VKAT_TEST_OPT_GUEST_ATS_PORT,
137 VKAT_TEST_OPT_HOST_ATS_ADDR,
138 VKAT_TEST_OPT_HOST_ATS_PORT,
139 VKAT_TEST_OPT_MODE,
140 VKAT_TEST_OPT_NO_AUDIO_OK,
141 VKAT_TEST_OPT_NO_VERIFY,
142 VKAT_TEST_OPT_OUTDIR,
143 VKAT_TEST_OPT_PAUSE,
144 VKAT_TEST_OPT_PCM_HZ,
145 VKAT_TEST_OPT_PCM_BIT,
146 VKAT_TEST_OPT_PCM_CHAN,
147 VKAT_TEST_OPT_PCM_SIGNED,
148 VKAT_TEST_OPT_PROBE_BACKENDS,
149 VKAT_TEST_OPT_TAG,
150 VKAT_TEST_OPT_TEMPDIR,
151 VKAT_TEST_OPT_VOL,
152 VKAT_TEST_OPT_TCP_BIND_ADDRESS,
153 VKAT_TEST_OPT_TCP_BIND_PORT,
154 VKAT_TEST_OPT_TCP_CONNECT_ADDRESS,
155 VKAT_TEST_OPT_TCP_CONNECT_PORT,
156 VKAT_TEST_OPT_TONE_DURATION_MS,
157 VKAT_TEST_OPT_TONE_VOL_PERCENT
158};
159
160/**
161 * Long option values for the 'verify' command.
162 */
163enum
164{
165 VKAT_VERIFY_OPT_MAX_DIFF_COUNT = 900,
166 VKAT_VERIFY_OPT_MAX_DIFF_PERCENT,
167 VKAT_VERIFY_OPT_MAX_SIZE_PERCENT,
168 VKAT_VERIFY_OPT_NORMALIZE
169};
170
171/**
172 * Common command line parameters.
173 */
174static const RTGETOPTDEF g_aCmdCommonOptions[] =
175{
176 { "--quiet", 'q', RTGETOPT_REQ_NOTHING },
177 { "--verbose", 'v', RTGETOPT_REQ_NOTHING },
178 { "--daemonize", AUDIO_TEST_OPT_CMN_DAEMONIZE, RTGETOPT_REQ_NOTHING },
179 { "--daemonized", AUDIO_TEST_OPT_CMN_DAEMONIZED, RTGETOPT_REQ_NOTHING },
180 { "--debug-audio", AUDIO_TEST_OPT_CMN_DEBUG_AUDIO_ENABLE, RTGETOPT_REQ_NOTHING },
181 { "--debug-audio-path", AUDIO_TEST_OPT_CMN_DEBUG_AUDIO_PATH, RTGETOPT_REQ_STRING },
182};
183
184/**
185 * Command line parameters for test mode.
186 */
187static const RTGETOPTDEF g_aCmdTestOptions[] =
188{
189 { "--backend", 'b', RTGETOPT_REQ_STRING },
190 { "--drvaudio", 'd', RTGETOPT_REQ_NOTHING },
191 { "--exclude", 'e', RTGETOPT_REQ_UINT32 },
192 { "--exclude-all", 'a', RTGETOPT_REQ_NOTHING },
193 { "--guest-ats-addr", VKAT_TEST_OPT_GUEST_ATS_ADDR, RTGETOPT_REQ_STRING },
194 { "--guest-ats-port", VKAT_TEST_OPT_GUEST_ATS_PORT, RTGETOPT_REQ_UINT32 },
195 { "--host-ats-address", VKAT_TEST_OPT_HOST_ATS_ADDR, RTGETOPT_REQ_STRING },
196 { "--host-ats-port", VKAT_TEST_OPT_HOST_ATS_PORT, RTGETOPT_REQ_UINT32 },
197 { "--include", 'i', RTGETOPT_REQ_UINT32 },
198 { "--outdir", VKAT_TEST_OPT_OUTDIR, RTGETOPT_REQ_STRING },
199 { "--count", VKAT_TEST_OPT_COUNT, RTGETOPT_REQ_UINT32 },
200 { "--device", VKAT_TEST_OPT_DEV, RTGETOPT_REQ_STRING },
201 { "--pause", VKAT_TEST_OPT_PAUSE, RTGETOPT_REQ_UINT32 },
202 { "--pcm-bit", VKAT_TEST_OPT_PCM_BIT, RTGETOPT_REQ_UINT8 },
203 { "--pcm-chan", VKAT_TEST_OPT_PCM_CHAN, RTGETOPT_REQ_UINT8 },
204 { "--pcm-hz", VKAT_TEST_OPT_PCM_HZ, RTGETOPT_REQ_UINT16 },
205 { "--pcm-signed", VKAT_TEST_OPT_PCM_SIGNED, RTGETOPT_REQ_BOOL },
206 { "--probe-backends", VKAT_TEST_OPT_PROBE_BACKENDS, RTGETOPT_REQ_NOTHING },
207 { "--mode", VKAT_TEST_OPT_MODE, RTGETOPT_REQ_STRING },
208 { "--no-audio-ok", VKAT_TEST_OPT_NO_AUDIO_OK, RTGETOPT_REQ_NOTHING },
209 { "--no-verify", VKAT_TEST_OPT_NO_VERIFY, RTGETOPT_REQ_NOTHING },
210 { "--tag", VKAT_TEST_OPT_TAG, RTGETOPT_REQ_STRING },
211 { "--tempdir", VKAT_TEST_OPT_TEMPDIR, RTGETOPT_REQ_STRING },
212 { "--vol", VKAT_TEST_OPT_VOL, RTGETOPT_REQ_UINT8 },
213 { "--tcp-bind-addr", VKAT_TEST_OPT_TCP_BIND_ADDRESS, RTGETOPT_REQ_STRING },
214 { "--tcp-bind-port", VKAT_TEST_OPT_TCP_BIND_PORT, RTGETOPT_REQ_UINT16 },
215 { "--tcp-connect-addr", VKAT_TEST_OPT_TCP_CONNECT_ADDRESS, RTGETOPT_REQ_STRING },
216 { "--tcp-connect-port", VKAT_TEST_OPT_TCP_CONNECT_PORT, RTGETOPT_REQ_UINT16 },
217 { "--tone-duration", VKAT_TEST_OPT_TONE_DURATION_MS, RTGETOPT_REQ_UINT32 },
218 { "--tone-vol", VKAT_TEST_OPT_TONE_VOL_PERCENT, RTGETOPT_REQ_UINT8 }
219};
220
221/**
222 * Command line parameters for verification mode.
223 */
224static const RTGETOPTDEF g_aCmdVerifyOptions[] =
225{
226 { "--max-diff-count", VKAT_VERIFY_OPT_MAX_DIFF_COUNT, RTGETOPT_REQ_UINT32 },
227 { "--max-diff-percent", VKAT_VERIFY_OPT_MAX_DIFF_PERCENT, RTGETOPT_REQ_UINT8 },
228 { "--max-size-percent", VKAT_VERIFY_OPT_MAX_SIZE_PERCENT, RTGETOPT_REQ_UINT8 },
229 { "--normalize", VKAT_VERIFY_OPT_NORMALIZE, RTGETOPT_REQ_BOOL }
230};
231
232/** Terminate ASAP if set. Set on Ctrl-C. */
233bool volatile g_fTerminate = false;
234/** The release logger. */
235PRTLOGGER g_pRelLogger = NULL;
236/** The test handle. */
237RTTEST g_hTest;
238/** The current verbosity level. */
239unsigned g_uVerbosity = 0;
240/** DrvAudio: Enable debug (or not). */
241bool g_fDrvAudioDebug = false;
242/** DrvAudio: The debug output path. */
243const char *g_pszDrvAudioDebug = NULL;
244
245
246/**
247 * Get default backend.
248 */
249PCPDMDRVREG AudioTestGetDefaultBackend(void)
250{
251 return g_aBackends[0].pDrvReg;
252}
253
254
255/**
256 * Helper for handling --backend options.
257 *
258 * @returns Pointer to the specified backend, NULL if not found (error
259 * displayed).
260 * @param pszBackend The backend option value.
261 */
262PCPDMDRVREG AudioTestFindBackendOpt(const char *pszBackend)
263{
264 for (uintptr_t i = 0; i < RT_ELEMENTS(g_aBackends); i++)
265 if ( strcmp(pszBackend, g_aBackends[i].pszName) == 0
266 || strcmp(pszBackend, g_aBackends[i].pDrvReg->szName) == 0)
267 return g_aBackends[i].pDrvReg;
268 RTMsgError("Unknown backend: '%s'", pszBackend);
269 return NULL;
270}
271
272
273/*********************************************************************************************************************************
274* Test callbacks *
275*********************************************************************************************************************************/
276
277/**
278 * @copydoc FNAUDIOTESTSETUP
279 */
280static DECLCALLBACK(int) audioTestPlayToneSetup(PAUDIOTESTENV pTstEnv, PAUDIOTESTDESC pTstDesc, PAUDIOTESTPARMS pTstParmsAcq, void **ppvCtx)
281{
282 RT_NOREF(pTstDesc, ppvCtx);
283
284 int rc = VINF_SUCCESS;
285
286 if (strlen(pTstEnv->szDev))
287 {
288 rc = audioTestDriverStackSetDevice(pTstEnv->pDrvStack, PDMAUDIODIR_OUT, pTstEnv->szDev);
289 if (RT_FAILURE(rc))
290 return rc;
291 }
292
293 pTstParmsAcq->enmType = AUDIOTESTTYPE_TESTTONE_PLAY;
294 pTstParmsAcq->enmDir = PDMAUDIODIR_OUT;
295
296 pTstParmsAcq->TestTone = pTstEnv->ToneParms;
297
298 pTstParmsAcq->TestTone.Hdr.idxTest = pTstEnv->idxTest; /* Assign unique test ID. */
299
300 return rc;
301}
302
303/**
304 * @copydoc FNAUDIOTESTEXEC
305 */
306static DECLCALLBACK(int) audioTestPlayToneExec(PAUDIOTESTENV pTstEnv, void *pvCtx, PAUDIOTESTPARMS pTstParms)
307{
308 RT_NOREF(pvCtx);
309
310 int rc = VINF_SUCCESS;
311
312 PAUDIOTESTTONEPARMS const pToneParms = &pTstParms->TestTone;
313
314 uint32_t const idxTest = pToneParms->Hdr.idxTest;
315
316 RTTIMESPEC NowTimeSpec;
317 RTTimeExplode(&pToneParms->Hdr.tsCreated, RTTimeNow(&NowTimeSpec));
318
319 RTTestPrintf(g_hTest, RTTESTLVL_ALWAYS, "Test #%RU32: Playing test tone (%RU16Hz, %RU32ms)\n",
320 idxTest, (uint16_t)pToneParms->dbFreqHz, pToneParms->msDuration);
321
322 /*
323 * 1. Arm the (host) ValKit ATS with the recording parameters.
324 */
325 RTTestPrintf(g_hTest, RTTESTLVL_ALWAYS,
326 "Test #%RU32: Telling ValKit audio driver on host to record new tone ...\n", idxTest);
327
328 rc = AudioTestSvcClientToneRecord(&pTstEnv->u.Host.AtsClValKit, pToneParms);
329 if (RT_SUCCESS(rc))
330 {
331 /* Give the Validaiton Kit audio driver on the host a bit of time to register / arming the new test. */
332 RTThreadSleep(5000); /* Fudge factor. */
333
334 /*
335 * 2. Tell VKAT on guest to start playback.
336 */
337 RTTestPrintf(g_hTest, RTTESTLVL_ALWAYS, "Test #%RU32: Telling VKAT on guest to play tone ...\n", idxTest);
338
339 rc = AudioTestSvcClientTonePlay(&pTstEnv->u.Host.AtsClGuest, pToneParms);
340 if (RT_FAILURE(rc))
341 RTTestFailed(g_hTest, "Test #%RU32: AudioTestSvcClientTonePlay() failed with %Rrc\n", idxTest, rc);
342 }
343 else
344 RTTestFailed(g_hTest, "Test #%RU32: AudioTestSvcClientToneRecord() failed with %Rrc\n", idxTest, rc);
345
346 if (RT_SUCCESS(rc))
347 {
348 RTTestPrintf(g_hTest, RTTESTLVL_ALWAYS, "Test #%RU32: Playing tone done\n", idxTest);
349
350 /* Give the audio stack a random amount of time for draining data before the next iteration. */
351 if (pTstEnv->cIterations > 1)
352 RTThreadSleep(RTRandU32Ex(2000, 5000)); /** @todo Implement some dedicated ATS command for this? */
353 }
354
355 if (RT_FAILURE(rc))
356 RTTestFailed(g_hTest, "Test #%RU32: Playing test tone failed with %Rrc\n", idxTest, rc);
357
358 return rc;
359}
360
361/**
362 * @copydoc FNAUDIOTESTDESTROY
363 */
364static DECLCALLBACK(int) audioTestPlayToneDestroy(PAUDIOTESTENV pTstEnv, void *pvCtx)
365{
366 RT_NOREF(pTstEnv, pvCtx);
367
368 return VINF_SUCCESS;
369}
370
371/**
372 * @copydoc FNAUDIOTESTSETUP
373 */
374static DECLCALLBACK(int) audioTestRecordToneSetup(PAUDIOTESTENV pTstEnv, PAUDIOTESTDESC pTstDesc, PAUDIOTESTPARMS pTstParmsAcq, void **ppvCtx)
375{
376 RT_NOREF(pTstDesc, ppvCtx);
377
378 int rc = VINF_SUCCESS;
379
380 if (strlen(pTstEnv->szDev))
381 {
382 rc = audioTestDriverStackSetDevice(pTstEnv->pDrvStack, PDMAUDIODIR_IN, pTstEnv->szDev);
383 if (RT_FAILURE(rc))
384 return rc;
385 }
386
387 pTstParmsAcq->enmType = AUDIOTESTTYPE_TESTTONE_RECORD;
388 pTstParmsAcq->enmDir = PDMAUDIODIR_IN;
389
390 pTstParmsAcq->TestTone = pTstEnv->ToneParms;
391
392 pTstParmsAcq->TestTone.Hdr.idxTest = pTstEnv->idxTest; /* Assign unique test ID. */
393
394 return rc;
395}
396
397/**
398 * @copydoc FNAUDIOTESTEXEC
399 */
400static DECLCALLBACK(int) audioTestRecordToneExec(PAUDIOTESTENV pTstEnv, void *pvCtx, PAUDIOTESTPARMS pTstParms)
401{
402 RT_NOREF(pvCtx);
403
404 int rc = VINF_SUCCESS;
405
406 PAUDIOTESTTONEPARMS const pToneParms = &pTstParms->TestTone;
407
408 uint32_t const idxTest = pToneParms->Hdr.idxTest;
409
410 RTTIMESPEC NowTimeSpec;
411 RTTimeExplode(&pToneParms->Hdr.tsCreated, RTTimeNow(&NowTimeSpec));
412
413 RTTestPrintf(g_hTest, RTTESTLVL_ALWAYS, "Test #%RU32: Recording test tone (%RU16Hz, %RU32ms)\n",
414 idxTest, (uint16_t)pToneParms->dbFreqHz, pToneParms->msDuration);
415
416 /*
417 * 1. Arm the (host) ValKit ATS with the playback parameters.
418 */
419 RTTestPrintf(g_hTest, RTTESTLVL_ALWAYS,
420 "Test #%RU32: Telling ValKit audio driver on host to inject recording data ...\n", idxTest);
421
422 rc = AudioTestSvcClientTonePlay(&pTstEnv->u.Host.AtsClValKit, &pTstParms->TestTone);
423 if (RT_SUCCESS(rc))
424 {
425 /*
426 * 2. Tell the guest ATS to start recording.
427 */
428 RTTestPrintf(g_hTest, RTTESTLVL_ALWAYS, "Test #%RU32: Telling VKAT on guest to record audio ...\n", idxTest);
429
430 rc = AudioTestSvcClientToneRecord(&pTstEnv->u.Host.AtsClGuest, &pTstParms->TestTone);
431 if (RT_FAILURE(rc))
432 RTTestFailed(g_hTest, "Test #%RU32: AudioTestSvcClientToneRecord() failed with %Rrc\n", idxTest, rc);
433 }
434 else
435 RTTestFailed(g_hTest, "Test #%RU32: AudioTestSvcClientTonePlay() failed with %Rrc\n", idxTest, rc);
436
437 if (RT_SUCCESS(rc))
438 {
439 /* Wait a bit to let the left over audio bits being processed. */
440 if (pTstEnv->cIterations > 1)
441 RTThreadSleep(RTRandU32Ex(2000, 5000)); /** @todo Implement some dedicated ATS command for this? */
442 }
443
444 if (RT_FAILURE(rc))
445 RTTestFailed(g_hTest, "Test #%RU32: Recording test tone failed with %Rrc\n", idxTest, rc);
446
447 return rc;
448}
449
450/**
451 * @copydoc FNAUDIOTESTDESTROY
452 */
453static DECLCALLBACK(int) audioTestRecordToneDestroy(PAUDIOTESTENV pTstEnv, void *pvCtx)
454{
455 RT_NOREF(pTstEnv, pvCtx);
456
457 return VINF_SUCCESS;
458}
459
460
461/*********************************************************************************************************************************
462* Test execution *
463*********************************************************************************************************************************/
464
465/** Test definition table. */
466AUDIOTESTDESC g_aTests[] =
467{
468 /* pszTest fExcluded pfnSetup */
469 { "PlayTone", false, audioTestPlayToneSetup, audioTestPlayToneExec, audioTestPlayToneDestroy },
470 { "RecordTone", false, audioTestRecordToneSetup, audioTestRecordToneExec, audioTestRecordToneDestroy }
471};
472/** Number of tests defined. */
473unsigned g_cTests = RT_ELEMENTS(g_aTests);
474
475/**
476 * Runs one specific audio test.
477 *
478 * @returns VBox status code.
479 * @param pTstEnv Test environment to use for running the test.
480 * @param pTstDesc Test to run.
481 */
482static int audioTestOne(PAUDIOTESTENV pTstEnv, PAUDIOTESTDESC pTstDesc)
483{
484 int rc = VINF_SUCCESS;
485
486 AUDIOTESTPARMS TstParms;
487 audioTestParmsInit(&TstParms);
488
489 RTTestSub(g_hTest, pTstDesc->pszName);
490
491 if (pTstDesc->fExcluded)
492 {
493 RTTestSkipped(g_hTest, "Test #%RU32 is excluded from list, skipping", pTstEnv->idxTest);
494 return VINF_SUCCESS;
495 }
496
497 pTstEnv->cIterations = pTstEnv->cIterations == 0 ? RTRandU32Ex(1, 10) : pTstEnv->cIterations;
498
499 RTTestPrintf(g_hTest, RTTESTLVL_ALWAYS, "Test #%RU32 (%RU32 iterations total)\n", pTstEnv->idxTest, pTstEnv->cIterations);
500
501 void *pvCtx = NULL; /* Test-specific opaque context. Optional and can be NULL. */
502
503 AssertPtr(pTstDesc->pfnExec);
504 for (uint32_t i = 0; i < pTstEnv->cIterations; i++)
505 {
506 int rc2;
507
508 if (pTstDesc->pfnSetup)
509 {
510 rc2 = pTstDesc->pfnSetup(pTstEnv, pTstDesc, &TstParms, &pvCtx);
511 if (RT_FAILURE(rc2))
512 RTTestFailed(g_hTest, "Test #%RU32 setup failed with %Rrc\n", pTstEnv->idxTest, rc2);
513 }
514 else
515 rc2 = VINF_SUCCESS;
516
517 if (RT_SUCCESS(rc2))
518 {
519 AssertPtrBreakStmt(pTstDesc->pfnExec, VERR_INVALID_POINTER);
520 rc2 = pTstDesc->pfnExec(pTstEnv, pvCtx, &TstParms);
521 if (RT_FAILURE(rc2))
522 RTTestFailed(g_hTest, "Test #%RU32 execution failed with %Rrc\n", pTstEnv->idxTest, rc2);
523 }
524
525 if (pTstDesc->pfnDestroy)
526 {
527 rc2 = pTstDesc->pfnDestroy(pTstEnv, pvCtx);
528 if (RT_FAILURE(rc2))
529 RTTestFailed(g_hTest, "Test #%RU32 destruction failed with %Rrc\n", pTstEnv->idxTest, rc2);
530 }
531
532 if (RT_SUCCESS(rc))
533 rc = rc2;
534
535 /* Keep going. */
536 pTstEnv->idxTest++;
537 }
538
539 RTTestSubDone(g_hTest);
540
541 audioTestParmsDestroy(&TstParms);
542
543 return rc;
544}
545
546/**
547 * Runs all specified tests in a row.
548 *
549 * @returns VBox status code.
550 * @param pTstEnv Test environment to use for running all tests.
551 */
552int audioTestWorker(PAUDIOTESTENV pTstEnv)
553{
554 int rc = VINF_SUCCESS;
555
556 if (pTstEnv->enmMode == AUDIOTESTMODE_GUEST)
557 {
558 RTTestPrintf(g_hTest, RTTESTLVL_ALWAYS, "Guest ATS running\n");
559
560 while (!g_fTerminate)
561 RTThreadSleep(100);
562
563 RTTestPrintf(g_hTest, RTTESTLVL_ALWAYS, "Shutting down guest ATS ...\n");
564
565 int rc2 = AudioTestSvcStop(pTstEnv->pSrv);
566 if (RT_SUCCESS(rc))
567 rc = rc2;
568
569 RTTestPrintf(g_hTest, RTTESTLVL_ALWAYS, "Guest ATS shutdown complete\n");
570 }
571 else if (pTstEnv->enmMode == AUDIOTESTMODE_HOST)
572 {
573 RTTestPrintf(g_hTest, RTTESTLVL_ALWAYS, "Using tag '%s'\n", pTstEnv->szTag);
574
575 RTTestPrintf(g_hTest, RTTESTLVL_ALWAYS, "Telling ValKit audio driver on host to begin a new test set ...\n");
576 rc = AudioTestSvcClientTestSetBegin(&pTstEnv->u.Host.AtsClValKit, pTstEnv->szTag);
577 if (RT_SUCCESS(rc))
578 {
579 RTTestPrintf(g_hTest, RTTESTLVL_ALWAYS, "Telling VKAT on guest to begin a new test set ...\n");
580 rc = AudioTestSvcClientTestSetBegin(&pTstEnv->u.Host.AtsClGuest, pTstEnv->szTag);
581 if (RT_FAILURE(rc))
582 RTTestPrintf(g_hTest, RTTESTLVL_ALWAYS,
583 "Beginning test set on guest failed with %Rrc\n", rc);
584 }
585 else
586 RTTestPrintf(g_hTest, RTTESTLVL_ALWAYS,
587 "Beginning test set on host (Validation Kit audio driver) failed with %Rrc\n", rc);
588
589 if (RT_SUCCESS(rc))
590 {
591 for (unsigned i = 0; i < RT_ELEMENTS(g_aTests); i++)
592 {
593 int rc2 = audioTestOne(pTstEnv, &g_aTests[i]);
594 if (RT_SUCCESS(rc))
595 rc = rc2;
596
597 if (g_fTerminate)
598 break;
599 }
600
601 if (RT_SUCCESS(rc))
602 {
603 /** @todo Fudge! */
604 RTMSINTERVAL const msWait = RTRandU32Ex(RT_MS_1SEC, RT_MS_5SEC);
605 RTTestPrintf(g_hTest, RTTESTLVL_ALWAYS,
606 "Waiting %RU32ms to let guest and the audio stack process remaining data ...\n", msWait);
607 RTThreadSleep(msWait);
608 }
609
610 RTTestPrintf(g_hTest, RTTESTLVL_ALWAYS, "Ending test set on guest ...\n");
611 int rc2 = AudioTestSvcClientTestSetEnd(&pTstEnv->u.Host.AtsClGuest, pTstEnv->szTag);
612 if (RT_FAILURE(rc2))
613 {
614 RTTestPrintf(g_hTest, RTTESTLVL_ALWAYS, "Ending test set on guest failed with %Rrc\n", rc2);
615 if (RT_SUCCESS(rc))
616 rc = rc2;
617 }
618
619 RTTestPrintf(g_hTest, RTTESTLVL_ALWAYS, "Ending test set on host (Validation Kit audio driver) ...\n");
620 rc2 = AudioTestSvcClientTestSetEnd(&pTstEnv->u.Host.AtsClValKit, pTstEnv->szTag);
621 if (RT_FAILURE(rc2))
622 {
623 RTTestPrintf(g_hTest, RTTESTLVL_ALWAYS,
624 "Ending test set on host (Validation Kit audio driver) failed with %Rrc\n", rc2);
625 if (RT_SUCCESS(rc))
626 rc = rc2;
627 }
628
629 if ( !g_fTerminate
630 && RT_SUCCESS(rc))
631 {
632 /*
633 * Download guest + Validation Kit audio driver test sets to our output directory.
634 */
635 char szFileName[RTPATH_MAX];
636 if (RTStrPrintf2(szFileName, sizeof(szFileName), "%s-guest.tar.gz", pTstEnv->szTag))
637 {
638 rc = RTPathJoin(pTstEnv->u.Host.szPathTestSetGuest, sizeof(pTstEnv->u.Host.szPathTestSetGuest),
639 pTstEnv->szPathOut, szFileName);
640 if (RT_SUCCESS(rc))
641 {
642 if (RTStrPrintf2(szFileName, sizeof(szFileName), "%s-host.tar.gz", pTstEnv->szTag))
643 {
644 rc = RTPathJoin(pTstEnv->u.Host.szPathTestSetValKit, sizeof(pTstEnv->u.Host.szPathTestSetValKit),
645 pTstEnv->szPathOut, szFileName);
646 }
647 else
648 rc = VERR_BUFFER_OVERFLOW;
649 }
650 else
651 rc = VERR_BUFFER_OVERFLOW;
652
653 if (RT_SUCCESS(rc))
654 {
655 RTTestPrintf(g_hTest, RTTESTLVL_ALWAYS, "Downloading guest test set to '%s'\n",
656 pTstEnv->u.Host.szPathTestSetGuest);
657 rc = AudioTestSvcClientTestSetDownload(&pTstEnv->u.Host.AtsClGuest,
658 pTstEnv->szTag, pTstEnv->u.Host.szPathTestSetGuest);
659 }
660
661 if (RT_SUCCESS(rc))
662 {
663 RTTestPrintf(g_hTest, RTTESTLVL_ALWAYS, "Downloading host test set to '%s'\n",
664 pTstEnv->u.Host.szPathTestSetValKit);
665 rc = AudioTestSvcClientTestSetDownload(&pTstEnv->u.Host.AtsClValKit,
666 pTstEnv->szTag, pTstEnv->u.Host.szPathTestSetValKit);
667 }
668 }
669 else
670 rc = VERR_BUFFER_OVERFLOW;
671
672 if ( RT_SUCCESS(rc)
673 && !pTstEnv->fSkipVerify)
674 {
675 rc = audioVerifyOne(pTstEnv->u.Host.szPathTestSetGuest, pTstEnv->u.Host.szPathTestSetValKit, NULL /* pOpts */);
676 }
677 else
678 RTTestPrintf(g_hTest, RTTESTLVL_ALWAYS, "Verification skipped\n");
679
680 if (!pTstEnv->fSkipVerify)
681 {
682 RTFileDelete(pTstEnv->u.Host.szPathTestSetGuest);
683 RTFileDelete(pTstEnv->u.Host.szPathTestSetValKit);
684 }
685 else
686 RTTestPrintf(g_hTest, RTTESTLVL_ALWAYS, "Leaving test set files behind\n");
687 }
688 }
689 }
690 else
691 rc = VERR_NOT_IMPLEMENTED;
692
693 /* Clean up. */
694 RTDirRemove(pTstEnv->szPathTemp);
695 RTDirRemove(pTstEnv->szPathOut);
696
697 if (RT_FAILURE(rc))
698 RTTestFailed(g_hTest, "Test worker failed with %Rrc", rc);
699
700 return rc;
701}
702
703/** Option help for the 'test' command. */
704static DECLCALLBACK(const char *) audioTestCmdTestHelp(PCRTGETOPTDEF pOpt)
705{
706 switch (pOpt->iShort)
707 {
708 case 'a': return "Exclude all tests from the list (useful to enable single tests later with --include)";
709 case 'b': return "The audio backend to use";
710 case 'd': return "Go via DrvAudio instead of directly interfacing with the backend";
711 case 'e': return "Exclude the given test id from the list";
712 case 'i': return "Include the given test id in the list";
713 case VKAT_TEST_OPT_COUNT: return "Number of test iterations to perform for selected tests\n"
714 " Default: random number";
715 case VKAT_TEST_OPT_DEV: return "Name of the input/output device to use\n"
716 " Default: default device";
717 case VKAT_TEST_OPT_TONE_DURATION_MS: return "Test tone duration to play / record (ms)\n"
718 " Default: random duration";
719 case VKAT_TEST_OPT_TONE_VOL_PERCENT: return "Test tone volume (percent)\n"
720 " Default: 100";
721 case VKAT_TEST_OPT_GUEST_ATS_ADDR: return "Address of guest ATS to connect to\n"
722 " Default: " ATS_TCP_DEF_CONNECT_GUEST_STR;
723 case VKAT_TEST_OPT_GUEST_ATS_PORT: return "Port of guest ATS to connect to (needs NAT port forwarding)\n"
724 " Default: 6042"; /* ATS_TCP_DEF_CONNECT_PORT_GUEST */
725 case VKAT_TEST_OPT_HOST_ATS_ADDR: return "Address of host ATS to connect to\n"
726 " Default: " ATS_TCP_DEF_CONNECT_HOST_ADDR_STR;
727 case VKAT_TEST_OPT_HOST_ATS_PORT: return "Port of host ATS to connect to\n"
728 " Default: 6052"; /* ATS_TCP_DEF_BIND_PORT_VALKIT */
729 case VKAT_TEST_OPT_MODE: return "Test mode to use when running the tests";
730 case VKAT_TEST_OPT_NO_AUDIO_OK: return "Enables running without any found audio hardware (e.g. servers)";
731 case VKAT_TEST_OPT_NO_VERIFY: return "Skips the verification step";
732 case VKAT_TEST_OPT_OUTDIR: return "Output directory to use";
733 case VKAT_TEST_OPT_PAUSE: return "Not yet implemented";
734 case VKAT_TEST_OPT_PCM_HZ: return "PCM Hertz (Hz) rate to use\n"
735 " Default: 44100";
736 case VKAT_TEST_OPT_PCM_BIT: return "PCM sample bits (i.e. 16) to use\n"
737 " Default: 16";
738 case VKAT_TEST_OPT_PCM_CHAN: return "PCM channels to use\n"
739 " Default: 2";
740 case VKAT_TEST_OPT_PCM_SIGNED: return "PCM samples to use (signed = true, unsigned = false)\n"
741 " Default: true";
742 case VKAT_TEST_OPT_PROBE_BACKENDS: return "Probes all (available) backends until a working one is found";
743 case VKAT_TEST_OPT_TAG: return "Test set tag to use";
744 case VKAT_TEST_OPT_TEMPDIR: return "Temporary directory to use";
745 case VKAT_TEST_OPT_VOL: return "Audio volume (percent) to use";
746 case VKAT_TEST_OPT_TCP_BIND_ADDRESS: return "TCP address listening to (server mode)";
747 case VKAT_TEST_OPT_TCP_BIND_PORT: return "TCP port listening to (server mode)";
748 case VKAT_TEST_OPT_TCP_CONNECT_ADDRESS: return "TCP address to connect to (client mode)";
749 case VKAT_TEST_OPT_TCP_CONNECT_PORT: return "TCP port to connect to (client mode)";
750 default:
751 break;
752 }
753 return NULL;
754}
755
756/**
757 * Main (entry) function for the testing functionality of VKAT.
758 *
759 * @returns Program exit code.
760 * @param pGetState RTGetOpt state.
761 */
762static DECLCALLBACK(RTEXITCODE) audioTestMain(PRTGETOPTSTATE pGetState)
763{
764 AUDIOTESTENV TstEnv;
765 audioTestEnvInit(&TstEnv);
766
767 int rc;
768
769 PCPDMDRVREG pDrvReg = AudioTestGetDefaultBackend();
770 uint8_t cPcmSampleBit = 0;
771 uint8_t cPcmChannels = 0;
772 uint32_t uPcmHz = 0;
773 bool fPcmSigned = true;
774 bool fProbeBackends = false;
775 bool fNoAudioOk = false;
776
777 const char *pszGuestTcpAddr = NULL;
778 uint16_t uGuestTcpPort = ATS_TCP_DEF_BIND_PORT_GUEST;
779 const char *pszValKitTcpAddr = NULL;
780 uint16_t uValKitTcpPort = ATS_TCP_DEF_BIND_PORT_VALKIT;
781
782 int ch;
783 RTGETOPTUNION ValueUnion;
784 while ((ch = RTGetOpt(pGetState, &ValueUnion)))
785 {
786 switch (ch)
787 {
788 case 'a':
789 for (unsigned i = 0; i < RT_ELEMENTS(g_aTests); i++)
790 g_aTests[i].fExcluded = true;
791 break;
792
793 case 'b':
794 pDrvReg = AudioTestFindBackendOpt(ValueUnion.psz);
795 if (pDrvReg == NULL)
796 return RTEXITCODE_SYNTAX;
797 break;
798
799 case 'd':
800 TstEnv.IoOpts.fWithDrvAudio = true;
801 break;
802
803 case 'e':
804 if (ValueUnion.u32 >= RT_ELEMENTS(g_aTests))
805 return RTMsgErrorExit(RTEXITCODE_SYNTAX, "Invalid test number %u passed to --exclude", ValueUnion.u32);
806 g_aTests[ValueUnion.u32].fExcluded = true;
807 break;
808
809 case VKAT_TEST_OPT_GUEST_ATS_ADDR:
810 pszGuestTcpAddr = ValueUnion.psz;
811 break;
812
813 case VKAT_TEST_OPT_GUEST_ATS_PORT:
814 uGuestTcpPort = ValueUnion.u32;
815 break;
816
817 case VKAT_TEST_OPT_HOST_ATS_ADDR:
818 pszValKitTcpAddr = ValueUnion.psz;
819 break;
820
821 case VKAT_TEST_OPT_HOST_ATS_PORT:
822 uValKitTcpPort = ValueUnion.u32;
823 break;
824
825 case VKAT_TEST_OPT_MODE:
826 if (TstEnv.enmMode != AUDIOTESTMODE_UNKNOWN)
827 return RTMsgErrorExit(RTEXITCODE_SYNTAX, "Test mode (guest / host) already specified");
828 TstEnv.enmMode = RTStrICmp(ValueUnion.psz, "guest") == 0 ? AUDIOTESTMODE_GUEST : AUDIOTESTMODE_HOST;
829 break;
830
831 case VKAT_TEST_OPT_NO_AUDIO_OK:
832 fNoAudioOk = true;
833 break;
834
835 case VKAT_TEST_OPT_NO_VERIFY:
836 TstEnv.fSkipVerify = true;
837 break;
838
839 case 'i':
840 if (ValueUnion.u32 >= RT_ELEMENTS(g_aTests))
841 return RTMsgErrorExit(RTEXITCODE_SYNTAX, "Invalid test number %u passed to --include", ValueUnion.u32);
842 g_aTests[ValueUnion.u32].fExcluded = false;
843 break;
844
845 case VKAT_TEST_OPT_COUNT:
846 TstEnv.cIterations = ValueUnion.u32;
847 break;
848
849 case VKAT_TEST_OPT_DEV:
850 rc = RTStrCopy(TstEnv.szDev, sizeof(TstEnv.szDev), ValueUnion.psz);
851 if (RT_FAILURE(rc))
852 return RTMsgErrorExitFailure("Failed to copy out device: %Rrc", rc);
853 break;
854
855 case VKAT_TEST_OPT_TONE_DURATION_MS:
856 TstEnv.ToneParms.msDuration = ValueUnion.u32;
857 break;
858
859 case VKAT_TEST_OPT_TONE_VOL_PERCENT:
860 TstEnv.ToneParms.uVolumePercent = ValueUnion.u8;
861 break;
862
863 case VKAT_TEST_OPT_PAUSE:
864 return RTMsgErrorExitFailure("Not yet implemented!");
865
866 case VKAT_TEST_OPT_OUTDIR:
867 rc = RTStrCopy(TstEnv.szPathOut, sizeof(TstEnv.szPathOut), ValueUnion.psz);
868 if (RT_FAILURE(rc))
869 return RTMsgErrorExitFailure("Failed to copy out directory: %Rrc", rc);
870 break;
871
872 case VKAT_TEST_OPT_PCM_BIT:
873 cPcmSampleBit = ValueUnion.u8;
874 break;
875
876 case VKAT_TEST_OPT_PCM_CHAN:
877 cPcmChannels = ValueUnion.u8;
878 break;
879
880 case VKAT_TEST_OPT_PCM_HZ:
881 uPcmHz = ValueUnion.u32;
882 break;
883
884 case VKAT_TEST_OPT_PCM_SIGNED:
885 fPcmSigned = ValueUnion.f;
886 break;
887
888 case VKAT_TEST_OPT_PROBE_BACKENDS:
889 fProbeBackends = true;
890 break;
891
892 case VKAT_TEST_OPT_TAG:
893 rc = RTStrCopy(TstEnv.szTag, sizeof(TstEnv.szTag), ValueUnion.psz);
894 if (RT_FAILURE(rc))
895 return RTMsgErrorExit(RTEXITCODE_FAILURE, "Tag invalid, rc=%Rrc", rc);
896 break;
897
898 case VKAT_TEST_OPT_TEMPDIR:
899 rc = RTStrCopy(TstEnv.szPathTemp, sizeof(TstEnv.szPathTemp), ValueUnion.psz);
900 if (RT_FAILURE(rc))
901 return RTMsgErrorExit(RTEXITCODE_FAILURE, "Temp dir invalid, rc=%Rrc", rc);
902 break;
903
904 case VKAT_TEST_OPT_VOL:
905 TstEnv.IoOpts.uVolumePercent = ValueUnion.u8;
906 break;
907
908 case VKAT_TEST_OPT_TCP_BIND_ADDRESS:
909 rc = RTStrCopy(TstEnv.TcpOpts.szBindAddr, sizeof(TstEnv.TcpOpts.szBindAddr), ValueUnion.psz);
910 if (RT_FAILURE(rc))
911 return RTMsgErrorExit(RTEXITCODE_FAILURE, "Bind address invalid, rc=%Rrc", rc);
912 break;
913
914 case VKAT_TEST_OPT_TCP_BIND_PORT:
915 TstEnv.TcpOpts.uBindPort = ValueUnion.u16;
916 break;
917
918 case VKAT_TEST_OPT_TCP_CONNECT_ADDRESS:
919 rc = RTStrCopy(TstEnv.TcpOpts.szConnectAddr, sizeof(TstEnv.TcpOpts.szConnectAddr), ValueUnion.psz);
920 if (RT_FAILURE(rc))
921 return RTMsgErrorExit(RTEXITCODE_FAILURE, "Connect address invalid, rc=%Rrc", rc);
922 break;
923
924 case VKAT_TEST_OPT_TCP_CONNECT_PORT:
925 TstEnv.TcpOpts.uConnectPort = ValueUnion.u16;
926 break;
927
928 AUDIO_TEST_COMMON_OPTION_CASES(ValueUnion, &g_CmdTest);
929
930 default:
931 return RTGetOptPrintError(ch, &ValueUnion);
932 }
933 }
934
935 /*
936 * Start testing.
937 */
938 RTTestBanner(g_hTest);
939
940 if (TstEnv.enmMode == AUDIOTESTMODE_UNKNOWN)
941 return RTMsgErrorExit(RTEXITCODE_SYNTAX, "No test mode (--mode) specified!\n");
942
943 /* Validate TCP options. */
944 if ( TstEnv.TcpOpts.szBindAddr[0]
945 && TstEnv.TcpOpts.szConnectAddr[0])
946 return RTMsgErrorExit(RTEXITCODE_SYNTAX, "Only one TCP connection mode (connect as client *or* bind as server) can be specified) at a time!\n");
947
948 /* Set new (override standard) I/O PCM properties if set by the user. */
949 if ( cPcmSampleBit
950 || cPcmChannels
951 || uPcmHz)
952 {
953 PDMAudioPropsInit(&TstEnv.IoOpts.Props,
954 cPcmSampleBit ? cPcmSampleBit / 2 : 2 /* 16-bit */, fPcmSigned /* fSigned */,
955 cPcmChannels ? cPcmChannels : 2 /* Stereo */, uPcmHz ? uPcmHz : 44100);
956 }
957
958 /* Do this first before everything else below. */
959 rc = AudioTestDriverStackPerformSelftest();
960 if (RT_FAILURE(rc))
961 {
962 if (!fNoAudioOk)
963 return RTMsgErrorExit(RTEXITCODE_FAILURE, "Testing driver stack failed: %Rrc\n", rc);
964 RTTestPrintf(g_hTest, RTTESTLVL_ALWAYS,
965 "Warning: Testing driver stack not possible (%Rrc), but --no-audio-ok was specified. Running on a server without audio hardware?\n", rc);
966 }
967
968 AUDIOTESTDRVSTACK DrvStack;
969 if (fProbeBackends)
970 rc = audioTestDriverStackProbe(&DrvStack, pDrvReg,
971 true /* fEnabledIn */, true /* fEnabledOut */, TstEnv.IoOpts.fWithDrvAudio); /** @todo Make in/out configurable, too. */
972 else
973 rc = audioTestDriverStackInitEx(&DrvStack, pDrvReg,
974 true /* fEnabledIn */, true /* fEnabledOut */, TstEnv.IoOpts.fWithDrvAudio); /** @todo Make in/out configurable, too. */
975 if (RT_FAILURE(rc))
976 {
977 if (!fNoAudioOk)
978 return RTMsgErrorExit(RTEXITCODE_FAILURE, "Unable to init driver stack: %Rrc\n", rc);
979 RTTestPrintf(g_hTest, RTTESTLVL_ALWAYS,
980 "Warning: Initializing driver stack not possible (%Rrc), but --no-audio-ok was specified. Running on a server without audio hardware?\n", rc);
981 }
982
983 PPDMAUDIOHOSTDEV pDev;
984 rc = audioTestDevicesEnumerateAndCheck(&DrvStack, TstEnv.szDev, &pDev);
985 if (RT_FAILURE(rc))
986 {
987 if (!fNoAudioOk)
988 return RTMsgErrorExit(RTEXITCODE_FAILURE, "Enumerating device(s) failed: %Rrc\n", rc);
989 }
990
991 /* For now all tests have the same test environment and driver stack. */
992 rc = audioTestEnvCreate(&TstEnv, &DrvStack);
993 if (RT_SUCCESS(rc))
994 rc = audioTestWorker(&TstEnv);
995
996 audioTestEnvDestroy(&TstEnv);
997 audioTestDriverStackDelete(&DrvStack);
998
999 if (RT_FAILURE(rc)) /* Let us know that something went wrong in case we forgot to mention it. */
1000 RTTestFailed(g_hTest, "Testing failed with %Rrc\n", rc);
1001
1002 /*
1003 * Print summary and exit.
1004 */
1005 return RTTestSummaryAndDestroy(g_hTest);
1006}
1007
1008
1009const VKATCMD g_CmdTest =
1010{
1011 "test",
1012 audioTestMain,
1013 "Runs audio tests and creates an audio test set.",
1014 g_aCmdTestOptions,
1015 RT_ELEMENTS(g_aCmdTestOptions),
1016 audioTestCmdTestHelp,
1017 true /* fNeedsTransport */
1018};
1019
1020
1021/*********************************************************************************************************************************
1022* Command: verify *
1023*********************************************************************************************************************************/
1024
1025static int audioVerifyOpenTestSet(const char *pszPathSet, PAUDIOTESTSET pSet)
1026{
1027 int rc;
1028
1029 char szPathExtracted[RTPATH_MAX];
1030
1031 RTTestPrintf(g_hTest, RTTESTLVL_ALWAYS, "Opening test set '%s'\n", pszPathSet);
1032
1033 const bool fPacked = AudioTestSetIsPacked(pszPathSet);
1034
1035 if (fPacked)
1036 {
1037 RTTestPrintf(g_hTest, RTTESTLVL_ALWAYS, "Test set is an archive and needs to be unpacked\n");
1038
1039 if (!RTFileExists(pszPathSet))
1040 {
1041 RTTestPrintf(g_hTest, RTTESTLVL_ALWAYS, "Test set '%s' does not exist\n", pszPathSet);
1042 rc = VERR_FILE_NOT_FOUND;
1043 }
1044 else
1045 rc = VINF_SUCCESS;
1046
1047 if (RT_SUCCESS(rc))
1048 {
1049 char szPathTemp[RTPATH_MAX];
1050 rc = RTPathTemp(szPathTemp, sizeof(szPathTemp));
1051 if (RT_SUCCESS(rc))
1052 {
1053 RTTestPrintf(g_hTest, RTTESTLVL_ALWAYS, "Using temporary directory '%s'\n", szPathTemp);
1054
1055 rc = RTPathJoin(szPathExtracted, sizeof(szPathExtracted), szPathTemp, "vkat-testset-XXXX");
1056 if (RT_SUCCESS(rc))
1057 {
1058 rc = RTDirCreateTemp(szPathExtracted, 0755);
1059 if (RT_SUCCESS(rc))
1060 {
1061 RTTestPrintf(g_hTest, RTTESTLVL_ALWAYS, "Unpacking archive to '%s'\n", szPathExtracted);
1062 rc = AudioTestSetUnpack(pszPathSet, szPathExtracted);
1063 if (RT_SUCCESS(rc))
1064 RTTestPrintf(g_hTest, RTTESTLVL_ALWAYS, "Archive successfully unpacked\n");
1065 }
1066 }
1067 }
1068 }
1069 }
1070 else
1071 rc = VINF_SUCCESS;
1072
1073 if (RT_SUCCESS(rc))
1074 rc = AudioTestSetOpen(pSet, fPacked ? szPathExtracted : pszPathSet);
1075
1076 if (RT_FAILURE(rc))
1077 RTTestFailed(g_hTest, "Unable to open / unpack test set archive: %Rrc", rc);
1078
1079 return rc;
1080}
1081
1082/**
1083 * Verifies one test set pair.
1084 *
1085 * @returns VBox status code.
1086 * @param pszPathSetA Absolute path to test set A.
1087 * @param pszPathSetB Absolute path to test set B.
1088 * @param pOpts Verification options to use. Optional.
1089 * When NULL, the (very strict) defaults will be used.
1090 */
1091static int audioVerifyOne(const char *pszPathSetA, const char *pszPathSetB, PAUDIOTESTVERIFYOPTS pOpts)
1092{
1093 RTTestSubF(g_hTest, "Verifying");
1094 RTTestPrintf(g_hTest, RTTESTLVL_ALWAYS, "Verifying test set '%s' with test set '%s'\n", pszPathSetA, pszPathSetB);
1095
1096 AUDIOTESTSET SetA, SetB;
1097 int rc = audioVerifyOpenTestSet(pszPathSetA, &SetA);
1098 if (RT_SUCCESS(rc))
1099 {
1100 rc = audioVerifyOpenTestSet(pszPathSetB, &SetB);
1101 if (RT_SUCCESS(rc))
1102 {
1103 AUDIOTESTERRORDESC errDesc;
1104 if (pOpts)
1105 rc = AudioTestSetVerifyEx(&SetA, &SetB, pOpts, &errDesc);
1106 else
1107 rc = AudioTestSetVerify(&SetA, &SetB, &errDesc);
1108 if (RT_SUCCESS(rc))
1109 {
1110 uint32_t const cErr = AudioTestErrorDescCount(&errDesc);
1111 RTTestPrintf(g_hTest, RTTESTLVL_ALWAYS, "%RU32 errors occurred while verifying\n", cErr);
1112
1113 /** @todo Use some AudioTestErrorXXX API for enumeration here later. */
1114 PAUDIOTESTERRORENTRY pErrEntry;
1115 RTListForEach(&errDesc.List, pErrEntry, AUDIOTESTERRORENTRY, Node)
1116 {
1117 if (RT_FAILURE(pErrEntry->rc))
1118 RTTestFailed(g_hTest, "%s\n", pErrEntry->szDesc);
1119 else
1120 RTTestPrintf(g_hTest, RTTESTLVL_ALWAYS, "%s\n", pErrEntry->szDesc);
1121 }
1122
1123 if (cErr == 0)
1124 RTTestPrintf(g_hTest, RTTESTLVL_ALWAYS, "Verification successful\n");
1125
1126 AudioTestErrorDescDestroy(&errDesc);
1127 }
1128 else
1129 RTTestFailed(g_hTest, "Verification failed with %Rrc", rc);
1130
1131#ifdef DEBUG
1132 if (g_fDrvAudioDebug)
1133 RTTestPrintf(g_hTest, RTTESTLVL_ALWAYS,
1134 "\n"
1135 "Use the following command line to re-run verification in the debugger:\n"
1136 "gdb --args ./VBoxAudioTest -vvvv --debug-audio verify \"%s\" \"%s\"\n",
1137 SetA.szPathAbs, SetB.szPathAbs);
1138#endif
1139 if (!g_fDrvAudioDebug) /* Don't wipe stuff when debugging. Can be useful for introspecting data. */
1140 AudioTestSetWipe(&SetB);
1141 AudioTestSetClose(&SetB);
1142 }
1143
1144 if (!g_fDrvAudioDebug) /* Ditto. */
1145 AudioTestSetWipe(&SetA);
1146 AudioTestSetClose(&SetA);
1147 }
1148
1149 RTTestSubDone(g_hTest);
1150
1151 return rc;
1152}
1153
1154/** Option help for the 'verify' command. */
1155static DECLCALLBACK(const char *) audioTestCmdVerifyHelp(PCRTGETOPTDEF pOpt)
1156{
1157 switch (pOpt->iShort)
1158 {
1159 case VKAT_VERIFY_OPT_MAX_DIFF_COUNT: return "Specifies the maximum number of differences\n"
1160 " Default: 0 (strict)";
1161 case VKAT_VERIFY_OPT_MAX_DIFF_PERCENT: return "Specifies the maximum difference (percent)\n"
1162 " Default: 0 (strict)";
1163 case VKAT_VERIFY_OPT_MAX_SIZE_PERCENT: return "Specifies the maximum size difference (percent)\n"
1164 " Default: 1 (strict)";
1165 case VKAT_VERIFY_OPT_NORMALIZE: return "Enables / disables audio data normalization\n"
1166 " Default: false";
1167 default:
1168 break;
1169 }
1170 return NULL;
1171}
1172
1173/**
1174 * Main (entry) function for the verification functionality of VKAT.
1175 *
1176 * @returns Program exit code.
1177 * @param pGetState RTGetOpt state.
1178 */
1179static DECLCALLBACK(RTEXITCODE) audioVerifyMain(PRTGETOPTSTATE pGetState)
1180{
1181 /*
1182 * Parse options and process arguments.
1183 */
1184 const char *apszSets[2] = { NULL, NULL };
1185 unsigned iTestSet = 0;
1186
1187 AUDIOTESTVERIFYOPTS Opts;
1188 AudioTestSetVerifyOptsInit(&Opts);
1189
1190 int ch;
1191 RTGETOPTUNION ValueUnion;
1192 while ((ch = RTGetOpt(pGetState, &ValueUnion)))
1193 {
1194 switch (ch)
1195 {
1196 case VKAT_VERIFY_OPT_MAX_DIFF_COUNT:
1197 Opts.cMaxDiff = ValueUnion.u32;
1198 break;
1199
1200 case VKAT_VERIFY_OPT_MAX_DIFF_PERCENT:
1201 Opts.uMaxDiffPercent = ValueUnion.u8;
1202 break;
1203
1204 case VKAT_VERIFY_OPT_MAX_SIZE_PERCENT:
1205 Opts.uMaxSizePercent = ValueUnion.u8;
1206 break;
1207
1208 case VKAT_VERIFY_OPT_NORMALIZE:
1209 Opts.fNormalize = ValueUnion.f;
1210 break;
1211
1212 case VINF_GETOPT_NOT_OPTION:
1213 if (iTestSet == 0)
1214 RTTestBanner(g_hTest);
1215 if (iTestSet >= RT_ELEMENTS(apszSets))
1216 return RTMsgErrorExitFailure("Only two test sets can be verified at one time");
1217 apszSets[iTestSet++] = ValueUnion.psz;
1218 break;
1219
1220 AUDIO_TEST_COMMON_OPTION_CASES(ValueUnion, &g_CmdVerify);
1221
1222 default:
1223 return RTGetOptPrintError(ch, &ValueUnion);
1224 }
1225 }
1226
1227 if (!iTestSet)
1228 return RTMsgErrorExitFailure("At least one test set must be specified");
1229
1230 int rc = VINF_SUCCESS;
1231
1232 /*
1233 * If only test set A is given, default to the current directory
1234 * for test set B.
1235 */
1236 char szDirCur[RTPATH_MAX];
1237 if (iTestSet == 1)
1238 {
1239 rc = RTPathGetCurrent(szDirCur, sizeof(szDirCur));
1240 if (RT_SUCCESS(rc))
1241 apszSets[1] = szDirCur;
1242 else
1243 RTTestFailed(g_hTest, "Failed to retrieve current directory: %Rrc", rc);
1244 }
1245
1246 if (RT_SUCCESS(rc))
1247 audioVerifyOne(apszSets[0], apszSets[1], &Opts);
1248
1249 /*
1250 * Print summary and exit.
1251 */
1252 return RTTestSummaryAndDestroy(g_hTest);
1253}
1254
1255
1256const VKATCMD g_CmdVerify =
1257{
1258 "verify",
1259 audioVerifyMain,
1260 "Verifies a formerly created audio test set.",
1261 g_aCmdVerifyOptions,
1262 RT_ELEMENTS(g_aCmdVerifyOptions),
1263 audioTestCmdVerifyHelp,
1264 false /* fNeedsTransport */
1265};
1266
1267
1268/*********************************************************************************************************************************
1269* Main *
1270*********************************************************************************************************************************/
1271
1272/**
1273 * Ctrl-C signal handler.
1274 *
1275 * This just sets g_fTerminate and hope it will be noticed soon.
1276 *
1277 * On non-Windows it restores the SIGINT action to default, so that a second
1278 * Ctrl-C will have the normal effect (just in case the code doesn't respond to
1279 * g_fTerminate).
1280 */
1281#ifdef RT_OS_WINDOWS
1282static BOOL CALLBACK audioTestConsoleCtrlHandler(DWORD dwCtrlType) RT_NOEXCEPT
1283{
1284 if (dwCtrlType != CTRL_C_EVENT && dwCtrlType != CTRL_BREAK_EVENT)
1285 return false;
1286 RTPrintf(dwCtrlType == CTRL_C_EVENT ? "Ctrl-C!\n" : "Ctrl-Break!\n");
1287
1288 ASMAtomicWriteBool(&g_fTerminate, true);
1289
1290 return true;
1291}
1292#else
1293static void audioTestSignalHandler(int iSig) RT_NOEXCEPT
1294{
1295 Assert(iSig == SIGINT); RT_NOREF(iSig);
1296 RTPrintf("Ctrl-C!\n");
1297
1298 ASMAtomicWriteBool(&g_fTerminate, true);
1299
1300 signal(SIGINT, SIG_DFL);
1301}
1302#endif
1303
1304/**
1305 * Commands.
1306 */
1307static const VKATCMD * const g_apCommands[] =
1308{
1309 &g_CmdTest,
1310 &g_CmdVerify,
1311 &g_CmdBackends,
1312 &g_CmdEnum,
1313 &g_CmdPlay,
1314 &g_CmdRec,
1315 &g_CmdSelfTest
1316};
1317
1318/**
1319 * Shows tool usage text.
1320 */
1321RTEXITCODE audioTestUsage(PRTSTREAM pStrm, PCVKATCMD pOnlyCmd)
1322{
1323 RTStrmPrintf(pStrm, "usage: %s [global options] <command> [command-options]\n", RTProcShortName());
1324 RTStrmPrintf(pStrm,
1325 "\n"
1326 "Global Options:\n"
1327 " --debug-audio\n"
1328 " Enables (DrvAudio) debugging\n"
1329 " --debug-audio-path=<path>\n"
1330 " Tells DrvAudio where to put its debug output (wav-files)\n"
1331 " -q, --quiet\n"
1332 " Sets verbosity to zero\n"
1333 " -v, --verbose\n"
1334 " Increase verbosity\n"
1335 " -V, --version\n"
1336 " Displays version\n"
1337 " -h, -?, --help\n"
1338 " Displays help\n"
1339 );
1340
1341 for (uintptr_t iCmd = 0; iCmd < RT_ELEMENTS(g_apCommands); iCmd++)
1342 {
1343 PCVKATCMD const pCmd = g_apCommands[iCmd];
1344 if (!pOnlyCmd || pCmd == pOnlyCmd)
1345 {
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);
1370 }
1371 }
1372
1373 return RTEXITCODE_SUCCESS;
1374}
1375
1376/**
1377 * Lists the commands and their descriptions.
1378 */
1379static 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);
1384 return RTEXITCODE_SUCCESS;
1385}
1386
1387/**
1388 * Shows tool version.
1389 */
1390RTEXITCODE audioTestVersion(void)
1391{
1392 RTPrintf("%s\n", RTBldCfgRevisionStr());
1393 return RTEXITCODE_SUCCESS;
1394}
1395
1396/**
1397 * Shows the logo.
1398 *
1399 * @param pStream Output stream to show logo on.
1400 */
1401void audioTestShowLogo(PRTSTREAM pStream)
1402{
1403 RTStrmPrintf(pStream, VBOX_PRODUCT " VKAT (Validation Kit Audio Test) Version " VBOX_VERSION_STRING " - r%s\n"
1404 "Copyright (C) " VBOX_C_YEAR " " VBOX_VENDOR "\n\n", RTBldCfgRevisionStr());
1405}
1406
1407int main(int argc, char **argv)
1408{
1409 /*
1410 * Init IPRT.
1411 */
1412 int rc = RTR3InitExe(argc, &argv, 0);
1413 if (RT_FAILURE(rc))
1414 return RTMsgInitFailure(rc);
1415
1416 /*
1417 * Handle special command line options which need parsing before
1418 * everything else.
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. */
1437 bool fDaemonize = false;
1438 bool fDaemonized = false;
1439
1440 RTGETOPTSTATE GetState;
1441 rc = RTGetOptInit(&GetState, argc, argv, g_aCmdCommonOptions,
1442 RT_ELEMENTS(g_aCmdCommonOptions), 1 /*idxFirst*/, 0 /*fFlags - must not sort! */);
1443 AssertRCReturn(rc, RTEXITCODE_INIT);
1444
1445 int ch;
1446 RTGETOPTUNION ValueUnion;
1447 while ((ch = RTGetOpt(&GetState, &ValueUnion)) != 0)
1448 {
1449 switch (ch)
1450 {
1451 case AUDIO_TEST_OPT_CMN_DAEMONIZE:
1452 fDaemonize = true;
1453 break;
1454
1455 case AUDIO_TEST_OPT_CMN_DAEMONIZED:
1456 fDaemonized = true;
1457 break;
1458
1459 /* Has to be defined here and not in AUDIO_TEST_COMMON_OPTION_CASES, to get the logger
1460 * configured before the specific command handlers down below come into play. */
1461 case 'v':
1462 g_uVerbosity++;
1463 break;
1464
1465 default:
1466 break;
1467 }
1468 }
1469
1470 /** @todo add something to suppress this stuff. */
1471 audioTestShowLogo(g_pStdOut);
1472
1473 if (fDaemonize)
1474 {
1475 if (!fDaemonized)
1476 {
1477 rc = RTProcDaemonize(argv, "--daemonized");
1478 if (RT_FAILURE(rc))
1479 return RTMsgErrorExit(RTEXITCODE_FAILURE, "RTProcDaemonize() failed with %Rrc\n", rc);
1480
1481 RTMsgInfo("Starting in background (daemonizing) ...");
1482 return RTEXITCODE_SUCCESS;
1483 }
1484 /* else continue running in background. */
1485 }
1486
1487 /*
1488 * Init test and globals.
1489 * Note: Needs to be done *after* daemonizing, otherwise the child will fail!
1490 */
1491 rc = RTTestCreate("AudioTest", &g_hTest);
1492 if (RT_FAILURE(rc))
1493 return RTMsgErrorExit(RTEXITCODE_FAILURE, "RTTestCreate() failed with %Rrc\n", rc);
1494
1495#ifdef RT_OS_WINDOWS
1496 HRESULT hrc = CoInitializeEx(NULL /*pReserved*/, COINIT_MULTITHREADED | COINIT_SPEED_OVER_MEMORY | COINIT_DISABLE_OLE1DDE);
1497 if (FAILED(hrc))
1498 RTMsgWarning("CoInitializeEx failed: %#x", hrc);
1499#endif
1500
1501 /*
1502 * Configure release logging to go to stdout.
1503 */
1504 RTUINT fFlags = RTLOGFLAGS_PREFIX_THREAD | RTLOGFLAGS_PREFIX_TIME_PROG;
1505#if defined(RT_OS_WINDOWS) || defined(RT_OS_OS2)
1506 fFlags |= RTLOGFLAGS_USECRLF;
1507#endif
1508 static const char * const s_apszLogGroups[] = VBOX_LOGGROUP_NAMES;
1509 rc = RTLogCreate(&g_pRelLogger, fFlags, "all.e.l", "VKAT_RELEASE_LOG",
1510 RT_ELEMENTS(s_apszLogGroups), s_apszLogGroups, RTLOGDEST_STDOUT, NULL /*"vkat-release.log"*/);
1511 if (RT_SUCCESS(rc))
1512 {
1513 RTLogRelSetDefaultInstance(g_pRelLogger);
1514 if (g_uVerbosity)
1515 {
1516 RTMsgInfo("Setting verbosity logging to level %u\n", g_uVerbosity);
1517 switch (g_uVerbosity) /* Not very elegant, but has to do it for now. */
1518 {
1519 case 1:
1520 rc = RTLogGroupSettings(g_pRelLogger,
1521 "drv_audio.e.l+drv_host_audio.e.l+"
1522 "audio_mixer.e.l+audio_test.e.l");
1523 break;
1524
1525 case 2:
1526 rc = RTLogGroupSettings(g_pRelLogger,
1527 "drv_audio.e.l.l2+drv_host_audio.e.l.l2+"
1528 "audio_mixer.e.l.l2+audio_test.e.l.l2");
1529 break;
1530
1531 case 3:
1532 rc = RTLogGroupSettings(g_pRelLogger,
1533 "drv_audio.e.l.l2.l3+drv_host_audio.e.l.l2.l3+"
1534 "audio_mixer.e.l.l2.l3+audio_test.e.l.l2.l3");
1535 break;
1536
1537 case 4:
1538 RT_FALL_THROUGH();
1539 default:
1540 rc = RTLogGroupSettings(g_pRelLogger,
1541 "drv_audio.e.l.l2.l3.l4.f+drv_host_audio.e.l.l2.l3.l4.f+"
1542 "audio_mixer.e.l.l2.l3.l4.f+audio_test.e.l.l2.l3.l4.f");
1543 break;
1544 }
1545 if (RT_FAILURE(rc))
1546 RTMsgError("Setting debug logging failed, rc=%Rrc\n", rc);
1547 }
1548 }
1549 else
1550 RTMsgWarning("Failed to create release logger: %Rrc", rc);
1551
1552 /*
1553 * Install a Ctrl-C signal handler.
1554 */
1555#ifdef RT_OS_WINDOWS
1556 SetConsoleCtrlHandler(audioTestConsoleCtrlHandler, TRUE);
1557#else
1558 struct sigaction sa;
1559 RT_ZERO(sa);
1560 sa.sa_handler = audioTestSignalHandler;
1561 sigaction(SIGINT, &sa, NULL);
1562#endif
1563
1564 /*
1565 * Process common options.
1566 */
1567 RT_ZERO(GetState);
1568 rc = RTGetOptInit(&GetState, argc, argv, g_aCmdCommonOptions,
1569 RT_ELEMENTS(g_aCmdCommonOptions), 1 /*idxFirst*/, 0 /*fFlags - must not sort! */);
1570 AssertRCReturn(rc, RTEXITCODE_INIT);
1571
1572 while ((ch = RTGetOpt(&GetState, &ValueUnion)) != 0)
1573 {
1574 switch (ch)
1575 {
1576 AUDIO_TEST_COMMON_OPTION_CASES(ValueUnion, NULL);
1577
1578 case VINF_GETOPT_NOT_OPTION:
1579 {
1580 for (uintptr_t iCmd = 0; iCmd < RT_ELEMENTS(g_apCommands); iCmd++)
1581 {
1582 PCVKATCMD const pCmd = g_apCommands[iCmd];
1583 if (strcmp(ValueUnion.psz, pCmd->pszCommand) == 0)
1584 {
1585 /* Count the combined option definitions: */
1586 size_t cCombinedOptions = pCmd->cOptions + RT_ELEMENTS(g_aCmdCommonOptions);
1587 if (pCmd->fNeedsTransport)
1588 for (uintptr_t iTx = 0; iTx < g_cTransports; iTx++)
1589 cCombinedOptions += g_apTransports[iTx]->cOpts;
1590
1591 /* Combine the option definitions: */
1592 PRTGETOPTDEF paCombinedOptions = (PRTGETOPTDEF)RTMemAlloc(cCombinedOptions * sizeof(RTGETOPTDEF));
1593 if (paCombinedOptions)
1594 {
1595 uint32_t idxOpts = 0;
1596 memcpy(paCombinedOptions, g_aCmdCommonOptions, sizeof(g_aCmdCommonOptions));
1597 idxOpts += RT_ELEMENTS(g_aCmdCommonOptions);
1598
1599 memcpy(&paCombinedOptions[idxOpts], pCmd->paOptions, pCmd->cOptions * sizeof(RTGETOPTDEF));
1600 idxOpts += (uint32_t)pCmd->cOptions;
1601
1602 if (pCmd->fNeedsTransport)
1603 for (uintptr_t iTx = 0; iTx < g_cTransports; iTx++)
1604 {
1605 memcpy(&paCombinedOptions[idxOpts],
1606 g_apTransports[iTx]->paOpts, g_apTransports[iTx]->cOpts * sizeof(RTGETOPTDEF));
1607 idxOpts += (uint32_t)g_apTransports[iTx]->cOpts;
1608 }
1609
1610 /* Re-initialize the option getter state and pass it to the command handler. */
1611 rc = RTGetOptInit(&GetState, argc, argv, paCombinedOptions, cCombinedOptions,
1612 GetState.iNext /*idxFirst*/, RTGETOPTINIT_FLAGS_OPTS_FIRST);
1613 if (RT_SUCCESS(rc))
1614 {
1615 RTEXITCODE rcExit = pCmd->pfnHandler(&GetState);
1616 RTMemFree(paCombinedOptions);
1617 return rcExit;
1618 }
1619 RTMemFree(paCombinedOptions);
1620 return RTMsgErrorExitFailure("RTGetOptInit failed for '%s': %Rrc", ValueUnion.psz, rc);
1621 }
1622 return RTMsgErrorExitFailure("Out of memory!");
1623 }
1624 }
1625 RTMsgError("Unknown command '%s'!\n", ValueUnion.psz);
1626 audioTestListCommands(g_pStdErr);
1627 return RTEXITCODE_SYNTAX;
1628 }
1629
1630 default:
1631 return RTGetOptPrintError(ch, &ValueUnion);
1632 }
1633 }
1634
1635 RTMsgError("No command specified!\n");
1636 audioTestListCommands(g_pStdErr);
1637 return RTEXITCODE_SYNTAX;
1638}
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