os/kernelhwsrv/kerneltest/e32test/misc/t_svr3.cpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
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\misc\t_svr3.cpp
sl@0
    15
// 
sl@0
    16
//
sl@0
    17
sl@0
    18
#define __E32TEST_EXTENSION__
sl@0
    19
sl@0
    20
#include <e32base.h>
sl@0
    21
#include <e32base_private.h>
sl@0
    22
#include <e32test.h>
sl@0
    23
#include <e32svr.h>
sl@0
    24
#include "u32std.h"
sl@0
    25
#include "../misc/prbs.h"
sl@0
    26
#include "../mmu/freeram.h"
sl@0
    27
sl@0
    28
const TInt KStackSize=0x1000;
sl@0
    29
const TInt KHeapMaxSize=0x100000;
sl@0
    30
const TInt KMajorVersionNumber=1;
sl@0
    31
const TInt KMinorVersionNumber=0;
sl@0
    32
const TInt KBuildVersionNumber=1;
sl@0
    33
const TInt KNumMessageSlots=20;
sl@0
    34
sl@0
    35
_LIT(KServerName,"StressSvr");
sl@0
    36
sl@0
    37
LOCAL_D RTest test(_L("T_SVR3"));
sl@0
    38
sl@0
    39
class CMySession : public CSession2
sl@0
    40
	{
sl@0
    41
public:
sl@0
    42
	CMySession();
sl@0
    43
	virtual void ServiceL(const RMessage2& aMessage);			 //pure virtual fns.
sl@0
    44
	void Process(const RMessage2& aMessage);
sl@0
    45
public:
sl@0
    46
	TInt iOutstanding;
sl@0
    47
	TUint iSeed[2];
sl@0
    48
	};
sl@0
    49
sl@0
    50
class CMyServer : public CServer2
sl@0
    51
	{
sl@0
    52
public:
sl@0
    53
	enum {ETest};
sl@0
    54
public:
sl@0
    55
	CMyServer(TInt aPriority);
sl@0
    56
	static CMyServer* New(TInt aPriority);
sl@0
    57
	virtual CSession2* NewSessionL(const TVersion& aVersion, const RMessage2& aMessage) const;//Overloading
sl@0
    58
	};
sl@0
    59
sl@0
    60
class CMyActiveScheduler : public CActiveScheduler
sl@0
    61
	{
sl@0
    62
public:
sl@0
    63
	virtual void Error(TInt anError) const;  //Overloading pure virtual function
sl@0
    64
	};
sl@0
    65
sl@0
    66
class RStressSvr : public RSessionBase
sl@0
    67
	{
sl@0
    68
public:
sl@0
    69
	TInt Connect();
sl@0
    70
	TInt Test();
sl@0
    71
	void Test(TRequestStatus& aStatus);
sl@0
    72
	TVersion Version();
sl@0
    73
	};
sl@0
    74
sl@0
    75
class CThread : public CActive
sl@0
    76
	{
sl@0
    77
public:
sl@0
    78
	CThread(TInt aPriority);
sl@0
    79
	~CThread();
sl@0
    80
	virtual void RunL();
sl@0
    81
	virtual void DoCancel();
sl@0
    82
	virtual void DisplayStats()=0;
sl@0
    83
	TInt Start();
sl@0
    84
public:
sl@0
    85
	virtual TInt StartThread()=0;
sl@0
    86
public:
sl@0
    87
	RThread iThread;
sl@0
    88
	TInt iExitCount;
sl@0
    89
	TInt iServerTerminatedCount;
sl@0
    90
	TInt iTerminateCount;
sl@0
    91
	};
sl@0
    92
sl@0
    93
class CServerThread : public CThread
sl@0
    94
	{
sl@0
    95
public:
sl@0
    96
	static void NewL();
sl@0
    97
	CServerThread();
sl@0
    98
	virtual TInt StartThread();
sl@0
    99
	virtual void DisplayStats();
sl@0
   100
public:
sl@0
   101
	TInt iMessagesReceived;
sl@0
   102
	};
sl@0
   103
sl@0
   104
class CClientThread : public CThread
sl@0
   105
	{
sl@0
   106
public:
sl@0
   107
	static void NewL(TInt anId);
sl@0
   108
	CClientThread(TInt anId);
sl@0
   109
	virtual TInt StartThread();
sl@0
   110
	virtual void DisplayStats();
sl@0
   111
public:
sl@0
   112
	TInt iId;
sl@0
   113
	TInt iCloses;
sl@0
   114
	};
