os/kernelhwsrv/kerneltest/e32test/bench/t_ipcbm.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
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".
     7 //
     8 // Initial Contributors:
     9 // Nokia Corporation - initial contribution.
    10 //
    11 // Contributors:
    12 //
    13 // Description:
    14 // e32test\bench\t_ipcbm.cpp
    15 // Overview:
    16 // Test and benchmark the data copy in inter-process communication. 
    17 // API Information:
    18 // RServer2, RSessionBase
    19 // Details:
    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 
    23 // to the server.
    24 // - Print the block size, total number of bytes written along with usec 
    25 // per block.
    26 // - Verify that the heap was not corrupted by any of the tests.
    27 // Platforms/Drives/Compatibility:
    28 // All.
    29 // Assumptions/Requirement/Pre-requisites:
    30 // Failures and causes:
    31 // Base Port information:
    32 // 
    33 //
    34 
    35 #include <e32test.h>
    36 #include <e32def.h>
    37 #include <e32def_private.h>
    38 
    39 LOCAL_D RTest test(_L("T_IPCBM"));
    40 
    41 const TInt KBufferSize = 65536;
    42 
    43 LOCAL_D TUint32* Src;
    44 LOCAL_D TUint32* Dest;
    45 LOCAL_D TInt Count=0;
    46 LOCAL_D RServer2 Server;
    47 LOCAL_D RSemaphore ServerSem;
    48 
    49 
    50 class RMySession : public RSessionBase
    51 	{
    52 public:
    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));}
    57 	};
    58 
    59 LOCAL_C TInt TestThread(TAny* aSize)
    60 	{
    61 	TInt r = Server.CreateGlobal(KNullDesC);
    62 	ServerSem.Signal();
    63 	if (r != KErrNone)
    64 		return r;
    65 
    66 	RMessage2 m;
    67 	Server.Receive(m);
    68 	m.Complete(KErrNone);	// connect message
    69 
    70 	Server.Receive(m);
    71 	TInt size=(TInt)aSize;
    72 	TPtrC8 src((const TUint8*)Src,size);
    73 	FOREVER
    74 		{
    75 		m.Write(0,src);
    76 		Count++;
    77 		}
    78 	}
    79 
    80 const TInt KTestRunSeconds = 10;
    81 
    82 LOCAL_C void RunTest(TInt aSize)
    83 	{
    84 	const TInt KTestRunUs = KTestRunSeconds * 1000000;
    85 
    86 	RThread t;
    87 	TInt r=t.Create(KNullDesC,TestThread,0x1000,NULL,(TAny*)aSize);
    88 	test(r==KErrNone);
    89 	t.SetPriority(EPriorityLess);
    90 	TRequestStatus s;
    91 	t.Logon(s);
    92 	t.Resume();
    93 	ServerSem.Wait();
    94 	test(Server.Handle() != KNullHandle);
    95 
    96 	RMySession sess;
    97 	TRequestStatus stat;
    98 	test(sess.Connect(Server,stat) == KErrNone);
    99 	User::WaitForRequest(stat);	// connected
   100 
   101 	Count=0;
   102 	TPtr8 des((TUint8*)Dest, 0, aSize);
   103 	sess.Test(des);
   104 	User::After(KTestRunUs);
   105 	t.Kill(0);
   106 	User::WaitForRequest(s);
   107 	sess.Close();
   108 	Server.Close();
   109 	CLOSE_AND_WAIT(t);
   110 
   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);
   113 	}
   114 
   115 GLDEF_C TInt E32Main()
   116 	{
   117 	test.Title();
   118 	test.Start(_L("Benchmark IPC copy"));
   119 
   120 	__KHEAP_MARK;
   121 
   122 	TAny* buffer = User::Alloc(2 * KBufferSize + 32);
   123 	test(buffer != 0);
   124 
   125 	Src = (TUint32*)((((TInt)buffer) & ~0x1f) + 0x20);	
   126 	Dest = (TUint32*)(((TInt)Src) + KBufferSize);
   127 	
   128 	test(ServerSem.CreateLocal(0) == KErrNone);
   129 
   130 	static TInt KMaxCounts[] = { 16, 256, 512, 2048, 2052, 4096, 32768, 65536 };
   131 	for (TUint i=0; i<sizeof KMaxCounts/sizeof KMaxCounts[0]; ++i)
   132 		{
   133 		RunTest(KMaxCounts[i]);
   134 		}
   135 
   136 	ServerSem.Close();
   137 	User::Free(buffer);
   138 
   139 	__KHEAP_MARKEND;
   140 
   141 	test.End();
   142 	return KErrNone;
   143 	}