VirtualBox

source: vbox/trunk/src/VBox/Devices/Audio/testcase/tstAudioTestService.cpp@ 103914

Last change on this file since 103914 was 98103, checked in by vboxsync, 23 months ago

Copyright year updates by scm.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 5.3 KB
Line 
1/* $Id: tstAudioTestService.cpp 98103 2023-01-17 14:15:46Z vboxsync $ */
2/** @file
3 * Audio testcase - Tests for the Audio Test Service (ATS).
4 */
5
6/*
7 * Copyright (C) 2021-2023 Oracle and/or its affiliates.
8 *
9 * This file is part of VirtualBox base platform packages, as
10 * available from https://www.virtualbox.org.
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation, in version 3 of the
15 * License.
16 *
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, see <https://www.gnu.org/licenses>.
24 *
25 * SPDX-License-Identifier: GPL-3.0-only
26 */
27
28
29/*********************************************************************************************************************************
30* Header Files *
31*********************************************************************************************************************************/
32
33#include <iprt/errcore.h>
34#include <iprt/file.h>
35#include <iprt/initterm.h>
36#include <iprt/mem.h>
37#include <iprt/rand.h>
38#include <iprt/stream.h>
39#include <iprt/string.h>
40#include <iprt/test.h>
41
42#include "../AudioTestService.h"
43#include "../AudioTestServiceClient.h"
44
45
46static size_t g_cToRead = _1M;
47static size_t g_cbRead = 0;
48
49
50/** @copydoc ATSCALLBACKS::pfnTestSetSendRead */
51static DECLCALLBACK(int) tstTestSetSendReadCallback(void const *pvUser,
52 const char *pszTag, void *pvBuf, size_t cbBuf, size_t *pcbRead)
53{
54 RT_NOREF(pvUser, pszTag);
55
56 size_t cbToRead = RT_MIN(g_cToRead - g_cbRead, cbBuf);
57 if (cbToRead)
58 {
59 memset(pvBuf, 0x42, cbToRead);
60 g_cbRead += cbToRead;
61 }
62
63 *pcbRead = cbToRead;
64
65 return VINF_SUCCESS;
66}
67
68int main(int argc, char **argv)
69{
70 RTR3InitExe(argc, &argv, 0);
71
72 /*
73 * Initialize IPRT and create the test.
74 */
75 RTTEST hTest;
76 int rc = RTTestInitAndCreate("tstAudioTestService", &hTest);
77 if (rc)
78 return rc;
79 RTTestBanner(hTest);
80
81 ATSCALLBACKS Callbacks;
82 RT_ZERO(Callbacks);
83 Callbacks.pfnTestSetSendRead = tstTestSetSendReadCallback;
84
85 ATSSERVER Srv;
86 rc = AudioTestSvcInit(&Srv, &Callbacks);
87 RTTEST_CHECK_RC_OK(hTest, rc);
88
89 RTGETOPTUNION Val;
90 RT_ZERO(Val);
91
92 Val.u32 = ATSCONNMODE_SERVER;
93 rc = AudioTestSvcHandleOption(&Srv, ATSTCPOPT_CONN_MODE, &Val);
94 RTTEST_CHECK_RC_OK(hTest, rc);
95
96 ATSCLIENT Client;
97
98 if (RT_SUCCESS(rc))
99 {
100 uint16_t uPort = ATS_TCP_DEF_BIND_PORT_HOST;
101
102 for (unsigned i = 0; i < 64; i++)
103 {
104 Val.u16 = uPort;
105 rc = AudioTestSvcHandleOption(&Srv, ATSTCPOPT_BIND_PORT, &Val);
106 RTTEST_CHECK_RC_OK(hTest, rc);
107
108 rc = AudioTestSvcStart(&Srv);
109 if (RT_SUCCESS(rc))
110 break;
111
112 RTTestPrintf(hTest, RTTESTLVL_ALWAYS, "Port %RU32 already used\n", uPort);
113
114 /* Use a different port base in case VBox already is running
115 * with the same service using ATS_TCP_DEF_BIND_PORT_HOST. */
116 uPort = ATS_TCP_DEF_BIND_PORT_HOST + RTRandU32Ex(0, 4242);
117 }
118
119 if (RT_SUCCESS(rc))
120 {
121 RTTestPrintf(hTest, RTTESTLVL_ALWAYS, "Using port %RU32\n", uPort);
122
123 rc = AudioTestSvcClientCreate(&Client);
124 RTTEST_CHECK_RC_OK(hTest, rc);
125
126 Val.u32 = ATSCONNMODE_CLIENT;
127 rc = AudioTestSvcClientHandleOption(&Client, ATSTCPOPT_CONN_MODE, &Val);
128 RTTEST_CHECK_RC_OK(hTest, rc);
129
130 Val.psz = ATS_TCP_DEF_CONNECT_HOST_ADDR_STR;
131 rc = AudioTestSvcClientHandleOption(&Client, ATSTCPOPT_CONNECT_ADDRESS, &Val);
132 RTTEST_CHECK_RC_OK(hTest, rc);
133
134 Val.u16 = uPort;
135 rc = AudioTestSvcClientHandleOption(&Client, ATSTCPOPT_CONNECT_PORT, &Val);
136 RTTEST_CHECK_RC_OK(hTest, rc);
137
138 rc = AudioTestSvcClientConnect(&Client);
139 RTTEST_CHECK_RC_OK(hTest, rc);
140 }
141 }
142
143 if (RT_SUCCESS(rc))
144 {
145 char szTemp[RTPATH_MAX];
146 rc = RTPathTemp(szTemp, sizeof(szTemp));
147 RTTEST_CHECK_RC_OK(hTest, rc);
148 if (RT_SUCCESS(rc))
149 {
150 char szName[RTPATH_MAX];
151 RTTESTI_CHECK_RC(rc = RTStrCopy(szName, sizeof(szName), szTemp), VINF_SUCCESS);
152 RTTESTI_CHECK_RC(rc = RTPathAppend(szName, sizeof(szName), "tstAudioTestService-XXXXX"), VINF_SUCCESS);
153 if (RT_SUCCESS(rc))
154 {
155 rc = AudioTestSvcClientTestSetDownload(&Client, "ignored", szName);
156 RTTEST_CHECK_RC_OK(hTest, rc);
157
158 /* ignore rc */ RTFileDelete(szName);
159 }
160 }
161 }
162
163 rc = AudioTestSvcClientDisconnect(&Client);
164 RTTEST_CHECK_RC_OK(hTest, rc);
165
166 AudioTestSvcClientDestroy(&Client);
167
168 rc = AudioTestSvcStop(&Srv);
169 RTTEST_CHECK_RC_OK(hTest, rc);
170
171 rc = AudioTestSvcDestroy(&Srv);
172 RTTEST_CHECK_RC_OK(hTest, rc);
173
174 /*
175 * Summary
176 */
177 return RTTestSummaryAndDestroy(hTest);
178}
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