sl@0
   115
sl@0
   116
class CRandomTimer : public CActive
sl@0
   117
	{
sl@0
   118
public:
sl@0
   119
	static void NewL();
sl@0
   120
	CRandomTimer(TInt aPriority);
sl@0
   121
	~CRandomTimer();
sl@0
   122
	virtual void RunL();
sl@0
   123
	virtual void DoCancel();
sl@0
   124
	void Start();
sl@0
   125
public:
sl@0
   126
	RTimer iTimer;
sl@0
   127
	TUint iSeed[2];
sl@0
   128
	TInt iCount;
sl@0
   129
	};
sl@0
   130
sl@0
   131
class CStatsTimer : public CActive
sl@0
   132
	{
sl@0
   133
public:
sl@0
   134
	static void NewL();
sl@0
   135
	CStatsTimer(TInt aPriority);
sl@0
   136
	~CStatsTimer();
sl@0
   137
	virtual void RunL();
sl@0
   138
	virtual void DoCancel();
sl@0
   139
	void Start();
sl@0
   140
public:
sl@0
   141
	RTimer iTimer;
sl@0
   142
	TInt iInitFreeRam;
sl@0
   143
	TInt iMaxDelta;
sl@0
   144
	TInt iCount;
sl@0
   145
	};
sl@0
   146
sl@0
   147
const TInt KNumClients=3;
sl@0
   148
LOCAL_D CServerThread* TheServer;
sl@0
   149
LOCAL_D CClientThread* TheClients[KNumClients];
sl@0
   150
LOCAL_D CRandomTimer* TheRandomTimer;
sl@0
   151
sl@0
   152
CMySession::CMySession()
sl@0
   153
//
sl@0
   154
// Constructor
sl@0
   155
//
sl@0
   156
	{
sl@0
   157
	iSeed[0]=User::TickCount();
sl@0
   158
	}
sl@0
   159
sl@0
   160
CMyServer* CMyServer::New(TInt aPriority)
sl@0
   161
//
sl@0
   162
// Create a new CMyServer.
sl@0
   163
//
sl@0
   164
	{
sl@0
   165
sl@0
   166
	return new CMyServer(aPriority);
sl@0
   167
	}
sl@0
   168
sl@0
   169
CMyServer::CMyServer(TInt aPriority)
sl@0
   170
//
sl@0
   171
// Constructor.
sl@0
   172
//
sl@0
   173
	: CServer2(aPriority)
sl@0
   174
	{}
sl@0
   175
sl@0
   176
CSession2* CMyServer::NewSessionL(const TVersion& aVersion, const RMessage2&) const
sl@0
   177
//
sl@0
   178
// Create a new client for this server.
sl@0
   179
//
sl@0
   180
	{
sl@0
   181
sl@0
   182
	TVersion v(KMajorVersionNumber,KMinorVersionNumber,KBuildVersionNumber);
sl@0
   183
	if (!User::QueryVersionSupported(v,aVersion))
sl@0
   184
		User::Leave(KErrNotSupported);
sl@0
   185
	return new(ELeave) CMySession;
sl@0
   186
	}
sl@0
   187
sl@0
   188
void CMySession::ServiceL(const RMessage2& aMessage)
sl@0
   189
//
sl@0
   190
// Handle messages for this server.
sl@0
   191
//
sl@0
   192
	{
sl@0
   193
sl@0
   194
	++TheServer->iMessagesReceived;
sl@0
   195
	switch (aMessage.Function())
sl@0
   196
		{
sl@0
   197
		case CMyServer::ETest:
sl@0
   198
			if (iOutstanding==KNumMessageSlots-1)
sl@0
   199
				Process(aMessage);
sl@0
   200
			else
sl@0
   201
				++iOutstanding;
sl@0
   202
			break;
sl@0
   203
		default:
sl@0
   204
			aMessage.Complete(KErrNotSupported);
sl@0
   205
			break;
sl@0
   206
		}
sl@0
   207
	}
sl@0
   208
sl@0
   209
void CMySession::Process(const RMessage2& aMessage)
sl@0
   210
	{
sl@0
   211
	TUint x=Random(iSeed)&16383;
sl@0
   212
	if (x==0)
sl@0
   213
		User::Exit(0);			// exit the server
sl@0
   214
	else if (x<8)
sl@0
   215
		aMessage.Terminate(0);	// terminate the client
sl@0
   216
	else
sl@0
   217
		aMessage.Complete(KErrNone);
sl@0
   218
	}
