sl@0: // Copyright (c) 1998-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: // e32test\bench\t_ipcbm.cpp sl@0: // Overview: sl@0: // Test and benchmark the data copy in inter-process communication. sl@0: // API Information: sl@0: // RServer2, RSessionBase sl@0: // Details: sl@0: // - Create a server thread and write data blocks of varying sizes from the sl@0: // server to client, increment a count after each write. sl@0: // - Create a client session, connect to server and send data block size sl@0: // to the server. sl@0: // - Print the block size, total number of bytes written along with usec sl@0: // per block. sl@0: // - Verify that the heap was not corrupted by any of the tests. sl@0: // Platforms/Drives/Compatibility: sl@0: // All. sl@0: // Assumptions/Requirement/Pre-requisites: sl@0: // Failures and causes: sl@0: // Base Port information: sl@0: // sl@0: // sl@0: sl@0: #include sl@0: #include sl@0: #include sl@0: sl@0: LOCAL_D RTest test(_L("T_IPCBM")); sl@0: sl@0: const TInt KBufferSize = 65536; sl@0: sl@0: LOCAL_D TUint32* Src; sl@0: LOCAL_D TUint32* Dest; sl@0: LOCAL_D TInt Count=0; sl@0: LOCAL_D RServer2 Server; sl@0: LOCAL_D RSemaphore ServerSem; sl@0: sl@0: sl@0: class RMySession : public RSessionBase sl@0: { sl@0: public: sl@0: TInt Connect(RServer2 aSrv,TRequestStatus& aStat) sl@0: {return CreateSession(aSrv,TVersion(),1,EIpcSession_Unsharable,0,&aStat);} sl@0: void Test(TDes8& aDes) sl@0: {Send(0,TIpcArgs(&aDes));} sl@0: }; sl@0: sl@0: LOCAL_C TInt TestThread(TAny* aSize) sl@0: { sl@0: TInt r = Server.CreateGlobal(KNullDesC); sl@0: ServerSem.Signal(); sl@0: if (r != KErrNone) sl@0: return r; sl@0: sl@0: RMessage2 m; sl@0: Server.Receive(m); sl@0: m.Complete(KErrNone); // connect message sl@0: sl@0: Server.Receive(m); sl@0: TInt size=(TInt)aSize; sl@0: TPtrC8 src((const TUint8*)Src,size); sl@0: FOREVER sl@0: { sl@0: m.Write(0,src); sl@0: Count++; sl@0: } sl@0: } sl@0: sl@0: const TInt KTestRunSeconds = 10; sl@0: sl@0: LOCAL_C void RunTest(TInt aSize) sl@0: { sl@0: const TInt KTestRunUs = KTestRunSeconds * 1000000; sl@0: sl@0: RThread t; sl@0: TInt r=t.Create(KNullDesC,TestThread,0x1000,NULL,(TAny*)aSize); sl@0: test(r==KErrNone); sl@0: t.SetPriority(EPriorityLess); sl@0: TRequestStatus s; sl@0: t.Logon(s); sl@0: t.Resume(); sl@0: ServerSem.Wait(); sl@0: test(Server.Handle() != KNullHandle); sl@0: sl@0: RMySession sess; sl@0: TRequestStatus stat; sl@0: test(sess.Connect(Server,stat) == KErrNone); sl@0: User::WaitForRequest(stat); // connected sl@0: sl@0: Count=0; sl@0: TPtr8 des((TUint8*)Dest, 0, aSize); sl@0: sess.Test(des); sl@0: User::After(KTestRunUs); sl@0: t.Kill(0); sl@0: User::WaitForRequest(s); sl@0: sess.Close(); sl@0: Server.Close(); sl@0: CLOSE_AND_WAIT(t); sl@0: sl@0: TInt us=10*KTestRunUs/Count; sl@0: test.Printf(_L("%5d byte writes: %8d/%ds %4d.%01dus\n"),aSize,Count,KTestRunSeconds,us/10,us%10); sl@0: } sl@0: sl@0: GLDEF_C TInt E32Main() sl@0: { sl@0: test.Title(); sl@0: test.Start(_L("Benchmark IPC copy")); sl@0: sl@0: __KHEAP_MARK; sl@0: sl@0: TAny* buffer = User::Alloc(2 * KBufferSize + 32); sl@0: test(buffer != 0); sl@0: sl@0: Src = (TUint32*)((((TInt)buffer) & ~0x1f) + 0x20); sl@0: Dest = (TUint32*)(((TInt)Src) + KBufferSize); sl@0: sl@0: test(ServerSem.CreateLocal(0) == KErrNone); sl@0: sl@0: static TInt KMaxCounts[] = { 16, 256, 512, 2048, 2052, 4096, 32768, 65536 }; sl@0: for (TUint i=0; i