VirtualBox

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

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

Audio/VKAT: More code for TCP/IP connection mode handling; don't do things less implicitly but let the caller (or rather test driver) choose how to connect to the guest/host instead. ​bugref:10008

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