os/kernelhwsrv/kerneltest/e32test/bench/t_svr5.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
sl@0
     1
// Copyright (c) 1995-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     2
// All rights reserved.
sl@0
     3
// This component and the accompanying materials are made available
sl@0
     4
// under the terms of the License "Eclipse Public License v1.0"
sl@0
     5
// which accompanies this distribution, and is available
sl@0
     6
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     7
//
sl@0
     8
// Initial Contributors:
sl@0
     9
// Nokia Corporation - initial contribution.
sl@0
    10
//
sl@0
    11
// Contributors:
sl@0
    12
//
sl@0
    13
// Description:
sl@0
    14
// e32test\bench\t_svr5.cpp
sl@0
    15
// Overview:
sl@0
    16
// Test client server shareable sessions and benchmark their performance.
sl@0
    17
// API information:
sl@0
    18
// CSession2, CServer2, RSessionBase, RMessage2, DServer, DSession 
sl@0
    19
// Details:
sl@0
    20
// - Start the test server
sl@0
    21
// - Open a connection with the server specifying 0 message slots should be 
sl@0
    22
// available for the session and verify the server returns KErrServerBusy 
sl@0
    23
// when it tries to pass a message to it.
sl@0
    24
// - Open a connection using a fixed pool of messages and test that the server 
sl@0
    25
// handles the messages correctly.
sl@0
    26
// - Open a connection using the kernel's global pool of messages and test the 
sl@0
    27
// servers handles the messages correctly.
sl@0
    28
// - Open a shareable session with the server and verify that:
sl@0
    29
// - all arguments are passed to the server and back correctly
sl@0
    30
// - server can read and write to/from the client and return the appropriate 
sl@0
    31
// errors when bad descriptors are passed in.
sl@0
    32
// - another thread can share the session to send messages to the server.
sl@0
    33
// - a message sent by one thread can be saved and completed later in 
sl@0
    34
// response to a message sent by a different thread.
sl@0
    35
// - another thread can close the session.
sl@0
    36
// - a different thread can attach to a session by handle.
sl@0
    37
// - Establish a global shareable session to the server and test it fails, as 
sl@0
    38
// the server doesn't support global shareable sessions.
sl@0
    39
// - Open an unshareable session with the server and verify that:
sl@0
    40
// - all arguments are passed to the server and back correctly.
sl@0
    41
// - server can reads and write to/from the client and return the 
sl@0
    42
// appropriate errors when bad descriptors are passed in.
sl@0
    43
// - the session handle is local (thread owned)
sl@0
    44
// - Open an automatically shared session using ShareAuto and test it can be 
sl@0
    45
// shared by threads in the same process.
sl@0
    46
// - Send dummy messages that the server completes immediately and display how 
sl@0
    47
// many are completed per second.
sl@0
    48
// - Verify that stopping the server completes existing pending requests with 
sl@0
    49
// KErrServerTerminated.
sl@0
    50
// - Verify that the kernel does not crash by completing a message with an invalid 
sl@0
    51
// handle and verify the client is panicked with EBadMessageHandle.
sl@0
    52
// Platforms/Drives/Compatibility:
sl@0
    53
// All.
sl@0
    54
// Assumptions/Requirement/Pre-requisites:
sl@0
    55
// Failures and causes:
sl@0
    56
// Base Port information:
sl@0
    57
// This test does not help to validate an EKA2 port.
sl@0
    58
// 
sl@0
    59
//
sl@0
    60
sl@0
    61
#include <e32base.h>
sl@0
    62
#include <e32base_private.h>
sl@0
    63
#define __E32TEST_EXTENSION__
sl@0
    64
#include <e32test.h>
sl@0
    65
#include <e32svr.h>
sl@0
    66
sl@0
    67
#include "../mmu/mmudetect.h"
sl@0
    68
sl@0
    69
const TInt KHeapSize=0x2000;
sl@0
    70
const TInt KMajorVersionNumber=1;
sl@0
    71
const TInt KMinorVersionNumber=0;
sl@0
    72
const TInt KBuildVersionNumber=1;
sl@0
    73
sl@0
    74
_LIT(KServerName,"Display");
sl@0
    75
sl@0
    76
TInt SessionCreateLResult=0;
sl@0
    77
TInt SessionCostructCount=0;
sl@0
    78
TInt SessionDestructCount=0;
sl@0
    79
sl@0
    80
class CMySession : public CSession2
sl@0
    81
	{
sl@0
    82
public:
sl@0
    83
	CMySession();
sl@0
    84
	~CMySession();
sl@0
    85
	void DisplayName(const RMessage2& aM);
sl@0
    86
	virtual void ServiceL(const RMessage2& aMessage);
sl@0
    87
	virtual void CreateL();
sl@0
    88
	TInt Hold(const RMessage2& aM);
sl@0
    89
	TInt Release(const RMessage2& aM);
sl@0
    90
public:
sl@0
    91
	RPointerArray<TInt> iAsyncMsgArray;	// 'pointers' are actually message handles
sl@0
    92
	TInt iCompleteIndex;
sl@0
    93
	};
sl@0
    94
sl@0
    95
TInt AsyncMsgOrder(const TInt& aL, const TInt& aR)
sl@0
    96
	{
sl@0
    97
	TInt lh = (TInt)&aL;
sl@0
    98
	TInt rh = (TInt)&aR;
sl@0
    99
	RMessage2 l(*(const RMessagePtr2*)&lh);
sl@0
   100
	RMessage2 r(*(const RMessagePtr2*)&rh);
sl@0
   101
	return l.Int0() - r.Int0();
sl@0
   102
	}
sl@0
   103
sl@0
   104
TInt GetClientName(const RMessagePtr2& aM, TFullName& aN)
sl@0
   105
	{
sl@0
   106
	RThread t;
sl@0
   107
	TInt r = aM.Client(t);
sl@0
   108
	if (r==KErrNone)
sl@0
   109
		{
sl@0
   110
		aN = t.FullName();
sl@0
   111
		t.Close();
sl@0
   112
		}
sl@0
   113
	return r;
sl@0
   114
	}
sl@0
   115
sl@0
   116
class CMyServer : public CServer2
sl@0
   117
	{
sl@0
   118
public:
sl@0
   119
	enum {EDisplay,ERead,EWrite,ETest,EStop,EHold,ERelease,EGetCompleteIndex};
sl@0
   120
public:
sl@0
   121
	CMyServer(TInt aPriority);
sl@0
   122
	static CMyServer* New(TInt aPriority);
sl@0
   123
	virtual CSession2* NewSessionL(const TVersion& aVersion,const RMessage2& aMessage) const;
sl@0
   124
	};
sl@0
   125
sl@0
   126
class CMyActiveScheduler : public CActiveScheduler
sl@0
   127
	{
sl@0
   128
public:
sl@0
   129
	virtual void Error(TInt anError) const;	 //Overloading pure virtual function
sl@0
   130
	};
sl@0
   131
sl@0
   132
