Update contrib.
1 // Copyright (c) 1998-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.
14 // e32test\bench\t_ipcbm.cpp
16 // Test and benchmark the data copy in inter-process communication.
18 // RServer2, RSessionBase
20 // - Create a server thread and write data blocks of varying sizes from the
21 // server to client, increment a count after each write.
22 // - Create a client session, connect to server and send data block size
24 // - Print the block size, total number of bytes written along with usec
26 // - Verify that the heap was not corrupted by any of the tests.
27 // Platforms/Drives/Compatibility:
29 // Assumptions/Requirement/Pre-requisites:
30 // Failures and causes:
31 // Base Port information:
37 #include <e32def_private.h>
39 LOCAL_D RTest test(_L("T_IPCBM"));
41 const TInt KBufferSize = 65536;
44 LOCAL_D TUint32* Dest;
46 LOCAL_D RServer2 Server;
47 LOCAL_D RSemaphore ServerSem;
50 class RMySession : public RSessionBase
53 TInt Connect(RServer2 aSrv,TRequestStatus& aStat)
54 {return CreateSession(aSrv,TVersion(),1,EIpcSession_Unsharable,0,&aStat);}
55 void Test(TDes8& aDes)
56 {Send(0,TIpcArgs(&aDes));}
59 LOCAL_C TInt TestThread(TAny* aSize)
61 TInt r = Server.CreateGlobal(KNullDesC);
68 m.Complete(KErrNone); // connect message
71 TInt size=(TInt)aSize;
72 TPtrC8 src((const TUint8*)Src,size);
80 const TInt KTestRunSeconds = 10;
82 LOCAL_C void RunTest(TInt aSize)
84 const TInt KTestRunUs = KTestRunSeconds * 1000000;
87 TInt r=t.Create(KNullDesC,TestThread,0x1000,NULL,(TAny*)aSize);
89 t.SetPriority(EPriorityLess);
94 test(Server.Handle() != KNullHandle);
98 test(sess.Connect(Server,stat) == KErrNone);
99 User::WaitForRequest(stat); // connected
102 TPtr8 des((TUint8*)Dest, 0, aSize);
104 User::After(KTestRunUs);
106 User::WaitForRequest(s);
111 TInt us=10*KTestRunUs/Count;
112 test.Printf(_L("%5d byte writes: %8d/%ds %4d.%01dus\n"),aSize,Count,KTestRunSeconds,us/10,us%10);
115 GLDEF_C TInt E32Main()
118 test.Start(_L("Benchmark IPC copy"));
122 TAny* buffer = User::Alloc(2 * KBufferSize + 32);
125 Src = (TUint32*)((((TInt)buffer) & ~0x1f) + 0x20);
126 Dest = (TUint32*)(((TInt)Src) + KBufferSize);
128 test(ServerSem.CreateLocal(0) == KErrNone);
130 static TInt KMaxCounts[] = { 16, 256, 512, 2048, 2052, 4096, 32768, 65536 };
131 for (TUint i=0; i<sizeof KMaxCounts/sizeof KMaxCounts[0]; ++i)
133 RunTest(KMaxCounts[i]);