os/kernelhwsrv/kerneltest/e32test/emi/t_emi.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) 2005-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\emi\t_emi.cpp
sl@0
    15
// 
sl@0
    16
//
sl@0
    17
sl@0
    18
#include <e32test.h>
sl@0
    19
#include <e32math.h>
sl@0
    20
#include <e32def.h>
sl@0
    21
#include <e32def_private.h>
sl@0
    22
#include "d_emitest.h"
sl@0
    23
sl@0
    24
//#define VERBOSE
sl@0
    25
sl@0
    26
LOCAL_D RTest test(_L("T_EMI"));
sl@0
    27
sl@0
    28
_LIT(KEMITestLddFileName,"D_EMITEST");
sl@0
    29
const TInt KHeapSize=0x200;
sl@0
    30
sl@0
    31
REMITest Ldd;
sl@0
    32
sl@0
    33
sl@0
    34
/*
sl@0
    35
	TestEventLogging
sl@0
    36
	
sl@0
    37
	Tests initialisation of the logging system, ensuring no memory leaks, and then that user events can
sl@0
    38
	be added and read correctly.
sl@0
    39
	
sl@0
    40
	The test tries filling and emptying the buffer from each possible start position.
sl@0
    41
	Each time it over fills it (Causing offset to rotate) and each time try and take too many.
sl@0
    42
	The last record should show the event lost flag. Each field is checked for consistency.
sl@0
    43
sl@0
    44
*/
sl@0
    45
sl@0
    46
void TestEventLogging()
sl@0
    47
	{		
sl@0
    48
	TInt no;
sl@0
    49
	TInt i;
sl@0
    50
	TInt ii;
sl@0
    51
	TInt iii;
sl@0
    52
	TUint time;
sl@0
    53
	TInt wrapcount = 0;
sl@0
    54
	TInt changecount = 0;
sl@0
    55
 
sl@0
    56
	TUserTaskEventRecord outrec;
sl@0
    57
	TUserTaskEventRecord rec[5];
sl@0
    58
	TUserTaskEventRecord blank;
sl@0
    59
sl@0
    60
	
sl@0
    61
//! @SYMTestCaseID t_emi_0
sl@0
    62
//! @SYMTestType CT
sl@0
    63
//! @SYMTestCaseDesc Set/Get State
sl@0
    64
//! @SYMPREQ PREQ898
sl@0
    65
//! @SYMTestActions Sets the EMI user state randomly 100 times, and reads back the state. 
sl@0
    66
//! @SYMTestExpectedResults The read back state should always be the same as set.
sl@0
    67
//! @SYMTestPriority High
sl@0
    68
//! @SYMTestStatus Defined
sl@0
    69
	
sl@0
    70
	test.Next(_L("(Set/Get)State"));
sl@0
    71
	for (i=0; i<100; i++) 
sl@0
    72
		{
sl@0
    73
		no = Math::Random();	
sl@0
    74
		Ldd.SetState(no);
sl@0
    75
		test(Ldd.GetState()==no);
sl@0
    76
		}
sl@0
    77
	
sl@0
    78
//! @SYMTestCaseID t_emi_1
sl@0
    79
//! @SYMTestType CT
sl@0
    80
//! @SYMTestCaseDesc Log Alloc/Free
sl@0
    81
//! @SYMPREQ PREQ898
sl@0
    82
//! @SYMTestActions Allocates different sizes of event log.
sl@0
    83
//! @SYMTestExpectedResults No memory leak.
sl@0
    84
//! @SYMTestPriority High
sl@0
    85
//! @SYMTestStatus Defined
sl@0
    86
	
sl@0
    87
	test.Next(_L("TaskEventLogging - Log Alloc/Free"));
sl@0
    88
	
sl@0
    89
	__KHEAP_MARK;	
sl@0
    90
	test(Ldd.TaskEventLogging(EFalse,0,ENone)==KErrNone);
sl@0
    91
	test(Ldd.TaskEventLogging(EFalse,2,ENone)==KErrNone);
sl@0
    92
	test(Ldd.TaskEventLogging(EFalse,200,ENone)==KErrNone);
sl@0
    93
	test(Ldd.TaskEventLogging(EFalse,0,ENone)==KErrNone);
sl@0
    94
	__KHEAP_MARKEND;
sl@0
    95
sl@0
    96
#ifdef _DEBUG
sl@0
    97
	__KHEAP_MARK;
sl@0
    98
	__KHEAP_FAILNEXT(1);
sl@0
    99
	test(Ldd.TaskEventLogging(EFalse,200,ENone)==KErrNoMemory);
sl@0
   100
	__KHEAP_MARKEND;
sl@0
   101
#endif
sl@0
   102
sl@0
   103
sl@0
   104
//! @SYMTestCaseID t_emi_2
sl@0
   105
//! @SYMTestType CT
sl@0
   106
//! @SYMTestCaseDesc AddTaskEvent/GetTaskEvent
sl@0
   107
//! @SYMPREQ PREQ898
sl@0
   108
//! @SYMTestActions Tries filling and emptying the buffer from each possible start position. Each time it over fills it (Causing offset to rotate) and each time try and take too many.
sl@0
   109
//! @SYMTestExpectedResults The last record of each group should show the event lost flag.  Except for the lost record, the contents should be consistant with when the record was added.
sl@0
   110
//! @SYMTestPriority High
sl@0
   111
//! @SYMTestStatus Defined
sl@0
   112
sl@0
   113
	test.Next(_L("AddTaskEvent/GetTaskEvent"));
sl@0
   114
	
sl@0
   115
	test(!Ldd.GetTaskEvent(outrec));
sl@0
   116
sl@0
   117
	test(Ldd.TaskEventLogging(EFalse,5,ENone)==KErrNone);
sl@0
   118
	
sl@0
   119
	test(Ldd.AddTaskEvent(blank));
sl@0
   120
	test(Ldd.GetTaskEvent(outrec));
sl@0
   121
sl@0
   122
	time=outrec.iTime;
sl@0
   123
sl@0
   124
	test(!Ldd.GetTaskEvent(outrec));
sl@0
   125
		
sl@0
   126
	// This next test tries filling and emptying the buffer from each possible start position.
sl@0
   127
	// Each time it over fills it (Causeing offset to rotate) and each time try and take too many.
sl@0
   128
	// The last record should show the event lost flag.
sl@0
   129
		
sl@0
   130
	// To ensure the time field is samething like you'd expect, let it tick over by 50.
sl@0
   131
	iii=0;
sl@0
   132
	do 	
sl@0
   133
		{
sl@0
   134
		for (ii=0; ii<5; ii++) 
sl@0
   135
			{
sl@0
   136
			test(Ldd.AddTaskEvent(blank)); //will be lost
sl@0
   137
			for (i=0; i<5; i++)
sl@0
   138
				{
sl@0
   139
				rec[i].iType=(TUint8) ((Math::Random() & 255) | 128);
sl@0
   140
				rec[i].iFlags=0;
sl@0
   141
				rec[i].iExtra=(TUint16) (Math::Random() & 65535);
sl@0
   142
				rec[i].iPrevious=&rec[i];
sl@0
   143
				rec[i].iNext=&rec[ii];
sl@0
   144
				no = Math::Random();
sl@0
   145
				Ldd.SetState(no);
sl@0
   146
				test(Ldd.AddTaskEvent(rec[i]));
sl@0
   147
				rec[i].iUserState=no;
sl@0
   148
				}
sl@0
   149
			
sl@0
   150
			for (i=0; i<5; i++)
sl@0
   151
				{			
sl@0
   152
				test(Ldd.GetTaskEvent(outrec));
sl@0
   153
#ifdef VERBOSE
sl@0
   154
				test.Printf(_L("%x : Type %x(%x), Time %x, flag %x, ThdA %x ThdB %x\n"),i,outrec.iType,rec[i].iType,outrec.iTime, outrec.iFlags, outrec.iPrevious,outrec.iNext);
sl@0
   155
#endif
sl@0
   156
				if (i==0)
sl@0
   157
					test((outrec.iFlags & KEMI_EventLost)==KEMI_EventLost);
sl@0
   158
				else 
sl@0
   159
					test((outrec.iFlags & KEMI_EventLost)!=KEMI_EventLost);
sl@0
   160
				
sl@0
   161
				test(outrec.iType==rec[i].iType);
sl@0
   162
				test(outrec.iExtra==rec[i].iExtra);
sl@0
   163
				test(outrec.iPrevious==rec[i].iPrevious);
sl@0
   164
				test(outrec.iNext==rec[i].iNext);
sl@0
   165
				test(outrec.iUserState==rec[i].iUserState);
sl@0
   166
				if (outrec.iTime!=time)
sl@0
   167
					{
sl@0
   168
					if (outrec.iTime<time)
sl@0
   169
						wrapcount++;
sl@0
   170
					time=outrec.iTime;
sl@0
   171
					changecount++;
sl@0
   172
					}
sl@0
   173
				}
sl@0
   174
			test(!Ldd.GetTaskEvent(outrec));
sl@0
   175
			}
sl@0
   176
#ifdef VERBOSE
sl@0
   177
		test.Printf(_L("Time = %i\n"),time);
sl@0
   178
#endif
sl@0
   179
		iii++;		
sl@0
   180
		if (changecount<50)
sl@0
   181
			User::After(1);
sl@0
   182
		} while ((changecount<50) && (iii<50));
sl@0
   183
	test(changecount>=50);
sl@0
   184
	test(wrapcount<2);
sl@0
   185
	}
