os/kernelhwsrv/kerneltest/f32test/bench/t_notify_perf_impl.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) 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
// f32test\bench\t_notify_perf_impl.cpp
sl@0
    15
// 
sl@0
    16
//
sl@0
    17
sl@0
    18
#include "t_notify_perf.h"
sl@0
    19
#include "t_server.h"
sl@0
    20
sl@0
    21
extern void FileNameGen(TFileName& aName, TInt aNum, TBool aIsFile = ETrue);
sl@0
    22
extern TInt FileOperationThread(TAny* aSetting);
sl@0
    23
extern TInt NotificationOperationThread(TAny* aSetting);
sl@0
    24
extern TInt KillerThread(TAny*);
sl@0
    25
extern TUint OpNotifyMapping(TUint16& aOption, TInt aOperation);
sl@0
    26
extern TBool CompareEntryName(const TEntry& aEntry1, const TEntry& aEntry2);
sl@0
    27
extern void SafeTestL(TBool aResult, TInt aId, TInt aLine, TText* aFile);
sl@0
    28
extern void SafeTestL(TInt aResult, TInt aExpected, TInt aId, TInt aLine, TText* aFile);
sl@0
    29
sl@0
    30
const TInt KNotificationHeaderSize = (sizeof(TUint16)*2)+(sizeof(TUint));
sl@0
    31
const TInt KMinNotificationBufferSize = 2*KNotificationHeaderSize + 2*KMaxFileName;
sl@0
    32
sl@0
    33
TBool gPerfMeasure;
sl@0
    34
TFileName gTestPath;
sl@0
    35
TFileName gLogFilePath;
sl@0
    36
RArray<RThread> gNotiThreads;
sl@0
    37
RThread gFileThread;
sl@0
    38
TBuf<50> gLogPostFix;
sl@0
    39
sl@0
    40
// Prints out the filename
sl@0
    41
#define ExpandMe(X)  L ## X
sl@0
    42
#define Expand(X)    ExpandMe(X)
sl@0
    43
sl@0
    44
// Safe test, so that sub-threads are not hanging after check fail
sl@0
    45
#define SAFETEST0(a) SafeTestL(a,KNoThreadId,__LINE__,(TText*)Expand("t_notify_perf_impl.cpp"))
sl@0
    46
#define SAFETEST1(a,b) SafeTestL(a,b,__LINE__,(TText*)Expand("t_notify_perf_impl.cpp"))
sl@0
    47
#define SAFETEST2(a,b,c) SafeTestL(a,b,c,__LINE__,(TText*)Expand("t_notify_perf_impl.cpp"))
sl@0
    48
sl@0
    49
sl@0
    50
TTestSetting::TTestSetting()
sl@0
    51
: iNumFiles(0), iNumCli(0), iOption(0), iOperationList(NULL)
sl@0
    52
	{
sl@0
    53
	}
sl@0
    54
sl@0
    55
TTestSetting::TTestSetting(TInt aNumFiles, TInt aNumCli, TUint16 aOpt, const TUint* aOpList)
sl@0
    56
: iNumFiles(aNumFiles), iNumCli(aNumCli), iOption(aOpt), iOperationList(aOpList)
sl@0
    57
	{
sl@0
    58
	}
sl@0
    59
sl@0
    60
//===========================================================
sl@0
    61
sl@0
    62
CTimerLogger* CTimerLogger::NewL(const TFileName& aLogFile)
sl@0
    63
	{
sl@0
    64
	CTimerLogger* self = new(ELeave) CTimerLogger();
sl@0
    65
	CleanupStack::PushL(self);
sl@0
    66
	self->ConstructL(aLogFile);
sl@0
    67
	CleanupStack::Pop(self);
sl@0
    68
	return self;
sl@0
    69
	}
sl@0
    70
sl@0
    71
void CTimerLogger::ConstructL(const TFileName& aLogFile)
sl@0
    72
	{
sl@0
    73
	User::LeaveIfError(HAL::Get(HALData::ENanoTickPeriod, iTickPeriod));
sl@0
    74
	iLogFile.Copy(aLogFile);
sl@0
    75
	}
sl@0
    76
sl@0
    77
CTimerLogger::CTimerLogger()
sl@0
    78
:  iTiming(EFalse), iTickNumber(0), iTimeScale(KDefaultTimeScale)
sl@0
    79
	{
sl@0
    80
	iFs.Connect();
sl@0
    81
	}
sl@0
    82
sl@0
    83
CTimerLogger::~CTimerLogger()
sl@0
    84
	{
sl@0
    85
	iFs.Close();
sl@0
    86
	}
sl@0
    87
sl@0
    88
// Write Logs
sl@0
    89
TInt CTimerLogger::Log(const TDesC& aDes, TBool aIsLine)
sl@0
    90
	{
sl@0
    91
	RFile file;
sl@0
    92
	iFs.Connect();
sl@0
    93
	
sl@0
    94
	TInt err = file.Open(iFs,iLogFile,EFileShareExclusive|EFileWrite);
sl@0
    95
	SAFETEST0(err == KErrNone || err == KErrNotFound || err == KErrPathNotFound);
sl@0
    96
	
sl@0
    97
	if (err != KErrNone)
sl@0
    98
		{
sl@0
    99
		err = iFs.MkDirAll(iLogFile);
sl@0
   100
		SAFETEST0(err == KErrNone || err == KErrAlreadyExists);
sl@0
   101
		err = file.Create(iFs,iLogFile,EFileShareExclusive|EFileWrite);
sl@0
   102
		SAFETEST0(err == KErrNone);
sl@0
   103
		}
sl@0
   104
	
sl@0
   105
	TBuf8<240> data;
sl@0
   106
	data.Copy(aDes);
sl@0
   107
	if (aIsLine)
sl@0
   108
		{
sl@0
   109
		data.Append(_L8("\r\n"));
sl@0
   110
		}
sl@0
   111
		
sl@0
   112
	TInt offset = 0;
sl@0
   113
	err = file.Seek(ESeekEnd, offset);
sl@0
   114
	SAFETEST0(err == KErrNone);
sl@0
   115
	err = file.Write(data);
sl@0
   116
	SAFETEST0(err == KErrNone);
sl@0
   117
sl@0
   118
	file.Close();
sl@0
   119
	iFs.Close();
sl@0
   120
	return err;
sl@0
   121
	}
sl@0
   122
sl@0
   123
// Write Logs and also print the line written in the console
sl@0
   124
TInt CTimerLogger::LogAndPrint(const TDesC& aDes, TBool aIsLine)
sl@0
   125
	{
sl@0
   126
	TInt err = KErrNone;
sl@0
   127
	RDebug::Print(aDes);
sl@0
   128
	if (gPerfMeasure)
sl@0
   129
	    err = Log(aDes, aIsLine);
sl@0
   130
	return err;
sl@0
   131
	}
sl@0
   132
sl@0
   133
// Write and print the time result
sl@0
   134
TInt CTimerLogger::LogTestStepTime(TUint aOp, TInt aNum)
sl@0
   135
	{
sl@0
   136
	if (iTiming)
sl@0
   137
		return KErrGeneral;
sl@0
   138
	
sl@0
   139
	TBuf<100> buf;
sl@0
   140
	switch (aOp)
sl@0
   141
		{
sl@0
   142
		case EOpCreate:
sl@0
   143
			buf.Append(_L("Create - "));
sl@0
   144
			break;
sl@0
   145
		case EOpReplace:
sl@0
   146
			buf.Append(_L("Replace - "));
sl@0
   147
			break;
sl@0
   148
		case EOpChgAttr:
sl@0
   149
			buf.Append(_L("Change Attribute - "));
sl@0
   150
			break;
sl@0
   151
		case EOpRename:
sl@0
   152
			buf.Append(_L("Rename - "));
sl@0
   153
			break;
sl@0
   154
		case EOpWrite:
sl@0
   155
			buf.Append(_L("Write - "));
sl@0
   156
			break;
sl@0
   157
		case EOpResize:
sl@0
   158
			buf.Append(_L("Resize - "));
sl@0
   159
			break;
sl@0
   160
		case EOpDelete:
sl@0
   161
			buf.Append(_L("Delete - "));
sl@0
   162
			break;
sl@0
   163
		case EOpManyChanges:
sl@0
   164
			buf.AppendFormat(_L("%d Changes on Single File - "), aNum);
sl@0
   165
			break;
sl@0
   166
		case EOpManyFiles:
sl@0
   167
			buf.AppendFormat(_L("Small Changes on %d Files - "), aNum);
sl@0
   168
			break;
sl@0
   169
		case EOpCreateDir:
sl@0
   170
			buf.Append(_L("Create(dir) - "));
sl@0
   171
			break;
sl@0
   172
		case EOpRenameDir:
sl@0
   173
			buf.Append(_L("Rename(dir) - "));
sl@0
   174
			break;
sl@0
   175
		case EOpDeleteDir:
sl@0
   176
			buf.Append(_L("Delete(dir) - "));
sl@0
   177
			break;
sl@0
   178
		case EOpMixed:
sl@0
   179
			buf.AppendFormat(_L("%d Mixed Operations - "), aNum*18);
sl@0
   180
		default:
sl@0
   181
			break;
sl@0
   182
		}
sl@0
   183
	
sl@0
   184
	TReal time = (static_cast<TReal>(iTickNumber) * iTickPeriod) / iTimeScale;
sl@0
   185
	buf.AppendFormat(_L("time: %d ms"), static_cast<TInt>(time));
sl@0
   186
	return LogAndPrint(buf);
sl@0
   187
	}
sl@0
   188
sl@0
   189
// write and print the test case discription
sl@0
   190