class RDisplay : public RSessionBase
sl@0
   133
	{
sl@0
   134
public:
sl@0
   135
	TInt Open();
sl@0
   136
	TInt OpenNoAsync();
sl@0
   137
	TInt OpenDynamic();
sl@0
   138
	TInt OpenUS();
sl@0
   139
	TInt OpenS();
sl@0
   140
	TInt OpenGS();
sl@0
   141
	TInt Display(const TDesC& aMessage);
sl@0
   142
	TInt Read();
sl@0
   143
	TInt Write();
sl@0
   144
	TInt Stop();
sl@0
   145
	TInt Test();
sl@0
   146
	TInt Echo(TInt aWhat, TInt a0, TInt a1, TInt a2, TInt a3);
sl@0
   147
	TVersion Version();
sl@0
   148
	TInt Hold(TInt aOrder=0, TInt aArg=0);
sl@0
   149
	void Hold(TRequestStatus& aStatus, TInt aOrder=0, TInt aArg=0);
sl@0
   150
	TInt Release(TInt aCount=KMaxTInt);
sl@0
   151
	TInt CompleteIndex();
sl@0
   152
	};
sl@0
   153
sl@0
   154
LOCAL_D RTest test(_L("T_SVR"));
sl@0
   155
LOCAL_D RTest testSvr(_L("T_SVR Server"));
sl@0
   156
LOCAL_D RTest testSpeedy(_L("T_SVR Speedy"));
sl@0
   157
LOCAL_D RSemaphore client;
sl@0
   158
LOCAL_D TInt speedCount;
sl@0
   159
sl@0
   160
CMySession::CMySession()
sl@0
   161
//
sl@0
   162
// Constructor
sl@0
   163
//
sl@0
   164
	{
sl@0
   165
	++SessionCostructCount;
sl@0
   166
	}
sl@0
   167
sl@0
   168
CMySession::~CMySession()
sl@0
   169
	{
sl@0
   170
	iAsyncMsgArray.Close();
sl@0
   171
	++SessionDestructCount;
sl@0
   172
	}
sl@0
   173
sl@0
   174
void CMySession::CreateL()
sl@0
   175
	{
sl@0
   176
	User::LeaveIfError(SessionCreateLResult);
sl@0
   177
	}
sl@0
   178
sl@0
   179
void CMySession::DisplayName(const RMessage2& aM)
sl@0
   180
//
sl@0
   181
// Display the client's name.
sl@0
   182
//
sl@0
   183
	{
sl@0
   184
sl@0
   185
	TFullName fn;
sl@0
   186
	TInt r = GetClientName(aM, fn);
sl@0
   187
	testSvr(r==KErrNone);
sl@0
   188
	TBuf<256> text;
sl@0
   189
	r=aM.Read(0,text);
sl@0
   190
	testSvr(r==KErrNone);
sl@0
   191
	testSvr.Printf(_L("Session %08x %S\n%S\n"), this, &fn, &text);
sl@0
   192
	}
sl@0
   193
sl@0
   194
CMyServer* CMyServer::New(TInt aPriority)
sl@0
   195
//
sl@0
   196
// Create a new CMyServer.
sl@0
   197
//
sl@0
   198
	{
sl@0
   199
	
sl@0
   200
	return new CMyServer(aPriority);
sl@0
   201
	}
sl@0
   202
sl@0
   203
CMyServer::CMyServer(TInt aPriority)
sl@0
   204
//
sl@0
   205
// Constructor.
sl@0
   206
//
sl@0
   207
	: CServer2(aPriority, ESharableSessions)
sl@0
   208
	{}
sl@0
   209
sl@0
   210
CSession2* CMyServer::NewSessionL(const TVersion& aVersion, const RMessage2&) const
sl@0
   211
//
sl@0
   212
// Create a new client for this server.
sl@0
   213
//
sl@0
   214
	{
sl@0
   215
sl@0
   216
	TVersion v(KMajorVersionNumber,KMinorVersionNumber,KBuildVersionNumber);
sl@0
   217
	if (!User::QueryVersionSupported(v,aVersion))
sl@0
   218
		User::Leave(KErrNotSupported);
sl@0
   219
	return new(ELeave) CMySession;
sl@0
   220
	}
sl@0
   221
sl@0
   222
void CMySession::ServiceL(const RMessage2& aMessage)
sl@0
   223
//
sl@0
   224
// Handle messages for this server.
sl@0
   225
//
sl@0
   226
	{
sl@0
   227
sl@0
   228
	TInt f = aMessage.Function();
sl@0
   229
	if (f & 0x40000000)
sl@0
   230
		{
sl@0
   231
		TInt what = f & 0x3fffffff;
sl@0
   232
		TInt a0 = aMessage.Int0();
sl@0
   233
		TInt a1 = aMessage.Int1();
sl@0
   234
		TInt a2 = aMessage.Int2();
sl@0
   235
		TInt a3 = aMessage.Int3();
sl@0
   236
		switch (what)
sl@0
   237
			{
sl@0
   238
			case 0:
sl@0
   239
				aMessage.Complete(a0);
sl@0
   240
				return;
sl@0
   241
			case 1:
sl@0
   242
				aMessage.Complete(a1);
sl@0
   243
				return;
sl@0
   244
			case 2:
sl@0
   245
				aMessage.Complete(a2);
sl@0
   246
				return;
sl@0
   247
			case 3:
sl@0
   248
				aMessage.Complete(a3);
sl@0
   249
				return;
sl@0
   250
			case 4:
sl@0
   251
				aMessage.Complete(a0+a1+a2+a3);
sl@0
   252
				return;
sl@0
   253
			case 5:
sl@0
   254
				aMessage.Complete(a0*a0+a1*a1+a2*a2+a3*a3);
sl@0
   255
				return;
sl@0
   256
			default:
sl@0
   257
				break;
sl@0
   258
			}
sl@0
   259
		}
sl@0
   260
sl@0
   261
	TInt r=KErrNone;
sl@0
   262
	TBuf<0x100> b;
sl@0
   263
	switch (f)
sl@0
   264
		{
sl@0
   265
	case CMyServer::EDisplay:
sl@0
   266
		DisplayName(aMessage);
sl@0
   267
		break;
sl@0
   268
	case CMyServer::ERead:
sl@0
   269
		testSvr.Printf(_L("read message received\n"));
sl@0
   270
		r=aMessage.Read(0,b);
sl@0
   271
		if (r==KErrNone && b!=_L("Testing read"))
sl@0
   272
			r=KErrGeneral;
sl@0
   273
		if (r==KErrNone)
sl@0
   274
			{
sl@0
   275
            r=aMessage.Read(0,b,-1);
sl@0
   276
			if (r==KErrNone)
sl@0
   277
				r=KErrGeneral;
sl@0
   278
			if (r==KErrArgument)
sl@0
   279
				r=KErrNone;
sl@0
   280
			}
sl@0
   281
		if (r==KErrNone && HaveVirtMem())
sl@0
   282
			{
sl@0
   283
			r=aMessage.Read(1,b);
sl@0
   284
			if (r==KErrNone)
sl@0
   285
				r=KErrGeneral;
sl@0
   286
			if (r==KErrBadDescriptor)
sl@0
   287
				r=KErrNone;
sl@0
   288
			}
sl@0
   289
		break;
sl@0
   290
	case CMyServer::EWrite:
sl@0
   291
		testSvr.Printf(_L("write message received\n"));
sl@0
   292
		r=aMessage.Write(0,_L("It worked!"));
sl@0
   293
		RDebug::Print(_L("Write returns %d"),r);
sl@0
   294
		if (r==KErrNone)
sl@0
   295
			{
sl@0
   296
			r=aMessage.Write(0,b,-1);
sl@0
   297
			if (r==KErrNone)
sl@0
   298
				r=KErrGeneral;
sl@0
   299
			if (r==KErrArgument)
sl@0
   300
				r=KErrNone;
sl@0
   301
			}
sl@0
   302
		if (r==KErrNone)
sl@0
   303
			{
sl@0
   304
			r=aMessage.Write(1,b);
sl@0
   305
			if (r==KErrNone)
sl@0
   306
				r=KErrGeneral;
sl@0
   307
			if (r==KErrBadDescriptor)
sl@0
   308
				r=KErrNone;
sl@0
   309
			}
sl@0
   310
		if (r==KErrNone && HaveVirtMem())
sl@0
   311
			{
sl@0
   312
			r=aMessage.Write(2,b);
sl@0
   313
			if (r==KErrNone)
sl@0
   314
				r=KErrGeneral;
sl@0
   315
			if (r==KErrBadDescriptor)
sl@0
   316
				r=KErrNone;
sl@0
   317
			}
sl@0
   318
		break;
sl@0
   319
	case CMyServer::ETest:
sl@0
   320
		break;
sl@0
   321
	case CMyServer::EStop:
sl@0
   322
		testSvr.Printf(_L("stop message received\n"));
sl@0
   323
		CActiveScheduler::Stop();
sl@0
   324
		break;
sl@0
   325
	case CMyServer::EHold:
sl@0
   326
		{
sl@0
   327
		r = Hold(aMessage);
sl@0
   328
		if (r==KErrNone)
sl@0
   329
			return;
sl@0
   330
		break;
sl@0
   331
		}
sl@0
   332
	case CMyServer::ERelease:
sl@0
   333
		{
sl@0
   334
		r = Release(aMessage);
sl@0
   335
		break;
sl@0
   336
		}
sl@0
   337
	case CMyServer::EGetCompleteIndex:
sl@0
   338
		{
sl@0
   339
		r = iCompleteIndex;
sl@0
   340
		break;
sl@0
   341
		}
sl@0
   342
	default:
sl@0
   343
		r=KErrNotSupported;
sl@0
   344
		}
sl@0
   345
	aMessage.Complete(r);
sl@0
   346
	}
