os/kernelhwsrv/kerneltest/e32test/mmu/t_shbuf_perfclient.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/kernelhwsrv/kerneltest/e32test/mmu/t_shbuf_perfclient.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,321 @@
     1.4 +// Copyright (c) 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/mmu/t_shbuf_perfclient.cpp
    1.18 +//
    1.19 +//
    1.20 +
    1.21 +#include <e32std.h>
    1.22 +#include <e32cmn.h>
    1.23 +#include <e32debug.h>
    1.24 +#include <e32msgqueue.h>
    1.25 +#include <e32shbuf.h>
    1.26 +
    1.27 +#include "t_shbuf_perfserver.h"
    1.28 +#include "t_shbuf_perfclient.h"
    1.29 +
    1.30 +
    1.31 +/**
    1.32 + *  @file
    1.33 + * 
    1.34 + *  Client side APIs for a test server used for Performance Testing of shared buffers.
    1.35 + */
    1.36 +
    1.37 +
    1.38 +/**
    1.39 + *  Test API version.
    1.40 + */
    1.41 +const TInt KRShBufTestServerMajorVersion = 1;
    1.42 +const TInt KRShBufTestServerMinorVersion = 0;
    1.43 +const TInt KRShBufTestServerBuildVersion = 1;
    1.44 +
    1.45 +
    1.46 +/**
    1.47 + *  Start the server process which lives in its own executable and rendezvous with it.
    1.48 + *
    1.49 + *  @return  KErrNone if successful, or an error code if not.
    1.50 + */
    1.51 +static TInt StartTestServer()
    1.52 +	{
    1.53 +#ifdef CAN_TRANSFER_SHBUF_TO_ANOTHER_PROCESS
    1.54 +	//
    1.55 +	// Create a new server process. Simultaneous launching of two such
    1.56 +	// processes should be detected when the second one attempts to
    1.57 +	// create the server object, failing with KErrAlreadyExists.
    1.58 +	//		
    1.59 +	_LIT(KTestServerExeImg, "T_SHBUF_PERFSERVER.EXE");
    1.60 +	RProcess server;
    1.61 +	
    1.62 +	TInt  ret = server.Create(KTestServerExeImg, KNullDesC);
    1.63 +	if (ret != KErrNone)
    1.64 +		{
    1.65 +		return ret;
    1.66 +		}
    1.67 +#else
    1.68 +	//
    1.69 +	// Start a thread with the server in it.
    1.70 +	//		
    1.71 +	RThread  server;
    1.72 +	
    1.73 +	TInt  ret = server.Create(_L("RShBufTestServerThread"), RShBufTestServerThread,
    1.74 +							  KDefaultStackSize, 0x10000, 0x10000, NULL);
    1.75 +	if (ret != KErrNone)
    1.76 +		{
    1.77 +		return ret;
    1.78 +		}
    1.79 +#endif
    1.80 +	
    1.81 +	//
    1.82 +	// Rendezvous with the server or abort startup...
    1.83 +	//
    1.84 +	TRequestStatus  status;
    1.85 +
    1.86 +	server.Rendezvous(status);
    1.87 +	if (status != KRequestPending)
    1.88 +		{
    1.89 +		server.Kill(0);
    1.90 +		}
    1.91 +	else
    1.92 +		{
    1.93 +		server.Resume();
    1.94 +		}
    1.95 +	User::WaitForRequest(status);
    1.96 +
    1.97 +	//
    1.98 +	// We can't use the 'exit reason' if the server panicked as this
    1.99 +	// is the panic 'reason' and may be '0' which cannot be distinguished
   1.100 +	// from KErrNone.
   1.101 +	//
   1.102 +	if (server.ExitType() == EExitPanic)
   1.103 +		{
   1.104 +		ret = KErrGeneral;
   1.105 +		}
   1.106 +	else if (status.Int() != KErrAlreadyExists)
   1.107 +		{
   1.108 +		ret = status.Int();
   1.109 +		}
   1.110 +
   1.111 +	server.Close();
   1.112 +	
   1.113 +	return ret;
   1.114 +	} // StartTestServer
   1.115 +
   1.116 +
   1.117 +/**
   1.118 + *  Standard constructor.
   1.119 + */
   1.120 +EXPORT_C RShBufTestServerSession::RShBufTestServerSession()
   1.121 +	{
   1.122 +	// NOP
   1.123 +	} // RShBufTestServerSession::RShBufTestServerSession
   1.124 +
   1.125 +
   1.126 +/**
   1.127 + *  Connects the client to the test server. 
   1.128 + *
   1.129 + *  @return  KErrNone if successful, a system-wide error code if not. 
   1.130 + *
   1.131 + *  @capability None
   1.132 + */
   1.133 +EXPORT_C TInt RShBufTestServerSession::Connect()
   1.134 +	{
   1.135 +	//
   1.136 +	// Create a session with the server, but if it doesn't exist then start it and
   1.137 +	// then create a session.
   1.138 +	//
   1.139 +	TInt  result = CreateSession(KRShBufTestServerName,
   1.140 +								 TVersion(KRShBufTestServerMajorVersion,
   1.141 +	                					  KRShBufTestServerMinorVersion,
   1.142 +	                					  KRShBufTestServerBuildVersion));
   1.143 +	if (result == KErrNotFound  ||  result == KErrServerTerminated)
   1.144 +		{
   1.145 +		result = StartTestServer();
   1.146 +		
   1.147 +		if(result == KErrNone)
   1.148 +			{
   1.149 +			result = CreateSession(KRShBufTestServerName,
   1.150 +								   TVersion(KRShBufTestServerMajorVersion,
   1.151 +	                					    KRShBufTestServerMinorVersion,
   1.152 +	                					    KRShBufTestServerBuildVersion));
   1.153 +			}
   1.154 +		}	
   1.155 +		
   1.156 +	//
   1.157 +	// If the creation of the session fails clean up session data...
   1.158 +	//
   1.159 +	if (result != KErrNone)
   1.160 +		{
   1.161 +		Close();
   1.162 +		}
   1.163 +
   1.164 +	return result;
   1.165 +	} // RShBufTestServerSession::Connect
   1.166 +
   1.167 +
   1.168 +/**
   1.169 + *  Closes the client's session with the RShBuf Test Server. 
   1.170 + *
   1.171 + *  @capability None
   1.172 + */
   1.173 +EXPORT_C void RShBufTestServerSession::Close()
   1.174 +	{
   1.175 +	RSessionBase::Close();
   1.176 +	} // RShBufTestServerSession::Close
   1.177 +
   1.178 +
   1.179 +/**
   1.180 + *  Returns the current version of the RShBuf Test Server.
   1.181 + *
   1.182 + *  @return The version of the RShBuf Test Server. 
   1.183 + *
   1.184 + *  @capability None
   1.185 + */
   1.186 +EXPORT_C TVersion RShBufTestServerSession::Version() const
   1.187 +	{
   1.188 +	return(TVersion(KRShBufTestServerMajorVersion,
   1.189 +	                KRShBufTestServerMinorVersion,
   1.190 +	                KRShBufTestServerBuildVersion));
   1.191 +	} // RShBufTestServerSession::Version
   1.192 +
   1.193 +
   1.194 +/**
   1.195 + *  Requests the shutdown of the server when the last client disconnects.
   1.196 + *  There is no support for immediate shutdown functionality. This API call
   1.197 + *  can only be executed if the server is compiled as a debug release.
   1.198 + *  
   1.199 + *  @return  KErrNone if successful, a system-wide error code if not. 
   1.200 + */
   1.201 +EXPORT_C TInt RShBufTestServerSession::ShutdownServer()
   1.202 +	{	
   1.203 +	return SendReceive(EShBufServerShutdownServer, TIpcArgs());
   1.204 +	} // RShBufTestServerSession::ShutdownServer
   1.205 +
   1.206 +
   1.207 +EXPORT_C TInt RShBufTestServerSession::FromTPtr8ProcessAndReturn(TDes8& aBuf, TUint aBufSize)
   1.208 +	{
   1.209 +	TIpcArgs  args(&aBuf, aBufSize);
   1.210 +	
   1.211 +	return SendReceive(EShBufServerFromTPtr8ProcessAndReturn, args);
   1.212 +	} // RShBufTestServerSession::FromTPtr8ProcessAndReturn
   1.213 +
   1.214 +
   1.215 +EXPORT_C TInt RShBufTestServerSession::FromTPtr8ProcessAndRelease(const TDesC8& aBuf)
   1.216 +	{
   1.217 +	TIpcArgs  args(&aBuf);
   1.218 +	
   1.219 +	return SendReceive(EShBufServerFromTPtr8ProcessAndRelease, args);
   1.220 +	} // RShBufTestServerSession::FromTPtr8ProcessAndRelease
   1.221 +
   1.222 +
   1.223 +EXPORT_C TInt RShBufTestServerSession::FromRShBufProcessAndReturn(RShBuf& aShBuf, TUint aBufSize)
   1.224 +	{
   1.225 +	TInt r;
   1.226 +	TInt handle;
   1.227 +	TPckg<TInt> handlePckg(handle);
   1.228 +
   1.229 +	TIpcArgs  args(&handlePckg, aBufSize);
   1.230 +
   1.231 +	r = SendReceive(EShBufServerFromRShBufProcessAndReturn, args);
   1.232 +
   1.233 +	if (r == KErrNone)
   1.234 +	    aShBuf.SetReturnedHandle(handle);
   1.235 +
   1.236 +	return r;
   1.237 +	} // RShBufTestServerSession::FromRShBufProcessAndReturn
   1.238 +
   1.239 +
   1.240 +EXPORT_C TInt RShBufTestServerSession::OpenRShBufPool(TInt aHandle, const TShPoolInfo& aShPoolInfo)
   1.241 +	{
   1.242 +	TPckg<TShPoolInfo>  shPoolInfoPckg(aShPoolInfo);
   1.243 +	TIpcArgs  args(aHandle, &shPoolInfoPckg);
   1.244 +	
   1.245 +	return SendReceive(EShBufServerOpenRShBufPool, args);
   1.246 +	} // RShBufTestServerSession::OpenRShBufPool
   1.247 +
   1.248 +
   1.249 +EXPORT_C TInt RShBufTestServerSession::CloseRShBufPool(TInt aHandle)
   1.250 +	{
   1.251 +	TIpcArgs  args(aHandle);
   1.252 +	
   1.253 +	return SendReceive(EShBufServerCloseRShBufPool, args);
   1.254 +	} // RShBufTestServerSession::CloseRShBufPool
   1.255 +
   1.256 +
   1.257 +EXPORT_C TInt RShBufTestServerSession::FromRShBufProcessAndRelease(RShBuf& aShBuf)
   1.258 +	{
   1.259 +	TIpcArgs  args(aShBuf.Handle());
   1.260 +
   1.261 +	return SendReceive(EShBufServerFromRShBufProcessAndRelease, args);
   1.262 +	} // RShBufTestServerSession::FromRShBufProcessAndRelease
   1.263 +
   1.264 +
   1.265 +/**
   1.266 + *  Set a heap mark in the RShBuf Test Server thread.
   1.267 + *
   1.268 + *  @capability None
   1.269 + */
   1.270 +EXPORT_C TInt RShBufTestServerSession::__DbgMarkHeap()
   1.271 +	{
   1.272 +	TIpcArgs args(TIpcArgs::ENothing);
   1.273 +
   1.274 +	return SendReceive(EShBufServerDbgMarkHeap, args);
   1.275 +	} // RShBufTestServerSession::__DbgMarkHeap
   1.276 +
   1.277 +
   1.278 +/**
   1.279 + *  Performs a heap mark check in the RShBuf Test Server thread.
   1.280 + *
   1.281 + *  @param aCount  The number of heap cells expected to be allocated at
   1.282 + *                 the current nest level.
   1.283 + *
   1.284 + *  @capability None
   1.285 + */
   1.286 +EXPORT_C TInt RShBufTestServerSession::__DbgCheckHeap(TInt aCount)
   1.287 +	{
   1.288 +	TIpcArgs args(aCount);
   1.289 +
   1.290 +	return SendReceive(EShBufServerDbgCheckHeap, args);
   1.291 +	} // RShBufTestServerSession::__DbgCheckHeap
   1.292 +
   1.293 +
   1.294 +/**
   1.295 + *  Perfom a heap mark end check in the RShBuf Test Server thread.
   1.296 + *
   1.297 + *  @param aCount  The number of heap cells expected to remain allocated
   1.298 + *                 at the current nest level.
   1.299 + *
   1.300 + *  @capability None
   1.301 + */
   1.302 +EXPORT_C TInt RShBufTestServerSession::__DbgMarkEnd(TInt aCount)
   1.303 +	{
   1.304 +	TIpcArgs args(aCount);
   1.305 +
   1.306 +	return SendReceive(EShBufServerDbgMarkEnd, args);
   1.307 +	} // RShBufTestServerSession::__DbgMarkEnd
   1.308 +
   1.309 +
   1.310 +/**
   1.311 + *  Set a heap fail next condition in the RShBuf Test Server thread.
   1.312 + *
   1.313 + *  @param aCount  Determines when the allocation will fail.
   1.314 + *
   1.315 + *  @capability None
   1.316 + */
   1.317 +EXPORT_C TInt RShBufTestServerSession::__DbgFailNext(TInt aCount)
   1.318 +	{
   1.319 +	TIpcArgs args(aCount);
   1.320 +
   1.321 +	return SendReceive(EShBufServerDbgFailNext, args);
   1.322 +	} // RShBufTestServerSession::__DbgFailNext
   1.323 +
   1.324 +