TInt CTimerLogger::LogSettingDescription(const TInt aNumFile, const TInt aNumCli, const TUint16 aOption, TBool aNumOpVaries)
sl@0
   191
	{	
sl@0
   192
	LogAndPrint(_L("===================================================="));
sl@0
   193
	
sl@0
   194
	TBuf<120> buf;
sl@0
   195
	buf.Append(_L("Test: "));
sl@0
   196
	if (!aNumOpVaries)
sl@0
   197
		{
sl@0
   198
		buf.AppendFormat(_L("%d files/directories, %d Clients, "), aNumFile, aNumCli);
sl@0
   199
		}
sl@0
   200
	
sl@0
   201
	// Notification Type
sl@0
   202
	switch(aOption & KNotifyOptionMask)
sl@0
   203
		{		
sl@0
   204
		case ENoNotify:
sl@0
   205
			buf.Append(_L("No Notification"));
sl@0
   206
			break;
sl@0
   207
		case EEnhanced:
sl@0
   208
			buf.Append(_L("Enhanced"));
sl@0
   209
			break;
sl@0
   210
		case EOriginal:
sl@0
   211
			buf.Append(_L("Original"));
sl@0
   212
			break;
sl@0
   213
		case EPlugin:
sl@0
   214
			buf.Append(_L("Nokia Plug-in"));
sl@0
   215
			break;
sl@0
   216
		default:
sl@0
   217
			return KErrArgument;
sl@0
   218
		}
sl@0
   219
	
sl@0
   220
	if (aOption & EBigFilter)
sl@0
   221
		{
sl@0
   222
		buf.Append(_L(", 100 Filters"));
sl@0
   223
		}
sl@0
   224
	
sl@0
   225
	if (aOption & EReportChg)
sl@0
   226
		{
sl@0
   227
		buf.Append(_L(", Change Reporting"));
sl@0
   228
		}
sl@0
   229
	else
sl@0
   230
		{
sl@0
   231
		buf.Append(_L(", Not Report Changes"));
sl@0
   232
		}
sl@0
   233
	
sl@0
   234
	if (aOption & EEnhanced)
sl@0
   235
		{
sl@0
   236
		if (aOption & EBigBuffer)
sl@0
   237
			{
sl@0
   238
			buf.Append(_L(", Big Buffer"));
sl@0
   239
			} 
sl@0
   240
		else
sl@0
   241
			{
sl@0
   242
			buf.Append(_L(", Small Buffer"));
sl@0
   243
			}
sl@0
   244
		
sl@0
   245
		if (aOption & EMultiNoti1)
sl@0
   246
			{
sl@0
   247
			buf.Append(_L(", Multi Notification Mode 1"));
sl@0
   248
			}
sl@0
   249
		else if (aOption & EMultiNoti2)
sl@0
   250
			{
sl@0
   251
			buf.Append(_L(", Multi Notification Mode 2"));
sl@0
   252
			}
sl@0
   253
		}
sl@0
   254
sl@0
   255
	LogAndPrint(buf);
sl@0
   256
	LogAndPrint(_L("----------------------------------------------------"));
sl@0
   257
	
sl@0
   258
	return KErrNone;
sl@0
   259
	}
sl@0
   260
sl@0
   261
//===========================================================
sl@0
   262
sl@0
   263
CTestExecutor::CTestExecutor(TTestSetting& aSetting)
sl@0
   264
: iTestSetting(aSetting)
sl@0
   265
	{
sl@0
   266
	}
sl@0
   267
sl@0
   268
CTestExecutor::~CTestExecutor()
sl@0
   269
	{
sl@0
   270
	}
sl@0
   271
sl@0
   272
void CTestExecutor::KillAllTestThreads()
sl@0
   273
    {
sl@0
   274
    RThread killer;
sl@0
   275
    killer.Create(_L("KillerThread"), KillerThread, KDefaultStackSize, KMinHeapSize, KMaxHeapSize, NULL); 
sl@0
   276
    killer.Resume();
sl@0
   277
   
sl@0
   278
    TRequestStatus status;
sl@0
   279
    killer.Logon(status);
sl@0
   280
    User::WaitForRequest(status);
sl@0
   281
    TInt err = killer.ExitReason();
sl@0
   282
    test(err == KErrNone);
sl@0
   283
    }
sl@0
   284
sl@0
   285
// start run a test case
sl@0
   286
void CTestExecutor::RunTestCaseL()
sl@0
   287
	{
sl@0
   288
	RSemaphore smphF;
sl@0
   289
	smphF.CreateLocal(0);
sl@0
   290
	RSemaphore smphN;
sl@0
   291
	smphN.CreateLocal(0);
sl@0
   292
		
sl@0
   293
	RArray<RThread> notiThreads; // list of handles of notification threads
sl@0
   294
	RPointerArray<CTimerLogger> loggerList;
sl@0
   295
	
sl@0
   296
	TUint16 count = 0;
sl@0
   297
	TUint16 option = iTestSetting.iOption;
sl@0
   298
	while (count < iTestSetting.iNumCli)
sl@0
   299
		{
sl@0
   300
		test(count < 16);
sl@0
   301
		iTestSetting.iOption = (TUint16)(option + count); // Put Thread ID in option
sl@0
   302
		
sl@0
   303
		TThreadParam param;
sl@0
   304
		param.iSetting = iTestSetting;
sl@0
   305
		param.iSmphFT = &smphF;
sl@0
   306
		param.iSmphNT = &smphN;
sl@0
   307
			
sl@0
   308
		TFileName logName;
sl@0
   309
		logName.FillZ();
sl@0
   310
		
sl@0
   311
		if (gPerfMeasure)
sl@0
   312
		    {
sl@0
   313
            logName.Append(gLogFilePath);
sl@0
   314
            if (iTestSetting.iNumCli == 1)
sl@0
   315
                logName.Append(_L("SingleClient"));
sl@0
   316
            else
sl@0
   317
                logName.AppendFormat(_L("MultiClient%02d"), count);
sl@0
   318
            
sl@0
   319
            logName.Append(gLogPostFix);
sl@0
   320
		    }
sl@0
   321
		
sl@0
   322
		CTimerLogger* logger = CTimerLogger::NewL(logName);
sl@0
   323
		CleanupStack::PushL(logger);
sl@0
   324
		
sl@0
   325
		param.iLogger = logger;
sl@0
   326
		param.iLoggerArray = NULL;
sl@0
   327
		
sl@0
   328
		TUint operation = *iTestSetting.iOperationList;
sl@0
   329
		TBool numFilesVaries = EFalse; 
sl@0
   330
		
sl@0
   331
		if (operation == EOpManyFiles || operation == EOpManyChanges || operation == EOpMixed)
sl@0
   332
			{
sl@0
   333
			numFilesVaries = ETrue;
sl@0
   334
			}
sl@0
   335
		logger->LogSettingDescription(iTestSetting.iNumFiles, iTestSetting.iNumCli, iTestSetting.iOption, numFilesVaries);
sl@0
   336
		
sl@0
   337
		loggerList.AppendL(logger);
sl@0
   338
		
sl@0
   339
		TBuf<20> threadName;
sl@0
   340
		threadName.AppendFormat(_L("NotificationThread%02d"), count);
sl@0
   341
sl@0
   342
		RThread notifyOp;
sl@0
   343
		notifyOp.Create(threadName, NotificationOperationThread, KDefaultStackSize, KMinHeapSize, KMaxHeapSize, &param);
sl@0
   344
		
sl@0
   345
		notiThreads.AppendL(notifyOp);
sl@0
   346
		
sl@0
   347
		notifyOp.Resume();
sl@0
   348
		
sl@0
   349
		smphF.Wait();	// Wait for the parameters being properly passed
sl@0
   350
		
sl@0
   351
		CleanupStack::Pop(logger);
sl@0
   352
		count++;
sl@0
   353
		}
sl@0
   354
	
sl@0
   355
	gNotiThreads = notiThreads;
sl@0
   356
	
sl@0
   357
	if (iTestSetting.iNumCli == 0)	// no notification
sl@0
   358
		{
sl@0
   359
		TFileName logName;
sl@0
   360
		logName.Append(gLogFilePath);
sl@0
   361
		logName.Append(_L("SingleClient"));
sl@0
   362
		logName.Append(gLogPostFix);
sl@0
   363
	
sl@0
   364
		CTimerLogger* logger = CTimerLogger::NewL(logName);
sl@0
   365
		CleanupStack::PushL(logger);
sl@0
   366
		
sl@0
   367
		logger->LogSettingDescription(iTestSetting.iNumFiles, iTestSetting.iNumCli, iTestSetting.iOption);
sl@0
   368
		
sl@0
   369
		loggerList.AppendL(logger);
sl@0
   370
		CleanupStack::Pop(logger);
sl@0
   371
		}
sl@0
   372
	
sl@0
   373
	TThreadParam paramFileOp;
sl@0
   374
	paramFileOp.iSetting = iTestSetting;
sl@0
   375
	paramFileOp.iSmphFT = &smphF;
sl@0
   376
	paramFileOp.iSmphNT = &smphN;
sl@0
   377
	paramFileOp.iLogger = NULL;
sl@0
   378
	paramFileOp.iLoggerArray = &loggerList;
sl@0
   379
	
sl@0
   380
	RThread fileOp;
sl@0
   381
	fileOp.Create(_L("FileOperationThread"), FileOperationThread, KDefaultStackSize, KMinHeapSize, KMaxHeapSize, &paramFileOp);	
sl@0
   382
	gFileThread = fileOp;
sl@0
   383
	
sl@0
   384
	fileOp.Resume();
sl@0
   385
	
sl@0
   386
	TInt err;
sl@0
   387
	
sl@0
   388
	TRequestStatus status;
sl@0
   389
	fileOp.Logon(status);
sl@0
   390
	User::WaitForRequest(status);
sl@0
   391
	err = fileOp.ExitReason();
sl@0
   392
	test(err == KErrNone);
sl@0
   393
		
sl@0
   394
	count = 0;
sl@0
   395
	while(count < notiThreads.Count())
sl@0
   396
		{
sl@0
   397
		notiThreads[count].Logon(status);
sl@0
   398
		User::WaitForRequest(status);
sl@0
   399
		err = notiThreads[count].ExitReason();
sl@0
   400
		test(err == KErrNone);
sl@0
   401
		count++;
sl@0
   402
		}
sl@0
   403
	
sl@0
   404
	CLOSE_AND_WAIT(fileOp);
sl@0
   405
	
sl@0
   406
	count = 0;
sl@0
   407
	while(count < notiThreads.Count())
sl@0
   408
		{
sl@0
   409
		RThread thread = notiThreads[count];
sl@0
   410
		CLOSE_AND_WAIT(thread);
sl@0
   411
		count++;
sl@0
   412
		}
sl@0
   413
	
sl@0
   414
	for (TInt i = 0; i < loggerList.Count(); i++)
sl@0
   415
		{
sl@0
   416
		loggerList[i]->LogAndPrint(_L("===================================================="));
sl@0
   417
		}
sl@0
   418
	
sl@0
   419
	smphN.Close();
sl@0
   420
	smphF.Close();
sl@0
   421
	loggerList.ResetAndDestroy();
sl@0
   422
	loggerList.Close();
sl@0
   423
	notiThreads.Reset();
sl@0
   424
	notiThreads.Close();
sl@0
   425
	}
sl@0
   426
sl@0
   427
//===========================================================
sl@0
   428
sl@0
   429
CFileOperator::CFileOperator(const TTestSetting& aSetting, RPointerArray<CTimerLogger>& aLoggerArray, RSemaphore* aSmphFT, RSemaphore* aSmphNT)
sl@0
   430
