VirtualBox

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

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

Audio/Validation Kit: Fixed memory leaks found by ASAN, added + renamed some functions to streamline client destruction. bugref:10008

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 5.0 KB
Line 
1/* $Id: tstAudioTestService.cpp 91999 2021-10-22 11:43:28Z vboxsync $ */
2/** @file
3 * Audio testcase - Tests for the Audio Test Service (ATS).
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
18
19/*********************************************************************************************************************************
20* Header Files *
21*********************************************************************************************************************************/
22
23#include <iprt/errcore.h>
24#include <iprt/file.h>
25#include <iprt/initterm.h>
26#include <iprt/mem.h>
27#include <iprt/rand.h>
28#include <iprt/stream.h>
29#include <iprt/string.h>
30#include <iprt/test.h>
31
32#include "../AudioTestService.h"
33#include "../AudioTestServiceClient.h"
34
35
36static size_t g_cToRead = _1M;
37static size_t g_cbRead = 0;
38
39
40/** @copydoc ATSCALLBACKS::pfnTestSetSendRead */
41static DECLCALLBACK(int) tstTestSetSendReadCallback(void const *pvUser,
42 const char *pszTag, void *pvBuf, size_t cbBuf, size_t *pcbRead)
43{
44 RT_NOREF(pvUser, pszTag);
45
46 size_t cbToRead = RT_MIN(g_cToRead - g_cbRead, cbBuf);
47 if (cbToRead)
48 {
49 memset(pvBuf, 0x42, cbToRead);
50 g_cbRead += cbToRead;
51 }
52
53 *pcbRead = cbToRead;
54
55 return VINF_SUCCESS;
56}
57
58int main(int argc, char **argv)
59{
60 RTR3InitExe(argc, &argv, 0);
61
62 /*
63 * Initialize IPRT and create the test.
64 */
65 RTTEST hTest;
66 int rc = RTTestInitAndCreate("tstAudioTestService", &hTest);
67 if (rc)
68 return rc;
69 RTTestBanner(hTest);
70
71 ATSCALLBACKS Callbacks;
72 RT_ZERO(Callbacks);
73 Callbacks.pfnTestSetSendRead = tstTestSetSendReadCallback;
74
75 ATSSERVER Srv;
76 rc = AudioTestSvcInit(&Srv, &Callbacks);
77 RTTEST_CHECK_RC_OK(hTest, rc);
78
79 RTGETOPTUNION Val;
80 RT_ZERO(Val);
81
82 Val.u32 = ATSCONNMODE_SERVER;
83 rc = AudioTestSvcHandleOption(&Srv, ATSTCPOPT_CONN_MODE, &Val);
84 RTTEST_CHECK_RC_OK(hTest, rc);
85
86 ATSCLIENT Client;
87
88 if (RT_SUCCESS(rc))
89 {
90 uint16_t uPort = ATS_TCP_DEF_BIND_PORT_HOST;
91
92 for (unsigned i = 0; i < 64; i++)
93 {
94 Val.u16 = uPort;
95 rc = AudioTestSvcHandleOption(&Srv, ATSTCPOPT_BIND_PORT, &Val);
96 RTTEST_CHECK_RC_OK(hTest, rc);
97
98 rc = AudioTestSvcStart(&Srv);
99 if (RT_SUCCESS(rc))
100 break;
101
102 RTTestPrintf(hTest, RTTESTLVL_ALWAYS, "Port %RU32 already used\n", uPort);
103
104 /* Use a different port base in case VBox already is running
105 * with the same service using ATS_TCP_DEF_BIND_PORT_HOST. */
106 uPort = ATS_TCP_DEF_BIND_PORT_HOST + RTRandU32Ex(0, 4242);
107 }
108
109 if (RT_SUCCESS(rc))
110 {
111 RTTestPrintf(hTest, RTTESTLVL_ALWAYS, "Using port %RU32\n", uPort);
112
113 rc = AudioTestSvcClientCreate(&Client);
114 RTTEST_CHECK_RC_OK(hTest, rc);
115
116 Val.u32 = ATSCONNMODE_CLIENT;
117 rc = AudioTestSvcClientHandleOption(&Client, ATSTCPOPT_CONN_MODE, &Val);
118 RTTEST_CHECK_RC_OK(hTest, rc);
119
120 Val.psz = ATS_TCP_DEF_CONNECT_HOST_ADDR_STR;
121 rc = AudioTestSvcClientHandleOption(&Client, ATSTCPOPT_CONNECT_ADDRESS, &Val);
122 RTTEST_CHECK_RC_OK(hTest, rc);
123
124 Val.u16 = uPort;
125 rc = AudioTestSvcClientHandleOption(&Client, ATSTCPOPT_CONNECT_PORT, &Val);
126 RTTEST_CHECK_RC_OK(hTest, rc);
127
128 rc = AudioTestSvcClientConnect(&Client);
129 RTTEST_CHECK_RC_OK(hTest, rc);
130 }
131 }
132
133 if (RT_SUCCESS(rc))
134 {
135 char szTemp[RTPATH_MAX];
136 rc = RTPathTemp(szTemp, sizeof(szTemp));
137 RTTEST_CHECK_RC_OK(hTest, rc);
138 if (RT_SUCCESS(rc))
139 {
140 char szName[RTPATH_MAX];
141 RTTESTI_CHECK_RC(rc = RTStrCopy(szName, sizeof(szName), szTemp), VINF_SUCCESS);
142 RTTESTI_CHECK_RC(rc = RTPathAppend(szName, sizeof(szName), "tstAudioTestService-XXXXX"), VINF_SUCCESS);
143 if (RT_SUCCESS(rc))
144 {
145 rc = AudioTestSvcClientTestSetDownload(&Client, "ignored", szName);
146 RTTEST_CHECK_RC_OK(hTest, rc);
147
148 /* ignore rc */ RTFileDelete(szName);
149 }
150 }
151 }
152
153 rc = AudioTestSvcClientDisconnect(&Client);
154 RTTEST_CHECK_RC_OK(hTest, rc);
155
156 AudioTestSvcClientDestroy(&Client);
157
158 rc = AudioTestSvcStop(&Srv);
159 RTTEST_CHECK_RC_OK(hTest, rc);
160
161 rc = AudioTestSvcDestroy(&Srv);
162 RTTEST_CHECK_RC_OK(hTest, rc);
163
164 /*
165 * Summary
166 */
167 return RTTestSummaryAndDestroy(hTest);
168}
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