sl@0
   186
sl@0
   187
sl@0
   188
sl@0
   189
/* Used by 	TestStartStopMonitors() and	TestScheduleEventLogging() */
sl@0
   190
sl@0
   191
TBool ShortLivedThreadDone;
sl@0
   192
sl@0
   193
LOCAL_C TInt ShortLivedThread(TAny*)
sl@0
   194
	{
sl@0
   195
	int i;
sl@0
   196
	for (i=0; i<50; i++)
sl@0
   197
		User::After(1);
sl@0
   198
	ShortLivedThreadDone=ETrue;
sl@0
   199
	return(KErrNone);
sl@0
   200
	}
sl@0
   201
sl@0
   202
sl@0
   203
/*
sl@0
   204
  TestStartStopMonitors
sl@0
   205
  
sl@0
   206
  Checks Start monitor was iterated with current thread list on startup.
sl@0
   207
  It then creates and destroys a thread, and see if it triggered the
sl@0
   208
  monitor callbacks in the test driver.  The test driver will add
sl@0
   209
  events to the event log, which are read and checked.
sl@0
   210
sl@0
   211
*/
sl@0
   212
sl@0
   213
void TestStartStopMonitors()
sl@0
   214
	{	
sl@0
   215
	TInt i;
sl@0
   216
	TInt no;
sl@0
   217
	TUserTaskEventRecord outrec;
sl@0
   218
	RThread thread;
sl@0
   219
	TRequestStatus stat;		
sl@0
   220
	TAny* myNThread;
sl@0
   221
	TInt seenIdle;
sl@0
   222
	TInt seenSigma;
sl@0
   223
sl@0
   224
	TAny* idleThread;
sl@0
   225
	TAny* sigmaThread;
sl@0
   226
sl@0
   227
//! @SYMTestCaseID t_emi_5
sl@0
   228
//! @SYMTestType CT
sl@0
   229
//! @SYMTestCaseDesc Null/Sigma
sl@0
   230
//! @SYMPREQ PREQ898
sl@0
   231
//! @SYMTestActions Get the null and sigma thread pointers.
sl@0
   232
//! @SYMTestExpectedResults Non-null pointers, which are usable in the following tests.
sl@0
   233
//! @SYMTestPriority High
sl@0
   234
//! @SYMTestStatus Defined
sl@0
   235
sl@0
   236
sl@0
   237
	test.Next(_L("Check Null/Sigma"));
sl@0
   238
	sigmaThread=Ldd.GetSigmaThread();
sl@0
   239
	test(sigmaThread!=NULL);			
sl@0
   240
	
sl@0
   241
	idleThread=Ldd.GetIdleThread();
sl@0
   242
	test(idleThread!=NULL);	
sl@0
   243
sl@0
   244
	sigmaThread=((TInt*) sigmaThread)+1;
sl@0
   245
	idleThread=((TInt*) idleThread)+1;
sl@0
   246
sl@0
   247
//! @SYMTestCaseID t_emi_3
sl@0
   248
//! @SYMTestType CT
sl@0
   249
//! @SYMTestCaseDesc Thread start/stop Monitors
sl@0
   250
//! @SYMPREQ PREQ898
sl@0
   251
//! @SYMTestActions The start stop monitors are enabled.  The start/stop monitors have been made to add event log entries, to allow there execution to be visible. After all existing threads have be iterated by the start monitor, the log is first filled with random entries for the thread, and then the log is watched as a thread is started and stopped.
sl@0
   252
//! @SYMTestExpectedResults At least 15 threads should be iterated on activation, and then both monitors should be called for the new thread. The random entries should have changed to refer to the sigma thread.
sl@0
   253
//! @SYMTestPriority High
sl@0
   254
//! @SYMTestStatus Defined
sl@0
   255
sl@0
   256
	test.Next(_L("Thread start/stop Monitors"));
sl@0
   257
	for (i=0; i<3; i++)
sl@0
   258
		{
sl@0
   259
		test(Ldd.TaskEventLogging(EFalse,50,ENone)==KErrNone);
sl@0
   260
		test(Ldd.TaskEventLogging(EFalse,50,ENormal)==KErrNone);
sl@0
   261
	
sl@0
   262
sl@0
   263
		// Check Start monitor was iterated with current thread list.
sl@0
   264
		test.Printf(_L("Check start monitor called for theads. (try %d)\n"),i);
sl@0
   265
		
sl@0
   266
		seenIdle=0;
sl@0
   267
		seenSigma=0;	
sl@0
   268
sl@0
   269
		no=0;
sl@0
   270
		while (Ldd.GetTaskEvent(outrec))
sl@0
   271
			{
sl@0
   272
			test(outrec.iType==128);
sl@0
   273
			if (outrec.iPrevious==sigmaThread)
sl@0
   274
				{
sl@0
   275
				test.Printf(_L("Seen Sigma Thread\n"));	
sl@0
   276
				seenSigma++;
sl@0
   277
				}
sl@0
   278
			if (outrec.iPrevious==idleThread)
sl@0
   279
				{
sl@0
   280
				test.Printf(_L("Seen Idle Thread\n"));	
sl@0
   281
				seenIdle++;
sl@0
   282
				}
sl@0
   283
sl@0
   284
			no++;
sl@0
   285
			}
sl@0
   286
		test.Printf(_L("Records = %d\n"),no);	
sl@0
   287
		test(no>=15);
sl@0
   288
		test(seenSigma==1);
sl@0
   289
		test(seenIdle==1);
sl@0
   290
		}
sl@0
   291
		
sl@0
   292
		
sl@0
   293
		
sl@0
   294
	test.Next(_L("Check monitor behaviour on thead creation/deletion"));
sl@0
   295
sl@0
   296
	// To test monitors, we need to create and destroy a thread, and see if it 
sl@0
   297
	// triggered the callbacks in the test driver.  The test driver will add
sl@0
   298
	// events to the event log.
sl@0
   299
	
sl@0
   300
sl@0
   301
	// First Check for background noise
sl@0
   302
	for (i=0; i<50; i++)
sl@0
   303
		{		
sl@0
   304
		test(!Ldd.GetTaskEvent(outrec));
sl@0
   305
		User::After(1);
sl@0
   306
		}
sl@0
   307
		
sl@0
   308
	test.Printf(_L("Create Thread..\n"));
sl@0
   309
	// Start thread, and let it die
sl@0
   310
	
sl@0
   311
	test(thread.Create(_L("ShortLivedThread"),ShortLivedThread,KDefaultStackSize,KHeapSize,KHeapSize,NULL)==KErrNone);
sl@0
   312
	thread.Logon(stat);
sl@0
   313
	test(stat==KRequestPending);
sl@0
   314
	
sl@0
   315
	myNThread = Ldd.GetNThread(thread);
sl@0
   316
sl@0
   317
	// Fill with records - should not survive cleanup
sl@0
   318
	for (i=0; i<50; i++)
sl@0
   319
		{
sl@0
   320
		outrec.iType=(TUint8) (((Math::Random() & 63) + 10) | 128);
sl@0
   321
		
sl@0
   322
		outrec.iPrevious= i<5?myNThread:(TAny*) Math::Random();
sl@0
   323
		outrec.iNext= i>10?myNThread:(TAny*) Math::Random();
sl@0
   324
	
sl@0
   325
		test(Ldd.AddTaskEvent(outrec));
sl@0
   326
		}	
sl@0
   327
		
sl@0
   328
	// Let thead run
sl@0
   329
	thread.Resume();
sl@0
   330
	User::WaitForRequest(stat);
sl@0
   331
	thread.Close();
sl@0
   332
	test(Ldd.TaskEventLogging(EFalse,50,ENone)==KErrNone);
sl@0
   333
	
sl@0
   334
	// Did it leave log as expected?
sl@0
   335
	test.Printf(_L("Check for logging/Clearing\n"));
sl@0
   336
	i = 0;
sl@0
   337
	no=0;
sl@0
   338
	while (Ldd.GetTaskEvent(outrec)) 
sl@0
   339
		{
sl@0
   340
		i++;
sl@0
   341
#ifdef VERBOSE
sl@0
   342
		test.Printf(_L("%x : Type %x, Time %x,ThdA %x ThdB %x\n"),i,outrec.iType,outrec.iTime, outrec.iPrevious,outrec.iNext);
sl@0
   343
#endif
sl@0
   344
		if (outrec.iType==128) 
sl@0
   345
			{
sl@0
   346
			test((TInt)outrec.iPrevious==((TInt) myNThread)+4);
sl@0
   347
			no++;
sl@0
   348
			}
sl@0
   349
		if (outrec.iType==129)
sl@0
   350
			{				
sl@0
   351
			test(outrec.iPrevious==myNThread);
sl@0
   352
			no++;
sl@0
   353
			}
sl@0
   354
		else
sl@0
   355
			{
sl@0
   356
			test(outrec.iPrevious!=myNThread);
sl@0
   357
			test(outrec.iNext!=myNThread);				
sl@0
   358
			}
sl@0
   359
		}
sl@0
   360
	test (no==2);
sl@0
   361
	}
