os/kernelhwsrv/kerneltest/e32test/smpsoak/t_smpsoakprocess.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) 2002-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\smpsoak\t_smpsoakprocess.cpp
sl@0
    15
sl@0
    16
//  User Includes
sl@0
    17
#include "t_smpsoak.h"
sl@0
    18
sl@0
    19
#define PRINT(args)\
sl@0
    20
    if (!TestSilent)\
sl@0
    21
        test.Printf args
sl@0
    22
sl@0
    23
void ParseCmdLine();
sl@0
    24
sl@0
    25
//class for soak process and same executable(t_smpsoakprocess.exe) will be lauched with different process operation
sl@0
    26
//Example: IPC Read, IPC Write, File Process, Timer Process
sl@0
    27
class CSMPSoakProcess
sl@0
    28
    {
sl@0
    29
public:
sl@0
    30
	CSMPSoakProcess();
sl@0
    31
	~CSMPSoakProcess();
sl@0
    32
	void CreateThread(TPtrC aThreadType);
sl@0
    33
private:
sl@0
    34
    //Thread Functions
sl@0
    35
 	static TInt FileThread(TAny*);
sl@0
    36
	static TInt TimerThread(TAny*);
sl@0
    37
	static TInt MemoryThread(TAny*);
sl@0
    38
private:
sl@0
    39
   // Thread member functions
sl@0
    40
    TInt DoFileThread();
sl@0
    41
    TInt DoTimerThread();
sl@0
    42
    TInt DoMemoryThread();
sl@0
    43
    void DoCreateThread(TAny*);
sl@0
    44
    void ResumeThread();
sl@0
    45
    //IPC's
sl@0
    46
    void WriteProcess();
sl@0
    47
    void ReadProcess();
sl@0
    48
    //Thread Priority
sl@0
    49
    void SetThreadPriority();
sl@0
    50
    //Utils for soak process
sl@0
    51
	void SetSoakProcessPriority();
sl@0
    52
	void CommitChunk(RChunk& aChunk, TInt aSize);
sl@0
    53
	void ReadChunk(RChunk& aChunk, TInt aSize);
sl@0
    54
	void WriteToChunk(RChunk& aChunk, TInt aSize);
sl@0
    55
	void DeleteChunk(RChunk& aChunk);
sl@0
    56
private:
sl@0
    57
    //Thread tables
sl@0
    58
    static TThread KOOMemoryTable[];
sl@0
    59
    static TThread KFileTable[];
sl@0
    60
    static TThread KTimerTable[];
sl@0
    61
private:
sl@0
    62
    TThreadData iThreadData;
sl@0
    63
    RThread     iThread;
sl@0
    64
    TInt        iPriority;
sl@0
    65
    };
sl@0
    66
 
sl@0
    67
//Memory thread data
sl@0
    68
TThread CSMPSoakProcess::KOOMemoryTable[] =
sl@0
    69
    {   
sl@0
    70
         { _L("SMPOOMemoryThread1"), CSMPSoakProcess::MemoryThread, {{EPriorityAbsoluteLowNormal, EPriorityAbsoluteVeryLow,   EPriorityNormal, 0}, EPriorityList, KCpuAffinityAny, 0, 4, NULL, NULL,NULL}},
sl@0
    71
         { _L("SMPOOMemoryThread2"), CSMPSoakProcess::MemoryThread, {{EPriorityAbsoluteLow, EPriorityAbsoluteVeryLow,   EPriorityNormal, 0}, EPriorityList, KCpuAffinityAny, 0, 4, NULL, NULL,NULL}},
sl@0
    72
         { _L("SMPOOMemoryThread3"), CSMPSoakProcess::MemoryThread, {{EPriorityMore, EPriorityAbsoluteVeryLow, EPriorityNormal, 0}, EPriorityList, KCpuAffinityAny, 0, 4, NULL, NULL,NULL}},
sl@0
    73
         { _L("SMPOOMemoryThread4"), CSMPSoakProcess::MemoryThread, {{EPriorityAbsoluteLow, EPriorityAbsoluteVeryLow, EPriorityNormal, 0}, EPriorityList, KCpuAffinityAny, 0, 4, NULL, NULL,NULL}},
sl@0
    74
    };
sl@0
    75
sl@0
    76
//File thread data
sl@0
    77
