kerneltest/f32test/bench/t_fsysbm.cpp
changeset 0 a41df078684a
child 33 0173bcd7697c
equal deleted inserted replaced
-1:000000000000 0:a41df078684a
       
     1 // Copyright (c) 1996-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of the License "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 // f32test/bench/t_fsysbm.cpp
       
    15 //
       
    16 //
       
    17 
       
    18 #define __E32TEST_EXTENSION__
       
    19 
       
    20 #include <f32file.h>
       
    21 #include <e32test.h>
       
    22 #include <hal.h>
       
    23 #include <e32math.h>
       
    24 #include "t_server.h"
       
    25 #include "../../e32test/mmu/d_sharedchunk.h"
       
    26 
       
    27 #define SYMBIAN_TEST_EXTENDED_BUFFER_SIZES	// test using a greater number of buffer sizes
       
    28 //#define SYMBIAN_TEST_COPY					// read from one drive and write to another
       
    29 
       
    30 
       
    31 GLDEF_D RTest test(_L("File System Benchmarks"));
       
    32 
       
    33 static const TUint K1K = 1024;								// 1K
       
    34 static const TUint K1M = 1024 * 1024;						// 1M
       
    35 static const TUint K2M = 2 * K1M;						    // 2M
       
    36 
       
    37 #ifdef SYMBIAN_ENABLE_64_BIT_FILE_SERVER_API
       
    38 const TInt64 KGb  	= 1 << 30;
       
    39 const TInt64 K3GB   = 3 * KGb;
       
    40 const TInt64 K4GB   = 4 * KGb;
       
    41 #endif //SYMBIAN_ENABLE_64_BIT_FILE_SERVER_API
       
    42 
       
    43 #if defined(__WINS__)
       
    44 LOCAL_D TInt KMaxFileSize = 256 * K1K;						// 256K
       
    45 //LOCAL_D TInt KMaxFileSize = K1M;							// 1M
       
    46 #else
       
    47 //LOCAL_D TInt KMaxFileSize = 256 * K1K;					// 256K
       
    48 //LOCAL_D TInt KMaxFileSize = K1M;							// 1M
       
    49 LOCAL_D TInt KMaxFileSize = K2M;							// 2M
       
    50 #endif
       
    51 
       
    52 const TTimeIntervalMicroSeconds32 KFloatingPointTestTime = 10000000;	// 10 seconds
       
    53 LOCAL_D const TInt KHeapSize = 0x4000;
       
    54 
       
    55 LOCAL_D TPtr8 DataBuf(NULL, KMaxFileSize,KMaxFileSize);
       
    56 LOCAL_D HBufC8* DataBufH = NULL;
       
    57 
       
    58 LOCAL_D RSharedChunkLdd Ldd;
       
    59 LOCAL_D RChunk TheChunk;
       
    60 LOCAL_D TInt PageSize;
       
    61 const TUint ChunkSize = KMaxFileSize;
       
    62 
       
    63 
       
    64 LOCAL_D RFile File, File2;
       
    65 LOCAL_D TChar gDriveToTest2;
       
    66 
       
    67 // if enabled, Read and Write operations are not boundary aligned.
       
    68 LOCAL_D TBool gMisalignedReadWrites = EFalse;
       
    69 
       
    70 // read & write caching enabled flags - may be overriden by +/-r +/-w command line switches
       
    71 LOCAL_D TBool gReadCachingOn  = EFalse;
       
    72 LOCAL_D TBool gWriteCachingOn = EFalse;
       
    73 
       
    74 // if enabled, timings are for write AND flush
       
    75 LOCAL_D TBool gFlushAfterWrite = ETrue;
       
    76 
       
    77 // if enabled, contiguous shared memory is used for Data buffer
       
    78 LOCAL_D TBool gSharedMemory = EFalse;
       
    79 
       
    80 // if enabled, fragmented shared memory is used for Data buffer
       
    81 LOCAL_D TBool gFragSharedMemory = EFalse;
       
    82 
       
    83 LOCAL_D TInt gFastCounterFreq;
       
    84 
       
    85 
       
    86 
       
    87 LOCAL_C void RecursiveRmDir(const TDesC& aDes)
       
    88 //
       
    89 // Delete directory contents recursively
       
    90 //
       
    91 	{
       
    92 	CDir* pD;
       
    93 	TFileName n=aDes;
       
    94 	n.Append(_L("*"));
       
    95 	TInt r=TheFs.GetDir(n,KEntryAttMaskSupported,EDirsLast,pD);
       
    96 	if (r==KErrNotFound || r==KErrPathNotFound)
       
    97 		return;
       
    98 	test(r==KErrNone);
       
    99 	TInt count=pD->Count();
       
   100 	TInt i=0;
       
   101 	while (i<count)
       
   102 		{
       
   103 		const TEntry& e=(*pD)[i++];
       
   104 		if (e.IsDir())
       
   105 			{
       
   106 			TFileName dirName;
       
   107 			dirName.Format(_L("%S%S\\"),&aDes,&e.iName);
       
   108 			RecursiveRmDir(dirName);
       
   109 			}
       
   110 		else
       
   111 			{
       
   112 			TFileName fileName;
       
   113 			fileName.Format(_L("%S%S"),&aDes,&e.iName);
       
   114 			r=TheFs.Delete(fileName);
       
   115 			test(r==KErrNone);
       
   116 			}
       
   117 		}
       
   118 	delete pD;
       
   119 	r=TheFs.RmDir(aDes);
       
   120 	test(r==KErrNone);
       
   121 	}
       
   122 
       
   123 
       
   124 void LOCAL_C ClearSessionDirectory()
       
   125 //
       
   126 // Delete the contents of F32-TST
       
   127 //
       
   128 	{
       
   129 	TParse sessionPath;
       
   130 	TInt r=TheFs.Parse(_L("\\F32-TST\\"),_L(""),sessionPath);
       
   131 	test(r==KErrNone);
       
   132 	RecursiveRmDir(sessionPath.FullName());
       
   133 	r=TheFs.MkDir(sessionPath.FullName());
       
   134 	test(r==KErrNone);
       
   135 	}
       
   136 
       
   137 
       
   138 LOCAL_C void DoTestFileRead(TInt aBlockSize, TInt aFileSize = KMaxFileSize, TBool aReRead = EFalse)
       
   139 //
       
   140 // Do Read Test
       
   141 //
       
   142 	{
       
   143 	// Create test data
       
   144 //	test.Printf(_L("Creating test file..."));
       
   145 	TInt writeBlockLen = aFileSize > DataBuf.MaxSize() ? DataBuf.MaxSize() : aFileSize;
       
   146 	DataBuf.SetLength(writeBlockLen);
       
   147 #if defined(_DEBUG)
       
   148 	for (TInt m = 0; m < DataBuf.Length(); m++)
       
   149 		DataBuf[m] = TText8(m % 256);
       
   150 #endif
       
   151 	// To allow this test to run on a non-preq914 branch :
       
   152 	enum {EFileWriteDirectIO = 0x00001000};
       
   153 	TInt r = File.Create(TheFs, _L("READTEST"), EFileStream | EFileWriteDirectIO);
       
   154 	test(r == KErrNone);
       
   155 	TInt count = aFileSize / DataBuf.Length();
       
   156 	while (count--)
       
   157 		File.Write(DataBuf);
       
   158 //	test.Printf(_L("done\n"));
       
   159 	File.Close();
       
   160 
       
   161 	enum {EFileReadBuffered = 0x00002000, EFileReadDirectIO = 0x00004000};
       
   162 	r = File.Open(TheFs, _L("READTEST"), EFileStream | (gReadCachingOn ? EFileReadBuffered : EFileReadDirectIO));
       
   163 	test(r == KErrNone);
       
   164 
       
   165 //	const TInt maxReadCount = aFileSize / aBlockSize;
       
   166 	TUint functionCalls = 0;
       
   167 
       
   168 #if defined SYMBIAN_TEST_COPY
       
   169 	// To allow this test to run on a non-preq914 branch :
       
   170 	enum {EFileWriteDirectIO = 0x00001000};
       
   171 	TInt r = File2.Replace(TheFs, _L("WRITETEST"), EFileStream | EFileWriteDirectIO);
       
   172 	test(r == KErrNone);
       
   173 #endif
       
   174 
       
   175 	TTime startTime(0);
       
   176 	TTime endTime(0);
       
   177 
       
   178 	// we stop after the entire file has been read or after 10 seconds, whichever happens sooner
       
   179 	RTimer timer;
       
   180 	timer.CreateLocal();
       
   181 	TRequestStatus reqStat;
       
   182 
       
   183 
       
   184 	TUint initTicks = 0;
       
   185 	TUint finalTicks = 0;
       
   186 
       
   187 	// if aReRead file is set, then read file twice
       
   188 	for (TInt n=0; n<(aReRead?2:1); n++)
       
   189 		{
       
   190 		functionCalls = 0;
       
   191 
       
   192 		const TInt readLen = (aReRead && n == 0) ? writeBlockLen : aBlockSize;
       
   193 		const TInt maxReadCount = aFileSize / readLen;
       
   194 
       
   195 		TInt pos = 0;
       
   196 		File.Seek(ESeekStart, pos);
       
   197 
       
   198 		timer.After(reqStat, 10000000); // After 10 secs
       
   199 		startTime.HomeTime();
       
   200 		initTicks = User::FastCounter();
       
   201 
       
   202 		for (TInt i = 0; i<maxReadCount && reqStat==KRequestPending; i++)
       
   203 			{
       
   204 //			test.Printf(_L("Read %d\n"),i);
       
   205 //			for (TInt a = 0; a < 512; a++)
       
   206 //				test.Printf(_L("%d"),DataBuf[a]);
       
   207 
       
   208 			TInt r = File.Read(DataBuf, readLen);
       
   209 			test (r == KErrNone);
       
   210 
       
   211 			if (DataBuf.Length() == 0)
       
   212 				break;
       
   213 
       
   214 #if defined SYMBIAN_TEST_COPY
       
   215 			r = File2.Write(DataBuf, readLen);
       
   216 			test (r == KErrNone);
       
   217 #endif
       
   218 			functionCalls++;
       
   219 
       
   220 #if defined(_DEBUG)
       
   221 //			for (TInt a = 0; a < 512; a++)
       
   222 //				test.Printf(_L("%d"),DataBuf[a]);
       
   223 
       
   224 			for (TInt j = 0; j < DataBuf.Size(); j++)
       
   225 				test(DataBuf[j] == (j + i * readLen) % 256);
       
   226 #endif
       
   227 
       
   228 			}
       
   229 
       
   230 		finalTicks = User::FastCounter();
       
   231 		endTime.HomeTime();
       
   232 		timer.Cancel();
       
   233 		}
       
   234 
       
   235 	TInt dataTransferred = functionCalls * aBlockSize;
       
   236 
       
   237 //	TTimeIntervalMicroSeconds duration = endTime.MicroSecondsFrom(startTime);
       
   238 	TTimeIntervalMicroSeconds duration = TInt64(finalTicks - initTicks) * TInt64(1000000) / TInt64(gFastCounterFreq) ;
       
   239 
       
   240 	TReal transferRate =
       
   241 		TReal32(dataTransferred) /
       
   242 		TReal(duration.Int64()) * TReal(1000000) / TReal(K1K); // KB/s
       
   243 	test.Printf(_L("Read %7d bytes in %7d byte blocks:\t%11.3f KBytes/s (%d microsecs)\n"),
       
   244 		dataTransferred, aBlockSize, transferRate, endTime.MicroSecondsFrom(startTime).Int64());
       
   245 
       
   246 
       
   247 	timer.Close();
       
   248 #if defined SYMBIAN_TEST_COPY
       
   249 	File2.Close();
       
   250 #endif
       
   251 
       
   252 	File.Close();
       
   253 	r = TheFs.Delete(_L("READTEST"));
       
   254 	test(r == KErrNone);
       
   255 	return;
       
   256 	}
       
   257 
       
   258 
       
   259 LOCAL_C void TestFileRead(TInt aFileSize = KMaxFileSize, TBool aMisalignedReadWrites = EFalse, TBool aReRead = EFalse)
       
   260 //
       
   261 // Benchmark read method
       
   262 //
       
   263 	{
       
   264 	ClearSessionDirectory();
       
   265 	test.Next(_L("Benchmark read method"));
       
   266 
       
   267 	_LIT(KLitReadOnce,"Read-once");
       
   268 	_LIT(KLitReRead,"Re-read");
       
   269 	test.Printf(_L("FileSize %d, MisalignedReadWrites %d %S\n"), aFileSize, aMisalignedReadWrites, aReRead ? &KLitReRead : &KLitReadOnce);
       
   270 	TInt misalignedOffset = aMisalignedReadWrites ? 1 : 0;
       
   271 
       
   272 #if defined (SYMBIAN_TEST_EXTENDED_BUFFER_SIZES)
       
   273 	DoTestFileRead(1+misalignedOffset, aFileSize, aReRead);
       
   274 	DoTestFileRead(2+misalignedOffset, aFileSize, aReRead);
       
   275 	DoTestFileRead(4+misalignedOffset, aFileSize, aReRead);
       
   276 	DoTestFileRead(8+misalignedOffset, aFileSize, aReRead);
       
   277 	DoTestFileRead(16+misalignedOffset, aFileSize, aReRead);
       
   278 	DoTestFileRead(32+misalignedOffset, aFileSize, aReRead);
       
   279 	DoTestFileRead(64+misalignedOffset, aFileSize, aReRead);
       
   280 	DoTestFileRead(128+misalignedOffset, aFileSize, aReRead);
       
   281 	DoTestFileRead(256+misalignedOffset, aFileSize, aReRead);
       
   282 	DoTestFileRead(512+misalignedOffset, aFileSize, aReRead);
       
   283 	DoTestFileRead(1024+misalignedOffset, aFileSize, aReRead);
       
   284 	DoTestFileRead(2 * 1024+misalignedOffset, aFileSize, aReRead);
       
   285 	DoTestFileRead(4 * 1024+misalignedOffset, aFileSize, aReRead);
       
   286 	DoTestFileRead(8 * 1024+misalignedOffset, aFileSize, aReRead);
       
   287 	DoTestFileRead(16 * 1024+misalignedOffset, aFileSize, aReRead);
       
   288 	DoTestFileRead(32 * 1024+misalignedOffset, aFileSize, aReRead);
       
   289 	DoTestFileRead(64 * 1024+misalignedOffset, aFileSize, aReRead);
       
   290 	DoTestFileRead(128 * 1024+misalignedOffset, aFileSize, aReRead);
       
   291 	DoTestFileRead(256 * 1024+misalignedOffset, aFileSize, aReRead);
       
   292 	DoTestFileRead(512 * 1024+misalignedOffset, aFileSize, aReRead);
       
   293 	DoTestFileRead(1024 * 1024+misalignedOffset, aFileSize, aReRead);
       
   294 #else
       
   295 	DoTestFileRead(16+misalignedOffset, aFileSize, aReRead);
       
   296 	DoTestFileRead(512+misalignedOffset, aFileSize, aReRead);
       
   297 	DoTestFileRead(4096+misalignedOffset, aFileSize, aReRead);
       
   298 	DoTestFileRead(32768+misalignedOffset, aFileSize, aReRead);
       
   299 	DoTestFileRead(64 * 1024+misalignedOffset, aFileSize, aReRead);
       
   300 	DoTestFileRead(K1M+misalignedOffset, aFileSize, aReRead);
       
   301 #endif
       
   302 
       
   303 	}
       
   304 
       
   305 
       
   306 LOCAL_C TInt FloatingPointLoop(TAny* funcCount)
       
   307 	{
       
   308 	TUint& count = *(TUint*) funcCount;
       
   309 	TReal eq = KPi;
       
   310 
       
   311 	FOREVER
       
   312 		{
       
   313 		eq *= eq;
       
   314 		count++;
       
   315 		}
       
   316 
       
   317 	}
       
   318 
       
   319 
       
   320 LOCAL_C void DoTestFileReadCPU(TInt aBlockSize)
       
   321 //
       
   322 // Benchmark CPU utilisation for Read method
       
   323 //
       
   324 // Read operations are performed for 10 seconds whilst a second thread executes floating point calculations
       
   325 // The higher the number of calculations the less amount of CPU time has been used by the Read method.
       
   326 //
       
   327 	{
       
   328 	enum {EFileReadBuffered = 0x00002000, EFileReadDirectIO = 0x00004000};
       
   329 	TInt r = File.Open(TheFs, _L("READCPUTEST"), EFileStream | (gReadCachingOn ? EFileReadBuffered : EFileReadDirectIO));
       
   330 	test(r == KErrNone);
       
   331 
       
   332 	TInt pos = 0;
       
   333 
       
   334 	TUint functionCalls = 0;
       
   335 	TUint fltPntCalls = 0;
       
   336 	RThread fltPntThrd;
       
   337 
       
   338 	TBuf<6> buf = _L("Floaty");
       
   339 	fltPntThrd.Create(buf, FloatingPointLoop, KDefaultStackSize, KHeapSize, KHeapSize, (TAny*) &fltPntCalls);
       
   340 
       
   341 	RTimer timer;
       
   342 	timer.CreateLocal();
       
   343 	TRequestStatus reqStat;
       
   344 
       
   345 	TUint initTicks = 0;
       
   346 	TUint finalTicks = 0;
       
   347 
       
   348 	timer.After(reqStat, KFloatingPointTestTime); // After 10 secs
       
   349 	initTicks = User::FastCounter();
       
   350 
       
   351 	// up the priority of this thread so that we only run the floating point thread when this thread is idle
       
   352 	RThread				thisThread;
       
   353 	thisThread.SetPriority(EPriorityMuchMore);
       
   354 
       
   355 	TRequestStatus req;
       
   356 	fltPntThrd.Logon(req);
       
   357 
       
   358 	fltPntThrd.Resume();
       
   359 
       
   360 	for (TInt i = 0; reqStat==KRequestPending; i++)
       
   361 		{
       
   362 		TInt r = File.Read(pos, DataBuf, aBlockSize);
       
   363 		test (r == KErrNone);
       
   364 
       
   365 		pos += aBlockSize;
       
   366 		if (pos > KMaxFileSize-aBlockSize)
       
   367 			pos = 0;
       
   368 
       
   369 		functionCalls++;
       
   370 		}
       
   371 
       
   372 	TUint fltPntCallsFinal = fltPntCalls;
       
   373 	fltPntThrd.Kill(KErrNone);
       
   374 
       
   375 	finalTicks = User::FastCounter();
       
   376 
       
   377 	fltPntThrd.Close();
       
   378 	User::WaitForRequest(req);
       
   379 
       
   380 	TInt dataTransferred = functionCalls * aBlockSize;
       
   381 
       
   382 	TTimeIntervalMicroSeconds duration = TInt64(finalTicks - initTicks) * TInt64(1000000) / TInt64(gFastCounterFreq) ;
       
   383 
       
   384 	TReal transferRate =  TReal32(dataTransferred) /
       
   385 						 TReal(duration.Int64()) * TReal(1000000) / TReal(K1K); // KB/s
       
   386 
       
   387 	test.Printf(_L("Read %7d bytes in %7d byte blocks:\t%11.3f KBytes/s; %d Flt Calcs\n"),
       
   388 				    dataTransferred, aBlockSize, transferRate, fltPntCallsFinal);
       
   389 
       
   390 	timer.Close();
       
   391 
       
   392 	File.Close();
       
   393 
       
   394 	return;
       
   395 	}
       
   396 
       
   397 
       
   398 LOCAL_C void TestFileReadCPU(TBool aMisalignedReadWrites = EFalse)
       
   399 //
       
   400 // Benchmark CPU utilisation for Read method
       
   401 //
       
   402 	{
       
   403 	ClearSessionDirectory();
       
   404 	test.Next(_L("Benchmark Read method CPU Utilisation"));
       
   405 
       
   406 	test.Printf(_L("MisalignedReadWrites %d\n"), aMisalignedReadWrites);
       
   407 	TInt misalignedOffset = aMisalignedReadWrites ? 1 : 0;
       
   408 
       
   409 	// Create test data
       
   410 	test.Printf(_L("Creating test file..."));
       
   411 	DataBuf.SetLength(KMaxFileSize);
       
   412 
       
   413 	TInt r = File.Create(TheFs, _L("READCPUTEST"), EFileStream | EFileWriteDirectIO);
       
   414 	test(r == KErrNone);
       
   415 
       
   416 	File.Write(DataBuf);
       
   417 
       
   418 	test.Printf(_L("done\n"));
       
   419 	File.Close();
       
   420 
       
   421 	DoTestFileReadCPU(1+misalignedOffset);
       
   422 	DoTestFileReadCPU(2+misalignedOffset);
       
   423 	DoTestFileReadCPU(4+misalignedOffset);
       
   424 	DoTestFileReadCPU(8+misalignedOffset);
       
   425 	DoTestFileReadCPU(16+misalignedOffset);
       
   426 	DoTestFileReadCPU(32+misalignedOffset);
       
   427 	DoTestFileReadCPU(64+misalignedOffset);
       
   428 	DoTestFileReadCPU(128+misalignedOffset);
       
   429 	DoTestFileReadCPU(256+misalignedOffset);
       
   430 	DoTestFileReadCPU(512+misalignedOffset);
       
   431 	DoTestFileReadCPU(1024+misalignedOffset);
       
   432 	DoTestFileReadCPU(2 * 1024+misalignedOffset);
       
   433 	DoTestFileReadCPU(4 * 1024+misalignedOffset);
       
   434 	DoTestFileReadCPU(8 * 1024+misalignedOffset);
       
   435 	DoTestFileReadCPU(16 * 1024+misalignedOffset);
       
   436 	DoTestFileReadCPU(32 * 1024+misalignedOffset);
       
   437 	DoTestFileReadCPU(64 * 1024+misalignedOffset);
       
   438 	DoTestFileReadCPU(128 * 1024+misalignedOffset);
       
   439 	DoTestFileReadCPU(256 * 1024+misalignedOffset);
       
   440 	DoTestFileReadCPU(512 * 1024+misalignedOffset);
       
   441 	DoTestFileReadCPU(K1M+misalignedOffset);
       
   442 
       
   443 
       
   444 	r = TheFs.Delete(_L("READCPUTEST"));
       
   445 	test(r == KErrNone);
       
   446 	}
       
   447 
       
   448 
       
   449 LOCAL_C void DoTestFileWrite(TInt aBlockSize, TInt aFileSize = KMaxFileSize, TBool aUpdate = EFalse)
       
   450 //
       
   451 // Do Write benchmark
       
   452 //
       
   453 	{
       
   454 	DataBuf.SetLength(aBlockSize);
       
   455 	const TInt maxWriteCount = aFileSize / aBlockSize;
       
   456 
       
   457 	TFileName testDir(_L("?:\\F32-TST\\"));
       
   458 	testDir[0] = (TText) gDriveToTest;
       
   459 	TInt r = TheFs.MkDir(testDir);
       
   460 	test(r == KErrNone || r == KErrAlreadyExists);
       
   461 
       
   462 	TFileName fileName;
       
   463 	enum {EFileWriteDirectIO = 0x00001000, EFileWriteBuffered = 0x00000800};
       
   464 	r = File.Temp(TheFs, testDir, fileName, EFileWrite | (gWriteCachingOn ? EFileWriteBuffered : EFileWriteDirectIO));
       
   465 	test(r == KErrNone);
       
   466 
       
   467 	if (aUpdate)
       
   468 		{
       
   469 		TInt r = File.SetSize(aFileSize);
       
   470 		test(r == KErrNone);
       
   471 		}
       
   472 
       
   473 	TUint functionCalls = 0;
       
   474 
       
   475 	TTime startTime;
       
   476 	TTime endTime;
       
   477 	TUint initTicks = 0;
       
   478 	TUint finalTicks = 0;
       
   479 
       
   480 
       
   481 	// we stop after the entire file has been written or after 10 seconds, whichever happens sooner
       
   482 	RTimer timer;
       
   483 	timer.CreateLocal();
       
   484 	TRequestStatus reqStat;
       
   485 
       
   486 	TInt pos = 0;
       
   487 	File.Seek(ESeekStart, pos);
       
   488 
       
   489 	timer.After(reqStat, 10000000); // After 10 secs
       
   490 
       
   491 	startTime.HomeTime();
       
   492 	initTicks = User::FastCounter();
       
   493 
       
   494 	for (TInt i = 0 ; i<maxWriteCount && reqStat==KRequestPending; i++)
       
   495 		{
       
   496 		File.Write(pos, DataBuf, aBlockSize);
       
   497 
       
   498 		pos += aBlockSize;
       
   499 		if (pos > KMaxFileSize-aBlockSize)
       
   500 			pos = 0;
       
   501 
       
   502 		functionCalls++;
       
   503 		}
       
   504 
       
   505 	if (gFlushAfterWrite)
       
   506 		{
       
   507 		r = File.Flush();
       
   508 		test_KErrNone(r)
       
   509 		}
       
   510 
       
   511 	// write file once only
       
   512 	finalTicks = User::FastCounter();
       
   513 	endTime.HomeTime();
       
   514 //	TTimeIntervalMicroSeconds duration = endTime.MicroSecondsFrom(startTime);
       
   515 	TTimeIntervalMicroSeconds duration = TInt64(finalTicks - initTicks) * TInt64(1000000) / TInt64(gFastCounterFreq) ;
       
   516 
       
   517 	TInt dataTransferred = functionCalls * aBlockSize;
       
   518 	TReal transferRate =
       
   519 		TReal32(dataTransferred) /
       
   520 		TReal(duration.Int64()) * TReal(1000000) / TReal(K1K); // KB/s
       
   521 	test.Printf(_L("Write %7d bytes in %7d byte blocks:\t%11.3f KBytes/s (%d microsecs)\n"),
       
   522 		dataTransferred, aBlockSize, transferRate, endTime.MicroSecondsFrom(startTime).Int64());
       
   523 
       
   524 	timer.Close();
       
   525 
       
   526 	File.Close();
       
   527 	r = TheFs.Delete(fileName);
       
   528 	test_KErrNone(r)
       
   529 
       
   530 	return;
       
   531 	}
       
   532 
       
   533 
       
   534 LOCAL_C void TestFileWrite(TInt aFileSize = KMaxFileSize, TBool aMisalignedReadWrites = EFalse, TBool aUpdate = EFalse)
       
   535 //
       
   536 // Benchmark write method
       
   537 //
       
   538 	{
       
   539 	ClearSessionDirectory();
       
   540 	test.Next(_L("Benchmark write method"));
       
   541 
       
   542 	_LIT(KLitUpdate,"update");
       
   543 	_LIT(KLitAppend,"append");
       
   544 	test.Printf(_L("FileSize %d %S MisalignedReadWrites %d\n"), aFileSize, aUpdate? &KLitUpdate : &KLitAppend, aMisalignedReadWrites);
       
   545 
       
   546 	TInt misalignedOffset = aMisalignedReadWrites ? 1 : 0;
       
   547 
       
   548 #if defined (SYMBIAN_TEST_EXTENDED_BUFFER_SIZES)
       
   549 	DoTestFileWrite(1+misalignedOffset, aFileSize, aUpdate);
       
   550 	DoTestFileWrite(2+misalignedOffset, aFileSize, aUpdate);
       
   551 	DoTestFileWrite(4+misalignedOffset, aFileSize, aUpdate);
       
   552 	DoTestFileWrite(8+misalignedOffset, aFileSize, aUpdate);
       
   553 	DoTestFileWrite(16+misalignedOffset, aFileSize, aUpdate);
       
   554 	DoTestFileWrite(32+misalignedOffset, aFileSize, aUpdate);
       
   555 	DoTestFileWrite(64+misalignedOffset, aFileSize, aUpdate);
       
   556 	DoTestFileWrite(128+misalignedOffset, aFileSize, aUpdate);
       
   557 	DoTestFileWrite(256+misalignedOffset, aFileSize, aUpdate);
       
   558 	DoTestFileWrite(512+misalignedOffset, aFileSize, aUpdate);
       
   559 	DoTestFileWrite(1024+misalignedOffset, aFileSize, aUpdate);
       
   560 	DoTestFileWrite(2 * 1024+misalignedOffset, aFileSize, aUpdate);
       
   561 	DoTestFileWrite(4 * 1024+misalignedOffset, aFileSize, aUpdate);
       
   562 	DoTestFileWrite(8 * 1024+misalignedOffset, aFileSize, aUpdate);
       
   563 	DoTestFileWrite(16 * 1024+misalignedOffset, aFileSize, aUpdate);
       
   564 	DoTestFileWrite(32 * 1024+misalignedOffset, aFileSize, aUpdate);
       
   565 	DoTestFileWrite(64 * 1024+misalignedOffset, aFileSize, aUpdate);
       
   566 	DoTestFileWrite(128 * 1024+misalignedOffset, aFileSize, aUpdate);
       
   567 	DoTestFileWrite(256 * 1024+misalignedOffset, aFileSize, aUpdate);
       
   568 	DoTestFileWrite(512 * 1024+misalignedOffset, aFileSize, aUpdate);
       
   569 	DoTestFileWrite(1024 * 1024+misalignedOffset, aFileSize, aUpdate);
       
   570 #else
       
   571 	DoTestFileWrite(16+misalignedOffset, aFileSize, aUpdate);
       
   572 	DoTestFileWrite(512+misalignedOffset, aFileSize, aUpdate);
       
   573 	DoTestFileWrite(4096+misalignedOffset, aFileSize, aUpdate);
       
   574 	DoTestFileWrite(32768+misalignedOffset, aFileSize, aUpdate);
       
   575 	DoTestFileWrite(64 * 1024+misalignedOffset, aFileSize, aUpdate);
       
   576 	DoTestFileWrite(K1M+misalignedOffset, aFileSize, aUpdate);
       
   577 #endif
       
   578 	}
       
   579 
       
   580 
       
   581 
       
   582 LOCAL_C void DoTestFileWriteCPU(TInt aBlockSize)
       
   583 //
       
   584 // Benchmark CPU utilisation for Write method
       
   585 //
       
   586 // Write operations are performed for 10 seconds whilst a second thread executes floating point calculations
       
   587 // The higher the number of calculations the less amount of CPU time has been used by the Write method.
       
   588 //
       
   589 	{
       
   590 	DataBuf.SetLength(aBlockSize);
       
   591 
       
   592 	TFileName testDir(_L("?:\\F32-TST\\"));
       
   593 	testDir[0] = (TText) gDriveToTest;
       
   594 	TInt r = TheFs.MkDir(testDir);
       
   595 	test(r == KErrNone || r == KErrAlreadyExists);
       
   596 
       
   597 	TFileName fileName;
       
   598 	enum {EFileWriteDirectIO = 0x00001000, EFileWriteBuffered = 0x00000800};
       
   599 	r = File.Temp(TheFs, testDir, fileName, EFileWrite | (gWriteCachingOn ? EFileWriteBuffered : EFileWriteDirectIO));
       
   600 	test(r == KErrNone);
       
   601 
       
   602 	TUint functionCalls = 0;
       
   603 	TUint fltPntCalls = 0;
       
   604 	RThread fltPntThrd;
       
   605 
       
   606 	TBuf<6> buf = _L("Floaty");
       
   607 	fltPntThrd.Create(buf, FloatingPointLoop, KDefaultStackSize, KHeapSize, KHeapSize, (TAny*) &fltPntCalls);
       
   608 
       
   609 	TUint initTicks = 0;
       
   610 	TUint finalTicks = 0;
       
   611 
       
   612 	// up the priority of this thread so that we only run the floating point thread when this thread is idle
       
   613 	RThread				thisThread;
       
   614 	thisThread.SetPriority(EPriorityMuchMore);
       
   615 
       
   616 	TRequestStatus req;
       
   617 	fltPntThrd.Logon(req);
       
   618 
       
   619 	RTimer timer;
       
   620 	timer.CreateLocal();
       
   621 	TRequestStatus reqStat;
       
   622 
       
   623 	TInt pos = 0;
       
   624 	File.Seek(ESeekStart, pos);
       
   625 
       
   626 	timer.After(reqStat, KFloatingPointTestTime);
       
   627 	initTicks = User::FastCounter();
       
   628 
       
   629 	fltPntThrd.Resume();
       
   630 
       
   631 	for (TInt i = 0 ; reqStat==KRequestPending; i++)
       
   632 		{
       
   633 		File.Write(DataBuf, aBlockSize);
       
   634 		functionCalls++;
       
   635 		}
       
   636 	TUint fltPntCallsFinal = fltPntCalls;
       
   637 
       
   638 	fltPntThrd.Kill(KErrNone);
       
   639 
       
   640 	finalTicks = User::FastCounter();
       
   641 
       
   642 	fltPntThrd.Close();
       
   643 	User::WaitForRequest(req);
       
   644 
       
   645 	TTimeIntervalMicroSeconds duration = TInt64(finalTicks - initTicks) * TInt64(1000000) / TInt64(gFastCounterFreq) ;
       
   646 
       
   647 	TInt dataTransferred = functionCalls * aBlockSize;
       
   648 	TReal transferRate =  TReal32(dataTransferred) /
       
   649 						 TReal(duration.Int64()) * TReal(1000000) / TReal(K1K); // KB/s
       
   650 
       
   651 	test.Printf(_L("Write %7d bytes in %7d byte blocks:\t%11.3f KBytes/s; %d Flt Calcs\n"),
       
   652 				    dataTransferred, aBlockSize, transferRate, fltPntCallsFinal);
       
   653 
       
   654 	timer.Close();
       
   655 
       
   656 	File.Close();
       
   657 	r = TheFs.Delete(fileName);
       
   658 	test_KErrNone(r)
       
   659 
       
   660 	return;
       
   661 	}
       
   662 
       
   663 
       
   664 LOCAL_C void TestFileWriteCPU(TBool aMisalignedReadWrites = EFalse)
       
   665 //
       
   666 // Benchmark CPU utilisation for Write method
       
   667 //
       
   668 	{
       
   669 	ClearSessionDirectory();
       
   670 	test.Next(_L("Benchmark Write method CPU Utilisation"));
       
   671 
       
   672 	test.Printf(_L("MisalignedReadWrites %d\n"), aMisalignedReadWrites);
       
   673 	TInt misalignedOffset = aMisalignedReadWrites ? 1 : 0;
       
   674 
       
   675 	DoTestFileWriteCPU(1+misalignedOffset);
       
   676 	DoTestFileWriteCPU(2+misalignedOffset);
       
   677 	DoTestFileWriteCPU(4+misalignedOffset);
       
   678 	DoTestFileWriteCPU(8+misalignedOffset);
       
   679 	DoTestFileWriteCPU(16+misalignedOffset);
       
   680 	DoTestFileWriteCPU(32+misalignedOffset);
       
   681 	DoTestFileWriteCPU(64+misalignedOffset);
       
   682 	DoTestFileWriteCPU(128+misalignedOffset);
       
   683 	DoTestFileWriteCPU(256+misalignedOffset);
       
   684 	DoTestFileWriteCPU(512+misalignedOffset);
       
   685 	DoTestFileWriteCPU(1024+misalignedOffset);
       
   686 	DoTestFileWriteCPU(2 * 1024+misalignedOffset);
       
   687 	DoTestFileWriteCPU(4 * 1024+misalignedOffset);
       
   688 	DoTestFileWriteCPU(8 * 1024+misalignedOffset);
       
   689 	DoTestFileWriteCPU(16 * 1024+misalignedOffset);
       
   690 	DoTestFileWriteCPU(32 * 1024+misalignedOffset);
       
   691 	DoTestFileWriteCPU(64 * 1024+misalignedOffset);
       
   692 	DoTestFileWriteCPU(128 * 1024+misalignedOffset);
       
   693 	DoTestFileWriteCPU(256 * 1024+misalignedOffset);
       
   694 	DoTestFileWriteCPU(512 * 1024+misalignedOffset);
       
   695 	DoTestFileWriteCPU(K1M+misalignedOffset);
       
   696 	}
       
   697 
       
   698 
       
   699 LOCAL_C void TestFileSeek()
       
   700 //
       
   701 // Benchmark file seek method
       
   702 //
       
   703 	{
       
   704 	ClearSessionDirectory();
       
   705 	test.Next(_L("RFile::Seek method"));
       
   706 	TInt increment=1789; // random number > cluster size
       
   707 	TInt count=0;
       
   708 	TInt pos=0;
       
   709 
       
   710 	// Create test file
       
   711 	TBuf8<1024> testdata(1024);
       
   712 	RFile f;
       
   713 	TInt r=f.Create(TheFs,_L("SEEKTEST"),EFileStream);
       
   714 	test(r==KErrNone);
       
   715 	count=64;
       
   716 	while (count--)
       
   717 		f.Write(testdata);
       
   718 	TInt fileSize=count*testdata.MaxLength();
       
   719 
       
   720 	pos=0;
       
   721 	count=0;
       
   722 	RTimer timer;
       
   723 	timer.CreateLocal();
       
   724 	TRequestStatus reqStat;
       
   725 	timer.After(reqStat,10000000); // After 10 secs
       
   726 	while(reqStat==KRequestPending)
       
   727 		{
       
   728 		TInt dum=(pos+=increment)%fileSize;
       
   729 		f.Seek(ESeekStart,dum);
       
   730 		count++;
       
   731 		}
       
   732 	test.Printf(_L("RFile::Seek operations in 10 secs == %d\n"),count);
       
   733 	timer.Close();
       
   734 
       
   735 	f.Close();
       
   736 	TheFs.Delete(_L("SEEKTEST"));
       
   737 	}
       
   738 
       
   739 #ifdef SYMBIAN_ENABLE_64_BIT_FILE_SERVER_API
       
   740 
       
   741 LOCAL_C void CreateManyLargFiles(TInt aNumber)
       
   742 //
       
   743 // Make a directory with aNumber entries
       
   744 //
       
   745 	{
       
   746 	RFile64 f;
       
   747 	TInt maxEntry=aNumber;
       
   748 
       
   749 	test.Printf(_L("Create a directory with %d entries\n"),aNumber);
       
   750 
       
   751 	TFileName sessionPath;
       
   752 	TInt r=TheFs.SessionPath(sessionPath);
       
   753 	test(r==KErrNone);
       
   754 	r=TheFs.MkDir(_L("\\F32-TST\\"));
       
   755 	test((r==KErrNone)||(r==KErrAlreadyExists));
       
   756 	r=TheFs.MkDir(_L("\\F32-TST\\BENCH_DELETE\\"));
       
   757 	test((r==KErrNone)||(r==KErrAlreadyExists));
       
   758 	TBuf8<8> WriteData =_L8("Wibbleuy");
       
   759 	for (TInt i=0;i<maxEntry;i++)
       
   760 		{
       
   761 		TFileName baseName=_L("\\F32-TST\\BENCH_DELETE\\FILE");
       
   762 		baseName.AppendNum(i);
       
   763 		r=f.Replace(TheFs,baseName,EFileWrite);
       
   764 		test(r==KErrNone);
       
   765 		r = f.SetSize(K3GB);
       
   766 		test(r==KErrNone);
       
   767 		r=f.Write((K3GB-30),WriteData);
       
   768 		test(r==KErrNone);
       
   769 		f.Flush();
       
   770 		f.Close();
       
   771 		}
       
   772 
       
   773 	test.Printf(_L("Test all entries have been created successfully\n"));
       
   774 	TBuf8<8> ReadData;
       
   775 	TInt64 Size=0;
       
   776 	for (TInt j=0;j<=maxEntry;j++)
       
   777 		{
       
   778 		TFileName baseName=_L("\\F32-TST\\BENCH_DELETE\\FILE");
       
   779 		baseName.AppendNum(j);
       
   780 
       
   781 		TInt r=f.Open(TheFs,baseName,EFileRead);
       
   782 		if (r!=KErrNone)
       
   783 			{
       
   784 			test(r==KErrNotFound && j==maxEntry);
       
   785 			return;
       
   786 			}
       
   787 		ReadData.FillZ();
       
   788 		r=f.Read((K3GB-30),ReadData);
       
   789 		test(r==KErrNone);
       
   790 		test(f.Size(Size)==KErrNone);
       
   791 		test(K3GB == Size);
       
   792 		test(ReadData==WriteData);
       
   793 		f.Close();
       
   794 		}
       
   795 	}
       
   796 
       
   797 
       
   798 LOCAL_C void TestLargeFileDelete()
       
   799 //
       
   800 // This test require MMC/SD card size >=4GB-2 in size
       
   801 //
       
   802 	{
       
   803 	ClearSessionDirectory();
       
   804 	test.Next(_L("Benchmark delete large file"));
       
   805 
       
   806 	TInt64 total=0;
       
   807 
       
   808 	TInt cycles=1;
       
   809 
       
   810 	TInt i=0;
       
   811 
       
   812 	//check Disk space and decide how many files to create
       
   813 	TVolumeInfo volInfo;
       
   814     TInt r;
       
   815 
       
   816     r = TheFs.Volume(volInfo);
       
   817     test(r == KErrNone);
       
   818 
       
   819 	TInt numberOfFiles = (TUint)(volInfo.iFree/(K4GB -2));
       
   820 	test.Printf(_L("Number of large files =%d \n"),numberOfFiles);
       
   821 
       
   822 	if(numberOfFiles<=0)
       
   823 		{
       
   824 		test.Printf(_L("Large File delete is skipped \n"));
       
   825 		return;
       
   826 		}
       
   827 
       
   828 	for (; i<cycles; i++)
       
   829 		{
       
   830 	//	Create many files
       
   831 		CreateManyLargFiles(numberOfFiles);
       
   832 
       
   833 		test.Next(_L("Time the delete"));
       
   834 	//	Now delete them and time it
       
   835 		TTime startTime;
       
   836 		startTime.HomeTime();
       
   837 
       
   838 		for (TInt index=0;index<numberOfFiles;index++)
       
   839 			{
       
   840 			TFileName baseName=_L("\\F32-TST\\BENCH_DELETE\\FILE");
       
   841 			baseName.AppendNum(index);
       
   842 
       
   843 			TInt r=TheFs.Delete(baseName);
       
   844 			test(r==KErrNone);
       
   845 			}
       
   846 
       
   847 		TTime endTime;
       
   848 		endTime.HomeTime();
       
   849 		TTimeIntervalMicroSeconds timeTaken;
       
   850 		timeTaken=endTime.MicroSecondsFrom(startTime);
       
   851 		TInt64 time=timeTaken.Int64();
       
   852 		total+=time;
       
   853 		}
       
   854 //	We deleted cycles*numberOfFiles files in total microseconds
       
   855 	TInt64 fileDeleteTime=total/(numberOfFiles*cycles);
       
   856 	test.Next(_L("Benchmarked RFs::Delete()"));
       
   857 	test.Printf(_L("Delete time per file = %d microseconds\n"),fileDeleteTime);
       
   858 
       
   859 	CFileMan* fMan=CFileMan::NewL(TheFs);
       
   860 	total=0;
       
   861 
       
   862 	cycles=1;
       
   863 	i=0;
       
   864 	for (; i<cycles; i++)
       
   865 		{
       
   866 	//	Create many files
       
   867 		CreateManyLargFiles(numberOfFiles);
       
   868 
       
   869 		test.Next(_L("Time the delete"));
       
   870 	//	Now delete them and time it
       
   871 		TTime startTime;
       
   872 		startTime.HomeTime();
       
   873 
       
   874 		for (TInt index=0;index<numberOfFiles;index++)
       
   875 			{
       
   876 			TInt r=fMan->Delete(_L("\\F32-TST\\BENCH_DELETE\\FILE*"));
       
   877 			test(r==KErrNone || r==KErrNotFound);
       
   878 			}
       
   879 
       
   880 		TTime endTime;
       
   881 		endTime.HomeTime();
       
   882 		TTimeIntervalMicroSeconds timeTaken;
       
   883 		timeTaken=endTime.MicroSecondsFrom(startTime);
       
   884 		TInt64 time=timeTaken.Int64();
       
   885 		total+=time;
       
   886 		}
       
   887 //	We deleted cycles*numberOfFiles files in total microseconds
       
   888 	fileDeleteTime=total/(numberOfFiles*cycles);
       
   889 	test.Next(_L("Benchmarked CFileMan::Delete()"));
       
   890 	test.Printf(_L("Delete time per file = %d microseconds\n"),fileDeleteTime);
       
   891 
       
   892 	delete fMan;
       
   893 }
       
   894 
       
   895 #endif //SYMBIAN_ENABLE_64_BIT_FILE_SERVER_API
       
   896 
       
   897 
       
   898 LOCAL_C void CreateManyFiles(TInt aNumber)
       
   899 //
       
   900 // Make a directory with aNumber entries
       
   901 //
       
   902 	{
       
   903 	RFile f;
       
   904 	TInt maxEntry=aNumber;
       
   905 
       
   906 	test.Printf(_L("Create a directory with %d entries\n"),aNumber);
       
   907 
       
   908 	TFileName sessionPath;
       
   909 	TInt r=TheFs.SessionPath(sessionPath);
       
   910 	test(r==KErrNone);
       
   911 	r=TheFs.MkDir(_L("\\F32-TST\\"));
       
   912 	test((r==KErrNone)||(r==KErrAlreadyExists));
       
   913 	r=TheFs.MkDir(_L("\\F32-TST\\BENCH_DELETE\\"));
       
   914 	test((r==KErrNone)||(r==KErrAlreadyExists));
       
   915 
       
   916 	for (TInt i=0;i<maxEntry;i++)
       
   917 		{
       
   918 		TFileName baseName=_L("\\F32-TST\\BENCH_DELETE\\FILE");
       
   919 		baseName.AppendNum(i);
       
   920 		r=f.Replace(TheFs,baseName,EFileRead);
       
   921 		test(r==KErrNone);
       
   922 		r=f.Write(_L8("Wibble"));
       
   923 		test(r==KErrNone);
       
   924 		f.Close();
       
   925 		}
       
   926 
       
   927 	test.Printf(_L("Test all entries have been created successfully\n"));
       
   928 	for (TInt j=0;j<=maxEntry;j++)
       
   929 		{
       
   930 		TFileName baseName=_L("\\F32-TST\\BENCH_DELETE\\FILE");
       
   931 		baseName.AppendNum(j);
       
   932 		TInt r=f.Open(TheFs,baseName,EFileRead);
       
   933 		if (r!=KErrNone)
       
   934 			{
       
   935 			test(r==KErrNotFound && j==maxEntry);
       
   936 			return;
       
   937 			}
       
   938 		TBuf8<16> data;
       
   939 		r=f.Read(data);
       
   940 		test(r==KErrNone);
       
   941 		test(data==_L8("Wibble"));
       
   942 		f.Close();
       
   943 		}
       
   944 	}
       
   945 
       
   946 
       
   947 LOCAL_C void TestFileDelete()
       
   948 //
       
   949 //
       
   950 //
       
   951 	{
       
   952 	ClearSessionDirectory();
       
   953 	test.Next(_L("Benchmark delete"));
       
   954 
       
   955 	TInt64 total=0;
       
   956 	TInt numberOfFiles=100;
       
   957 	TInt cycles=1;
       
   958 
       
   959 	TInt i=0;
       
   960 	for (; i<cycles; i++)
       
   961 		{
       
   962 	//	Create many files
       
   963 		CreateManyFiles(numberOfFiles);
       
   964 
       
   965 		test.Next(_L("Time the delete"));
       
   966 	//	Now delete them and time it
       
   967 		TTime startTime;
       
   968 		startTime.HomeTime();
       
   969 
       
   970 		for (TInt index=0;index<numberOfFiles;index++)
       
   971 			{
       
   972 			TFileName baseName=_L("\\F32-TST\\BENCH_DELETE\\FILE");
       
   973 			baseName.AppendNum(index);
       
   974 
       
   975 			TInt r=TheFs.Delete(baseName);
       
   976 			test(r==KErrNone);
       
   977 			}
       
   978 
       
   979 		TTime endTime;
       
   980 		endTime.HomeTime();
       
   981 		TTimeIntervalMicroSeconds timeTaken;
       
   982 		timeTaken=endTime.MicroSecondsFrom(startTime);
       
   983 		TInt64 time=timeTaken.Int64();
       
   984 		total+=time;
       
   985 		}
       
   986 //	We deleted cycles*numberOfFiles files in total microseconds
       
   987 	TInt64 fileDeleteTime=total/(numberOfFiles*cycles);
       
   988 	test.Next(_L("Benchmarked RFs::Delete()"));
       
   989 	test.Printf(_L("Delete time per file = %d microseconds\n"),fileDeleteTime);
       
   990 
       
   991 	CFileMan* fMan=CFileMan::NewL(TheFs);
       
   992 	total=0;
       
   993 	numberOfFiles=100;
       
   994 	cycles=1;
       
   995 	i=0;
       
   996 	for (; i<cycles; i++)
       
   997 		{
       
   998 	//	Create many files
       
   999 		CreateManyFiles(numberOfFiles);
       
  1000 
       
  1001 		test.Next(_L("Time the delete"));
       
  1002 	//	Now delete them and time it
       
  1003 		TTime startTime;
       
  1004 		startTime.HomeTime();
       
  1005 
       
  1006 		for (TInt index=0;index<numberOfFiles;index++)
       
  1007 			{
       
  1008 			TInt r=fMan->Delete(_L("\\F32-TST\\BENCH_DELETE\\FILE*"));
       
  1009 			test(r==KErrNone || r==KErrNotFound);
       
  1010 			}
       
  1011 
       
  1012 		TTime endTime;
       
  1013 		endTime.HomeTime();
       
  1014 		TTimeIntervalMicroSeconds timeTaken;
       
  1015 		timeTaken=endTime.MicroSecondsFrom(startTime);
       
  1016 		TInt64 time=timeTaken.Int64();
       
  1017 		total+=time;
       
  1018 		}
       
  1019 //	We deleted cycles*numberOfFiles files in total microseconds
       
  1020 	fileDeleteTime=total/(numberOfFiles*cycles);
       
  1021 	test.Next(_L("Benchmarked CFileMan::Delete()"));
       
  1022 	test.Printf(_L("Delete time per file = %d microseconds\n"),fileDeleteTime);
       
  1023 
       
  1024 	delete fMan;
       
  1025 }
       
  1026 
       
  1027 
       
  1028 /*
       
  1029 TInt maxDirEntry=200;
       
  1030 LOCAL_C void TestDirRead()
       
  1031 //
       
  1032 // Benchmark directory read method
       
  1033 //
       
  1034 	{
       
  1035 
       
  1036 	ClearSessionDirectory();
       
  1037 	test.Next(_L("Benchmark directory read method"));
       
  1038 // Create one test entry
       
  1039 	RFile f;
       
  1040 	f.Create(TheFs,_L("ONE.XXX"),EFileStream);
       
  1041 	f.Close();
       
  1042 	TTime start;
       
  1043 	start.HomeTime();
       
  1044 	TInt i=0;
       
  1045 	for (i=0;i<maxDirEntry;i++)
       
  1046 		{
       
  1047 		CDir* dirPtr;
       
  1048 		TheFs.GetDir(_L("*"),KEntryAttMaskSupported,ESortByName,dirPtr);
       
  1049 		delete dirPtr;
       
  1050 		}
       
  1051 	TTime end;
       
  1052 	end.HomeTime();
       
  1053 	DirReadOne=end.MicroSecondsFrom(start);
       
  1054 // Create lost of test entries
       
  1055 	for (i=0;i<maxDirEntry;i++)
       
  1056 		{
       
  1057 		TBuf<12> baseName(_L("MANY"));
       
  1058 		baseName.AppendNum(i,EHex);
       
  1059 		baseName.Append(_L(".TXT"));
       
  1060 		RFile f;
       
  1061 		f.Create(TheFs,baseName,EFileStream);
       
  1062 		f.Close();
       
  1063 		}
       
  1064 	start.HomeTime();
       
  1065 	CDir* dirPtr;
       
  1066 	TheFs.GetDir(_L("*"),KEntryAttMaskSupported,ESortByName,dirPtr);
       
  1067 	delete dirPtr;
       
  1068 	end.HomeTime();
       
  1069 	DirReadMany=end.MicroSecondsFrom(start);
       
  1070 // Select one entry from lots
       
  1071 	start.HomeTime();
       
  1072 	TheFs.GetDir(_L("*.XXX"),KEntryAttMaskSupported,ESortByName,dirPtr);
       
  1073 	end.HomeTime();
       
  1074 	test(dirPtr->Count()==1);
       
  1075 	delete dirPtr;
       
  1076 	DirMatchOne=end.MicroSecondsFrom(start);
       
  1077 	}
       
  1078 
       
  1079 
       
  1080 void LOCAL_C PrintDirResults()
       
  1081 //
       
  1082 // Print results of Directory Benchmark
       
  1083 //
       
  1084 	{
       
  1085 	test.Printf(_L("\nBenchmark: Dir Results\n"));
       
  1086 	test.Printf(_L("Read one entry %d times = %d ms\n"),maxDirEntry,DirReadOne.Int64().GetTInt()/1000);
       
  1087 	test.Printf(_L("Read %d entries = %d ms\n"),maxDirEntry,DirReadMany.Int64().GetTInt()/1000);
       
  1088 	test.Printf(_L("Match 1 entry from %d entries = %d ms\n"),maxDirEntry,DirMatchOne.Int64().GetTInt()/1000);
       
  1089 	test.Printf(_L("Press Enter to continue\n\n"));
       
  1090 	test.Getch();
       
  1091 	}
       
  1092 */
       
  1093 
       
  1094 
       
  1095 LOCAL_C void TestMkDir()
       
  1096 	{
       
  1097 	test.Next(_L("Benchmark MkDir"));
       
  1098 	ClearSessionDirectory();
       
  1099 
       
  1100 	TTime startTime;
       
  1101 	TTime endTime;
       
  1102 	TTimeIntervalMicroSeconds timeTaken(0);
       
  1103 	startTime.HomeTime();
       
  1104 
       
  1105 	const TInt KNumDirEntries = 100;
       
  1106 	for (TInt n=0; n<KNumDirEntries; n++)
       
  1107 		{
       
  1108 		TFileName dirName = _L("\\F32-TST\\DIR_");
       
  1109 		dirName.AppendNum(n);
       
  1110 		dirName.Append(_L("\\"));
       
  1111 		TInt r = TheFs.MkDir(dirName);
       
  1112 		test(r == KErrNone);
       
  1113 		}
       
  1114 
       
  1115 	endTime.HomeTime();
       
  1116 	timeTaken=endTime.MicroSecondsFrom(startTime);
       
  1117 	TInt timeTakenInMs = I64LOW(timeTaken.Int64() / 1000);
       
  1118 	test.Printf(_L("Time taken to create %d entries = %d ms\n"), KNumDirEntries, timeTakenInMs);
       
  1119 	}
       
  1120 
       
  1121 
       
  1122 // Allocate Data Buffers for Read/Write Tests
       
  1123 void AllocateBuffers()
       
  1124 	{
       
  1125 	test.Printf(_L("Allocate Buffers -"));
       
  1126 
       
  1127 	if (gFragSharedMemory || gSharedMemory)
       
  1128 		{
       
  1129 		test.Printf(_L("Shared Memory\n"));
       
  1130 
       
  1131 		RLoader l;
       
  1132 		test(l.Connect()==KErrNone);
       
  1133 		test(l.CancelLazyDllUnload()==KErrNone);
       
  1134 		l.Close();
       
  1135 
       
  1136 		test.Printf(_L("Initialise\n"));
       
  1137 		TInt r = UserHal::PageSizeInBytes(PageSize);
       
  1138 		test(r==KErrNone);
       
  1139 
       
  1140 		test.Printf(_L("Loading test driver\n"));
       
  1141 		r = User::LoadLogicalDevice(KSharedChunkLddName);
       
  1142 		test(r==KErrNone || r==KErrAlreadyExists);
       
  1143 
       
  1144 		test.Printf(_L("Opening channel\n"));
       
  1145 		r = Ldd.Open();
       
  1146 		test(r==KErrNone);
       
  1147 
       
  1148 		test.Printf(_L("Create chunk\n"));
       
  1149 
       
  1150 		TUint aCreateFlags = EMultiple|EOwnsMemory;
       
  1151 	    TCommitType aCommitType = EContiguous;
       
  1152 
       
  1153 	    TUint TotalChunkSize = ChunkSize;  // rounded to nearest Page Size
       
  1154 
       
  1155 		TUint ChunkAttribs = TotalChunkSize|aCreateFlags;
       
  1156 		r = Ldd.CreateChunk(ChunkAttribs);
       
  1157 		test(r==KErrNone);
       
  1158 
       
  1159 		if (gSharedMemory)
       
  1160 			{
       
  1161 		    test.Printf(_L("Commit Contigouos Memory\n"));
       
  1162 		    r = Ldd.CommitMemory(aCommitType,TotalChunkSize);
       
  1163 			test(r==KErrNone);
       
  1164 			}
       
  1165 		else
       
  1166 			{
       
  1167 			test.Printf(_L("Commit Fragmented Memory\n"));
       
  1168 
       
  1169 			// Allocate Pages in reverse order to maximise memory fragmentation
       
  1170 			TUint i = ChunkSize;
       
  1171 			do
       
  1172 				{
       
  1173 				i-=PageSize;
       
  1174 				test.Printf(_L("Commit %d\n"), i);
       
  1175 				r = Ldd.CommitMemory(aCommitType|i,PageSize);
       
  1176 				test(r==KErrNone);
       
  1177 				}while (i>0);
       
  1178 /*
       
  1179 			for (TInt i = (ChunkSize-PageSize); i>=0; )
       
  1180 				{
       
  1181 				test.Printf(_L("Commit %d\n"), i);
       
  1182 				r = Ldd.CommitMemory(aCommitType|i,PageSize);
       
  1183 				test(r==KErrNone);
       
  1184 				i-=PageSize;
       
  1185 				}
       
  1186 */
       
  1187 			}
       
  1188 
       
  1189 		test.Printf(_L("\nOpen user handle\n"));
       
  1190 		r = Ldd.GetChunkHandle(TheChunk);
       
  1191 		test(r==KErrNone);
       
  1192 
       
  1193 		DataBuf.Set(TheChunk.Base(),KMaxFileSize, KMaxFileSize);
       
  1194 		}
       
  1195 	else
       
  1196 		{
       
  1197 		test.Printf(_L("Heap Memory\n"));
       
  1198 		DataBufH = HBufC8::New(KMaxFileSize);
       
  1199 		test(DataBufH != NULL);
       
  1200 
       
  1201 		DataBuf.Set(DataBufH->Des());
       
  1202 		}
       
  1203 	}
       
  1204 
       
  1205 
       
  1206 void DeAllocateBuffers()
       
  1207 	{
       
  1208 	test.Printf(_L("DeAllocate Buffers -"));
       
  1209 
       
  1210 	if (gFragSharedMemory || gSharedMemory)
       
  1211 	{
       
  1212 		test.Printf(_L("Shared Memory\n"));
       
  1213 		test.Printf(_L("Close user chunk handle\n"));
       
  1214 		TheChunk.Close();
       
  1215 
       
  1216 		test.Printf(_L("Close kernel chunk handle\n"));
       
  1217 		TInt r = Ldd.CloseChunk();
       
  1218 		test(r==1);
       
  1219 
       
  1220 		test.Printf(_L("Check chunk is destroyed\n"));
       
  1221 		r = Ldd.IsDestroyed();
       
  1222 		test(r==1);
       
  1223 
       
  1224 		test.Printf(_L("Close test driver\n"));
       
  1225 		Ldd.Close();
       
  1226 		}
       
  1227 	else
       
  1228 		{
       
  1229 		test.Printf(_L("Heap Memory\n"));
       
  1230 		test.Printf(_L("Delete Heap Buffer\n"));
       
  1231 		delete DataBufH;
       
  1232 		}
       
  1233 	}
       
  1234 
       
  1235 void ParseCommandLine()
       
  1236 	{
       
  1237 	TBuf<0x100> cmd;
       
  1238 	User::CommandLine(cmd);
       
  1239 	TLex lex(cmd);
       
  1240 
       
  1241     for (TPtrC token=lex.NextToken(); token.Length() != 0;token.Set(lex.NextToken()))
       
  1242 		{
       
  1243 		if (token.MatchF(RProcess().FileName())==0)
       
  1244 			{
       
  1245 			continue;
       
  1246 			}
       
  1247 
       
  1248 		if (token.CompareF(_L("-m"))== 0)
       
  1249 			{
       
  1250 			gMisalignedReadWrites = ETrue;
       
  1251 			continue;
       
  1252 			}
       
  1253 		if (token.CompareF(_L("-r"))== 0)
       
  1254 			{
       
  1255 			gReadCachingOn = EFalse;
       
  1256 			continue;
       
  1257 			}
       
  1258 		if (token.CompareF(_L("+r"))== 0)
       
  1259 			{
       
  1260 			gReadCachingOn = ETrue;
       
  1261 			continue;
       
  1262 			}
       
  1263 		if (token.CompareF(_L("-w"))== 0)
       
  1264 			{
       
  1265 			gWriteCachingOn = EFalse;
       
  1266 			continue;
       
  1267 			}
       
  1268 		if (token.CompareF(_L("+w"))== 0)
       
  1269 			{
       
  1270 			gWriteCachingOn = ETrue;
       
  1271 			continue;
       
  1272 			}
       
  1273 
       
  1274 		if (token.CompareF(_L("-f"))== 0)
       
  1275 			{
       
  1276 			gFlushAfterWrite = EFalse;
       
  1277 			continue;
       
  1278 			}
       
  1279 		if (token.CompareF(_L("+f"))== 0)
       
  1280 			{
       
  1281 			gFlushAfterWrite = ETrue;
       
  1282 			continue;
       
  1283 			}
       
  1284 		if (token.CompareF(_L("+s"))== 0)
       
  1285 			{
       
  1286 			gSharedMemory = ETrue;
       
  1287 			continue;
       
  1288 			}
       
  1289 		if (token.CompareF(_L("+x"))== 0)
       
  1290 			{
       
  1291 			gFragSharedMemory = ETrue;
       
  1292 			continue;
       
  1293 			}
       
  1294 
       
  1295 		test.Printf(_L("CLP=%S\n"),&token);
       
  1296 
       
  1297 		if(token.Length()!=0)
       
  1298 			{
       
  1299 			gDriveToTest=token[0];
       
  1300 			gDriveToTest.UpperCase();
       
  1301 			}
       
  1302 		else
       
  1303 			gDriveToTest='C';
       
  1304 
       
  1305 #if defined SYMBIAN_TEST_COPY
       
  1306 		token.Set(lex.NextToken());
       
  1307 		if(token.Length()!=0)
       
  1308 			{
       
  1309 			gDriveToTest2=token[0];
       
  1310 			gDriveToTest2.UpperCase();
       
  1311 			}
       
  1312 		else
       
  1313 			gDriveToTest2='C';
       
  1314 		test.Printf(_L("CLP2=%S\n"),&token);
       
  1315 #endif
       
  1316 
       
  1317 		}
       
  1318 	}
       
  1319 
       
  1320 
       
  1321 GLDEF_C void CallTestsL(void)
       
  1322 //
       
  1323 // Call all tests
       
  1324 //
       
  1325 	{
       
  1326 	test.Title();
       
  1327 	test.Start(_L("Start Benchmarking ..."));
       
  1328 
       
  1329 	test.Next(gSessionPath);
       
  1330 
       
  1331 	ParseCommandLine();
       
  1332 
       
  1333 	AllocateBuffers();
       
  1334 	RProcess().SetPriority(EPriorityBackground);
       
  1335 
       
  1336 	TInt r = HAL::Get(HAL::EFastCounterFrequency, gFastCounterFreq);
       
  1337 	test(r == KErrNone);
       
  1338 	test.Printf(_L("HAL::EFastCounterFrequency %d\n"), gFastCounterFreq);
       
  1339 
       
  1340 	test.Printf(_L("gReadCachingOn %d  gWriteCachingOn %d gFlushAfterWrite %d\n"), gReadCachingOn, gWriteCachingOn, gFlushAfterWrite);
       
  1341 
       
  1342 	TestFileSeek();
       
  1343 
       
  1344 	// read once
       
  1345 	TestFileRead(KMaxFileSize, gMisalignedReadWrites, EFalse);
       
  1346 
       
  1347 	// re-read
       
  1348 	TestFileRead(KMaxFileSize, gMisalignedReadWrites, ETrue);
       
  1349 
       
  1350 	TestFileReadCPU(gMisalignedReadWrites);
       
  1351 
       
  1352 	// append to file
       
  1353 	TestFileWrite(KMaxFileSize, gMisalignedReadWrites, EFalse);
       
  1354 
       
  1355 	// update (overwrite) file
       
  1356 	TestFileWrite(KMaxFileSize, gMisalignedReadWrites, ETrue);
       
  1357 
       
  1358 	TestFileWriteCPU(gMisalignedReadWrites);
       
  1359 
       
  1360 	TestFileDelete();
       
  1361 
       
  1362 //	TestDirRead();
       
  1363 //	PrintDirResults();
       
  1364 #ifdef SYMBIAN_ENABLE_64_BIT_FILE_SERVER_API
       
  1365 	TestLargeFileDelete();
       
  1366 #endif //SYMBIAN_ENABLE_64_BIT_FILE_SERVER_API
       
  1367 
       
  1368 	TestMkDir();
       
  1369 
       
  1370 	RecursiveRmDir(gSessionPath);
       
  1371 
       
  1372 	DeAllocateBuffers();
       
  1373 
       
  1374 	test.End();
       
  1375 	test.Close();
       
  1376 	}