VirtualBox

source: vbox/trunk/src/VBox/ValidationKit/utils/audio/vkatCommon.cpp@ 91148

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

Audio/Validation Kit: Try draining the stream in the hope that we can write to it soon again. bugref:10008

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

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette