VirtualBox

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

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

Audio/ValKit: Added daemonizing testing support for VKAT / VBoxAudioTest, as TXS (on the guest) does not allow starting programs in the background. bugref:10008

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