sl@0
   347
sl@0
   348
TInt CMySession::Hold(const RMessage2& a)
sl@0
   349
	{
sl@0
   350
	TInt ord = a.Int0();
sl@0
   351
	TInt arg = a.Int1();
sl@0
   352
	TFullName fn;
sl@0
   353
	TInt r = GetClientName(a, fn);
sl@0
   354
	testSvr(r==KErrNone);
sl@0
   355
    testSvr.Printf(_L("Hold message from %S ord %08x arg %08x\n"), &fn, ord, arg);
sl@0
   356
	r = iAsyncMsgArray.InsertInOrder((const TInt*)a.Handle(), &AsyncMsgOrder);
sl@0
   357
	return r;
sl@0
   358
	}
sl@0
   359
sl@0
   360
TInt CMySession::Release(const RMessage2& a)
sl@0
   361
	{
sl@0
   362
	TInt req_count = a.Int0();
sl@0
   363
	TInt avail = iAsyncMsgArray.Count();
sl@0
   364
	TInt count = Min(req_count, avail);
sl@0
   365
	TFullName fn;
sl@0
   366
	TInt r = GetClientName(a, fn);
sl@0
   367
	testSvr(r==KErrNone);
sl@0
   368
	testSvr.Printf(_L("Release message from %S req_count=%d count=%d\n"), &fn, req_count, count);
sl@0
   369
	while (count--)
sl@0
   370
		{
sl@0
   371
		TInt mp = (TInt)iAsyncMsgArray[0];
sl@0
   372
		iAsyncMsgArray.Remove(0);
sl@0
   373
		RMessage2 m(*(const RMessagePtr2*)&mp);
sl@0
   374
		TInt arg = m.Int1();
sl@0
   375
		TInt code = arg ? arg ^ iCompleteIndex : 0;
sl@0
   376
		r = GetClientName(m, fn);
sl@0
   377
		testSvr(r==KErrNone);
sl@0
   378
		testSvr.Printf(_L("Releasing %S arg=%08x index=%08x code=%08x\n"), &fn, arg, iCompleteIndex, code);
sl@0
   379
		++iCompleteIndex;
sl@0
   380
		m.Complete(code);
sl@0
   381
		}
sl@0
   382
	return KErrNone;
sl@0
   383
	}
sl@0
   384
sl@0
   385
void CMyActiveScheduler::Error(TInt anError) const
sl@0
   386
//
sl@0
   387
// Called if any Run() method leaves.
sl@0
   388
//
sl@0
   389
	{
sl@0
   390
sl@0
   391
	testSvr.Panic(anError,_L("CMyActiveScheduler::Error"));
sl@0
   392
	}
sl@0
   393
sl@0
   394
TInt RDisplay::Open()
sl@0
   395
	{
sl@0
   396
	TInt r=CreateSession(KServerName,Version(),8);	// use fixed pool of 8 slots
sl@0
   397
	if (r==KErrNone)
sl@0
   398
		r=ShareAuto();
sl@0
   399
	return r;
sl@0
   400
	}
sl@0
   401
sl@0
   402
TInt RDisplay::OpenUS()
sl@0
   403
	{
sl@0
   404
	return CreateSession(KServerName,Version(),8,EIpcSession_Unsharable);	// use fixed pool of 8 slots
sl@0
   405
	}
sl@0
   406
sl@0
   407
TInt RDisplay::OpenS()
sl@0
   408
	{
sl@0
   409
	return CreateSession(KServerName,Version(),8,EIpcSession_Sharable);	// use fixed pool of 8 slots
sl@0
   410
	}
sl@0
   411
sl@0
   412
TInt RDisplay::OpenGS()
sl@0
   413
	{
sl@0
   414
	return CreateSession(KServerName,Version(),8,EIpcSession_GlobalSharable);	// use fixed pool of 8 slots
sl@0
   415
	}
sl@0
   416
sl@0
   417
TInt RDisplay::OpenNoAsync()
sl@0
   418
	{
sl@0
   419
sl@0
   420
	TInt r=CreateSession(KServerName,Version(),0);	// no asynchronous messages allowed
sl@0
   421
	if (r==KErrNone)
sl@0
   422
		r=ShareAuto();
sl@0
   423
	return r;
sl@0
   424
	}
sl@0
   425
sl@0
   426
TInt RDisplay::OpenDynamic()
sl@0
   427
	{
sl@0
   428
	TInt r=CreateSession(KServerName,Version(),-1);	// use global dynamic message pool
sl@0
   429
	if (r==KErrNone)
sl@0
   430
		r=ShareAuto();
sl@0
   431
	return r;
sl@0
   432
	}
sl@0
   433
sl@0
   434
TInt RDisplay::Display(const TDesC& aMessage)
sl@0
   435
//
sl@0
   436
// Display a message.
sl@0
   437
//
sl@0
   438
	{
sl@0
   439
sl@0
   440
	TBuf<0x100> b(aMessage);
sl@0
   441
	return SendReceive(CMyServer::EDisplay, TIpcArgs(&b));
sl@0
   442
	}
sl@0
   443
sl@0
   444
TInt RDisplay::Read()
sl@0
   445
//
sl@0
   446
// Get session to test CSession2::ReadL.
sl@0
   447
//
sl@0
   448
	{
sl@0
   449
sl@0
   450
	TBuf<0x10> b(_L("Testing read"));
sl@0
   451
	TBuf<0x10>* bad = (TBuf<0x10> *)(0x30000000);
sl@0
   452
sl@0
   453
	return SendReceive(CMyServer::ERead, TIpcArgs(&b, bad));
sl@0
   454
	}
sl@0
   455
sl@0
   456
