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