0
|
1 |
// Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
2 |
// All rights reserved.
|
|
3 |
// This component and the accompanying materials are made available
|
|
4 |
// under the terms of the License "Eclipse Public License v1.0"
|
|
5 |
// which accompanies this distribution, and is available
|
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
7 |
//
|
|
8 |
// Initial Contributors:
|
|
9 |
// Nokia Corporation - initial contribution.
|
|
10 |
//
|
|
11 |
// Contributors:
|
|
12 |
//
|
|
13 |
// Description:
|
|
14 |
// e32test/mmu/t_shbuf_perfclient.cpp
|
|
15 |
//
|
|
16 |
//
|
|
17 |
|
|
18 |
#include <e32std.h>
|
|
19 |
#include <e32cmn.h>
|
|
20 |
#include <e32debug.h>
|
|
21 |
#include <e32msgqueue.h>
|
|
22 |
#include <e32shbuf.h>
|
|
23 |
|
|
24 |
#include "t_shbuf_perfserver.h"
|
|
25 |
#include "t_shbuf_perfclient.h"
|
|
26 |
|
|
27 |
|
|
28 |
/**
|
|
29 |
* @file
|
|
30 |
*
|
|
31 |
* Client side APIs for a test server used for Performance Testing of shared buffers.
|
|
32 |
*/
|
|
33 |
|
|
34 |
|
|
35 |
/**
|
|
36 |
* Test API version.
|
|
37 |
*/
|
|
38 |
const TInt KRShBufTestServerMajorVersion = 1;
|
|
39 |
const TInt KRShBufTestServerMinorVersion = 0;
|
|
40 |
const TInt KRShBufTestServerBuildVersion = 1;
|
|
41 |
|
|
42 |
|
|
43 |
/**
|
|
44 |
* Start the server process which lives in its own executable and rendezvous with it.
|
|
45 |
*
|
|
46 |
* @return KErrNone if successful, or an error code if not.
|
|
47 |
*/
|
|
48 |
static TInt StartTestServer()
|
|
49 |
{
|
|
50 |
#ifdef CAN_TRANSFER_SHBUF_TO_ANOTHER_PROCESS
|
|
51 |
//
|
|
52 |
// Create a new server process. Simultaneous launching of two such
|
|
53 |
// processes should be detected when the second one attempts to
|
|
54 |
// create the server object, failing with KErrAlreadyExists.
|
|
55 |
//
|
|
56 |
_LIT(KTestServerExeImg, "T_SHBUF_PERFSERVER.EXE");
|
|
57 |
RProcess server;
|
|
58 |
|
|
59 |
TInt ret = server.Create(KTestServerExeImg, KNullDesC);
|
|
60 |
if (ret != KErrNone)
|
|
61 |
{
|
|
62 |
return ret;
|
|
63 |
}
|
|
64 |
#else
|
|
65 |
//
|
|
66 |
// Start a thread with the server in it.
|
|
67 |
//
|
|
68 |
RThread server;
|
|
69 |
|
|
70 |
TInt ret = server.Create(_L("RShBufTestServerThread"), RShBufTestServerThread,
|
|
71 |
KDefaultStackSize, 0x10000, 0x10000, NULL);
|
|
72 |
if (ret != KErrNone)
|
|
73 |
{
|
|
74 |
return ret;
|
|
75 |
}
|
|
76 |
#endif
|
|
77 |
|
|
78 |
//
|
|
79 |
// Rendezvous with the server or abort startup...
|
|
80 |
//
|
|
81 |
TRequestStatus status;
|
|
82 |
|
|
83 |
server.Rendezvous(status);
|
|
84 |
if (status != KRequestPending)
|
|
85 |
{
|
|
86 |
server.Kill(0);
|
|
87 |
}
|
|
88 |
else
|
|
89 |
{
|
|
90 |
server.Resume();
|
|
91 |
}
|
|
92 |
User::WaitForRequest(status);
|
|
93 |
|
|
94 |
//
|
|
95 |
// We can't use the 'exit reason' if the server panicked as this
|
|
96 |
// is the panic 'reason' and may be '0' which cannot be distinguished
|
|
97 |
// from KErrNone.
|
|
98 |
//
|
|
99 |
if (server.ExitType() == EExitPanic)
|
|
100 |
{
|
|
101 |
ret = KErrGeneral;
|
|
102 |
}
|
|
103 |
else if (status.Int() != KErrAlreadyExists)
|
|
104 |
{
|
|
105 |
ret = status.Int();
|
|
106 |
}
|
|
107 |
|
|
108 |
server.Close();
|
|
109 |
|
|
110 |
return ret;
|
|
111 |
} // StartTestServer
|
|
112 |
|
|
113 |
|
|
114 |
/**
|
|
115 |
* Standard constructor.
|
|
116 |
*/
|
|
117 |
EXPORT_C RShBufTestServerSession::RShBufTestServerSession()
|
|
118 |
{
|
|
119 |
// NOP
|
|
120 |
} // RShBufTestServerSession::RShBufTestServerSession
|
|
121 |
|
|
122 |
|
|
123 |
/**
|
|
124 |
* Connects the client to the test server.
|
|
125 |
*
|
|
126 |
* @return KErrNone if successful, a system-wide error code if not.
|
|
127 |
*
|
|
128 |
* @capability None
|
|
129 |
*/
|
|
130 |
EXPORT_C TInt RShBufTestServerSession::Connect()
|
|
131 |
{
|
|
132 |
//
|
|
133 |
// Create a session with the server, but if it doesn't exist then start it and
|
|
134 |
// then create a session.
|
|
135 |
//
|
|
136 |
TInt result = CreateSession(KRShBufTestServerName,
|
|
137 |
TVersion(KRShBufTestServerMajorVersion,
|
|
138 |
KRShBufTestServerMinorVersion,
|
|
139 |
KRShBufTestServerBuildVersion));
|
|
140 |
if (result == KErrNotFound || result == KErrServerTerminated)
|
|
141 |
{
|
|
142 |
result = StartTestServer();
|
|
143 |
|
|
144 |
if(result == KErrNone)
|
|
145 |
{
|
|
146 |
result = CreateSession(KRShBufTestServerName,
|
|
147 |
TVersion(KRShBufTestServerMajorVersion,
|
|
148 |
KRShBufTestServerMinorVersion,
|
|
149 |
KRShBufTestServerBuildVersion));
|
|
150 |
}
|
|
151 |
}
|
|
152 |
|
|
153 |
//
|
|
154 |
// If the creation of the session fails clean up session data...
|
|
155 |
//
|
|
156 |
if (result != KErrNone)
|
|
157 |
{
|
|
158 |
Close();
|
|
159 |
}
|
|
160 |
|
|
161 |
return result;
|
|
162 |
} // RShBufTestServerSession::Connect
|
|
163 |
|
|
164 |
|
|
165 |
/**
|
|
166 |
* Closes the client's session with the RShBuf Test Server.
|
|
167 |
*
|
|
168 |
* @capability None
|
|
169 |
*/
|
|
170 |
EXPORT_C void RShBufTestServerSession::Close()
|
|
171 |
{
|
|
172 |
RSessionBase::Close();
|
|
173 |
} // RShBufTestServerSession::Close
|
|
174 |
|
|
175 |
|
|
176 |
/**
|
|
177 |
* Returns the current version of the RShBuf Test Server.
|
|
178 |
*
|
|
179 |
* @return The version of the RShBuf Test Server.
|
|
180 |
*
|
|
181 |
* @capability None
|
|
182 |
*/
|
|
183 |
EXPORT_C TVersion RShBufTestServerSession::Version() const
|
|
184 |
{
|
|
185 |
return(TVersion(KRShBufTestServerMajorVersion,
|
|
186 |
KRShBufTestServerMinorVersion,
|
|
187 |
KRShBufTestServerBuildVersion));
|
|
188 |
} // RShBufTestServerSession::Version
|
|
189 |
|
|
190 |
|
|
191 |
/**
|
|
192 |
* Requests the shutdown of the server when the last client disconnects.
|
|
193 |
* There is no support for immediate shutdown functionality. This API call
|
|
194 |
* can only be executed if the server is compiled as a debug release.
|
|
195 |
*
|
|
196 |
* @return KErrNone if successful, a system-wide error code if not.
|
|
197 |
*/
|
|
198 |
EXPORT_C TInt RShBufTestServerSession::ShutdownServer()
|
|
199 |
{
|
|
200 |
return SendReceive(EShBufServerShutdownServer, TIpcArgs());
|
|
201 |
} // RShBufTestServerSession::ShutdownServer
|
|
202 |
|
|
203 |
|
|
204 |
EXPORT_C TInt RShBufTestServerSession::FromTPtr8ProcessAndReturn(TDes8& aBuf, TUint aBufSize)
|
|
205 |
{
|
|
206 |
TIpcArgs args(&aBuf, aBufSize);
|
|
207 |
|
|
208 |
return SendReceive(EShBufServerFromTPtr8ProcessAndReturn, args);
|
|
209 |
} // RShBufTestServerSession::FromTPtr8ProcessAndReturn
|
|
210 |
|
|
211 |
|
|
212 |
EXPORT_C TInt RShBufTestServerSession::FromTPtr8ProcessAndRelease(const TDesC8& aBuf)
|
|
213 |
{
|
|
214 |
TIpcArgs args(&aBuf);
|
|
215 |
|
|
216 |
return SendReceive(EShBufServerFromTPtr8ProcessAndRelease, args);
|
|
217 |
} // RShBufTestServerSession::FromTPtr8ProcessAndRelease
|
|
218 |
|
|
219 |
|
|
220 |
EXPORT_C TInt RShBufTestServerSession::FromRShBufProcessAndReturn(RShBuf& aShBuf, TUint aBufSize)
|
|
221 |
{
|
|
222 |
TInt r;
|
|
223 |
TInt handle;
|
|
224 |
TPckg<TInt> handlePckg(handle);
|
|
225 |
|
|
226 |
TIpcArgs args(&handlePckg, aBufSize);
|
|
227 |
|
|
228 |
r = SendReceive(EShBufServerFromRShBufProcessAndReturn, args);
|
|
229 |
|
|
230 |
if (r == KErrNone)
|
|
231 |
aShBuf.SetReturnedHandle(handle);
|
|
232 |
|
|
233 |
return r;
|
|
234 |
} // RShBufTestServerSession::FromRShBufProcessAndReturn
|
|
235 |
|
|
236 |
|
|
237 |
EXPORT_C TInt RShBufTestServerSession::OpenRShBufPool(TInt aHandle, const TShPoolInfo& aShPoolInfo)
|
|
238 |
{
|
|
239 |
TPckg<TShPoolInfo> shPoolInfoPckg(aShPoolInfo);
|
|
240 |
TIpcArgs args(aHandle, &shPoolInfoPckg);
|
|
241 |
|
|
242 |
return SendReceive(EShBufServerOpenRShBufPool, args);
|
|
243 |
} // RShBufTestServerSession::OpenRShBufPool
|
|
244 |
|
|
245 |
|
|
246 |
EXPORT_C TInt RShBufTestServerSession::CloseRShBufPool(TInt aHandle)
|
|
247 |
{
|
|
248 |
TIpcArgs args(aHandle);
|
|
249 |
|
|
250 |
return SendReceive(EShBufServerCloseRShBufPool, args);
|
|
251 |
} // RShBufTestServerSession::CloseRShBufPool
|
|
252 |
|
|
253 |
|
|
254 |
EXPORT_C TInt RShBufTestServerSession::FromRShBufProcessAndRelease(RShBuf& aShBuf)
|
|
255 |
{
|
|
256 |
TIpcArgs args(aShBuf.Handle());
|
|
257 |
|
|
258 |
return SendReceive(EShBufServerFromRShBufProcessAndRelease, args);
|
|
259 |
} // RShBufTestServerSession::FromRShBufProcessAndRelease
|
|
260 |
|
|
261 |
|
|
262 |
/**
|
|
263 |
* Set a heap mark in the RShBuf Test Server thread.
|
|
264 |
*
|
|
265 |
* @capability None
|
|
266 |
*/
|
|
267 |
EXPORT_C TInt RShBufTestServerSession::__DbgMarkHeap()
|
|
268 |
{
|
|
269 |
TIpcArgs args(TIpcArgs::ENothing);
|
|
270 |
|
|
271 |
return SendReceive(EShBufServerDbgMarkHeap, args);
|
|
272 |
} // RShBufTestServerSession::__DbgMarkHeap
|
|
273 |
|
|
274 |
|
|
275 |
/**
|
|
276 |
* Performs a heap mark check in the RShBuf Test Server thread.
|
|
277 |
*
|
|
278 |
* @param aCount The number of heap cells expected to be allocated at
|
|
279 |
* the current nest level.
|
|
280 |
*
|
|
281 |
* @capability None
|
|
282 |
*/
|
|
283 |
EXPORT_C TInt RShBufTestServerSession::__DbgCheckHeap(TInt aCount)
|
|
284 |
{
|
|
285 |
TIpcArgs args(aCount);
|
|
286 |
|
|
287 |
return SendReceive(EShBufServerDbgCheckHeap, args);
|
|
288 |
} // RShBufTestServerSession::__DbgCheckHeap
|
|
289 |
|
|
290 |
|
|
291 |
/**
|
|
292 |
* Perfom a heap mark end check in the RShBuf Test Server thread.
|
|
293 |
*
|
|
294 |
* @param aCount The number of heap cells expected to remain allocated
|
|
295 |
* at the current nest level.
|
|
296 |
*
|
|
297 |
* @capability None
|
|
298 |
*/
|
|
299 |
EXPORT_C TInt RShBufTestServerSession::__DbgMarkEnd(TInt aCount)
|
|
300 |
{
|
|
301 |
TIpcArgs args(aCount);
|
|
302 |
|
|
303 |
return SendReceive(EShBufServerDbgMarkEnd, args);
|
|
304 |
} // RShBufTestServerSession::__DbgMarkEnd
|
|
305 |
|
|
306 |
|
|
307 |
/**
|
|
308 |
* Set a heap fail next condition in the RShBuf Test Server thread.
|
|
309 |
*
|
|
310 |
* @param aCount Determines when the allocation will fail.
|
|
311 |
*
|
|
312 |
* @capability None
|
|
313 |
*/
|
|
314 |
EXPORT_C TInt RShBufTestServerSession::__DbgFailNext(TInt aCount)
|
|
315 |
{
|
|
316 |
TIpcArgs args(aCount);
|
|
317 |
|
|
318 |
return SendReceive(EShBufServerDbgFailNext, args);
|
|
319 |
} // RShBufTestServerSession::__DbgFailNext
|
|
320 |
|
|
321 |
|