TInt RDisplay::Write()
sl@0
   457
//
sl@0
   458
// Get session to test CSession2::WriteL.
sl@0
   459
//
sl@0
   460
	{
sl@0
   461
sl@0
   462
	TBuf<0x10> b;
sl@0
   463
    TBufC<0x10> c; // Bad descriptor - read only
sl@0
   464
	TBuf<0x10>* bad = (TBuf<0x10> *)(0x30000000);
sl@0
   465
	TInt r=SendReceive(CMyServer::EWrite, TIpcArgs(&b, &c, bad));
sl@0
   466
	if (r==KErrNone && b!=_L("It worked!"))
sl@0
   467
		r=KErrGeneral;
sl@0
   468
	return r;
sl@0
   469
	}
sl@0
   470
sl@0
   471
TInt RDisplay::Test()
sl@0
   472
//
sl@0
   473
// Send a message and wait for completion.
sl@0
   474
//
sl@0
   475
	{
sl@0
   476
sl@0
   477
	return SendReceive(CMyServer::ETest, TIpcArgs());
sl@0
   478
	}
sl@0
   479
sl@0
   480
TInt RDisplay::Stop()
sl@0
   481
//
sl@0
   482
// Stop the server.
sl@0
   483
//
sl@0
   484
	{
sl@0
   485
sl@0
   486
	return SendReceive(CMyServer::EStop, TIpcArgs());
sl@0
   487
	}
sl@0
   488
sl@0
   489
TVersion RDisplay::Version()
sl@0
   490
//
sl@0
   491
// Return the current version.
sl@0
   492
//
sl@0
   493
	{
sl@0
   494
sl@0
   495
	TVersion v(KMajorVersionNumber,KMinorVersionNumber,KBuildVersionNumber);
sl@0
   496
	return v;
sl@0
   497
	}
sl@0
   498
sl@0
   499
TInt RDisplay::Echo(TInt aWhat, TInt a0, TInt a1, TInt a2, TInt a3)
sl@0
   500
	{
sl@0
   501
	return SendReceive(0x40000000|aWhat, TIpcArgs(a0,a1,a2,a3));
sl@0
   502
	}
sl@0
   503
sl@0
   504
TInt RDisplay::Hold(TInt aOrder, TInt aArg)
sl@0
   505
	{
sl@0
   506
sl@0
   507
	return Send(CMyServer::EHold, TIpcArgs(aOrder, aArg));
sl@0
   508
	}
sl@0
   509
sl@0
   510
void RDisplay::Hold(TRequestStatus& aStatus, TInt aOrder, TInt aArg)
sl@0
   511
	{
sl@0
   512
sl@0
   513
	SendReceive(CMyServer::EHold, TIpcArgs(aOrder, aArg), aStatus);
sl@0
   514
	}
sl@0
   515
sl@0
   516
TInt RDisplay::Release(TInt aCount)
sl@0
   517
	{
sl@0
   518
sl@0
   519
	return SendReceive(CMyServer::ERelease, TIpcArgs(aCount));
sl@0
   520
	}
sl@0
   521
sl@0
   522
TInt RDisplay::CompleteIndex()
sl@0
   523
	{
sl@0
   524
	return SendReceive(CMyServer::EGetCompleteIndex, TIpcArgs());
sl@0
   525
	}
sl@0
   526
sl@0
   527
TInt serverThreadEntryPoint(TAny*)
sl@0
   528
//
sl@0
   529
// The entry point for the producer thread.
sl@0
   530
//
sl@0
   531
	{
sl@0
   532
sl@0
   533
	testSvr.Title();
sl@0
   534
	testSvr.Start(_L("Create CActiveScheduler"));
sl@0
   535
	CMyActiveScheduler* pR=new CMyActiveScheduler;
sl@0
   536
	testSvr(pR!=NULL);
sl@0
   537
	CActiveScheduler::Install(pR);
sl@0
   538
//
sl@0
   539
	testSvr.Next(_L("Create CMyServer"));
sl@0
   540
	CMyServer* pS=CMyServer::New(0);
sl@0
   541
	testSvr(pS!=NULL);
sl@0
   542
//
sl@0
   543
	testSvr.Next(_L("Start CMyServer"));
sl@0
   544
	TInt r=pS->Start(KServerName);
sl@0
   545
	testSvr(r==KErrNone);
sl@0
   546
//
sl@0
   547
	testSvr.Next(_L("Signal to client that we have started"));
sl@0
   548
	client.Signal();
sl@0
   549
//
sl@0
   550
	testSvr.Next(_L("Start CActiveScheduler"));
sl@0
   551
	CActiveScheduler::Start();
sl@0
   552
//
sl@0
   553
	testSvr.Next(_L("Exit server"));
sl@0
   554
	delete pS;
sl@0
   555
	testSvr.Close();
sl@0
   556
	return(KErrNone);
sl@0
   557
	}
sl@0
   558
sl@0
   559
TInt speedyThreadEntryPoint(TAny* aDisplay)
sl@0
   560
//
sl@0
   561
// The entry point for the speed test thread.
sl@0
   562
//
sl@0
   563
	{
sl@0
   564
sl@0
   565
	RDisplay& t=*(RDisplay*)aDisplay;
sl@0
   566
	TInt r=t.Test();
sl@0
   567
	testSpeedy(r==KErrNone);
sl@0
   568
	speedCount=0;
sl@0
   569
	client.Signal();
sl@0
   570
	while ((r=t.Test())==KErrNone)
sl@0
   571
		speedCount++;
sl@0
   572
	testSpeedy(r==KErrServerTerminated);
sl@0
   573
	return(KErrNone);
sl@0
   574
	}
sl@0
   575
sl@0
   576
TInt RunPanicThread(RThread& aThread)
sl@0
   577
	{
sl@0
   578
	TRequestStatus s;
sl@0
   579
	aThread.Logon(s);
sl@0
   580
	TBool jit = User::JustInTime();
sl@0
   581
	User::SetJustInTime(EFalse);
sl@0
   582
	aThread.Resume();
sl@0
   583
	User::WaitForRequest(s);
sl@0
   584
	User::SetJustInTime(jit);
sl@0
   585
	return s.Int();
sl@0
   586
	}
sl@0
   587
sl@0
   588
TInt RogueThread1(TAny*)
sl@0
   589
	{
sl@0
   590
	// try to kill the kernel
sl@0
   591
	RMutex mutex;
sl@0
   592
	TPtrC* p=(TPtrC*)0x30000000;
sl@0
   593
	mutex.CreateGlobal(*p,EOwnerProcess);	// this should panic the thread
sl@0
   594
	return KErrNone;
sl@0
   595
	}
sl@0
   596
sl@0
   597
class RMessageT : public RMessage2
sl@0
   598
	{
sl@0
   599
public:
sl@0
   600
	RMessageT(TLinAddr anAddr) { iFunction=0; iHandle=(TInt)anAddr; }
sl@0
   601
	};
sl@0
   602
sl@0
   603
TInt RogueThread2(TAny*)
sl@0
   604
	{
sl@0
   605
	// try to kill the kernel
sl@0
   606
	RMessageT m(0x30000000);
sl@0
   607
	m.Complete(KErrNone);					// this should panic the thread
sl@0
   608
	return KErrNone;
sl@0
   609
	}
sl@0
   610
sl@0
   611
TInt RogueThread3(TAny*)
sl@0
   612
	{
sl@0
   613
	// try to kill the kernel
sl@0
   614
	RMessageT m(0x80000000);
sl@0
   615
	m.Complete(KErrNone);					// this should panic the thread
sl@0
   616
	return KErrNone;
sl@0
   617
	}
