1 | /* $Id: vkatCommon.cpp 90887 2021-08-25 16:20:14Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * Validation Kit Audio Test (VKAT) - Self test code.
|
---|
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 | #include <iprt/log.h>
|
---|
33 |
|
---|
34 | #include <iprt/ctype.h>
|
---|
35 | #include <iprt/dir.h>
|
---|
36 | #include <iprt/errcore.h>
|
---|
37 | #include <iprt/getopt.h>
|
---|
38 | #include <iprt/message.h>
|
---|
39 | #include <iprt/rand.h>
|
---|
40 | #include <iprt/test.h>
|
---|
41 |
|
---|
42 | #include "Audio/AudioHlp.h"
|
---|
43 | #include "Audio/AudioTest.h"
|
---|
44 | #include "Audio/AudioTestService.h"
|
---|
45 | #include "Audio/AudioTestServiceClient.h"
|
---|
46 |
|
---|
47 | #include "vkatInternal.h"
|
---|
48 |
|
---|
49 |
|
---|
50 | /*********************************************************************************************************************************
|
---|
51 | * Defined Constants And Macros *
|
---|
52 | *********************************************************************************************************************************/
|
---|
53 | /**
|
---|
54 | * Structure for keeping a user context for the test service callbacks.
|
---|
55 | */
|
---|
56 | typedef struct ATSCALLBACKCTX
|
---|
57 | {
|
---|
58 | /** The test environment bound to this context. */
|
---|
59 | PAUDIOTESTENV pTstEnv;
|
---|
60 | /** Absolute path to the packed up test set archive.
|
---|
61 | * Keep it simple for now and only support one (open) archive at a time. */
|
---|
62 | char szTestSetArchive[RTPATH_MAX];
|
---|
63 | /** File handle to the (opened) test set archive for reading. */
|
---|
64 | RTFILE hTestSetArchive;
|
---|
65 | /** Number of currently connected clients. */
|
---|
66 | uint8_t cClients;
|
---|
67 | } ATSCALLBACKCTX;
|
---|
68 | typedef ATSCALLBACKCTX *PATSCALLBACKCTX;
|
---|
69 |
|
---|
70 |
|
---|
71 | /*********************************************************************************************************************************
|
---|
72 | * Internal Functions *
|
---|
73 | *********************************************************************************************************************************/
|
---|
74 | static int audioTestStreamInit(PAUDIOTESTDRVSTACK pDrvStack, PAUDIOTESTSTREAM pStream, PDMAUDIODIR enmDir, PCPDMAUDIOPCMPROPS pProps, bool fWithMixer, uint32_t cMsBufferSize, uint32_t cMsPreBuffer, uint32_t cMsSchedulingHint);
|
---|
75 | static int audioTestStreamDestroy(PAUDIOTESTENV pTstEnv, PAUDIOTESTSTREAM pStream);
|
---|
76 |
|
---|
77 |
|
---|
78 | /*********************************************************************************************************************************
|
---|
79 | * Device enumeration + handling. *
|
---|
80 | *********************************************************************************************************************************/
|
---|
81 |
|
---|
82 | /**
|
---|
83 | * Enumerates audio devices and optionally searches for a specific device.
|
---|
84 | *
|
---|
85 | * @returns VBox status code.
|
---|
86 | * @param pDrvStack Driver stack to use for enumeration.
|
---|
87 | * @param pszDev Device name to search for. Can be NULL if the default device shall be used.
|
---|
88 | * @param ppDev Where to return the pointer of the device enumeration of \a pTstEnv when a
|
---|
89 | * specific device was found.
|
---|
90 | */
|
---|
91 | int audioTestDevicesEnumerateAndCheck(PAUDIOTESTDRVSTACK pDrvStack, const char *pszDev, PPDMAUDIOHOSTDEV *ppDev)
|
---|
92 | {
|
---|
93 | RTTestSubF(g_hTest, "Enumerating audio devices and checking for device '%s'", pszDev && *pszDev ? pszDev : "[Default]");
|
---|
94 |
|
---|
95 | if (!pDrvStack->pIHostAudio->pfnGetDevices)
|
---|
96 | {
|
---|
97 | RTTestSkipped(g_hTest, "Backend does not support device enumeration, skipping");
|
---|
98 | return VINF_NOT_SUPPORTED;
|
---|
99 | }
|
---|
100 |
|
---|
101 | Assert(pszDev == NULL || ppDev);
|
---|
102 |
|
---|
103 | if (ppDev)
|
---|
104 | *ppDev = NULL;
|
---|
105 |
|
---|
106 | int rc = pDrvStack->pIHostAudio->pfnGetDevices(pDrvStack->pIHostAudio, &pDrvStack->DevEnum);
|
---|
107 | if (RT_SUCCESS(rc))
|
---|
108 | {
|
---|
109 | PPDMAUDIOHOSTDEV pDev;
|
---|
110 | RTListForEach(&pDrvStack->DevEnum.LstDevices, pDev, PDMAUDIOHOSTDEV, ListEntry)
|
---|
111 | {
|
---|
112 | char szFlags[PDMAUDIOHOSTDEV_MAX_FLAGS_STRING_LEN];
|
---|
113 | if (pDev->pszId)
|
---|
114 | RTTestPrintf(g_hTest, RTTESTLVL_ALWAYS, "Enum: Device '%s' (ID '%s'):\n", pDev->pszName, pDev->pszId);
|
---|
115 | else
|
---|
116 | RTTestPrintf(g_hTest, RTTESTLVL_ALWAYS, "Enum: Device '%s':\n", pDev->pszName);
|
---|
117 | RTTestPrintf(g_hTest, RTTESTLVL_ALWAYS, "Enum: Usage = %s\n", PDMAudioDirGetName(pDev->enmUsage));
|
---|
118 | RTTestPrintf(g_hTest, RTTESTLVL_ALWAYS, "Enum: Flags = %s\n", PDMAudioHostDevFlagsToString(szFlags, pDev->fFlags));
|
---|
119 | RTTestPrintf(g_hTest, RTTESTLVL_ALWAYS, "Enum: Input channels = %RU8\n", pDev->cMaxInputChannels);
|
---|
120 | RTTestPrintf(g_hTest, RTTESTLVL_ALWAYS, "Enum: Output channels = %RU8\n", pDev->cMaxOutputChannels);
|
---|
121 |
|
---|
122 | if ( (pszDev && *pszDev)
|
---|
123 | && !RTStrCmp(pDev->pszName, pszDev))
|
---|
124 | {
|
---|
125 | *ppDev = pDev;
|
---|
126 | }
|
---|
127 | }
|
---|
128 | }
|
---|
129 | else
|
---|
130 | RTTestFailed(g_hTest, "Enumerating audio devices failed with %Rrc", rc);
|
---|
131 |
|
---|
132 | if (RT_SUCCESS(rc))
|
---|
133 | {
|
---|
134 | if ( (pszDev && *pszDev)
|
---|
135 | && *ppDev == NULL)
|
---|
136 | {
|
---|
137 | RTTestFailed(g_hTest, "Audio device '%s' not found", pszDev);
|
---|
138 | rc = VERR_NOT_FOUND;
|
---|
139 | }
|
---|
140 | }
|
---|
141 |
|
---|
142 | RTTestSubDone(g_hTest);
|
---|
143 | return rc;
|
---|
144 | }
|
---|
145 |
|
---|
146 | static int audioTestStreamInit(PAUDIOTESTDRVSTACK pDrvStack, PAUDIOTESTSTREAM pStream,
|
---|
147 | PDMAUDIODIR enmDir, PCPDMAUDIOPCMPROPS pProps, bool fWithMixer,
|
---|
148 | uint32_t cMsBufferSize, uint32_t cMsPreBuffer, uint32_t cMsSchedulingHint)
|
---|
149 | {
|
---|
150 | int rc;
|
---|
151 |
|
---|
152 | if (enmDir == PDMAUDIODIR_IN)
|
---|
153 | rc = audioTestDriverStackStreamCreateInput(pDrvStack, pProps, cMsBufferSize,
|
---|
154 | cMsPreBuffer, cMsSchedulingHint, &pStream->pStream, &pStream->Cfg);
|
---|
155 | else if (enmDir == PDMAUDIODIR_OUT)
|
---|
156 | rc = audioTestDriverStackStreamCreateOutput(pDrvStack, pProps, cMsBufferSize,
|
---|
157 | cMsPreBuffer, cMsSchedulingHint, &pStream->pStream, &pStream->Cfg);
|
---|
158 | else
|
---|
159 | rc = VERR_NOT_SUPPORTED;
|
---|
160 |
|
---|
161 | if (RT_SUCCESS(rc))
|
---|
162 | {
|
---|
163 | if (!pDrvStack->pIAudioConnector)
|
---|
164 | {
|
---|
165 | pStream->pBackend = &((PAUDIOTESTDRVSTACKSTREAM)pStream->pStream)->Backend;
|
---|
166 | }
|
---|
167 | else
|
---|
168 | pStream->pBackend = NULL;
|
---|
169 |
|
---|
170 | /*
|
---|
171 | * Automatically enable the mixer if the PCM properties don't match.
|
---|
172 | */
|
---|
173 | if ( !fWithMixer
|
---|
174 | && !PDMAudioPropsAreEqual(pProps, &pStream->Cfg.Props))
|
---|
175 | {
|
---|
176 | RTTestPrintf(g_hTest, RTTESTLVL_ALWAYS, "Enabling stream mixer\n");
|
---|
177 | fWithMixer = true;
|
---|
178 | }
|
---|
179 |
|
---|
180 | rc = AudioTestMixStreamInit(&pStream->Mix, pDrvStack, pStream->pStream,
|
---|
181 | fWithMixer ? pProps : NULL, 100 /* ms */); /** @todo Configure mixer buffer? */
|
---|
182 | }
|
---|
183 |
|
---|
184 | if (RT_FAILURE(rc))
|
---|
185 | RTTestFailed(g_hTest, "Initializing %s stream failed with %Rrc", enmDir == PDMAUDIODIR_IN ? "input" : "output", rc);
|
---|
186 |
|
---|
187 | return rc;
|
---|
188 | }
|
---|
189 |
|
---|
190 | /**
|
---|
191 | * Destroys an audio test stream.
|
---|
192 | *
|
---|
193 | * @returns VBox status code.
|
---|
194 | * @param pTstEnv Test environment the stream to destroy contains.
|
---|
195 | * @param pStream Audio stream to destroy.
|
---|
196 | */
|
---|
197 | static int audioTestStreamDestroy(PAUDIOTESTENV pTstEnv, PAUDIOTESTSTREAM pStream)
|
---|
198 | {
|
---|
199 | int rc = VINF_SUCCESS;
|
---|
200 | if (pStream && pStream->pStream)
|
---|
201 | {
|
---|
202 | /** @todo Anything else to do here, e.g. test if there are left over samples or some such? */
|
---|
203 |
|
---|
204 | audioTestDriverStackStreamDestroy(pTstEnv->pDrvStack, pStream->pStream);
|
---|
205 | pStream->pStream = NULL;
|
---|
206 | pStream->pBackend = NULL;
|
---|
207 | }
|
---|
208 |
|
---|
209 | AudioTestMixStreamTerm(&pStream->Mix);
|
---|
210 |
|
---|
211 | return rc;
|
---|
212 | }
|
---|
213 |
|
---|
214 |
|
---|
215 | /*********************************************************************************************************************************
|
---|
216 | * Test Primitives *
|
---|
217 | *********************************************************************************************************************************/
|
---|
218 |
|
---|
219 | #if 0 /* Unused */
|
---|
220 | /**
|
---|
221 | * Returns a random scheduling hint (in ms).
|
---|
222 | */
|
---|
223 | DECLINLINE(uint32_t) audioTestEnvGetRandomSchedulingHint(void)
|
---|
224 | {
|
---|
225 | static const unsigned s_aSchedulingHintsMs[] =
|
---|
226 | {
|
---|
227 | 10,
|
---|
228 | 25,
|
---|
229 | 50,
|
---|
230 | 100,
|
---|
231 | 200,
|
---|
232 | 250
|
---|
233 | };
|
---|
234 |
|
---|
235 | return s_aSchedulingHintsMs[RTRandU32Ex(0, RT_ELEMENTS(s_aSchedulingHintsMs) - 1)];
|
---|
236 | }
|
---|
237 | #endif
|
---|
238 |
|
---|
239 | /**
|
---|
240 | * Plays a test tone on a specific audio test stream.
|
---|
241 | *
|
---|
242 | * @returns VBox status code.
|
---|
243 | * @param pTstEnv Test environment to use for running the test.
|
---|
244 | * Optional and can be NULL (for simple playback only).
|
---|
245 | * @param pStream Stream to use for playing the tone.
|
---|
246 | * @param pParms Tone parameters to use.
|
---|
247 | *
|
---|
248 | * @note Blocking function.
|
---|
249 | */
|
---|
250 | int audioTestPlayTone(PAUDIOTESTENV pTstEnv, PAUDIOTESTSTREAM pStream, PAUDIOTESTTONEPARMS pParms)
|
---|
251 | {
|
---|
252 | AUDIOTESTTONE TstTone;
|
---|
253 | AudioTestToneInit(&TstTone, &pStream->Cfg.Props, pParms->dbFreqHz);
|
---|
254 |
|
---|
255 | char const *pcszPathOut = NULL;
|
---|
256 | if (pTstEnv)
|
---|
257 | pcszPathOut = pTstEnv->Set.szPathAbs;
|
---|
258 |
|
---|
259 | RTTestPrintf(g_hTest, RTTESTLVL_ALWAYS, "Playing test tone (tone frequency is %RU16Hz, %RU32ms)\n", (uint16_t)pParms->dbFreqHz, pParms->msDuration);
|
---|
260 | RTTestPrintf(g_hTest, RTTESTLVL_ALWAYS, "Using %RU32ms stream scheduling hint\n", pStream->Cfg.Device.cMsSchedulingHint);
|
---|
261 | if (pcszPathOut)
|
---|
262 | RTTestPrintf(g_hTest, RTTESTLVL_ALWAYS, "Writing to '%s'\n", pcszPathOut);
|
---|
263 |
|
---|
264 | int rc;
|
---|
265 |
|
---|
266 | /** @todo Use .WAV here? */
|
---|
267 | AUDIOTESTOBJ Obj;
|
---|
268 | RT_ZERO(Obj); /* Shut up MSVC. */
|
---|
269 | if (pTstEnv)
|
---|
270 | {
|
---|
271 | rc = AudioTestSetObjCreateAndRegister(&pTstEnv->Set, "guest-tone-play.pcm", &Obj);
|
---|
272 | AssertRCReturn(rc, rc);
|
---|
273 | }
|
---|
274 |
|
---|
275 | rc = AudioTestMixStreamEnable(&pStream->Mix);
|
---|
276 | if ( RT_SUCCESS(rc)
|
---|
277 | && AudioTestMixStreamIsOkay(&pStream->Mix))
|
---|
278 | {
|
---|
279 | uint8_t abBuf[_4K];
|
---|
280 |
|
---|
281 | uint32_t cbToPlayTotal = PDMAudioPropsMilliToBytes(&pStream->Cfg.Props, pParms->msDuration);
|
---|
282 | AssertStmt(cbToPlayTotal, rc = VERR_INVALID_PARAMETER);
|
---|
283 |
|
---|
284 | RTTestPrintf(g_hTest, RTTESTLVL_DEBUG, "Playing %RU32 bytes total\n", cbToPlayTotal);
|
---|
285 |
|
---|
286 | if (pTstEnv)
|
---|
287 | {
|
---|
288 | AudioTestObjAddMetadataStr(Obj, "stream_to_play_bytes=%RU32\n", cbToPlayTotal);
|
---|
289 | AudioTestObjAddMetadataStr(Obj, "stream_period_size_frames=%RU32\n", pStream->Cfg.Backend.cFramesPeriod);
|
---|
290 | AudioTestObjAddMetadataStr(Obj, "stream_buffer_size_frames=%RU32\n", pStream->Cfg.Backend.cFramesBufferSize);
|
---|
291 | AudioTestObjAddMetadataStr(Obj, "stream_prebuf_size_frames=%RU32\n", pStream->Cfg.Backend.cFramesPreBuffering);
|
---|
292 | /* Note: This mostly is provided by backend (e.g. PulseAudio / ALSA / ++) and
|
---|
293 | * has nothing to do with the device emulation scheduling hint. */
|
---|
294 | AudioTestObjAddMetadataStr(Obj, "device_scheduling_hint_ms=%RU32\n", pStream->Cfg.Device.cMsSchedulingHint);
|
---|
295 | }
|
---|
296 |
|
---|
297 | PAUDIOTESTDRVMIXSTREAM pMix = &pStream->Mix;
|
---|
298 |
|
---|
299 | uint32_t const cbPreBuffer = PDMAudioPropsFramesToBytes(pMix->pProps, pStream->Cfg.Backend.cFramesPreBuffering);
|
---|
300 | uint64_t const nsStarted = RTTimeNanoTS();
|
---|
301 | uint64_t nsDonePreBuffering = 0;
|
---|
302 |
|
---|
303 | uint64_t offStream = 0;
|
---|
304 | uint64_t tsStartMs = RTTimeMilliTS();
|
---|
305 | RTMSINTERVAL uTimeoutMs = pParms->msDuration * 4; /* Four times the time playback should roughly take */
|
---|
306 |
|
---|
307 | while (cbToPlayTotal)
|
---|
308 | {
|
---|
309 | /* Pace ourselves a little. */
|
---|
310 | if (offStream >= cbPreBuffer)
|
---|
311 | {
|
---|
312 | if (!nsDonePreBuffering)
|
---|
313 | nsDonePreBuffering = RTTimeNanoTS();
|
---|
314 | uint64_t const cNsWritten = PDMAudioPropsBytesToNano64(pMix->pProps, offStream - cbPreBuffer);
|
---|
315 | uint64_t const cNsElapsed = RTTimeNanoTS() - nsStarted;
|
---|
316 | if (cNsWritten > cNsElapsed + RT_NS_10MS)
|
---|
317 | RTThreadSleep((cNsWritten - cNsElapsed - RT_NS_10MS / 2) / RT_NS_1MS);
|
---|
318 | }
|
---|
319 |
|
---|
320 | uint32_t cbPlayed = 0;
|
---|
321 | uint32_t const cbCanWrite = AudioTestMixStreamGetWritable(&pStream->Mix);
|
---|
322 | if (cbCanWrite)
|
---|
323 | {
|
---|
324 | uint32_t const cbToGenerate = RT_MIN(RT_MIN(cbToPlayTotal, sizeof(abBuf)), cbCanWrite);
|
---|
325 | uint32_t cbToPlay;
|
---|
326 | rc = AudioTestToneGenerate(&TstTone, abBuf, cbToGenerate, &cbToPlay);
|
---|
327 | if (RT_SUCCESS(rc))
|
---|
328 | {
|
---|
329 | if (pTstEnv)
|
---|
330 | {
|
---|
331 | /* Write stuff to disk before trying to play it. Help analysis later. */
|
---|
332 | rc = AudioTestObjWrite(Obj, abBuf, cbToPlay);
|
---|
333 | }
|
---|
334 | if (RT_SUCCESS(rc))
|
---|
335 | {
|
---|
336 | rc = AudioTestMixStreamPlay(&pStream->Mix, abBuf, cbToPlay, &cbPlayed);
|
---|
337 | if (RT_SUCCESS(rc))
|
---|
338 | {
|
---|
339 | offStream += cbPlayed;
|
---|
340 | }
|
---|
341 | }
|
---|
342 | }
|
---|
343 |
|
---|
344 | if (RT_FAILURE(rc))
|
---|
345 | break;
|
---|
346 | }
|
---|
347 | else if (AudioTestMixStreamIsOkay(&pStream->Mix))
|
---|
348 | RTThreadSleep(RT_MIN(RT_MAX(1, pStream->Cfg.Device.cMsSchedulingHint), 256));
|
---|
349 | else
|
---|
350 | AssertFailedBreakStmt(rc = VERR_AUDIO_STREAM_NOT_READY);
|
---|
351 |
|
---|
352 | Assert(cbToPlayTotal >= cbPlayed);
|
---|
353 | cbToPlayTotal -= cbPlayed;
|
---|
354 |
|
---|
355 | /* Fail-safe in case something screwed up while playing back. */
|
---|
356 | if (RTTimeMilliTS() - tsStartMs > uTimeoutMs)
|
---|
357 | {
|
---|
358 | RTTestFailed(g_hTest, "Playback took too long (%RU32ms exceeded), aborting\n", uTimeoutMs);
|
---|
359 | rc = VERR_TIMEOUT;
|
---|
360 | break;
|
---|
361 | }
|
---|
362 | }
|
---|
363 |
|
---|
364 | if (cbToPlayTotal != 0)
|
---|
365 | RTTestFailed(g_hTest, "Playback ended unexpectedly (%RU32 bytes left)\n", cbToPlayTotal);
|
---|
366 |
|
---|
367 | if (RT_SUCCESS(rc))
|
---|
368 | {
|
---|
369 | RTTestPrintf(g_hTest, RTTESTLVL_ALWAYS, "Draining stream ...\n");
|
---|
370 | rc = AudioTestMixStreamDrain(&pStream->Mix, true /*fSync*/);
|
---|
371 | }
|
---|
372 | }
|
---|
373 | else
|
---|
374 | rc = VERR_AUDIO_STREAM_NOT_READY;
|
---|
375 |
|
---|
376 | if (pTstEnv)
|
---|
377 | {
|
---|
378 | int rc2 = AudioTestObjClose(Obj);
|
---|
379 | if (RT_SUCCESS(rc))
|
---|
380 | rc = rc2;
|
---|
381 | }
|
---|
382 |
|
---|
383 | if (RT_FAILURE(rc))
|
---|
384 | RTTestFailed(g_hTest, "Playing tone failed with %Rrc\n", rc);
|
---|
385 |
|
---|
386 | return rc;
|
---|
387 | }
|
---|
388 |
|
---|
389 | /**
|
---|
390 | * Records a test tone from a specific audio test stream.
|
---|
391 | *
|
---|
392 | * @returns VBox status code.
|
---|
393 | * @param pTstEnv Test environment to use for running the test.
|
---|
394 | * @param pStream Stream to use for recording the tone.
|
---|
395 | * @param pParms Tone parameters to use.
|
---|
396 | *
|
---|
397 | * @note Blocking function.
|
---|
398 | */
|
---|
399 | static int audioTestRecordTone(PAUDIOTESTENV pTstEnv, PAUDIOTESTSTREAM pStream, PAUDIOTESTTONEPARMS pParms)
|
---|
400 | {
|
---|
401 | const char *pcszPathOut = pTstEnv->Set.szPathAbs;
|
---|
402 |
|
---|
403 | RTTestPrintf(g_hTest, RTTESTLVL_ALWAYS, "Recording test tone (tone frequency is %RU16Hz, %RU32ms)\n", (uint16_t)pParms->dbFreqHz, pParms->msDuration);
|
---|
404 | RTTestPrintf(g_hTest, RTTESTLVL_DEBUG, "Writing to '%s'\n", pcszPathOut);
|
---|
405 |
|
---|
406 | /** @todo Use .WAV here? */
|
---|
407 | AUDIOTESTOBJ Obj;
|
---|
408 | int rc = AudioTestSetObjCreateAndRegister(&pTstEnv->Set, "guest-tone-rec.pcm", &Obj);
|
---|
409 | AssertRCReturn(rc, rc);
|
---|
410 |
|
---|
411 | PAUDIOTESTDRVMIXSTREAM pMix = &pStream->Mix;
|
---|
412 |
|
---|
413 | rc = AudioTestMixStreamEnable(pMix);
|
---|
414 | if (RT_SUCCESS(rc))
|
---|
415 | {
|
---|
416 | uint64_t cbToRecTotal = PDMAudioPropsMilliToBytes(&pStream->Cfg.Props, pParms->msDuration);
|
---|
417 |
|
---|
418 | RTTestPrintf(g_hTest, RTTESTLVL_DEBUG, "Recording %RU32 bytes total\n", cbToRecTotal);
|
---|
419 |
|
---|
420 | AudioTestObjAddMetadataStr(Obj, "stream_to_record_bytes=%RU32\n", cbToRecTotal);
|
---|
421 | AudioTestObjAddMetadataStr(Obj, "stream_buffer_size_ms=%RU32\n", pTstEnv->cMsBufferSize);
|
---|
422 | AudioTestObjAddMetadataStr(Obj, "stream_prebuf_size_ms=%RU32\n", pTstEnv->cMsPreBuffer);
|
---|
423 | /* Note: This mostly is provided by backend (e.g. PulseAudio / ALSA / ++) and
|
---|
424 | * has nothing to do with the device emulation scheduling hint. */
|
---|
425 | AudioTestObjAddMetadataStr(Obj, "device_scheduling_hint_ms=%RU32\n", pTstEnv->cMsSchedulingHint);
|
---|
426 |
|
---|
427 | uint8_t abSamples[16384];
|
---|
428 | uint32_t const cbSamplesAligned = PDMAudioPropsFloorBytesToFrame(pMix->pProps, sizeof(abSamples));
|
---|
429 | uint64_t cbRecTotal = 0;
|
---|
430 | while (!g_fTerminate && cbRecTotal < cbToRecTotal)
|
---|
431 | {
|
---|
432 | /*
|
---|
433 | * Anything we can read?
|
---|
434 | */
|
---|
435 | uint32_t const cbCanRead = AudioTestMixStreamGetReadable(pMix);
|
---|
436 | if (cbCanRead)
|
---|
437 | {
|
---|
438 | uint32_t const cbToRead = RT_MIN(cbCanRead, cbSamplesAligned);
|
---|
439 | uint32_t cbRecorded = 0;
|
---|
440 | rc = AudioTestMixStreamCapture(pMix, abSamples, cbToRead, &cbRecorded);
|
---|
441 | if (RT_SUCCESS(rc))
|
---|
442 | {
|
---|
443 | if (cbRecorded)
|
---|
444 | {
|
---|
445 | rc = AudioTestObjWrite(Obj, abSamples, cbRecorded);
|
---|
446 | if (RT_SUCCESS(rc))
|
---|
447 | {
|
---|
448 | cbRecTotal += cbRecorded;
|
---|
449 |
|
---|
450 | /** @todo Clamp result? */
|
---|
451 | }
|
---|
452 | }
|
---|
453 | }
|
---|
454 | }
|
---|
455 | else if (AudioTestMixStreamIsOkay(pMix))
|
---|
456 | RTThreadSleep(RT_MIN(RT_MAX(1, pTstEnv->cMsSchedulingHint), 256));
|
---|
457 |
|
---|
458 | if (RT_FAILURE(rc))
|
---|
459 | break;
|
---|
460 | }
|
---|
461 |
|
---|
462 | int rc2 = AudioTestMixStreamDisable(pMix);
|
---|
463 | if (RT_SUCCESS(rc))
|
---|
464 | rc = rc2;
|
---|
465 | }
|
---|
466 |
|
---|
467 | int rc2 = AudioTestObjClose(Obj);
|
---|
468 | if (RT_SUCCESS(rc))
|
---|
469 | rc = rc2;
|
---|
470 |
|
---|
471 | if (RT_FAILURE(rc))
|
---|
472 | RTTestFailed(g_hTest, "Recording tone done failed with %Rrc\n", rc);
|
---|
473 |
|
---|
474 | return rc;
|
---|
475 | }
|
---|
476 |
|
---|
477 |
|
---|
478 | /*********************************************************************************************************************************
|
---|
479 | * ATS Callback Implementations *
|
---|
480 | *********************************************************************************************************************************/
|
---|
481 |
|
---|
482 | /** @copydoc ATSCALLBACKS::pfnHowdy
|
---|
483 | *
|
---|
484 | * @note Runs as part of the guest ATS.
|
---|
485 | */
|
---|
486 | static DECLCALLBACK(int) audioTestGstAtsHowdyCallback(void const *pvUser)
|
---|
487 | {
|
---|
488 | PATSCALLBACKCTX pCtx = (PATSCALLBACKCTX)pvUser;
|
---|
489 |
|
---|
490 | AssertReturn(pCtx->cClients <= UINT8_MAX - 1, VERR_BUFFER_OVERFLOW);
|
---|
491 |
|
---|
492 | pCtx->cClients++;
|
---|
493 |
|
---|
494 | RTTestPrintf(g_hTest, RTTESTLVL_ALWAYS, "New client connected, now %RU8 total\n", pCtx->cClients);
|
---|
495 |
|
---|
496 | return VINF_SUCCESS;
|
---|
497 | }
|
---|
498 |
|
---|
499 | /** @copydoc ATSCALLBACKS::pfnBye
|
---|
500 | *
|
---|
501 | * @note Runs as part of the guest ATS.
|
---|
502 | */
|
---|
503 | static DECLCALLBACK(int) audioTestGstAtsByeCallback(void const *pvUser)
|
---|
504 | {
|
---|
505 | PATSCALLBACKCTX pCtx = (PATSCALLBACKCTX)pvUser;
|
---|
506 |
|
---|
507 | AssertReturn(pCtx->cClients, VERR_WRONG_ORDER);
|
---|
508 | pCtx->cClients--;
|
---|
509 |
|
---|
510 | RTTestPrintf(g_hTest, RTTESTLVL_ALWAYS, "Clients wants to disconnect, %RU8 remaining\n", pCtx->cClients);
|
---|
511 |
|
---|
512 | if (0 == pCtx->cClients) /* All clients disconnected? Tear things down. */
|
---|
513 | {
|
---|
514 | RTTestPrintf(g_hTest, RTTESTLVL_ALWAYS, "Last client disconnected, terminating server ...\n");
|
---|
515 | ASMAtomicWriteBool(&g_fTerminate, true);
|
---|
516 | }
|
---|
517 |
|
---|
518 | return VINF_SUCCESS;
|
---|
519 | }
|
---|
520 |
|
---|
521 | /** @copydoc ATSCALLBACKS::pfnTestSetBegin
|
---|
522 | *
|
---|
523 | * @note Runs as part of the guest ATS.
|
---|
524 | */
|
---|
525 | static DECLCALLBACK(int) audioTestGstAtsTestSetBeginCallback(void const *pvUser, const char *pszTag)
|
---|
526 | {
|
---|
527 | PATSCALLBACKCTX pCtx = (PATSCALLBACKCTX)pvUser;
|
---|
528 | PAUDIOTESTENV pTstEnv = pCtx->pTstEnv;
|
---|
529 |
|
---|
530 | RTTestPrintf(g_hTest, RTTESTLVL_ALWAYS, "Beginning test set '%s' in '%s'\n", pszTag, pTstEnv->szPathTemp);
|
---|
531 |
|
---|
532 | return AudioTestSetCreate(&pTstEnv->Set, pTstEnv->szPathTemp, pszTag);
|
---|
533 | }
|
---|
534 |
|
---|
535 | /** @copydoc ATSCALLBACKS::pfnTestSetEnd
|
---|
536 | *
|
---|
537 | * @note Runs as part of the guest ATS.
|
---|
538 | */
|
---|
539 | static DECLCALLBACK(int) audioTestGstAtsTestSetEndCallback(void const *pvUser, const char *pszTag)
|
---|
540 | {
|
---|
541 | PATSCALLBACKCTX pCtx = (PATSCALLBACKCTX)pvUser;
|
---|
542 | PAUDIOTESTENV pTstEnv = pCtx->pTstEnv;
|
---|
543 |
|
---|
544 | RTTestPrintf(g_hTest, RTTESTLVL_ALWAYS, "Ending test set '%s'\n", pszTag);
|
---|
545 |
|
---|
546 | /* Pack up everything to be ready for transmission. */
|
---|
547 | return audioTestEnvPrologue(pTstEnv, true /* fPack */, pCtx->szTestSetArchive, sizeof(pCtx->szTestSetArchive));
|
---|
548 | }
|
---|
549 |
|
---|
550 | /** @copydoc ATSCALLBACKS::pfnTonePlay
|
---|
551 | *
|
---|
552 | * @note Runs as part of the guest ATS.
|
---|
553 | */
|
---|
554 | static DECLCALLBACK(int) audioTestGstAtsTonePlayCallback(void const *pvUser, PAUDIOTESTTONEPARMS pToneParms)
|
---|
555 | {
|
---|
556 | PATSCALLBACKCTX pCtx = (PATSCALLBACKCTX)pvUser;
|
---|
557 | PAUDIOTESTENV pTstEnv = pCtx->pTstEnv;
|
---|
558 |
|
---|
559 | const PAUDIOTESTSTREAM pTstStream = &pTstEnv->aStreams[0]; /** @todo Make this dynamic. */
|
---|
560 |
|
---|
561 | int rc = audioTestStreamInit(pTstEnv->pDrvStack, pTstStream, PDMAUDIODIR_OUT, &pTstEnv->Props, false /* fWithMixer */,
|
---|
562 | pTstEnv->cMsBufferSize, pTstEnv->cMsPreBuffer, pTstEnv->cMsSchedulingHint);
|
---|
563 | if (RT_SUCCESS(rc))
|
---|
564 | {
|
---|
565 | AUDIOTESTPARMS TstParms;
|
---|
566 | RT_ZERO(TstParms);
|
---|
567 | TstParms.enmType = AUDIOTESTTYPE_TESTTONE_PLAY;
|
---|
568 | TstParms.enmDir = PDMAUDIODIR_OUT;
|
---|
569 | TstParms.TestTone = *pToneParms;
|
---|
570 |
|
---|
571 | PAUDIOTESTENTRY pTst;
|
---|
572 | rc = AudioTestSetTestBegin(&pTstEnv->Set, "Playing test tone", &TstParms, &pTst);
|
---|
573 | if (RT_SUCCESS(rc))
|
---|
574 | {
|
---|
575 | rc = audioTestPlayTone(pTstEnv, pTstStream, pToneParms);
|
---|
576 | if (RT_SUCCESS(rc))
|
---|
577 | {
|
---|
578 | AudioTestSetTestDone(pTst);
|
---|
579 | }
|
---|
580 | else
|
---|
581 | AudioTestSetTestFailed(pTst, rc, "Playing tone failed");
|
---|
582 | }
|
---|
583 |
|
---|
584 | int rc2 = audioTestStreamDestroy(pTstEnv, pTstStream);
|
---|
585 | if (RT_SUCCESS(rc))
|
---|
586 | rc = rc2;
|
---|
587 | }
|
---|
588 | else
|
---|
589 | RTTestFailed(g_hTest, "Error creating output stream, rc=%Rrc\n", rc);
|
---|
590 |
|
---|
591 | return rc;
|
---|
592 | }
|
---|
593 |
|
---|
594 | /** @copydoc ATSCALLBACKS::pfnToneRecord */
|
---|
595 | static DECLCALLBACK(int) audioTestGstAtsToneRecordCallback(void const *pvUser, PAUDIOTESTTONEPARMS pToneParms)
|
---|
596 | {
|
---|
597 | PATSCALLBACKCTX pCtx = (PATSCALLBACKCTX)pvUser;
|
---|
598 | PAUDIOTESTENV pTstEnv = pCtx->pTstEnv;
|
---|
599 |
|
---|
600 | const PAUDIOTESTSTREAM pTstStream = &pTstEnv->aStreams[0]; /** @todo Make this dynamic. */
|
---|
601 |
|
---|
602 | int rc = audioTestStreamInit(pTstEnv->pDrvStack, pTstStream, PDMAUDIODIR_IN, &pTstEnv->Props, false /* fWithMixer */,
|
---|
603 | pTstEnv->cMsBufferSize, pTstEnv->cMsPreBuffer, pTstEnv->cMsSchedulingHint);
|
---|
604 | if (RT_SUCCESS(rc))
|
---|
605 | {
|
---|
606 | AUDIOTESTPARMS TstParms;
|
---|
607 | RT_ZERO(TstParms);
|
---|
608 | TstParms.enmType = AUDIOTESTTYPE_TESTTONE_RECORD;
|
---|
609 | TstParms.enmDir = PDMAUDIODIR_IN;
|
---|
610 | TstParms.Props = pToneParms->Props;
|
---|
611 | TstParms.TestTone = *pToneParms;
|
---|
612 |
|
---|
613 | PAUDIOTESTENTRY pTst;
|
---|
614 | rc = AudioTestSetTestBegin(&pTstEnv->Set, "Recording test tone from host", &TstParms, &pTst);
|
---|
615 | if (RT_SUCCESS(rc))
|
---|
616 | {
|
---|
617 | rc = audioTestRecordTone(pTstEnv, pTstStream, pToneParms);
|
---|
618 | if (RT_SUCCESS(rc))
|
---|
619 | {
|
---|
620 | AudioTestSetTestDone(pTst);
|
---|
621 | }
|
---|
622 | else
|
---|
623 | AudioTestSetTestFailed(pTst, rc, "Recording tone failed");
|
---|
624 | }
|
---|
625 |
|
---|
626 | int rc2 = audioTestStreamDestroy(pTstEnv, pTstStream);
|
---|
627 | if (RT_SUCCESS(rc))
|
---|
628 | rc = rc2;
|
---|
629 | }
|
---|
630 | else
|
---|
631 | RTTestFailed(g_hTest, "Error creating input stream, rc=%Rrc\n", rc);
|
---|
632 |
|
---|
633 | return rc;
|
---|
634 | }
|
---|
635 |
|
---|
636 | /** @copydoc ATSCALLBACKS::pfnTestSetSendBegin */
|
---|
637 | static DECLCALLBACK(int) audioTestGstAtsTestSetSendBeginCallback(void const *pvUser, const char *pszTag)
|
---|
638 | {
|
---|
639 | RT_NOREF(pszTag);
|
---|
640 |
|
---|
641 | PATSCALLBACKCTX pCtx = (PATSCALLBACKCTX)pvUser;
|
---|
642 |
|
---|
643 | if (!RTFileExists(pCtx->szTestSetArchive)) /* Has the archive successfully been created yet? */
|
---|
644 | return VERR_WRONG_ORDER;
|
---|
645 |
|
---|
646 | int rc = RTFileOpen(&pCtx->hTestSetArchive, pCtx->szTestSetArchive, RTFILE_O_READ | RTFILE_O_OPEN | RTFILE_O_DENY_WRITE);
|
---|
647 | if (RT_SUCCESS(rc))
|
---|
648 | {
|
---|
649 | uint64_t uSize;
|
---|
650 | rc = RTFileQuerySize(pCtx->hTestSetArchive, &uSize);
|
---|
651 | if (RT_SUCCESS(rc))
|
---|
652 | RTTestPrintf(g_hTest, RTTESTLVL_ALWAYS, "Sending test set '%s' (%zu bytes)\n", pCtx->szTestSetArchive, uSize);
|
---|
653 | }
|
---|
654 |
|
---|
655 | return rc;
|
---|
656 | }
|
---|
657 |
|
---|
658 | /** @copydoc ATSCALLBACKS::pfnTestSetSendRead */
|
---|
659 | static DECLCALLBACK(int) audioTestGstAtsTestSetSendReadCallback(void const *pvUser,
|
---|
660 | const char *pszTag, void *pvBuf, size_t cbBuf, size_t *pcbRead)
|
---|
661 | {
|
---|
662 | RT_NOREF(pszTag);
|
---|
663 |
|
---|
664 | PATSCALLBACKCTX pCtx = (PATSCALLBACKCTX)pvUser;
|
---|
665 |
|
---|
666 | return RTFileRead(pCtx->hTestSetArchive, pvBuf, cbBuf, pcbRead);
|
---|
667 | }
|
---|
668 |
|
---|
669 | /** @copydoc ATSCALLBACKS::pfnTestSetSendEnd */
|
---|
670 | static DECLCALLBACK(int) audioTestGstAtsTestSetSendEndCallback(void const *pvUser, const char *pszTag)
|
---|
671 | {
|
---|
672 | RT_NOREF(pszTag);
|
---|
673 |
|
---|
674 | PATSCALLBACKCTX pCtx = (PATSCALLBACKCTX)pvUser;
|
---|
675 |
|
---|
676 | int rc = RTFileClose(pCtx->hTestSetArchive);
|
---|
677 | if (RT_SUCCESS(rc))
|
---|
678 | {
|
---|
679 | pCtx->hTestSetArchive = NIL_RTFILE;
|
---|
680 | }
|
---|
681 |
|
---|
682 | return rc;
|
---|
683 | }
|
---|
684 |
|
---|
685 |
|
---|
686 | /*********************************************************************************************************************************
|
---|
687 | * Implementation of audio test environment handling *
|
---|
688 | *********************************************************************************************************************************/
|
---|
689 |
|
---|
690 | /**
|
---|
691 | * Connects an ATS client via TCP/IP to a peer.
|
---|
692 | *
|
---|
693 | * @returns VBox status code.
|
---|
694 | * @param pTstEnv Test environment to use.
|
---|
695 | * @param pClient Client to connect.
|
---|
696 | * @param pszWhat Hint of what to connect to where.
|
---|
697 | * @param pTcpOpts Pointer to TCP options to use.
|
---|
698 | */
|
---|
699 | int audioTestEnvConnectViaTcp(PAUDIOTESTENV pTstEnv, PATSCLIENT pClient, const char *pszWhat, PAUDIOTESTENVTCPOPTS pTcpOpts)
|
---|
700 | {
|
---|
701 | RT_NOREF(pTstEnv);
|
---|
702 |
|
---|
703 | RTGETOPTUNION Val;
|
---|
704 | RT_ZERO(Val);
|
---|
705 |
|
---|
706 | int rc;
|
---|
707 |
|
---|
708 | if (!pTcpOpts->szBindAddr[0])
|
---|
709 | {
|
---|
710 | Val.psz = "client";
|
---|
711 | }
|
---|
712 | else if (!pTcpOpts->szConnectAddr[0])
|
---|
713 | {
|
---|
714 | Val.psz = "server";
|
---|
715 | }
|
---|
716 | else
|
---|
717 | Val.psz = "both";
|
---|
718 |
|
---|
719 | rc = AudioTestSvcClientHandleOption(pClient, ATSTCPOPT_MODE, &Val);
|
---|
720 | AssertRCReturn(rc, rc);
|
---|
721 |
|
---|
722 | RTTestPrintf(g_hTest, RTTESTLVL_ALWAYS, "Connecting %s (connection mode '%s') ...\n", pszWhat, Val.psz);
|
---|
723 |
|
---|
724 | if ( !RTStrCmp(Val.psz, "client")
|
---|
725 | || !RTStrCmp(Val.psz, "both"))
|
---|
726 | RTTestPrintf(g_hTest, RTTESTLVL_ALWAYS, "Connecting to %s:%RU32\n",
|
---|
727 | pTcpOpts->szConnectAddr, pTcpOpts->uConnectPort);
|
---|
728 |
|
---|
729 | if ( !RTStrCmp(Val.psz, "server")
|
---|
730 | || !RTStrCmp(Val.psz, "both"))
|
---|
731 | RTTestPrintf(g_hTest, RTTESTLVL_ALWAYS, "Listening at %s:%RU32\n",
|
---|
732 | pTcpOpts->szBindAddr ? pTcpOpts->szBindAddr : "<None>", pTcpOpts->uBindPort);
|
---|
733 |
|
---|
734 | if (pTcpOpts->szBindAddr[0])
|
---|
735 | {
|
---|
736 | Val.psz = pTcpOpts->szBindAddr;
|
---|
737 | rc = AudioTestSvcClientHandleOption(pClient, ATSTCPOPT_BIND_ADDRESS, &Val);
|
---|
738 | AssertRCReturn(rc, rc);
|
---|
739 | }
|
---|
740 |
|
---|
741 | if (pTcpOpts->uBindPort)
|
---|
742 | {
|
---|
743 | Val.u16 = pTcpOpts->uBindPort;
|
---|
744 | rc = AudioTestSvcClientHandleOption(pClient, ATSTCPOPT_BIND_PORT, &Val);
|
---|
745 | AssertRCReturn(rc, rc);
|
---|
746 | }
|
---|
747 |
|
---|
748 | if (pTcpOpts->szConnectAddr[0])
|
---|
749 | {
|
---|
750 | Val.psz = pTcpOpts->szConnectAddr;
|
---|
751 | rc = AudioTestSvcClientHandleOption(pClient, ATSTCPOPT_CONNECT_ADDRESS, &Val);
|
---|
752 | AssertRCReturn(rc, rc);
|
---|
753 | }
|
---|
754 |
|
---|
755 | if (pTcpOpts->uConnectPort)
|
---|
756 | {
|
---|
757 | Val.u16 = pTcpOpts->uConnectPort;
|
---|
758 | rc = AudioTestSvcClientHandleOption(pClient, ATSTCPOPT_CONNECT_PORT, &Val);
|
---|
759 | AssertRCReturn(rc, rc);
|
---|
760 | }
|
---|
761 |
|
---|
762 | rc = AudioTestSvcClientConnect(pClient);
|
---|
763 | if (RT_FAILURE(rc))
|
---|
764 | {
|
---|
765 | RTTestFailed(g_hTest, "Connecting %s failed with %Rrc\n", pszWhat, rc);
|
---|
766 | return rc;
|
---|
767 | }
|
---|
768 |
|
---|
769 | RTTestPrintf(g_hTest, RTTESTLVL_ALWAYS, "Successfully connected %s\n", pszWhat);
|
---|
770 | return rc;
|
---|
771 | }
|
---|
772 |
|
---|
773 | /**
|
---|
774 | * Configures and starts an ATS TCP/IP server.
|
---|
775 | *
|
---|
776 | * @returns VBox status code.
|
---|
777 | * @param pSrv ATS server instance to configure and start.
|
---|
778 | * @param pCallbacks ATS callback table to use.
|
---|
779 | * @param pszDesc Hint of server type which is being started.
|
---|
780 | * @param pTcpOpts TCP options to use.
|
---|
781 | */
|
---|
782 | int audioTestEnvConfigureAndStartTcpServer(PATSSERVER pSrv, PCATSCALLBACKS pCallbacks, const char *pszDesc,
|
---|
783 | PAUDIOTESTENVTCPOPTS pTcpOpts)
|
---|
784 | {
|
---|
785 | RTGETOPTUNION Val;
|
---|
786 | RT_ZERO(Val);
|
---|
787 |
|
---|
788 | if (pTcpOpts->szBindAddr[0])
|
---|
789 | {
|
---|
790 | Val.psz = pTcpOpts->szBindAddr;
|
---|
791 | AudioTestSvcHandleOption(pSrv, ATSTCPOPT_BIND_ADDRESS, &Val);
|
---|
792 | }
|
---|
793 |
|
---|
794 | if (pTcpOpts->uBindPort)
|
---|
795 | {
|
---|
796 | Val.u16 = pTcpOpts->uBindPort;
|
---|
797 | AudioTestSvcHandleOption(pSrv, ATSTCPOPT_BIND_PORT, &Val);
|
---|
798 | }
|
---|
799 |
|
---|
800 | if (pTcpOpts->szConnectAddr[0])
|
---|
801 | {
|
---|
802 | Val.psz = pTcpOpts->szConnectAddr;
|
---|
803 | AudioTestSvcHandleOption(pSrv, ATSTCPOPT_CONNECT_ADDRESS, &Val);
|
---|
804 | }
|
---|
805 |
|
---|
806 | if (pTcpOpts->uConnectPort)
|
---|
807 | {
|
---|
808 | Val.u16 = pTcpOpts->uConnectPort;
|
---|
809 | AudioTestSvcHandleOption(pSrv, ATSTCPOPT_CONNECT_PORT, &Val);
|
---|
810 | }
|
---|
811 |
|
---|
812 | RTTestPrintf(g_hTest, RTTESTLVL_ALWAYS, "Starting server for %s at %s:%RU32 ...\n",
|
---|
813 | pszDesc, pTcpOpts->szBindAddr[0] ? pTcpOpts->szBindAddr : "0.0.0.0", pTcpOpts->uBindPort);
|
---|
814 | if (pTcpOpts->szConnectAddr[0])
|
---|
815 | RTTestPrintf(g_hTest, RTTESTLVL_ALWAYS, "Trying %s to connect as client to %s:%RU32 ...\n",
|
---|
816 | pszDesc, pTcpOpts->szConnectAddr[0] ? pTcpOpts->szConnectAddr : "0.0.0.0", pTcpOpts->uConnectPort);
|
---|
817 |
|
---|
818 | int rc = AudioTestSvcInit(pSrv, pCallbacks);
|
---|
819 | if (RT_SUCCESS(rc))
|
---|
820 | rc = AudioTestSvcStart(pSrv);
|
---|
821 |
|
---|
822 | if (RT_FAILURE(rc))
|
---|
823 | RTTestFailed(g_hTest, "Starting server for %s failed with %Rrc\n", pszDesc, rc);
|
---|
824 |
|
---|
825 | return rc;
|
---|
826 | }
|
---|
827 |
|
---|
828 | /**
|
---|
829 | * Initializes an audio test environment.
|
---|
830 | *
|
---|
831 | * @returns VBox status code.
|
---|
832 | * @param pTstEnv Audio test environment to initialize.
|
---|
833 | * @param pDrvStack Driver stack to use.
|
---|
834 | */
|
---|
835 | int audioTestEnvInit(PAUDIOTESTENV pTstEnv, PAUDIOTESTDRVSTACK pDrvStack)
|
---|
836 | {
|
---|
837 | int rc = VINF_SUCCESS;
|
---|
838 |
|
---|
839 | pTstEnv->pDrvStack = pDrvStack;
|
---|
840 |
|
---|
841 | /*
|
---|
842 | * Set sane defaults if not already set.
|
---|
843 | */
|
---|
844 | if (!RTStrNLen(pTstEnv->szTag, sizeof(pTstEnv->szTag)))
|
---|
845 | {
|
---|
846 | rc = AudioTestGenTag(pTstEnv->szTag, sizeof(pTstEnv->szTag));
|
---|
847 | AssertRCReturn(rc, rc);
|
---|
848 | }
|
---|
849 |
|
---|
850 | if (!RTStrNLen(pTstEnv->szPathTemp, sizeof(pTstEnv->szPathTemp)))
|
---|
851 | {
|
---|
852 | rc = AudioTestPathGetTemp(pTstEnv->szPathTemp, sizeof(pTstEnv->szPathTemp));
|
---|
853 | AssertRCReturn(rc, rc);
|
---|
854 | }
|
---|
855 |
|
---|
856 | if (!RTStrNLen(pTstEnv->szPathOut, sizeof(pTstEnv->szPathOut)))
|
---|
857 | {
|
---|
858 | rc = RTPathJoin(pTstEnv->szPathOut, sizeof(pTstEnv->szPathOut), pTstEnv->szPathTemp, "vkat-temp");
|
---|
859 | AssertRCReturn(rc, rc);
|
---|
860 | }
|
---|
861 |
|
---|
862 | RTTestPrintf(g_hTest, RTTESTLVL_ALWAYS, "Initializing environment for mode '%s'\n", pTstEnv->enmMode == AUDIOTESTMODE_HOST ? "host" : "guest");
|
---|
863 | RTTestPrintf(g_hTest, RTTESTLVL_ALWAYS, "Using tag '%s'\n", pTstEnv->szTag);
|
---|
864 | RTTestPrintf(g_hTest, RTTESTLVL_ALWAYS, "Output directory is '%s'\n", pTstEnv->szPathOut);
|
---|
865 | RTTestPrintf(g_hTest, RTTESTLVL_ALWAYS, "Temp directory is '%s'\n", pTstEnv->szPathTemp);
|
---|
866 |
|
---|
867 | if (!pTstEnv->cMsBufferSize)
|
---|
868 | pTstEnv->cMsBufferSize = UINT32_MAX;
|
---|
869 | if (!pTstEnv->cMsPreBuffer)
|
---|
870 | pTstEnv->cMsPreBuffer = UINT32_MAX;
|
---|
871 | if (!pTstEnv->cMsSchedulingHint)
|
---|
872 | pTstEnv->cMsSchedulingHint = UINT32_MAX;
|
---|
873 |
|
---|
874 | char szPathTemp[RTPATH_MAX];
|
---|
875 | if ( !strlen(pTstEnv->szPathTemp)
|
---|
876 | || !strlen(pTstEnv->szPathOut))
|
---|
877 | rc = RTPathTemp(szPathTemp, sizeof(szPathTemp));
|
---|
878 |
|
---|
879 | if ( RT_SUCCESS(rc)
|
---|
880 | && !strlen(pTstEnv->szPathTemp))
|
---|
881 | rc = RTPathJoin(pTstEnv->szPathTemp, sizeof(pTstEnv->szPathTemp), szPathTemp, "vkat-temp");
|
---|
882 |
|
---|
883 | if (RT_SUCCESS(rc))
|
---|
884 | {
|
---|
885 | rc = RTDirCreate(pTstEnv->szPathTemp, RTFS_UNIX_IRWXU, 0 /* fFlags */);
|
---|
886 | if (rc == VERR_ALREADY_EXISTS)
|
---|
887 | rc = VINF_SUCCESS;
|
---|
888 | }
|
---|
889 |
|
---|
890 | if ( RT_SUCCESS(rc)
|
---|
891 | && !strlen(pTstEnv->szPathOut))
|
---|
892 | rc = RTPathJoin(pTstEnv->szPathOut, sizeof(pTstEnv->szPathOut), szPathTemp, "vkat");
|
---|
893 |
|
---|
894 | if (RT_SUCCESS(rc))
|
---|
895 | {
|
---|
896 | rc = RTDirCreate(pTstEnv->szPathOut, RTFS_UNIX_IRWXU, 0 /* fFlags */);
|
---|
897 | if (rc == VERR_ALREADY_EXISTS)
|
---|
898 | rc = VINF_SUCCESS;
|
---|
899 | }
|
---|
900 |
|
---|
901 | if (RT_FAILURE(rc))
|
---|
902 | return rc;
|
---|
903 |
|
---|
904 | /**
|
---|
905 | * For NAT'ed VMs we use (default):
|
---|
906 | * - client mode (uConnectAddr / uConnectPort) on the guest.
|
---|
907 | * - server mode (uBindAddr / uBindPort) on the host.
|
---|
908 | */
|
---|
909 | if ( !pTstEnv->TcpOpts.szConnectAddr[0]
|
---|
910 | && !pTstEnv->TcpOpts.szBindAddr[0])
|
---|
911 | RTStrCopy(pTstEnv->TcpOpts.szBindAddr, sizeof(pTstEnv->TcpOpts.szBindAddr), "0.0.0.0");
|
---|
912 |
|
---|
913 | if (pTstEnv->enmMode == AUDIOTESTMODE_GUEST)
|
---|
914 | {
|
---|
915 | ATSCALLBACKCTX Ctx;
|
---|
916 | Ctx.pTstEnv = pTstEnv;
|
---|
917 |
|
---|
918 | ATSCALLBACKS Callbacks;
|
---|
919 | RT_ZERO(Callbacks);
|
---|
920 | Callbacks.pfnHowdy = audioTestGstAtsHowdyCallback;
|
---|
921 | Callbacks.pfnBye = audioTestGstAtsByeCallback;
|
---|
922 | Callbacks.pfnTestSetBegin = audioTestGstAtsTestSetBeginCallback;
|
---|
923 | Callbacks.pfnTestSetEnd = audioTestGstAtsTestSetEndCallback;
|
---|
924 | Callbacks.pfnTonePlay = audioTestGstAtsTonePlayCallback;
|
---|
925 | Callbacks.pfnToneRecord = audioTestGstAtsToneRecordCallback;
|
---|
926 | Callbacks.pfnTestSetSendBegin = audioTestGstAtsTestSetSendBeginCallback;
|
---|
927 | Callbacks.pfnTestSetSendRead = audioTestGstAtsTestSetSendReadCallback;
|
---|
928 | Callbacks.pfnTestSetSendEnd = audioTestGstAtsTestSetSendEndCallback;
|
---|
929 | Callbacks.pvUser = &Ctx;
|
---|
930 |
|
---|
931 | if (!pTstEnv->TcpOpts.uBindPort)
|
---|
932 | pTstEnv->TcpOpts.uBindPort = ATS_TCP_DEF_BIND_PORT_GUEST;
|
---|
933 |
|
---|
934 | if (!pTstEnv->TcpOpts.uConnectPort)
|
---|
935 | pTstEnv->TcpOpts.uConnectPort = ATS_TCP_DEF_CONNECT_PORT_GUEST;
|
---|
936 |
|
---|
937 | /**
|
---|
938 | * Note: Don't set pTstEnv->TcpOpts.szTcpConnectAddr by default here, as this specifies what connection mode
|
---|
939 | * (client / server / both) we use on the guest.
|
---|
940 | */
|
---|
941 |
|
---|
942 | /*
|
---|
943 | * Start the ATS (Audio Test Service) on the guest side.
|
---|
944 | * That service then will perform playback and recording operations on the guest, triggered from the host.
|
---|
945 | *
|
---|
946 | * When running this in self-test mode, that service also can be run on the host if nothing else is specified.
|
---|
947 | * Note that we have to bind to "0.0.0.0" by default so that the host can connect to it.
|
---|
948 | */
|
---|
949 | rc = audioTestEnvConfigureAndStartTcpServer(&pTstEnv->Srv, &Callbacks, "Guest ATS", &pTstEnv->TcpOpts);
|
---|
950 | }
|
---|
951 | else /* Host mode */
|
---|
952 | {
|
---|
953 |
|
---|
954 | ATSCALLBACKCTX Ctx;
|
---|
955 | Ctx.pTstEnv = pTstEnv;
|
---|
956 |
|
---|
957 | ATSCALLBACKS Callbacks;
|
---|
958 | RT_ZERO(Callbacks);
|
---|
959 | Callbacks.pvUser = &Ctx;
|
---|
960 |
|
---|
961 | if (!pTstEnv->TcpOpts.uBindPort)
|
---|
962 | pTstEnv->TcpOpts.uBindPort = ATS_TCP_DEF_BIND_PORT_HOST;
|
---|
963 |
|
---|
964 | if (!pTstEnv->TcpOpts.uConnectPort)
|
---|
965 | pTstEnv->TcpOpts.uConnectPort = ATS_TCP_DEF_CONNECT_PORT_HOST_PORT_FWD;
|
---|
966 |
|
---|
967 | /**
|
---|
968 | * Note: Don't set pTstEnv->TcpOpts.szTcpConnectAddr by default here, as this specifies what connection mode
|
---|
969 | * (client / server / both) we use on the host.
|
---|
970 | */
|
---|
971 |
|
---|
972 | /* We need to start a server on the host so that VMs configured with NAT networking
|
---|
973 | * can connect to it as well. */
|
---|
974 | rc = AudioTestSvcClientCreate(&pTstEnv->u.Host.AtsClGuest);
|
---|
975 | if (RT_SUCCESS(rc))
|
---|
976 | rc = audioTestEnvConnectViaTcp(pTstEnv, &pTstEnv->u.Host.AtsClGuest,
|
---|
977 | "Host -> Guest ATS", &pTstEnv->TcpOpts);
|
---|
978 | if (RT_SUCCESS(rc))
|
---|
979 | {
|
---|
980 | AUDIOTESTENVTCPOPTS ValKitTcpOpts;
|
---|
981 | RT_ZERO(ValKitTcpOpts);
|
---|
982 |
|
---|
983 | /* For now we ASSUME that the Validation Kit audio driver ATS runs on the same host as VKAT (this binary) runs on. */
|
---|
984 | ValKitTcpOpts.uConnectPort = ATS_TCP_DEF_CONNECT_PORT_VALKIT; /** @todo Make this dynamic. */
|
---|
985 | RTStrCopy(ValKitTcpOpts.szConnectAddr, sizeof(ValKitTcpOpts.szConnectAddr), ATS_TCP_DEF_CONNECT_HOST_ADDR_STR); /** @todo Ditto. */
|
---|
986 |
|
---|
987 | rc = AudioTestSvcClientCreate(&pTstEnv->u.Host.AtsClValKit);
|
---|
988 | if (RT_SUCCESS(rc))
|
---|
989 | rc = audioTestEnvConnectViaTcp(pTstEnv, &pTstEnv->u.Host.AtsClValKit,
|
---|
990 | "Host -> Validation Kit Host Audio Driver ATS", &ValKitTcpOpts);
|
---|
991 | }
|
---|
992 | }
|
---|
993 |
|
---|
994 | return rc;
|
---|
995 | }
|
---|
996 |
|
---|
997 | /**
|
---|
998 | * Destroys an audio test environment.
|
---|
999 | *
|
---|
1000 | * @param pTstEnv Audio test environment to destroy.
|
---|
1001 | */
|
---|
1002 | void audioTestEnvDestroy(PAUDIOTESTENV pTstEnv)
|
---|
1003 | {
|
---|
1004 | if (!pTstEnv)
|
---|
1005 | return;
|
---|
1006 |
|
---|
1007 | /* When in host mode, we need to destroy our ATS clients in order to also let
|
---|
1008 | * the ATS server(s) know we're going to quit. */
|
---|
1009 | if (pTstEnv->enmMode == AUDIOTESTMODE_HOST)
|
---|
1010 | {
|
---|
1011 | AudioTestSvcClientDestroy(&pTstEnv->u.Host.AtsClValKit);
|
---|
1012 | AudioTestSvcClientDestroy(&pTstEnv->u.Host.AtsClGuest);
|
---|
1013 | }
|
---|
1014 |
|
---|
1015 | for (unsigned i = 0; i < RT_ELEMENTS(pTstEnv->aStreams); i++)
|
---|
1016 | {
|
---|
1017 | int rc2 = audioTestStreamDestroy(pTstEnv, &pTstEnv->aStreams[i]);
|
---|
1018 | if (RT_FAILURE(rc2))
|
---|
1019 | RTTestFailed(g_hTest, "Stream destruction for stream #%u failed with %Rrc\n", i, rc2);
|
---|
1020 | }
|
---|
1021 |
|
---|
1022 | /* Try cleaning up a bit. */
|
---|
1023 | RTDirRemove(pTstEnv->szPathTemp);
|
---|
1024 | RTDirRemove(pTstEnv->szPathOut);
|
---|
1025 |
|
---|
1026 | pTstEnv->pDrvStack = NULL;
|
---|
1027 | }
|
---|
1028 |
|
---|
1029 | /**
|
---|
1030 | * Closes, packs up and destroys a test environment.
|
---|
1031 | *
|
---|
1032 | * @returns VBox status code.
|
---|
1033 | * @param pTstEnv Test environment to handle.
|
---|
1034 | * @param fPack Whether to pack the test set up before destroying / wiping it.
|
---|
1035 | * @param pszPackFile Where to store the packed test set file on success. Can be NULL if \a fPack is \c false.
|
---|
1036 | * @param cbPackFile Size (in bytes) of \a pszPackFile. Can be 0 if \a fPack is \c false.
|
---|
1037 | */
|
---|
1038 | int audioTestEnvPrologue(PAUDIOTESTENV pTstEnv, bool fPack, char *pszPackFile, size_t cbPackFile)
|
---|
1039 | {
|
---|
1040 | /* Close the test set first. */
|
---|
1041 | AudioTestSetClose(&pTstEnv->Set);
|
---|
1042 |
|
---|
1043 | int rc = VINF_SUCCESS;
|
---|
1044 |
|
---|
1045 | if (fPack)
|
---|
1046 | {
|
---|
1047 | /* Before destroying the test environment, pack up the test set so
|
---|
1048 | * that it's ready for transmission. */
|
---|
1049 | rc = AudioTestSetPack(&pTstEnv->Set, pTstEnv->szPathOut, pszPackFile, cbPackFile);
|
---|
1050 | if (RT_SUCCESS(rc))
|
---|
1051 | RTTestPrintf(g_hTest, RTTESTLVL_ALWAYS, "Test set packed up to '%s'\n", pszPackFile);
|
---|
1052 | }
|
---|
1053 |
|
---|
1054 | if (!g_fDrvAudioDebug) /* Don't wipe stuff when debugging. Can be useful for introspecting data. */
|
---|
1055 | /* ignore rc */ AudioTestSetWipe(&pTstEnv->Set);
|
---|
1056 |
|
---|
1057 | AudioTestSetDestroy(&pTstEnv->Set);
|
---|
1058 |
|
---|
1059 | if (RT_FAILURE(rc))
|
---|
1060 | RTTestFailed(g_hTest, "Test set prologue failed with %Rrc\n", rc);
|
---|
1061 |
|
---|
1062 | return rc;
|
---|
1063 | }
|
---|
1064 |
|
---|
1065 | /**
|
---|
1066 | * Initializes an audio test parameters set.
|
---|
1067 | *
|
---|
1068 | * @param pTstParms Test parameters set to initialize.
|
---|
1069 | */
|
---|
1070 | void audioTestParmsInit(PAUDIOTESTPARMS pTstParms)
|
---|
1071 | {
|
---|
1072 | RT_ZERO(*pTstParms);
|
---|
1073 | }
|
---|
1074 |
|
---|
1075 | /**
|
---|
1076 | * Destroys an audio test parameters set.
|
---|
1077 | *
|
---|
1078 | * @param pTstParms Test parameters set to destroy.
|
---|
1079 | */
|
---|
1080 | void audioTestParmsDestroy(PAUDIOTESTPARMS pTstParms)
|
---|
1081 | {
|
---|
1082 | if (!pTstParms)
|
---|
1083 | return;
|
---|
1084 |
|
---|
1085 | return;
|
---|
1086 | }
|
---|
1087 |
|
---|