os/kernelhwsrv/kerneltest/f32test/bench/t_fcachebm.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 // Copyright (c) 2006-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_fcachebm.cpp
    15 // 
    16 //
    17 
    18 #include <f32file.h>
    19 #include <e32test.h>
    20 #include <e32math.h>
    21 #include "t_select.h"
    22 #include "t_benchmain.h"
    23 
    24 //----------------------------------------------------------------------------------------------
    25 //! @SYMTestCaseID      PBASE-T_RCACHE-0192
    26 //! @SYMTestType        CIT
    27 //! @SYMPREQ            PREQ914
    28 //! @SYMTestCaseDesc    This test case is testing performance of the File Server Cache.  
    29 //! @SYMTestActions     0   setup the environment to execute the tests
    30 //!						1	small random reads/writes
    31 //!						2	large sequential reads/writes
    32 //!						3 	streaming test (100, 200 and 500 kbps)
    33 //! @SYMTestExpectedResults Finishes if the system behaves as expected, panics otherwise
    34 //! @SYMTestPriority        High
    35 //! @SYMTestStatus          Implemented
    36 //----------------------------------------------------------------------------------------------
    37 
    38 
    39 GLDEF_D RTest test(_L("File Cache BM"));
    40 
    41 LOCAL_D RSemaphore client;
    42 LOCAL_D const TInt KHeapSize = 0x4000;
    43 LOCAL_D const TInt KTobps = 1000;
    44 LOCAL_D const TInt KByte = 8;
    45 LOCAL_D const TInt KOneSec = 1000000; // One second in microseconds
    46 
    47 // Tests setup
    48 LOCAL_D const TInt KSmallRow = 11;
    49 LOCAL_D const TInt KSmallCol = 7;
    50 LOCAL_D const TInt KSmallThreshold = 64;
    51 LOCAL_D const TInt KSeveralTimes = 10;
    52 
    53 LOCAL_D const TInt KLargeRow = 19;
    54 LOCAL_D const TInt KLargeCol = 3;
    55 
    56 LOCAL_D TInt gCurrentSpeed = 0; 
    57 LOCAL_D TInt gCurrentBS = 0;
    58 
    59 
    60 LOCAL_D TBuf8<4096> buf;
    61 LOCAL_D TDriveList gDriveList;
    62 
    63 // Concurrent thread
    64 RThread gSpeedy;
    65 RThread gSpeedyII;
    66 
    67 TBuf16<25> gBaseFile;
    68 TBuf16<25> gFileA;
    69 TBuf16<25> gFileB;
    70 TBuf16<25> gStreamFile;
    71 TInt64 gMediaSize;
    72 
    73 HBufC8* gBuf = NULL;
    74 TPtr8 gBufReadPtr(NULL, 0);	
    75 HBufC8* gBufSec = NULL;
    76 TPtr8 gBufWritePtr(NULL, 0);	
    77 
    78 
    79 HBufC8* gBufB = NULL;
    80 TPtr8 gBufReadBPtr(NULL, 0);	
    81 TBool gWriting = EFalse;
    82 
    83 LOCAL_D TInt ThreadCount=0;
    84 
    85 enum TTestState 
    86 	{
    87 	ENoThreads,			// No threads 
    88 	ETwoThreadsDif,		// Accessing to different files 
    89 	ETwoThreadsDifDif, 	// Accessing to different files, different blocksizes
    90 	ETwoThreadsSame		// Accessing the same file
    91 	};
    92 
    93 
    94 /** 2 ^ b
    95 
    96 	@param b Power 
    97 */
    98 LOCAL_C TInt Pow(TInt b)
    99 {
   100 	return 1 << b;
   101 }
   102 
   103 /** Pseudo-random number generator, random enough for the purpose
   104 
   105 	@param aMax Upper limit of the number. The interval of generated numbers is [0,aMax)
   106 */
   107 LOCAL_C TInt Rand(TInt aMax) 
   108 {
   109 	return (Math::Random() % aMax);
   110 }
   111 
   112 
   113 /** Fills a buffer with character aC, aC+1, aC+2, ..., aC+32, aC, etc 
   114 
   115 	@param aBuffer 	Buffer to fill out
   116 	@param aLength 	Length to be filled with characters
   117 	@param aC 		Base character to fill the buffer
   118 */
   119 LOCAL_C void FillBuffer(TDes8& aBuffer, TInt aLength, TChar aC)
   120 	{
   121 	test (aBuffer.MaxLength() >= aLength);
   122 	
   123 	for(TInt i = 0; i < aLength; i++)
   124 		{
   125 		aBuffer.Append((i%32)+aC);
   126 		}
   127 	}
   128 	
   129 /** Send content through the RDebug for trgtest 
   130 	not to hung, when the test is not writing
   131 
   132 */
   133 LOCAL_C TInt noise(TAny* )
   134 {
   135 	FOREVER
   136 	{	
   137 		User::After(2147483647); // max value, 35 minutes, 47 seconds
   138 		if(!gWriting)
   139 			RDebug::Print(_L("."));
   140 	}
   141 }
   142 
   143 /**  Delete content of directory
   144 
   145 	@param aDir Directory to be emptied
   146 */
   147 LOCAL_C TInt DeleteAll(TDes16& aDir) 
   148 	{
   149 		TBuf16<100> dir;
   150 		CFileMan* fMan = CFileMan::NewL(TheFs);
   151 		TInt r = 0;
   152 		
   153 		dir = aDir;
   154 		dir.Append(_L("F*.*"));
   155 		r = fMan->Delete(dir);	
   156 
   157 		delete fMan;
   158 		return r;
   159 	}
   160 
   161 
   162 /**   Creates a file of aSize KBytes
   163 
   164 	@param aFile File name 
   165 	@param aSize Size of the file to be created
   166 */
   167 LOCAL_C void CreateFile(TDes16& aFile, TInt aSize)
   168 {
   169 	TInt r = 0;
   170 	RFile file;
   171 	
   172 	
   173 	r = file.Replace(TheFs, aFile, EFileShareAny|EFileWrite);
   174 	FailIfError(r);
   175 
   176 	TInt j = 0;
   177 	while(j <= aSize)
   178 		{
   179 			r = file.Write(gBufWritePtr, KOneK);
   180 			FailIfError(r);
   181 			j += KOneK;
   182 		}					
   183 	file.Close();
   184 }
   185 
   186 /**   Kills the concurrent session
   187 
   188 */
   189 LOCAL_C void DoTestKill()
   190 {
   191 	TInt r = 0;
   192 	
   193 	gSpeedy.Kill(KErrNone);
   194 	FailIfError(r);
   195 	gSpeedy.Close();	
   196 	
   197 	gSpeedyII.Kill(KErrNone);
   198 	FailIfError(r);
   199 	gSpeedyII.Close();	
   200 }
   201 
   202 /** Read aSize KBs from aFile file in blocks of aBlockSize bytes
   203 
   204 	@param aFile 		Name of the file
   205 	@param aPos			Position from where the read starts within the file
   206 	@param aBlockSize 	Block size for the I/O operation
   207 	@param aSize 		
   208 */
   209 LOCAL_C TInt ReadFromFile(TDes16& aFile, TInt aPos, TInt aBlockSize, TInt aSize) 
   210 {
   211 	TInt r = 0;
   212 	TTime startTime;
   213 	TTime endTime;
   214 	RFile file;
   215 	TInt j = 0;
   216 	TInt size = aSize * KOneK;
   217 	TTimeIntervalMicroSeconds timeTaken(0);
   218 
   219 	r = file.Open(TheFs,aFile,EFileShareAny|EFileRead);
   220 	FailIfError(r);
   221 	
   222 	startTime.HomeTime();	
   223 	r = file.Seek(ESeekStart, aPos);
   224 	FailIfError(r);	
   225 	
   226 	while(j <= size)
   227 		{
   228 			r = file.Read(gBufReadPtr, aBlockSize);
   229 			FailIfError(r);
   230 			j += aBlockSize;
   231 		}					
   232 	endTime.HomeTime();
   233 	
   234 	file.Close();
   235 	timeTaken = endTime.MicroSecondsFrom(startTime);
   236 	
   237 	return I64LOW(timeTaken.Int64() / gTimeUnit);
   238 }
   239 
   240 /** Read aSize KBs from aFile file in blocks of aBlockSize bytes several times
   241 
   242 	@param aFile 		Name of the file
   243 	@param ayMax 		Maximum for the position
   244 	@param aBlockSize 	Block size for the I/O operation
   245 	@param aSize 		Size of the file in KB
   246 */
   247 LOCAL_C TInt ReadFromFileSeveralTimes(TDes16& aFile, TInt ayMax, TInt aBlockSize, TInt aSize) 
   248 {
   249 	TInt r = 0;
   250 	TTime startTime;
   251 	TTime endTime;
   252 	RFile file;
   253 	TInt j = 0, i, pos;
   254 	TInt size = aSize * KOneK;
   255 	TTimeIntervalMicroSeconds timeTaken(0);
   256 	TInt64 time = 0;
   257 	
   258 
   259 	r = file.Open(TheFs, aFile, EFileShareAny|EFileRead);
   260 	FailIfError(r);
   261 	
   262 	i = 0;
   263 	while( i < KSeveralTimes ) 
   264 		{
   265 		pos = Rand(Pow(ayMax - 1));
   266 		startTime.HomeTime();	
   267 		r = file.Seek(ESeekStart, pos); 
   268 		FailIfError(r);	
   269 		
   270 		j = 0;
   271 		while(j <= size)
   272 			{
   273 				r = file.Read(gBufReadPtr, aBlockSize);
   274 				FailIfError(r);
   275 				j += aBlockSize;
   276 			}					
   277 		endTime.HomeTime();
   278 
   279 		timeTaken = endTime.MicroSecondsFrom(startTime);
   280 		time += I64LOW(timeTaken.Int64());
   281 		i++;
   282 		}
   283 	
   284 	file.Close();
   285 	
   286 	return I64LOW((time / gTimeUnit) / KSeveralTimes); // Overflow not expected here, since the number is not big enough
   287 }
   288 
   289 
   290 /** Write aSize KBs to  aFile file in blocks of aBlockSize bytes
   291 
   292 	@param aFile 		Name of the file
   293 	@param aPos			Position from where the read starts within the file
   294 	@param aBlockSize 	Block size for the I/O operation
   295 	@param aSize 		Size of the file in KB
   296 */
   297 LOCAL_C TInt WriteToFile(TDes16& aFile, TInt aPos, TInt aBlockSize, TInt aSize) 
   298 {
   299 	TInt r = 0;
   300 	TTime startTime;
   301 	TTime endTime;
   302 	RFile file;
   303 	TInt j = 0;
   304 	TInt size = aSize * KOneK;
   305 	TTimeIntervalMicroSeconds timeTaken(0);
   306 	
   307 	r = file.Open(TheFs, aFile, EFileShareAny|EFileWrite);
   308 	FailIfError(r);
   309 	
   310 	startTime.HomeTime();	
   311 	r = file.Seek(ESeekStart, aPos);
   312 	FailIfError(r);	
   313 	while(j <= size)
   314 		{
   315 			r = file.Write(gBufWritePtr, aBlockSize);
   316 			FailIfError(r);
   317 			j += aBlockSize;
   318 		}					
   319 	endTime.HomeTime();
   320 	
   321 	file.Close();
   322 	timeTaken = endTime.MicroSecondsFrom(startTime);
   323 	
   324 	return I64LOW(timeTaken.Int64() / gTimeUnit);
   325 }
   326 
   327 /** Write aSize KBs to  aFile file in blocks of aBlockSize bytes several times
   328 
   329 	@param aFile 		Name of the file
   330 	@param ayMax 		Maximum for the position
   331 	@param aBlockSize 	Block size for the I/O operation
   332 	@param aSize 		Size of the file in KB
   333 */
   334 LOCAL_C TInt WriteToFileSeveralTimes(TDes16& aFile, TInt ayMax, TInt aBlockSize, TInt aSize) 
   335 {
   336 	TInt r = 0;
   337 	TTime startTime;
   338 	TTime endTime;
   339 	RFile file;
   340 	TInt i, j = 0, pos;
   341 	TInt size = aSize * KOneK;
   342 	TTimeIntervalMicroSeconds timeTaken(0);
   343 	TInt64 time = 0;
   344 	
   345 	r = file.Open(TheFs, aFile, EFileShareAny|EFileWrite);
   346 	FailIfError(r);
   347 	
   348 	i = 0;
   349 	while( i < KSeveralTimes ) 
   350 		{
   351 		pos = Rand(Pow(ayMax - 1));
   352 		startTime.HomeTime();	
   353 		r = file.Seek(ESeekStart, pos);
   354 		FailIfError(r);	
   355 		
   356 		j = 0;
   357 		while(j <= size)
   358 			{
   359 				r = file.Write(gBufWritePtr, aBlockSize);
   360 				FailIfError(r);
   361 				j += aBlockSize;
   362 			}					
   363 		endTime.HomeTime();
   364 	
   365 		timeTaken = endTime.MicroSecondsFrom(startTime);
   366 		time += I64LOW(timeTaken.Int64());
   367 		i++;
   368 		}
   369 		
   370 	file.Close();
   371 
   372 	return I64LOW((time / gTimeUnit) / KSeveralTimes); // Overflow not expected here, since the number is not big enough
   373 }
   374 
   375 /** Read small blocks in the gBaseFile
   376 
   377 */
   378 LOCAL_C TInt ReadSmallBase(TAny* )
   379 {
   380 	RTest test(_L("test 2"));
   381 	RFs fs;
   382 	RFile file;
   383 	TBuf8<1024> dummy(1024);
   384 	TInt blockSize = 0;
   385 	TInt randPos = 0;
   386 	TInt i = 0;
   387 
   388 	TInt r = fs.Connect();
   389 	
   390 	fs.SetSessionPath(gSessionPath);
   391 	r = file.Open(fs, gBaseFile, EFileShareAny|EFileRead);
   392 	client.Signal();
   393 	
   394 	FailIfError(r);
   395 		
   396 	FOREVER
   397 	{	
   398 			randPos = Rand(64) * KOneK ; 
   399 			r = file.Seek(ESeekStart, randPos);
   400 			FailIfError(r);
   401 			blockSize = i;
   402 			
   403 			r = file.Read(dummy, blockSize); // Sync operation
   404 			if(i >= 1023) i = 0;
   405 			else i++;
   406 	}
   407 }
   408 	
   409 /** Read small blocks in gFileA
   410 
   411 */
   412 LOCAL_C TInt ReadSmallA(TAny* )
   413 {
   414 	RTest test(_L("test 2"));
   415 	RFs fs;
   416 	RFile file;
   417 	TInt blockSize = 0;
   418 	TInt randPos = 0;
   419 	TBuf8<1024> dummy(1024);
   420 	TInt i = 0;
   421 
   422 	TInt r = fs.Connect();
   423 	
   424 	fs.SetSessionPath(gSessionPath);
   425 
   426 	r = file.Open(fs,gFileA,EFileShareAny|EFileRead);
   427 	
   428 	client.Signal();
   429 	FailIfError(r);
   430 	
   431 	FOREVER
   432 	{	
   433 			randPos = Rand(64) * KOneK ; 
   434 			r = file.Seek(ESeekStart, randPos);
   435 			FailIfError(r);
   436 			
   437 			blockSize = i;
   438 			
   439 			r = file.Read(dummy, blockSize); // Sync operation
   440 			FailIfError(r);
   441 			if(i >= 1023) i = 0;
   442 			else i++;
   443 	}
   444 }
   445 	
   446 /** Read small blocks in gFileB
   447 
   448 */
   449 LOCAL_C TInt ReadSmallB(TAny* )
   450 	{
   451 	RTest test(_L("test 2"));
   452 	RFs fs;
   453 	RFile file;
   454 	TBuf8<1024> dummy(1024);
   455 	TInt blockSize = 0;
   456 	TInt randPos = 0;
   457 	TInt i = 0;
   458 
   459 	TInt r = fs.Connect();
   460 	
   461 	fs.SetSessionPath(gSessionPath);
   462 	r = file.Open(fs, gFileB, EFileShareAny|EFileRead);
   463 	
   464 	client.Signal();
   465 	FailIfError(r);
   466 	
   467 	FOREVER
   468 	{
   469 		randPos = Rand(64) * KOneK ; 
   470 		r = file.Seek(ESeekStart, randPos);
   471 		FailIfError(r);
   472 		blockSize = i;
   473 		
   474 		r = file.Read(dummy, blockSize); // Sync operation
   475 		FailIfError(r);
   476 		if(i >= 1023) i = 0;
   477 		else i++;
   478 	}
   479 }
   480 
   481 
   482 /** Read large blocks in gBaseFile
   483 
   484 */
   485 LOCAL_C TInt ReadLargeBase(TAny* )
   486 	{
   487 	RTest test(_L("test 2"));
   488 	RFs fs;
   489 	RFile file;
   490 	TInt pos = 0;
   491 	TInt blockSize = 128 * KOneK;
   492 	
   493 	TInt r = fs.Connect();
   494 	
   495 	fs.SetSessionPath(gSessionPath);
   496 	r = file.Open(fs,gBaseFile,EFileShareAny|EFileRead);
   497 	
   498 	client.Signal();
   499 	FailIfError(r);
   500 	
   501 	FOREVER
   502 	{	
   503 			r = file.Seek(ESeekStart, pos);
   504 			FailIfError(r);
   505 			
   506 			r = file.Read(gBufReadBPtr, blockSize); // Sync operation
   507 			FailIfError(r);
   508 	}
   509 }
   510 
   511 /** Read large blocks in gFileA
   512 
   513 */
   514 LOCAL_C TInt ReadLargeA(TAny* )
   515 {
   516 	RTest test(_L("test 2"));
   517 	RFs fs;
   518 	RFile file;
   519 	TInt blockSize = 128 * KOneK;
   520 	TInt pos = 0;
   521 
   522 	TInt r = fs.Connect();
   523 
   524 	fs.SetSessionPath(gSessionPath);
   525 	
   526 	r = file.Open(fs,gFileA,EFileShareAny|EFileRead);
   527 	
   528 	client.Signal();
   529 	FailIfError(r);
   530 		
   531 	FOREVER
   532 	{	
   533 		r = file.Seek(ESeekStart, pos);
   534 		FailIfError(r);
   535 		
   536 		r = file.Read(gBufReadBPtr, blockSize); // Sync operation
   537 		FailIfError(r);
   538 	}
   539 }
   540 	
   541 /** Read large blocks in gFileB
   542 
   543 */
   544 LOCAL_C TInt ReadLargeB(TAny* )
   545 {
   546 	RTest test(_L("test 2"));
   547 	RFs fs;
   548 	RFile file;
   549 	TInt blockSize = 128 * KOneK;
   550 	TInt pos = 0;
   551 
   552 	TInt r=fs.Connect();
   553 	FailIfError(r);
   554 	
   555 	fs.SetSessionPath(gSessionPath);
   556 
   557 	r = file.Open(fs,gFileB,EFileShareAny|EFileRead);
   558 
   559 	client.Signal();
   560 	FailIfError(r);
   561 	
   562 	FOREVER
   563 	{
   564 		r = file.Seek(ESeekStart, pos);
   565 		FailIfError(r);
   566 		
   567 		r = file.Read(gBufReadBPtr, blockSize); // Sync operation
   568 		FailIfError(r);
   569 	}
   570 }
   571 
   572 /** Small reads from a file
   573  
   574 	@param xMax 	Maximum position on the x axe
   575 	@param yMax		Maximum position on the y axe
   576 	@param aCase	Type of test. Possible values:
   577 		 - ENoThreads : isolated
   578 		 - ETwoThreadsSame : with two threads accessing same file
   579 		 - ETwoThreadsDif : with two threads accessing dif. files 
   580 */
   581 LOCAL_C void smallReads(TInt xMax, TInt yMax, TTestState aCase)
   582 	{	
   583 	TInt i = 0;
   584 	TInt j = 0;
   585 	TInt r = 0;
   586 	TInt timeRes = 0;
   587 	
   588 	CreateFile(gBaseFile, Pow(yMax-1));
   589 	
   590 	if(aCase == ETwoThreadsSame) 
   591 		{ // Start two different threads accessing the same file
   592 		TBuf<20> buf = _L("Speedy");
   593 		buf.AppendNum(ThreadCount++);
   594 		r = gSpeedy.Create(buf, ReadSmallBase, KDefaultStackSize, KHeapSize, KHeapSize, NULL);
   595 		FailIfError(r);
   596 		
   597 		buf = _L("Speedy");
   598 		buf.AppendNum(ThreadCount++);
   599 		
   600 		r = gSpeedyII.Create(buf, ReadSmallBase, KDefaultStackSize, KHeapSize, KHeapSize, NULL);
   601 		FailIfError(r);
   602 		
   603 		gSpeedy.Resume();
   604 		gSpeedyII.Resume();
   605 
   606 		client.Wait();
   607 		client.Wait();
   608 		}
   609 	
   610 	if(aCase == ETwoThreadsDif)
   611 		{ // Start two different threads accessing different files
   612 		CreateFile(gFileA, Pow(yMax-1));
   613 		CreateFile(gFileB, Pow(yMax-1));
   614 		
   615 		TBuf<20> buf = _L("Speedy");
   616 		buf.AppendNum(ThreadCount++);
   617 		r = gSpeedy.Create(buf, ReadSmallA, KDefaultStackSize, KHeapSize, KHeapSize, NULL);
   618 		FailIfError(r);
   619 		
   620 		buf = _L("Speedy");
   621 		buf.AppendNum(ThreadCount++);
   622 		
   623 		r = gSpeedyII.Create(buf, ReadSmallB, KDefaultStackSize, KHeapSize, KHeapSize, NULL);
   624 		FailIfError(r);
   625 		
   626 		gSpeedy.Resume();
   627 		gSpeedyII.Resume();
   628 				
   629 		client.Wait();
   630 		client.Wait();
   631 		}
   632 	
   633 	while(i < xMax)
   634 		{ // Actual accesses and timing to the main file
   635 		j = 0;
   636 		PrintResult(i + 1, j + 1, Pow(i));
   637 		while(j < yMax) 
   638 			{
   639 			if(Pow(i) < KSmallThreshold) 
   640 				{
   641 				timeRes = ReadFromFile(gBaseFile, Rand(Pow(yMax - 1)), Pow(i), Pow(j));
   642 				}
   643 			else
   644 				{ // Too small for only one time measure
   645 				timeRes = ReadFromFileSeveralTimes(gBaseFile, yMax, Pow(i), Pow(j)); 			
   646 				}
   647 			
   648 			gWriting = ETrue; 
   649 			User::After(1000000);
   650 
   651 			PrintResultTime(i + 1, j + 2, timeRes); 
   652 			
   653 			gWriting = EFalse;
   654 			
   655 			j++;
   656 			}
   657 		i++;
   658 		}
   659 		
   660 	
   661 	if((aCase == ETwoThreadsSame) || (aCase == ETwoThreadsDif))
   662 		{ // Finish the threads
   663 		DoTestKill();			
   664 		}
   665 	}
   666 
   667 /** Large reads from a file
   668  
   669  	@param xMax 	Maximum position on the x axe
   670 	@param yMax		Maximum position on the y axe
   671 	@param aCase	Type of test. Possible values:
   672 		 - ENoThreads : isolated
   673 		 - ETwoThreadsSame : with two threads accessing same file
   674 		 - ETwoThreadsDif : with two threads accessing dif. files 
   675 		 - ETwoThreadsDifDif : with two threads accessing dif. files, different block sizes (big/small)
   676 */
   677 LOCAL_C void largeReads(TInt xMax, TInt yMax, TTestState aCase)
   678 {
   679 	TInt i = 0;
   680 	TInt j = 0;
   681 	TInt r = 0;
   682 	TInt timeRes = 0;
   683 	
   684 	CreateFile(gBaseFile, 10 * KOneK * KOneK); // 10 Mb 
   685 	
   686 	if(aCase == ETwoThreadsSame) 
   687 	{ // Start two different threads accessing the same file
   688 
   689 		TRAPD(res, gBufB = HBufC8::NewL(256 * KOneK));
   690 		test(res == KErrNone && gBufB != NULL);
   691 		gBufReadBPtr.Set(gBufSec->Des());
   692 
   693 		TBuf<20> buf = _L("Speedy");
   694 		buf.AppendNum(ThreadCount++);
   695 		r = gSpeedy.Create(buf, ReadLargeBase, KDefaultStackSize, KHeapSize, KHeapSize, NULL);
   696 		FailIfError(r);
   697 		
   698 		buf = _L("Speedy");
   699 		buf.AppendNum(ThreadCount++);
   700 		
   701 		r = gSpeedyII.Create(buf, ReadLargeBase, KDefaultStackSize, KHeapSize, KHeapSize, NULL);
   702 		FailIfError(r);
   703 		
   704 		gSpeedy.Resume();
   705 		gSpeedyII.Resume();
   706 
   707 		client.Wait();
   708 		client.Wait();
   709 	}
   710 	
   711 	if(aCase == ETwoThreadsDif)
   712 	{ // Start two different threads accessing different files
   713 	
   714 		CreateFile(gFileA, KOneK * KOneK);
   715 		CreateFile(gFileB, KOneK * KOneK);
   716 		
   717 		TRAPD(res, gBufB = HBufC8::NewL(256 * KOneK));
   718 		test(res == KErrNone && gBufB != NULL);
   719 		gBufReadBPtr.Set(gBufSec->Des());
   720 		
   721 		TBuf<20> buf = _L("Speedy");
   722 		buf.AppendNum(ThreadCount++);
   723 		r = gSpeedy.Create(buf, ReadLargeA, KDefaultStackSize, KHeapSize, KHeapSize, NULL);
   724 		FailIfError(r);
   725 		
   726 		buf = _L("Speedy");
   727 		buf.AppendNum(ThreadCount++);
   728 		
   729 		r = gSpeedyII.Create(buf, ReadLargeB, KDefaultStackSize, KHeapSize, KHeapSize, NULL);
   730 		FailIfError(r);
   731 		
   732 		gSpeedy.Resume();
   733 		gSpeedyII.Resume();
   734 				
   735 		client.Wait();
   736 		client.Wait();
   737 	}
   738 	
   739 	if(aCase == ETwoThreadsDifDif)
   740 	{ // Start two different threads accessing different files
   741 	
   742 		CreateFile(gFileA, KOneK * KOneK);
   743 		CreateFile(gFileB, KOneK * KOneK);
   744 		
   745 		TRAPD(res,gBufB = HBufC8::NewL(256 * KOneK));
   746 		test(res == KErrNone && gBufB != NULL);
   747 		gBufReadBPtr.Set(gBufSec->Des());
   748 		
   749 		TBuf<20> buf=_L("Speedy");
   750 		buf.AppendNum(ThreadCount++);
   751 		r = gSpeedy.Create(buf, ReadLargeA, KDefaultStackSize, KHeapSize, KHeapSize, NULL);
   752 		FailIfError(r);
   753 		
   754 		buf = _L("Speedy");
   755 		buf.AppendNum(ThreadCount++);
   756 		
   757 		r = gSpeedyII.Create(buf, ReadSmallB, KDefaultStackSize, KHeapSize, KHeapSize, NULL);
   758 		FailIfError(r);
   759 		
   760 		gSpeedy.Resume();
   761 		gSpeedyII.Resume();
   762 				
   763 		client.Wait();
   764 		client.Wait();
   765 	}
   766 
   767 	i = 11;
   768 	while(i < xMax )
   769 	{ // Actual accesses and timing to the main file
   770 		j = 0;
   771 		PrintResult(i - 10, j + 1, Pow(i));
   772 		while(j < yMax) 
   773 		{
   774 			TInt size=0;
   775 			if(j == 0) 	size = 100 ; // 100 Kb
   776 			if(j == 1) 	size = KOneK ; // 1 Mb
   777 			if(j == 2) 	size = 10 * KOneK ; // 10 Mb
   778 			
   779 			timeRes = ReadFromFile(gBaseFile, 0, Pow(i), size); 
   780 
   781 			gWriting = ETrue; 
   782 			User::After(1000000);
   783 
   784 			PrintResultTime(i - 10, j + 2, timeRes); 
   785 				
   786 			gWriting = EFalse;
   787 
   788 			j++;
   789 		}
   790 		i++;
   791 	}
   792 	
   793 	if((aCase == ETwoThreadsSame) || (aCase == ETwoThreadsDif) || (aCase == ETwoThreadsDifDif))
   794 	{ // Finish the threads
   795 		DoTestKill();			
   796 		delete gBufB;
   797 	}
   798 	
   799 }
   800 
   801 /** Large writes to a file
   802  
   803 	@param xMax 	Maximum position on the x axe
   804 	@param yMax		Maximum position on the y axe
   805 	@param aCase	Type of test. Possible values:
   806 		 - ENoThreads : isolated
   807 		 - ETwoThreadsSame : with two threads accessing same file
   808 		 - ETwoThreadsDif : with two threads accessing dif. files 
   809 */
   810 LOCAL_C void largeWrites(TInt xMax, TInt yMax, TTestState aCase)
   811 {
   812 	TInt i = 0;
   813 	TInt j = 0;
   814 	TInt r = 0;
   815 	TInt timeRes = 0;
   816 		
   817 	CreateFile(gBaseFile, 10 * KOneK * KOneK); // 10 Mb 
   818 	
   819 	if(aCase == ETwoThreadsSame) 
   820 	{ // Start two different threads accessing the same file
   821 
   822 		TRAPD(res, gBufB = HBufC8::NewL(256 * KOneK));
   823 		test(res == KErrNone && gBufB != NULL);
   824 		gBufReadBPtr.Set(gBufSec->Des());
   825 
   826 		TBuf<20> buf = _L("Speedy");
   827 		buf.AppendNum(ThreadCount++);
   828 		r = gSpeedy.Create(buf, ReadLargeBase, KDefaultStackSize, KHeapSize, KHeapSize, NULL);
   829 		FailIfError(r);
   830 		
   831 		buf = _L("Speedy");
   832 		buf.AppendNum(ThreadCount++);
   833 		
   834 		r = gSpeedyII.Create(buf, ReadLargeBase, KDefaultStackSize, KHeapSize, KHeapSize, NULL);
   835 		FailIfError(r);
   836 		
   837 		gSpeedy.Resume();
   838 		gSpeedyII.Resume();
   839 
   840 		client.Wait();
   841 		client.Wait();
   842 	}
   843 	
   844 	if(aCase == ETwoThreadsDif)
   845 	{ // Start two different threads accessing different files
   846 	
   847 		CreateFile(gFileA, KOneK * KOneK);
   848 		CreateFile(gFileB, KOneK * KOneK);
   849 		
   850 		TRAPD(res, gBufB = HBufC8::NewL(256 * KOneK));
   851 		test(res == KErrNone && gBufB != NULL);
   852 		gBufReadBPtr.Set(gBufSec->Des());
   853 		
   854 		TBuf<20> buf = _L("Speedy");
   855 		buf.AppendNum(ThreadCount++);
   856 		r = gSpeedy.Create(buf, ReadLargeA, KDefaultStackSize, KHeapSize, KHeapSize, NULL);
   857 		FailIfError(r);
   858 		
   859 		buf = _L("Speedy");
   860 		buf.AppendNum(ThreadCount++);
   861 		
   862 		r = gSpeedyII.Create(buf, ReadLargeB, KDefaultStackSize, KHeapSize, KHeapSize, NULL);
   863 		FailIfError(r);
   864 		
   865 		gSpeedy.Resume();
   866 		gSpeedyII.Resume();
   867 				
   868 		client.Wait();
   869 		client.Wait();
   870 	}
   871 	
   872 	i = 11;
   873 	while(i < xMax )
   874 	{ // Actual accesses and timing to the main file
   875 		j = 0;
   876 		PrintResult(i - 10 , j + 1, Pow(i));
   877 		while(j < yMax) 
   878 		{
   879 			TInt size=0;
   880 			if(j == 0) 	size = 100 ; // 100 Kb
   881 			if(j == 1) 	size = KOneK ; // 1 Mb
   882 			if(j == 2) 	size = 10 * KOneK ; // 10 Mb
   883 			timeRes = WriteToFile(gBaseFile, 0, Pow(i), size); 
   884 			
   885 			gWriting = ETrue; 
   886 			User::After(1000000);
   887 
   888 			PrintResultTime(i - 10, j + 2, timeRes); 
   889 			
   890 			gWriting = EFalse;			
   891 			j++;
   892 		}
   893 		i++;
   894 	}
   895 	
   896 	if((aCase == ETwoThreadsSame) || (aCase == ETwoThreadsDif) || (aCase == ETwoThreadsDifDif))
   897 	{ // Finish the threads
   898 		DoTestKill();			
   899 		delete gBufB;
   900 	}
   901 	
   902 }
   903 
   904 /** Small writes to a file
   905  
   906 	@param xMax 	Maximum position on the x axe
   907 	@param yMax		Maximum position on the y axe
   908 	@param aCase	Type of test. Possible values:
   909 		 - ENoThreads : isolated
   910 		 - ETwoThreadsSame : with two threads accessing same file
   911 		 - ETwoThreadsDif : with two threads accessing dif. files 
   912 */
   913 LOCAL_C void smallWrites(TInt xMax, TInt yMax, TTestState aCase)
   914 {
   915 	TInt i = 0;
   916 	TInt j = 0;
   917 	TInt r = 0;
   918 	TInt timeRes = 0;
   919 	
   920 	CreateFile(gBaseFile, Pow(yMax-1));
   921 	
   922 	if(aCase == ETwoThreadsSame) 
   923 	{ // Start two different threads accessing the same file
   924 		TBuf<20> buf = _L("Speedy");
   925 		buf.AppendNum(ThreadCount++);
   926 		r = gSpeedy.Create(buf, ReadSmallBase, KDefaultStackSize, KHeapSize, KHeapSize, NULL);
   927 		FailIfError(r);
   928 		
   929 		buf = _L("Speedy");
   930 		buf.AppendNum(ThreadCount++);
   931 		
   932 		r = gSpeedyII.Create(buf, ReadSmallBase, KDefaultStackSize, KHeapSize, KHeapSize, NULL);
   933 		FailIfError(r);
   934 		
   935 		gSpeedy.Resume();
   936 		gSpeedyII.Resume();
   937 
   938 		client.Wait();
   939 		client.Wait();
   940 	}
   941 	
   942 	if(aCase == ETwoThreadsDif)
   943 	{ // Start two different threads accessing different files
   944 		CreateFile(gFileA, Pow(yMax-1));
   945 		CreateFile(gFileB, Pow(yMax-1));
   946 		
   947 		TBuf<20> buf = _L("Speedy");
   948 		buf.AppendNum(ThreadCount++);
   949 		r = gSpeedy.Create(buf, ReadSmallA, KDefaultStackSize, KHeapSize, KHeapSize, NULL);
   950 		FailIfError(r);
   951 		
   952 		buf = _L("Speedy");
   953 		buf.AppendNum(ThreadCount++);
   954 		
   955 		r = gSpeedyII.Create(buf, ReadSmallB, KDefaultStackSize, KHeapSize, KHeapSize, NULL);
   956 		FailIfError(r);
   957 		
   958 		gSpeedy.Resume();
   959 		gSpeedyII.Resume();
   960 				
   961 		client.Wait();
   962 		client.Wait();
   963 	}
   964 	
   965 	while(i < xMax)
   966 	{
   967 		j = 0;
   968 		PrintResult(i + 1, j + 1, Pow(i));
   969 		while(j < yMax) 
   970 		{
   971 			if(Pow(i) < KSmallThreshold) 
   972 				{
   973 				timeRes = WriteToFile(gBaseFile, Rand(Pow(yMax-1)), Pow(i), Pow(j)); 
   974 				}
   975 			else
   976 				{
   977 				timeRes = WriteToFileSeveralTimes(gBaseFile, yMax, Pow(i), Pow(j)); 
   978 				}
   979 							
   980 			gWriting = ETrue; 
   981 			User::After(1000000);
   982 
   983 			PrintResultTime(i + 1, j + 2, timeRes); 
   984 			
   985 			gWriting = EFalse;
   986 				
   987 			j++;
   988 		}
   989 		i++;
   990 	}
   991 	
   992 	if((aCase == ETwoThreadsSame) || (aCase == ETwoThreadsDif))
   993 	{ // Finish the threads
   994 		DoTestKill();
   995 	}
   996 	
   997 }
   998 
   999 /** This test benchmarks small random r/w (e.g. database access)
  1000 
  1001 	@param aSelector Selection array for manual tests
  1002 */
  1003 LOCAL_C TInt TestSmall(TAny* aSelector)
  1004 {
  1005 	
  1006 	Validate(aSelector);
  1007 	
  1008 	// Each test case of the suite has an identifyer for parsing purposes of the results
  1009 	gTestHarness = 7;	
  1010 	gTestCase = 1;
  1011 	gTimeUnit = 1;
  1012 	
  1013 	PrintHeaders(4, _L("t_fcachebm. Small Random r/w"));
  1014 	
  1015 	// Small reads
  1016 	test.Printf(_L("#~TS_Title_%d,%d: Small reads, no threads \n"), gTestHarness, gTestCase);
  1017 
  1018 	smallReads(KSmallRow, KSmallCol, ENoThreads); 
  1019 
  1020 	gTestCase++;
  1021 	test.Printf(_L("#~TS_Title_%d,%d: Small reads, threads accessing same file \n"), 
  1022 														gTestHarness, gTestCase);
  1023 	
  1024 	smallReads(KSmallRow, KSmallCol, ETwoThreadsSame); 
  1025 	
  1026 	gTestCase++;
  1027 	test.Printf(_L("#~TS_Title_%d,%d: Small reads, threads accessing dif files \n"),
  1028 															 gTestHarness, gTestCase);
  1029 	
  1030 	smallReads(KSmallRow, KSmallCol, ETwoThreadsDif); 
  1031 	
  1032 	gTestCase++;
  1033 	DeleteAll(gSessionPath);
  1034 	
  1035 	// Small writes test case 
  1036 	
  1037 	test.Printf(_L("#~TS_Title_%d,%d: Test small writes\n"), gTestHarness, gTestCase);
  1038 
  1039 	smallWrites(KSmallRow, KSmallCol, ENoThreads); 
  1040 
  1041 	gTestCase++;
  1042 	test.Printf(_L("#~TS_Title_%d,%d: Small writes, threads accessing same file \n"), 
  1043 															gTestHarness, gTestCase);
  1044 	smallWrites(KSmallRow, KSmallCol, ETwoThreadsSame); 
  1045 
  1046 	gTestCase++;
  1047 	test.Printf(_L("#~TS_Title_%d,%d: Small writes, threads accessing dif files \n"),
  1048 															 gTestHarness, gTestCase);
  1049 	smallWrites(KSmallRow, KSmallCol, ETwoThreadsDif); 
  1050 
  1051 	gTestCase++;
  1052 	DeleteAll(gSessionPath);
  1053 	test.Printf(_L("#~TestEnd_%d\n"), gTestHarness);
  1054 	
  1055 	return(KErrNone);
  1056 }
  1057 
  1058 /** This test benchmarks large sequential r/w (e.g. MM)
  1059 
  1060 	@param aSelector Selection array for manual tests
  1061 */
  1062 LOCAL_C TInt TestLarge(TAny* aSelector)
  1063 {
  1064 	
  1065 	Validate(aSelector);
  1066 
  1067 	// Each test case of the suite has an identifyer for parsing purposes of the results
  1068 	gTestHarness = 8;	
  1069 	gTestCase = 1;
  1070 	gTimeUnit = 1000;
  1071 	
  1072 	PrintHeaders(3, _L("t_fcachebm. Large sequential r/w"));
  1073 	
  1074 	// Large reads
  1075 	test.Printf(_L("#~TS_Title_%d,%d: Large sequential reads\n"), gTestHarness, gTestCase);
  1076 	
  1077 	largeReads(KLargeRow, KLargeCol, ENoThreads); 
  1078 
  1079 	gTestCase++;
  1080 	test.Printf(_L("#~TS_Title_%d,%d: Large sequential reads, threads accessing same file\n"), 
  1081 																	gTestHarness, gTestCase);
  1082 	largeReads(KLargeRow, KLargeCol, ETwoThreadsSame); 
  1083 
  1084 	gTestCase++;
  1085 	test.Printf(_L("#~TS_Title_%d,%d: Large sequential reads, threads accessing dif files\n"), 
  1086 																	gTestHarness, gTestCase);
  1087 	largeReads(KLargeRow, KLargeCol, ETwoThreadsDif); 
  1088 
  1089 	gTestCase++;
  1090 	test.Printf(_L("#~TS_Title_%d,%d: Large sequential reads, threads accessing dif files some big some small blocks\n"),
  1091 																	gTestHarness, gTestCase);
  1092 	largeReads(KLargeRow, KLargeCol, ETwoThreadsDifDif); 
  1093 
  1094 	gTestCase++;
  1095 	DeleteAll(gSessionPath);
  1096 
  1097 	// Large writings		
  1098 	test.Printf(_L("#~TS_Title_%d,%d: Large sequential writes\n"), gTestHarness, gTestCase);
  1099 
  1100 	largeWrites(KLargeRow, KLargeCol, ENoThreads); 
  1101 
  1102 	gTestCase++;
  1103 	test.Printf(_L("#~TS_Title_%d,%d: Large sequential writes, threads accessing same file\n"), 
  1104 																	gTestHarness, gTestCase);
  1105 	largeWrites(KLargeRow, KLargeCol, ETwoThreadsSame); 
  1106 
  1107 	gTestCase++;
  1108 	test.Printf(_L("#~TS_Title_%d,%d: Large sequential writes, threads accessing dif files\n"), 
  1109 																	gTestHarness, gTestCase);
  1110 	largeWrites(KLargeRow, KLargeCol, ETwoThreadsDif); 
  1111 
  1112 	gTestCase++;
  1113 	DeleteAll(gSessionPath);
  1114 	test.Printf(_L("#~TestEnd_%d\n"), gTestHarness);
  1115 	
  1116 	return(KErrNone);
  1117 }
  1118 
  1119 /** Writes aSize bytes of data in aBlockSize during aTime seconds 
  1120 	if the aSize bps is not met, it fails
  1121 
  1122 	@param f 			File to write to
  1123 	@param aSize 		Size in bytes of data to be written 
  1124 	@param aBlockSize 	Block size to be used
  1125 	@param aTime 		Time during which the write has to happen in seconds 
  1126 */
  1127 LOCAL_C TBool writeStr( RFile f, TInt aSize, TInt aBlockSize, TInt aTime) 
  1128 {
  1129 	TInt r = 0, j = 0;
  1130 	TTime startTime, endTime;
  1131 	TTimeIntervalMicroSeconds timeTaken(0);
  1132 	TTimeIntervalMicroSeconds32 timeLeft(0);
  1133 	TBool onTarget = ETrue;
  1134 	
  1135 	TInt time;
  1136 
  1137 	TInt i = 0;
  1138 	while((i < aTime) && onTarget) 
  1139 	{
  1140 		// If measuring the CPU time
  1141 		
  1142 		startTime.HomeTime();	
  1143 		j = 0;
  1144 		while(j < aSize)
  1145 			{
  1146 				r = f.Write(gBufWritePtr, aBlockSize);
  1147 				FailIfError(r);
  1148 				j += aBlockSize;
  1149 			}					
  1150 		endTime.HomeTime();
  1151 		
  1152 		timeTaken = endTime.MicroSecondsFrom(startTime);	
  1153 		time = I64LOW(timeTaken.Int64());
  1154 		if(time > KOneSec) 
  1155 		{
  1156 			onTarget = EFalse; 			
  1157 		}
  1158 		
  1159 		timeLeft = KOneSec - time;
  1160 		if(timeLeft.Int() >= 0) 
  1161 		{
  1162 			User::After(timeLeft);
  1163 		}
  1164 		i++;
  1165 	}
  1166 	
  1167 	return onTarget;
  1168 }
  1169 
  1170 /** Reads streaming
  1171 
  1172 */
  1173 LOCAL_C TInt ReadStream(TAny*)
  1174 {
  1175 	RTest test(_L("test 2"));
  1176 	RFs fs;
  1177 	RFile file;
  1178 	TInt j = 0;
  1179 	TTime startTime, endTime;
  1180 	TTimeIntervalMicroSeconds timeTaken(0);
  1181 	TTimeIntervalMicroSeconds32 timeLeft(0);
  1182 	TInt time;
  1183 	TInt size , currentPos = 0; 
  1184 
  1185 	TInt r = fs.Connect();
  1186 	
  1187 	fs.SetSessionPath(gSessionPath);
  1188 	
  1189 	r = file.Open(fs, gStreamFile, EFileShareAny|EFileRead);
  1190 	
  1191 	client.Signal();
  1192 
  1193 	FailIfError(r);
  1194 	r = file.Size(size);
  1195 	FailIfError(r);
  1196 
  1197 	FOREVER
  1198 	{
  1199 		startTime.HomeTime();	
  1200 		j = 0;
  1201 		while(j < (gCurrentSpeed * KOneK))
  1202 			{
  1203 				r=file.Read(gBufReadPtr,gCurrentBS);
  1204 				FailIfError(r);
  1205 				j += gCurrentBS;
  1206 			}					
  1207 		endTime.HomeTime();
  1208 		
  1209 		timeTaken = endTime.MicroSecondsFrom(startTime);	
  1210 		time = I64LOW(timeTaken.Int64());
  1211 		
  1212 		if(time > KOneSec) 
  1213 		{
  1214 			test.Printf(_L("Background Thread: Speed failed to be achieved: %d kbps\n"), gCurrentSpeed);			
  1215 		}
  1216 		
  1217 
  1218 		
  1219 		timeLeft = KOneSec - time;
  1220 		User::After(timeLeft);
  1221 		currentPos += (gCurrentSpeed * KOneK); 
  1222 		r = file.Size(size);
  1223 		FailIfError(r);
  1224 		if(currentPos > size ) 
  1225 		{
  1226 			currentPos = 0;
  1227 			file.Seek(ESeekStart, currentPos);
  1228 		}
  1229 
  1230 	}
  1231 	
  1232 }
  1233 
  1234 /** Test case layout, read/write at aSpeed during aWtime and aRTime
  1235 
  1236 	@param aSpeed 		Target speed in kbps
  1237 	@param aBlockSize 	Block size for the I/O operation
  1238 	@param aWTime		Writing time
  1239 	@param aRTime 		Reading time 		
  1240 */
  1241 LOCAL_C void streamIt ( TInt aSpeed, TInt aBlockSize, TInt aWTime, TInt aRTime, TInt aStep)
  1242 {
  1243 	TInt iSize = (aSpeed * KTobps) / KByte;  // Size in bytes
  1244 	RFile file;
  1245 	TInt pos = 0;
  1246 	TInt r = 0;
  1247 	
  1248 	PrintResult(aStep, 1, aBlockSize);
  1249 	
  1250 	r = file.Replace(TheFs, gStreamFile, EFileShareAny|EFileWrite);
  1251 	FailIfError(r);
  1252 
  1253 	// Streaming to the media during aWTime seconds
  1254 	if(writeStr(file, iSize, aBlockSize, aWTime))
  1255 	{	//Pass (1)
  1256 		PrintResult(aStep, 2, 1); 
  1257 	}
  1258 	else 
  1259 	{ //Fail (0)
  1260 		PrintResult(aStep, 2, 0); 
  1261 	}
  1262 	
  1263 	// Create a different thread for reading from the beginning during aRTime
  1264 	TBuf<20> buf = _L("Speedy");
  1265 	buf.AppendNum(ThreadCount++);
  1266 	
  1267 	gCurrentSpeed = aSpeed; 
  1268 	gCurrentBS = aBlockSize; 
  1269 	r = gSpeedy.Create(buf, ReadStream, KDefaultStackSize, KHeapSize, KHeapSize, NULL);
  1270 	FailIfError(r);
  1271 
  1272 	gSpeedy.Resume();
  1273 	client.Wait();
  1274 
  1275 	// Keep writing during the time the other thread is reading
  1276 	if(writeStr(file, iSize, aBlockSize, aRTime))
  1277 	{ //Pass (1)
  1278 		PrintResult(aStep, 3, 1); 	
  1279 	}
  1280 	else
  1281 	{ //Fail (0)
  1282 		PrintResult(aStep, 3, 0); 
  1283 	}
  1284 	
  1285 	// Writing from the beginning again 
  1286 	file.Seek(ESeekStart, pos);
  1287 	if(writeStr(file, iSize, aBlockSize, aRTime))
  1288 	{ //Pass (1)
  1289 		PrintResult(aStep, 4, 1); 	
  1290 	}
  1291 	else
  1292 	{ //Fail (0)
  1293 		PrintResult(aStep, 4, 0); 
  1294 	}
  1295 	
  1296 
  1297 	// Kill the thread for reading
  1298 	gSpeedy.Kill(KErrNone);
  1299 	FailIfError(r);
  1300 	gSpeedy.Close();	
  1301 	
  1302 	file.Close();	
  1303 }
  1304 
  1305 /** Iterating through different blocksizes
  1306 
  1307 	@param aSpeed Speed at which the test happens
  1308 */
  1309 LOCAL_C void streaming(TInt aSpeed)
  1310 {
  1311 	TInt i = 9; // Pow(i) = 512 bytes
  1312 	TInt blockSize = 0;
  1313 	TInt testStep = 1;
  1314 	
  1315 	while( i < 15 ) // Pow(i) = 16 Kb
  1316 	{
  1317 		blockSize = Pow(i) ; 
  1318 		streamIt(aSpeed, blockSize, 5 * 60, 15, testStep++); // 5 minutes writing , then 15 secs reading
  1319 		i++;
  1320 	}
  1321 }
  1322 
  1323 /** High level test routine. Different test cases executed
  1324 
  1325 	@param aSelector 	Test case configuration in case of manual execution
  1326 */
  1327 LOCAL_C TInt TestStreaming(TAny* aSelector)
  1328 {
  1329 	
  1330 	Validate(aSelector);
  1331 	// Each test case of the suite has an identifyer for parsing purposes of the results
  1332 	gTestHarness = 9;	
  1333 	gTestCase = 1;
  1334 
  1335 
  1336 	PrintHeaders(5, _L("t_fcachebm. Streaming"));
  1337 	
  1338 	test.Printf(_L("#~TS_Title_%d,%d: Writing / reading at 100 kbps\n"), 
  1339 												gTestHarness, gTestCase);
  1340 	
  1341 	streaming(100);
  1342 	
  1343 	test.Printf(_L("#~TS_Title_%d,%d: Writing / reading at 200 kbps\n"), 
  1344 												gTestHarness, ++gTestCase);
  1345 
  1346 	streaming(200);
  1347 
  1348 	test.Printf(_L("#~TS_Title_%d,%d: Writing / reading at 500 kbps\n"), 
  1349 												gTestHarness, ++gTestCase);
  1350 
  1351 	streaming(500);
  1352 
  1353 
  1354 	DeleteAll(gSessionPath);
  1355 
  1356 	// Start the small random reads in the background
  1357 	CreateFile(gBaseFile, Pow(KSmallCol-1));
  1358 	
  1359 	TBuf<20> buf=_L("Speedy");
  1360 	buf.AppendNum(ThreadCount++);
  1361 	
  1362 	TInt r = gSpeedyII.Create(buf, ReadSmallBase, KDefaultStackSize, KHeapSize, KHeapSize, NULL);
  1363 	FailIfError(r);
  1364 
  1365 	gSpeedyII.Resume();
  1366 	client.Wait();
  1367 	
  1368 	// Measure the throughput with background activity
  1369 	test.Printf(_L("#~TS_Title_%d,%d: Writing / reading at 100 kbps, while small reads\n"), 
  1370 																gTestHarness, ++gTestCase);
  1371 
  1372 	streaming(100);	
  1373 
  1374 	test.Printf(_L("#~TS_Title_%d,%d: Writing / reading at 200 kbps, while small reads\n"), 
  1375 																gTestHarness, ++gTestCase);
  1376 
  1377 	streaming(200);
  1378 	
  1379 	test.Printf(_L("#~TS_Title_%d,%d: Writing / reading at 500 kbps, while small reads\n"), 
  1380 																gTestHarness, ++gTestCase);
  1381 	
  1382 	streaming(500);
  1383 	
  1384 	// Kill the small random reads and writes 
  1385 	gSpeedyII.Kill(KErrNone);
  1386 	FailIfError(r);
  1387 	
  1388 	gSpeedyII.Close();	
  1389 	
  1390 	DeleteAll(gSessionPath);
  1391 
  1392 	gTestCase++;
  1393 	test.Printf(_L("#~TestEnd_%d\n"), gTestHarness);
  1394 	
  1395 	return(KErrNone);
  1396 }
  1397 
  1398 /** It goes automatically through all the options
  1399 
  1400 	@param aSelector Configuration in case of manual execution
  1401 */
  1402 LOCAL_C TInt TestAll(TAny* aSelector)
  1403 {
  1404  	TestSmall(aSelector);
  1405  	TestLarge(aSelector);
  1406  	TestStreaming(aSelector);
  1407 
  1408 	return(KErrNone);
  1409 }
  1410 
  1411 /** Call all tests
  1412 
  1413 */
  1414 GLDEF_C void CallTestsL()
  1415 {
  1416 	TBuf16<25> temp;
  1417 	
  1418 	TInt r=client.CreateLocal(0);
  1419 	FailIfError(r);
  1420 	
  1421 	// Setting up the environment and creating the needed files
  1422 	gSessionPath = _L("?:\\F32-TST\\");
  1423 	gSessionPath[0] = (TText) gDriveToTest;
  1424 	
  1425 	FileNamesGeneration(temp, 8, 0, 1);	
  1426 	gBaseFile = gSessionPath;
  1427 	gBaseFile.Append(temp);
  1428 	
  1429 	FileNamesGeneration(temp, 8, 1, 1);	
  1430 	gFileA = gSessionPath;
  1431 	gFileA.Append(temp);
  1432 	
  1433 	FileNamesGeneration(temp, 8, 2, 1);	
  1434 	gFileB = gSessionPath;
  1435 	gFileB.Append(temp);
  1436 
  1437 	FileNamesGeneration(temp, 8, 3, 1);	
  1438 	gStreamFile = gSessionPath;
  1439 	gStreamFile.Append(temp);
  1440 
  1441 	TRAPD(res,gBuf = HBufC8::NewL(256 * KOneK));
  1442 	test(res == KErrNone && gBuf != NULL);
  1443 		
  1444 	gBufWritePtr.Set(gBuf->Des());
  1445 	FillBuffer(gBufWritePtr, 256 * KOneK, 'A');
  1446 	
  1447 	TRAPD(res2, gBufSec = HBufC8::NewL(256 * KOneK));
  1448 	test(res2 == KErrNone && gBufSec != NULL);
  1449 	gBufReadPtr.Set(gBufSec->Des());
  1450 
  1451 	TVolumeInfo volInfo;
  1452 	TInt drive;
  1453 	
  1454 	r = TheFs.CharToDrive(gDriveToTest,drive);
  1455 	FailIfError(r);
  1456 	r = TheFs.Volume(volInfo, drive);
  1457 	FailIfError(r);
  1458 	
  1459 	gMediaSize = volInfo.iSize;
  1460 	
  1461 	FormatFat(gSessionPath[0]-'A');
  1462 	TheFs.MkDirAll(gSessionPath);
  1463 
  1464 	RThread noisy; 
  1465 	TBuf<20> buf = _L("Noisy");
  1466 	r = noisy.Create(buf, noise, KDefaultStackSize, KHeapSize, KHeapSize, NULL);
  1467 	FailIfError(r);
  1468 	
  1469 	noisy.Resume();
  1470 
  1471 	CSelectionBox* TheSelector=CSelectionBox::NewL(test.Console());
  1472 	
  1473 	if(gMode == 0) 
  1474 	{ // Manual
  1475 		gSessionPath=_L("?:\\");
  1476 		TCallBack smallOps(TestSmall, TheSelector);
  1477 		TCallBack largeOps(TestLarge, TheSelector);
  1478 		TCallBack simulOps(TestStreaming, TheSelector);
  1479 		TCallBack tAll(TestAll, TheSelector);
  1480 		TheSelector->AddDriveSelectorL(TheFs);
  1481 		TheSelector->AddLineL(_L("Small random r/w"), smallOps);
  1482 		TheSelector->AddLineL(_L("Large conseq r/w"), largeOps);
  1483 		TheSelector->AddLineL(_L("Streaming"), simulOps);
  1484 		TheSelector->AddLineL(_L("Execute all options"), tAll);
  1485 		TheSelector->Run();
  1486 	}
  1487 	else 
  1488 	{ // Automatic
  1489 		TestAll(TheSelector);
  1490 	}
  1491 	
  1492 	DeleteAll(gSessionPath);
  1493 			
  1494 	client.Close();
  1495 	delete TheSelector;
  1496 	delete gBuf;
  1497 	delete gBufSec;
  1498 	noisy.Kill(KErrNone);
  1499 	noisy.Close();	
  1500 }