os/kernelhwsrv/kerneltest/e32test/bench/t_ipcbm.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/kernelhwsrv/kerneltest/e32test/bench/t_ipcbm.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,143 @@
     1.4 +// Copyright (c) 1998-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.5 +// All rights reserved.
     1.6 +// This component and the accompanying materials are made available
     1.7 +// under the terms of the License "Eclipse Public License v1.0"
     1.8 +// which accompanies this distribution, and is available
     1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.10 +//
    1.11 +// Initial Contributors:
    1.12 +// Nokia Corporation - initial contribution.
    1.13 +//
    1.14 +// Contributors:
    1.15 +//
    1.16 +// Description:
    1.17 +// e32test\bench\t_ipcbm.cpp
    1.18 +// Overview:
    1.19 +// Test and benchmark the data copy in inter-process communication. 
    1.20 +// API Information:
    1.21 +// RServer2, RSessionBase
    1.22 +// Details:
    1.23 +// - Create a server thread and write data blocks of varying sizes from the 
    1.24 +// server to client, increment a count after each write.
    1.25 +// - Create a client session, connect to server and send data block size 
    1.26 +// to the server.
    1.27 +// - Print the block size, total number of bytes written along with usec 
    1.28 +// per block.
    1.29 +// - Verify that the heap was not corrupted by any of the tests.
    1.30 +// Platforms/Drives/Compatibility:
    1.31 +// All.
    1.32 +// Assumptions/Requirement/Pre-requisites:
    1.33 +// Failures and causes:
    1.34 +// Base Port information:
    1.35 +// 
    1.36 +//
    1.37 +
    1.38 +#include <e32test.h>
    1.39 +#include <e32def.h>
    1.40 +#include <e32def_private.h>
    1.41 +
    1.42 +LOCAL_D RTest test(_L("T_IPCBM"));
    1.43 +
    1.44 +const TInt KBufferSize = 65536;
    1.45 +
    1.46 +LOCAL_D TUint32* Src;
    1.47 +LOCAL_D TUint32* Dest;
    1.48 +LOCAL_D TInt Count=0;
    1.49 +LOCAL_D RServer2 Server;
    1.50 +LOCAL_D RSemaphore ServerSem;
    1.51 +
    1.52 +
    1.53 +class RMySession : public RSessionBase
    1.54 +	{
    1.55 +public:
    1.56 +	TInt Connect(RServer2 aSrv,TRequestStatus& aStat)
    1.57 +		{return CreateSession(aSrv,TVersion(),1,EIpcSession_Unsharable,0,&aStat);}
    1.58 +	void Test(TDes8& aDes)
    1.59 +		{Send(0,TIpcArgs(&aDes));}
    1.60 +	};
    1.61 +
    1.62 +LOCAL_C TInt TestThread(TAny* aSize)
    1.63 +	{
    1.64 +	TInt r = Server.CreateGlobal(KNullDesC);
    1.65 +	ServerSem.Signal();
    1.66 +	if (r != KErrNone)
    1.67 +		return r;
    1.68 +
    1.69 +	RMessage2 m;
    1.70 +	Server.Receive(m);
    1.71 +	m.Complete(KErrNone);	// connect message
    1.72 +
    1.73 +	Server.Receive(m);
    1.74 +	TInt size=(TInt)aSize;
    1.75 +	TPtrC8 src((const TUint8*)Src,size);
    1.76 +	FOREVER
    1.77 +		{
    1.78 +		m.Write(0,src);
    1.79 +		Count++;
    1.80 +		}
    1.81 +	}
    1.82 +
    1.83 +const TInt KTestRunSeconds = 10;
    1.84 +
    1.85 +LOCAL_C void RunTest(TInt aSize)
    1.86 +	{
    1.87 +	const TInt KTestRunUs = KTestRunSeconds * 1000000;
    1.88 +
    1.89 +	RThread t;
    1.90 +	TInt r=t.Create(KNullDesC,TestThread,0x1000,NULL,(TAny*)aSize);
    1.91 +	test(r==KErrNone);
    1.92 +	t.SetPriority(EPriorityLess);
    1.93 +	TRequestStatus s;
    1.94 +	t.Logon(s);
    1.95 +	t.Resume();
    1.96 +	ServerSem.Wait();
    1.97 +	test(Server.Handle() != KNullHandle);
    1.98 +
    1.99 +	RMySession sess;
   1.100 +	TRequestStatus stat;
   1.101 +	test(sess.Connect(Server,stat) == KErrNone);
   1.102 +	User::WaitForRequest(stat);	// connected
   1.103 +
   1.104 +	Count=0;
   1.105 +	TPtr8 des((TUint8*)Dest, 0, aSize);
   1.106 +	sess.Test(des);
   1.107 +	User::After(KTestRunUs);
   1.108 +	t.Kill(0);
   1.109 +	User::WaitForRequest(s);
   1.110 +	sess.Close();
   1.111 +	Server.Close();
   1.112 +	CLOSE_AND_WAIT(t);
   1.113 +
   1.114 +	TInt us=10*KTestRunUs/Count;
   1.115 +	test.Printf(_L("%5d byte writes: %8d/%ds %4d.%01dus\n"),aSize,Count,KTestRunSeconds,us/10,us%10);
   1.116 +	}
   1.117 +
   1.118 +GLDEF_C TInt E32Main()
   1.119 +	{
   1.120 +	test.Title();
   1.121 +	test.Start(_L("Benchmark IPC copy"));
   1.122 +
   1.123 +	__KHEAP_MARK;
   1.124 +
   1.125 +	TAny* buffer = User::Alloc(2 * KBufferSize + 32);
   1.126 +	test(buffer != 0);
   1.127 +
   1.128 +	Src = (TUint32*)((((TInt)buffer) & ~0x1f) + 0x20);	
   1.129 +	Dest = (TUint32*)(((TInt)Src) + KBufferSize);
   1.130 +	
   1.131 +	test(ServerSem.CreateLocal(0) == KErrNone);
   1.132 +
   1.133 +	static TInt KMaxCounts[] = { 16, 256, 512, 2048, 2052, 4096, 32768, 65536 };
   1.134 +	for (TUint i=0; i<sizeof KMaxCounts/sizeof KMaxCounts[0]; ++i)
   1.135 +		{
   1.136 +		RunTest(KMaxCounts[i]);
   1.137 +		}
   1.138 +
   1.139 +	ServerSem.Close();
   1.140 +	User::Free(buffer);
   1.141 +
   1.142 +	__KHEAP_MARKEND;
   1.143 +
   1.144 +	test.End();
   1.145 +	return KErrNone;
   1.146 +	}