: iFirstFile(0)
sl@0
   431
	{
sl@0
   432
	iNumFiles = aSetting.iNumFiles;
sl@0
   433
	iOption = aSetting.iOption;
sl@0
   434
	iCurrentOp = aSetting.iOperationList;
sl@0
   435
	iNumCli = aSetting.iNumCli;
sl@0
   436
	
sl@0
   437
	iLoggers = aLoggerArray; 
sl@0
   438
	iSmphS = aSmphNT;
sl@0
   439
	iSmphW = aSmphFT;
sl@0
   440
sl@0
   441
	iFs.Connect();
sl@0
   442
	}
sl@0
   443
sl@0
   444
CFileOperator::~CFileOperator()
sl@0
   445
	{
sl@0
   446
	iFs.Close();
sl@0
   447
	}
sl@0
   448
sl@0
   449
// starts measuring for all the notification thread
sl@0
   450
// the loggers in iLogger are shared by Notification thread
sl@0
   451
void CFileOperator::MesureStartsAll()
sl@0
   452
	{
sl@0
   453
	TInt i = 0;
sl@0
   454
	while (i < iNumCli)
sl@0
   455
		{
sl@0
   456
		iLoggers[i]->MeasureStart();
sl@0
   457
		i++;
sl@0
   458
		}
sl@0
   459
	}
sl@0
   460
sl@0
   461
// Wait for all notification threads to signal
sl@0
   462
void CFileOperator::WaitForSignalsAll()
sl@0
   463
	{
sl@0
   464
	TInt i = 0;
sl@0
   465
	while (i < iNumCli)
sl@0
   466
		{
sl@0
   467
		iSmphW->Wait();
sl@0
   468
		i++;
sl@0
   469
		}
sl@0
   470
	}
sl@0
   471
sl@0
   472
// prepare each test step
sl@0
   473
void CFileOperator::TestStepPrepare(TUint aOp)
sl@0
   474
	{
sl@0
   475
	RDebug::Print(_L("Preparing for the next test step..."));
sl@0
   476
	switch (aOp)
sl@0
   477
		{
sl@0
   478
		case EOpReplace:
sl@0
   479
			{
sl@0
   480
			User::After(1500000); // Wait for 1.5 sec so that the new files have different modified time
sl@0
   481
			RFile file;
sl@0
   482
			TInt count = iFirstFile + iNumFiles;
sl@0
   483
			while (count < (iFirstFile + (iNumFiles * 2)))
sl@0
   484
				{
sl@0
   485
				TFileName nextFile;
sl@0
   486
				FileNameGen(nextFile, count);
sl@0
   487
				file.Create(iFs, nextFile, EFileRead);
sl@0
   488
				file.Close();
sl@0
   489
				count++;
sl@0
   490
				}
sl@0
   491
			break;
sl@0
   492
			}
sl@0
   493
		case EOpManyChanges:
sl@0
   494
			{
sl@0
   495
			RFile file;
sl@0
   496
			TFileName nextFile;
sl@0
   497
			FileNameGen(nextFile, 9999);
sl@0
   498
			file.Create(iFs, nextFile, EFileRead);
sl@0
   499
			file.Close();
sl@0
   500
			break;
sl@0
   501
			}
sl@0
   502
		case EOpManyFiles:
sl@0
   503
			{
sl@0
   504
			CDir* list;
sl@0
   505
			iFs.GetDir(gTestPath, KEntryAttMaskSupported, ESortNone, list);
sl@0
   506
			TInt count = list->Count();
sl@0
   507
			delete list;
sl@0
   508
			
sl@0
   509
			RFile file;
sl@0
   510
			
sl@0
   511
			for (TInt i = 0; i < iNumFiles - count; i++)
sl@0
   512
				{
sl@0
   513
				TFileName nextFile;
sl@0
   514
				FileNameGen(nextFile, count + i);
sl@0
   515
				file.Create(iFs, nextFile, EFileRead);
sl@0
   516
				file.Close();
sl@0
   517
				}
sl@0
   518
			
sl@0
   519
			break;
sl@0
   520
			}
sl@0
   521
		// No preparation for other operations
sl@0
   522
		default:
sl@0
   523
			break;
sl@0
   524
		}
sl@0
   525
	RDebug::Print(_L("Preparation done..."));
sl@0
   526
	}
sl@0
   527
sl@0
   528
// Finish each test step, do some clearing or test setting modification
sl@0
   529
void CFileOperator::TestStepFinish(TUint aOp)
sl@0
   530
	{
sl@0
   531
	RDebug::Print(_L("Finishing the test step..."));
sl@0
   532
	switch (aOp)
sl@0
   533
		{
sl@0
   534
		case EOpRenameDir:
sl@0
   535
		case EOpRename:
sl@0
   536
			{
sl@0
   537
			iFirstFile += iNumFiles;
sl@0
   538
			break;
sl@0
   539
			}
sl@0
   540
		case EOpDelete:
sl@0
   541
		case EOpDeleteDir:
sl@0
   542
			{
sl@0
   543
			iFirstFile = 0;
sl@0
   544
			break;
sl@0
   545
			}
sl@0
   546
		case EOpManyChanges:
sl@0
   547
			{
sl@0
   548
			TFileName fileName;
sl@0
   549
			FileNameGen(fileName, 9999);
sl@0
   550
			iFs.Delete(fileName);
sl@0
   551
			iNumFiles += 1000;
sl@0
   552
			break;
sl@0
   553
			}
sl@0
   554
		case EOpManyFiles:
sl@0
   555
			{
sl@0
   556
			iNumFiles += 1000;
sl@0
   557
			break;
sl@0
   558
			}
sl@0
   559
	    case EOpMixed:
sl@0
   560
	        {
sl@0
   561
	        iNumFiles += 50;
sl@0
   562
	        }
sl@0
   563
	    // no clearing for other operations
sl@0
   564
		default:
sl@0
   565
			break;
sl@0
   566
		}
sl@0
   567
	RDebug::Print(_L("***** Test step finished *****"));
sl@0
   568
	RDebug::Print(_L("\n"));
sl@0
   569
	}
sl@0
   570
sl@0
   571
// perform the file operations
sl@0
   572
void CFileOperator::DoChangesL()
sl@0
   573
	{
sl@0
   574
	while(*iCurrentOp != EOpEnd)
sl@0
   575
		{
sl@0
   576
		TestStepPrepare(*iCurrentOp);
sl@0
   577
		
sl@0
   578
		if (iOption & ENoNotify)
sl@0
   579
			{
sl@0
   580
			iLoggers[0]->MeasureStart();
sl@0
   581
			}
sl@0
   582
		else
sl@0
   583
			{
sl@0
   584
			iSmphS->Signal(iNumCli);	// Signal notification threads that preparation is done
sl@0
   585
			WaitForSignalsAll();	// Wait for notification threads to finish requesting notifications 
sl@0
   586
			MesureStartsAll();
sl@0
   587
			}
sl@0
   588
		
sl@0
   589
		RDebug::Print(_L("Start Timing and File operations..."));	
sl@0
   590
		switch(*iCurrentOp)
sl@0
   591
			{
sl@0
   592
			case EOpCreate:
sl@0
   593
				DoCreateL(); 
sl@0
   594
				break;
sl@0
   595
			case EOpReplace:
sl@0
   596
				DoReplaceL();
sl@0
   597
				break;
sl@0
   598
			case EOpChgAttr:
sl@0
   599
				DoChangeAttL();
sl@0
   600
				break;
sl@0
   601
			case EOpRename:
sl@0
   602
				DoRenameL();
sl@0
   603
				break;
sl@0
   604
			case EOpWrite:
sl@0
   605
				DoWriteL(); 
sl@0
   606
				break;
sl@0
   607
			case EOpResize:
sl@0
   608
				DoResizeL(); 
sl@0
   609
				break;
sl@0
   610
			case EOpDelete:
sl@0
   611
				DoDeleteL();
sl@0
   612
				break;
sl@0
   613
			case EOpManyChanges:
sl@0
   614
				DoManyChangesOnSingleFileL();
sl@0
   615
				break;
sl@0
   616
			case EOpManyFiles:
sl@0
   617
				DoSmallChangesOnManyFilesL();
sl@0
   618
				break;
sl@0
   619
			case EOpCreateDir:
sl@0
   620
				DoCreateDirL();
sl@0
   621
				break;
sl@0
   622
			case EOpRenameDir:
sl@0
   623
				DoRenameDirL();
sl@0
   624
				break;
sl@0
   625
			case EOpDeleteDir:
sl@0
   626
				DoDeleteDirL();
sl@0
   627
				break;
sl@0
   628
			case EOpMixed:
sl@0
   629
				DoMixedOperationsL();
sl@0
   630
				break;
sl@0
   631
			default: 
sl@0
   632
				User::Leave(KErrArgument);
sl@0
   633
			}
sl@0
   634
		RDebug::Print(_L("File Operation Ended..."));
sl@0
   635
		
sl@0
   636
		if (iOption & ENoNotify)
sl@0
   637
			{
sl@0
   638
			RDebug::Print(_L("Timing ended..."));
sl@0
   639
			iLoggers[0]->MeasureEnd();
sl@0
   640
			iLoggers[0]->LogTestStepTime(*iCurrentOp, iNumFiles);
sl@0
   641
			}
sl@0
   642
		else 
sl@0
   643
			{
sl@0
   644
			RFile file;
sl@0
   645
			TFileName endFile(gLogFilePath);
sl@0
   646
			endFile.Append(_L("test.end"));
sl@0
   647
			TInt r = file.Replace(iFs, endFile, EFileWrite);
sl@0
   648
			SAFETEST0(r == KErrNone);
sl@0
   649
			file.Close();
sl@0
   650
	
sl@0
   651
			WaitForSignalsAll();	// Wait for notification threads to receive all the notifications 
sl@0
   652
			}
sl@0
   653
		
sl@0
   654
		TestStepFinish(*iCurrentOp);
sl@0
   655
			
sl@0
   656
		iCurrentOp++;
sl@0
   657
		}
sl@0
   658
	}
sl@0
   659
sl@0
   660
void CFileOperator::DoCreateL()
sl@0
   661
	{
sl@0
   662
	RFile file;
sl@0
   663
	TInt count = iFirstFile;
sl@0
   664
	
sl@0
   665
	while (count < iFirstFile + iNumFiles)
sl@0
   666
		{
sl@0
   667
		TFileName nextFile;
sl@0
   668
		FileNameGen(nextFile, count);
sl@0
   669
sl@0
   670
		TInt r = file.Create(iFs, nextFile, EFileRead);
sl@0
   671
		SAFETEST0(r == KErrNone);
sl@0
   672
		file.Close();	
sl@0
   673
		count++;
sl@0
   674
		}
sl@0
   675
	}
