VirtualBox

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

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

Audio/Validation Kit: Some more diagnostics to find out why some testbox guests refuse to play any test tones. ​bugref:10008

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 42.2 KB
Line 
1/* $Id: vkatCommon.cpp 91139 2021-09-07 12:37:53Z 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 uTimeoutNs = (pParms->msDuration * 4) * RT_NS_1MS; /* Four times the time playback should roughly take */
290
291 while (cbToPlayTotal)
292 {
293 /* Pace ourselves a little. */
294 if (offStream >= cbPreBuffer)
295 {
296 if (!nsDonePreBuffering)
297 nsDonePreBuffering = RTTimeNanoTS();
298 uint64_t const cNsWritten = PDMAudioPropsBytesToNano64(pMix->pProps, offStream - cbPreBuffer);
299 uint64_t const cNsElapsed = RTTimeNanoTS() - nsStarted;
300 if (cNsWritten > cNsElapsed + RT_NS_10MS)
301 RTThreadSleep((cNsWritten - cNsElapsed - RT_NS_10MS / 2) / RT_NS_1MS);
302 }
303
304 uint32_t cbPlayed = 0;
305 uint32_t const cbCanWrite = AudioTestMixStreamGetWritable(&pStream->Mix);
306 if (cbCanWrite)
307 {
308 uint32_t const cbToGenerate = RT_MIN(RT_MIN(cbToPlayTotal, sizeof(abBuf)), cbCanWrite);
309 uint32_t cbToPlay;
310 rc = AudioTestToneGenerate(&TstTone, abBuf, cbToGenerate, &cbToPlay);
311 if (RT_SUCCESS(rc))
312 {
313 if (pTstEnv)
314 {
315 /* Write stuff to disk before trying to play it. Help analysis later. */
316 rc = AudioTestObjWrite(Obj, abBuf, cbToPlay);
317 }
318 if (RT_SUCCESS(rc))
319 {
320 rc = AudioTestMixStreamPlay(&pStream->Mix, abBuf, cbToPlay, &cbPlayed);
321 if (RT_SUCCESS(rc))
322 {
323 offStream += cbPlayed;
324
325 if (cbPlayed != cbToPlay)
326 RTTestFailed(g_hTest, "Only played %RU32/%RU32 bytes", cbPlayed, cbToPlay);
327 }
328 }
329 }
330
331 if (RT_FAILURE(rc))
332 break;
333 }
334 else if (AudioTestMixStreamIsOkay(&pStream->Mix))
335 RTThreadSleep(RT_MIN(RT_MAX(1, pStream->Cfg.Device.cMsSchedulingHint), 256));
336 else
337 AssertFailedBreakStmt(rc = VERR_AUDIO_STREAM_NOT_READY);
338
339 cbPlayedTotal += cbPlayed;
340 AssertBreakStmt(cbPlayedTotal <= cbToPlayTotal, VERR_BUFFER_OVERFLOW);
341
342 /* Fail-safe in case something screwed up while playing back. */
343 if (RTTimeNanoTS() - nsStarted > uTimeoutNs)
344 {
345 RTTestFailed(g_hTest, "Playback took too long (%RU32ms exceeded), aborting\n", uTimeoutNs / RT_NS_1MS);
346 rc = VERR_TIMEOUT;
347 }
348
349 if (RT_FAILURE(rc))
350 break;
351 }
352
353 if (cbPlayedTotal != cbToPlayTotal)
354 RTTestFailed(g_hTest, "Playback ended unexpectedly (%RU32/%RU32 played)\n", cbPlayedTotal, cbToPlayTotal);
355
356 if (RT_SUCCESS(rc))
357 {
358 RTTestPrintf(g_hTest, RTTESTLVL_ALWAYS, "Draining stream ...\n");
359 rc = AudioTestMixStreamDrain(&pStream->Mix, true /*fSync*/);
360 }
361 }
362 else
363 rc = VERR_AUDIO_STREAM_NOT_READY;
364
365 if (pTstEnv)
366 {
367 int rc2 = AudioTestObjClose(Obj);
368 if (RT_SUCCESS(rc))
369 rc = rc2;
370 }
371
372 if (RT_FAILURE(rc))
373 RTTestFailed(g_hTest, "Playing tone failed with %Rrc\n", rc);
374
375 return rc;
376}
377
378/**
379 * Records a test tone from a specific audio test stream.
380 *
381 * @returns VBox status code.
382 * @param pTstEnv Test environment to use for running the test.
383 * @param pStream Stream to use for recording the tone.
384 * @param pParms Tone parameters to use.
385 *
386 * @note Blocking function.
387 */
388static int audioTestRecordTone(PAUDIOTESTENV pTstEnv, PAUDIOTESTSTREAM pStream, PAUDIOTESTTONEPARMS pParms)
389{
390 const char *pcszPathOut = pTstEnv->Set.szPathAbs;
391
392 RTTestPrintf(g_hTest, RTTESTLVL_ALWAYS, "Recording test tone (tone frequency is %RU16Hz, %RU32ms)\n", (uint16_t)pParms->dbFreqHz, pParms->msDuration);
393 RTTestPrintf(g_hTest, RTTESTLVL_DEBUG, "Writing to '%s'\n", pcszPathOut);
394
395 /** @todo Use .WAV here? */
396 AUDIOTESTOBJ Obj;
397 int rc = AudioTestSetObjCreateAndRegister(&pTstEnv->Set, "guest-tone-rec.pcm", &Obj);
398 AssertRCReturn(rc, rc);
399
400 PAUDIOTESTDRVMIXSTREAM pMix = &pStream->Mix;
401
402 rc = AudioTestMixStreamEnable(pMix);
403 if (RT_SUCCESS(rc))
404 {
405 uint64_t cbToRecTotal = PDMAudioPropsMilliToBytes(&pStream->Cfg.Props, pParms->msDuration);
406
407 RTTestPrintf(g_hTest, RTTESTLVL_DEBUG, "Recording %RU32 bytes total\n", cbToRecTotal);
408
409 AudioTestObjAddMetadataStr(Obj, "stream_to_record_bytes=%RU32\n", cbToRecTotal);
410 AudioTestObjAddMetadataStr(Obj, "stream_buffer_size_ms=%RU32\n", pTstEnv->cMsBufferSize);
411 AudioTestObjAddMetadataStr(Obj, "stream_prebuf_size_ms=%RU32\n", pTstEnv->cMsPreBuffer);
412 /* Note: This mostly is provided by backend (e.g. PulseAudio / ALSA / ++) and
413 * has nothing to do with the device emulation scheduling hint. */
414 AudioTestObjAddMetadataStr(Obj, "device_scheduling_hint_ms=%RU32\n", pTstEnv->cMsSchedulingHint);
415
416 uint8_t abSamples[16384];
417 uint32_t const cbSamplesAligned = PDMAudioPropsFloorBytesToFrame(pMix->pProps, sizeof(abSamples));
418 uint64_t cbRecTotal = 0;
419 while (!g_fTerminate && cbRecTotal < cbToRecTotal)
420 {
421 /*
422 * Anything we can read?
423 */
424 uint32_t const cbCanRead = AudioTestMixStreamGetReadable(pMix);
425 if (cbCanRead)
426 {
427 uint32_t const cbToRead = RT_MIN(cbCanRead, cbSamplesAligned);
428 uint32_t cbRecorded = 0;
429 rc = AudioTestMixStreamCapture(pMix, abSamples, cbToRead, &cbRecorded);
430 if (RT_SUCCESS(rc))
431 {
432 if (cbRecorded)
433 {
434 rc = AudioTestObjWrite(Obj, abSamples, cbRecorded);
435 if (RT_SUCCESS(rc))
436 {
437 cbRecTotal += cbRecorded;
438
439 /** @todo Clamp result? */
440 }
441 }
442 }
443 }
444 else if (AudioTestMixStreamIsOkay(pMix))
445 RTThreadSleep(RT_MIN(RT_MAX(1, pTstEnv->cMsSchedulingHint), 256));
446
447 if (RT_FAILURE(rc))
448 break;
449 }
450
451 int rc2 = AudioTestMixStreamDisable(pMix);
452 if (RT_SUCCESS(rc))
453 rc = rc2;
454 }
455
456 int rc2 = AudioTestObjClose(Obj);
457 if (RT_SUCCESS(rc))
458 rc = rc2;
459
460 if (RT_FAILURE(rc))
461 RTTestFailed(g_hTest, "Recording tone done failed with %Rrc\n", rc);
462
463 return rc;
464}
465
466
467/*********************************************************************************************************************************
468* ATS Callback Implementations *
469*********************************************************************************************************************************/
470
471/** @copydoc ATSCALLBACKS::pfnHowdy
472 *
473 * @note Runs as part of the guest ATS.
474 */
475static DECLCALLBACK(int) audioTestGstAtsHowdyCallback(void const *pvUser)
476{
477 PATSCALLBACKCTX pCtx = (PATSCALLBACKCTX)pvUser;
478
479 AssertReturn(pCtx->cClients <= UINT8_MAX - 1, VERR_BUFFER_OVERFLOW);
480
481 pCtx->cClients++;
482
483 RTTestPrintf(g_hTest, RTTESTLVL_ALWAYS, "New client connected, now %RU8 total\n", pCtx->cClients);
484
485 return VINF_SUCCESS;
486}
487
488/** @copydoc ATSCALLBACKS::pfnBye
489 *
490 * @note Runs as part of the guest ATS.
491 */
492static DECLCALLBACK(int) audioTestGstAtsByeCallback(void const *pvUser)
493{
494 PATSCALLBACKCTX pCtx = (PATSCALLBACKCTX)pvUser;
495
496 AssertReturn(pCtx->cClients, VERR_WRONG_ORDER);
497 pCtx->cClients--;
498
499 RTTestPrintf(g_hTest, RTTESTLVL_ALWAYS, "Client wants to disconnect, %RU8 remaining\n", pCtx->cClients);
500
501 if (0 == pCtx->cClients) /* All clients disconnected? Tear things down. */
502 {
503 RTTestPrintf(g_hTest, RTTESTLVL_ALWAYS, "Last client disconnected, terminating server ...\n");
504 ASMAtomicWriteBool(&g_fTerminate, true);
505 }
506
507 return VINF_SUCCESS;
508}
509
510/** @copydoc ATSCALLBACKS::pfnTestSetBegin
511 *
512 * @note Runs as part of the guest ATS.
513 */
514static DECLCALLBACK(int) audioTestGstAtsTestSetBeginCallback(void const *pvUser, const char *pszTag)
515{
516 PATSCALLBACKCTX pCtx = (PATSCALLBACKCTX)pvUser;
517 PAUDIOTESTENV pTstEnv = pCtx->pTstEnv;
518
519 RTTestPrintf(g_hTest, RTTESTLVL_ALWAYS, "Got request for beginning test set '%s' in '%s'\n", pszTag, pTstEnv->szPathTemp);
520
521 return AudioTestSetCreate(&pTstEnv->Set, pTstEnv->szPathTemp, pszTag);
522}
523
524/** @copydoc ATSCALLBACKS::pfnTestSetEnd
525 *
526 * @note Runs as part of the guest ATS.
527 */
528static DECLCALLBACK(int) audioTestGstAtsTestSetEndCallback(void const *pvUser, const char *pszTag)
529{
530 PATSCALLBACKCTX pCtx = (PATSCALLBACKCTX)pvUser;
531 PAUDIOTESTENV pTstEnv = pCtx->pTstEnv;
532
533 RTTestPrintf(g_hTest, RTTESTLVL_ALWAYS, "Got request for ending test set '%s'\n", pszTag);
534
535 /* Pack up everything to be ready for transmission. */
536 return audioTestEnvPrologue(pTstEnv, true /* fPack */, pCtx->szTestSetArchive, sizeof(pCtx->szTestSetArchive));
537}
538
539/** @copydoc ATSCALLBACKS::pfnTonePlay
540 *
541 * @note Runs as part of the guest ATS.
542 */
543static DECLCALLBACK(int) audioTestGstAtsTonePlayCallback(void const *pvUser, PAUDIOTESTTONEPARMS pToneParms)
544{
545 PATSCALLBACKCTX pCtx = (PATSCALLBACKCTX)pvUser;
546 PAUDIOTESTENV pTstEnv = pCtx->pTstEnv;
547
548 RTTestPrintf(g_hTest, RTTESTLVL_ALWAYS, "Got request for playing test tone (%RU16Hz, %RU32ms) ...\n",
549 (uint16_t)pToneParms->dbFreqHz, pToneParms->msDuration);
550
551 const PAUDIOTESTSTREAM pTstStream = &pTstEnv->aStreams[0]; /** @todo Make this dynamic. */
552
553 int rc = audioTestStreamInit(pTstEnv->pDrvStack, pTstStream, PDMAUDIODIR_OUT, &pTstEnv->Props, false /* fWithMixer */,
554 pTstEnv->cMsBufferSize, pTstEnv->cMsPreBuffer, pTstEnv->cMsSchedulingHint);
555 if (RT_SUCCESS(rc))
556 {
557 AUDIOTESTPARMS TstParms;
558 RT_ZERO(TstParms);
559 TstParms.enmType = AUDIOTESTTYPE_TESTTONE_PLAY;
560 TstParms.enmDir = PDMAUDIODIR_OUT;
561 TstParms.TestTone = *pToneParms;
562
563 PAUDIOTESTENTRY pTst;
564 rc = AudioTestSetTestBegin(&pTstEnv->Set, "Playing test tone", &TstParms, &pTst);
565 if (RT_SUCCESS(rc))
566 {
567 rc = audioTestPlayTone(pTstEnv, pTstStream, pToneParms);
568 if (RT_SUCCESS(rc))
569 {
570 AudioTestSetTestDone(pTst);
571 }
572 else
573 AudioTestSetTestFailed(pTst, rc, "Playing tone failed");
574 }
575
576 int rc2 = audioTestStreamDestroy(pTstEnv, pTstStream);
577 if (RT_SUCCESS(rc))
578 rc = rc2;
579 }
580 else
581 RTTestFailed(g_hTest, "Error creating output stream, rc=%Rrc\n", rc);
582
583 return rc;
584}
585
586/** @copydoc ATSCALLBACKS::pfnToneRecord */
587static DECLCALLBACK(int) audioTestGstAtsToneRecordCallback(void const *pvUser, PAUDIOTESTTONEPARMS pToneParms)
588{
589 PATSCALLBACKCTX pCtx = (PATSCALLBACKCTX)pvUser;
590 PAUDIOTESTENV pTstEnv = pCtx->pTstEnv;
591
592 RTTestPrintf(g_hTest, RTTESTLVL_ALWAYS, "Got request for recording test tone (%RU32ms) ...\n", pToneParms->msDuration);
593
594 const PAUDIOTESTSTREAM pTstStream = &pTstEnv->aStreams[0]; /** @todo Make this dynamic. */
595
596 int rc = audioTestStreamInit(pTstEnv->pDrvStack, pTstStream, PDMAUDIODIR_IN, &pTstEnv->Props, false /* fWithMixer */,
597 pTstEnv->cMsBufferSize, pTstEnv->cMsPreBuffer, pTstEnv->cMsSchedulingHint);
598 if (RT_SUCCESS(rc))
599 {
600 AUDIOTESTPARMS TstParms;
601 RT_ZERO(TstParms);
602 TstParms.enmType = AUDIOTESTTYPE_TESTTONE_RECORD;
603 TstParms.enmDir = PDMAUDIODIR_IN;
604 TstParms.Props = pToneParms->Props;
605 TstParms.TestTone = *pToneParms;
606
607 PAUDIOTESTENTRY pTst;
608 rc = AudioTestSetTestBegin(&pTstEnv->Set, "Recording test tone from host", &TstParms, &pTst);
609 if (RT_SUCCESS(rc))
610 {
611 rc = audioTestRecordTone(pTstEnv, pTstStream, pToneParms);
612 if (RT_SUCCESS(rc))
613 {
614 AudioTestSetTestDone(pTst);
615 }
616 else
617 AudioTestSetTestFailed(pTst, rc, "Recording tone failed");
618 }
619
620 int rc2 = audioTestStreamDestroy(pTstEnv, pTstStream);
621 if (RT_SUCCESS(rc))
622 rc = rc2;
623 }
624 else
625 RTTestFailed(g_hTest, "Error creating input stream, rc=%Rrc\n", rc);
626
627 return rc;
628}
629
630/** @copydoc ATSCALLBACKS::pfnTestSetSendBegin */
631static DECLCALLBACK(int) audioTestGstAtsTestSetSendBeginCallback(void const *pvUser, const char *pszTag)
632{
633 RT_NOREF(pszTag);
634
635 PATSCALLBACKCTX pCtx = (PATSCALLBACKCTX)pvUser;
636
637 if (!RTFileExists(pCtx->szTestSetArchive)) /* Has the archive successfully been created yet? */
638 return VERR_WRONG_ORDER;
639
640 int rc = RTFileOpen(&pCtx->hTestSetArchive, pCtx->szTestSetArchive, RTFILE_O_READ | RTFILE_O_OPEN | RTFILE_O_DENY_WRITE);
641 if (RT_SUCCESS(rc))
642 {
643 uint64_t uSize;
644 rc = RTFileQuerySize(pCtx->hTestSetArchive, &uSize);
645 if (RT_SUCCESS(rc))
646 RTTestPrintf(g_hTest, RTTESTLVL_ALWAYS, "Sending test set '%s' (%zu bytes)\n", pCtx->szTestSetArchive, uSize);
647 }
648
649 return rc;
650}
651
652/** @copydoc ATSCALLBACKS::pfnTestSetSendRead */
653static DECLCALLBACK(int) audioTestGstAtsTestSetSendReadCallback(void const *pvUser,
654 const char *pszTag, void *pvBuf, size_t cbBuf, size_t *pcbRead)
655{
656 RT_NOREF(pszTag);
657
658 PATSCALLBACKCTX pCtx = (PATSCALLBACKCTX)pvUser;
659
660 return RTFileRead(pCtx->hTestSetArchive, pvBuf, cbBuf, pcbRead);
661}
662
663/** @copydoc ATSCALLBACKS::pfnTestSetSendEnd */
664static DECLCALLBACK(int) audioTestGstAtsTestSetSendEndCallback(void const *pvUser, const char *pszTag)
665{
666 RT_NOREF(pszTag);
667
668 PATSCALLBACKCTX pCtx = (PATSCALLBACKCTX)pvUser;
669
670 int rc = RTFileClose(pCtx->hTestSetArchive);
671 if (RT_SUCCESS(rc))
672 {
673 pCtx->hTestSetArchive = NIL_RTFILE;
674 }
675
676 return rc;
677}
678
679
680/*********************************************************************************************************************************
681* Implementation of audio test environment handling *
682*********************************************************************************************************************************/
683
684/**
685 * Connects an ATS client via TCP/IP to a peer.
686 *
687 * @returns VBox status code.
688 * @param pTstEnv Test environment to use.
689 * @param pClient Client to connect.
690 * @param pszWhat Hint of what to connect to where.
691 * @param pTcpOpts Pointer to TCP options to use.
692 */
693int audioTestEnvConnectViaTcp(PAUDIOTESTENV pTstEnv, PATSCLIENT pClient, const char *pszWhat, PAUDIOTESTENVTCPOPTS pTcpOpts)
694{
695 RT_NOREF(pTstEnv);
696
697 RTGETOPTUNION Val;
698 RT_ZERO(Val);
699
700 Val.u32 = pTcpOpts->enmConnMode;
701 int rc = AudioTestSvcClientHandleOption(pClient, ATSTCPOPT_CONN_MODE, &Val);
702 AssertRCReturn(rc, rc);
703
704 if ( pTcpOpts->enmConnMode == ATSCONNMODE_BOTH
705 || pTcpOpts->enmConnMode == ATSCONNMODE_SERVER)
706 {
707 Assert(pTcpOpts->uBindPort); /* Always set by the caller. */
708 Val.u16 = pTcpOpts->uBindPort;
709 rc = AudioTestSvcClientHandleOption(pClient, ATSTCPOPT_BIND_PORT, &Val);
710 AssertRCReturn(rc, rc);
711
712 if (pTcpOpts->szBindAddr[0])
713 {
714 Val.psz = pTcpOpts->szBindAddr;
715 rc = AudioTestSvcClientHandleOption(pClient, ATSTCPOPT_BIND_ADDRESS, &Val);
716 AssertRCReturn(rc, rc);
717 }
718 else
719 {
720 RTTestFailed(g_hTest, "No bind address specified!\n");
721 return VERR_INVALID_PARAMETER;
722 }
723
724 RTTestPrintf(g_hTest, RTTESTLVL_ALWAYS, "Connecting %s by listening as server at %s:%RU32 ...\n",
725 pszWhat, pTcpOpts->szBindAddr, pTcpOpts->uBindPort);
726 }
727
728
729 if ( pTcpOpts->enmConnMode == ATSCONNMODE_BOTH
730 || pTcpOpts->enmConnMode == ATSCONNMODE_CLIENT)
731 {
732 Assert(pTcpOpts->uConnectPort); /* Always set by the caller. */
733 Val.u16 = pTcpOpts->uConnectPort;
734 rc = AudioTestSvcClientHandleOption(pClient, ATSTCPOPT_CONNECT_PORT, &Val);
735 AssertRCReturn(rc, rc);
736
737 if (pTcpOpts->szConnectAddr[0])
738 {
739 Val.psz = pTcpOpts->szConnectAddr;
740 rc = AudioTestSvcClientHandleOption(pClient, ATSTCPOPT_CONNECT_ADDRESS, &Val);
741 AssertRCReturn(rc, rc);
742 }
743 else
744 {
745 RTTestFailed(g_hTest, "No connect address specified!\n");
746 return VERR_INVALID_PARAMETER;
747 }
748
749 RTTestPrintf(g_hTest, RTTESTLVL_ALWAYS, "Connecting %s by connecting as client to %s:%RU32 ...\n",
750 pszWhat, pTcpOpts->szConnectAddr, pTcpOpts->uConnectPort);
751 }
752
753 rc = AudioTestSvcClientConnect(pClient);
754 if (RT_FAILURE(rc))
755 {
756 RTTestFailed(g_hTest, "Connecting %s failed with %Rrc\n", pszWhat, rc);
757 return rc;
758 }
759
760 RTTestPrintf(g_hTest, RTTESTLVL_ALWAYS, "Successfully connected %s\n", pszWhat);
761 return rc;
762}
763
764/**
765 * Configures and starts an ATS TCP/IP server.
766 *
767 * @returns VBox status code.
768 * @param pSrv ATS server instance to configure and start.
769 * @param pCallbacks ATS callback table to use.
770 * @param pszDesc Hint of server type which is being started.
771 * @param pTcpOpts TCP options to use.
772 */
773int audioTestEnvConfigureAndStartTcpServer(PATSSERVER pSrv, PCATSCALLBACKS pCallbacks, const char *pszDesc,
774 PAUDIOTESTENVTCPOPTS pTcpOpts)
775{
776 RTGETOPTUNION Val;
777 RT_ZERO(Val);
778
779 int rc = AudioTestSvcInit(pSrv, pCallbacks);
780 if (RT_FAILURE(rc))
781 return rc;
782
783 Val.u32 = pTcpOpts->enmConnMode;
784 rc = AudioTestSvcHandleOption(pSrv, ATSTCPOPT_CONN_MODE, &Val);
785 AssertRCReturn(rc, rc);
786
787 if ( pTcpOpts->enmConnMode == ATSCONNMODE_BOTH
788 || pTcpOpts->enmConnMode == ATSCONNMODE_SERVER)
789 {
790 Assert(pTcpOpts->uBindPort); /* Always set by the caller. */
791 Val.u16 = pTcpOpts->uBindPort;
792 rc = AudioTestSvcHandleOption(pSrv, ATSTCPOPT_BIND_PORT, &Val);
793 AssertRCReturn(rc, rc);
794
795 if (pTcpOpts->szBindAddr[0])
796 {
797 Val.psz = pTcpOpts->szBindAddr;
798 rc = AudioTestSvcHandleOption(pSrv, ATSTCPOPT_BIND_ADDRESS, &Val);
799 AssertRCReturn(rc, rc);
800 }
801 else
802 {
803 RTTestFailed(g_hTest, "No bind address specified!\n");
804 return VERR_INVALID_PARAMETER;
805 }
806
807 RTTestPrintf(g_hTest, RTTESTLVL_ALWAYS, "Starting server for %s at %s:%RU32 ...\n",
808 pszDesc, pTcpOpts->szBindAddr, pTcpOpts->uBindPort);
809 }
810
811
812 if ( pTcpOpts->enmConnMode == ATSCONNMODE_BOTH
813 || pTcpOpts->enmConnMode == ATSCONNMODE_CLIENT)
814 {
815 Assert(pTcpOpts->uConnectPort); /* Always set by the caller. */
816 Val.u16 = pTcpOpts->uConnectPort;
817 rc = AudioTestSvcHandleOption(pSrv, ATSTCPOPT_CONNECT_PORT, &Val);
818 AssertRCReturn(rc, rc);
819
820 if (pTcpOpts->szConnectAddr[0])
821 {
822 Val.psz = pTcpOpts->szConnectAddr;
823 rc = AudioTestSvcHandleOption(pSrv, ATSTCPOPT_CONNECT_ADDRESS, &Val);
824 AssertRCReturn(rc, rc);
825 }
826 else
827 {
828 RTTestFailed(g_hTest, "No connect address specified!\n");
829 return VERR_INVALID_PARAMETER;
830 }
831
832 RTTestPrintf(g_hTest, RTTESTLVL_ALWAYS, "Starting server for %s by connecting as client to %s:%RU32 ...\n",
833 pszDesc, pTcpOpts->szConnectAddr, pTcpOpts->uConnectPort);
834 }
835
836 if (RT_SUCCESS(rc))
837 {
838 rc = AudioTestSvcStart(pSrv);
839 if (RT_FAILURE(rc))
840 RTTestFailed(g_hTest, "Starting server for %s failed with %Rrc\n", pszDesc, rc);
841 }
842
843 return rc;
844}
845
846/**
847 * Initializes an audio test environment.
848 *
849 * @returns VBox status code.
850 * @param pTstEnv Audio test environment to initialize.
851 * @param pDrvStack Driver stack to use.
852 */
853int audioTestEnvInit(PAUDIOTESTENV pTstEnv, PAUDIOTESTDRVSTACK pDrvStack)
854{
855 int rc = VINF_SUCCESS;
856
857 pTstEnv->pDrvStack = pDrvStack;
858
859 /*
860 * Set sane defaults if not already set.
861 */
862 if (!RTStrNLen(pTstEnv->szTag, sizeof(pTstEnv->szTag)))
863 {
864 rc = AudioTestGenTag(pTstEnv->szTag, sizeof(pTstEnv->szTag));
865 AssertRCReturn(rc, rc);
866 }
867
868 if (!RTStrNLen(pTstEnv->szPathTemp, sizeof(pTstEnv->szPathTemp)))
869 {
870 rc = AudioTestPathGetTemp(pTstEnv->szPathTemp, sizeof(pTstEnv->szPathTemp));
871 AssertRCReturn(rc, rc);
872 }
873
874 if (!RTStrNLen(pTstEnv->szPathOut, sizeof(pTstEnv->szPathOut)))
875 {
876 rc = RTPathJoin(pTstEnv->szPathOut, sizeof(pTstEnv->szPathOut), pTstEnv->szPathTemp, "vkat-temp");
877 AssertRCReturn(rc, rc);
878 }
879
880 RTTestPrintf(g_hTest, RTTESTLVL_ALWAYS, "Initializing environment for mode '%s'\n", pTstEnv->enmMode == AUDIOTESTMODE_HOST ? "host" : "guest");
881 RTTestPrintf(g_hTest, RTTESTLVL_ALWAYS, "Using tag '%s'\n", pTstEnv->szTag);
882 RTTestPrintf(g_hTest, RTTESTLVL_ALWAYS, "Output directory is '%s'\n", pTstEnv->szPathOut);
883 RTTestPrintf(g_hTest, RTTESTLVL_ALWAYS, "Temp directory is '%s'\n", pTstEnv->szPathTemp);
884
885 if (!pTstEnv->cMsBufferSize)
886 pTstEnv->cMsBufferSize = UINT32_MAX;
887 if (!pTstEnv->cMsPreBuffer)
888 pTstEnv->cMsPreBuffer = UINT32_MAX;
889 if (!pTstEnv->cMsSchedulingHint)
890 pTstEnv->cMsSchedulingHint = UINT32_MAX;
891
892 char szPathTemp[RTPATH_MAX];
893 if ( !strlen(pTstEnv->szPathTemp)
894 || !strlen(pTstEnv->szPathOut))
895 rc = RTPathTemp(szPathTemp, sizeof(szPathTemp));
896
897 if ( RT_SUCCESS(rc)
898 && !strlen(pTstEnv->szPathTemp))
899 rc = RTPathJoin(pTstEnv->szPathTemp, sizeof(pTstEnv->szPathTemp), szPathTemp, "vkat-temp");
900
901 if (RT_SUCCESS(rc))
902 {
903 rc = RTDirCreate(pTstEnv->szPathTemp, RTFS_UNIX_IRWXU, 0 /* fFlags */);
904 if (rc == VERR_ALREADY_EXISTS)
905 rc = VINF_SUCCESS;
906 }
907
908 if ( RT_SUCCESS(rc)
909 && !strlen(pTstEnv->szPathOut))
910 rc = RTPathJoin(pTstEnv->szPathOut, sizeof(pTstEnv->szPathOut), szPathTemp, "vkat");
911
912 if (RT_SUCCESS(rc))
913 {
914 rc = RTDirCreate(pTstEnv->szPathOut, RTFS_UNIX_IRWXU, 0 /* fFlags */);
915 if (rc == VERR_ALREADY_EXISTS)
916 rc = VINF_SUCCESS;
917 }
918
919 if (RT_FAILURE(rc))
920 return rc;
921
922 /**
923 * For NAT'ed VMs we use (default):
924 * - client mode (uConnectAddr / uConnectPort) on the guest.
925 * - server mode (uBindAddr / uBindPort) on the host.
926 */
927 if ( !pTstEnv->TcpOpts.szConnectAddr[0]
928 && !pTstEnv->TcpOpts.szBindAddr[0])
929 RTStrCopy(pTstEnv->TcpOpts.szBindAddr, sizeof(pTstEnv->TcpOpts.szBindAddr), "0.0.0.0");
930
931 /*
932 * Determine connection mode based on set variables.
933 */
934 if ( pTstEnv->TcpOpts.szBindAddr[0]
935 && pTstEnv->TcpOpts.szConnectAddr[0])
936 {
937 pTstEnv->TcpOpts.enmConnMode = ATSCONNMODE_BOTH;
938 }
939 else if (pTstEnv->TcpOpts.szBindAddr[0])
940 pTstEnv->TcpOpts.enmConnMode = ATSCONNMODE_SERVER;
941 else /* "Reversed mode", i.e. used for NATed VMs. */
942 pTstEnv->TcpOpts.enmConnMode = ATSCONNMODE_CLIENT;
943
944 /* Set a back reference to the test environment for the callback context. */
945 pTstEnv->CallbackCtx.pTstEnv = pTstEnv;
946
947 ATSCALLBACKS Callbacks;
948 RT_ZERO(Callbacks);
949 Callbacks.pvUser = &pTstEnv->CallbackCtx;
950
951 if (pTstEnv->enmMode == AUDIOTESTMODE_GUEST)
952 {
953 Callbacks.pfnHowdy = audioTestGstAtsHowdyCallback;
954 Callbacks.pfnBye = audioTestGstAtsByeCallback;
955 Callbacks.pfnTestSetBegin = audioTestGstAtsTestSetBeginCallback;
956 Callbacks.pfnTestSetEnd = audioTestGstAtsTestSetEndCallback;
957 Callbacks.pfnTonePlay = audioTestGstAtsTonePlayCallback;
958 Callbacks.pfnToneRecord = audioTestGstAtsToneRecordCallback;
959 Callbacks.pfnTestSetSendBegin = audioTestGstAtsTestSetSendBeginCallback;
960 Callbacks.pfnTestSetSendRead = audioTestGstAtsTestSetSendReadCallback;
961 Callbacks.pfnTestSetSendEnd = audioTestGstAtsTestSetSendEndCallback;
962
963 if (!pTstEnv->TcpOpts.uBindPort)
964 pTstEnv->TcpOpts.uBindPort = ATS_TCP_DEF_BIND_PORT_GUEST;
965
966 if (!pTstEnv->TcpOpts.uConnectPort)
967 pTstEnv->TcpOpts.uConnectPort = ATS_TCP_DEF_CONNECT_PORT_GUEST;
968
969 pTstEnv->pSrv = (PATSSERVER)RTMemAlloc(sizeof(ATSSERVER));
970 AssertPtrReturn(pTstEnv->pSrv, VERR_NO_MEMORY);
971
972 /*
973 * Start the ATS (Audio Test Service) on the guest side.
974 * That service then will perform playback and recording operations on the guest, triggered from the host.
975 *
976 * When running this in self-test mode, that service also can be run on the host if nothing else is specified.
977 * Note that we have to bind to "0.0.0.0" by default so that the host can connect to it.
978 */
979 rc = audioTestEnvConfigureAndStartTcpServer(pTstEnv->pSrv, &Callbacks, "guest", &pTstEnv->TcpOpts);
980 }
981 else /* Host mode */
982 {
983 if (!pTstEnv->TcpOpts.uBindPort)
984 pTstEnv->TcpOpts.uBindPort = ATS_TCP_DEF_BIND_PORT_HOST;
985
986 if (!pTstEnv->TcpOpts.uConnectPort)
987 pTstEnv->TcpOpts.uConnectPort = ATS_TCP_DEF_CONNECT_PORT_HOST_PORT_FWD;
988
989 /**
990 * Note: Don't set pTstEnv->TcpOpts.szTcpConnectAddr by default here, as this specifies what connection mode
991 * (client / server / both) we use on the host.
992 */
993
994 /* We need to start a server on the host so that VMs configured with NAT networking
995 * can connect to it as well. */
996 rc = AudioTestSvcClientCreate(&pTstEnv->u.Host.AtsClGuest);
997 if (RT_SUCCESS(rc))
998 rc = audioTestEnvConnectViaTcp(pTstEnv, &pTstEnv->u.Host.AtsClGuest,
999 "host -> guest", &pTstEnv->TcpOpts);
1000 if (RT_SUCCESS(rc))
1001 {
1002 AUDIOTESTENVTCPOPTS ValKitTcpOpts;
1003 RT_ZERO(ValKitTcpOpts);
1004
1005 /* We only connect as client to the Validation Kit audio driver ATS. */
1006 ValKitTcpOpts.enmConnMode = ATSCONNMODE_CLIENT;
1007
1008 /* For now we ASSUME that the Validation Kit audio driver ATS runs on the same host as VKAT (this binary) runs on. */
1009 ValKitTcpOpts.uConnectPort = ATS_TCP_DEF_CONNECT_PORT_VALKIT; /** @todo Make this dynamic. */
1010 RTStrCopy(ValKitTcpOpts.szConnectAddr, sizeof(ValKitTcpOpts.szConnectAddr), ATS_TCP_DEF_CONNECT_HOST_ADDR_STR); /** @todo Ditto. */
1011
1012 rc = AudioTestSvcClientCreate(&pTstEnv->u.Host.AtsClValKit);
1013 if (RT_SUCCESS(rc))
1014 {
1015 rc = audioTestEnvConnectViaTcp(pTstEnv, &pTstEnv->u.Host.AtsClValKit,
1016 "host -> valkit", &ValKitTcpOpts);
1017 if (RT_FAILURE(rc))
1018 RTTestPrintf(g_hTest, RTTESTLVL_ALWAYS, "Unable to connect to the Validation Kit audio driver!\n"
1019 "There could be multiple reasons:\n\n"
1020 " - Wrong host being used\n"
1021 " - VirtualBox host version is too old\n"
1022 " - Audio debug mode is not enabled\n"
1023 " - Support for Validation Kit audio driver is not included\n"
1024 " - Firewall / network configuration problem\n");
1025 }
1026 }
1027 }
1028
1029 return rc;
1030}
1031
1032/**
1033 * Destroys an audio test environment.
1034 *
1035 * @param pTstEnv Audio test environment to destroy.
1036 */
1037void audioTestEnvDestroy(PAUDIOTESTENV pTstEnv)
1038{
1039 if (!pTstEnv)
1040 return;
1041
1042 /* When in host mode, we need to destroy our ATS clients in order to also let
1043 * the ATS server(s) know we're going to quit. */
1044 if (pTstEnv->enmMode == AUDIOTESTMODE_HOST)
1045 {
1046 AudioTestSvcClientDestroy(&pTstEnv->u.Host.AtsClValKit);
1047 AudioTestSvcClientDestroy(&pTstEnv->u.Host.AtsClGuest);
1048 }
1049
1050 if (pTstEnv->pSrv)
1051 {
1052 int rc2 = AudioTestSvcDestroy(pTstEnv->pSrv);
1053 AssertRC(rc2);
1054
1055 RTMemFree(pTstEnv->pSrv);
1056 pTstEnv->pSrv = NULL;
1057 }
1058
1059 for (unsigned i = 0; i < RT_ELEMENTS(pTstEnv->aStreams); i++)
1060 {
1061 int rc2 = audioTestStreamDestroy(pTstEnv, &pTstEnv->aStreams[i]);
1062 if (RT_FAILURE(rc2))
1063 RTTestFailed(g_hTest, "Stream destruction for stream #%u failed with %Rrc\n", i, rc2);
1064 }
1065
1066 /* Try cleaning up a bit. */
1067 RTDirRemove(pTstEnv->szPathTemp);
1068 RTDirRemove(pTstEnv->szPathOut);
1069
1070 pTstEnv->pDrvStack = NULL;
1071}
1072
1073/**
1074 * Closes, packs up and destroys a test environment.
1075 *
1076 * @returns VBox status code.
1077 * @param pTstEnv Test environment to handle.
1078 * @param fPack Whether to pack the test set up before destroying / wiping it.
1079 * @param pszPackFile Where to store the packed test set file on success. Can be NULL if \a fPack is \c false.
1080 * @param cbPackFile Size (in bytes) of \a pszPackFile. Can be 0 if \a fPack is \c false.
1081 */
1082int audioTestEnvPrologue(PAUDIOTESTENV pTstEnv, bool fPack, char *pszPackFile, size_t cbPackFile)
1083{
1084 /* Close the test set first. */
1085 AudioTestSetClose(&pTstEnv->Set);
1086
1087 int rc = VINF_SUCCESS;
1088
1089 if (fPack)
1090 {
1091 /* Before destroying the test environment, pack up the test set so
1092 * that it's ready for transmission. */
1093 rc = AudioTestSetPack(&pTstEnv->Set, pTstEnv->szPathOut, pszPackFile, cbPackFile);
1094 if (RT_SUCCESS(rc))
1095 RTTestPrintf(g_hTest, RTTESTLVL_ALWAYS, "Test set packed up to '%s'\n", pszPackFile);
1096 }
1097
1098 if (!g_fDrvAudioDebug) /* Don't wipe stuff when debugging. Can be useful for introspecting data. */
1099 /* ignore rc */ AudioTestSetWipe(&pTstEnv->Set);
1100
1101 AudioTestSetDestroy(&pTstEnv->Set);
1102
1103 if (RT_FAILURE(rc))
1104 RTTestFailed(g_hTest, "Test set prologue failed with %Rrc\n", rc);
1105
1106 return rc;
1107}
1108
1109/**
1110 * Initializes an audio test parameters set.
1111 *
1112 * @param pTstParms Test parameters set to initialize.
1113 */
1114void audioTestParmsInit(PAUDIOTESTPARMS pTstParms)
1115{
1116 RT_ZERO(*pTstParms);
1117}
1118
1119/**
1120 * Destroys an audio test parameters set.
1121 *
1122 * @param pTstParms Test parameters set to destroy.
1123 */
1124void audioTestParmsDestroy(PAUDIOTESTPARMS pTstParms)
1125{
1126 if (!pTstParms)
1127 return;
1128
1129 return;
1130}
1131
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