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