TThread CSMPSoakProcess::KFileTable[] =
sl@0
    78
    {   
sl@0
    79
        { _L("SMPFileThread1"), CSMPSoakProcess::FileThread, {{EPriorityAbsoluteLow, EPriorityAbsoluteVeryLow,   EPriorityNormal, 0}, EPriorityList, KCpuAffinityAny, 0, 4, NULL, 11, 5}},
sl@0
    80
        { _L("SMPFileThread2"), CSMPSoakProcess::FileThread, {{EPriorityNormal, EPriorityAbsoluteVeryLow,   EPriorityNormal, 0}, EPriorityList, KCpuAffinityAny, 0, 4, NULL, 22, 10}},
sl@0
    81
        { _L("SMPFileThread3"), CSMPSoakProcess::FileThread, {{EPriorityMore, EPriorityAbsoluteVeryLow,   EPriorityNormal, 0}, EPriorityList, KCpuAffinityAny, 0, 4, NULL, 33, 15}},
sl@0
    82
        { _L("SMPFileThread4"), CSMPSoakProcess::FileThread, {{EPriorityAbsoluteVeryLow, EPriorityMore,   EPriorityNormal, 0}, EPriorityList, KCpuAffinityAny, 0, 4, NULL, 44, 20}},
sl@0
    83
    };
sl@0
    84
sl@0
    85
//Timer thread data
sl@0
    86
TThread CSMPSoakProcess::KTimerTable[] =
sl@0
    87
    {   
sl@0
    88
        { _L("SMPTimerThread1"), CSMPSoakProcess::TimerThread, {{EPriorityAbsoluteLowNormal, EPriorityAbsoluteVeryLow,   EPriorityNormal, 0}, EPriorityList, KCpuAffinityAny, 1000, 2, NULL, NULL,NULL}},
sl@0
    89
        { _L("SMPTimerThread2"), CSMPSoakProcess::TimerThread, {{EPriorityAbsoluteLow, EPriorityAbsoluteVeryLow,   EPriorityNormal, 0}, EPriorityList, KCpuAffinityAny, 1500, 2, NULL, NULL,NULL}},
sl@0
    90
    };
sl@0
    91
//Constructor
sl@0
    92
CSMPSoakProcess::CSMPSoakProcess()
sl@0
    93
    { 
sl@0
    94
    }
sl@0
    95
//Destructor
sl@0
    96
CSMPSoakProcess::~CSMPSoakProcess()
sl@0
    97
    {    
sl@0
    98
    }
sl@0
    99
//Set the process priority each time for each process
sl@0
   100
void CSMPSoakProcess::SetSoakProcessPriority()
sl@0
   101
	{
sl@0
   102
	RProcess proc;
sl@0
   103
	TInt priority;
sl@0
   104
	static TInt priorityindex = 0;
sl@0
   105
	static const TProcessPriority priorityTable[]=
sl@0
   106
		{
sl@0
   107
		EPriorityLow,
sl@0
   108
		EPriorityBackground,
sl@0
   109
		EPriorityForeground,
sl@0
   110
		EPriorityHigh
sl@0
   111
		};
sl@0
   112
	if(++priorityindex >= 4)
sl@0
   113
		priorityindex=0;
sl@0
   114
	priority = priorityTable[priorityindex];
sl@0
   115
	proc.SetPriority((TProcessPriority)priority);
sl@0
   116
	PRINT((_L("Process Priority:%d \n"),proc.Priority()));
sl@0
   117
	}
sl@0
   118
//Changes the thread priority each time time, for each thread by Random, Increment, from List, Fixed.
sl@0
   119
//pick up the priority option from thread table
sl@0
   120
