VirtualBox

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

Last change on this file since 100240 was 98324, checked in by vboxsync, 22 months ago

Audio/VKAT: Added syntax help for "--mode" and show the available (compiled-in) audio backends when specifying an invalid backend [build fix].

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 62.3 KB
Line 
1/* $Id: vkat.cpp 98324 2023-01-26 16:10:02Z 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'\n\n", pszBackend);
269 RTPrintf("Supported backend values are: ");
270 for (uintptr_t i = 0; i < RT_ELEMENTS(g_aBackends); i++)
271 {
272 if (i > 0)
273 RTPrintf(", ");
274 RTPrintf(g_aBackends[i].pszName);
275 }
276 RTPrintf("\n");
277 return NULL;
278}
279
280
281/*********************************************************************************************************************************
282* Test callbacks *
283*********************************************************************************************************************************/
284
285/**
286 * @copydoc FNAUDIOTESTSETUP
287 */
288static DECLCALLBACK(int) audioTestPlayToneSetup(PAUDIOTESTENV pTstEnv, PAUDIOTESTDESC pTstDesc, PAUDIOTESTPARMS pTstParmsAcq, void **ppvCtx)
289{
290 RT_NOREF(pTstDesc, ppvCtx);
291
292 int rc = VINF_SUCCESS;
293
294 if (strlen(pTstEnv->szDev))
295 {
296 rc = audioTestDriverStackSetDevice(pTstEnv->pDrvStack, PDMAUDIODIR_OUT, pTstEnv->szDev);
297 if (RT_FAILURE(rc))
298 return rc;
299 }
300
301 pTstParmsAcq->enmType = AUDIOTESTTYPE_TESTTONE_PLAY;
302 pTstParmsAcq->enmDir = PDMAUDIODIR_OUT;
303
304 pTstParmsAcq->TestTone = pTstEnv->ToneParms;
305
306 pTstParmsAcq->TestTone.Hdr.idxTest = pTstEnv->idxTest; /* Assign unique test ID. */
307
308 return rc;
309}
310
311/**
312 * @copydoc FNAUDIOTESTEXEC
313 */
314static DECLCALLBACK(int) audioTestPlayToneExec(PAUDIOTESTENV pTstEnv, void *pvCtx, PAUDIOTESTPARMS pTstParms)
315{
316 RT_NOREF(pvCtx);
317
318 int rc = VINF_SUCCESS;
319
320 PAUDIOTESTTONEPARMS const pToneParms = &pTstParms->TestTone;
321
322 uint32_t const idxTest = pToneParms->Hdr.idxTest;
323
324 RTTIMESPEC NowTimeSpec;
325 RTTimeExplode(&pToneParms->Hdr.tsCreated, RTTimeNow(&NowTimeSpec));
326
327 RTTestPrintf(g_hTest, RTTESTLVL_ALWAYS, "Test #%RU32: Playing test tone (%RU16Hz, %RU32ms)\n",
328 idxTest, (uint16_t)pToneParms->dbFreqHz, pToneParms->msDuration);
329
330 /*
331 * 1. Arm the (host) ValKit ATS with the recording parameters.
332 */
333 RTTestPrintf(g_hTest, RTTESTLVL_ALWAYS,
334 "Test #%RU32: Telling ValKit audio driver on host to record new tone ...\n", idxTest);
335
336 rc = AudioTestSvcClientToneRecord(&pTstEnv->u.Host.AtsClValKit, pToneParms);
337 if (RT_SUCCESS(rc))
338 {
339 /* Give the Validaiton Kit audio driver on the host a bit of time to register / arming the new test. */
340 RTThreadSleep(5000); /* Fudge factor. */
341
342 /*
343 * 2. Tell VKAT on guest to start playback.
344 */
345 RTTestPrintf(g_hTest, RTTESTLVL_ALWAYS, "Test #%RU32: Telling VKAT on guest to play tone ...\n", idxTest);
346
347 rc = AudioTestSvcClientTonePlay(&pTstEnv->u.Host.AtsClGuest, pToneParms);
348 if (RT_FAILURE(rc))
349 RTTestFailed(g_hTest, "Test #%RU32: AudioTestSvcClientTonePlay() failed with %Rrc\n", idxTest, rc);
350 }
351 else
352 RTTestFailed(g_hTest, "Test #%RU32: AudioTestSvcClientToneRecord() failed with %Rrc\n", idxTest, rc);
353
354 if (RT_SUCCESS(rc))
355 {
356 RTTestPrintf(g_hTest, RTTESTLVL_ALWAYS, "Test #%RU32: Playing tone done\n", idxTest);
357
358 /* Give the audio stack a random amount of time for draining data before the next iteration. */
359 if (pTstEnv->cIterations > 1)
360 RTThreadSleep(RTRandU32Ex(2000, 5000)); /** @todo Implement some dedicated ATS command for this? */
361 }
362
363 if (RT_FAILURE(rc))
364 RTTestFailed(g_hTest, "Test #%RU32: Playing test tone failed with %Rrc\n", idxTest, rc);
365
366 return rc;
367}
368
369/**
370 * @copydoc FNAUDIOTESTDESTROY
371 */
372static DECLCALLBACK(int) audioTestPlayToneDestroy(PAUDIOTESTENV pTstEnv, void *pvCtx)
373{
374 RT_NOREF(pTstEnv, pvCtx);
375
376 return VINF_SUCCESS;
377}
378
379/**
380 * @copydoc FNAUDIOTESTSETUP
381 */
382static DECLCALLBACK(int) audioTestRecordToneSetup(PAUDIOTESTENV pTstEnv, PAUDIOTESTDESC pTstDesc, PAUDIOTESTPARMS pTstParmsAcq, void **ppvCtx)
383{
384 RT_NOREF(pTstDesc, ppvCtx);
385
386 int rc = VINF_SUCCESS;
387
388 if (strlen(pTstEnv->szDev))
389 {
390 rc = audioTestDriverStackSetDevice(pTstEnv->pDrvStack, PDMAUDIODIR_IN, pTstEnv->szDev);
391 if (RT_FAILURE(rc))
392 return rc;
393 }
394
395 pTstParmsAcq->enmType = AUDIOTESTTYPE_TESTTONE_RECORD;
396 pTstParmsAcq->enmDir = PDMAUDIODIR_IN;
397
398 pTstParmsAcq->TestTone = pTstEnv->ToneParms;
399
400 pTstParmsAcq->TestTone.Hdr.idxTest = pTstEnv->idxTest; /* Assign unique test ID. */
401
402 return rc;
403}
404
405/**
406 * @copydoc FNAUDIOTESTEXEC
407 */
408static DECLCALLBACK(int) audioTestRecordToneExec(PAUDIOTESTENV pTstEnv, void *pvCtx, PAUDIOTESTPARMS pTstParms)
409{
410 RT_NOREF(pvCtx);
411
412 int rc = VINF_SUCCESS;
413
414 PAUDIOTESTTONEPARMS const pToneParms = &pTstParms->TestTone;
415
416 uint32_t const idxTest = pToneParms->Hdr.idxTest;
417
418 RTTIMESPEC NowTimeSpec;
419 RTTimeExplode(&pToneParms->Hdr.tsCreated, RTTimeNow(&NowTimeSpec));
420
421 RTTestPrintf(g_hTest, RTTESTLVL_ALWAYS, "Test #%RU32: Recording test tone (%RU16Hz, %RU32ms)\n",
422 idxTest, (uint16_t)pToneParms->dbFreqHz, pToneParms->msDuration);
423
424 /*
425 * 1. Arm the (host) ValKit ATS with the playback parameters.
426 */
427 RTTestPrintf(g_hTest, RTTESTLVL_ALWAYS,
428 "Test #%RU32: Telling ValKit audio driver on host to inject recording data ...\n", idxTest);
429
430 rc = AudioTestSvcClientTonePlay(&pTstEnv->u.Host.AtsClValKit, &pTstParms->TestTone);
431 if (RT_SUCCESS(rc))
432 {
433 /*
434 * 2. Tell the guest ATS to start recording.
435 */
436 RTTestPrintf(g_hTest, RTTESTLVL_ALWAYS, "Test #%RU32: Telling VKAT on guest to record audio ...\n", idxTest);
437
438 rc = AudioTestSvcClientToneRecord(&pTstEnv->u.Host.AtsClGuest, &pTstParms->TestTone);
439 if (RT_FAILURE(rc))
440 RTTestFailed(g_hTest, "Test #%RU32: AudioTestSvcClientToneRecord() failed with %Rrc\n", idxTest, rc);
441 }
442 else
443 RTTestFailed(g_hTest, "Test #%RU32: AudioTestSvcClientTonePlay() failed with %Rrc\n", idxTest, rc);
444
445 if (RT_SUCCESS(rc))
446 {
447 /* Wait a bit to let the left over audio bits being processed. */
448 if (pTstEnv->cIterations > 1)
449 RTThreadSleep(RTRandU32Ex(2000, 5000)); /** @todo Implement some dedicated ATS command for this? */
450 }
451
452 if (RT_FAILURE(rc))
453 RTTestFailed(g_hTest, "Test #%RU32: Recording test tone failed with %Rrc\n", idxTest, rc);
454
455 return rc;
456}
457
458/**
459 * @copydoc FNAUDIOTESTDESTROY
460 */
461static DECLCALLBACK(int) audioTestRecordToneDestroy(PAUDIOTESTENV pTstEnv, void *pvCtx)
462{
463 RT_NOREF(pTstEnv, pvCtx);
464
465 return VINF_SUCCESS;
466}
467
468
469/*********************************************************************************************************************************
470* Test execution *
471*********************************************************************************************************************************/
472
473/** Test definition table. */
474AUDIOTESTDESC g_aTests[] =
475{
476 /* pszTest fExcluded pfnSetup */
477 { "PlayTone", false, audioTestPlayToneSetup, audioTestPlayToneExec, audioTestPlayToneDestroy },
478 { "RecordTone", false, audioTestRecordToneSetup, audioTestRecordToneExec, audioTestRecordToneDestroy }
479};
480/** Number of tests defined. */
481unsigned g_cTests = RT_ELEMENTS(g_aTests);
482
483/**
484 * Runs one specific audio test.
485 *
486 * @returns VBox status code.
487 * @param pTstEnv Test environment to use for running the test.
488 * @param pTstDesc Test to run.
489 */
490static int audioTestOne(PAUDIOTESTENV pTstEnv, PAUDIOTESTDESC pTstDesc)
491{
492 int rc = VINF_SUCCESS;
493
494 AUDIOTESTPARMS TstParms;
495 audioTestParmsInit(&TstParms);
496
497 RTTestSub(g_hTest, pTstDesc->pszName);
498
499 if (pTstDesc->fExcluded)
500 {
501 RTTestSkipped(g_hTest, "Test #%RU32 is excluded from list, skipping", pTstEnv->idxTest);
502 return VINF_SUCCESS;
503 }
504
505 pTstEnv->cIterations = pTstEnv->cIterations == 0 ? RTRandU32Ex(1, 10) : pTstEnv->cIterations;
506
507 RTTestPrintf(g_hTest, RTTESTLVL_ALWAYS, "Test #%RU32 (%RU32 iterations total)\n", pTstEnv->idxTest, pTstEnv->cIterations);
508
509 void *pvCtx = NULL; /* Test-specific opaque context. Optional and can be NULL. */
510
511 AssertPtr(pTstDesc->pfnExec);
512 for (uint32_t i = 0; i < pTstEnv->cIterations; i++)
513 {
514 int rc2;
515
516 if (pTstDesc->pfnSetup)
517 {
518 rc2 = pTstDesc->pfnSetup(pTstEnv, pTstDesc, &TstParms, &pvCtx);
519 if (RT_FAILURE(rc2))
520 RTTestFailed(g_hTest, "Test #%RU32 setup failed with %Rrc\n", pTstEnv->idxTest, rc2);
521 }
522 else
523 rc2 = VINF_SUCCESS;
524
525 if (RT_SUCCESS(rc2))
526 {
527 AssertPtrBreakStmt(pTstDesc->pfnExec, VERR_INVALID_POINTER);
528 rc2 = pTstDesc->pfnExec(pTstEnv, pvCtx, &TstParms);
529 if (RT_FAILURE(rc2))
530 RTTestFailed(g_hTest, "Test #%RU32 execution failed with %Rrc\n", pTstEnv->idxTest, rc2);
531 }
532
533 if (pTstDesc->pfnDestroy)
534 {
535 rc2 = pTstDesc->pfnDestroy(pTstEnv, pvCtx);
536 if (RT_FAILURE(rc2))
537 RTTestFailed(g_hTest, "Test #%RU32 destruction failed with %Rrc\n", pTstEnv->idxTest, rc2);
538 }
539
540 if (RT_SUCCESS(rc))
541 rc = rc2;
542
543 /* Keep going. */
544 pTstEnv->idxTest++;
545 }
546
547 RTTestSubDone(g_hTest);
548
549 audioTestParmsDestroy(&TstParms);
550
551 return rc;
552}
553
554/**
555 * Runs all specified tests in a row.
556 *
557 * @returns VBox status code.
558 * @param pTstEnv Test environment to use for running all tests.
559 */
560int audioTestWorker(PAUDIOTESTENV pTstEnv)
561{
562 int rc = VINF_SUCCESS;
563
564 if (pTstEnv->enmMode == AUDIOTESTMODE_GUEST)
565 {
566 RTTestPrintf(g_hTest, RTTESTLVL_ALWAYS, "Guest ATS running\n");
567
568 while (!g_fTerminate)
569 RTThreadSleep(100);
570
571 RTTestPrintf(g_hTest, RTTESTLVL_ALWAYS, "Shutting down guest ATS ...\n");
572
573 int rc2 = AudioTestSvcStop(pTstEnv->pSrv);
574 if (RT_SUCCESS(rc))
575 rc = rc2;
576
577 RTTestPrintf(g_hTest, RTTESTLVL_ALWAYS, "Guest ATS shutdown complete\n");
578 }
579 else if (pTstEnv->enmMode == AUDIOTESTMODE_HOST)
580 {
581 RTTestPrintf(g_hTest, RTTESTLVL_ALWAYS, "Using tag '%s'\n", pTstEnv->szTag);
582
583 RTTestPrintf(g_hTest, RTTESTLVL_ALWAYS, "Telling ValKit audio driver on host to begin a new test set ...\n");
584 rc = AudioTestSvcClientTestSetBegin(&pTstEnv->u.Host.AtsClValKit, pTstEnv->szTag);
585 if (RT_SUCCESS(rc))
586 {
587 RTTestPrintf(g_hTest, RTTESTLVL_ALWAYS, "Telling VKAT on guest to begin a new test set ...\n");
588 rc = AudioTestSvcClientTestSetBegin(&pTstEnv->u.Host.AtsClGuest, pTstEnv->szTag);
589 if (RT_FAILURE(rc))
590 RTTestPrintf(g_hTest, RTTESTLVL_ALWAYS,
591 "Beginning test set on guest failed with %Rrc\n", rc);
592 }
593 else
594 RTTestPrintf(g_hTest, RTTESTLVL_ALWAYS,
595 "Beginning test set on host (Validation Kit audio driver) failed with %Rrc\n", rc);
596
597 if (RT_SUCCESS(rc))
598 {
599 for (unsigned i = 0; i < RT_ELEMENTS(g_aTests); i++)
600 {
601 int rc2 = audioTestOne(pTstEnv, &g_aTests[i]);
602 if (RT_SUCCESS(rc))
603 rc = rc2;
604
605 if (g_fTerminate)
606 break;
607 }
608
609 if (RT_SUCCESS(rc))
610 {
611 /** @todo Fudge! */
612 RTMSINTERVAL const msWait = RTRandU32Ex(RT_MS_1SEC, RT_MS_5SEC);
613 RTTestPrintf(g_hTest, RTTESTLVL_ALWAYS,
614 "Waiting %RU32ms to let guest and the audio stack process remaining data ...\n", msWait);
615 RTThreadSleep(msWait);
616 }
617
618 RTTestPrintf(g_hTest, RTTESTLVL_ALWAYS, "Ending test set on guest ...\n");
619 int rc2 = AudioTestSvcClientTestSetEnd(&pTstEnv->u.Host.AtsClGuest, pTstEnv->szTag);
620 if (RT_FAILURE(rc2))
621 {
622 RTTestPrintf(g_hTest, RTTESTLVL_ALWAYS, "Ending test set on guest failed with %Rrc\n", rc2);
623 if (RT_SUCCESS(rc))
624 rc = rc2;
625 }
626
627 RTTestPrintf(g_hTest, RTTESTLVL_ALWAYS, "Ending test set on host (Validation Kit audio driver) ...\n");
628 rc2 = AudioTestSvcClientTestSetEnd(&pTstEnv->u.Host.AtsClValKit, pTstEnv->szTag);
629 if (RT_FAILURE(rc2))
630 {
631 RTTestPrintf(g_hTest, RTTESTLVL_ALWAYS,
632 "Ending test set on host (Validation Kit audio driver) failed with %Rrc\n", rc2);
633 if (RT_SUCCESS(rc))
634 rc = rc2;
635 }
636
637 if ( !g_fTerminate
638 && RT_SUCCESS(rc))
639 {
640 /*
641 * Download guest + Validation Kit audio driver test sets to our output directory.
642 */
643 char szFileName[RTPATH_MAX];
644 if (RTStrPrintf2(szFileName, sizeof(szFileName), "%s-guest.tar.gz", pTstEnv->szTag))
645 {
646 rc = RTPathJoin(pTstEnv->u.Host.szPathTestSetGuest, sizeof(pTstEnv->u.Host.szPathTestSetGuest),
647 pTstEnv->szPathOut, szFileName);
648 if (RT_SUCCESS(rc))
649 {
650 if (RTStrPrintf2(szFileName, sizeof(szFileName), "%s-host.tar.gz", pTstEnv->szTag))
651 {
652 rc = RTPathJoin(pTstEnv->u.Host.szPathTestSetValKit, sizeof(pTstEnv->u.Host.szPathTestSetValKit),
653 pTstEnv->szPathOut, szFileName);
654 }
655 else
656 rc = VERR_BUFFER_OVERFLOW;
657 }
658 else
659 rc = VERR_BUFFER_OVERFLOW;
660
661 if (RT_SUCCESS(rc))
662 {
663 RTTestPrintf(g_hTest, RTTESTLVL_ALWAYS, "Downloading guest test set to '%s'\n",
664 pTstEnv->u.Host.szPathTestSetGuest);
665 rc = AudioTestSvcClientTestSetDownload(&pTstEnv->u.Host.AtsClGuest,
666 pTstEnv->szTag, pTstEnv->u.Host.szPathTestSetGuest);
667 }
668
669 if (RT_SUCCESS(rc))
670 {
671 RTTestPrintf(g_hTest, RTTESTLVL_ALWAYS, "Downloading host test set to '%s'\n",
672 pTstEnv->u.Host.szPathTestSetValKit);
673 rc = AudioTestSvcClientTestSetDownload(&pTstEnv->u.Host.AtsClValKit,
674 pTstEnv->szTag, pTstEnv->u.Host.szPathTestSetValKit);
675 }
676 }
677 else
678 rc = VERR_BUFFER_OVERFLOW;
679
680 if ( RT_SUCCESS(rc)
681 && !pTstEnv->fSkipVerify)
682 {
683 rc = audioVerifyOne(pTstEnv->u.Host.szPathTestSetGuest, pTstEnv->u.Host.szPathTestSetValKit, NULL /* pOpts */);
684 }
685 else
686 RTTestPrintf(g_hTest, RTTESTLVL_ALWAYS, "Verification skipped\n");
687
688 if (!pTstEnv->fSkipVerify)
689 {
690 RTFileDelete(pTstEnv->u.Host.szPathTestSetGuest);
691 RTFileDelete(pTstEnv->u.Host.szPathTestSetValKit);
692 }
693 else
694 RTTestPrintf(g_hTest, RTTESTLVL_ALWAYS, "Leaving test set files behind\n");
695 }
696 }
697 }
698 else
699 rc = VERR_NOT_IMPLEMENTED;
700
701 /* Clean up. */
702 RTDirRemove(pTstEnv->szPathTemp);
703 RTDirRemove(pTstEnv->szPathOut);
704
705 if (RT_FAILURE(rc))
706 RTTestFailed(g_hTest, "Test worker failed with %Rrc", rc);
707
708 return rc;
709}
710
711/** Option help for the 'test' command. */
712static DECLCALLBACK(const char *) audioTestCmdTestHelp(PCRTGETOPTDEF pOpt)
713{
714 switch (pOpt->iShort)
715 {
716 case 'a': return "Exclude all tests from the list (useful to enable single tests later with --include)";
717 case 'b': return "The audio backend to use";
718 case 'd': return "Go via DrvAudio instead of directly interfacing with the backend";
719 case 'e': return "Exclude the given test id from the list";
720 case 'i': return "Include the given test id in the list";
721 case VKAT_TEST_OPT_COUNT: return "Number of test iterations to perform for selected tests\n"
722 " Default: random number";
723 case VKAT_TEST_OPT_DEV: return "Name of the input/output device to use\n"
724 " Default: default device";
725 case VKAT_TEST_OPT_TONE_DURATION_MS: return "Test tone duration to play / record (ms)\n"
726 " Default: random duration";
727 case VKAT_TEST_OPT_TONE_VOL_PERCENT: return "Test tone volume (percent)\n"
728 " Default: 100";
729 case VKAT_TEST_OPT_GUEST_ATS_ADDR: return "Address of guest ATS to connect to\n"
730 " Default: " ATS_TCP_DEF_CONNECT_GUEST_STR;
731 case VKAT_TEST_OPT_GUEST_ATS_PORT: return "Port of guest ATS to connect to (needs NAT port forwarding)\n"
732 " Default: 6042"; /* ATS_TCP_DEF_CONNECT_PORT_GUEST */
733 case VKAT_TEST_OPT_HOST_ATS_ADDR: return "Address of host ATS to connect to\n"
734 " Default: " ATS_TCP_DEF_CONNECT_HOST_ADDR_STR;
735 case VKAT_TEST_OPT_HOST_ATS_PORT: return "Port of host ATS to connect to\n"
736 " Default: 6052"; /* ATS_TCP_DEF_BIND_PORT_VALKIT */
737 case VKAT_TEST_OPT_MODE: return "Test mode to use when running the tests\n"
738 " Available modes:\n"
739 " guest: Run as a guest-side ATS\n"
740 " host: Run as a host-side ATS";
741 case VKAT_TEST_OPT_NO_AUDIO_OK: return "Enables running without any found audio hardware (e.g. servers)";
742 case VKAT_TEST_OPT_NO_VERIFY: return "Skips the verification step";
743 case VKAT_TEST_OPT_OUTDIR: return "Output directory to use";
744 case VKAT_TEST_OPT_PAUSE: return "Not yet implemented";
745 case VKAT_TEST_OPT_PCM_HZ: return "PCM Hertz (Hz) rate to use\n"
746 " Default: 44100";
747 case VKAT_TEST_OPT_PCM_BIT: return "PCM sample bits (i.e. 16) to use\n"
748 " Default: 16";
749 case VKAT_TEST_OPT_PCM_CHAN: return "PCM channels to use\n"
750 " Default: 2";
751 case VKAT_TEST_OPT_PCM_SIGNED: return "PCM samples to use (signed = true, unsigned = false)\n"
752 " Default: true";
753 case VKAT_TEST_OPT_PROBE_BACKENDS: return "Probes all (available) backends until a working one is found";
754 case VKAT_TEST_OPT_TAG: return "Test set tag to use";
755 case VKAT_TEST_OPT_TEMPDIR: return "Temporary directory to use";
756 case VKAT_TEST_OPT_VOL: return "Audio volume (percent) to use";
757 case VKAT_TEST_OPT_TCP_BIND_ADDRESS: return "TCP address listening to (server mode)";
758 case VKAT_TEST_OPT_TCP_BIND_PORT: return "TCP port listening to (server mode)";
759 case VKAT_TEST_OPT_TCP_CONNECT_ADDRESS: return "TCP address to connect to (client mode)";
760 case VKAT_TEST_OPT_TCP_CONNECT_PORT: return "TCP port to connect to (client mode)";
761 default:
762 break;
763 }
764 return NULL;
765}
766
767/**
768 * Main (entry) function for the testing functionality of VKAT.
769 *
770 * @returns Program exit code.
771 * @param pGetState RTGetOpt state.
772 */
773static DECLCALLBACK(RTEXITCODE) audioTestMain(PRTGETOPTSTATE pGetState)
774{
775 AUDIOTESTENV TstEnv;
776 audioTestEnvInit(&TstEnv);
777
778 int rc;
779
780 PCPDMDRVREG pDrvReg = AudioTestGetDefaultBackend();
781 uint8_t cPcmSampleBit = 0;
782 uint8_t cPcmChannels = 0;
783 uint32_t uPcmHz = 0;
784 bool fPcmSigned = true;
785 bool fProbeBackends = false;
786 bool fNoAudioOk = false;
787
788 const char *pszGuestTcpAddr = NULL;
789 uint16_t uGuestTcpPort = ATS_TCP_DEF_BIND_PORT_GUEST;
790 const char *pszValKitTcpAddr = NULL;
791 uint16_t uValKitTcpPort = ATS_TCP_DEF_BIND_PORT_VALKIT;
792
793 int ch;
794 RTGETOPTUNION ValueUnion;
795 while ((ch = RTGetOpt(pGetState, &ValueUnion)))
796 {
797 switch (ch)
798 {
799 case 'a':
800 for (unsigned i = 0; i < RT_ELEMENTS(g_aTests); i++)
801 g_aTests[i].fExcluded = true;
802 break;
803
804 case 'b':
805 pDrvReg = AudioTestFindBackendOpt(ValueUnion.psz);
806 if (pDrvReg == NULL)
807 return RTEXITCODE_SYNTAX;
808 break;
809
810 case 'd':
811 TstEnv.IoOpts.fWithDrvAudio = true;
812 break;
813
814 case 'e':
815 if (ValueUnion.u32 >= RT_ELEMENTS(g_aTests))
816 return RTMsgErrorExit(RTEXITCODE_SYNTAX, "Invalid test number %u passed to --exclude", ValueUnion.u32);
817 g_aTests[ValueUnion.u32].fExcluded = true;
818 break;
819
820 case VKAT_TEST_OPT_GUEST_ATS_ADDR:
821 pszGuestTcpAddr = ValueUnion.psz;
822 break;
823
824 case VKAT_TEST_OPT_GUEST_ATS_PORT:
825 uGuestTcpPort = ValueUnion.u32;
826 break;
827
828 case VKAT_TEST_OPT_HOST_ATS_ADDR:
829 pszValKitTcpAddr = ValueUnion.psz;
830 break;
831
832 case VKAT_TEST_OPT_HOST_ATS_PORT:
833 uValKitTcpPort = ValueUnion.u32;
834 break;
835
836 case VKAT_TEST_OPT_MODE:
837 if (TstEnv.enmMode != AUDIOTESTMODE_UNKNOWN)
838 return RTMsgErrorExit(RTEXITCODE_SYNTAX, "Test mode (guest / host) already specified");
839 TstEnv.enmMode = RTStrICmp(ValueUnion.psz, "guest") == 0 ? AUDIOTESTMODE_GUEST : AUDIOTESTMODE_HOST;
840 break;
841
842 case VKAT_TEST_OPT_NO_AUDIO_OK:
843 fNoAudioOk = true;
844 break;
845
846 case VKAT_TEST_OPT_NO_VERIFY:
847 TstEnv.fSkipVerify = true;
848 break;
849
850 case 'i':
851 if (ValueUnion.u32 >= RT_ELEMENTS(g_aTests))
852 return RTMsgErrorExit(RTEXITCODE_SYNTAX, "Invalid test number %u passed to --include", ValueUnion.u32);
853 g_aTests[ValueUnion.u32].fExcluded = false;
854 break;
855
856 case VKAT_TEST_OPT_COUNT:
857 TstEnv.cIterations = ValueUnion.u32;
858 break;
859
860 case VKAT_TEST_OPT_DEV:
861 rc = RTStrCopy(TstEnv.szDev, sizeof(TstEnv.szDev), ValueUnion.psz);
862 if (RT_FAILURE(rc))
863 return RTMsgErrorExitFailure("Failed to copy out device: %Rrc", rc);
864 break;
865
866 case VKAT_TEST_OPT_TONE_DURATION_MS:
867 TstEnv.ToneParms.msDuration = ValueUnion.u32;
868 break;
869
870 case VKAT_TEST_OPT_TONE_VOL_PERCENT:
871 TstEnv.ToneParms.uVolumePercent = ValueUnion.u8;
872 break;
873
874 case VKAT_TEST_OPT_PAUSE:
875 return RTMsgErrorExitFailure("Not yet implemented!");
876
877 case VKAT_TEST_OPT_OUTDIR:
878 rc = RTStrCopy(TstEnv.szPathOut, sizeof(TstEnv.szPathOut), ValueUnion.psz);
879 if (RT_FAILURE(rc))
880 return RTMsgErrorExitFailure("Failed to copy out directory: %Rrc", rc);
881 break;
882
883 case VKAT_TEST_OPT_PCM_BIT:
884 cPcmSampleBit = ValueUnion.u8;
885 break;
886
887 case VKAT_TEST_OPT_PCM_CHAN:
888 cPcmChannels = ValueUnion.u8;
889 break;
890
891 case VKAT_TEST_OPT_PCM_HZ:
892 uPcmHz = ValueUnion.u32;
893 break;
894
895 case VKAT_TEST_OPT_PCM_SIGNED:
896 fPcmSigned = ValueUnion.f;
897 break;
898
899 case VKAT_TEST_OPT_PROBE_BACKENDS:
900 fProbeBackends = true;
901 break;
902
903 case VKAT_TEST_OPT_TAG:
904 rc = RTStrCopy(TstEnv.szTag, sizeof(TstEnv.szTag), ValueUnion.psz);
905 if (RT_FAILURE(rc))
906 return RTMsgErrorExit(RTEXITCODE_FAILURE, "Tag invalid, rc=%Rrc", rc);
907 break;
908
909 case VKAT_TEST_OPT_TEMPDIR:
910 rc = RTStrCopy(TstEnv.szPathTemp, sizeof(TstEnv.szPathTemp), ValueUnion.psz);
911 if (RT_FAILURE(rc))
912 return RTMsgErrorExit(RTEXITCODE_FAILURE, "Temp dir invalid, rc=%Rrc", rc);
913 break;
914
915 case VKAT_TEST_OPT_VOL:
916 TstEnv.IoOpts.uVolumePercent = ValueUnion.u8;
917 break;
918
919 case VKAT_TEST_OPT_TCP_BIND_ADDRESS:
920 rc = RTStrCopy(TstEnv.TcpOpts.szBindAddr, sizeof(TstEnv.TcpOpts.szBindAddr), ValueUnion.psz);
921 if (RT_FAILURE(rc))
922 return RTMsgErrorExit(RTEXITCODE_FAILURE, "Bind address invalid, rc=%Rrc", rc);
923 break;
924
925 case VKAT_TEST_OPT_TCP_BIND_PORT:
926 TstEnv.TcpOpts.uBindPort = ValueUnion.u16;
927 break;
928
929 case VKAT_TEST_OPT_TCP_CONNECT_ADDRESS:
930 rc = RTStrCopy(TstEnv.TcpOpts.szConnectAddr, sizeof(TstEnv.TcpOpts.szConnectAddr), ValueUnion.psz);
931 if (RT_FAILURE(rc))
932 return RTMsgErrorExit(RTEXITCODE_FAILURE, "Connect address invalid, rc=%Rrc", rc);
933 break;
934
935 case VKAT_TEST_OPT_TCP_CONNECT_PORT:
936 TstEnv.TcpOpts.uConnectPort = ValueUnion.u16;
937 break;
938
939 AUDIO_TEST_COMMON_OPTION_CASES(ValueUnion, &g_CmdTest);
940
941 default:
942 return RTGetOptPrintError(ch, &ValueUnion);
943 }
944 }
945
946 /*
947 * Start testing.
948 */
949 RTTestBanner(g_hTest);
950
951 if (TstEnv.enmMode == AUDIOTESTMODE_UNKNOWN)
952 return RTMsgErrorExit(RTEXITCODE_SYNTAX, "No test mode (--mode) specified!\n");
953
954 /* Validate TCP options. */
955 if ( TstEnv.TcpOpts.szBindAddr[0]
956 && TstEnv.TcpOpts.szConnectAddr[0])
957 return RTMsgErrorExit(RTEXITCODE_SYNTAX, "Only one TCP connection mode (connect as client *or* bind as server) can be specified) at a time!\n");
958
959 /* Set new (override standard) I/O PCM properties if set by the user. */
960 if ( cPcmSampleBit
961 || cPcmChannels
962 || uPcmHz)
963 {
964 PDMAudioPropsInit(&TstEnv.IoOpts.Props,
965 cPcmSampleBit ? cPcmSampleBit / 2 : 2 /* 16-bit */, fPcmSigned /* fSigned */,
966 cPcmChannels ? cPcmChannels : 2 /* Stereo */, uPcmHz ? uPcmHz : 44100);
967 }
968
969 /* Do this first before everything else below. */
970 rc = AudioTestDriverStackPerformSelftest();
971 if (RT_FAILURE(rc))
972 {
973 if (!fNoAudioOk)
974 return RTMsgErrorExit(RTEXITCODE_FAILURE, "Testing driver stack failed: %Rrc\n", rc);
975 RTTestPrintf(g_hTest, RTTESTLVL_ALWAYS,
976 "Warning: Testing driver stack not possible (%Rrc), but --no-audio-ok was specified. Running on a server without audio hardware?\n", rc);
977 }
978
979 AUDIOTESTDRVSTACK DrvStack;
980 if (fProbeBackends)
981 rc = audioTestDriverStackProbe(&DrvStack, pDrvReg,
982 true /* fEnabledIn */, true /* fEnabledOut */, TstEnv.IoOpts.fWithDrvAudio); /** @todo Make in/out configurable, too. */
983 else
984 rc = audioTestDriverStackInitEx(&DrvStack, pDrvReg,
985 true /* fEnabledIn */, true /* fEnabledOut */, TstEnv.IoOpts.fWithDrvAudio); /** @todo Make in/out configurable, too. */
986 if (RT_FAILURE(rc))
987 {
988 if (!fNoAudioOk)
989 return RTMsgErrorExit(RTEXITCODE_FAILURE, "Unable to init driver stack: %Rrc\n", rc);
990 RTTestPrintf(g_hTest, RTTESTLVL_ALWAYS,
991 "Warning: Initializing driver stack not possible (%Rrc), but --no-audio-ok was specified. Running on a server without audio hardware?\n", rc);
992 }
993
994 PPDMAUDIOHOSTDEV pDev;
995 rc = audioTestDevicesEnumerateAndCheck(&DrvStack, TstEnv.szDev, &pDev);
996 if (RT_FAILURE(rc))
997 {
998 if (!fNoAudioOk)
999 return RTMsgErrorExit(RTEXITCODE_FAILURE, "Enumerating device(s) failed: %Rrc\n", rc);
1000 }
1001
1002 /* For now all tests have the same test environment and driver stack. */
1003 rc = audioTestEnvCreate(&TstEnv, &DrvStack);
1004 if (RT_SUCCESS(rc))
1005 rc = audioTestWorker(&TstEnv);
1006
1007 audioTestEnvDestroy(&TstEnv);
1008 audioTestDriverStackDelete(&DrvStack);
1009
1010 if (RT_FAILURE(rc)) /* Let us know that something went wrong in case we forgot to mention it. */
1011 RTTestFailed(g_hTest, "Testing failed with %Rrc\n", rc);
1012
1013 /*
1014 * Print summary and exit.
1015 */
1016 return RTTestSummaryAndDestroy(g_hTest);
1017}
1018
1019
1020const VKATCMD g_CmdTest =
1021{
1022 "test",
1023 audioTestMain,
1024 "Runs audio tests and creates an audio test set.",
1025 g_aCmdTestOptions,
1026 RT_ELEMENTS(g_aCmdTestOptions),
1027 audioTestCmdTestHelp,
1028 true /* fNeedsTransport */
1029};
1030
1031
1032/*********************************************************************************************************************************
1033* Command: verify *
1034*********************************************************************************************************************************/
1035
1036static int audioVerifyOpenTestSet(const char *pszPathSet, PAUDIOTESTSET pSet)
1037{
1038 int rc;
1039
1040 char szPathExtracted[RTPATH_MAX];
1041
1042 RTTestPrintf(g_hTest, RTTESTLVL_ALWAYS, "Opening test set '%s'\n", pszPathSet);
1043
1044 const bool fPacked = AudioTestSetIsPacked(pszPathSet);
1045
1046 if (fPacked)
1047 {
1048 RTTestPrintf(g_hTest, RTTESTLVL_ALWAYS, "Test set is an archive and needs to be unpacked\n");
1049
1050 if (!RTFileExists(pszPathSet))
1051 {
1052 RTTestPrintf(g_hTest, RTTESTLVL_ALWAYS, "Test set '%s' does not exist\n", pszPathSet);
1053 rc = VERR_FILE_NOT_FOUND;
1054 }
1055 else
1056 rc = VINF_SUCCESS;
1057
1058 if (RT_SUCCESS(rc))
1059 {
1060 char szPathTemp[RTPATH_MAX];
1061 rc = RTPathTemp(szPathTemp, sizeof(szPathTemp));
1062 if (RT_SUCCESS(rc))
1063 {
1064 RTTestPrintf(g_hTest, RTTESTLVL_ALWAYS, "Using temporary directory '%s'\n", szPathTemp);
1065
1066 rc = RTPathJoin(szPathExtracted, sizeof(szPathExtracted), szPathTemp, "vkat-testset-XXXX");
1067 if (RT_SUCCESS(rc))
1068 {
1069 rc = RTDirCreateTemp(szPathExtracted, 0755);
1070 if (RT_SUCCESS(rc))
1071 {
1072 RTTestPrintf(g_hTest, RTTESTLVL_ALWAYS, "Unpacking archive to '%s'\n", szPathExtracted);
1073 rc = AudioTestSetUnpack(pszPathSet, szPathExtracted);
1074 if (RT_SUCCESS(rc))
1075 RTTestPrintf(g_hTest, RTTESTLVL_ALWAYS, "Archive successfully unpacked\n");
1076 }
1077 }
1078 }
1079 }
1080 }
1081 else
1082 rc = VINF_SUCCESS;
1083
1084 if (RT_SUCCESS(rc))
1085 rc = AudioTestSetOpen(pSet, fPacked ? szPathExtracted : pszPathSet);
1086
1087 if (RT_FAILURE(rc))
1088 RTTestFailed(g_hTest, "Unable to open / unpack test set archive: %Rrc", rc);
1089
1090 return rc;
1091}
1092
1093/**
1094 * Verifies one test set pair.
1095 *
1096 * @returns VBox status code.
1097 * @param pszPathSetA Absolute path to test set A.
1098 * @param pszPathSetB Absolute path to test set B.
1099 * @param pOpts Verification options to use. Optional.
1100 * When NULL, the (very strict) defaults will be used.
1101 */
1102static int audioVerifyOne(const char *pszPathSetA, const char *pszPathSetB, PAUDIOTESTVERIFYOPTS pOpts)
1103{
1104 RTTestSubF(g_hTest, "Verifying");
1105 RTTestPrintf(g_hTest, RTTESTLVL_ALWAYS, "Verifying test set '%s' with test set '%s'\n", pszPathSetA, pszPathSetB);
1106
1107 AUDIOTESTSET SetA, SetB;
1108 int rc = audioVerifyOpenTestSet(pszPathSetA, &SetA);
1109 if (RT_SUCCESS(rc))
1110 {
1111 rc = audioVerifyOpenTestSet(pszPathSetB, &SetB);
1112 if (RT_SUCCESS(rc))
1113 {
1114 AUDIOTESTERRORDESC errDesc;
1115 if (pOpts)
1116 rc = AudioTestSetVerifyEx(&SetA, &SetB, pOpts, &errDesc);
1117 else
1118 rc = AudioTestSetVerify(&SetA, &SetB, &errDesc);
1119 if (RT_SUCCESS(rc))
1120 {
1121 uint32_t const cErr = AudioTestErrorDescCount(&errDesc);
1122 RTTestPrintf(g_hTest, RTTESTLVL_ALWAYS, "%RU32 errors occurred while verifying\n", cErr);
1123
1124 /** @todo Use some AudioTestErrorXXX API for enumeration here later. */
1125 PAUDIOTESTERRORENTRY pErrEntry;
1126 RTListForEach(&errDesc.List, pErrEntry, AUDIOTESTERRORENTRY, Node)
1127 {
1128 if (RT_FAILURE(pErrEntry->rc))
1129 RTTestFailed(g_hTest, "%s\n", pErrEntry->szDesc);
1130 else
1131 RTTestPrintf(g_hTest, RTTESTLVL_ALWAYS, "%s\n", pErrEntry->szDesc);
1132 }
1133
1134 if (cErr == 0)
1135 RTTestPrintf(g_hTest, RTTESTLVL_ALWAYS, "Verification successful\n");
1136
1137 AudioTestErrorDescDestroy(&errDesc);
1138 }
1139 else
1140 RTTestFailed(g_hTest, "Verification failed with %Rrc", rc);
1141
1142#ifdef DEBUG
1143 if (g_fDrvAudioDebug)
1144 RTTestPrintf(g_hTest, RTTESTLVL_ALWAYS,
1145 "\n"
1146 "Use the following command line to re-run verification in the debugger:\n"
1147 "gdb --args ./VBoxAudioTest -vvvv --debug-audio verify \"%s\" \"%s\"\n",
1148 SetA.szPathAbs, SetB.szPathAbs);
1149#endif
1150 if (!g_fDrvAudioDebug) /* Don't wipe stuff when debugging. Can be useful for introspecting data. */
1151 AudioTestSetWipe(&SetB);
1152 AudioTestSetClose(&SetB);
1153 }
1154
1155 if (!g_fDrvAudioDebug) /* Ditto. */
1156 AudioTestSetWipe(&SetA);
1157 AudioTestSetClose(&SetA);
1158 }
1159
1160 RTTestSubDone(g_hTest);
1161
1162 return rc;
1163}
1164
1165/** Option help for the 'verify' command. */
1166static DECLCALLBACK(const char *) audioTestCmdVerifyHelp(PCRTGETOPTDEF pOpt)
1167{
1168 switch (pOpt->iShort)
1169 {
1170 case VKAT_VERIFY_OPT_MAX_DIFF_COUNT: return "Specifies the maximum number of differences\n"
1171 " Default: 0 (strict)";
1172 case VKAT_VERIFY_OPT_MAX_DIFF_PERCENT: return "Specifies the maximum difference (percent)\n"
1173 " Default: 0 (strict)";
1174 case VKAT_VERIFY_OPT_MAX_SIZE_PERCENT: return "Specifies the maximum size difference (percent)\n"
1175 " Default: 1 (strict)";
1176 case VKAT_VERIFY_OPT_NORMALIZE: return "Enables / disables audio data normalization\n"
1177 " Default: false";
1178 default:
1179 break;
1180 }
1181 return NULL;
1182}
1183
1184/**
1185 * Main (entry) function for the verification functionality of VKAT.
1186 *
1187 * @returns Program exit code.
1188 * @param pGetState RTGetOpt state.
1189 */
1190static DECLCALLBACK(RTEXITCODE) audioVerifyMain(PRTGETOPTSTATE pGetState)
1191{
1192 /*
1193 * Parse options and process arguments.
1194 */
1195 const char *apszSets[2] = { NULL, NULL };
1196 unsigned iTestSet = 0;
1197
1198 AUDIOTESTVERIFYOPTS Opts;
1199 AudioTestSetVerifyOptsInit(&Opts);
1200
1201 int ch;
1202 RTGETOPTUNION ValueUnion;
1203 while ((ch = RTGetOpt(pGetState, &ValueUnion)))
1204 {
1205 switch (ch)
1206 {
1207 case VKAT_VERIFY_OPT_MAX_DIFF_COUNT:
1208 Opts.cMaxDiff = ValueUnion.u32;
1209 break;
1210
1211 case VKAT_VERIFY_OPT_MAX_DIFF_PERCENT:
1212 Opts.uMaxDiffPercent = ValueUnion.u8;
1213 break;
1214
1215 case VKAT_VERIFY_OPT_MAX_SIZE_PERCENT:
1216 Opts.uMaxSizePercent = ValueUnion.u8;
1217 break;
1218
1219 case VKAT_VERIFY_OPT_NORMALIZE:
1220 Opts.fNormalize = ValueUnion.f;
1221 break;
1222
1223 case VINF_GETOPT_NOT_OPTION:
1224 if (iTestSet == 0)
1225 RTTestBanner(g_hTest);
1226 if (iTestSet >= RT_ELEMENTS(apszSets))
1227 return RTMsgErrorExitFailure("Only two test sets can be verified at one time");
1228 apszSets[iTestSet++] = ValueUnion.psz;
1229 break;
1230
1231 AUDIO_TEST_COMMON_OPTION_CASES(ValueUnion, &g_CmdVerify);
1232
1233 default:
1234 return RTGetOptPrintError(ch, &ValueUnion);
1235 }
1236 }
1237
1238 if (!iTestSet)
1239 return RTMsgErrorExitFailure("At least one test set must be specified");
1240
1241 int rc = VINF_SUCCESS;
1242
1243 /*
1244 * If only test set A is given, default to the current directory
1245 * for test set B.
1246 */
1247 char szDirCur[RTPATH_MAX];
1248 if (iTestSet == 1)
1249 {
1250 rc = RTPathGetCurrent(szDirCur, sizeof(szDirCur));
1251 if (RT_SUCCESS(rc))
1252 apszSets[1] = szDirCur;
1253 else
1254 RTTestFailed(g_hTest, "Failed to retrieve current directory: %Rrc", rc);
1255 }
1256
1257 if (RT_SUCCESS(rc))
1258 audioVerifyOne(apszSets[0], apszSets[1], &Opts);
1259
1260 /*
1261 * Print summary and exit.
1262 */
1263 return RTTestSummaryAndDestroy(g_hTest);
1264}
1265
1266
1267const VKATCMD g_CmdVerify =
1268{
1269 "verify",
1270 audioVerifyMain,
1271 "Verifies a formerly created audio test set.",
1272 g_aCmdVerifyOptions,
1273 RT_ELEMENTS(g_aCmdVerifyOptions),
1274 audioTestCmdVerifyHelp,
1275 false /* fNeedsTransport */
1276};
1277
1278
1279/*********************************************************************************************************************************
1280* Main *
1281*********************************************************************************************************************************/
1282
1283/**
1284 * Ctrl-C signal handler.
1285 *
1286 * This just sets g_fTerminate and hope it will be noticed soon.
1287 *
1288 * On non-Windows it restores the SIGINT action to default, so that a second
1289 * Ctrl-C will have the normal effect (just in case the code doesn't respond to
1290 * g_fTerminate).
1291 */
1292#ifdef RT_OS_WINDOWS
1293static BOOL CALLBACK audioTestConsoleCtrlHandler(DWORD dwCtrlType) RT_NOEXCEPT
1294{
1295 if (dwCtrlType != CTRL_C_EVENT && dwCtrlType != CTRL_BREAK_EVENT)
1296 return false;
1297 RTPrintf(dwCtrlType == CTRL_C_EVENT ? "Ctrl-C!\n" : "Ctrl-Break!\n");
1298
1299 ASMAtomicWriteBool(&g_fTerminate, true);
1300
1301 return true;
1302}
1303#else
1304static void audioTestSignalHandler(int iSig) RT_NOEXCEPT
1305{
1306 Assert(iSig == SIGINT); RT_NOREF(iSig);
1307 RTPrintf("Ctrl-C!\n");
1308
1309 ASMAtomicWriteBool(&g_fTerminate, true);
1310
1311 signal(SIGINT, SIG_DFL);
1312}
1313#endif
1314
1315/**
1316 * Commands.
1317 */
1318static const VKATCMD * const g_apCommands[] =
1319{
1320 &g_CmdTest,
1321 &g_CmdVerify,
1322 &g_CmdBackends,
1323 &g_CmdEnum,
1324 &g_CmdPlay,
1325 &g_CmdRec,
1326 &g_CmdSelfTest
1327};
1328
1329/**
1330 * Shows tool usage text.
1331 */
1332RTEXITCODE audioTestUsage(PRTSTREAM pStrm, PCVKATCMD pOnlyCmd)
1333{
1334 RTStrmPrintf(pStrm, "usage: %s [global options] <command> [command-options]\n", RTProcShortName());
1335 RTStrmPrintf(pStrm,
1336 "\n"
1337 "Global Options:\n"
1338 " --debug-audio\n"
1339 " Enables (DrvAudio) debugging\n"
1340 " --debug-audio-path=<path>\n"
1341 " Tells DrvAudio where to put its debug output (wav-files)\n"
1342 " -q, --quiet\n"
1343 " Sets verbosity to zero\n"
1344 " -v, --verbose\n"
1345 " Increase verbosity\n"
1346 " -V, --version\n"
1347 " Displays version\n"
1348 " -h, -?, --help\n"
1349 " Displays help\n"
1350 );
1351
1352 for (uintptr_t iCmd = 0; iCmd < RT_ELEMENTS(g_apCommands); iCmd++)
1353 {
1354 PCVKATCMD const pCmd = g_apCommands[iCmd];
1355 if (!pOnlyCmd || pCmd == pOnlyCmd)
1356 {
1357 RTStrmPrintf(pStrm,
1358 "\n"
1359 "Command '%s':\n"
1360 " %s\n"
1361 "Options for '%s':\n",
1362 pCmd->pszCommand, pCmd->pszDesc, pCmd->pszCommand);
1363 PCRTGETOPTDEF const paOptions = pCmd->paOptions;
1364 for (unsigned i = 0; i < pCmd->cOptions; i++)
1365 {
1366 if (RT_C_IS_PRINT(paOptions[i].iShort))
1367 RTStrmPrintf(pStrm, " -%c, %s\n", paOptions[i].iShort, paOptions[i].pszLong);
1368 else
1369 RTStrmPrintf(pStrm, " %s\n", paOptions[i].pszLong);
1370
1371 const char *pszHelp = NULL;
1372 if (pCmd->pfnOptionHelp)
1373 pszHelp = pCmd->pfnOptionHelp(&paOptions[i]);
1374 if (pszHelp)
1375 RTStrmPrintf(pStrm, " %s\n", pszHelp);
1376 }
1377
1378 if (pCmd->fNeedsTransport)
1379 for (uintptr_t iTx = 0; iTx < g_cTransports; iTx++)
1380 g_apTransports[iTx]->pfnUsage(pStrm);
1381 }
1382 }
1383
1384 return RTEXITCODE_SUCCESS;
1385}
1386
1387/**
1388 * Lists the commands and their descriptions.
1389 */
1390static RTEXITCODE audioTestListCommands(PRTSTREAM pStrm)
1391{
1392 RTStrmPrintf(pStrm, "Commands:\n");
1393 for (uintptr_t iCmd = 0; iCmd < RT_ELEMENTS(g_apCommands); iCmd++)
1394 RTStrmPrintf(pStrm, "%8s - %s\n", g_apCommands[iCmd]->pszCommand, g_apCommands[iCmd]->pszDesc);
1395 return RTEXITCODE_SUCCESS;
1396}
1397
1398/**
1399 * Shows tool version.
1400 */
1401RTEXITCODE audioTestVersion(void)
1402{
1403 RTPrintf("%s\n", RTBldCfgRevisionStr());
1404 return RTEXITCODE_SUCCESS;
1405}
1406
1407/**
1408 * Shows the logo.
1409 *
1410 * @param pStream Output stream to show logo on.
1411 */
1412void audioTestShowLogo(PRTSTREAM pStream)
1413{
1414 RTStrmPrintf(pStream, VBOX_PRODUCT " VKAT (Validation Kit Audio Test) Version " VBOX_VERSION_STRING " - r%s\n"
1415 "Copyright (C) " VBOX_C_YEAR " " VBOX_VENDOR "\n\n", RTBldCfgRevisionStr());
1416}
1417
1418int main(int argc, char **argv)
1419{
1420 /*
1421 * Init IPRT.
1422 */
1423 int rc = RTR3InitExe(argc, &argv, 0);
1424 if (RT_FAILURE(rc))
1425 return RTMsgInitFailure(rc);
1426
1427 /*
1428 * Handle special command line options which need parsing before
1429 * everything else.
1430 */
1431 /** @todo r=bird: this isn't at all syntactically sane, because you don't know
1432 * how to parse past the command (can almost be done safely thought, since
1433 * you've got the option definitions for every command at hand). So, if someone
1434 * wants to play a file named "-v.wav", you'll incorrectly take that as two 'v'
1435 * options. The parsing has to stop when you get to the command, i.e. first
1436 * VINF_GETOPT_NOT_OPTION or anything that isn't a common option. Daemonizing
1437 * when for instance encountering an invalid command, is not correct.
1438 *
1439 * Btw. you MUST however process the 'q' option in parallel to 'v' here, they
1440 * are oposites. For instance '-vqvvv' is supposed to give you level 3 logging,
1441 * not quiet! So, either you process both 'v' and 'q' here, or you pospone them
1442 * (better option).
1443 */
1444 /** @todo r=bird: Is the daemonizing needed? The testcase doesn't seem to use
1445 * it... If you don't need it, drop it as it make the parsing complex
1446 * and illogical. The --daemonized / --damonize options should be
1447 * required to before the command, then okay. */
1448 bool fDaemonize = false;
1449 bool fDaemonized = false;
1450
1451 RTGETOPTSTATE GetState;
1452 rc = RTGetOptInit(&GetState, argc, argv, g_aCmdCommonOptions,
1453 RT_ELEMENTS(g_aCmdCommonOptions), 1 /*idxFirst*/, 0 /*fFlags - must not sort! */);
1454 AssertRCReturn(rc, RTEXITCODE_INIT);
1455
1456 int ch;
1457 RTGETOPTUNION ValueUnion;
1458 while ((ch = RTGetOpt(&GetState, &ValueUnion)) != 0)
1459 {
1460 switch (ch)
1461 {
1462 case AUDIO_TEST_OPT_CMN_DAEMONIZE:
1463 fDaemonize = true;
1464 break;
1465
1466 case AUDIO_TEST_OPT_CMN_DAEMONIZED:
1467 fDaemonized = true;
1468 break;
1469
1470 /* Has to be defined here and not in AUDIO_TEST_COMMON_OPTION_CASES, to get the logger
1471 * configured before the specific command handlers down below come into play. */
1472 case 'v':
1473 g_uVerbosity++;
1474 break;
1475
1476 default:
1477 break;
1478 }
1479 }
1480
1481 /** @todo add something to suppress this stuff. */
1482 audioTestShowLogo(g_pStdOut);
1483
1484 if (fDaemonize)
1485 {
1486 if (!fDaemonized)
1487 {
1488 rc = RTProcDaemonize(argv, "--daemonized");
1489 if (RT_FAILURE(rc))
1490 return RTMsgErrorExit(RTEXITCODE_FAILURE, "RTProcDaemonize() failed with %Rrc\n", rc);
1491
1492 RTMsgInfo("Starting in background (daemonizing) ...");
1493 return RTEXITCODE_SUCCESS;
1494 }
1495 /* else continue running in background. */
1496 }
1497
1498 /*
1499 * Init test and globals.
1500 * Note: Needs to be done *after* daemonizing, otherwise the child will fail!
1501 */
1502 rc = RTTestCreate("AudioTest", &g_hTest);
1503 if (RT_FAILURE(rc))
1504 return RTMsgErrorExit(RTEXITCODE_FAILURE, "RTTestCreate() failed with %Rrc\n", rc);
1505
1506#ifdef RT_OS_WINDOWS
1507 HRESULT hrc = CoInitializeEx(NULL /*pReserved*/, COINIT_MULTITHREADED | COINIT_SPEED_OVER_MEMORY | COINIT_DISABLE_OLE1DDE);
1508 if (FAILED(hrc))
1509 RTMsgWarning("CoInitializeEx failed: %#x", hrc);
1510#endif
1511
1512 /*
1513 * Configure release logging to go to stdout.
1514 */
1515 RTUINT fFlags = RTLOGFLAGS_PREFIX_THREAD | RTLOGFLAGS_PREFIX_TIME_PROG;
1516#if defined(RT_OS_WINDOWS) || defined(RT_OS_OS2)
1517 fFlags |= RTLOGFLAGS_USECRLF;
1518#endif
1519 static const char * const s_apszLogGroups[] = VBOX_LOGGROUP_NAMES;
1520 rc = RTLogCreate(&g_pRelLogger, fFlags, "all.e.l", "VKAT_RELEASE_LOG",
1521 RT_ELEMENTS(s_apszLogGroups), s_apszLogGroups, RTLOGDEST_STDOUT, NULL /*"vkat-release.log"*/);
1522 if (RT_SUCCESS(rc))
1523 {
1524 RTLogRelSetDefaultInstance(g_pRelLogger);
1525 if (g_uVerbosity)
1526 {
1527 RTMsgInfo("Setting verbosity logging to level %u\n", g_uVerbosity);
1528 switch (g_uVerbosity) /* Not very elegant, but has to do it for now. */
1529 {
1530 case 1:
1531 rc = RTLogGroupSettings(g_pRelLogger,
1532 "drv_audio.e.l+drv_host_audio.e.l+"
1533 "audio_mixer.e.l+audio_test.e.l");
1534 break;
1535
1536 case 2:
1537 rc = RTLogGroupSettings(g_pRelLogger,
1538 "drv_audio.e.l.l2+drv_host_audio.e.l.l2+"
1539 "audio_mixer.e.l.l2+audio_test.e.l.l2");
1540 break;
1541
1542 case 3:
1543 rc = RTLogGroupSettings(g_pRelLogger,
1544 "drv_audio.e.l.l2.l3+drv_host_audio.e.l.l2.l3+"
1545 "audio_mixer.e.l.l2.l3+audio_test.e.l.l2.l3");
1546 break;
1547
1548 case 4:
1549 RT_FALL_THROUGH();
1550 default:
1551 rc = RTLogGroupSettings(g_pRelLogger,
1552 "drv_audio.e.l.l2.l3.l4.f+drv_host_audio.e.l.l2.l3.l4.f+"
1553 "audio_mixer.e.l.l2.l3.l4.f+audio_test.e.l.l2.l3.l4.f");
1554 break;
1555 }
1556 if (RT_FAILURE(rc))
1557 RTMsgError("Setting debug logging failed, rc=%Rrc\n", rc);
1558 }
1559 }
1560 else
1561 RTMsgWarning("Failed to create release logger: %Rrc", rc);
1562
1563 /*
1564 * Install a Ctrl-C signal handler.
1565 */
1566#ifdef RT_OS_WINDOWS
1567 SetConsoleCtrlHandler(audioTestConsoleCtrlHandler, TRUE);
1568#else
1569 struct sigaction sa;
1570 RT_ZERO(sa);
1571 sa.sa_handler = audioTestSignalHandler;
1572 sigaction(SIGINT, &sa, NULL);
1573#endif
1574
1575 /*
1576 * Process common options.
1577 */
1578 RT_ZERO(GetState);
1579 rc = RTGetOptInit(&GetState, argc, argv, g_aCmdCommonOptions,
1580 RT_ELEMENTS(g_aCmdCommonOptions), 1 /*idxFirst*/, 0 /*fFlags - must not sort! */);
1581 AssertRCReturn(rc, RTEXITCODE_INIT);
1582
1583 while ((ch = RTGetOpt(&GetState, &ValueUnion)) != 0)
1584 {
1585 switch (ch)
1586 {
1587 AUDIO_TEST_COMMON_OPTION_CASES(ValueUnion, NULL);
1588
1589 case VINF_GETOPT_NOT_OPTION:
1590 {
1591 for (uintptr_t iCmd = 0; iCmd < RT_ELEMENTS(g_apCommands); iCmd++)
1592 {
1593 PCVKATCMD const pCmd = g_apCommands[iCmd];
1594 if (strcmp(ValueUnion.psz, pCmd->pszCommand) == 0)
1595 {
1596 /* Count the combined option definitions: */
1597 size_t cCombinedOptions = pCmd->cOptions + RT_ELEMENTS(g_aCmdCommonOptions);
1598 if (pCmd->fNeedsTransport)
1599 for (uintptr_t iTx = 0; iTx < g_cTransports; iTx++)
1600 cCombinedOptions += g_apTransports[iTx]->cOpts;
1601
1602 /* Combine the option definitions: */
1603 PRTGETOPTDEF paCombinedOptions = (PRTGETOPTDEF)RTMemAlloc(cCombinedOptions * sizeof(RTGETOPTDEF));
1604 if (paCombinedOptions)
1605 {
1606 uint32_t idxOpts = 0;
1607 memcpy(paCombinedOptions, g_aCmdCommonOptions, sizeof(g_aCmdCommonOptions));
1608 idxOpts += RT_ELEMENTS(g_aCmdCommonOptions);
1609
1610 memcpy(&paCombinedOptions[idxOpts], pCmd->paOptions, pCmd->cOptions * sizeof(RTGETOPTDEF));
1611 idxOpts += (uint32_t)pCmd->cOptions;
1612
1613 if (pCmd->fNeedsTransport)
1614 for (uintptr_t iTx = 0; iTx < g_cTransports; iTx++)
1615 {
1616 memcpy(&paCombinedOptions[idxOpts],
1617 g_apTransports[iTx]->paOpts, g_apTransports[iTx]->cOpts * sizeof(RTGETOPTDEF));
1618 idxOpts += (uint32_t)g_apTransports[iTx]->cOpts;
1619 }
1620
1621 /* Re-initialize the option getter state and pass it to the command handler. */
1622 rc = RTGetOptInit(&GetState, argc, argv, paCombinedOptions, cCombinedOptions,
1623 GetState.iNext /*idxFirst*/, RTGETOPTINIT_FLAGS_OPTS_FIRST);
1624 if (RT_SUCCESS(rc))
1625 {
1626 RTEXITCODE rcExit = pCmd->pfnHandler(&GetState);
1627 RTMemFree(paCombinedOptions);
1628 return rcExit;
1629 }
1630 RTMemFree(paCombinedOptions);
1631 return RTMsgErrorExitFailure("RTGetOptInit failed for '%s': %Rrc", ValueUnion.psz, rc);
1632 }
1633 return RTMsgErrorExitFailure("Out of memory!");
1634 }
1635 }
1636 RTMsgError("Unknown command '%s'!\n", ValueUnion.psz);
1637 audioTestListCommands(g_pStdErr);
1638 return RTEXITCODE_SYNTAX;
1639 }
1640
1641 default:
1642 return RTGetOptPrintError(ch, &ValueUnion);
1643 }
1644 }
1645
1646 RTMsgError("No command specified!\n");
1647 audioTestListCommands(g_pStdErr);
1648 return RTEXITCODE_SYNTAX;
1649}
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