sl@0
   219
sl@0
   220
void CMyActiveScheduler::Error(TInt anError) const
sl@0
   221
//
sl@0
   222
// Called if any Run() method leaves.
sl@0
   223
//
sl@0
   224
	{
sl@0
   225
sl@0
   226
	User::Panic(_L("Server Error"),anError);
sl@0
   227
	}
sl@0
   228
sl@0
   229
TInt RStressSvr::Connect()
sl@0
   230
//
sl@0
   231
// Connect to the server
sl@0
   232
//
sl@0
   233
	{
sl@0
   234
sl@0
   235
	return CreateSession(KServerName,Version(),KNumMessageSlots);
sl@0
   236
	}
sl@0
   237
sl@0
   238
TInt RStressSvr::Test()
sl@0
   239
//
sl@0
   240
// Send a message and wait for completion.
sl@0
   241
//
sl@0
   242
	{
sl@0
   243
sl@0
   244
	return SendReceive(CMyServer::ETest);
sl@0
   245
	}
sl@0
   246
sl@0
   247
void RStressSvr::Test(TRequestStatus& aStatus)
sl@0
   248
//
sl@0
   249
// Send a message asynchronously
sl@0
   250
//
sl@0
   251
	{
sl@0
   252
sl@0
   253
	SendReceive(CMyServer::ETest,aStatus);
sl@0
   254
	}
sl@0
   255
sl@0
   256
TVersion RStressSvr::Version()
sl@0
   257
//
sl@0
   258
// Return the current version.
sl@0
   259
//
sl@0
   260
	{
sl@0
   261
sl@0
   262
	TVersion v(KMajorVersionNumber,KMinorVersionNumber,KBuildVersionNumber);
sl@0
   263
	return(v);
sl@0
   264
	}
sl@0
   265
sl@0
   266
LOCAL_C TInt ServerThread(TAny*)
sl@0
   267
	{
sl@0
   268
sl@0
   269
	CMyActiveScheduler* pR=new CMyActiveScheduler;
sl@0
   270
	if (!pR)
sl@0
   271
		return KErrNoMemory;
sl@0
   272
	CActiveScheduler::Install(pR);
sl@0
   273
	CMyServer* pS=CMyServer::New(0);
sl@0
   274
	if (!pS)
sl@0
   275
		return KErrNoMemory;
sl@0
   276
	TInt r=pS->Start(KServerName);
sl@0
   277
	if (r!=KErrNone)
sl@0
   278
		return r;
sl@0
   279
sl@0
   280
	CActiveScheduler::Start();
sl@0
   281
sl@0
   282
	delete pS;
sl@0
   283
	delete pR;
sl@0
   284
	return KErrNone;
sl@0
   285
	}
sl@0
   286
sl@0
   287
LOCAL_C TInt ClientThread(TAny* aPtr)
sl@0
   288
	{
sl@0
   289
	CClientThread* pT=(CClientThread*)aPtr;
sl@0
   290
	RStressSvr d;
sl@0
   291
	TUint seed[2];
sl@0
   292
	seed[0]=User::TickCount();
sl@0
   293
	seed[1]=0;
sl@0
   294
	FOREVER
sl@0
   295
		{
sl@0
   296
		TInt r;
sl@0
   297
		FOREVER
sl@0
   298
			{
sl@0
   299
			r=d.Connect();
sl@0
   300
			if (r!=KErrNotFound)
sl@0
   301
				break;
sl@0
   302
			User::After(50000);
sl@0
   303
			}
sl@0
   304
		if (r!=KErrNone)
sl@0
   305
			return r;
sl@0
   306
		TRequestStatus s[KNumMessageSlots];
sl@0
   307
		TInt i;
sl@0
   308
		for (i=0; i<KNumMessageSlots-1; i++)
sl@0
   309
			d.Test(s[i]);
sl@0
   310
		TInt n=Random(seed)&16383;
sl@0
   311
		for (i=0; i<n; i++)
sl@0
   312
			d.Test();
sl@0
   313
		d.Close();
sl@0
   314
		++pT->iCloses;
sl@0
   315
		}
sl@0
   316
	}
sl@0
   317
sl@0
   318