void CSMPSoakProcess::SetThreadPriority()
sl@0
   121
    {
sl@0
   122
    static TInt64 randSeed = KRandSeed;
sl@0
   123
    static const TThreadPriority priorityTable[]=
sl@0
   124
        {
sl@0
   125
        EPriorityMuchLess, EPriorityLess, EPriorityNormal, EPriorityMore, EPriorityMuchMore,
sl@0
   126
        EPriorityRealTime, EPriorityRealTime, EPriorityAbsoluteVeryLow, EPriorityAbsoluteLowNormal,
sl@0
   127
        EPriorityAbsoluteLow, EPriorityAbsoluteBackgroundNormal, EPriorityAbsoluteBackground,
sl@0
   128
        EPriorityAbsoluteForegroundNormal, EPriorityAbsoluteForeground, EPriorityAbsoluteHighNormal, EPriorityAbsoluteHigh
sl@0
   129
        };
sl@0
   130
    TInt priorityIndex = 0;
sl@0
   131
    switch (iThreadData.threadPriorityChange)
sl@0
   132
        {
sl@0
   133
        case EpriorityFixed:
sl@0
   134
            break;
sl@0
   135
sl@0
   136
        case EPriorityList:
sl@0
   137
            if (++iPriority >= KPriorityOrder)
sl@0
   138
                iPriority = 0;
sl@0
   139
            if (iThreadData.threadPriorities[iPriority] == 0)
sl@0
   140
                iPriority = 0;
sl@0
   141
         //   PRINT(_L("SetPriority List CPU %d index %d priority %d\n"),gSMPStressDrv.GetThreadCPU(&iThread),iPriority, iThreadData.threadPriorities[iPriority]);
sl@0
   142
            iThread.SetPriority((TThreadPriority)iThreadData.threadPriorities[iPriority]);
sl@0
   143
            break;
sl@0
   144
sl@0
   145
        case EPriorityIncrement:
sl@0
   146
            while (priorityTable[priorityIndex] <= iPriority)
sl@0
   147
                {
sl@0
   148
                priorityIndex++;
sl@0
   149
                }
sl@0
   150
            iPriority = priorityTable[priorityIndex];
sl@0
   151
            if (iPriority > iThreadData.threadPriorities[2])
sl@0
   152
                iPriority = iThreadData.threadPriorities[1];
sl@0
   153
          //  PRINT(_L("SetPriority Increment CPU %d priority %d\n"),gSMPStressDrv.GetThreadCPU(&iThread), iPriority);
sl@0
   154
            iThread.SetPriority((TThreadPriority)iPriority);
sl@0
   155
            break;
sl@0
   156
sl@0
   157
        case EPriorityRandom:
sl@0
   158
            iPriority = Math::Rand(randSeed) % (iThreadData.threadPriorities[2] - iThreadData.threadPriorities[1] + 1);
sl@0
   159
            iPriority += iThreadData.threadPriorities[1];
sl@0
   160
            while (priorityTable[priorityIndex] < iPriority)
sl@0
   161
                {
sl@0
   162
                priorityIndex++;
sl@0
   163
                }
sl@0
   164
            iPriority = priorityTable[priorityIndex];
sl@0
   165
           // PRINT(_L("SetPriority Random CPU %d iPriority %d\n"),gSMPStressDrv.GetThreadCPU(&iThread), iPriority);
sl@0
   166
            iThread.SetPriority((TThreadPriority)iPriority);
sl@0
   167
            break;
sl@0
   168
        }
sl@0
   169
    }
sl@0
   170
//Resume each thread
sl@0
   171
void CSMPSoakProcess::ResumeThread()
sl@0
   172
    {
sl@0
   173
    iThread.Resume();
sl@0
   174
    }
sl@0
   175
// CSMPSoakProcess Thread Creation.
sl@0
   176
// @param aThread thread table data          
sl@0
   177
void CSMPSoakProcess::DoCreateThread(TAny* aThread)
sl@0
   178
    {
sl@0
   179
    //Initialize each thread data
sl@0
   180
    iThreadData = ((TThread*)aThread)->threadData;
sl@0
   181
    test.Next(_L("Create Thread"));
sl@0
   182
    PRINT ((_L("%s   CPU affinity %d  Priority %d\n"),((TThread*)aThread)->threadName.Ptr(),iThreadData.cpuAffinity,iThreadData.threadPriorities[0]));
sl@0
   183
    TInt r = iThread.Create(((TThread*)aThread)->threadName, ((TThread*)aThread)->threadFunction, KDefaultStackSize, KHeapMinSize, KHeapMaxSize,(TAny*)this);
sl@0
   184
    test_KErrNone(r);
sl@0
   185
    if (iThreadData.threadPriorityChange == EPriorityList)
sl@0
   186
        {
sl@0
   187
        iPriority = 0;
sl@0
   188
        }
sl@0
   189
    else
sl@0
   190
        {
sl@0
   191
        iPriority = iThreadData.threadPriorities[0];
sl@0
   192
        }
sl@0
   193
    iThread.SetPriority((TThreadPriority)iThreadData.threadPriorities[0]);
sl@0
   194
    //Set the thread CPU Affinity
sl@0
   195
    gSMPStressDrv.ChangeThreadAffinity(&iThread, iThreadData.cpuAffinity);
sl@0
   196
    }
sl@0
   197
//Commit the chunk with aSize
sl@0
   198
void CSMPSoakProcess::CommitChunk(RChunk& aChunk, TInt aSize)
sl@0
   199
	{
sl@0
   200
	//PRINT ((_L("Commit Chunk \n")));
sl@0
   201
	test_KErrNone(aChunk.Adjust(aSize));
sl@0
   202
	}