sl@0
   676
sl@0
   677
void CFileOperator::DoReplaceL()
sl@0
   678
	{
sl@0
   679
	TInt count = iFirstFile;
sl@0
   680
	
sl@0
   681
	while (count < iFirstFile + iNumFiles)
sl@0
   682
		{
sl@0
   683
		TFileName newFile;
sl@0
   684
		TFileName oldFile;
sl@0
   685
		FileNameGen(newFile, count);
sl@0
   686
		FileNameGen(oldFile, count + iNumFiles);
sl@0
   687
		
sl@0
   688
		iFs.Replace(oldFile, newFile);
sl@0
   689
		count++;
sl@0
   690
		}
sl@0
   691
	}
sl@0
   692
sl@0
   693
void CFileOperator::DoChangeAttL()
sl@0
   694
	{
sl@0
   695
	TInt count = iFirstFile;
sl@0
   696
	
sl@0
   697
	while (count < iFirstFile + iNumFiles)
sl@0
   698
		{
sl@0
   699
		TFileName nextFile;
sl@0
   700
		FileNameGen(nextFile, count);
sl@0
   701
		iFs.SetAtt(nextFile, KEntryAttNormal, KEntryAttArchive);
sl@0
   702
		count++;
sl@0
   703
		}
sl@0
   704
	}
sl@0
   705
sl@0
   706
void CFileOperator::DoRenameL()
sl@0
   707
	{
sl@0
   708
	TInt count = iFirstFile;
sl@0
   709
	
sl@0
   710
	while (count < iFirstFile + iNumFiles)
sl@0
   711
		{
sl@0
   712
		TFileName newFile;
sl@0
   713
		TFileName oldFile;
sl@0
   714
		FileNameGen(oldFile, count);
sl@0
   715
		FileNameGen(newFile, count + iNumFiles);
sl@0
   716
		
sl@0
   717
		iFs.Rename(oldFile, newFile);
sl@0
   718
		count++;
sl@0
   719
		}
sl@0
   720
	}
sl@0
   721
sl@0
   722
void CFileOperator::DoWriteL()
sl@0
   723
	{
sl@0
   724
	RFile file;
sl@0
   725
	TInt count = iFirstFile;
sl@0
   726
	_LIT8(KData, "Some text for writing test of enhanced notification performance test.");
sl@0
   727
	
sl@0
   728
	while (count < iFirstFile + iNumFiles)
sl@0
   729
		{
sl@0
   730
		TFileName nextFile;
sl@0
   731
		FileNameGen(nextFile, count);
sl@0
   732
		file.Open(iFs, nextFile, EFileWrite);
sl@0
   733
		file.Write(KData);
sl@0
   734
		// Flush file to ensure notification is received
sl@0
   735
		file.Flush();
sl@0
   736
		file.Close();	
sl@0
   737
		count++;
sl@0
   738
		}
sl@0
   739
	}
sl@0
   740
sl@0
   741
void CFileOperator::DoResizeL()
sl@0
   742
	{
sl@0
   743
	RFile file;
sl@0
   744
	TInt count = iFirstFile;
sl@0
   745
sl@0
   746
	while (count < iFirstFile + iNumFiles)
sl@0
   747
		{
sl@0
   748
		TFileName nextFile;
sl@0
   749
		FileNameGen(nextFile, count);
sl@0
   750
		file.Open(iFs, nextFile, EFileWrite);
sl@0
   751
		TInt size;
sl@0
   752
		file.Size(size);
sl@0
   753
		file.SetSize(size+10);
sl@0
   754
		file.Close();	
sl@0
   755
		count++;
sl@0
   756
		}
sl@0
   757
	}
sl@0
   758
sl@0
   759
void CFileOperator::DoDeleteL()
sl@0
   760
	{
sl@0
   761
	TInt count = iFirstFile;
sl@0
   762
	
sl@0
   763
	while (count < iFirstFile + iNumFiles)
sl@0
   764
		{
sl@0
   765
		TFileName nextFile;
sl@0
   766
		FileNameGen(nextFile, count);
sl@0
   767
		iFs.Delete(nextFile);
sl@0
   768
		count++;
sl@0
   769
		}
sl@0
   770
	}
sl@0
   771
sl@0
   772
void CFileOperator::DoCreateDirL()
sl@0
   773
	{
sl@0
   774
	TInt count = iFirstFile;
sl@0
   775
	
sl@0
   776
	while (count < iFirstFile + iNumFiles)
sl@0
   777
		{
sl@0
   778
		TFileName nextFile;
sl@0
   779
		FileNameGen(nextFile, count, EFalse);
sl@0
   780
		iFs.MkDir(nextFile);
sl@0
   781
		count++;
sl@0
   782
		}
sl@0
   783
	}
sl@0
   784
sl@0
   785
void CFileOperator::DoRenameDirL()
sl@0
   786
	{
sl@0
   787
	TInt count = iFirstFile;
sl@0
   788
	while (count < iFirstFile + iNumFiles)
sl@0
   789
		{
sl@0
   790
		TFileName newFile;
sl@0
   791
		TFileName oldFile;
sl@0
   792
		FileNameGen(oldFile, count, EFalse);
sl@0
   793
		FileNameGen(newFile, count + iNumFiles, EFalse);
sl@0
   794
		
sl@0
   795
		iFs.Rename(oldFile, newFile);
sl@0
   796
		count++;
sl@0
   797
		}
sl@0
   798
	}
sl@0
   799
sl@0
   800
void CFileOperator::DoDeleteDirL()
sl@0
   801
	{
sl@0
   802
	TInt count = iFirstFile;
sl@0
   803
	
sl@0
   804
	while (count < iFirstFile + iNumFiles)
sl@0
   805
		{
sl@0
   806
		TFileName nextFile;
sl@0
   807
		FileNameGen(nextFile, count, EFalse);
sl@0
   808
		iFs.RmDir(nextFile);
sl@0
   809
		count++;
sl@0
   810
		}
sl@0
   811
	}
sl@0
   812
sl@0
   813
void CFileOperator::DoManyChangesOnSingleFileL()
sl@0
   814
	{
sl@0
   815
	TFileName fileName;
sl@0
   816
	FileNameGen(fileName, 9999);
sl@0
   817
	
sl@0
   818
	RFile file;
sl@0
   819
	_LIT8(KData, "a");
sl@0
   820
	
sl@0
   821
	for(TInt i = 0; i < iNumFiles; i++)
sl@0
   822
		{
sl@0
   823
		TInt offset = 0;
sl@0
   824
		file.Open(iFs, fileName, EFileWrite);
sl@0
   825
		file.Seek(ESeekEnd, offset);
sl@0
   826
		file.Write(KData);
sl@0
   827
		file.Flush();
sl@0
   828
		file.Close();
sl@0
   829
		}
sl@0
   830
	}
sl@0
   831
sl@0
   832
void CFileOperator::DoSmallChangesOnManyFilesL()
sl@0
   833
	{
sl@0
   834
	RFile file;
sl@0
   835
    _LIT8(KData, "a");
sl@0
   836
	
sl@0
   837
	for(TInt i = 0; i < iNumFiles; i++)
sl@0
   838
		{
sl@0
   839
		TFileName nextFile;
sl@0
   840
		FileNameGen(nextFile, i);
sl@0
   841
		file.Open(iFs, nextFile, EFileWrite);
sl@0
   842
		file.Write(KData);
sl@0
   843
		file.Flush();
sl@0
   844
		file.Close();	
sl@0
   845
		}
sl@0
   846
	}
sl@0
   847
sl@0
   848
void CFileOperator::DoMixedOperationsL()
sl@0
   849
	{
sl@0
   850
	// will perform 18*iNumFiles operations
sl@0
   851
	RFile file;
sl@0
   852
	TInt firstFile = iFirstFile;
sl@0
   853
	TInt lastFile = iFirstFile + (2 * iNumFiles);
sl@0
   854
	TInt firstDir = iFirstFile;
sl@0
   855
	TInt lastDir = iFirstFile + iNumFiles;
sl@0
   856
	
sl@0
   857
	_LIT8(KData, "Some text.");
sl@0
   858
sl@0
   859
	TInt i;
sl@0
   860
	// Create Files - 2*iNumFiles Ops
sl@0
   861
	// we create 2*iNumFiles files here so that we can ensure that at least iNumfiles ops are performed after the replace step
sl@0
   862
	for (i = firstFile; i < lastFile; i++)
sl@0
   863
		{
sl@0
   864
		TFileName nextFile;
sl@0
   865
		FileNameGen(nextFile, i);
sl@0
   866
		file.Create(iFs, nextFile, EFileRead);
sl@0
   867
		file.Close();	
sl@0
   868
		}
sl@0
   869
sl@0
   870
	// Create Directories - iNumFiles Ops
sl@0
   871
	for (i = firstDir; i < lastDir; i++)
sl@0
   872
		{
sl@0
   873
		TFileName nextFile;
sl@0
   874
		FileNameGen(nextFile, i, EFalse);
sl@0
   875
		iFs.MkDir(nextFile);
sl@0
   876
		}
sl@0
   877
	
sl@0
   878
	// Write - 2*iNumFiles Ops
sl@0
   879
	for (i = firstFile; i < lastFile; i++)
sl@0
   880
		{
sl@0
   881
		TFileName nextFile;
sl@0
   882
		FileNameGen(nextFile, i);
sl@0
   883
		file.Open(iFs, nextFile, EFileWrite);
sl@0
   884
		file.Write(KData);
sl@0
   885
		file.Flush();
sl@0
   886
		file.Close();
sl@0
   887
		}
sl@0
   888
sl@0
   889
	// Resize - 2*iNumFiles Ops
sl@0
   890
	for (i = firstFile; i < lastFile; i++)
sl@0
   891
		{
sl@0
   892
		TFileName nextFile;
sl@0
   893
		FileNameGen(nextFile, i);
sl@0
   894
		file.Open(iFs, nextFile, EFileWrite);
sl@0
   895
		TInt size;
sl@0
   896
		file.Size(size);
sl@0
   897
		file.SetSize(size+10);
sl@0
   898
		file.Close();
sl@0
   899
		}
sl@0
   900
	
sl@0
   901
	// Replace Files - iNumFiles Ops
sl@0
   902
	for (i = firstFile; i < firstFile + iNumFiles; i++)
sl@0
   903
		{
sl@0
   904
		TFileName newFile;
sl@0
   905
		TFileName oldFile;
sl@0
   906
		FileNameGen(oldFile, i);
sl@0
   907
		FileNameGen(newFile, i + iNumFiles);
sl@0
   908
		iFs.Replace(oldFile, newFile);
sl@0
   909
		}
sl@0
   910
	firstFile += iNumFiles;
sl@0
   911
	
sl@0
   912
	// Rename Files - iNumFiles Ops
sl@0
   913
	for (i = firstFile; i < lastFile; i++)
sl@0
   914
		{
sl@0
   915
		TFileName newFile;
sl@0
   916
		TFileName oldFile;
sl@0
   917
		FileNameGen(newFile, i - iNumFiles);
sl@0
   918
		FileNameGen(oldFile, i);	
sl@0
   919
		iFs.Rename(oldFile, newFile);
sl@0
   920
		}
sl@0
   921
	firstFile -= iNumFiles;
sl@0
   922
	lastFile -= iNumFiles;
sl@0
   923
	
sl@0
   924
	// Delete Dirs - iNumFiles Ops
sl@0
   925
	for (i = firstDir; i < lastDir; i++)
sl@0
   926
		{
sl@0
   927
		TFileName nextFile;
sl@0
   928
		FileNameGen(nextFile, i, EFalse);
sl@0
   929
		iFs.RmDir(nextFile);
sl@0
   930
		}
sl@0
   931
	
sl@0
   932
	// Delete File - iNumFiles Ops
sl@0
   933
	for (i = firstFile; i < lastFile; i++)
sl@0
   934
		{
sl@0
   935
		TFileName nextFile;
sl@0
   936
		FileNameGen(nextFile, i);
sl@0
   937
		iFs.Delete(nextFile);
sl@0
   938
		}
sl@0
   939
sl@0
   940
	// All-in-one - 7*iNumFiles Ops
sl@0
   941
	for (i = firstFile; i < lastFile; i++)
sl@0
   942
		{
sl@0
   943
		TFileName nextFile;
sl@0
   944
		FileNameGen(nextFile, i);
sl@0
   945
		TFileName nextDir;
sl@0
   946
		FileNameGen(nextDir, i, EFalse);
sl@0
   947
		
sl@0
   948
		iFs.MkDir(nextDir);
sl@0
   949
		
sl@0
   950
		file.Create(iFs, nextFile, EFileWrite);
sl@0
   951
		file.Write(KData);
sl@0
   952
		file.Flush();
sl@0
   953
		TInt size;
sl@0
   954
		file.Size(size);
sl@0
   955
		file.SetSize(size+10);
sl@0
   956
		file.Close();
sl@0
   957
		
sl@0
   958
		TFileName newName;
sl@0
   959
		FileNameGen(newName, i + iNumFiles);
sl@0
   960
		iFs.Rename(nextFile, newName);
sl@0
   961
		
sl@0
   962
		iFs.Delete(newName);
sl@0
   963
		iFs.RmDir(nextDir);
sl@0
   964
		}
sl@0
   965
	}