sl@0
   362
sl@0
   363
sl@0
   364
sl@0
   365
/* 
sl@0
   366
sl@0
   367
Thread Tracking functions, 
sl@0
   368
used in	TestScheduleEventLogging() and TestTagMaskDFC()
sl@0
   369
sl@0
   370
*/
sl@0
   371
sl@0
   372
struct TThreadList
sl@0
   373
	{
sl@0
   374
	TAny* iThread;
sl@0
   375
	TUint iRan;
sl@0
   376
	};
sl@0
   377
sl@0
   378
TThreadList ThreadList[51];
sl@0
   379
TInt NoThreads=0;
sl@0
   380
sl@0
   381
inline TUint LookupThread(TAny* aThread)
sl@0
   382
	{
sl@0
   383
	for (TInt i=0; i<NoThreads;i++)
sl@0
   384
		if (aThread==ThreadList[i].iThread)
sl@0
   385
			return i;
sl@0
   386
	if (NoThreads<49)
sl@0
   387
		{
sl@0
   388
			ThreadList[NoThreads].iThread=aThread;
sl@0
   389
			ThreadList[NoThreads].iRan=0;
sl@0
   390
			NoThreads++;
sl@0
   391
		
sl@0
   392
		}
sl@0
   393
	return NoThreads-1;	
sl@0
   394
	}
sl@0
   395
	
sl@0
   396
void AddThread(TAny* aThread) 
sl@0
   397
	{
sl@0
   398
	test(NoThreads<49);
sl@0
   399
	ThreadList[NoThreads].iThread=aThread;
sl@0
   400
	ThreadList[NoThreads].iRan=0;
sl@0
   401
	NoThreads++;
sl@0
   402
	}