sl@0
   203
//Write some data into the chunk 
sl@0
   204
void CSMPSoakProcess::WriteToChunk(RChunk& aChunk, TInt aSize)
sl@0
   205
	{
sl@0
   206
	TUint8 *writeaddr = aChunk.Base();
sl@0
   207
	TPtr8 write(writeaddr,aSize);
sl@0
   208
	write.Fill('S',aSize);
sl@0
   209
	write.Copy(memData);
sl@0
   210
	}
sl@0
   211
//Read the data from chunk and verify
sl@0
   212
void CSMPSoakProcess::ReadChunk(RChunk& aChunk, TInt aSize)
sl@0
   213
	{
sl@0
   214
	TUint8 *readaddr = aChunk.Base();
sl@0
   215
	TPtr8 read(readaddr,aSize);
sl@0
   216
	test_KErrNone(read.Compare(memData));
sl@0
   217
	}
sl@0
   218
//Cleaunup chunk
sl@0
   219
void CSMPSoakProcess::DeleteChunk(RChunk& aChunk)
sl@0
   220
	{
sl@0
   221
	test_KErrNone(aChunk.Adjust(0));
sl@0
   222
	}
sl@0
   223
//IPC Read operation
sl@0
   224
void CSMPSoakProcess::ReadProcess()
sl@0
   225
    {
sl@0
   226
	RTest test(_L("SMPSoakReadProcess"));
sl@0
   227
	FOREVER
sl@0
   228
		{
sl@0
   229
		// SetSoakProcessPriority();
sl@0
   230
		 gWriteSem.Wait(); //Wait for write completion
sl@0
   231
		 PRINT((_L("Read Chunk\n")));
sl@0
   232
		 ReadChunk( gChunk,KChunkSize);
sl@0
   233
		 PRINT((_L("Delete Chunk\n")));
sl@0
   234
		 DeleteChunk(gChunk);
sl@0
   235
		 gReadSem.Signal(); //Read completion
sl@0
   236
		}
sl@0
   237
    }
sl@0
   238
//IPC Write operation
sl@0
   239
void CSMPSoakProcess::WriteProcess()
sl@0
   240
	{
sl@0
   241
	RTest test(_L("SMPSoakWriteProcess"));
sl@0
   242
	FOREVER
sl@0
   243
		{
sl@0
   244
		// SetSoakProcessPriority();
sl@0
   245
		 CommitChunk( gChunk, KChunkSize);
sl@0
   246
		 PRINT((_L("Write To Chunk\n")));
sl@0
   247
		 WriteToChunk( gChunk,KChunkSize);
sl@0
   248
		 gWriteSem.Signal(); //Write completion
sl@0
   249
		 gReadSem.Wait(); //Wait for read completion
sl@0
   250
		}
sl@0
   251
	}
sl@0
   252
//File Thread - creates Dir's, Files, Fileread, Filewrite and verify
sl@0
   253
//param aSoakThread - CSMPSoakUtil pointer
sl@0
   254
TInt CSMPSoakProcess::FileThread(TAny* aSoakThread)
sl@0
   255
     {
sl@0
   256
    CSMPSoakProcess* self = (CSMPSoakProcess*)aSoakThread;
sl@0
   257
    __ASSERT_ALWAYS(self !=NULL, User::Panic(_L("CSMPSoakProcess::TimerThread Panic"),0));
sl@0
   258
    return self->DoFileThread();
sl@0
   259
     }
sl@0
   260
//Member Filethread
sl@0
   261
 TInt CSMPSoakProcess::DoFileThread()