sl@0
   966
sl@0
   967
//==========================================================
sl@0
   968
sl@0
   969
CNotifyOperator::CNotifyOperator(const TTestSetting& aSetting, RSemaphore* aSmphFT, RSemaphore* aSmphNT, CTimerLogger* aLogger)
sl@0
   970
	{
sl@0
   971
	iNumFiles = aSetting.iNumFiles;
sl@0
   972
	iOption = aSetting.iOption;
sl@0
   973
	iCurrentOp = aSetting.iOperationList;
sl@0
   974
	iLogger = aLogger;
sl@0
   975
	iSmphS = aSmphFT;
sl@0
   976
	iSmphW = aSmphNT;
sl@0
   977
	}
sl@0
   978
sl@0
   979
CNotifyOperator::~CNotifyOperator()
sl@0
   980
	{
sl@0
   981
	}
sl@0
   982
sl@0
   983
// start operations in notification thread
sl@0
   984
// this is the main function called in the thread,
sl@0
   985
// it creates notification watcher, requests notification, and check test result
sl@0
   986
void CNotifyOperator::StartOperationL()
sl@0
   987
	{
sl@0
   988
	CNotifyWatcher* notifyWatcher = CNotifyWatcher::NewL(iNumFiles, iOption, *iCurrentOp, iLogger);
sl@0
   989
	CleanupStack::PushL(notifyWatcher);
sl@0
   990
	CTestStopper* stopper = new(ELeave) CTestStopper();
sl@0
   991
	CleanupStack::PushL(stopper);
sl@0
   992
	
sl@0
   993
	CActiveScheduler::Add(notifyWatcher);
sl@0
   994
	CActiveScheduler::Add(stopper);
sl@0
   995
	
sl@0
   996
	while (*iCurrentOp != EOpEnd)
sl@0
   997
		{
sl@0
   998
		iSmphW->Wait();	// wait for file thread finishing preparation for the current file operation.
sl@0
   999
		
sl@0
  1000
		notifyWatcher->FullDirectoryScanL(notifyWatcher->iEntries);
sl@0
  1001
		notifyWatcher->RequestNotification();
sl@0
  1002
		stopper->StartWaitingForFile();
sl@0
  1003
		
sl@0
  1004
		iSmphS->Signal();	// Signal file thread that the notifications are requested, ready to receive
sl@0
  1005
		
sl@0
  1006
		CActiveScheduler::Start();
sl@0
  1007
		////////////////////////////////
sl@0
  1008
		// receiving notifications... //
sl@0
  1009
		////////////////////////////////
sl@0
  1010
		
sl@0
  1011
		notifyWatcher->HandleNotification(ETrue); // handle for the last time
sl@0
  1012
		
sl@0
  1013
		LogTestResult(notifyWatcher->iCounter, notifyWatcher->iMeanCounter, notifyWatcher->iOverflowCounter);
sl@0
  1014
		
sl@0
  1015
		if(iOption & EReportChg)
sl@0
  1016
		    {
sl@0
  1017
			TestChangeReport(notifyWatcher->iRecords.Count());
sl@0
  1018
		    }
sl@0
  1019
		
sl@0
  1020
		if (!gPerfMeasure)
sl@0
  1021
		    {
sl@0
  1022
		    TInt id = iOption & KNotifyTreadIdMask;
sl@0
  1023
            if (iOption & EMultiNoti2)
sl@0
  1024
                {
sl@0
  1025
                if ( *iCurrentOp == EOpCreate ||
sl@0
  1026
                    (id % 4 == 0 && (*iCurrentOp == EOpRename || *iCurrentOp == EOpReplace)) ||
sl@0
  1027
                    (id % 4 == 1 && *iCurrentOp == EOpChgAttr) || 
sl@0
  1028
                    (id % 4 == 2 && (*iCurrentOp == EOpResize || *iCurrentOp == EOpWrite)) ||
sl@0
  1029
                    (id % 4 == 3 && *iCurrentOp == EOpDelete))
sl@0
  1030
                    {
sl@0
  1031
                    SAFETEST2(notifyWatcher->iCounter, iNumFiles, id);
sl@0
  1032
                    }
sl@0
  1033
                }
sl@0
  1034
            else
sl@0
  1035
                {
sl@0
  1036
                SAFETEST2(notifyWatcher->iCounter, iNumFiles, id);
sl@0
  1037
                }
sl@0
  1038
		    }
sl@0
  1039
		
sl@0
  1040
		iSmphS->Signal();	// Signal file thread that all notifications are received
sl@0
  1041
		
sl@0
  1042
		iCurrentOp++;
sl@0
  1043
		
sl@0
  1044
		notifyWatcher->Reset(*iCurrentOp);
sl@0
  1045
		if ((*iCurrentOp == EOpManyFiles) || (*iCurrentOp == EOpManyChanges))
sl@0
  1046
			{
sl@0
  1047
			iNumFiles += 1000;
sl@0
  1048
			}
sl@0
  1049
		else if (*iCurrentOp == EOpMixed)
sl@0
  1050
		    {
sl@0
  1051
		    iNumFiles += 50;
sl@0
  1052
		    }
sl@0
  1053
		}
sl@0
  1054
sl@0
  1055
	CleanupStack::PopAndDestroy(2);
sl@0
  1056
	
sl@0
  1057
	}
sl@0
  1058
sl@0
  1059
// Write log and print the notification numbers using iLogger
sl@0
  1060
void CNotifyOperator::LogNotificationNumbers(TInt aNumNoti, TInt aNumIter, TInt aNumOverflow)
sl@0
  1061
	{
sl@0
  1062
	TBuf<100> buf;
sl@0
  1063
	
sl@0
  1064
	if (iOption & EEnhanced)
sl@0
  1065
		{	
sl@0
  1066
		if (aNumOverflow > 0)
sl@0
  1067
			{
sl@0
  1068
			buf.AppendFormat(_L("Buffer overflow: %d overflow notifications received."), aNumOverflow, aNumNoti);
sl@0
  1069
			iLogger->LogAndPrint(buf);
sl@0
  1070
			buf.Zero();
sl@0
  1071
			}
sl@0
  1072
		
sl@0
  1073
		TReal mean = static_cast<TReal>(aNumNoti)/aNumIter;
sl@0
  1074
		buf.AppendFormat(_L("%.2f mean enhanced notifications per iteration."), mean);	
sl@0
  1075
		iLogger->LogAndPrint(buf);
sl@0
  1076
		buf.Zero();
sl@0
  1077
		}
sl@0
  1078
	
sl@0
  1079
	buf.AppendFormat(_L("%d notifications received overall."), aNumNoti);
sl@0
  1080
	iLogger->LogAndPrint(buf);
sl@0
  1081
	}
sl@0
  1082
sl@0
  1083
// Write log and print the test reault
sl@0
  1084
