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