VirtualBox

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

Last change on this file since 90507 was 90507, checked in by vboxsync, 3 years ago

Audio/ValKit: More error logging for VKAT. ​bugref:10008

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