void CNotifyOperator::LogTestResult(TInt aCounter, TInt aMeanCounter, TInt aOFCounter)
sl@0
  1085
    {
sl@0
  1086
    if (iOption & EMultiNoti2)
sl@0
  1087
        {
sl@0
  1088
        TInt id = iOption & KNotifyTreadIdMask;
sl@0
  1089
        if ( *iCurrentOp == EOpCreate || 
sl@0
  1090
            (id % 4 == 0 && (*iCurrentOp == EOpRename || *iCurrentOp == EOpReplace)) || 
sl@0
  1091
            (id % 4 == 1 && *iCurrentOp == EOpChgAttr) || 
sl@0
  1092
            (id % 4 == 2 && (*iCurrentOp == EOpWrite || *iCurrentOp == EOpResize)) ||
sl@0
  1093
            (id % 4 == 3 && *iCurrentOp == EOpDelete))
sl@0
  1094
            {
sl@0
  1095
            iLogger->LogTestStepTime(*iCurrentOp, iNumFiles);
sl@0
  1096
            LogNotificationNumbers(aCounter, aMeanCounter, aOFCounter);
sl@0
  1097
            }
sl@0
  1098
        else 
sl@0
  1099
            iLogger->LogAndPrint(_L("File operation not tested - time: 0 ms"));
sl@0
  1100
        }
sl@0
  1101
    else if (iOption & EPlugin)
sl@0
  1102
        {
sl@0
  1103
        if (*iCurrentOp == EOpChgAttr || *iCurrentOp == EOpWrite || *iCurrentOp == EOpResize)
sl@0
  1104
            iLogger->LogAndPrint(_L("File operation not tested - time: 0 ms"));
sl@0
  1105
        else
sl@0
  1106
            {
sl@0
  1107
            iLogger->LogTestStepTime(*iCurrentOp, iNumFiles);
sl@0
  1108
            LogNotificationNumbers(aCounter, aMeanCounter, aOFCounter);
sl@0
  1109
            } 
sl@0
  1110
        }
sl@0
  1111
    else
sl@0
  1112
        {
sl@0
  1113
        iLogger->LogTestStepTime(*iCurrentOp, iNumFiles);
sl@0
  1114
        LogNotificationNumbers(aCounter, aMeanCounter, aOFCounter);
sl@0
  1115
        }
sl@0
  1116
    }
sl@0
  1117
sl@0
  1118
// When change report enabled, check the number of changes we detected
sl@0
  1119
void CNotifyOperator::TestChangeReport(TInt aNumChanges)
sl@0
  1120
    {
sl@0
  1121
    TBuf<100> buf;
sl@0
  1122
    buf.AppendFormat(_L("%d file changes detected.\r\n"), aNumChanges);
sl@0
  1123
    iLogger->LogAndPrint(buf);
sl@0
  1124
    
sl@0
  1125
    TInt id = iOption & KNotifyTreadIdMask;
sl@0
  1126
    if (iOption & EEnhanced)
sl@0
  1127
        {
sl@0
  1128
        if (iOption & EMultiNoti2)
sl@0
  1129
            {
sl@0
  1130
            if ( *iCurrentOp == EOpCreate ||
sl@0
  1131
                (id % 4 == 0 && (*iCurrentOp == EOpRename || *iCurrentOp == EOpReplace)) ||
sl@0
  1132
                (id % 4 == 1 && *iCurrentOp == EOpChgAttr) || 
sl@0
  1133
                (id % 4 == 2 && (*iCurrentOp == EOpResize || *iCurrentOp == EOpWrite)) ||
sl@0
  1134
                (id % 4 == 3 && *iCurrentOp == EOpDelete))
sl@0
  1135
                {
sl@0
  1136
                SAFETEST2(aNumChanges, iNumFiles, id);
sl@0
  1137
                }
sl@0
  1138
            }
sl@0
  1139
        else if (!(iOption & EBigBuffer))
sl@0
  1140
            {
sl@0
  1141
            // not testing this case, because the number of file changes detected 
sl@0
  1142
            // could varies depend on when notifications are received
sl@0
  1143
            }
sl@0
  1144
        else if (*iCurrentOp == EOpMixed)
sl@0
  1145
            {
sl@0
  1146
            SAFETEST2(aNumChanges, (18*iNumFiles), id); // On cached drives, the number of write notification could vary.
sl@0
  1147
            }
sl@0
  1148
        else
sl@0
  1149
            {
sl@0
  1150
            SAFETEST2(aNumChanges, iNumFiles, id);
sl@0
  1151
            }
sl@0
  1152
        }
sl@0
  1153
    else if (iOption & EOriginal)
sl@0
  1154
        {
sl@0
  1155
        if ((*iCurrentOp == EOpManyChanges) || (*iCurrentOp == EOpMixed))
sl@0
  1156
            {
sl@0
  1157
            // not testing this case, because the number of file changes detected 
sl@0
  1158
            // could varies depend on when notifications are received
sl@0
  1159
            }
sl@0
  1160
        else if ((*iCurrentOp == EOpReplace) || (*iCurrentOp == EOpRename) || (*iCurrentOp == EOpRenameDir))
sl@0
  1161
            {
sl@0
  1162
            SAFETEST2(aNumChanges, (2*iNumFiles), id);
sl@0
  1163
            }
sl@0
  1164
        else
sl@0
  1165
            {
sl@0
  1166
            SAFETEST2(aNumChanges, iNumFiles, id);
sl@0
  1167
            }
sl@0
  1168
        }
sl@0
  1169
    else if (iOption & EPlugin)
sl@0
  1170
        {
sl@0
  1171
        if (*iCurrentOp == EOpCreate || *iCurrentOp == EOpReplace || *iCurrentOp == EOpRename || 
sl@0
  1172
                *iCurrentOp == EOpDelete || *iCurrentOp == EOpRenameDir)
sl@0
  1173
            {
sl@0
  1174
            SAFETEST2(aNumChanges, iNumFiles, id);
sl@0
  1175
            }
sl@0
  1176
        else if (*iCurrentOp == EOpMixed)
sl@0
  1177
            {
sl@0
  1178
            SAFETEST2(aNumChanges, (8*iNumFiles), id); // only part of operations can be notified
sl@0
  1179
            }
sl@0
  1180
        // Other cases are not testable.
sl@0
  1181
        }
sl@0
  1182
    }
sl@0
  1183
sl@0
  1184
//===========================================================
sl@0
  1185
	
sl@0
  1186
CNotifyWatcher::CNotifyWatcher(TInt aNumFiles, TUint16 aOption, TUint aCurrentOp, CTimerLogger* aLogger) 
sl@0
  1187
: CActive(CActive::EPriorityStandard), iCounter(0), iMeanCounter(0), iOverflowCounter(0), iCurrentOp(aCurrentOp),
sl@0
  1188
iNumFiles(aNumFiles), iOption(aOption), iEntries(aNumFiles), iRecords(aNumFiles), iLogger(aLogger)
sl@0
  1189
	{
sl@0
  1190
	}
sl@0
  1191
sl@0
  1192
CNotifyWatcher::~CNotifyWatcher()
sl@0
  1193
	{
sl@0
  1194
	Cancel();
sl@0
  1195
	delete iNotify;
sl@0
  1196
sl@0
  1197
    iFs.DismountPlugin(KPluginName);
sl@0
  1198
    iFs.RemovePlugin(KPluginName);
sl@0
  1199
	
sl@0
  1200
	iFs.Close();
sl@0
  1201
	iEntries.Close();
sl@0
  1202
	iRecords.Close();
sl@0
  1203
	}
sl@0
  1204
sl@0
  1205
CNotifyWatcher* CNotifyWatcher::NewL(TInt aNumFiles, TUint16 aOption, TUint aCurrentOp, CTimerLogger* aLogger)
sl@0
  1206
	{
sl@0
  1207
	CNotifyWatcher* self = new(ELeave) CNotifyWatcher(aNumFiles, aOption, aCurrentOp, aLogger);
sl@0
  1208
	CleanupStack::PushL(self);
sl@0
  1209
	self->ConstructL();
sl@0
  1210
	CleanupStack::Pop(self);
sl@0
  1211
	return self;
sl@0
  1212
	}
sl@0
  1213
sl@0
  1214
void CNotifyWatcher::ConstructL()
sl@0
  1215
	{
sl@0
  1216
	iFs.Connect();
sl@0
  1217
	
sl@0
  1218
	if (iOption & EEnhanced)
sl@0
  1219
		{
sl@0
  1220
		TInt bufferSize;
sl@0
  1221
		if(iOption & EBigBuffer)
sl@0
  1222
			{
sl@0
  1223
			bufferSize = KMinNotificationBufferSize * iNumFiles;
sl@0
  1224
			if (iCurrentOp == EOpMixed)
sl@0
  1225
				bufferSize = bufferSize * 18;
sl@0
  1226
			}
sl@0
  1227
		else
sl@0
  1228
			bufferSize = KMinNotificationBufferSize;
sl@0
  1229
		
sl@0
  1230
		iNotify = CFsNotify::NewL(iFs, bufferSize);
sl@0
  1231
		}
sl@0
  1232
	else
sl@0
  1233
		iNotify = NULL;
sl@0
  1234
sl@0
  1235
	if (iOption& EPlugin)
sl@0
  1236
		{
sl@0
  1237
		TInt r = iFs.AddPlugin(KPluginName);
sl@0
  1238
		test(r == KErrNone || r == KErrAlreadyExists);
sl@0
  1239
		if (r != KErrAlreadyExists)
sl@0
  1240
		    {
sl@0
  1241
		    r = iFs.MountPlugin(KPluginName);
sl@0
  1242
		    test(r == KErrNone);
sl@0
  1243
		    }
sl@0
  1244
		}
sl@0
  1245
	
sl@0
  1246
	FullDirectoryScanL(iEntries);
sl@0
  1247
	iRecords.Reset();
sl@0
  1248
	}
sl@0
  1249
sl@0
  1250
// reset certain members so that we can do next test step
sl@0
  1251
void CNotifyWatcher::Reset(TUint aOp)
sl@0
  1252
	{
sl@0
  1253
	iCurrentOp = aOp;
sl@0
  1254
	iRecords.Reset();
sl@0
  1255
	iCounter = 0;
sl@0
  1256
	iOverflowCounter = 0;
sl@0
  1257
	iMeanCounter = 0;
sl@0
  1258
	if ((aOp == EOpManyFiles) || (aOp == EOpManyChanges))
sl@0
  1259
		iNumFiles += 1000;
sl@0
  1260
	}
sl@0
  1261
sl@0
  1262
// perform a full dir scan
sl@0
  1263
void CNotifyWatcher::FullDirectoryScanL(RArray<TEntry>& aArray)
sl@0
  1264
	{
sl@0
  1265
	aArray.Reset();
sl@0
  1266
	
sl@0
  1267
	CDir* list;
sl@0
  1268
	iFs.GetDir(gTestPath, KEntryAttMaskSupported, ESortByName, list);
sl@0
  1269
	
sl@0
  1270
	if (!list)
sl@0
  1271
	    return;
sl@0
  1272
	
sl@0
  1273
	CleanupStack::PushL(list);
sl@0
  1274
	
sl@0
  1275
	for (TInt i = 0; i < list->Count(); i++)
sl@0
  1276
		{
sl@0
  1277
		TEntry en ((*list)[i]);
sl@0
  1278
		aArray.AppendL(en);
sl@0
  1279
		}
sl@0
  1280
	
sl@0
  1281
	CleanupStack::PopAndDestroy();
sl@0
  1282
	}
sl@0
  1283
sl@0
  1284
