VirtualBox

source: vbox/trunk/src/VBox/ValidationKit/utils/audio/vkatCmdSelfTest.cpp@ 89545

Last change on this file since 89545 was 89544, checked in by vboxsync, 4 years ago

Audio/ValKit: Split up VKAT code into some more files as vkat.cpp got too big already. bugref:10008

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 6.2 KB
Line 
1/* $Id: vkatCmdSelfTest.cpp 89544 2021-06-07 11:06:40Z 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
32#include <iprt/ctype.h>
33#include <iprt/errcore.h>
34#include <iprt/getopt.h>
35#include <iprt/message.h>
36#include <iprt/test.h>
37
38#include "Audio/AudioHlp.h"
39#include "Audio/AudioTest.h"
40#include "Audio/AudioTestService.h"
41#include "Audio/AudioTestServiceClient.h"
42
43#include "vkatInternal.h"
44
45
46static DECLCALLBACK(int) audioTestSelftestGuestAtsThread(RTTHREAD hThread, void *pvUser)
47{
48 RT_NOREF(hThread);
49 PSELFTESTCTX pCtx = (PSELFTESTCTX)pvUser;
50
51 AUDIOTESTPARMS TstCust;
52 audioTestParmsInit(&TstCust);
53
54 PAUDIOTESTENV pTstEnv = &pCtx->Guest.TstEnv;
55
56 /* Flag the environment for self test mode. */
57 pTstEnv->fSelftest = true;
58
59 /* Generate tag for guest side. */
60 int rc = RTStrCopy(pTstEnv->szTag, sizeof(pTstEnv->szTag), pCtx->szTag);
61 AssertRCReturn(rc, rc);
62
63 rc = AudioTestPathCreateTemp(pTstEnv->szPathTemp, sizeof(pTstEnv->szPathTemp), "selftest-guest");
64 AssertRCReturn(rc, rc);
65
66 rc = AudioTestPathCreateTemp(pTstEnv->szPathOut, sizeof(pTstEnv->szPathOut), "selftest-out");
67 AssertRCReturn(rc, rc);
68
69 pTstEnv->enmMode = AUDIOTESTMODE_GUEST;
70
71 /** @todo Make this customizable. */
72 PDMAudioPropsInit(&TstCust.TestTone.Props,
73 2 /* 16-bit */, true /* fSigned */, 2 /* cChannels */, 44100 /* uHz */);
74
75 /* Use ATS_ALT_PORT, as on ATS_DEFAULT_PORT the
76 * Validation Kit audio driver ATS already is running on ATS_DEFAULT_PORT. */
77 rc = audioTestEnvInit(pTstEnv, pCtx->Guest.pDrvReg, pCtx->fWithDrvAudio,
78 "127.0.0.1", ATS_TCP_ALT_PORT);
79 if (RT_SUCCESS(rc))
80 {
81 RTThreadUserSignal(hThread);
82
83 audioTestWorker(pTstEnv, &TstCust);
84 audioTestEnvDestroy(pTstEnv);
85 }
86
87 audioTestParmsDestroy(&TstCust);
88
89 return rc;
90}
91
92/**
93 * Main function for performing the self test.
94 *
95 * @returns RTEXITCODE
96 * @param pCtx Self test context to use.
97 */
98RTEXITCODE audioTestDoSelftest(PSELFTESTCTX pCtx)
99{
100 RTTestPrintf(g_hTest, RTTESTLVL_ALWAYS, "Running self test ...\n");
101
102 /*
103 * The self-test does the following:
104 * - 1. Creates an ATS instance to emulate the guest mode ("--mode guest")
105 * at port 6042 (ATS_ALT_PORT).
106 * - 2. Uses the Validation Kit audio backend, which in turn creates an ATS instance
107 * at port 6052 (ATS_DEFAULT_PORT).
108 * - 3. Executes a complete test run locally (e.g. without any guest (VM) involved).
109 */
110
111 AUDIOTESTPARMS TstCust;
112 audioTestParmsInit(&TstCust);
113
114 /* Generate a common tag for guest and host side. */
115 int rc = AudioTestGenTag(pCtx->szTag, sizeof(pCtx->szTag));
116 AssertRCReturn(rc, RTEXITCODE_FAILURE);
117
118 PAUDIOTESTENV pTstEnv = &pCtx->Host.TstEnv;
119
120 /* Flag the environment for self test mode. */
121 pTstEnv->fSelftest = true;
122
123 /* Generate tag for host side. */
124 rc = RTStrCopy(pTstEnv->szTag, sizeof(pTstEnv->szTag), pCtx->szTag);
125 AssertRCReturn(rc, RTEXITCODE_FAILURE);
126
127 rc = AudioTestPathCreateTemp(pTstEnv->szPathTemp, sizeof(pTstEnv->szPathTemp), "selftest-host");
128 AssertRCReturn(rc, RTEXITCODE_FAILURE);
129
130 rc = AudioTestPathCreateTemp(pTstEnv->szPathOut, sizeof(pTstEnv->szPathOut), "selftest-out");
131 AssertRCReturn(rc, RTEXITCODE_FAILURE);
132
133 /*
134 * Step 1.
135 * Creates a separate thread for the guest ATS.
136 */
137 RTTHREAD hThreadGstAts;
138 rc = RTThreadCreate(&hThreadGstAts, audioTestSelftestGuestAtsThread, pCtx, 0, RTTHREADTYPE_IO, RTTHREADFLAGS_WAITABLE,
139 "VKATGstAts");
140 if (RT_SUCCESS(rc))
141 {
142 rc = RTThreadUserWait(hThreadGstAts, RT_MS_30SEC);
143 if (RT_SUCCESS(rc))
144 {
145 /*
146 * Steps 2 + 3.
147 */
148 pTstEnv->enmMode = AUDIOTESTMODE_HOST;
149
150 if (!pCtx->Host.uGuestAtsPort)
151 pCtx->Host.uGuestAtsPort = ATS_TCP_ALT_PORT;
152
153 rc = audioTestEnvInit(pTstEnv, &g_DrvHostValidationKitAudio, true /* fWithDrvAudio */,
154 pCtx->Host.szGuestAtsAddr, pCtx->Host.uGuestAtsPort);
155 if (RT_SUCCESS(rc))
156 {
157 audioTestWorker(pTstEnv, &TstCust);
158 audioTestEnvDestroy(pTstEnv);
159 }
160 }
161 }
162
163 audioTestParmsDestroy(&TstCust);
164
165 /*
166 * Shutting down.
167 */
168 RTTestPrintf(g_hTest, RTTESTLVL_ALWAYS, "Shutting down self test\n");
169
170 ASMAtomicWriteBool(&g_fTerminate, true);
171
172 int rcThread;
173 int rc2 = RTThreadWait(hThreadGstAts, RT_MS_30SEC, &rcThread);
174 if (RT_SUCCESS(rc2))
175 rc2 = rcThread;
176 if (RT_FAILURE(rc2))
177 RTTestFailed(g_hTest, "Shutting down self test failed with %Rrc\n", rc2);
178
179 if (RT_SUCCESS(rc))
180 rc = rc2;
181
182 if (RT_FAILURE(rc))
183 RTTestFailed(g_hTest, "Self test failed with %Rrc\n", rc);
184
185 return RT_SUCCESS(rc) ? RTEXITCODE_SUCCESS : RTEXITCODE_FAILURE;
186}
187
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