CThread::CThread(TInt aPriority)
sl@0
   319
	: CActive(aPriority)
sl@0
   320
	{
sl@0
   321
	}
sl@0
   322
sl@0
   323
CThread::~CThread()
sl@0
   324
	{
sl@0
   325
	Cancel();
sl@0
   326
	iThread.Kill(0);
sl@0
   327
	iThread.Close();
sl@0
   328
	}
sl@0
   329
sl@0
   330
void CThread::RunL()
sl@0
   331
	{
sl@0
   332
	TExitType exitType=iThread.ExitType();
sl@0
   333
	TInt exitReason=iThread.ExitReason();
sl@0
   334
	TBuf<32> exitCat=iThread.ExitCategory();
sl@0
   335
	TBool bad=EFalse;
sl@0
   336
	if (exitType==EExitKill)
sl@0
   337
		{
sl@0
   338
		if (exitReason!=KErrNone && exitReason!=KErrServerTerminated)
sl@0
   339
			bad=ETrue;
sl@0
   340
		}
sl@0
   341
	else if (exitType==EExitPanic)
sl@0
   342
		bad=ETrue;
sl@0
   343
	if (bad)
sl@0
   344
		{
sl@0
   345
		TFullName n(iThread.FullName());
sl@0
   346
		test.Printf(_L("Thread %S exited %d,%d,%S\n"),&n,exitType,exitReason,&exitCat);
sl@0
   347
		CActiveScheduler::Stop();
sl@0
   348
		return;
sl@0
   349
		}
sl@0
   350
	iThread.Close();
sl@0
   351
	if (exitType==EExitTerminate)
sl@0
   352
		++iTerminateCount;
sl@0
   353
	else if (exitReason==KErrNone)
sl@0
   354
		++iExitCount;
sl@0
   355
	else if (exitReason==KErrServerTerminated)
sl@0
   356
		++iServerTerminatedCount;
sl@0
   357
	TInt r=Start();
sl@0
   358
	if (r!=KErrNone)
sl@0
   359
		{
sl@0
   360
		test.Printf(_L("Start thread error %d\n"),r);
sl@0
   361
		CActiveScheduler::Stop();
sl@0
   362
		}
sl@0
   363
	}
sl@0
   364
sl@0
   365
void CThread::DoCancel()
sl@0
   366
	{
sl@0
   367
	iThread.LogonCancel(iStatus);
sl@0
   368
	}
sl@0
   369
sl@0
   370
TInt CThread::Start()
sl@0
   371
	{
sl@0
   372
	TInt r;
sl@0
   373
	FOREVER
sl@0
   374
		{
sl@0
   375
		r=StartThread();
sl@0
   376
		if (r==KErrNone)
sl@0
   377
			break;
sl@0
   378
		if (r!=KErrAlreadyExists)
sl@0
   379
			break;
sl@0
   380
		User::After(100000);
sl@0
   381
		}
sl@0
   382
	if (r==KErrNone)
sl@0
   383
		{
sl@0
   384
		iThread.Logon(iStatus);
sl@0
   385
		SetActive();
sl@0
   386
		}
sl@0
   387
	return r;
sl@0
   388
	}
sl@0
   389
sl@0
   390
CServerThread::CServerThread()
sl@0
   391
	: CThread(0)
sl@0
   392
	{
sl@0
   393
	}
sl@0
   394
sl@0
   395
TInt CServerThread::StartThread()
sl@0
   396
	{
sl@0
   397
	TUint seed[2];
sl@0
   398
	seed[1]=0;
sl@0
   399
	seed[0]=User::TickCount();
sl@0
   400
	TInt heapMin=TInt(Random(seed)&0x0f)+1;
sl@0
   401
	heapMin<<=12;
sl@0
   402
	TInt r=iThread.Create(KNullDesC(),ServerThread,KStackSize,heapMin,KHeapMaxSize,this);	// use unnamed thread
sl@0
   403
	if (r!=KErrNone)
sl@0
   404
		return r;
sl@0
   405
	iThread.Resume();
sl@0
   406
	return KErrNone;
sl@0
   407
	}
sl@0
   408
sl@0
   409
void CServerThread::NewL()
sl@0
   410
	{
sl@0
   411
	CServerThread* pT=new (ELeave) CServerThread;
sl@0
   412
	TheServer=pT;
sl@0
   413
	CActiveScheduler::Add(pT);
sl@0
   414
	User::LeaveIfError(pT->Start());
sl@0
   415
	}
