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