sl@0
   262
	 {
sl@0
   263
 	 RTest test(_L("SMPFileThread"));
sl@0
   264
 	 TInt r = KErrNone;
sl@0
   265
 
sl@0
   266
 	 TFileName sessionPath;
sl@0
   267
 	 TBuf8<KFileNameLength> fileData;
sl@0
   268
 	 fileData.Copy(KFileData);
sl@0
   269
 	 RFs fs;
sl@0
   270
 	 RFile file;
sl@0
   271
sl@0
   272
 	 TBuf<KFileNameLength> filename;
sl@0
   273
 	 TBuf<KFileNameLength> directory;
sl@0
   274
 	 TBuf<KFileNameLength> tempdir;
sl@0
   275
 	 
sl@0
   276
 	//Setup Dir structure
sl@0
   277
 	 tempdir.Format(KDir,iThreadData.dirID);
sl@0
   278
  	 test_KErrNone(fs.Connect());
sl@0
   279
  	 sessionPath=KSessionPath;
sl@0
   280
 	 TChar driveLetter;
sl@0
   281
 	 
sl@0
   282
 	 //Setup Drive and Session
sl@0
   283
 	 test_KErrNone(fs.DriveToChar(EDriveD,driveLetter));
sl@0
   284
 	 sessionPath[0]=(TText)driveLetter;
sl@0
   285
 	 test_KErrNone(fs.SetSessionPath(sessionPath));
sl@0
   286
 	 test.Printf(_L("SessionPath=%S\n"),&sessionPath);
sl@0
   287
 	 directory=sessionPath;
sl@0
   288
 	 directory.Append(tempdir);
sl@0
   289
 	PRINT((_L("Dir Level =%S Creation\n"),&directory));
sl@0
   290
 	 
sl@0
   291
 	 FOREVER
sl@0
   292
 			{
sl@0
   293
 			r= fs.MkDirAll(directory);
sl@0
   294
 			test(r == KErrNone || r == KErrAlreadyExists);
sl@0
   295
 			
sl@0
   296
                //Create Number of files then write data into it.
sl@0
   297
                for (TInt i = 0; i < iThreadData.numFile; i++)
sl@0
   298
                    {	
sl@0
   299
                    filename.Format(KFile,iThreadData.dirID,i);
sl@0
   300
                    PRINT((_L("File = %S Write\n"),&filename));
sl@0
   301
                    test_KErrNone(file.Create(fs,filename,EFileWrite));
sl@0
   302
                    test_KErrNone(file.Write(fileData));
sl@0
   303
                    file.Close();
sl@0
   304
                    }
sl@0
   305
                
sl@0
   306
                //Read those files and verify it
sl@0
   307
                for (TInt i = 0; i < iThreadData.numFile; i++)
sl@0
   308
                    {	
sl@0
   309
                    TBuf8<KFileNameLength> readData;
sl@0
   310
                    filename.Format(KFile,iThreadData.dirID,i);
sl@0
   311
                    PRINT((_L("File = %S Read/Verify\n"),&filename));
sl@0
   312
                    test_KErrNone(file.Open(fs,filename,EFileRead));
sl@0
   313
                    test_KErrNone(file.Read(readData));
sl@0
   314
                    test_KErrNone(readData.Compare(fileData));
sl@0
   315
                    file.Close();
sl@0
   316
                    }
sl@0
   317
                
sl@0
   318
                //Delete files
sl@0
   319
                for (TInt i = 0; i < iThreadData.numFile; i++)
sl@0
   320
                    {	
sl@0
   321
                    filename.Format(KFile,iThreadData.dirID,i);
sl@0
   322
                    PRINT((_L("File = %S Delete\n"),&filename));
sl@0
   323
                    test_KErrNone(fs.Delete(filename));
sl@0
   324
                    }
sl@0
   325
                
sl@0
   326
                //Remove Dir's
sl@0
   327
                PRINT((_L("Dir Level =%S Removed\n"),&directory));
sl@0
   328
 				test_KErrNone(fs.RmDir(directory));
sl@0
   329
 				SetThreadPriority();
sl@0
   330
 				if (gAbort)
sl@0
   331
 				    break;
sl@0
   332
 				User::After(gPeriod);
sl@0
   333
 			}
sl@0
   334
 	 fs.Close();
sl@0
   335
 	 return 0x00;
sl@0
   336
 	 }
sl@0
   337
//Timer Thread - produces DFC's in the kernel side
sl@0
   338
//param aSoakThread - CSMPSoakUtil pointer
sl@0
   339
 TInt CSMPSoakProcess::TimerThread(TAny* aSoakThread)
sl@0
   340
     {
sl@0
   341
     CSMPSoakProcess* self = (CSMPSoakProcess*)aSoakThread;
sl@0
   342
     __ASSERT_ALWAYS(self !=NULL, User::Panic(_L("CSMPSoakProcess::TimerThread Panic"),0));
sl@0
   343
     return self->DoTimerThread();
sl@0
   344
     }
sl@0
   345
//Member TimerThread
sl@0
   346