sl@0
   618
sl@0
   619
TInt RogueThread4(TAny*)
sl@0
   620
	{
sl@0
   621
	// try to kill the kernel
sl@0
   622
	RMessageT m(0x800fff00);				// this should be off the end of the kernel heap
sl@0
   623
	m.Complete(KErrNone);					// this should panic the thread
sl@0
   624
	return KErrNone;
sl@0
   625
	}
sl@0
   626
sl@0
   627
void DisplayThreadExitInfo(const RThread& aThread)
sl@0
   628
	{
sl@0
   629
	TFullName fn=aThread.FullName();
sl@0
   630
	TExitType exitType=aThread.ExitType();
sl@0
   631
	TInt exitReason=aThread.ExitReason();
sl@0
   632
	TBuf<32> exitCat=aThread.ExitCategory();
sl@0
   633
	test.Printf(_L("Thread %S exited %d,%d,%S\n"),&fn,exitType,exitReason,&exitCat);
sl@0
   634
	}
sl@0
   635
sl@0
   636
void RogueThreadTest()
sl@0
   637
	{
sl@0
   638
	RThread thread;
sl@0
   639
	TInt r;
sl@0
   640
	if (HaveVirtMem())
sl@0
   641
		{
sl@0
   642
		test.Next(_L("Rogue thread test 1"));
sl@0
   643
		r=thread.Create(_L("Rogue1"),RogueThread1,KDefaultStackSize,KHeapSize,KHeapSize,NULL);
sl@0
   644
		test_KErrNone(r);
sl@0
   645
		RunPanicThread(thread);	// wait for rogue thread to die
sl@0
   646
		DisplayThreadExitInfo(thread);
sl@0
   647
		test(thread.ExitType()==EExitPanic);
sl@0
   648
		test(thread.ExitReason()==ECausedException);
sl@0
   649
		thread.Close();
sl@0
   650
		}
sl@0
   651
sl@0
   652
	test.Next(_L("Rogue thread test 2"));
sl@0
   653
	r=thread.Create(_L("Rogue2"),RogueThread2,KDefaultStackSize,KHeapSize,KHeapSize,NULL);
sl@0
   654
	test_KErrNone(r);
sl@0
   655
	RunPanicThread(thread);	// wait for rogue thread to die
sl@0
   656
	DisplayThreadExitInfo(thread);
sl@0
   657
	test(thread.ExitType()==EExitPanic);
sl@0
   658
	test(thread.ExitReason()==EBadMessageHandle);
sl@0
   659
	thread.Close();
sl@0
   660
sl@0
   661
	test.Next(_L("Rogue thread test 3"));
sl@0
   662
	r=thread.Create(_L("Rogue3"),RogueThread3,KDefaultStackSize,KHeapSize,KHeapSize,NULL);
sl@0
   663
	test_KErrNone(r);
sl@0
   664
	RunPanicThread(thread);	// wait for rogue thread to die
sl@0
   665
	DisplayThreadExitInfo(thread);
sl@0
   666
	test(thread.ExitType()==EExitPanic);
sl@0
   667
	test(thread.ExitReason()==EBadMessageHandle);
sl@0
   668
	thread.Close();
sl@0
   669
sl@0
   670
	test.Next(_L("Rogue thread test 4"));
sl@0
   671
	r=thread.Create(_L("Rogue4"),RogueThread4,KDefaultStackSize,KHeapSize,KHeapSize,NULL);
sl@0
   672
	test_KErrNone(r);
sl@0
   673
	RunPanicThread(thread);	// wait for rogue thread to die
sl@0
   674
	DisplayThreadExitInfo(thread);
sl@0
   675
	test(thread.ExitType()==EExitPanic);
sl@0
   676
	test(thread.ExitReason()==EBadMessageHandle);
sl@0
   677
	thread.Close();
sl@0
   678
	}
sl@0
   679
sl@0
   680
TInt SecondClient(TAny* aSession)
sl@0
   681
	{
sl@0
   682
	RDisplay d;
sl@0
   683
	d.SetHandle(TInt(aSession));
sl@0
   684
	TInt r=d.Display(_L("Second client"));
sl@0
   685
	if (r!=KErrNone)
sl@0
   686
		return r;
sl@0
   687
	r = d.Echo(0,19,31,83,487);
sl@0
   688
	if (r!=19)
sl@0
   689
		return -999990;
sl@0
   690
	r = d.Echo(1,19,31,83,487);
sl@0
   691
	if (r!=31)
sl@0
   692
		return -999991;
sl@0
   693
	r = d.Echo(2,19,31,83,487);
sl@0
   694
	if (r!=83)
sl@0
   695
		return -999992;
sl@0
   696
	r = d.Echo(3,19,31,83,487);
sl@0
   697
	if (r!=487)
sl@0
   698
		return -999993;
sl@0
   699
	r = d.Echo(4,19,31,83,487);
sl@0
   700
	if (r!=620)
sl@0
   701
		return -999994;
sl@0
   702
	r = d.Echo(5,19,31,83,487);
sl@0
   703
	if (r!=245380)
sl@0
   704
		return -999995;
sl@0
   705
	r=d.Read();
sl@0
   706
	if (r!=KErrNone)
sl@0
   707
		return r;
sl@0
   708
	r=d.Write();
sl@0
   709
	if (r!=KErrNone)
sl@0
   710
		return r;
sl@0
   711
	d.Release();
sl@0
   712
	return KErrNone;
sl@0
   713
	}
sl@0
   714
sl@0
   715
TInt ThirdClient(TAny* aSession)
sl@0
   716
	{
sl@0
   717
	RDisplay d;
sl@0
   718
	d.SetHandle(TInt(aSession));
sl@0
   719
	TInt r=d.Display(_L("Third client"));
sl@0
   720
	if (r!=KErrNone)
sl@0
   721
		return r;
sl@0
   722
	r=d.Hold();
sl@0
   723
	if (r!=KErrNone)
sl@0
   724
		return r;
sl@0
   725
	r=d.Read();
sl@0
   726
	if (r!=KErrNone)
sl@0
   727
		return r;
sl@0
   728
	r=d.Write();
sl@0
   729
	if (r!=KErrNone)
sl@0
   730
		return r;
sl@0
   731
	return KErrNone;
sl@0
   732
	}
sl@0
   733
sl@0
   734
void TestSecondClient(RSessionBase& aSession)
sl@0
   735
	{
sl@0
   736
	RThread t;
sl@0
   737
	TInt r=t.Create(_L("SecondClient"),SecondClient,0x1000,NULL,(TAny*)aSession.Handle());
sl@0
   738
	test_KErrNone(r);
sl@0
   739
	TRequestStatus s;
sl@0
   740
	t.Logon(s);
sl@0
   741
	t.Resume();
sl@0
   742
	User::WaitForRequest(s);
sl@0
   743
	test_KErrNone(s.Int());
sl@0
   744
	t.Close();
sl@0
   745
	}
sl@0
   746
sl@0
   747
void TestThirdClient(RSessionBase& aSession)
sl@0
   748
	{
sl@0
   749
	RThread t;
sl@0
   750
	TInt r=t.Create(_L("ThirdClient"),ThirdClient,0x1000,NULL,(TAny*)aSession.Handle());
sl@0
   751
	test_KErrNone(r);
sl@0
   752
	TRequestStatus s;
sl@0
   753
	t.Logon(s);
sl@0
   754
	t.Resume();
sl@0
   755
	User::WaitForRequest(s);
sl@0
   756
	test_KErrNone(s.Int());
sl@0
   757
	t.Close();
sl@0
   758
	}