// find out what has changed in test path, and save the changes in iRecord
sl@0
  1285
void CNotifyWatcher::MakeChangeRecordL(RArray<TEntry>& aArray)
sl@0
  1286
	{
sl@0
  1287
	TInt num = aArray.Count();
sl@0
  1288
	TInt r,i;
sl@0
  1289
	for (i = 0; i < num; i++)
sl@0
  1290
		{
sl@0
  1291
		TInt index = iEntries.Find(aArray[i], CompareEntryName);
sl@0
  1292
		SAFETEST1((index == KErrNotFound || index >= 0), (iOption & KNotifyTreadIdMask));
sl@0
  1293
		
sl@0
  1294
		TFileName name(aArray[i].iName);
sl@0
  1295
		
sl@0
  1296
		if (index == KErrNotFound)
sl@0
  1297
			{
sl@0
  1298
			r = iRecords.Append(name);
sl@0
  1299
			SAFETEST2(r, KErrNone, (iOption & KNotifyTreadIdMask));
sl@0
  1300
			}
sl@0
  1301
		else
sl@0
  1302
			{
sl@0
  1303
			if (!CompareEntry(iEntries[index], aArray[i]))
sl@0
  1304
				{
sl@0
  1305
				r = iRecords.Append(name);
sl@0
  1306
				SAFETEST2(r, KErrNone, (iOption & KNotifyTreadIdMask));
sl@0
  1307
				}
sl@0
  1308
			iEntries.Remove(index);
sl@0
  1309
			}
sl@0
  1310
		}
sl@0
  1311
	
sl@0
  1312
	num = iEntries.Count();
sl@0
  1313
	
sl@0
  1314
	for (i = 0; i < num; i++)
sl@0
  1315
		{
sl@0
  1316
		TFileName name(iEntries[i].iName);
sl@0
  1317
		r = iRecords.Append(name);
sl@0
  1318
		SAFETEST2(r, KErrNone, (iOption & KNotifyTreadIdMask));
sl@0
  1319
		}
sl@0
  1320
	
sl@0
  1321
	iEntries.Reset();
sl@0
  1322
	num = aArray.Count();
sl@0
  1323
	for (i = 0; i < num; i++)
sl@0
  1324
		{
sl@0
  1325
		TEntry en (aArray[i]);
sl@0
  1326
		iEntries.AppendL(en);
sl@0
  1327
		}
sl@0
  1328
	}
sl@0
  1329
sl@0
  1330
sl@0
  1331
TBool CNotifyWatcher::CompareEntry(const TEntry& aEntry1, const TEntry& aEntry2)
sl@0
  1332
	{
sl@0
  1333
	// we don't compare name, because names are compared by CompareEntryName() already
sl@0
  1334
	// we don't check attributes when creating files, because dir scan sometimes returns file
sl@0
  1335
	// entries before attributes being flushed, and we don't care about it in this test case.
sl@0
  1336
	// we also don't check the modified time for all the test cases expect replacing test, 
sl@0
  1337
	// because dir scan sometimes returns file entries before time being flushed, 
sl@0
  1338
	// and we don't care about it as well.
sl@0
  1339
	// For replacing test, we check modification time, because it's the way we distinguish the old and new files.
sl@0
  1340
	if (iCurrentOp == EOpCreate)
sl@0
  1341
	    {
sl@0
  1342
	    if ((aEntry1.iSize == aEntry2.iSize) && (aEntry1.iType == aEntry2.iType))
sl@0
  1343
            return ETrue;
sl@0
  1344
	    }
sl@0
  1345
	else if (iCurrentOp == EOpReplace || iCurrentOp == EOpManyFiles || iCurrentOp == EOpManyChanges || iCurrentOp == EOpMixed)
sl@0
  1346
	    {
sl@0
  1347
        if ((aEntry1.iAtt == aEntry2.iAtt) && (aEntry1.iModified == aEntry2.iModified) 
sl@0
  1348
                && (aEntry1.iSize == aEntry2.iSize) && (aEntry1.iType == aEntry2.iType))
sl@0
  1349
            return ETrue;
sl@0
  1350
	    }
sl@0
  1351
	else
sl@0
  1352
	    {
sl@0
  1353
        if ((aEntry1.iAtt == aEntry2.iAtt) && (aEntry1.iSize == aEntry2.iSize) 
sl@0
  1354
                && (aEntry1.iType == aEntry2.iType))
sl@0
  1355
            return ETrue;
sl@0
  1356
	    }
sl@0
  1357
	
sl@0
  1358
	return EFalse;
sl@0
  1359
	}
sl@0
  1360
sl@0
  1361
// add 100 filters for enhanced notification test case
sl@0
  1362
void CNotifyWatcher::AddLotsOfFilters()
sl@0
  1363
	{
sl@0
  1364
	for (TInt i = 0; i < 100; i++)
sl@0
  1365
		{
sl@0
  1366
		TFileName path;
sl@0
  1367
		path.Copy(gTestPath);
sl@0
  1368
		path.Append('*');
sl@0
  1369
		TFileName file;
sl@0
  1370
		file.AppendFormat(_L("*.%3d"), i);
sl@0
  1371
		TInt r = iNotify->AddNotification((TUint)TFsNotification::EAllOps, gTestPath, file);
sl@0
  1372
		SAFETEST2(r, KErrNone, (iOption & KNotifyTreadIdMask));
sl@0
  1373
		}
sl@0
  1374
	}
sl@0
  1375
sl@0
  1376
void CNotifyWatcher::RequestNotification()
sl@0
  1377
	{
sl@0
  1378
	switch (iOption & KNotifyOptionMask)
sl@0
  1379
		{
sl@0
  1380
		case EEnhanced:
sl@0
  1381
			RequestNotificationEnhanced();
sl@0
  1382
			break;
sl@0
  1383
		case EOriginal:
sl@0
  1384
			RequestNotificationOriginal();
sl@0
  1385
			break;
sl@0
  1386
		case EPlugin:
sl@0
  1387
			RequestNotificationPlugin();
sl@0
  1388
			break;
sl@0
  1389
		case ENoNotify:
sl@0
  1390
		default:
sl@0
  1391
			return;
sl@0
  1392
		}
sl@0
  1393
	}
sl@0
  1394
sl@0
  1395
// request notification using enhanced notification
sl@0
  1396
void CNotifyWatcher::RequestNotificationEnhanced()
sl@0
  1397
	{
sl@0
  1398
	if (iOption & EBigFilter)
sl@0
  1399
		{
sl@0
  1400
		AddLotsOfFilters();
sl@0
  1401
		}
sl@0
  1402
	
sl@0
  1403
	TFileName path;
sl@0
  1404
	path.Copy(gTestPath);
sl@0
  1405
	path.Append('*');
sl@0
  1406
	TBuf<3> file = _L("*");
sl@0
  1407
	
sl@0
  1408
	if (iOption & EMultiNoti1)
sl@0
  1409
		{
sl@0
  1410
		TInt r = iNotify->AddNotification(TFsNotification::ECreate, path, file); // Create & replace
sl@0
  1411
		SAFETEST2(r, KErrNone, (iOption & KNotifyTreadIdMask));
sl@0
  1412
		r = iNotify->AddNotification(TFsNotification::ERename, path, file);	// Change Attribute
sl@0
  1413
		SAFETEST2(r, KErrNone, (iOption & KNotifyTreadIdMask));
sl@0
  1414
		r = iNotify->AddNotification(TFsNotification::EAttribute, path, file); // Rename
sl@0
  1415
		SAFETEST2(r, KErrNone, (iOption & KNotifyTreadIdMask));
sl@0
  1416
		r = iNotify->AddNotification(TFsNotification::EFileChange, path, file); // Write & Setsize
sl@0
  1417
		SAFETEST2(r, KErrNone, (iOption & KNotifyTreadIdMask));
sl@0
  1418
		r = iNotify->AddNotification(TFsNotification::EDelete, path, file); // Delete
sl@0
  1419
		SAFETEST2(r, KErrNone, (iOption & KNotifyTreadIdMask));
sl@0
  1420
		}
sl@0
  1421
	else if (iOption & EMultiNoti2)
sl@0
  1422
		{
sl@0
  1423
		TInt r = iNotify->AddNotification(TFsNotification::ECreate, path, file); // Create & replace
sl@0
  1424
		TInt id = iOption & KNotifyTreadIdMask;
sl@0
  1425
		
sl@0
  1426
		switch (id%4)
sl@0
  1427
			{
sl@0
  1428
			case 0:
sl@0
  1429
				r = iNotify->AddNotification(TFsNotification::ERename, path, file);	// Change Attribute
sl@0
  1430
				SAFETEST2(r, KErrNone, id);
sl@0
  1431
				break;
sl@0
  1432
			case 1:
sl@0
  1433
				r = iNotify->AddNotification(TFsNotification::EAttribute, path, file); // Rename
sl@0
  1434
				SAFETEST2(r, KErrNone, id);
sl@0
  1435
				break;
sl@0
  1436
			case 2:
sl@0
  1437
				r = iNotify->AddNotification(TFsNotification::EFileChange, path, file); // Write & Setsize
sl@0
  1438
				SAFETEST2(r, KErrNone, id);
sl@0
  1439
				break;
sl@0
  1440
			case 3:
sl@0
  1441
				r = iNotify->AddNotification(TFsNotification::EDelete, path, file); // Delete
sl@0
  1442
				SAFETEST2(r, KErrNone, id);
sl@0
  1443
				break;
sl@0
  1444
			default:
sl@0
  1445
				break;
sl@0
  1446
			}
sl@0
  1447
		}
sl@0
  1448
	else
sl@0
  1449
		{
sl@0
  1450
		TInt r = iNotify->AddNotification((TUint)TFsNotification::EAllOps, path, file);
sl@0
  1451
		SAFETEST2(r, KErrNone, (iOption & KNotifyTreadIdMask));
sl@0
  1452
		}
sl@0
  1453
	
sl@0
  1454
	TInt r = iNotify->RequestNotifications(iStatus);
sl@0
  1455
	SAFETEST2(r, KErrNone, (iOption & KNotifyTreadIdMask));
sl@0
  1456
	
sl@0
  1457
	SetActive();
sl@0
  1458
	}
sl@0
  1459
sl@0
  1460
// request notification using original notification
sl@0
  1461
void CNotifyWatcher::RequestNotificationOriginal()
sl@0
  1462
	{
sl@0
  1463
	iFs.NotifyChange(ENotifyAll, iStatus, gTestPath);
sl@0
  1464
	SetActive();
sl@0
  1465
	}
sl@0
  1466
sl@0
  1467
