Update contrib.
1 // Copyright (c) 2002-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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
20 class RIpcSession : public RSessionBase
23 TInt CreateSession(TDesC& aName, TVersion aVer, TInt aSlots)
25 return RSessionBase::CreateSession(aName, aVer, aSlots);
27 void SendReceive(TInt aService, TIpcArgs& args, TRequestStatus& aStatus)
29 RSessionBase::SendReceive(aService, args, aStatus);
31 TInt SendReceive(TInt aService, TIpcArgs& args)
33 return RSessionBase::SendReceive(aService, args);
37 class CIpcScheduler : public CActiveScheduler
42 CActiveScheduler::Install(this);
46 class CIpcServer : public CServer2
59 TBMTicks iNewSessionEntryTime;
60 TBMTicks iNewSessionLeaveTime;
61 TBMTicks iServiceLTime;
64 CIpcServer() : CServer2(0)
67 virtual CSession2* NewSessionL(const TVersion& aVer, const RMessage2&) const;
71 static TInt Entry(TAny* ptr);
74 class CIpcSession : public CSession2
77 CIpcSession(CIpcServer* aServer)
81 virtual void ServiceL(const RMessage2& aMessage);
86 class SpawnArgs : public TBMSpawnArgs
96 SpawnArgs(const TPtrC& aServerName, TInt aPrio, TInt aRemote, TInt aIter);
104 SpawnArgs::SpawnArgs(const TPtrC& aServerName, TInt aPrio, TInt aRemote, TInt aIter) :
105 TBMSpawnArgs(CIpcServer::Entry, aPrio, aRemote, sizeof(*this)),
106 iServerName(aServerName),
108 iIterationCount(aIter)
113 r = iSem.CreateGlobal(_L("Semaphore"), 0);
114 BM_ERROR(r, r == KErrNone);
118 r = iSem.CreateLocal(0);
119 BM_ERROR(r, r == KErrNone);
123 void SpawnArgs::ServerOpen()
127 iSem.Duplicate(iParent);
131 void SpawnArgs::ServerClose()
139 void SpawnArgs::Close()
144 void CIpcSession::ServiceL(const RMessage2& aMessage)
146 CIpcServer::TService f = (CIpcServer::TService) aMessage.Function();
149 case CIpcServer::ERunTest:
150 ::bmTimer.Stamp(&iServer->iTimes.iServiceLTime);
152 case CIpcServer::EGetTimes:
153 aMessage.WriteL(0, TPtrC8((TUint8*) &iServer->iTimes, sizeof(iServer->iTimes)));
155 case CIpcServer::EStop:
156 CActiveScheduler::Stop();
161 aMessage.Complete(KErrNone);
164 CSession2* CIpcServer::NewSessionL(const TVersion&, const RMessage2&) const
166 CIpcServer* srv = (CIpcServer*) this;
167 ::bmTimer.Stamp(&srv->iTimes.iNewSessionEntryTime);
168 CSession2* s = new CIpcSession(srv);
169 BM_ERROR(KErrNoMemory, s);
170 ::bmTimer.Stamp(&srv->iTimes.iNewSessionLeaveTime);
174 TInt CIpcServer::Entry(TAny* ptr)
176 SpawnArgs* sa = (SpawnArgs*) ptr;
180 CIpcScheduler* sched = new CIpcScheduler();
181 BM_ERROR(KErrNoMemory, sched);
183 CIpcServer* srv = new CIpcServer();
184 BM_ERROR(KErrNoMemory, srv);
185 TInt r = srv->Start(sa->iServerName);
186 BM_ERROR(r, r == KErrNone);
188 // signal to the parent the end of the server intialization
201 static const TInt KMaxIpcLatencyResults = 5;
203 class IpcLatency : public BMProgram
209 TBMResult iResults[KMaxIpcLatencyResults];
211 IpcLatency(TBool aRemote, TInt aPriority) :
214 ? ((aPriority == KBMPriorityHigh)
215 ? _L("Client-server Framework[Remote High Prioirty Server]")
216 : _L("Client-server Framework[Remote Low Prioirty Server]"))
217 : ((aPriority == KBMPriorityHigh)
218 ? _L("Client-server Framework[Local High Prioirty Server]")
219 : _L("Client-server Framework[Local Low Prioirty Server]")))
221 iPriority = aPriority;
225 virtual TBMResult* Run(TBMUInt64 aIter, TInt* aCount);
228 TBMResult* IpcLatency::Run(TBMUInt64 aIter, TInt* aCount)
230 SpawnArgs sa(_L("BMServer"), iPriority, iRemote, (TInt) aIter);
233 MBMChild* child = SpawnChild(&sa);
236 iResults[n++].Reset(_L("Connection Request Latency"));
237 iResults[n++].Reset(_L("Connection Reply Latency"));
238 iResults[n++].Reset(_L("Request Latency"));
239 iResults[n++].Reset(_L("Request Response Time"));
240 iResults[n++].Reset(_L("Reply Latency"));
241 BM_ASSERT(KMaxIpcLatencyResults >= n);
243 // wait for the srever intialization
245 // wait 2ms (ie more than one tick) to allow the server to complete its ActiveScheduler intialization ...
250 for (TBMUInt64 i = 0; i < aIter; ++i)
253 ::bmTimer.Stamp(&t1);
254 TInt r = s.CreateSession(sa.iServerName, sa.iVersion, 1);
255 BM_ERROR(r, r == KErrNone);
257 ::bmTimer.Stamp(&t2);
262 ::bmTimer.Stamp(&t3);
266 s.SendReceive(CIpcServer::ERunTest, args, st);
270 ::bmTimer.Stamp(&t4);
272 User::WaitForRequest(st);
273 BM_ERROR(r, st == KErrNone);
276 ::bmTimer.Stamp(&t5);
278 CIpcServer::TServerTimes serverTimes;
279 TPtr8 serverTimesDes((TUint8*) &serverTimes, sizeof(serverTimes), sizeof(serverTimes));
282 TIpcArgs args(&serverTimesDes);
283 r = s.SendReceive(CIpcServer::EGetTimes, args);
284 BM_ERROR(r, r == KErrNone);
290 iResults[n++].Cumulate(TBMTicksDelta(t1, serverTimes.iNewSessionEntryTime));
291 iResults[n++].Cumulate(TBMTicksDelta(serverTimes.iNewSessionLeaveTime, t2));
292 iResults[n++].Cumulate(TBMTicksDelta(t3, serverTimes.iServiceLTime));
293 iResults[n++].Cumulate(TBMTicksDelta(t3, t4));
294 iResults[n++].Cumulate(TBMTicksDelta(serverTimes.iServiceLTime, t5));
295 BM_ASSERT(KMaxIpcLatencyResults >= n);
297 // wait 2ms (ie more than one tick) to allow the server to complete.
301 TInt r = s.CreateSession(sa.iServerName, sa.iVersion, 1);
302 BM_ERROR(r, r == KErrNone);
305 s.SendReceive(CIpcServer::EStop, args);
309 child->WaitChildExit();
313 for (TInt j = 0; j < KMaxIpcLatencyResults; ++j)
315 iResults[j].Update();
318 *aCount = KMaxIpcLatencyResults;
322 IpcLatency test1(EFalse,KBMPriorityHigh);
323 IpcLatency test2(EFalse,KBMPriorityLow );
324 IpcLatency test3(ETrue, KBMPriorityHigh);
325 IpcLatency test4(ETrue, KBMPriorityLow );
329 BMProgram* next = bmSuite;
330 bmSuite=(BMProgram*)&test4;
331 bmSuite->Next()=next;
332 bmSuite=(BMProgram*)&test3;
333 bmSuite->Next()=&test4;
334 bmSuite=(BMProgram*)&test2;
335 bmSuite->Next()=&test3;
336 bmSuite=(BMProgram*)&test1;
337 bmSuite->Next()=&test2;