TInt CSMPSoakProcess::DoTimerThread()
sl@0
   347
	 {
sl@0
   348
 	 RTest test(_L("SMPSoakTimerThread"));
sl@0
   349
 	 
sl@0
   350
 	 RTimer timer;
sl@0
   351
 	 test_KErrNone(timer.CreateLocal());
sl@0
   352
 	 TRequestStatus status;
sl@0
   353
 	 
sl@0
   354
 	 FOREVER
sl@0
   355
 		{
sl@0
   356
 		timer.After(status, iThreadData.delayTime*1000);
sl@0
   357
 		User::WaitForRequest(status);
sl@0
   358
 		test(status == KErrNone);
sl@0
   359
 		PRINT((_L("$")));
sl@0
   360
 		SetThreadPriority();
sl@0
   361
 		if (gAbort)
sl@0
   362
 		    break;
sl@0
   363
 		User::After(gPeriod);
sl@0
   364
 		}
sl@0
   365
 	 
sl@0
   366
 	 timer.Close();
sl@0
   367
 	 return 0x00;
sl@0
   368
	 }
sl@0
   369
 
sl@0
   370
 //OOM Thread - produces out of memory condition on SMP threads run on different cpu cores
sl@0
   371
 //param aSoakThread - this pointer
sl@0
   372
 TInt CSMPSoakProcess::MemoryThread(TAny* aSoakThread)
sl@0
   373
     {
sl@0
   374
     CSMPSoakProcess* self = (CSMPSoakProcess*)aSoakThread;
sl@0
   375
     __ASSERT_ALWAYS(self !=NULL, User::Panic(_L("CSMPSoakProcess::MemoryThread Panic"),0));
sl@0
   376
     return self->DoMemoryThread();
sl@0
   377
     }
sl@0
   378
//Memory thread member
sl@0
   379
 TInt CSMPSoakProcess::DoMemoryThread()
sl@0
   380
     {
sl@0
   381
     RTest test(_L("SMPOOMemoryThread"));
sl@0
   382
     
sl@0
   383
     static TInt memOKCount =0;
sl@0
   384
     TAny* oomheap = NULL;
sl@0
   385
     TAny* prev = NULL;
sl@0
   386
     
sl@0
   387
     //Reserve the memory in heap
sl@0
   388
     RHeap* heap;
sl@0
   389
     heap = UserHeap::ChunkHeap(NULL, KHeapMinSize, KHeapMaxiSize);
sl@0
   390
     
sl@0
   391
     //Keep produce OOM condition and inform to other threads (run on different CPU cores)
sl@0
   392
     FOREVER
sl@0
   393
         {
sl@0
   394
          TInt allocsize = KHeapMaxiSize - KHeapReserveSize;
sl@0
   395
          
sl@0
   396
          if(memOKCount == iThreadData.numThreads-1)
sl@0
   397
              allocsize = KHeapMaxiSize;
sl@0
   398
     
sl@0
   399
          prev = oomheap;
sl@0
   400
          oomheap = heap->Alloc(allocsize);
sl@0
   401
          if(oomheap == NULL)
sl@0
   402
              {
sl@0
   403
              PRINT(_L("Out Of Memory\n"));
sl@0
   404
              heap->Free(prev);
sl@0
   405
              PRINT(_L("Recover Back Memory\n")); 
sl@0
   406
              memOKCount = 0;
sl@0
   407
              ooMemSem.Signal(iThreadData.numThreads - 1);
sl@0
   408
              }
sl@0
   409
          else
sl@0
   410
             {
sl@0
   411
             ++memOKCount;
sl@0
   412
             PRINT((_L("%d:Here MemOK\n"),memOKCount));
sl@0
   413
             ooMemSem.Wait();
sl@0
   414
             }
sl@0
   415
          //Change Thread Priority
sl@0
   416
          SetThreadPriority();
sl@0
   417
          if (gAbort)
sl@0
   418
             break;
sl@0
   419
          User::After(gPeriod);
sl@0
   420
         }
sl@0
   421
     if(heap != NULL)
sl@0
   422
     heap->Close();
sl@0
   423
     return 0x00;
sl@0
   424
     }
sl@0
   425
//Create thread
sl@0
   426
 void CSMPSoakProcess::CreateThread(TPtrC aThreadType)