sl@0
   403
sl@0
   404
sl@0
   405
/*
sl@0
   406
  TestScheduleEventLogging
sl@0
   407
  
sl@0
   408
  Checks AfterIdle, Null/Sigma thread lookup, Set/Get Loggable, as well as
sl@0
   409
  Schedule Event logging.  Select threads are marked as loggable, and starts a
sl@0
   410
  new thread (that repeatadly sleeps for short times, to generate events).
sl@0
   411
  The events are then collected and all of the fields checked.  The test
sl@0
   412
  
sl@0
   413
*/
sl@0
   414
sl@0
   415
void TestScheduleEventLogging()
sl@0
   416
	{	
sl@0
   417
	RThread thread;
sl@0
   418
	TRequestStatus stat;		
sl@0
   419
	TAny* myNThread;
sl@0
   420
	TInt i;
sl@0
   421
	TInt ii;
sl@0
   422
	TUint time=0;
sl@0
   423
	TInt wrapcount = 0;
sl@0
   424
	TInt changecount = 0;
sl@0
   425
	TUserTaskEventRecord outrec;
sl@0
   426
sl@0
   427
sl@0
   428
//! @SYMTestCaseID t_emi_4
sl@0
   429
//! @SYMTestType CT
sl@0
   430
//! @SYMTestCaseDesc AfterIdle
sl@0
   431
//! @SYMPREQ PREQ898
sl@0
   432
//! @SYMTestActions Uses AfterIdle.
sl@0
   433
//! @SYMTestExpectedResults No panic.
sl@0
   434
//! @SYMTestPriority High
sl@0
   435
//! @SYMTestStatus Defined
sl@0
   436
sl@0
   437
sl@0
   438
	test.Next(_L("Check AfterIdle"));
sl@0
   439
	Ldd.AfterIdle(100);
sl@0
   440
		
sl@0
   441
	
sl@0
   442
//! @SYMTestCaseID t_emi_6
sl@0
   443
//! @SYMTestType CT
sl@0
   444
//! @SYMTestCaseDesc Set/Get Loggable
sl@0
   445
//! @SYMPREQ PREQ898
sl@0
   446
//! @SYMTestActions Get/Set ThreadLoggable are used on multiple threads.
sl@0
   447
//! @SYMTestExpectedResults The Get function should confirm that the Set function changed the loggable state.
sl@0
   448
//! @SYMTestPriority High
sl@0
   449
//! @SYMTestStatus Defined
sl@0
   450
sl@0
   451
	test.Next(_L("Check Set/Get Loggable"));
sl@0
   452
	myNThread=Ldd.GetSigmaThread();
sl@0
   453
	test(myNThread!=NULL);		
sl@0
   454
	AddThread(myNThread);
sl@0
   455
		
sl@0
   456
	myNThread=Ldd.GetIdleThread();
sl@0
   457
	test(myNThread!=NULL);		
sl@0
   458
	AddThread(myNThread);
sl@0
   459
sl@0
   460
	
sl@0
   461
	Ldd.SetThreadLoggable(myNThread,ETrue);
sl@0
   462
	test(Ldd.GetThreadLoggable(myNThread)!=EFalse);
sl@0
   463
sl@0
   464
	Ldd.SetThreadLoggable(myNThread,EFalse);
sl@0
   465
	test(Ldd.GetThreadLoggable(myNThread)==EFalse);
sl@0
   466
sl@0
   467
	Ldd.SetThreadLoggable(myNThread,ETrue);
sl@0
   468
	test(Ldd.GetThreadLoggable(myNThread)!=EFalse);
sl@0
   469
		
sl@0
   470
	
sl@0
   471
//! @SYMTestCaseID t_emi_7
sl@0
   472
//! @SYMTestType CT
sl@0
   473
//! @SYMTestCaseDesc Set/Get VEMSData
sl@0
   474
//! @SYMPREQ PREQ898
sl@0
   475
//! @SYMTestActions Get/Set VEMSData are used on a thread 100 times.
sl@0
   476
//! @SYMTestExpectedResults The Get function should confirm that the Set function set the value correctly.
sl@0
   477
//! @SYMTestPriority High
sl@0
   478
//! @SYMTestStatus Defined
sl@0
   479
sl@0
   480
	
sl@0
   481
	test.Next(_L("(Set/Get) VEMSData"));
sl@0
   482
	
sl@0
   483
	test.Printf(_L("Spawn Thread\n"));
sl@0
   484
	ShortLivedThreadDone=EFalse;
sl@0
   485
	test(thread.Create(_L("ShortLivedThread"),ShortLivedThread,KDefaultStackSize,KHeapSize,KHeapSize,NULL)==KErrNone);
sl@0
   486
	thread.Logon(stat);
sl@0
   487
	test(stat==KRequestPending);	
sl@0
   488
	myNThread = Ldd.GetNThread(thread);
sl@0
   489
	Ldd.SetThreadLoggable(myNThread,ETrue);
sl@0
   490
	AddThread(myNThread);
sl@0
   491
	test(Ldd.GetThreadLoggable(myNThread)!=EFalse);
sl@0
   492
sl@0
   493
	for (i=0; i<100; i++) 
sl@0
   494
		{
sl@0
   495
		ii = Math::Random();
sl@0
   496
		Ldd.SetVEMSData(myNThread,(TAny*)ii);
sl@0
   497
		test((TInt)Ldd.GetVEMSData(myNThread)==ii);
sl@0
   498
		}
sl@0
   499
sl@0
   500
//! @SYMTestCaseID t_emi_8
sl@0
   501
//! @SYMTestType CT
sl@0
   502
//! @SYMTestCaseDesc Task Event Logging
sl@0
   503
//! @SYMPREQ PREQ898
sl@0
   504
//! @SYMTestActions Task event logging is turned on, with a thread running in the background. Some threads set as loggable. Each event record is inspected, and a count for the seen thread in incremented. User state is incremented on each iteration.
sl@0
   505
//! @SYMTestExpectedResults Each thread ran at lest 10 times.  Time changed over 45 times, but wrapped no more then once. User state changed over 15, some events where seen to be waiting, thread order is consistent, record type is correct, and at lest 100 records where read before the test finished.
sl@0
   506
//! @SYMTestPriority High
sl@0
   507
//! @SYMTestStatus Defined
sl@0
   508
sl@0
   509
sl@0
   510
		
sl@0
   511
	test.Next(_L("Task Event Logging"));	
sl@0
   512
	
sl@0
   513
	Ldd.SetState(0);
sl@0
   514
	thread.Resume();
sl@0
   515
	User::After(1);
sl@0
   516
	test(Ldd.TaskEventLogging(ETrue,50,ENone)==KErrNone);
sl@0
   517
	i=0;
sl@0
   518
	ii=0;
sl@0
   519
	TInt prevNextThread=-1;
sl@0
   520
	TInt lastThread;
sl@0
   521
	TInt nextThread;
sl@0
   522
	TBool seenWaiting=EFalse;
sl@0
   523
	wrapcount=0;
sl@0
   524
	changecount=0;
sl@0
   525
	TUint lastUserState=0;
sl@0
   526
	TInt userStateChange=0;
sl@0
   527
	FOREVER
sl@0
   528
		{
sl@0
   529
		
sl@0
   530
		if (!Ldd.GetTaskEvent(outrec))
sl@0
   531
			{			
sl@0
   532
			if ((i>100) && ShortLivedThreadDone)
sl@0
   533
				break;
sl@0
   534
			Ldd.AfterIdle(5);
sl@0
   535
			test((ii++)<500); //timeout!
sl@0
   536
			}
sl@0
   537
		else
sl@0
   538
			{
sl@0
   539
			lastThread=LookupThread(outrec.iPrevious);
sl@0
   540
			nextThread=LookupThread(outrec.iNext);
sl@0
   541
#ifdef VERBOSE
sl@0
   542
			test.Printf(_L("%x: Ty %x Tm %x ThdA %x ThdB %x F %x U %x\n"),
sl@0
   543
				i,outrec.iType,outrec.iTime, lastThread,nextThread, outrec.iFlags, outrec.iUserState);
sl@0
   544
#endif
sl@0
   545
			test(outrec.iType==0);
sl@0
   546
			
sl@0
   547
			
sl@0
   548
			if (outrec.iTime!=time)
sl@0
   549
				{
sl@0
   550
				if ((outrec.iTime<time) && (time!=0))
sl@0
   551
					wrapcount++;
sl@0
   552
				time=outrec.iTime;
sl@0
   553
				changecount++;
sl@0
   554
				}			
sl@0
   555
			
sl@0
   556
			if ((outrec.iFlags & KEMI_PrevWaiting)!=0)
sl@0
   557
				seenWaiting=ETrue;
sl@0
   558
			
sl@0
   559
			if (((outrec.iFlags & KEMI_EventLost)==0) && (prevNextThread!=-1))
sl@0
   560
				test (prevNextThread==lastThread);
sl@0
   561
			prevNextThread=nextThread;
sl@0
   562
			ThreadList[nextThread].iRan++;
sl@0
   563
sl@0
   564
			test(outrec.iUserState>=lastUserState);
sl@0
   565
			if (outrec.iUserState!=lastUserState)
sl@0
   566
				{
sl@0
   567
				userStateChange++;
sl@0
   568
				lastUserState=outrec.iUserState;
sl@0
   569
				}
sl@0
   570
sl@0
   571
			i++;
sl@0
   572
			Ldd.SetState(i);
sl@0
   573
			}
sl@0
   574
		if ((i>100) && ShortLivedThreadDone)
sl@0
   575
			test(Ldd.TaskEventLogging(EFalse,50,ENone)==KErrNone);			
sl@0
   576
		}
sl@0
   577
sl@0
   578
	test.Printf(_L("DTime %x DState %x Wrap %x\n"),changecount,userStateChange, wrapcount);
sl@0
   579
sl@0
   580
	test(changecount>=45);
sl@0
   581
	test(userStateChange>15);
sl@0
   582
	test(wrapcount<2);
sl@0
   583
		
sl@0
   584
	test(seenWaiting);
sl@0
   585
	
sl@0
   586
	User::WaitForRequest(stat);
sl@0
   587
	thread.Close();
sl@0
   588
	
sl@0
   589
	for (i=0; i<NoThreads;i++)
sl@0
   590
		{		
sl@0
   591
		test.Printf(_L("Thread %x ran %d times.\n"),i,ThreadList[i].iRan);
sl@0
   592
		test(ThreadList[i].iRan>10);
sl@0
   593
		}
sl@0
   594
	}