sl@0
   759
sl@0
   760
TInt FourthClient(TAny* aSession)
sl@0
   761
	{
sl@0
   762
	RDisplay d;
sl@0
   763
	d.SetHandle(TInt(aSession));
sl@0
   764
	TInt r=d.Display(_L("Fourth client"));
sl@0
   765
	if (r!=KErrNone)
sl@0
   766
		return r;
sl@0
   767
	d.Close();
sl@0
   768
	return KErrNone;
sl@0
   769
	}
sl@0
   770
sl@0
   771
void TestSessionClose()
sl@0
   772
	{
sl@0
   773
	RDisplay d;
sl@0
   774
	TInt r=d.Open();
sl@0
   775
	test_KErrNone(r);
sl@0
   776
	TRequestStatus msgStat;
sl@0
   777
	d.Hold(msgStat);
sl@0
   778
	test(msgStat==KRequestPending);
sl@0
   779
	RThread t;
sl@0
   780
	r=t.Create(_L("FourthClient"),FourthClient,0x1000,NULL,(TAny*)d.Handle());
sl@0
   781
	test_KErrNone(r);
sl@0
   782
	TRequestStatus s;
sl@0
   783
	t.Logon(s);
sl@0
   784
	t.Resume();
sl@0
   785
	User::WaitForRequest(s);
sl@0
   786
	test_KErrNone(s.Int());
sl@0
   787
	t.Close();
sl@0
   788
	User::After(1000000);
sl@0
   789
	test(msgStat==KRequestPending);
sl@0
   790
	}
sl@0
   791
sl@0
   792
TInt FifthClient(TAny* aDisplay)
sl@0
   793
	{
sl@0
   794
	RDisplay& d=*(RDisplay*)aDisplay;
sl@0
   795
	TInt r=d.Open();
sl@0
   796
	if (r!=KErrNone)
sl@0
   797
		return r;
sl@0
   798
	r=d.Display(_L("Fifth client"));
sl@0
   799
	if (r!=KErrNone)
sl@0
   800
		return r;
sl@0
   801
	return KErrNone;
sl@0
   802
	}
sl@0
   803
sl@0
   804
void TestZeroShares()
sl@0
   805
	{
sl@0
   806
	RDisplay d;
sl@0
   807
	d.SetHandle(0);
sl@0
   808
	RThread t;
sl@0
   809
	TInt r=t.Create(_L("FifthClient"),FifthClient,0x1000,NULL,&d);
sl@0
   810
	test_KErrNone(r);
sl@0
   811
	TRequestStatus s;
sl@0
   812
	t.Logon(s);
sl@0
   813
	t.Resume();
sl@0
   814
	User::WaitForRequest(s);
sl@0
   815
	test_KErrNone(s.Int());
sl@0
   816
	test(d.Handle()!=0);
sl@0
   817
	t.Close();
sl@0
   818
	r=d.Display(_L("Access after last share closed"));
sl@0
   819
	test_KErrNone(r);
sl@0
   820
	d.Close();
sl@0
   821
	}
sl@0
   822
sl@0
   823
TInt AttachClient1(TAny* aSession)
sl@0
   824
	{
sl@0
   825
	RDisplay d;
sl@0
   826
	d.SetHandle(TInt(aSession));
sl@0
   827
	__KHEAP_MARK;
sl@0
   828
	TInt r=d.Display(_L("Attach client 1"));
sl@0
   829
	__KHEAP_MARKEND;	// shouldn't need to allocate memory
sl@0
   830
	return r;
sl@0
   831
	}
sl@0
   832
sl@0
   833
TInt AttachClient2(TAny* aSession)
sl@0
   834
	{
sl@0
   835
	RDisplay d;
sl@0
   836
	d.SetHandle(TInt(aSession));
sl@0
   837
	TInt r=d.Display(_L("Attach client 2"));
sl@0
   838
	if (r!=KErrNone)
sl@0
   839
		return r;
sl@0
   840
	__KHEAP_MARK;
sl@0
   841
	r=d.Display(_L("Attach client 2"));
sl@0
   842
	__KHEAP_MARKEND;	// check no memory was allocated by message send
sl@0
   843
	return r;
sl@0
   844
	}
sl@0
   845
sl@0
   846
void TestAttach(RSessionBase& aSession)
sl@0
   847
	{
sl@0
   848
	test.Next(_L("Test Attach"));
sl@0
   849
	RThread t;
sl@0
   850
	TInt r=t.Create(_L("AttachClient1"),AttachClient1,0x1000,NULL,(TAny*)aSession.Handle());
sl@0
   851
	test_KErrNone(r);
sl@0
   852
	r=RunPanicThread(t);	// wait for thread to die
sl@0
   853
	test_KErrNone(r);
sl@0
   854
	test(t.ExitType()==EExitKill);
sl@0
   855
	test_KErrNone(t.ExitReason());
sl@0
   856
	t.Close();
sl@0
   857
sl@0
   858
	r=t.Create(_L("AttachClient2"),AttachClient2,0x1000,NULL,(TAny*)aSession.Handle());
sl@0
   859
	test_KErrNone(r);
sl@0
   860
	TRequestStatus s;
sl@0
   861
	t.Logon(s);
sl@0
   862
	t.Resume();
sl@0
   863
	User::WaitForRequest(s);
sl@0
   864
	test_KErrNone(s.Int());
sl@0
   865
	test(t.ExitType()==EExitKill);
sl@0
   866
	test_KErrNone(t.ExitReason());
sl@0
   867
	t.Close();
sl@0
   868
	}
sl@0
   869
sl@0
   870
TInt SixthClient(TAny* aDisplay)
sl@0
   871
	{
sl@0
   872
	RDisplay& d=*(RDisplay*)aDisplay;
sl@0
   873
	TInt r=d.Display(_L("Sixth client"));
sl@0
   874
	if (r!=KErrNone)
sl@0
   875
		return r;
sl@0
   876
	TRequestStatus s;
sl@0
   877
	User::WaitForRequest(s);
sl@0
   878
	return KErrNone;
sl@0
   879
	}
sl@0
   880
sl@0
   881
TInt SeventhClient(TAny* aDisplay)
sl@0
   882
	{
sl@0
   883
	RDisplay& d=*(RDisplay*)aDisplay;
sl@0
   884
	TInt r=d.Display(_L("Seventh client"));
sl@0
   885
	if (r!=KErrNone)
sl@0
   886
		return r;
sl@0
   887
	TRequestStatus s;
sl@0
   888
	User::WaitForRequest(s);
sl@0
   889
	return KErrNone;
sl@0
   890
	}
sl@0
   891
sl@0
   892
TInt EighthClient(TAny* aDisplay)
sl@0
   893
	{
sl@0
   894
	RDisplay& d=*(RDisplay*)aDisplay;
sl@0
   895
	TInt r=d.Display(_L("Eighth client"));
sl@0
   896
	if (r!=KErrNone)
sl@0
   897
		return r;
sl@0
   898
	TRequestStatus s;
sl@0
   899
	User::WaitForRequest(s);
sl@0
   900
	return KErrNone;
sl@0
   901
	}
sl@0
   902
sl@0
   903