sl@0
   427
     {
sl@0
   428
     if (aThreadType == _L("-W"))
sl@0
   429
         {
sl@0
   430
         CSMPSoakProcess smpipcwrite;
sl@0
   431
         smpipcwrite.WriteProcess();
sl@0
   432
         }
sl@0
   433
     else if (aThreadType == _L("-R"))
sl@0
   434
         {
sl@0
   435
         CSMPSoakProcess smpipcread;
sl@0
   436
         smpipcread.ReadProcess();
sl@0
   437
         }
sl@0
   438
     else if (aThreadType == _L("-F"))
sl@0
   439
         {
sl@0
   440
         CSMPSoakProcess smpfilethread[KNumFileThreads];
sl@0
   441
         for (TInt i = 0; i < KNumFileThreads; i++)
sl@0
   442
             smpfilethread[i].DoCreateThread(&KFileTable[i]);
sl@0
   443
         for (TInt i = 0; i < KNumFileThreads; i++)
sl@0
   444
             smpfilethread[i].ResumeThread();
sl@0
   445
         }
sl@0
   446
     else if (aThreadType == _L("-T"))
sl@0
   447
         {
sl@0
   448
         CSMPSoakProcess smptimerthread[KNumTimerThreads];
sl@0
   449
         for (TInt i = 0; i < KNumTimerThreads; i++)
sl@0
   450
             smptimerthread[i].DoCreateThread(&KTimerTable[i]);
sl@0
   451
         for (TInt i = 0; i < KNumTimerThreads; i++)
sl@0
   452
             smptimerthread[i].ResumeThread();
sl@0
   453
         }
sl@0
   454
     else if (aThreadType == _L("-O"))
sl@0
   455
         {
sl@0
   456
         CSMPSoakProcess smpoomthread[KNumOOMThreads];
sl@0
   457
         for (TInt i = 0; i < KNumOOMThreads; i++)
sl@0
   458
             smpoomthread[i].DoCreateThread(&KOOMemoryTable[i]);
sl@0
   459
         for (TInt i = 0; i < KNumOOMThreads; i++)
sl@0
   460
             smpoomthread[i].ResumeThread();
sl@0
   461
         }               
sl@0
   462
     /* else
sl@0
   463
          {
sl@0
   464
          test.Printf(_L("Invalid Argument for Soak Process \n"));
sl@0
   465
          test(EFalse);
sl@0
   466
          }*/
sl@0
   467
     }
sl@0
   468
//Command line arg to launch operation specific process
sl@0
   469
void ParseCmdLine()
sl@0
   470
	{
sl@0
   471
 	TBuf<256> cmd;
sl@0
   472
 	User::CommandLine(cmd);
sl@0
   473
 	TLex	lex(cmd);
sl@0
   474
 	PRINT ((_L("Command for Process = %s\n"), cmd.PtrZ()));
sl@0
   475
 	CSMPSoakProcess smpp;
sl@0
   476
 	FOREVER
sl@0
   477
 		{
sl@0
   478
 		TPtrC  token=lex.NextToken();
sl@0
   479
 		if(token.Length()!=0)
sl@0
   480
 			{   
sl@0
   481
               if (token.Length()==0)
sl@0
   482
 		            break;  // ignore trailing whitespace
sl@0
   483
 			   else if (token.Mid(0) == _L("-b"))
sl@0
   484
 			                {
sl@0
   485
 			                test.Printf(_L("SMPSOAKPROCESS: Silent Mode\n")); 
sl@0
   486
 			                TestSilent = ETrue;
sl@0
   487
 			                lex.SkipSpaceAndMark();
sl@0
   488
 			                token.Set(lex.NextToken());
sl@0
   489
 			                test.Printf(_L("-b Thread Type = %s\n"), token.Ptr());
sl@0
   490
 			                smpp.CreateThread(token);
sl@0
   491
 			                break;
sl@0
   492
 			                }
sl@0
   493
                else if (token.Left(2) == _L("-p"))
sl@0
   494
                            {
sl@0
   495
                            test.Printf(_L("SMPSOAKPROCESS: period\n"));
sl@0
   496
                            lex.SkipSpaceAndMark();
sl@0
   497
                            token.Set(lex.NextToken());
sl@0
   498
                            TLex lexNum(token);
sl@0
   499
                            lexNum.Val(gPeriod,EDecimal);    
sl@0
   500
                            test.Printf(_L("SMPSOAKPROCESS:period in mSeconds=%d \n"),gPeriod);  
sl@0
   501
                            token.Set(lex.NextToken());
sl@0
   502
                            test.Printf(_L("-p Thread Type = %s\n"), token.Ptr());
sl@0
   503
                            smpp.CreateThread(token);
sl@0
   504
                            break;
sl@0
   505
                            }
sl@0
   506
                else
sl@0
   507
                            {
sl@0
   508
                            test.Printf(_L("-d Thread Type = %s\n"), token.Ptr());
sl@0
   509
                            smpp.CreateThread(token);
sl@0
   510
                            break;
sl@0
   511
                            }
sl@0
   512
            }
sl@0
   513
 		 break;
sl@0
   514
 		}
sl@0
   515
	}