sl@0
   595
sl@0
   596
sl@0
   597
sl@0
   598
sl@0
   599
/* TagMaskTestThread() - used by TestTagMaskDFC */
sl@0
   600
LOCAL_C TInt TagMaskTestThread(TAny*)
sl@0
   601
	{
sl@0
   602
	TInt i;
sl@0
   603
	TInt mask=1;
sl@0
   604
	for (i=0; i<31; i++)
sl@0
   605
		{		
sl@0
   606
		User::After(1);
sl@0
   607
		mask = mask << 1;
sl@0
   608
		Ldd.SetMask(mask);
sl@0
   609
		}
sl@0
   610
	ShortLivedThreadDone=ETrue;
sl@0
   611
	return(KErrNone);
sl@0
   612
	}
sl@0
   613
sl@0
   614
/*
sl@0
   615
  TestTagMaskDFC()
sl@0
   616
sl@0
   617
  Checks Mask and Tag setting.
sl@0
   618
  Checks a that a DFC (found in driver) is triggered my an apropriate tag and mask.
sl@0
   619
*/
sl@0
   620
sl@0
   621
void TestTagMaskDFC()
sl@0
   622
	{	
sl@0
   623
	RThread thread;
sl@0
   624
	TRequestStatus stat;		
sl@0
   625
	TAny* myNThread;
sl@0
   626
	TUserTaskEventRecord outrec;
sl@0
   627
	TInt i=0;
sl@0
   628
	TInt ii=0;
sl@0
   629
	TInt seen9=0;
sl@0
   630
	TInt seen18=0;
sl@0
   631
	TInt seen27=0;	
sl@0
   632
	TUint no;
sl@0
   633
	
sl@0
   634
#ifdef VERBOSE	
sl@0
   635
	TInt lastThread;
sl@0
   636
#endif	
sl@0
   637
	TInt nextThread;
sl@0
   638
sl@0
   639
sl@0
   640
//! @SYMTestCaseID t_emi_9
sl@0
   641
//! @SYMTestType CT
sl@0
   642
//! @SYMTestCaseDesc Set/Get Mask
sl@0
   643
//! @SYMPREQ PREQ898
sl@0
   644
//! @SYMTestActions Get/Set the mask 100 times.
sl@0
   645
//! @SYMTestExpectedResults The Get function should confirm that the Set function changed the mask state.
sl@0
   646
//! @SYMTestPriority High
sl@0
   647
//! @SYMTestStatus Defined
sl@0
   648
sl@0
   649
sl@0
   650
	test.Next(_L("(Set/Get)Mask"));
sl@0
   651
	for (i=0; i<100; i++) 
sl@0
   652
		{
sl@0
   653
		no = Math::Random();
sl@0
   654
		Ldd.SetMask(no);
sl@0
   655
		test(Ldd.GetMask()==no);
sl@0
   656
		}
sl@0
   657
sl@0
   658
//! @SYMTestCaseID t_emi_10
sl@0
   659
//! @SYMTestType CT
sl@0
   660
//! @SYMTestCaseDesc Tag/Mask DFC
sl@0
   661
//! @SYMPREQ PREQ898
sl@0
   662
//! @SYMTestActions A DFC is set than will change the user state to the results of GetDFCTriggerTag.  The event log is monitored, with a background thread, which has had a tag set.  This thread repeatedly changes the mask.
sl@0
   663
//! @SYMTestExpectedResults The state should be seen to change once to the correct tag for the thread.  Other factors also checked in t_emi_7 should show the test running correctly.
sl@0
   664
//! @SYMTestPriority High
sl@0
   665
//! @SYMTestStatus Defined
sl@0
   666
sl@0
   667
sl@0
   668
	test.Next(_L("Tag/Mask DFC."));
sl@0
   669
	
sl@0
   670
	NoThreads=0; // Reset Thread Tracking
sl@0
   671
	
sl@0
   672
	myNThread=Ldd.GetSigmaThread();
sl@0
   673
	test(myNThread!=NULL);		
sl@0
   674
	AddThread(myNThread);
sl@0
   675
	
sl@0
   676
	myNThread=Ldd.GetIdleThread();
sl@0
   677
	test(myNThread!=NULL);		
sl@0
   678
	AddThread(myNThread);
sl@0
   679
	
sl@0
   680
	Ldd.SetThreadLoggable(myNThread,ETrue);
sl@0
   681
	test(Ldd.GetThreadLoggable(myNThread)!=EFalse);
sl@0
   682
		
sl@0
   683
	Ldd.SetDfc();
sl@0
   684
	test(Ldd.GetMask()==0);
sl@0
   685
	
sl@0
   686
	test.Printf(_L("Spawn Thread\n"));
sl@0
   687
	ShortLivedThreadDone=EFalse;
sl@0
   688
	test(thread.Create(_L("TagMaskTestThread"),TagMaskTestThread,KDefaultStackSize,KHeapSize,KHeapSize,NULL)==KErrNone);
sl@0
   689
	thread.Logon(stat);
sl@0
   690
	test(stat==KRequestPending);	
sl@0
   691
	myNThread = Ldd.GetNThread(thread);
sl@0
   692
	test(Ldd.GetThreadLoggable(myNThread)==EFalse);
sl@0
   693
	Ldd.SetThreadLoggable(myNThread,ETrue);
sl@0
   694
	test(Ldd.GetThreadLoggable(myNThread)!=EFalse);
sl@0
   695
	AddThread(myNThread);
sl@0
   696
	Ldd.SetThreadTag(myNThread,(1<<9)+(1<<18)+(1<<27));
sl@0
   697
	test(Ldd.GetThreadTag(myNThread)==(1<<9)+(1<<18)+(1<<27));
sl@0
   698
	
sl@0
   699
	Ldd.SetState(0);
sl@0
   700
	
sl@0
   701
	test.Printf(_L("Start Event Logging\n"));
sl@0
   702
	test(Ldd.TaskEventLogging(ETrue,50,ENone)==KErrNone);
sl@0
   703
sl@0
   704
	thread.Resume();
sl@0
   705
	
sl@0
   706
	FOREVER
sl@0
   707
		{		
sl@0
   708
		if (!Ldd.GetTaskEvent(outrec))
sl@0
   709
			{			
sl@0
   710
			if ((i>100) && ShortLivedThreadDone)
sl@0
   711
				break;
sl@0
   712
			Ldd.AfterIdle(5);
sl@0
   713
			test((ii++)<500); //timeout!
sl@0
   714
			}
sl@0
   715
		else
sl@0
   716
			{
sl@0
   717
sl@0
   718
#ifdef VERBOSE
sl@0
   719
			lastThread=LookupThread(outrec.iPrevious);
sl@0
   720
#else
sl@0
   721
			LookupThread(outrec.iPrevious);
sl@0
   722
#endif
sl@0
   723
			nextThread=LookupThread(outrec.iNext);
sl@0
   724
			
sl@0
   725
#ifdef VERBOSE
sl@0
   726
			test.Printf(_L("%x: Ty %x Tm %x ThdA %x ThdB %x F %x U %x\n"),
sl@0
   727
				i,outrec.iType,outrec.iTime, lastThread,nextThread, outrec.iFlags, outrec.iUserState);
sl@0
   728
#endif
sl@0
   729
sl@0
   730
			ThreadList[nextThread].iRan++;
sl@0
   731
				
sl@0
   732
			switch(outrec.iUserState)
sl@0
   733
				{
sl@0
   734
				case 0      : break;
sl@0
   735
				case (1<<9) : ++seen9; break;
sl@0
   736
				case (1<<18): ++seen18; break;
sl@0
   737
				case (1<<27): ++seen27; break;
sl@0
   738
				default: test(0); // bad state
sl@0
   739
				}
sl@0
   740
			}
sl@0
   741
		i++;		
sl@0
   742
		if ((i>100) && ShortLivedThreadDone)
sl@0
   743
			test(Ldd.TaskEventLogging(EFalse,50,ENone)==KErrNone);
sl@0
   744
		
sl@0
   745
		}
sl@0
   746
	Ldd.SetMask(0);
sl@0
   747
sl@0
   748
	test(seen9);
sl@0
   749
	test(seen18);
sl@0
   750
	test(seen27);
sl@0
   751
	User::WaitForRequest(stat);
sl@0
   752
	thread.Close();
sl@0
   753
		
sl@0
   754
	for (i=0; i<NoThreads;i++)
sl@0
   755
		{		
sl@0
   756
		test.Printf(_L("Thread %x ran %d times.\n"),i,ThreadList[i].iRan);
sl@0
   757
		test(ThreadList[i].iRan>10);
sl@0
   758
		}
sl@0
   759
	test(Ldd.TaskEventLogging(EFalse,0,ENone)==KErrNone);	
sl@0
   760
	}