sl@0
   416
sl@0
   417
void CServerThread::DisplayStats()
sl@0
   418
	{
sl@0
   419
	test.Printf(_L("Svr  : X:%9d ST:%9d T:%9d RX:%9d\n"),iExitCount,iServerTerminatedCount,iTerminateCount,iMessagesReceived);
sl@0
   420
	}
sl@0
   421
sl@0
   422
CClientThread::CClientThread(TInt anId)
sl@0
   423
	: CThread(0), iId(anId)
sl@0
   424
	{
sl@0
   425
	}
sl@0
   426
sl@0
   427
TInt CClientThread::StartThread()
sl@0
   428
	{
sl@0
   429
	TInt r=iThread.Create(KNullDesC(),ClientThread,KStackSize,NULL,this);	// use unnamed thread
sl@0
   430
	if (r!=KErrNone)
sl@0
   431
		return r;
sl@0
   432
	iThread.Resume();
sl@0
   433
	return KErrNone;
sl@0
   434
	}
sl@0
   435
sl@0
   436
void CClientThread::NewL(TInt anId)
sl@0
   437
	{
sl@0
   438
	CClientThread* pT=new (ELeave) CClientThread(anId);
sl@0
   439
	TheClients[anId]=pT;
sl@0
   440
	CActiveScheduler::Add(pT);
sl@0
   441
	User::LeaveIfError(pT->Start());
sl@0
   442
	}
sl@0
   443
sl@0
   444
void CClientThread::DisplayStats()
sl@0
   445
	{
sl@0
   446
	test.Printf(_L("Cli %1d: X:%9d ST:%9d T:%9d CL:%9d\n"),iId,iExitCount,iServerTerminatedCount,iTerminateCount,iCloses);
sl@0
   447
	}
sl@0
   448
sl@0
   449
void CRandomTimer::NewL()
sl@0
   450
	{
sl@0
   451
	CRandomTimer* pR=new (ELeave) CRandomTimer(20);
sl@0
   452
	User::LeaveIfError(pR->iTimer.CreateLocal());
sl@0
   453
	CActiveScheduler::Add(pR);
sl@0
   454
	TheRandomTimer=pR;
sl@0
   455
	pR->Start();
sl@0
   456
	}
sl@0
   457
sl@0
   458
CRandomTimer::CRandomTimer(TInt aPriority)
sl@0
   459
	: CActive(aPriority)
sl@0
   460
	{
sl@0
   461
	iSeed[0]=User::TickCount();
sl@0
   462
	}
sl@0
   463
sl@0
   464
CRandomTimer::~CRandomTimer()
sl@0
   465
	{
sl@0
   466
	Cancel();
sl@0
   467
	iTimer.Close();
sl@0
   468
	}
sl@0
   469
sl@0
   470
void CRandomTimer::RunL()
sl@0
   471
	{
sl@0
   472
	++iCount;
sl@0
   473
	TUint x=Random(iSeed)&3;
sl@0
   474
	CThread* pT;
sl@0
   475
	if (x==0)
sl@0
   476
		pT=TheServer;
sl@0
   477
	else
sl@0
   478
		pT=TheClients[x-1];
sl@0
   479
	pT->iThread.Kill(0);
sl@0
   480
	Start();
sl@0
   481
	}
sl@0
   482
sl@0
   483
void CRandomTimer::Start()
sl@0
   484
	{
sl@0
   485
	TUint x=Random(iSeed)&63;
sl@0
   486
	x+=32;
sl@0
   487
	iTimer.HighRes(iStatus, x*1000);
sl@0
   488
	SetActive();
sl@0
   489
	}
sl@0
   490
sl@0
   491
void CRandomTimer::DoCancel()
sl@0
   492
	{
sl@0
   493
	iTimer.Cancel();
sl@0
   494
	}
sl@0
   495
sl@0
   496
void CStatsTimer::NewL()
sl@0
   497
	{
sl@0
   498
	CStatsTimer* pT=new (ELeave) CStatsTimer(-10);
sl@0
   499
	User::LeaveIfError(pT->iTimer.CreateLocal());
sl@0
   500
	CActiveScheduler::Add(pT);
sl@0
   501
	pT->Start();
sl@0
   502
	}
sl@0
   503
sl@0
   504