sl@0
   516
// Child process called by (T_SMPSOAK) Main Process
sl@0
   517
TInt E32Main() 
sl@0
   518
	{
sl@0
   519
    test.Title();
sl@0
   520
    __UHEAP_MARK;
sl@0
   521
    test.Start(_L("t_SMPSoakProcess.exe"));
sl@0
   522
    test.Next(_L("Load device driver"));
sl@0
   523
    TInt r = User::LoadLogicalDevice(_L("d_smpsoak.ldd"));
sl@0
   524
    if (r == KErrNotFound)
sl@0
   525
  		{
sl@0
   526
  		PRINT (_L("Test not supported on this platform because the D_SMPSOAK.LDD Driver is Not Present\n"));
sl@0
   527
   		test(EFalse);
sl@0
   528
   		}
sl@0
   529
    
sl@0
   530
    PRINT (_L("Calling SMPStressDrv.Open\n"));
sl@0
   531
  	r = gSMPStressDrv.Open();
sl@0
   532
  	test_KErrNone(r);
sl@0
   533
  	
sl@0
   534
  	PRINT (_L("Create/Open Global Write Semaphores\n"));
sl@0
   535
    r = gWriteSem.CreateGlobal(KGlobalWriteSem,0);
sl@0
   536
   	if (r==KErrAlreadyExists)
sl@0
   537
   		{
sl@0
   538
   		r = gWriteSem.OpenGlobal(KGlobalWriteSem);
sl@0
   539
   		}
sl@0
   540
   	if (r!=KErrNone)
sl@0
   541
   		{
sl@0
   542
   		PRINT ((_L("Error- OpenGlobal Write Semaphore:%d\n"),r));
sl@0
   543
   		test(EFalse);
sl@0
   544
   		}
sl@0
   545
  
sl@0
   546
   PRINT (_L("Create/Open Global Read Semaphores\n"));
sl@0
   547
   r = gReadSem.CreateGlobal(KGlobalReadSem,0);
sl@0
   548
   if (r==KErrAlreadyExists)
sl@0
   549
	   {
sl@0
   550
   	   r = gReadSem.OpenGlobal(KGlobalReadSem);
sl@0
   551
	   }
sl@0
   552
   if (r!=KErrNone)
sl@0
   553
	   {
sl@0
   554
	   PRINT( (_L("Error- OpenGlobal Read Semaphore:%d\n"),r));
sl@0
   555
	   test(EFalse);
sl@0
   556
	   }
sl@0
   557
   
sl@0
   558
   PRINT (_L("Creating Global Chunk\n"));
sl@0
   559
   r = gChunk.CreateGlobal(KGlobalWRChunk,KChunkSize,KChunkMaxSize);
sl@0
   560
   if(r==KErrAlreadyExists)
sl@0
   561
       {
sl@0
   562
       test_KErrNone( gChunk.OpenGlobal(KGlobalWRChunk,EFalse));
sl@0
   563
       }
sl@0
   564
  
sl@0
   565
   PRINT (_L("Creating local OOM Memory semaphore\n"));
sl@0
   566
   r=ooMemSem.CreateLocal(0);
sl@0
   567
   if (r!=KErrNone)
sl@0
   568
       {
sl@0
   569
       PRINT ((_L("Error- Creating local OOM Memory semaphore:%d\n"),r));
sl@0
   570
       test(EFalse);
sl@0
   571
       }
sl@0
   572
   
sl@0
   573
   ParseCmdLine();
sl@0
   574
   
sl@0
   575
   CActiveScheduler* myScheduler = new (ELeave) CActiveScheduler();
sl@0
   576
   test(myScheduler != NULL);
sl@0
   577
   CActiveScheduler::Install(myScheduler);
sl@0
   578
   CActiveScheduler::Start();
sl@0
   579
 
sl@0
   580
   ooMemSem.Close();
sl@0
   581
   gWriteSem.Close();
sl@0
   582
   gReadSem.Close();
sl@0
   583
   gChunk.Close();
sl@0
   584
   gSMPStressDrv.Close();
sl@0
   585
   CActiveScheduler::Stop();
sl@0
   586
   __UHEAP_MARKEND;
sl@0
   587
   test.End();
sl@0
   588
   return 0x00; 
sl@0
   589
	}
sl@0
   590
sl@0
   591
sl@0
   592
sl@0
   593
sl@0
   594
sl@0
   595
sl@0
   596