sl@0
   761
sl@0
   762
sl@0
   763
/*
sl@0
   764
void SoakTest()
sl@0
   765
sl@0
   766
Repeatedly changes the start/exit monitors, while repeatedly starting and stopping threads.
sl@0
   767
As threads exit, they are checked for consistency.
sl@0
   768
sl@0
   769
*/
sl@0
   770
sl@0
   771
TBool FinishedSoak=EFalse;
sl@0
   772
TBool Going=EFalse;
sl@0
   773
LOCAL_C TInt SoakTest_Thread(TAny*)
sl@0
   774
	{
sl@0
   775
	int i;
sl@0
   776
	Going=ETrue;
sl@0
   777
	for (i=(Math::Random() & 1); i<2; i++)
sl@0
   778
			User::AfterHighRes(1000+(Math::Random() & 31));
sl@0
   779
	return(KErrNone);
sl@0
   780
	}
sl@0
   781
sl@0
   782
TInt MainCount=0;
sl@0
   783
TInt ThreadGenCount=0;
sl@0
   784
TInt Maxloops=4100;
sl@0
   785
TBool Forever=EFalse;
sl@0
   786
TInt State=1;
sl@0
   787
TInt GoodCount=0;
sl@0
   788
sl@0
   789
LOCAL_C TInt SoakTest_ThreadGenerator(TAny*)
sl@0
   790
	{
sl@0
   791
	const TInt NOTHREADS=100;
sl@0
   792
sl@0
   793
	RThread threadlist[NOTHREADS];
sl@0
   794
	TRequestStatus threadlist_stat[NOTHREADS];
sl@0
   795
	TInt head=0;
sl@0
   796
	TInt tail=0;
sl@0
   797
	TBool done=EFalse;
sl@0
   798
	TInt newHead;
sl@0
   799
	RThread thisThread = RThread();
sl@0
   800
	FOREVER
sl@0
   801
		{
sl@0
   802
		
sl@0
   803
		switch (Math::Random() & 63) 
sl@0
   804
			{
sl@0
   805
			case 1: thisThread.SetPriority(EPriorityLess);
sl@0
   806
			break;
sl@0
   807
			case 2: thisThread.SetPriority(EPriorityNormal);
sl@0
   808
			break;
sl@0
   809
			case 3: thisThread.SetPriority(EPriorityMore);
sl@0
   810
			break;
sl@0
   811
			}
sl@0
   812
			
sl@0
   813
		newHead = head+1;
sl@0
   814
		if (newHead==NOTHREADS)
sl@0
   815
			newHead=0;
sl@0
   816
		if ((newHead!=tail) &&  !done) //not full & not finished
sl@0
   817
			{
sl@0
   818
			test(threadlist[head].Create(_L(""),SoakTest_Thread,KDefaultStackSize,NULL,NULL)==KErrNone);
sl@0
   819
			threadlist[head].Logon(threadlist_stat[head]);
sl@0
   820
			switch (Math::Random() & 3) 
sl@0
   821
				{
sl@0
   822
				case 1: threadlist[head].SetPriority(EPriorityLess);
sl@0
   823
				break;
sl@0
   824
				case 2: threadlist[head].SetPriority(EPriorityNormal);
sl@0
   825
				break;
sl@0
   826
				case 3: threadlist[head].SetPriority(EPriorityMore);
sl@0
   827
				break;
sl@0
   828
				}
sl@0
   829
sl@0
   830
			threadlist[head].Resume();
sl@0
   831
			head=newHead;
sl@0
   832
			}
sl@0
   833
		else
sl@0
   834
			{
sl@0
   835
			if (head==tail)//empty
sl@0
   836
				{
sl@0
   837
				
sl@0
   838
				if (done)
sl@0
   839
					break;			
sl@0
   840
				}
sl@0
   841
sl@0
   842
			else
sl@0
   843
				{				
sl@0
   844
				User::WaitForRequest(threadlist_stat[tail] );
sl@0
   845
	
sl@0
   846
				if (State==1)
sl@0
   847
					{
sl@0
   848
					State=(TInt) Ldd.GetVEMSData(Ldd.GetNThread(threadlist[tail]));
sl@0
   849
					if (State!=1)
sl@0
   850
						done=ETrue;
sl@0
   851
					else
sl@0
   852
						GoodCount++;
sl@0
   853
					}
sl@0
   854
				threadlist[tail].Close();
sl@0
   855
				tail++;
sl@0
   856
				if (tail==NOTHREADS)
sl@0
   857
					tail=0;
sl@0
   858
				}					
sl@0
   859
			}
sl@0
   860
		if ((Math::Random() & 63)==1)
sl@0
   861
				User::AfterHighRes((Math::Random() & 32));
sl@0
   862
		ThreadGenCount=MainCount;
sl@0
   863
		if ((ThreadGenCount>=Maxloops) && !Forever)
sl@0
   864
			done=ETrue;
sl@0
   865
		}
sl@0
   866
	FinishedSoak=ETrue;
sl@0
   867
	return(KErrNone);
sl@0
   868
	}
