os/kernelhwsrv/kerneltest/e32test/misc/t_svrstress.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/kernelhwsrv/kerneltest/e32test/misc/t_svrstress.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,735 @@
     1.4 +// Copyright (c) 2008-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\misc\t_svrstress.cpp
    1.18 +// This is a stress test for client server session connect and disconnect
    1.19 +//
    1.20 +
    1.21 +#include <e32base.h>
    1.22 +#include <e32base_private.h>
    1.23 +#define __E32TEST_EXTENSION__
    1.24 +#include <e32test.h>
    1.25 +#include <e32svr.h>
    1.26 +#include "u32std.h"
    1.27 +#include <e32atomics.h>
    1.28 +#include <e32panic.h>
    1.29 +#include <e32def.h>
    1.30 +#include <e32def_private.h>
    1.31 +
    1.32 +RTest test(_L("T_SVRSTRESS"));
    1.33 +
    1.34 +RSemaphore SyncSemaphore;
    1.35 +TUint32 WaitABit;
    1.36 +
    1.37 +TInt NumMessageSlots;
    1.38 +TInt UseGlobalMessagePool;
    1.39 +
    1.40 +const TInt BigDesLength = 256 * 1024;
    1.41 +
    1.42 +#if 1
    1.43 +#define TRACE(t) RDebug::RawPrint(_L8(t))
    1.44 +#else
    1.45 +#define TRACE(t)
    1.46 +#endif
    1.47 +
    1.48 +//
    1.49 +// utility functions...
    1.50 +//
    1.51 +
    1.52 +void WaitForRequest()
    1.53 +	{
    1.54 +	User::WaitForAnyRequest();
    1.55 +	RThread().RequestSignal(); // put request semaphore count back
    1.56 +	}
    1.57 +
    1.58 +
    1.59 +TInt WaitForRequest(TRequestStatus& aStatus,TTimeIntervalMicroSeconds32 aTimeout=2*1000000)
    1.60 +	{
    1.61 +	RTimer timer;
    1.62 +	test_Equal(KErrNone,timer.CreateLocal());
    1.63 +
    1.64 +	TRequestStatus timeoutStatus;
    1.65 +	timer.After(timeoutStatus,aTimeout);
    1.66 +
    1.67 +	User::WaitForRequest(aStatus,timeoutStatus);
    1.68 +
    1.69 +	TInt r;
    1.70 +	if(aStatus.Int()==KRequestPending)
    1.71 +		{
    1.72 +		r = KErrTimedOut;
    1.73 +		}
    1.74 +	else
    1.75 +		{
    1.76 +		r = KErrNone;
    1.77 +		timer.Cancel();
    1.78 +		User::WaitForRequest(timeoutStatus);
    1.79 +		}
    1.80 +
    1.81 +	CLOSE_AND_WAIT(timer);
    1.82 +
    1.83 +	return r;
    1.84 +	}
    1.85 +
    1.86 +
    1.87 +//
    1.88 +// CMyServer
    1.89 +//
    1.90 +
    1.91 +_LIT(KMyServerName,"StressSvr");
    1.92 +
    1.93 +class CMyServer : public CServer2
    1.94 +	{
    1.95 +public:
    1.96 +	CMyServer(TInt aPriority);
    1.97 +	static CMyServer* New(TInt aPriority);
    1.98 +	virtual CSession2* NewSessionL(const TVersion&, const RMessage2&) const;
    1.99 +	};
   1.100 +
   1.101 +
   1.102 +class CMySession : public CSession2
   1.103 +	{
   1.104 +public:
   1.105 +	virtual void ServiceL(const RMessage2& aMessage);
   1.106 +	};
   1.107 +
   1.108 +
   1.109 +CMyServer* CMyServer::New(TInt aPriority)
   1.110 +	{
   1.111 +	return new CMyServer(aPriority);
   1.112 +	}
   1.113 +
   1.114 +
   1.115 +CMyServer::CMyServer(TInt aPriority)
   1.116 +	: CServer2(aPriority, ESharableSessions)
   1.117 +	{}
   1.118 +
   1.119 +
   1.120 +CSession2* CMyServer::NewSessionL(const TVersion&, const RMessage2&) const
   1.121 +	{
   1.122 +	TRACE("O");
   1.123 +	return new(ELeave) CMySession;
   1.124 +	}
   1.125 +
   1.126 +
   1.127 +TBool RestartServer;
   1.128 +
   1.129 +TInt MyServerThread(TAny*)
   1.130 +	{
   1.131 +	CActiveScheduler* pR=new CActiveScheduler;
   1.132 +	if(!pR)
   1.133 +		return KErrNoMemory;
   1.134 +	CActiveScheduler::Install(pR);
   1.135 +	RestartServer = ETrue;
   1.136 +
   1.137 +	while(RestartServer)
   1.138 +		{
   1.139 +		__UHEAP_MARK;
   1.140 +		CMyServer* pS=CMyServer::New(0);
   1.141 +		if(!pS)
   1.142 +			return KErrNoMemory;
   1.143 +		TInt r = pS->Start(KMyServerName);
   1.144 +		if(r!=KErrNone)
   1.145 +			return r;
   1.146 +
   1.147 +		TRACE("S");
   1.148 +		RThread::Rendezvous(KErrNone);
   1.149 +
   1.150 +		CActiveScheduler::Start();
   1.151 +
   1.152 +		delete pS;
   1.153 +		__UHEAP_MARKEND;
   1.154 +		}
   1.155 +
   1.156 +	delete pR;
   1.157 +	return KErrNone;
   1.158 +	}
   1.159 +
   1.160 +
   1.161 +//
   1.162 +// RMyServer
   1.163 +//
   1.164 +
   1.165 +class RMyServer : public RSessionBase
   1.166 +	{
   1.167 +public:
   1.168 +	enum TFunction
   1.169 +		{
   1.170 +		EStop,
   1.171 +		ESync,
   1.172 +		EPing,
   1.173 +		EShutdown,
   1.174 +		ECompleteWhileCopying
   1.175 +		};
   1.176 +public:
   1.177 +	TInt Connect();
   1.178 +
   1.179 +	inline TInt Send(TFunction aFunction) const
   1.180 +		{ return SendReceive(aFunction); }
   1.181 +
   1.182 +	inline TInt Send(TFunction aFunction, const TIpcArgs& aArgs) const
   1.183 +		{ return SendReceive(aFunction, aArgs); }
   1.184 +
   1.185 +	inline void Send(TFunction aFunction, TRequestStatus& aStatus) const
   1.186 +		{ SendReceive(aFunction, aStatus); }
   1.187 +
   1.188 +	inline void Send(TFunction aFunction, const TIpcArgs& aArgs, TRequestStatus& aStatus) const
   1.189 +		{ SendReceive(aFunction, aArgs, aStatus); }
   1.190 +	};
   1.191 +
   1.192 +
   1.193 +TInt RMyServer::Connect()
   1.194 +	{
   1.195 +	RMyServer temp;
   1.196 +	TInt r = temp.CreateSession(KMyServerName, TVersion(), UseGlobalMessagePool ? -1 : NumMessageSlots);
   1.197 +	if(r!=KErrNone)
   1.198 +		return r;
   1.199 +
   1.200 +	// turn handle into process owned...
   1.201 +	RMyServer temp2(temp);
   1.202 +	r = temp2.Duplicate(RThread());
   1.203 +	temp.Close();
   1.204 +
   1.205 +	*this = temp2;
   1.206 +	return r;
   1.207 +	}
   1.208 +
   1.209 +
   1.210 +
   1.211 +//
   1.212 +// CMySession
   1.213 +//
   1.214 +
   1.215 +TInt CopierThread(TAny* aPtr)
   1.216 +	{
   1.217 +	RMessage2& msg = *(RMessage2*)aPtr;
   1.218 +	HBufC* bigdes = HBufC::NewMax(BigDesLength);
   1.219 +	if (bigdes == NULL)
   1.220 +		return KErrNoMemory;
   1.221 +	TPtr ptr = bigdes->Des();
   1.222 +	RThread().Rendezvous(KErrNone);
   1.223 +	RDebug::Print(_L("START\n"));
   1.224 +	TInt r = msg.Read(2, ptr);
   1.225 +	RDebug::Print(_L("DONE\n"));
   1.226 +	delete bigdes;
   1.227 +	return r;
   1.228 +	}
   1.229 +
   1.230 +void CMySession::ServiceL(const RMessage2& aMessage)
   1.231 +	{
   1.232 +	RThread client;
   1.233 +	RThread copier;
   1.234 +	aMessage.Client(client);
   1.235 +	TRequestStatus* s;
   1.236 +	TRequestStatus* s2;
   1.237 +	TRequestStatus logon, rendez;
   1.238 +	TInt r;
   1.239 +	s = (TRequestStatus*)aMessage.Ptr0();
   1.240 +
   1.241 +	switch(aMessage.Function())
   1.242 +		{
   1.243 +	case RMyServer::EStop:
   1.244 +		TRACE("E");
   1.245 +		CActiveScheduler::Stop();
   1.246 +		break;
   1.247 +
   1.248 +	case RMyServer::ESync:
   1.249 +		TRACE("Y");
   1.250 +		client.RequestComplete(s,KErrNone);		// let client know we've received the message
   1.251 +		SyncSemaphore.Wait();					// wait for signal from client
   1.252 +		s = (TRequestStatus*)aMessage.Ptr1();	// use second status for later end signal
   1.253 +		aMessage.Complete(KErrNone);			// complete the message
   1.254 +		break;
   1.255 +
   1.256 +	case RMyServer::EPing:
   1.257 +		TRACE("P");
   1.258 +		aMessage.Complete(KErrNone);
   1.259 +		break;
   1.260 +
   1.261 +	case RMyServer::EShutdown:
   1.262 +		TRACE("D");
   1.263 +		RestartServer = EFalse;
   1.264 +		CActiveScheduler::Stop();
   1.265 +		break;
   1.266 +
   1.267 +	case RMyServer::ECompleteWhileCopying:
   1.268 +		s2 = (TRequestStatus*)aMessage.Ptr1();
   1.269 +		r = copier.Create(_L("Copier"),CopierThread,KDefaultStackSize,&User::Allocator(),(TAny*)&aMessage);
   1.270 +		if (r == KErrNone)
   1.271 +			{
   1.272 +			copier.Logon(logon);
   1.273 +			copier.Rendezvous(rendez);
   1.274 +			copier.SetPriority(EPriorityLess);
   1.275 +			copier.Resume();
   1.276 +			User::WaitForRequest(rendez);
   1.277 +			User::AfterHighRes(5000); // 5ms delay to let copy actually start
   1.278 +			RDebug::Print(_L("COMPLETING\n"));
   1.279 +			aMessage.Complete(KErrNone);
   1.280 +			User::WaitForRequest(logon);
   1.281 +			copier.Close();
   1.282 +			}
   1.283 +		client.RequestComplete(s,r);
   1.284 +		s = s2;
   1.285 +		break;
   1.286 +
   1.287 +	default:
   1.288 +		TRACE("?");
   1.289 +		aMessage.Complete(KErrNotSupported);
   1.290 +		break;
   1.291 +		}
   1.292 +
   1.293 +	// let client know we've completed the message...
   1.294 +	TRACE("X");
   1.295 +	client.RequestComplete(s,KErrNone);
   1.296 +
   1.297 +	client.Close();
   1.298 +	}
   1.299 +
   1.300 +
   1.301 +
   1.302 +//
   1.303 +// RStressThread
   1.304 +//
   1.305 +
   1.306 +class RStressThread
   1.307 +	{
   1.308 +public:
   1.309 +	RStressThread(TThreadFunction aThreadFunction, const char* aName, TInt aDelay=-1);
   1.310 +	~RStressThread();
   1.311 +	void Start();
   1.312 +	void Restart();
   1.313 +	void Stop();
   1.314 +	// for use by thread...
   1.315 +	static RStressThread& Begin(TAny* aInfo);
   1.316 +	TBool Loop();
   1.317 +private:
   1.318 +	TThreadFunction iThreadFunction;
   1.319 +	const char* iName;
   1.320 +	RThread iThread;
   1.321 +	TRequestStatus iLogon;
   1.322 +	TUint iCount;
   1.323 +	TBool iStop;
   1.324 +	TInt iDelay;
   1.325 +
   1.326 +private:
   1.327 +	static TInt iInstanceCounter;
   1.328 +	};
   1.329 +
   1.330 +
   1.331 +TInt RStressThread::iInstanceCounter = 0;
   1.332 +
   1.333 +
   1.334 +RStressThread::RStressThread(TThreadFunction aThreadFunction, const char* aName, TInt aDelay)
   1.335 +	: iThreadFunction(aThreadFunction), iName(aName), iLogon(KErrNone), iDelay(aDelay)
   1.336 +	{
   1.337 +	iThread.SetHandle(0);
   1.338 +	}
   1.339 +
   1.340 +
   1.341 +RStressThread::~RStressThread()
   1.342 +	{
   1.343 +	Stop();
   1.344 +	}
   1.345 +
   1.346 +
   1.347 +void RStressThread::Start()
   1.348 +	{
   1.349 +	iStop = false;
   1.350 +	iCount = 0;
   1.351 +
   1.352 +	TBuf<KMaxKernelName> name;
   1.353 +	name.Copy(TPtrC8((const TUint8*)iName));
   1.354 +	name.Append((TText)'-');
   1.355 +	name.AppendNum(iInstanceCounter++);
   1.356 +	test_Equal(KErrNone,iThread.Create(name,iThreadFunction,KDefaultStackSize,&User::Allocator(),this));
   1.357 +
   1.358 +	iThread.Logon(iLogon);
   1.359 +	test_Equal(KRequestPending,iLogon.Int());
   1.360 +
   1.361 +	TRequestStatus rendezvous;
   1.362 +	iThread.Rendezvous(rendezvous);
   1.363 +
   1.364 +	iThread.Resume();
   1.365 +
   1.366 +	User::WaitForRequest(rendezvous);
   1.367 +	test_Equal(KErrNone,rendezvous.Int());
   1.368 +	}
   1.369 +
   1.370 +
   1.371 +void RStressThread::Stop()
   1.372 +	{
   1.373 +	if(!iThread.Handle())
   1.374 +		return; // thread not running
   1.375 +
   1.376 +	iStop = true;
   1.377 +	RDebug::Printf("RStressThread::Stop %s (count=%d)",iName,iCount);
   1.378 +	if(WaitForRequest(iLogon,10*1000000)!=KErrNone)
   1.379 +		test(0);
   1.380 +	CLOSE_AND_WAIT(iThread);
   1.381 +	}
   1.382 +
   1.383 +
   1.384 +void RStressThread::Restart()
   1.385 +	{
   1.386 +	if(iThread.Handle())
   1.387 +		{
   1.388 +		if(iLogon==KRequestPending)
   1.389 +			return; // thread still running
   1.390 +
   1.391 +		User::WaitForRequest(iLogon);
   1.392 +		CLOSE_AND_WAIT(iThread);
   1.393 +		}
   1.394 +
   1.395 +	Start();
   1.396 +	}
   1.397 +
   1.398 +
   1.399 +TBool RStressThread::Loop()
   1.400 +	{
   1.401 +	if(iDelay>=0)
   1.402 +		User::AfterHighRes(iDelay);
   1.403 +	++iCount;
   1.404 +	return !iStop;
   1.405 +	}
   1.406 +
   1.407 +
   1.408 +RStressThread& RStressThread::Begin(TAny* aInfo)
   1.409 +	{
   1.410 +	RStressThread& t = *(RStressThread*)aInfo;
   1.411 +	if(t.iDelay>=0)
   1.412 +		RThread().SetPriority(EPriorityMore); // so this preempts threads after delay
   1.413 +	RThread::Rendezvous(KErrNone);
   1.414 +	return t;
   1.415 +	}
   1.416 +
   1.417 +//
   1.418 +//
   1.419 +//
   1.420 +
   1.421 +
   1.422 +RMyServer Session;
   1.423 +RThread ServerThread;
   1.424 +
   1.425 +
   1.426 +void NewSession()
   1.427 +	{
   1.428 +	RMyServer newSession;
   1.429 +	TRACE("o");
   1.430 +	test_Equal(KErrNone,newSession.Connect());
   1.431 +
   1.432 +	RMyServer oldSession(Session);
   1.433 +	Session = newSession;
   1.434 +
   1.435 +	TRACE("c");
   1.436 +	if(oldSession.Handle())
   1.437 +		CLOSE_AND_WAIT(oldSession);
   1.438 +	}
   1.439 +
   1.440 +
   1.441 +TInt SessionCloserThread(TAny* aInfo)
   1.442 +	{
   1.443 +	RStressThread& t = RStressThread::Begin(aInfo);
   1.444 +	do
   1.445 +		{
   1.446 +		NewSession();
   1.447 +		}
   1.448 +	while(t.Loop());
   1.449 +	return KErrNone;
   1.450 +	}
   1.451 +
   1.452 +
   1.453 +TInt ServerStopperThread(TAny* aInfo)
   1.454 +	{
   1.455 +	RStressThread& t = RStressThread::Begin(aInfo);
   1.456 +	do
   1.457 +		{
   1.458 +		TRACE("s");
   1.459 +		TRequestStatus rendezvous;
   1.460 +		ServerThread.Rendezvous(rendezvous);
   1.461 +
   1.462 +		TRequestStatus s1 = KRequestPending;
   1.463 +		TRequestStatus s2;
   1.464 +		Session.Send(RMyServer::EStop,TIpcArgs(&s1),s2);
   1.465 +		User::WaitForRequest(s1,s2);
   1.466 +		if(s2!=KRequestPending)
   1.467 +			{
   1.468 +			test_Equal(KErrServerTerminated,s2.Int());
   1.469 +			User::WaitForRequest(s1);
   1.470 +			}
   1.471 +
   1.472 +		User::WaitForRequest(rendezvous);
   1.473 +		NewSession();
   1.474 +		}
   1.475 +	while(t.Loop());
   1.476 +	return KErrNone;
   1.477 +	}
   1.478 +
   1.479 +
   1.480 +TInt SessionPingerThread(TAny* aInfo)
   1.481 +	{
   1.482 +	RStressThread& t = RStressThread::Begin(aInfo);
   1.483 +	do
   1.484 +		{
   1.485 +		TRACE("p");
   1.486 +		TRequestStatus s1 = KRequestPending;
   1.487 +		TRequestStatus s2;
   1.488 +		Session.Send(RMyServer::EPing,TIpcArgs(&s1),s2);
   1.489 +		User::WaitForRequest(s1,s2);
   1.490 +		if(s2.Int()==KErrNone)
   1.491 +			{
   1.492 +			// message completed OK, wait for servers extra signal
   1.493 +			User::WaitForRequest(s1);
   1.494 +			}
   1.495 +		else if(s2.Int()==KErrServerTerminated)
   1.496 +			{
   1.497 +			// server died before message processed, there shouldn't be an extra signal
   1.498 +			test_Equal(KRequestPending,s1.Int());
   1.499 +			}
   1.500 +		else
   1.501 +			{
   1.502 +			// assume message was completed by server, but we didn't get signalled because session was closed
   1.503 +			test_Equal(KRequestPending,s2.Int());
   1.504 +			test_Equal(KErrNone,s1.Int());
   1.505 +			}
   1.506 +		}
   1.507 +	while(t.Loop());
   1.508 +	return KErrNone;
   1.509 +	}
   1.510 +
   1.511 +
   1.512 +void TestInit()
   1.513 +	{
   1.514 +	RThread().SetPriority(EPriorityMuchMore); // so this main thread is higher priority than workers
   1.515 +
   1.516 +	test_Equal(KErrNone,SyncSemaphore.CreateLocal(0,EOwnerProcess));
   1.517 +
   1.518 +	// calculate async cleanup timeout value...
   1.519 +	TInt factor = UserSvr::HalFunction(EHalGroupVariant, EVariantHalTimeoutExpansion, 0, 0);
   1.520 +	if (factor<=0)
   1.521 +		factor = 1;
   1.522 +	if (factor>1024)
   1.523 +		factor = 1024;
   1.524 +	WaitABit = 200000 * (TUint32)factor;
   1.525 +	}
   1.526 +
   1.527 +
   1.528 +void StartServer()
   1.529 +	{
   1.530 +	// start test server...
   1.531 +	test_Equal(KErrNone,ServerThread.Create(_L("Server"),MyServerThread,KDefaultStackSize,1<<12,1<<20,0));
   1.532 +	TRequestStatus rendezvous;
   1.533 +	ServerThread.Rendezvous(rendezvous);
   1.534 +	ServerThread.Resume();
   1.535 +	User::WaitForRequest(rendezvous);
   1.536 +	test_Equal(KErrNone,rendezvous.Int());
   1.537 +	test_Equal(EExitPending,ServerThread.ExitType());
   1.538 +	}
   1.539 +
   1.540 +
   1.541 +void StopServer()
   1.542 +	{
   1.543 +	TRequestStatus logon;
   1.544 +	NewSession();
   1.545 +	TRequestStatus s1 = KRequestPending;
   1.546 +	TRequestStatus s2;
   1.547 +	ServerThread.Logon(logon);
   1.548 +	Session.Send(RMyServer::EShutdown,TIpcArgs(&s1),s2);
   1.549 +	User::WaitForRequest(s1,s2);
   1.550 +	if(s2!=KRequestPending)
   1.551 +		{
   1.552 +		test_Equal(KErrServerTerminated,s2.Int());
   1.553 +		User::WaitForRequest(s1);
   1.554 +		}
   1.555 +	CLOSE_AND_WAIT(Session);
   1.556 +	User::WaitForRequest(logon);
   1.557 +	test_KErrNone(logon.Int());
   1.558 +	test_Equal(EExitKill, ServerThread.ExitType());
   1.559 +	CLOSE_AND_WAIT(ServerThread);
   1.560 +	}
   1.561 +
   1.562 +
   1.563 +void TestMessageCompleteOnClosedSession()
   1.564 +	{
   1.565 +	__KHEAP_MARK;
   1.566 +
   1.567 +	test.Start(_L("Start server"));
   1.568 +	StartServer();
   1.569 +
   1.570 +	test.Next(_L("Connect"));
   1.571 +	test_Equal(KErrNone,Session.Connect());
   1.572 +
   1.573 +	test.Next(_L("Send message"));
   1.574 +	TRequestStatus s1 = KRequestPending;
   1.575 +	TRequestStatus s2 = KRequestPending;
   1.576 +	TRequestStatus s3;
   1.577 +	Session.Send(RMyServer::ESync,TIpcArgs(&s1,&s2),s3);
   1.578 +	test_Equal(KRequestPending,s3.Int());
   1.579 +
   1.580 +	test.Next(_L("Wait for s1"));
   1.581 +	test_Equal(KErrNone,WaitForRequest(s1));
   1.582 +	test_Equal(KErrNone,s1.Int());
   1.583 +	test_Equal(KRequestPending,s2.Int());
   1.584 +	test_Equal(KRequestPending,s3.Int());
   1.585 +
   1.586 +	test.Next(_L("Close session"));
   1.587 +	Session.Close();
   1.588 +	test_Equal(KRequestPending,s2.Int());
   1.589 +	test_Equal(KRequestPending,s3.Int());
   1.590 +
   1.591 +	test.Next(_L("Trigger message completion"));
   1.592 +	SyncSemaphore.Signal();
   1.593 +
   1.594 +	test.Next(_L("Wait for s2"));
   1.595 +	test_Equal(KErrNone,WaitForRequest(s2));
   1.596 +	test_Equal(KErrNone,s2.Int());
   1.597 +	test_Equal(KRequestPending,s3.Int());
   1.598 +
   1.599 +	test.Next(_L("Stop server"));
   1.600 +	StopServer();
   1.601 +
   1.602 +	test.End();
   1.603 +
   1.604 +	User::After(WaitABit);	// allow asynchronous cleanup to happen
   1.605 +
   1.606 +	__KHEAP_MARKEND;
   1.607 +	}
   1.608 +
   1.609 +
   1.610 +void TestMessageCompleteWhileCopying()
   1.611 +	{
   1.612 +	__KHEAP_MARK;
   1.613 +
   1.614 +	test.Start(_L("Start server"));
   1.615 +	StartServer();
   1.616 +
   1.617 +	test.Next(_L("Connect"));
   1.618 +	test_Equal(KErrNone,Session.Connect());
   1.619 +
   1.620 +	test.Next(_L("Create large descriptor"));
   1.621 +	HBufC* bigdes = HBufC::NewMax(BigDesLength);
   1.622 +	test_NotNull(bigdes);
   1.623 +	TPtr ptr = bigdes->Des();
   1.624 +
   1.625 +	test.Next(_L("Send message"));
   1.626 +	TRequestStatus s1 = KRequestPending;
   1.627 +	TRequestStatus s2 = KRequestPending;
   1.628 +	TRequestStatus s3;
   1.629 +	Session.Send(RMyServer::ECompleteWhileCopying,TIpcArgs(&s1,&s2,&ptr),s3);
   1.630 +
   1.631 +	test.Next(_L("Wait for s3"));
   1.632 +	test_Equal(KErrNone,WaitForRequest(s3,10*1000000));
   1.633 +	test_Equal(KErrNone,s3.Int());
   1.634 +
   1.635 +	test.Next(_L("Wait for s2"));
   1.636 +	test_Equal(KErrNone,WaitForRequest(s2,10*1000000));
   1.637 +	test_Equal(KErrNone,s2.Int());
   1.638 +
   1.639 +	test.Next(_L("Wait for s1"));
   1.640 +	test_Equal(KErrNone,WaitForRequest(s1,10*1000000));
   1.641 +	test_Equal(KErrNone,s1.Int());
   1.642 +
   1.643 +	test.Next(_L("Close session"));
   1.644 +	Session.Close();
   1.645 +
   1.646 +	test.Next(_L("Stop server"));
   1.647 +	StopServer();
   1.648 +
   1.649 +	test.End();
   1.650 +
   1.651 +	User::After(WaitABit);	// allow asynchronous cleanup to happen
   1.652 +
   1.653 +	__KHEAP_MARKEND;
   1.654 +	}
   1.655 +
   1.656 +
   1.657 +void RunStressThreads(RStressThread& aThread1, RStressThread& aThread2, TInt aTimeout=1000000)
   1.658 +	{
   1.659 +	__KHEAP_MARK;
   1.660 +
   1.661 +	StartServer();
   1.662 +
   1.663 +	NewSession();
   1.664 +
   1.665 +	aThread1.Start();
   1.666 +	aThread2.Start();
   1.667 +
   1.668 +	RTimer timer;
   1.669 +	test_Equal(KErrNone,timer.CreateLocal());
   1.670 +	TRequestStatus timeoutStatus;
   1.671 +	timer.After(timeoutStatus,aTimeout);
   1.672 +	do
   1.673 +		{
   1.674 +		aThread1.Restart();
   1.675 +		aThread2.Restart();
   1.676 +		WaitForRequest();
   1.677 +		}
   1.678 +	while(timeoutStatus==KRequestPending);
   1.679 +	User::WaitForRequest(timeoutStatus);
   1.680 +	CLOSE_AND_WAIT(timer);
   1.681 +
   1.682 +	aThread2.Stop();
   1.683 +	aThread1.Stop();
   1.684 +
   1.685 +	CLOSE_AND_WAIT(Session);
   1.686 +	StopServer();
   1.687 +
   1.688 +	User::After(WaitABit);	// allow asynchronous cleanup to happen
   1.689 +	__KHEAP_MARKEND;
   1.690 +	}
   1.691 +
   1.692 +
   1.693 +GLDEF_C TInt E32Main()
   1.694 +	{
   1.695 +	TInt i;
   1.696 +
   1.697 +	test.Title();
   1.698 +
   1.699 +	test.Start(_L("Initialise"));
   1.700 +	TestInit();
   1.701 +
   1.702 +	for(UseGlobalMessagePool=0; UseGlobalMessagePool<2; ++UseGlobalMessagePool)
   1.703 +		{
   1.704 +		if(UseGlobalMessagePool)
   1.705 +			test.Next(_L("Tests using global message pool"));
   1.706 +		else
   1.707 +			test.Next(_L("Tests using local message pool"));
   1.708 +
   1.709 +		NumMessageSlots = 1;
   1.710 +
   1.711 +		test.Start(_L("Check completing messages on dead session"));
   1.712 +		TestMessageCompleteOnClosedSession();
   1.713 +
   1.714 +		for (i=0; i<10; i++)
   1.715 +			{
   1.716 +			test.Next(_L("Check completing message while IPC copying"));
   1.717 +			TestMessageCompleteWhileCopying();
   1.718 +			}
   1.719 +
   1.720 +		test.Next(_L("Stress closing session whilst in use"));
   1.721 +		RStressThread closer(SessionCloserThread,"SessionCloser",0);
   1.722 +		RStressThread pinger1(SessionPingerThread,"Pinger");
   1.723 +		RunStressThreads(closer, pinger1);
   1.724 +
   1.725 +		NumMessageSlots = 2;
   1.726 +
   1.727 +		test.Next(_L("Stress stopping server whilst in use"));
   1.728 +		RStressThread stopper(ServerStopperThread,"ServerStopper",0);
   1.729 +		RStressThread pinger2(SessionPingerThread,"Pinger");
   1.730 +		RunStressThreads(stopper, pinger2);
   1.731 +
   1.732 +		test.End();
   1.733 +		}
   1.734 +
   1.735 +	test.End();
   1.736 +	return(0);
   1.737 +	}
   1.738 +