void CNotifyWatcher::HandleNotification(TBool aLastTime)
sl@0
  1468
	{
sl@0
  1469
	switch (iOption & KNotifyOptionMask)
sl@0
  1470
		{
sl@0
  1471
		case EEnhanced:
sl@0
  1472
			HandleNotificationEnhanced(aLastTime);
sl@0
  1473
			break;
sl@0
  1474
		case EOriginal:
sl@0
  1475
			HandleNotificationOriginal(aLastTime);
sl@0
  1476
			break;
sl@0
  1477
		case EPlugin:
sl@0
  1478
			HandleNotificationPlugin(aLastTime);
sl@0
  1479
			break;
sl@0
  1480
		case ENoNotify:
sl@0
  1481
		default:
sl@0
  1482
			return;
sl@0
  1483
		}
sl@0
  1484
	
sl@0
  1485
	if(aLastTime)
sl@0
  1486
		{
sl@0
  1487
		iLogger->MeasureEnd();
sl@0
  1488
		RDebug::Print(_L("Timing ended..."));
sl@0
  1489
		Cancel();
sl@0
  1490
		}
sl@0
  1491
	}
sl@0
  1492
sl@0
  1493
// handle enhanced notification
sl@0
  1494
void CNotifyWatcher::HandleNotificationEnhanced(TBool aLastTime)
sl@0
  1495
	{
sl@0
  1496
	TInt num = iCounter;
sl@0
  1497
	iMeanCounter++;
sl@0
  1498
	
sl@0
  1499
	TFsNotification::TFsNotificationType type;
sl@0
  1500
	const TFsNotification* notification;
sl@0
  1501
	
sl@0
  1502
	while((notification = iNotify->NextNotification())!= NULL)
sl@0
  1503
		{	
sl@0
  1504
		iCounter++;
sl@0
  1505
		type = notification->NotificationType();
sl@0
  1506
		if (iOption & EBigBuffer)
sl@0
  1507
			{
sl@0
  1508
			SAFETEST1((type & OpNotifyMapping(iOption, iCurrentOp)), (iOption & KNotifyTreadIdMask));
sl@0
  1509
			}
sl@0
  1510
		else
sl@0
  1511
			{
sl@0
  1512
			SAFETEST1((type & (OpNotifyMapping(iOption, iCurrentOp) | TFsNotification::EOverflow)), (iOption & KNotifyTreadIdMask));
sl@0
  1513
			}
sl@0
  1514
		
sl@0
  1515
      if(iOption & EReportChg)
sl@0
  1516
            {
sl@0
  1517
            if (type & TFsNotification::EOverflow)
sl@0
  1518
                {
sl@0
  1519
                iOverflowCounter++;
sl@0
  1520
                RArray<TEntry> newEntries;
sl@0
  1521
                FullDirectoryScanL(newEntries);
sl@0
  1522
                MakeChangeRecordL(newEntries);
sl@0
  1523
                newEntries.Close();
sl@0
  1524
                }
sl@0
  1525
            else
sl@0
  1526
                {
sl@0
  1527
                TPtrC ptr;
sl@0
  1528
                notification->Path(ptr);
sl@0
  1529
                TFileName name;
sl@0
  1530
                name.Copy(ptr);
sl@0
  1531
                TInt r = iRecords.Append(name);
sl@0
  1532
                SAFETEST2(r, KErrNone, (iOption & KNotifyTreadIdMask));
sl@0
  1533
                }
sl@0
  1534
            }
sl@0
  1535
		}
sl@0
  1536
	
sl@0
  1537
	if (aLastTime)
sl@0
  1538
		{
sl@0
  1539
		if (num == iCounter) // no new notification so this iteration doesn't count
sl@0
  1540
		    {
sl@0
  1541
		    iMeanCounter--;
sl@0
  1542
		    }
sl@0
  1543
		return;
sl@0
  1544
		}
sl@0
  1545
	
sl@0
  1546
	iNotify->RequestNotifications(iStatus);
sl@0
  1547
	SetActive();
sl@0
  1548
	}
sl@0
  1549
sl@0
  1550
// handle original notification
sl@0
  1551
void CNotifyWatcher::HandleNotificationOriginal(TBool aLastTime)
sl@0
  1552
	{
sl@0
  1553
	iCounter++;
sl@0
  1554
	
sl@0
  1555
	if (iOption & EReportChg)
sl@0
  1556
		{
sl@0
  1557
		RArray<TEntry> newEntries;
sl@0
  1558
		FullDirectoryScanL(newEntries);
sl@0
  1559
		MakeChangeRecordL(newEntries);
sl@0
  1560
		newEntries.Close();
sl@0
  1561
		}
sl@0
  1562
	
sl@0
  1563
	if (aLastTime)
sl@0
  1564
	    {
sl@0
  1565
	    iCounter--; // the last time this function is called is not a notification.
sl@0
  1566
		return;
sl@0
  1567
	    }
sl@0
  1568
sl@0
  1569
	RequestNotificationOriginal();
sl@0
  1570
	}
sl@0
  1571
sl@0
  1572
// reset the iPluginStatusPkg, so that we can request notification again
sl@0
  1573
void CNotifyWatcher::ResetMdsFSPStatus()
sl@0
  1574
    {
sl@0
  1575
    TMdsFSPStatus& status = iPluginStatusPkg();
sl@0
  1576
sl@0
  1577
    status.iDriveNumber = 0;
sl@0
  1578
    status.iFileEventType = EMdsFileUnknown;
sl@0
  1579
    status.iFileName.Zero();
sl@0
  1580
    status.iNewFileName.Zero();
sl@0
  1581
    status.iProcessId = TUid::Null();
sl@0
  1582
    }
sl@0
  1583
sl@0
  1584
// request notification using nokia MDS plugin
sl@0
  1585
void CNotifyWatcher::RequestNotificationPlugin()
sl@0
  1586
    {
sl@0
  1587
    TInt r = iPlugin.Open(iFs, KMdsFSPluginPosition);
sl@0
  1588
    SAFETEST2(r, KErrNone, (iOption & KNotifyTreadIdMask));
sl@0
  1589
    iPlugin.AddNotificationPath(gTestPath);
sl@0
  1590
    
sl@0
  1591
    iPlugin.Enable();  
sl@0
  1592
    ResetMdsFSPStatus();
sl@0
  1593
    iPlugin.RegisterNotification(iPluginStatusPkg, iStatus);
sl@0
  1594
    SetActive();
sl@0
  1595
    }
sl@0
  1596
sl@0
  1597
// handle notifications from plugin
sl@0
  1598
void CNotifyWatcher::HandleNotificationPlugin(TBool aLastTime)
sl@0
  1599
	{
sl@0
  1600
	if (aLastTime)
sl@0
  1601
	    return;
sl@0
  1602
sl@0
  1603
	if (iOption & EReportChg)
sl@0
  1604
	    {
sl@0
  1605
	    TMdsFSPStatus& status = iPluginStatusPkg();
sl@0
  1606
	    TFileName name;
sl@0
  1607
	    name.Copy(status.iFileName);
sl@0
  1608
	    iRecords.Append(name);
sl@0
  1609
	    if (iCurrentOp != EOpMixed)
sl@0
  1610
	        {
sl@0
  1611
	        TInt type = status.iFileEventType;
sl@0
  1612
	        SAFETEST1(((TUint)type == OpNotifyMapping(iOption, iCurrentOp)), (iOption & KNotifyTreadIdMask));
sl@0
  1613
	        }
sl@0
  1614
	    }
sl@0
  1615
	
sl@0
  1616
    iCounter++;
sl@0
  1617
    ResetMdsFSPStatus();
sl@0
  1618
    iPlugin.RegisterNotification(iPluginStatusPkg, iStatus);
sl@0
  1619
    SetActive();
sl@0
  1620
	}
sl@0
  1621
sl@0
  1622
// cancel request
sl@0
  1623
void CNotifyWatcher::DoCancel()
sl@0
  1624
	{
sl@0
  1625
	switch (iOption & KNotifyOptionMask)
sl@0
  1626
		{
sl@0
  1627
		case EEnhanced:
sl@0
  1628
			iNotify->CancelNotifications(iStatus);
sl@0
  1629
			iNotify->RemoveNotifications();
sl@0
  1630
			// not breaking here as the Enhanced may change to Original if Overflow
sl@0
  1631
		case EOriginal:
sl@0
  1632
			iFs.NotifyChangeCancel(iStatus);
sl@0
  1633
			break;
sl@0
  1634
		case EPlugin:
sl@0
  1635
            iPlugin.Disable();
sl@0
  1636
		    iPlugin.NotificationCancel();
sl@0
  1637
		    iPlugin.Close();
sl@0
  1638
			break;
sl@0
  1639
		case ENoNotify:
sl@0
  1640
		default:
sl@0
  1641
			return;
sl@0
  1642
		}
sl@0
  1643
	}
sl@0
  1644
sl@0
  1645
void CNotifyWatcher::RunL()
sl@0
  1646
	{	
sl@0
  1647
	HandleNotification(EFalse);
sl@0
  1648
	}
sl@0
  1649
sl@0
  1650
//========================================================================
sl@0
  1651
sl@0
  1652
CTestStopper::CTestStopper()
sl@0
  1653
: CActive(EPriorityLow)
sl@0
  1654
	{
sl@0
  1655
	iFs.Connect();
sl@0
  1656
	iTestEndFile.Append(gLogFilePath);
sl@0
  1657
	iTestEndFile.Append(_L("test.End"));
sl@0
  1658
	}
sl@0
  1659
sl@0
  1660
CTestStopper::~CTestStopper()
sl@0
  1661
	{
sl@0
  1662
	Cancel();
sl@0
  1663
	iFs.Close();
sl@0
  1664
	}
sl@0
  1665
sl@0
  1666
void CTestStopper::DoCancel()
sl@0
  1667
	{
sl@0
  1668
	iFs.NotifyChangeCancel(iStatus);
sl@0
  1669
	}
sl@0
  1670
sl@0
  1671
// stop the scheduler since the test is done
sl@0
  1672
void CTestStopper::RunL()
sl@0
  1673
	{
sl@0
  1674
	CActiveScheduler::Stop();
sl@0
  1675
	iFs.Delete(iTestEndFile);
sl@0
  1676
	Cancel();
sl@0
  1677
	}
sl@0
  1678
sl@0
  1679
// start waiting for "test.end" file
sl@0
  1680
void CTestStopper::StartWaitingForFile()
sl@0
  1681
	{
sl@0
  1682
	iFs.NotifyChange(ENotifyAll,iStatus,iTestEndFile);
sl@0
  1683
	SetActive();
sl@0
  1684
	}