sl@0
   869
sl@0
   870
sl@0
   871
void SoakTest()
sl@0
   872
	{
sl@0
   873
	RThread threadGenerator;
sl@0
   874
	TRequestStatus stat;
sl@0
   875
	TInt count=0;
sl@0
   876
	TInt oldcount=0;
sl@0
   877
	RThread thisThread = RThread();
sl@0
   878
	TInt ret;
sl@0
   879
	TMonitors monitor=EStressSecond;
sl@0
   880
sl@0
   881
	test.Next(_L("Repeated monitor switching Test"));
sl@0
   882
	test(Ldd.TaskEventLogging(EFalse,0,EStressSecond)==KErrNone);
sl@0
   883
sl@0
   884
	for (count=1; count<100; count++) 
sl@0
   885
		{
sl@0
   886
		
sl@0
   887
		Going=EFalse;
sl@0
   888
		test(threadGenerator.Create(_L(""),SoakTest_Thread,KDefaultStackSize,NULL,NULL)==KErrNone);
sl@0
   889
		threadGenerator.Logon(stat);
sl@0
   890
		test(stat==KRequestPending);	
sl@0
   891
		threadGenerator.Resume();
sl@0
   892
		while (!Going)	User::AfterHighRes(Math::Random() & 15);
sl@0
   893
sl@0
   894
		monitor= (monitor==EStressFirst)?EStressSecond:EStressFirst;
sl@0
   895
		test(Ldd.TaskEventLogging(EFalse,0,monitor)==KErrNone);
sl@0
   896
		
sl@0
   897
		if (count & 1)
sl@0
   898
			{
sl@0
   899
			monitor= (monitor==EStressFirst)?EStressSecond:EStressFirst;
sl@0
   900
			test(Ldd.TaskEventLogging(EFalse,0,monitor)==KErrNone);
sl@0
   901
			}
sl@0
   902
		User::WaitForRequest(stat);
sl@0
   903
		ret=(TInt) Ldd.GetVEMSData(Ldd.GetNThread(threadGenerator));
sl@0
   904
		if (ret!=1)
sl@0
   905
			test.Printf(_L("Thread %x had VEMs value was %x \n"),count,ret);
sl@0
   906
		threadGenerator.Close();
sl@0
   907
		test(ret==1);
sl@0
   908
		}
sl@0
   909
sl@0
   910
sl@0
   911
	// Full soak test
sl@0
   912
	
sl@0
   913
	count=1;
sl@0
   914
	test.Next(_L("Soak test"));
sl@0
   915
	test(Ldd.TaskEventLogging(EFalse,0,EStressSecond)==KErrNone);
sl@0
   916
sl@0
   917
	// Start threadGenerator
sl@0
   918
	test(threadGenerator.Create(_L("threadGenerator"),SoakTest_ThreadGenerator,KDefaultStackSize,KHeapSize,KHeapSize,NULL)==KErrNone);
sl@0
   919
	threadGenerator.Logon(stat);
sl@0
   920
	test(stat==KRequestPending);	
sl@0
   921
	threadGenerator.Resume();
sl@0
   922
	
sl@0
   923
	for (;!FinishedSoak; MainCount=ThreadGenCount+1) 
sl@0
   924
		{
sl@0
   925
			switch (Math::Random() & 63) 
sl@0
   926
			{
sl@0
   927
			case 1: thisThread.SetPriority(EPriorityLess);
sl@0
   928
			break;
sl@0
   929
			case 2: thisThread.SetPriority(EPriorityNormal);
sl@0
   930
			break;
sl@0
   931
			case 3: thisThread.SetPriority(EPriorityMore);
sl@0
   932
			break;
sl@0
   933
			}
sl@0
   934
sl@0
   935
		// Now repeatadly start and stop the start/exit monitors.
sl@0
   936
		test(Ldd.TaskEventLogging(EFalse,0,EStressFirst)==KErrNone);
sl@0
   937
		if ((Math::Random() & 63)==1)
sl@0
   938
				User::AfterHighRes((Math::Random() & 31));
sl@0
   939
		test(Ldd.TaskEventLogging(EFalse,0,EStressSecond)==KErrNone);
sl@0
   940
		if (MainCount>>7 != oldcount)
sl@0
   941
			{	
sl@0
   942
			oldcount=MainCount>>7;
sl@0
   943
			if ((count & 15)==1)
sl@0
   944
				test.Printf(_L("\nCount: "));			
sl@0
   945
			test.Printf(_L("%x "),count);
sl@0
   946
	
sl@0
   947
			count++;
sl@0
   948
			}
sl@0
   949
		if ((Math::Random() & 63)==1)
sl@0
   950
			User::AfterHighRes((Math::Random() & 31));
sl@0
   951
		}
sl@0
   952
		
sl@0
   953
	test.Printf(_L("\nDone.\n: "));	
sl@0
   954
	User::WaitForRequest(stat);
sl@0
   955
	threadGenerator.Close();
sl@0
   956
	if (State!=1)
sl@0
   957
		{
sl@0
   958
		test.Printf(_L("Thread %x VEMs value was %x \n"),GoodCount,State);
sl@0
   959
		test(0);
sl@0
   960
		}
sl@0
   961
sl@0
   962
	test(Ldd.TaskEventLogging(EFalse,0,ENone)==KErrNone);
sl@0
   963
	}