TInt NinthClient(TAny* aDisplay)
sl@0
   904
	{
sl@0
   905
	RDisplay& d=*(RDisplay*)aDisplay;
sl@0
   906
	TInt r=d.Display(_L("Ninth client"));
sl@0
   907
	if (r!=KErrNone)
sl@0
   908
		return r;
sl@0
   909
	TRequestStatus s;
sl@0
   910
	User::WaitForRequest(s);
sl@0
   911
	return KErrNone;
sl@0
   912
	}
sl@0
   913
sl@0
   914
void TestAsync(RDisplay& aD)
sl@0
   915
	{
sl@0
   916
	TInt ci = aD.CompleteIndex();
sl@0
   917
	TRequestStatus s[128];
sl@0
   918
	TInt i;
sl@0
   919
	TInt r;
sl@0
   920
	for (i=0; i<128; ++i)
sl@0
   921
		{
sl@0
   922
		TInt ord = i ^ 0x55;
sl@0
   923
		TInt arg = i + 1;
sl@0
   924
		aD.Hold(s[i], ord, arg);
sl@0
   925
		if (s[i]==KErrServerBusy)
sl@0
   926
			{
sl@0
   927
			User::WaitForRequest(s[i]);
sl@0
   928
			break;
sl@0
   929
			}
sl@0
   930
		test(s[i]==KRequestPending);
sl@0
   931
		}
sl@0
   932
	r = aD.Release();
sl@0
   933
	test_KErrNone(r);
sl@0
   934
	TInt j;
sl@0
   935
	for (j=0; j<128; ++j)
sl@0
   936
		{
sl@0
   937
		if ( (j^0x55) >= i )
sl@0
   938
			continue;
sl@0
   939
		TInt code = s[j^0x55].Int();
sl@0
   940
		TInt expected = ci ^ ((j^0x55)+1);
sl@0
   941
		if (code != expected)
sl@0
   942
			{
sl@0
   943
			test.Printf(_L("j=%02x i=%02x expected=%08x got=%08x\n"),j,j^0x55,expected,code);
sl@0
   944
			test(0);
sl@0
   945
			}
sl@0
   946
		User::WaitForRequest(s[j^0x55]);
sl@0
   947
		++ci;
sl@0
   948
		}
sl@0
   949
	}
sl@0
   950
sl@0
   951
void TestSession(RDisplay& aSess)
sl@0
   952
	{
sl@0
   953
//
sl@0
   954
	TInt r;
sl@0
   955
	test.Next(_L("Test all args passed"));
sl@0
   956
	test(aSess.Echo(0,3,5,7,11)==3);
sl@0
   957
	test(aSess.Echo(1,3,5,7,11)==5);
sl@0
   958
	test(aSess.Echo(2,3,5,7,11)==7);
sl@0
   959
	test(aSess.Echo(3,3,5,7,11)==11);
sl@0
   960
	test(aSess.Echo(4,3,5,7,11)==26);
sl@0
   961
	test(aSess.Echo(5,3,5,7,11)==204);
sl@0
   962
//
sl@0
   963
	test.Next(_L("Send to server"));
sl@0
   964
	r=aSess.Display(_L("First message"));
sl@0
   965
	test_KErrNone(r);
sl@0
   966
//
sl@0
   967
	test.Next(_L("Read"));
sl@0
   968
	r=aSess.Read();
sl@0
   969
	test_KErrNone(r);
sl@0
   970
//
sl@0
   971
	test.Next(_L("Write"));
sl@0
   972
	r=aSess.Write();
sl@0
   973
	test_KErrNone(r);
sl@0
   974
//
sl@0
   975
	TestThirdClient(aSess);
sl@0
   976
	User::After(1000000);
sl@0
   977
	TestSecondClient(aSess);
sl@0
   978
	User::After(1000000);
sl@0
   979
	TestSessionClose();
sl@0
   980
	User::After(1000000);
sl@0
   981
	TestZeroShares();
sl@0
   982
	User::After(1000000);
sl@0
   983
	TestAttach(aSess);
sl@0
   984
	User::After(1000000);
sl@0
   985
	}
sl@0
   986
sl@0
   987
void TestUnsharableSession(RDisplay& aSess)
sl@0
   988
	{
sl@0
   989
//
sl@0
   990
	TInt r;
sl@0
   991
	test.Next(_L("Test all args passed"));
sl@0
   992
	test(aSess.Echo(0,3,5,7,11)==3);
sl@0
   993
	test(aSess.Echo(1,3,5,7,11)==5);
sl@0
   994
	test(aSess.Echo(2,3,5,7,11)==7);
sl@0
   995
	test(aSess.Echo(3,3,5,7,11)==11);
sl@0
   996
	test(aSess.Echo(4,3,5,7,11)==26);
sl@0
   997
	test(aSess.Echo(5,3,5,7,11)==204);
sl@0
   998
//
sl@0
   999
	test.Next(_L("Send to server"));
sl@0
  1000
	r=aSess.Display(_L("First message"));
sl@0
  1001
	test_KErrNone(r);
sl@0
  1002
//
sl@0
  1003
	test.Next(_L("Read"));
sl@0
  1004
	r=aSess.Read();
sl@0
  1005
	test_KErrNone(r);
sl@0
  1006
//
sl@0
  1007
	test.Next(_L("Write"));
sl@0
  1008
	r=aSess.Write();
sl@0
  1009
	test_KErrNone(r);
sl@0
  1010
//
sl@0
  1011
	TInt h = aSess.Handle();
sl@0
  1012
	test.Printf(_L("HANDLE %08x\n"), h);
sl@0
  1013
	test((h & KHandleFlagLocal)!=0);
sl@0
  1014
	}
sl@0
  1015
sl@0
  1016
void TestSessionCreateLLeaving()
sl@0
  1017
	{
sl@0
  1018
	SessionCreateLResult=KErrGeneral;
sl@0
  1019
sl@0
  1020
	TInt c=SessionCostructCount;
sl@0
  1021
	TInt d=SessionDestructCount;
sl@0
  1022
sl@0
  1023
	RDisplay t;
sl@0
  1024
	TInt r = t.Open();
sl@0
  1025
	test(r==SessionCreateLResult);
sl@0
  1026
sl@0
  1027
	test(SessionCostructCount==c+1);
sl@0
  1028
	test(SessionDestructCount==d+1);
sl@0
  1029
sl@0
  1030
	SessionCreateLResult=KErrNone;
sl@0
  1031
	}
sl@0
  1032
sl@0
  1033
GLDEF_C TInt E32Main()
sl@0
  1034
//
sl@0
  1035
// Test timers.
sl@0
  1036
