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