sl@0
   964
sl@0
   965
void ParseCommandLine()
sl@0
   966
	{
sl@0
   967
	TBuf<32> args;
sl@0
   968
	User::CommandLine(args);
sl@0
   969
	
sl@0
   970
	if (args == KNullDesC)
sl@0
   971
		{
sl@0
   972
		test.Printf(_L("No soaklength specified, using default.\n"));
sl@0
   973
		return;
sl@0
   974
		}
sl@0
   975
	else if (args == _L("-"))
sl@0
   976
		{
sl@0
   977
		test.Printf(_L("Infinate soaklength specified.\n"));
sl@0
   978
sl@0
   979
		Forever=ETrue;
sl@0
   980
		}
sl@0
   981
	else 
sl@0
   982
		{
sl@0
   983
		TLex l(args);
sl@0
   984
		TInt r = l.Val(Maxloops);
sl@0
   985
		if (r != KErrNone)
sl@0
   986
			{
sl@0
   987
			test.Printf(_L("Bad parameter!\nUsage: t_emi <soaklength>\n       '-' indicates infinity.\n\n"));
sl@0
   988
			User::After(4000000);
sl@0
   989
			test(0);
sl@0
   990
			}
sl@0
   991
		else
sl@0
   992
			{
sl@0
   993
			test.Printf(_L("Soaklength set to 0x%x\n"),Maxloops);
sl@0
   994
			Maxloops = Maxloops << 7;
sl@0
   995
			}
sl@0
   996
sl@0
   997
		}
sl@0
   998
	}
sl@0
   999
sl@0
  1000
/* 
sl@0
  1001
 E32Main - Where it all begins.
sl@0
  1002
*/
sl@0
  1003
sl@0
  1004
GLDEF_C TInt E32Main()
sl@0
  1005
	{
sl@0
  1006
	TInt r;
sl@0
  1007
sl@0
  1008
	test.Title();
sl@0
  1009
	ParseCommandLine();
sl@0
  1010
sl@0
  1011
	test.Start(_L("Loading Device"));
sl@0
  1012
sl@0
  1013
	r=User::LoadLogicalDevice(KEMITestLddFileName);
sl@0
  1014
	test(r==KErrNone || r==KErrAlreadyExists);
sl@0
  1015
sl@0
  1016
	test.Next(_L("Open Logical Channel"));
sl@0
  1017
	r=Ldd.Open();
sl@0
  1018
	test(r==KErrNone);
sl@0
  1019
	
sl@0
  1020
	
sl@0
  1021
	test.Next(_L("Calling LDD"));
sl@0
  1022
sl@0
  1023
	if(Ldd.TaskEventLogging(EFalse,0,ENone)==KErrNotSupported)
sl@0
  1024
		{
sl@0
  1025
		test.Printf(_L("********************\n"));
sl@0
  1026
		test.Printf(_L("*  NO EMI SUPPORT  *\n"));
sl@0
  1027
		test.Printf(_L("********************\n"));
sl@0
  1028
		test.Printf(_L("*  Testing SKIPPED *\n"));
sl@0
  1029
		test.Printf(_L("********************\n"));
sl@0
  1030
		User::After(2000000);  //Time to read it!
sl@0
  1031
		test.Next(_L("Close Logical Channel"));
sl@0
  1032
		Ldd.Close();
sl@0
  1033
		test.End();
sl@0
  1034
		return(0);
sl@0
  1035
		}
sl@0
  1036
sl@0
  1037
	// Start Testing!
sl@0
  1038
	
sl@0
  1039
	TestEventLogging();
sl@0
  1040
	TestStartStopMonitors();
sl@0
  1041
	TestScheduleEventLogging();		
sl@0
  1042
	TestTagMaskDFC();
sl@0
  1043
	SoakTest();
sl@0
  1044
sl@0
  1045
	test.Next(_L("Close Logical Channel"));
sl@0
  1046
	Ldd.Close();
sl@0
  1047
	test.End();
sl@0
  1048
sl@0
  1049
	return(0);
sl@0
  1050
	}