//
sl@0
  1037
    {
sl@0
  1038
sl@0
  1039
	test.Title();
sl@0
  1040
	test.Start(_L("Creating client semaphore"));
sl@0
  1041
	TInt r=client.CreateLocal(0);
sl@0
  1042
	test_KErrNone(r);
sl@0
  1043
//
sl@0
  1044
	test.Next(_L("Creating server thread"));
sl@0
  1045
	RThread server;
sl@0
  1046
	r=server.Create(_L("Server"),serverThreadEntryPoint,KDefaultStackSize,KHeapSize,KHeapSize,NULL);
sl@0
  1047
	test_KErrNone(r);
sl@0
  1048
	server.SetPriority(EPriorityMore);
sl@0
  1049
//
sl@0
  1050
	test.Next(_L("Resume server thread"));
sl@0
  1051
	server.Resume();
sl@0
  1052
	test(ETrue);
sl@0
  1053
//
sl@0
  1054
	test.Next(_L("Wait for server to start"));
sl@0
  1055
	client.Wait();
sl@0
  1056
//
sl@0
  1057
	test.Next(_L("Connect to server"));
sl@0
  1058
	RDisplay t;
sl@0
  1059
	r = t.OpenNoAsync();
sl@0
  1060
	test_KErrNone(r);
sl@0
  1061
	test.Next(_L("Send to server"));
sl@0
  1062
	r=t.Display(_L("AsyncMsg"));
sl@0
  1063
	test_KErrNone(r);
sl@0
  1064
	TRequestStatus s0;
sl@0
  1065
	t.Hold(s0);
sl@0
  1066
	test(s0==KErrServerBusy);
sl@0
  1067
	t.Close();
sl@0
  1068
//
sl@0
  1069
	test.Next(_L("Test Session::CreateL leaving"));
sl@0
  1070
	TestSessionCreateLLeaving();
sl@0
  1071
//
sl@0
  1072
	test.Next(_L("Async fixed pool"));
sl@0
  1073
	r = t.Open();
sl@0
  1074
	test_KErrNone(r);
sl@0
  1075
	TestAsync(t);
sl@0
  1076
	TestAsync(t);
sl@0
  1077
	t.Close();
sl@0
  1078
	test.Next(_L("Async global pool"));
sl@0
  1079
	r = t.OpenDynamic();
sl@0
  1080
	test_KErrNone(r);
sl@0
  1081
	TestAsync(t);
sl@0
  1082
	TestAsync(t);
sl@0
  1083
	t.Close();
sl@0
  1084
//
sl@0
  1085
	r=t.Open();
sl@0
  1086
	test_KErrNone(r);
sl@0
  1087
//
sl@0
  1088
	TestSession(t);
sl@0
  1089
//
sl@0
  1090
	RDisplay tt;
sl@0
  1091
	r = tt.OpenS();
sl@0
  1092
	test.Printf(_L("OpenS -> %d\n"),r);
sl@0
  1093
	test_KErrNone(r);
sl@0
  1094
	TestSession(tt);
sl@0
  1095
	tt.Close();
sl@0
  1096
//
sl@0
  1097
	r = tt.OpenGS();
sl@0
  1098
	test.Printf(_L("OpenGS -> %d\n"),r);
sl@0
  1099
	test(r==KErrPermissionDenied);
sl@0
  1100
	tt.Close();
sl@0
  1101
//
sl@0
  1102
	r = tt.OpenUS();
sl@0
  1103
	test.Printf(_L("OpenUS -> %d\n"),r);
sl@0
  1104
	test_KErrNone(r);
sl@0
  1105
	TestUnsharableSession(tt);
sl@0
  1106
	tt.Close();
sl@0
  1107
//
sl@0
  1108
	test.Next(_L("Starting speedy client"));
sl@0
  1109
	RThread speedy;
sl@0
  1110
	TRequestStatus speedyStat;
sl@0
  1111
	r=speedy.Create(_L("Speedy"),speedyThreadEntryPoint,KDefaultStackSize,KHeapSize,KHeapSize,&t);
sl@0
  1112
	test_KErrNone(r);
sl@0
  1113
	speedy.Logon(speedyStat);
sl@0
  1114
	RThread t1;
sl@0
  1115
	RThread t2;
sl@0
  1116
	RThread t3;
sl@0
  1117
	RThread t4;
sl@0
  1118
	TRequestStatus s1;
sl@0
  1119
	TRequestStatus s2;
sl@0
  1120
	TRequestStatus s3;
sl@0
  1121
	TRequestStatus s4;
sl@0
  1122
	r=t1.Create(_L("SixthClient"),SixthClient,0x1000,NULL,&t);
sl@0
  1123
	test_KErrNone(r);
sl@0
  1124
	t1.Logon(s1);
sl@0
  1125
	r=t2.Create(_L("SeventhClient"),SeventhClient,0x1000,NULL,&t);
sl@0
  1126
	test_KErrNone(r);
sl@0
  1127
	t2.Logon(s2);
sl@0
  1128
	r=t3.Create(_L("EighthClient"),EighthClient,0x1000,NULL,&t);
sl@0
  1129
	test_KErrNone(r);
sl@0
  1130
	t3.Logon(s3);
sl@0
  1131
	r=t4.Create(_L("NinthClient"),NinthClient,0x1000,NULL,&t);
sl@0
  1132
	test_KErrNone(r);
sl@0
  1133
	t4.Logon(s4);
sl@0
  1134
	t1.Resume();
sl@0
  1135
	t2.Resume();
sl@0
  1136
	t3.Resume();
sl@0
  1137
	t4.Resume();
sl@0
  1138
	User::After(1000000);
sl@0
  1139
//
sl@0
  1140
	test.Next(_L("Wait for speedy to start"));
sl@0
  1141
    speedy.SetPriority(EPriorityNormal);
sl@0
  1142
	RThread().SetPriority(EPriorityMuchMore);
sl@0
  1143
	speedy.Resume();
sl@0
  1144
	client.Wait();
sl@0
  1145
//
sl@0
  1146
	test.Printf(_L("Starting speed test...\n"));
sl@0
  1147
    User::After(300000);
sl@0
  1148
    TInt b=speedCount;
sl@0
  1149
    User::After(3000000);
sl@0
  1150
    TInt n=speedCount;
sl@0
  1151
    test.Printf(_L("Count = %d in 1 second\n"),(n-b)/3);
sl@0
  1152
//
sl@0
  1153
	test.Next(_L("Stop server"));
sl@0
  1154
	r=t.Stop();
sl@0
  1155
	test_KErrNone(r);
sl@0
  1156
	User::After(0); // Allow the speed client to die
sl@0
  1157
//
sl@0
  1158
	test.Next(_L("Close extra threads"));
sl@0
  1159
	t1.Kill(0);
sl@0
  1160
	User::WaitForRequest(s1);
sl@0
  1161
	test(t1.ExitType()==EExitKill && s1==KErrNone);
sl@0
  1162
	t2.Kill(0);
sl@0
  1163
	User::WaitForRequest(s2);
sl@0
  1164
	test(t2.ExitType()==EExitKill && s2==KErrNone);
sl@0
  1165
	t3.Kill(0);
sl@0
  1166
	User::WaitForRequest(s3);
sl@0
  1167
	test(t3.ExitType()==EExitKill && s3==KErrNone);
sl@0
  1168
	t4.Kill(0);
sl@0
  1169
	User::WaitForRequest(s4);
sl@0
  1170
	test(t4.ExitType()==EExitKill && s4==KErrNone);
sl@0
  1171
	User::WaitForRequest(speedyStat);
sl@0
  1172
	test(speedy.ExitType()==EExitKill && speedyStat==KErrNone);
sl@0
  1173
//
sl@0
  1174
	test.Next(_L("Close all"));
sl@0
  1175
	t1.Close();
sl@0
  1176
	t2.Close();
sl@0
  1177
	t3.Close();
sl@0
  1178
	t4.Close();
sl@0
  1179
	speedy.Close();
sl@0
  1180
	server.Close();
sl@0
  1181
	client.Close();
sl@0
  1182
//
sl@0
  1183
	test.Next(_L("Close connection"));
sl@0
  1184
	t.Close();
sl@0
  1185
//
sl@0
  1186
	RogueThreadTest();
sl@0
  1187
//
sl@0
  1188
	test.End();
sl@0
  1189
	return(0);
sl@0
  1190
    }
sl@0
  1191