CStatsTimer::CStatsTimer(TInt aPriority)
sl@0
   505
	: CActive(aPriority)
sl@0
   506
	{
sl@0
   507
	iInitFreeRam = FreeRam();
sl@0
   508
	}
sl@0
   509
sl@0
   510
CStatsTimer::~CStatsTimer()
sl@0
   511
	{
sl@0
   512
	Cancel();
sl@0
   513
	iTimer.Close();
sl@0
   514
	}
sl@0
   515
sl@0
   516
void CStatsTimer::RunL()
sl@0
   517
	{
sl@0
   518
	TheServer->DisplayStats();
sl@0
   519
	TInt i;
sl@0
   520
	for (i=0; i<KNumClients; i++)
sl@0
   521
		TheClients[i]->DisplayStats();
sl@0
   522
	test.Printf(_L("RndTm: %9d\n"),TheRandomTimer->iCount);
sl@0
   523
	TInt free_ram = FreeRam();
sl@0
   524
	TInt delta_ram = iInitFreeRam - free_ram;
sl@0
   525
	if (delta_ram > iMaxDelta)
sl@0
   526
		iMaxDelta = delta_ram;
sl@0
   527
	if (++iCount==10)
sl@0
   528
		{
sl@0
   529
		test.Printf(_L("Max RAM delta %dK Free RAM %08x\n"), iMaxDelta/1024, free_ram);
sl@0
   530
		iCount=0;
sl@0
   531
		}
sl@0
   532
	Start();
sl@0
   533
	}
sl@0
   534
sl@0
   535
void CStatsTimer::Start()
sl@0
   536
	{
sl@0
   537
	iTimer.After(iStatus, 1000000);
sl@0
   538
	SetActive();
sl@0
   539
	}
sl@0
   540
sl@0
   541
void CStatsTimer::DoCancel()
sl@0
   542
	{
sl@0
   543
	iTimer.Cancel();
sl@0
   544
	}
sl@0
   545
sl@0
   546
void InitialiseL()
sl@0
   547
	{
sl@0
   548
	CActiveScheduler* pA=new (ELeave) CActiveScheduler;
sl@0
   549
	CActiveScheduler::Install(pA);
sl@0
   550
	CServerThread::NewL();
sl@0
   551
	TInt id;
sl@0
   552
	for (id=0; id<KNumClients; id++)
sl@0
   553
		CClientThread::NewL(id);
sl@0
   554
	CRandomTimer::NewL();
sl@0
   555
	CStatsTimer::NewL();
sl@0
   556
	}
sl@0
   557
sl@0
   558
GLDEF_C TInt E32Main()
sl@0
   559
//
sl@0
   560
// Test timers.
sl@0
   561
//
sl@0
   562
	{
sl@0
   563
sl@0
   564
	test.Title();
sl@0
   565
sl@0
   566
	RThread().SetPriority(EPriorityMore);
sl@0
   567
sl@0
   568
	TRAPD(r,InitialiseL());
sl@0
   569
	test(r==KErrNone);
sl@0
   570
sl@0
   571
	CActiveScheduler::Start();
sl@0
   572
sl@0
   573
	test(0);
sl@0
   574
sl@0
   575
	return(0);
sl@0
   576
	}
sl@0
   577
sl@0
   578
// Override heap creation for this process
sl@0
   579
// This function runs at the beginning of every thread
sl@0
   580
// Initial heap is shared but subsequent heaps are single threaded
sl@0
   581
TInt UserHeap::SetupThreadHeap(TBool aNotFirst, SStdEpocThreadCreateInfo& aInfo)
sl@0
   582
	{
sl@0
   583
	TInt r = KErrNone;
sl@0
   584
	if (!aInfo.iAllocator && aInfo.iHeapInitialSize>0)
sl@0
   585
		{
sl@0
   586
		// new heap required
sl@0
   587
		RHeap* pH = NULL;
sl@0
   588
		r = CreateThreadHeap(aInfo, pH, 0, aNotFirst);
sl@0
   589
		}
sl@0
   590
	else if (aInfo.iAllocator)
sl@0
   591
		{
sl@0
   592
		// sharing a heap
sl@0
   593
		RAllocator* pA = aInfo.iAllocator;
sl@0
   594
		pA->Open();
sl@0
   595
		User::SwitchAllocator(pA);
sl@0
   596
		}
sl@0
   597
	return r;
sl@0
   598
	}
sl@0
   599