sl@0: // Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of the License "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // sl@0: sl@0: #include sl@0: sl@0: #include "bm_suite.h" sl@0: sl@0: class RIpcSession : public RSessionBase sl@0: { sl@0: public: sl@0: TInt CreateSession(TDesC& aName, TVersion aVer, TInt aSlots) sl@0: { sl@0: return RSessionBase::CreateSession(aName, aVer, aSlots); sl@0: } sl@0: void SendReceive(TInt aService, TIpcArgs& args, TRequestStatus& aStatus) sl@0: { sl@0: RSessionBase::SendReceive(aService, args, aStatus); sl@0: } sl@0: TInt SendReceive(TInt aService, TIpcArgs& args) sl@0: { sl@0: return RSessionBase::SendReceive(aService, args); sl@0: } sl@0: }; sl@0: sl@0: class CIpcScheduler : public CActiveScheduler sl@0: { sl@0: public: sl@0: CIpcScheduler() sl@0: { sl@0: CActiveScheduler::Install(this); sl@0: } sl@0: }; sl@0: sl@0: class CIpcServer : public CServer2 sl@0: { sl@0: public: sl@0: sl@0: enum TService sl@0: { sl@0: ERunTest, sl@0: EGetTimes, sl@0: EStop sl@0: }; sl@0: sl@0: struct TServerTimes sl@0: { sl@0: TBMTicks iNewSessionEntryTime; sl@0: TBMTicks iNewSessionLeaveTime; sl@0: TBMTicks iServiceLTime; sl@0: }; sl@0: sl@0: CIpcServer() : CServer2(0) sl@0: { sl@0: } sl@0: virtual CSession2* NewSessionL(const TVersion& aVer, const RMessage2&) const; sl@0: sl@0: TServerTimes iTimes; sl@0: sl@0: static TInt Entry(TAny* ptr); sl@0: }; sl@0: sl@0: class CIpcSession : public CSession2 sl@0: { sl@0: public: sl@0: CIpcSession(CIpcServer* aServer) sl@0: { sl@0: iServer = aServer; sl@0: } sl@0: virtual void ServiceL(const RMessage2& aMessage); sl@0: sl@0: CIpcServer* iServer; sl@0: }; sl@0: sl@0: class SpawnArgs : public TBMSpawnArgs sl@0: { sl@0: public: sl@0: sl@0: TBuf<16> iServerName; sl@0: TVersion iVersion; sl@0: sl@0: RSemaphore iSem; sl@0: TInt iIterationCount; sl@0: sl@0: SpawnArgs(const TPtrC& aServerName, TInt aPrio, TInt aRemote, TInt aIter); sl@0: sl@0: void Close(); sl@0: void ServerOpen(); sl@0: void ServerClose(); sl@0: sl@0: }; sl@0: sl@0: SpawnArgs::SpawnArgs(const TPtrC& aServerName, TInt aPrio, TInt aRemote, TInt aIter) : sl@0: TBMSpawnArgs(CIpcServer::Entry, aPrio, aRemote, sizeof(*this)), sl@0: iServerName(aServerName), sl@0: iVersion(1,0,1), sl@0: iIterationCount(aIter) sl@0: { sl@0: TInt r; sl@0: if (aRemote) sl@0: { sl@0: r = iSem.CreateGlobal(_L("Semaphore"), 0); sl@0: BM_ERROR(r, r == KErrNone); sl@0: } sl@0: else sl@0: { sl@0: r = iSem.CreateLocal(0); sl@0: BM_ERROR(r, r == KErrNone); sl@0: } sl@0: } sl@0: sl@0: void SpawnArgs::ServerOpen() sl@0: { sl@0: if (iRemote) sl@0: { sl@0: iSem.Duplicate(iParent); sl@0: } sl@0: } sl@0: sl@0: void SpawnArgs::ServerClose() sl@0: { sl@0: if (iRemote) sl@0: { sl@0: iSem.Close(); sl@0: } sl@0: } sl@0: sl@0: void SpawnArgs::Close() sl@0: { sl@0: iSem.Close(); sl@0: } sl@0: sl@0: void CIpcSession::ServiceL(const RMessage2& aMessage) sl@0: { sl@0: CIpcServer::TService f = (CIpcServer::TService) aMessage.Function(); sl@0: switch (f) sl@0: { sl@0: case CIpcServer::ERunTest: sl@0: ::bmTimer.Stamp(&iServer->iTimes.iServiceLTime); sl@0: break; sl@0: case CIpcServer::EGetTimes: sl@0: aMessage.WriteL(0, TPtrC8((TUint8*) &iServer->iTimes, sizeof(iServer->iTimes))); sl@0: break; sl@0: case CIpcServer::EStop: sl@0: CActiveScheduler::Stop(); sl@0: break; sl@0: default: sl@0: BM_ASSERT(0); sl@0: } sl@0: aMessage.Complete(KErrNone); sl@0: } sl@0: sl@0: CSession2* CIpcServer::NewSessionL(const TVersion&, const RMessage2&) const sl@0: { sl@0: CIpcServer* srv = (CIpcServer*) this; sl@0: ::bmTimer.Stamp(&srv->iTimes.iNewSessionEntryTime); sl@0: CSession2* s = new CIpcSession(srv); sl@0: BM_ERROR(KErrNoMemory, s); sl@0: ::bmTimer.Stamp(&srv->iTimes.iNewSessionLeaveTime); sl@0: return s; sl@0: } sl@0: sl@0: TInt CIpcServer::Entry(TAny* ptr) sl@0: { sl@0: SpawnArgs* sa = (SpawnArgs*) ptr; sl@0: sl@0: sa->ServerOpen(); sl@0: sl@0: CIpcScheduler* sched = new CIpcScheduler(); sl@0: BM_ERROR(KErrNoMemory, sched); sl@0: sl@0: CIpcServer* srv = new CIpcServer(); sl@0: BM_ERROR(KErrNoMemory, srv); sl@0: TInt r = srv->Start(sa->iServerName); sl@0: BM_ERROR(r, r == KErrNone); sl@0: sl@0: // signal to the parent the end of the server intialization sl@0: sa->iSem.Signal(); sl@0: sl@0: sched->Start(); sl@0: sl@0: delete srv; sl@0: delete sched; sl@0: sl@0: sa->ServerClose(); sl@0: sl@0: return KErrNone; sl@0: } sl@0: sl@0: static const TInt KMaxIpcLatencyResults = 5; sl@0: sl@0: class IpcLatency : public BMProgram sl@0: { sl@0: public : sl@0: sl@0: TBool iRemote; sl@0: TInt iPriority; sl@0: TBMResult iResults[KMaxIpcLatencyResults]; sl@0: sl@0: IpcLatency(TBool aRemote, TInt aPriority) : sl@0: BMProgram( sl@0: aRemote sl@0: ? ((aPriority == KBMPriorityHigh) sl@0: ? _L("Client-server Framework[Remote High Prioirty Server]") sl@0: : _L("Client-server Framework[Remote Low Prioirty Server]")) sl@0: : ((aPriority == KBMPriorityHigh) sl@0: ? _L("Client-server Framework[Local High Prioirty Server]") sl@0: : _L("Client-server Framework[Local Low Prioirty Server]"))) sl@0: { sl@0: iPriority = aPriority; sl@0: iRemote = aRemote; sl@0: } sl@0: sl@0: virtual TBMResult* Run(TBMUInt64 aIter, TInt* aCount); sl@0: }; sl@0: sl@0: TBMResult* IpcLatency::Run(TBMUInt64 aIter, TInt* aCount) sl@0: { sl@0: SpawnArgs sa(_L("BMServer"), iPriority, iRemote, (TInt) aIter); sl@0: sl@0: // spawn the server sl@0: MBMChild* child = SpawnChild(&sa); sl@0: sl@0: TInt n = 0; sl@0: iResults[n++].Reset(_L("Connection Request Latency")); sl@0: iResults[n++].Reset(_L("Connection Reply Latency")); sl@0: iResults[n++].Reset(_L("Request Latency")); sl@0: iResults[n++].Reset(_L("Request Response Time")); sl@0: iResults[n++].Reset(_L("Reply Latency")); sl@0: BM_ASSERT(KMaxIpcLatencyResults >= n); sl@0: sl@0: // wait for the srever intialization sl@0: sa.iSem.Wait(); sl@0: // wait 2ms (ie more than one tick) to allow the server to complete its ActiveScheduler intialization ... sl@0: User::After(2000); sl@0: sl@0: RIpcSession s; sl@0: sl@0: for (TBMUInt64 i = 0; i < aIter; ++i) sl@0: { sl@0: TBMTicks t1; sl@0: ::bmTimer.Stamp(&t1); sl@0: TInt r = s.CreateSession(sa.iServerName, sa.iVersion, 1); sl@0: BM_ERROR(r, r == KErrNone); sl@0: TBMTicks t2; sl@0: ::bmTimer.Stamp(&t2); sl@0: sl@0: TRequestStatus st; sl@0: sl@0: TBMTicks t3; sl@0: ::bmTimer.Stamp(&t3); sl@0: sl@0: { sl@0: TIpcArgs args; sl@0: s.SendReceive(CIpcServer::ERunTest, args, st); sl@0: } sl@0: sl@0: TBMTicks t4; sl@0: ::bmTimer.Stamp(&t4); sl@0: sl@0: User::WaitForRequest(st); sl@0: BM_ERROR(r, st == KErrNone); sl@0: sl@0: TBMTicks t5; sl@0: ::bmTimer.Stamp(&t5); sl@0: sl@0: CIpcServer::TServerTimes serverTimes; sl@0: TPtr8 serverTimesDes((TUint8*) &serverTimes, sizeof(serverTimes), sizeof(serverTimes)); sl@0: sl@0: { sl@0: TIpcArgs args(&serverTimesDes); sl@0: r = s.SendReceive(CIpcServer::EGetTimes, args); sl@0: BM_ERROR(r, r == KErrNone); sl@0: } sl@0: sl@0: s.Close(); sl@0: sl@0: n = 0; sl@0: iResults[n++].Cumulate(TBMTicksDelta(t1, serverTimes.iNewSessionEntryTime)); sl@0: iResults[n++].Cumulate(TBMTicksDelta(serverTimes.iNewSessionLeaveTime, t2)); sl@0: iResults[n++].Cumulate(TBMTicksDelta(t3, serverTimes.iServiceLTime)); sl@0: iResults[n++].Cumulate(TBMTicksDelta(t3, t4)); sl@0: iResults[n++].Cumulate(TBMTicksDelta(serverTimes.iServiceLTime, t5)); sl@0: BM_ASSERT(KMaxIpcLatencyResults >= n); sl@0: sl@0: // wait 2ms (ie more than one tick) to allow the server to complete. sl@0: User::After(2000); sl@0: } sl@0: sl@0: TInt r = s.CreateSession(sa.iServerName, sa.iVersion, 1); sl@0: BM_ERROR(r, r == KErrNone); sl@0: { sl@0: TIpcArgs args; sl@0: s.SendReceive(CIpcServer::EStop, args); sl@0: } sl@0: s.Close(); sl@0: sl@0: child->WaitChildExit(); sl@0: sl@0: sa.Close(); sl@0: sl@0: for (TInt j = 0; j < KMaxIpcLatencyResults; ++j) sl@0: { sl@0: iResults[j].Update(); sl@0: } sl@0: sl@0: *aCount = KMaxIpcLatencyResults; sl@0: return iResults; sl@0: } sl@0: sl@0: IpcLatency test1(EFalse,KBMPriorityHigh); sl@0: IpcLatency test2(EFalse,KBMPriorityLow ); sl@0: IpcLatency test3(ETrue, KBMPriorityHigh); sl@0: IpcLatency test4(ETrue, KBMPriorityLow ); sl@0: sl@0: void AddIpc() sl@0: { sl@0: BMProgram* next = bmSuite; sl@0: bmSuite=(BMProgram*)&test4; sl@0: bmSuite->Next()=next; sl@0: bmSuite=(BMProgram*)&test3; sl@0: bmSuite->Next()=&test4; sl@0: bmSuite=(BMProgram*)&test2; sl@0: bmSuite->Next()=&test3; sl@0: bmSuite=(BMProgram*)&test1; sl@0: bmSuite->Next()=&test2; sl@0: }