VirtualBox

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

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

Audio/Validation Kit: Added more tweakable options for the audio test set verification and also let the test driver pass through those to VKAT when specified [build fix, forgot a file]. ​bugref:10008

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