1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/kernelhwsrv/kerneltest/f32test/bench/t_fcachebm.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,1500 @@
1.4 +// Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of the License "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +// f32test/bench/t_fcachebm.cpp
1.18 +//
1.19 +//
1.20 +
1.21 +#include <f32file.h>
1.22 +#include <e32test.h>
1.23 +#include <e32math.h>
1.24 +#include "t_select.h"
1.25 +#include "t_benchmain.h"
1.26 +
1.27 +//----------------------------------------------------------------------------------------------
1.28 +//! @SYMTestCaseID PBASE-T_RCACHE-0192
1.29 +//! @SYMTestType CIT
1.30 +//! @SYMPREQ PREQ914
1.31 +//! @SYMTestCaseDesc This test case is testing performance of the File Server Cache.
1.32 +//! @SYMTestActions 0 setup the environment to execute the tests
1.33 +//! 1 small random reads/writes
1.34 +//! 2 large sequential reads/writes
1.35 +//! 3 streaming test (100, 200 and 500 kbps)
1.36 +//! @SYMTestExpectedResults Finishes if the system behaves as expected, panics otherwise
1.37 +//! @SYMTestPriority High
1.38 +//! @SYMTestStatus Implemented
1.39 +//----------------------------------------------------------------------------------------------
1.40 +
1.41 +
1.42 +GLDEF_D RTest test(_L("File Cache BM"));
1.43 +
1.44 +LOCAL_D RSemaphore client;
1.45 +LOCAL_D const TInt KHeapSize = 0x4000;
1.46 +LOCAL_D const TInt KTobps = 1000;
1.47 +LOCAL_D const TInt KByte = 8;
1.48 +LOCAL_D const TInt KOneSec = 1000000; // One second in microseconds
1.49 +
1.50 +// Tests setup
1.51 +LOCAL_D const TInt KSmallRow = 11;
1.52 +LOCAL_D const TInt KSmallCol = 7;
1.53 +LOCAL_D const TInt KSmallThreshold = 64;
1.54 +LOCAL_D const TInt KSeveralTimes = 10;
1.55 +
1.56 +LOCAL_D const TInt KLargeRow = 19;
1.57 +LOCAL_D const TInt KLargeCol = 3;
1.58 +
1.59 +LOCAL_D TInt gCurrentSpeed = 0;
1.60 +LOCAL_D TInt gCurrentBS = 0;
1.61 +
1.62 +
1.63 +LOCAL_D TBuf8<4096> buf;
1.64 +LOCAL_D TDriveList gDriveList;
1.65 +
1.66 +// Concurrent thread
1.67 +RThread gSpeedy;
1.68 +RThread gSpeedyII;
1.69 +
1.70 +TBuf16<25> gBaseFile;
1.71 +TBuf16<25> gFileA;
1.72 +TBuf16<25> gFileB;
1.73 +TBuf16<25> gStreamFile;
1.74 +TInt64 gMediaSize;
1.75 +
1.76 +HBufC8* gBuf = NULL;
1.77 +TPtr8 gBufReadPtr(NULL, 0);
1.78 +HBufC8* gBufSec = NULL;
1.79 +TPtr8 gBufWritePtr(NULL, 0);
1.80 +
1.81 +
1.82 +HBufC8* gBufB = NULL;
1.83 +TPtr8 gBufReadBPtr(NULL, 0);
1.84 +TBool gWriting = EFalse;
1.85 +
1.86 +LOCAL_D TInt ThreadCount=0;
1.87 +
1.88 +enum TTestState
1.89 + {
1.90 + ENoThreads, // No threads
1.91 + ETwoThreadsDif, // Accessing to different files
1.92 + ETwoThreadsDifDif, // Accessing to different files, different blocksizes
1.93 + ETwoThreadsSame // Accessing the same file
1.94 + };
1.95 +
1.96 +
1.97 +/** 2 ^ b
1.98 +
1.99 + @param b Power
1.100 +*/
1.101 +LOCAL_C TInt Pow(TInt b)
1.102 +{
1.103 + return 1 << b;
1.104 +}
1.105 +
1.106 +/** Pseudo-random number generator, random enough for the purpose
1.107 +
1.108 + @param aMax Upper limit of the number. The interval of generated numbers is [0,aMax)
1.109 +*/
1.110 +LOCAL_C TInt Rand(TInt aMax)
1.111 +{
1.112 + return (Math::Random() % aMax);
1.113 +}
1.114 +
1.115 +
1.116 +/** Fills a buffer with character aC, aC+1, aC+2, ..., aC+32, aC, etc
1.117 +
1.118 + @param aBuffer Buffer to fill out
1.119 + @param aLength Length to be filled with characters
1.120 + @param aC Base character to fill the buffer
1.121 +*/
1.122 +LOCAL_C void FillBuffer(TDes8& aBuffer, TInt aLength, TChar aC)
1.123 + {
1.124 + test (aBuffer.MaxLength() >= aLength);
1.125 +
1.126 + for(TInt i = 0; i < aLength; i++)
1.127 + {
1.128 + aBuffer.Append((i%32)+aC);
1.129 + }
1.130 + }
1.131 +
1.132 +/** Send content through the RDebug for trgtest
1.133 + not to hung, when the test is not writing
1.134 +
1.135 +*/
1.136 +LOCAL_C TInt noise(TAny* )
1.137 +{
1.138 + FOREVER
1.139 + {
1.140 + User::After(2147483647); // max value, 35 minutes, 47 seconds
1.141 + if(!gWriting)
1.142 + RDebug::Print(_L("."));
1.143 + }
1.144 +}
1.145 +
1.146 +/** Delete content of directory
1.147 +
1.148 + @param aDir Directory to be emptied
1.149 +*/
1.150 +LOCAL_C TInt DeleteAll(TDes16& aDir)
1.151 + {
1.152 + TBuf16<100> dir;
1.153 + CFileMan* fMan = CFileMan::NewL(TheFs);
1.154 + TInt r = 0;
1.155 +
1.156 + dir = aDir;
1.157 + dir.Append(_L("F*.*"));
1.158 + r = fMan->Delete(dir);
1.159 +
1.160 + delete fMan;
1.161 + return r;
1.162 + }
1.163 +
1.164 +
1.165 +/** Creates a file of aSize KBytes
1.166 +
1.167 + @param aFile File name
1.168 + @param aSize Size of the file to be created
1.169 +*/
1.170 +LOCAL_C void CreateFile(TDes16& aFile, TInt aSize)
1.171 +{
1.172 + TInt r = 0;
1.173 + RFile file;
1.174 +
1.175 +
1.176 + r = file.Replace(TheFs, aFile, EFileShareAny|EFileWrite);
1.177 + FailIfError(r);
1.178 +
1.179 + TInt j = 0;
1.180 + while(j <= aSize)
1.181 + {
1.182 + r = file.Write(gBufWritePtr, KOneK);
1.183 + FailIfError(r);
1.184 + j += KOneK;
1.185 + }
1.186 + file.Close();
1.187 +}
1.188 +
1.189 +/** Kills the concurrent session
1.190 +
1.191 +*/
1.192 +LOCAL_C void DoTestKill()
1.193 +{
1.194 + TInt r = 0;
1.195 +
1.196 + gSpeedy.Kill(KErrNone);
1.197 + FailIfError(r);
1.198 + gSpeedy.Close();
1.199 +
1.200 + gSpeedyII.Kill(KErrNone);
1.201 + FailIfError(r);
1.202 + gSpeedyII.Close();
1.203 +}
1.204 +
1.205 +/** Read aSize KBs from aFile file in blocks of aBlockSize bytes
1.206 +
1.207 + @param aFile Name of the file
1.208 + @param aPos Position from where the read starts within the file
1.209 + @param aBlockSize Block size for the I/O operation
1.210 + @param aSize
1.211 +*/
1.212 +LOCAL_C TInt ReadFromFile(TDes16& aFile, TInt aPos, TInt aBlockSize, TInt aSize)
1.213 +{
1.214 + TInt r = 0;
1.215 + TTime startTime;
1.216 + TTime endTime;
1.217 + RFile file;
1.218 + TInt j = 0;
1.219 + TInt size = aSize * KOneK;
1.220 + TTimeIntervalMicroSeconds timeTaken(0);
1.221 +
1.222 + r = file.Open(TheFs,aFile,EFileShareAny|EFileRead);
1.223 + FailIfError(r);
1.224 +
1.225 + startTime.HomeTime();
1.226 + r = file.Seek(ESeekStart, aPos);
1.227 + FailIfError(r);
1.228 +
1.229 + while(j <= size)
1.230 + {
1.231 + r = file.Read(gBufReadPtr, aBlockSize);
1.232 + FailIfError(r);
1.233 + j += aBlockSize;
1.234 + }
1.235 + endTime.HomeTime();
1.236 +
1.237 + file.Close();
1.238 + timeTaken = endTime.MicroSecondsFrom(startTime);
1.239 +
1.240 + return I64LOW(timeTaken.Int64() / gTimeUnit);
1.241 +}
1.242 +
1.243 +/** Read aSize KBs from aFile file in blocks of aBlockSize bytes several times
1.244 +
1.245 + @param aFile Name of the file
1.246 + @param ayMax Maximum for the position
1.247 + @param aBlockSize Block size for the I/O operation
1.248 + @param aSize Size of the file in KB
1.249 +*/
1.250 +LOCAL_C TInt ReadFromFileSeveralTimes(TDes16& aFile, TInt ayMax, TInt aBlockSize, TInt aSize)
1.251 +{
1.252 + TInt r = 0;
1.253 + TTime startTime;
1.254 + TTime endTime;
1.255 + RFile file;
1.256 + TInt j = 0, i, pos;
1.257 + TInt size = aSize * KOneK;
1.258 + TTimeIntervalMicroSeconds timeTaken(0);
1.259 + TInt64 time = 0;
1.260 +
1.261 +
1.262 + r = file.Open(TheFs, aFile, EFileShareAny|EFileRead);
1.263 + FailIfError(r);
1.264 +
1.265 + i = 0;
1.266 + while( i < KSeveralTimes )
1.267 + {
1.268 + pos = Rand(Pow(ayMax - 1));
1.269 + startTime.HomeTime();
1.270 + r = file.Seek(ESeekStart, pos);
1.271 + FailIfError(r);
1.272 +
1.273 + j = 0;
1.274 + while(j <= size)
1.275 + {
1.276 + r = file.Read(gBufReadPtr, aBlockSize);
1.277 + FailIfError(r);
1.278 + j += aBlockSize;
1.279 + }
1.280 + endTime.HomeTime();
1.281 +
1.282 + timeTaken = endTime.MicroSecondsFrom(startTime);
1.283 + time += I64LOW(timeTaken.Int64());
1.284 + i++;
1.285 + }
1.286 +
1.287 + file.Close();
1.288 +
1.289 + return I64LOW((time / gTimeUnit) / KSeveralTimes); // Overflow not expected here, since the number is not big enough
1.290 +}
1.291 +
1.292 +
1.293 +/** Write aSize KBs to aFile file in blocks of aBlockSize bytes
1.294 +
1.295 + @param aFile Name of the file
1.296 + @param aPos Position from where the read starts within the file
1.297 + @param aBlockSize Block size for the I/O operation
1.298 + @param aSize Size of the file in KB
1.299 +*/
1.300 +LOCAL_C TInt WriteToFile(TDes16& aFile, TInt aPos, TInt aBlockSize, TInt aSize)
1.301 +{
1.302 + TInt r = 0;
1.303 + TTime startTime;
1.304 + TTime endTime;
1.305 + RFile file;
1.306 + TInt j = 0;
1.307 + TInt size = aSize * KOneK;
1.308 + TTimeIntervalMicroSeconds timeTaken(0);
1.309 +
1.310 + r = file.Open(TheFs, aFile, EFileShareAny|EFileWrite);
1.311 + FailIfError(r);
1.312 +
1.313 + startTime.HomeTime();
1.314 + r = file.Seek(ESeekStart, aPos);
1.315 + FailIfError(r);
1.316 + while(j <= size)
1.317 + {
1.318 + r = file.Write(gBufWritePtr, aBlockSize);
1.319 + FailIfError(r);
1.320 + j += aBlockSize;
1.321 + }
1.322 + endTime.HomeTime();
1.323 +
1.324 + file.Close();
1.325 + timeTaken = endTime.MicroSecondsFrom(startTime);
1.326 +
1.327 + return I64LOW(timeTaken.Int64() / gTimeUnit);
1.328 +}
1.329 +
1.330 +/** Write aSize KBs to aFile file in blocks of aBlockSize bytes several times
1.331 +
1.332 + @param aFile Name of the file
1.333 + @param ayMax Maximum for the position
1.334 + @param aBlockSize Block size for the I/O operation
1.335 + @param aSize Size of the file in KB
1.336 +*/
1.337 +LOCAL_C TInt WriteToFileSeveralTimes(TDes16& aFile, TInt ayMax, TInt aBlockSize, TInt aSize)
1.338 +{
1.339 + TInt r = 0;
1.340 + TTime startTime;
1.341 + TTime endTime;
1.342 + RFile file;
1.343 + TInt i, j = 0, pos;
1.344 + TInt size = aSize * KOneK;
1.345 + TTimeIntervalMicroSeconds timeTaken(0);
1.346 + TInt64 time = 0;
1.347 +
1.348 + r = file.Open(TheFs, aFile, EFileShareAny|EFileWrite);
1.349 + FailIfError(r);
1.350 +
1.351 + i = 0;
1.352 + while( i < KSeveralTimes )
1.353 + {
1.354 + pos = Rand(Pow(ayMax - 1));
1.355 + startTime.HomeTime();
1.356 + r = file.Seek(ESeekStart, pos);
1.357 + FailIfError(r);
1.358 +
1.359 + j = 0;
1.360 + while(j <= size)
1.361 + {
1.362 + r = file.Write(gBufWritePtr, aBlockSize);
1.363 + FailIfError(r);
1.364 + j += aBlockSize;
1.365 + }
1.366 + endTime.HomeTime();
1.367 +
1.368 + timeTaken = endTime.MicroSecondsFrom(startTime);
1.369 + time += I64LOW(timeTaken.Int64());
1.370 + i++;
1.371 + }
1.372 +
1.373 + file.Close();
1.374 +
1.375 + return I64LOW((time / gTimeUnit) / KSeveralTimes); // Overflow not expected here, since the number is not big enough
1.376 +}
1.377 +
1.378 +/** Read small blocks in the gBaseFile
1.379 +
1.380 +*/
1.381 +LOCAL_C TInt ReadSmallBase(TAny* )
1.382 +{
1.383 + RTest test(_L("test 2"));
1.384 + RFs fs;
1.385 + RFile file;
1.386 + TBuf8<1024> dummy(1024);
1.387 + TInt blockSize = 0;
1.388 + TInt randPos = 0;
1.389 + TInt i = 0;
1.390 +
1.391 + TInt r = fs.Connect();
1.392 +
1.393 + fs.SetSessionPath(gSessionPath);
1.394 + r = file.Open(fs, gBaseFile, EFileShareAny|EFileRead);
1.395 + client.Signal();
1.396 +
1.397 + FailIfError(r);
1.398 +
1.399 + FOREVER
1.400 + {
1.401 + randPos = Rand(64) * KOneK ;
1.402 + r = file.Seek(ESeekStart, randPos);
1.403 + FailIfError(r);
1.404 + blockSize = i;
1.405 +
1.406 + r = file.Read(dummy, blockSize); // Sync operation
1.407 + if(i >= 1023) i = 0;
1.408 + else i++;
1.409 + }
1.410 +}
1.411 +
1.412 +/** Read small blocks in gFileA
1.413 +
1.414 +*/
1.415 +LOCAL_C TInt ReadSmallA(TAny* )
1.416 +{
1.417 + RTest test(_L("test 2"));
1.418 + RFs fs;
1.419 + RFile file;
1.420 + TInt blockSize = 0;
1.421 + TInt randPos = 0;
1.422 + TBuf8<1024> dummy(1024);
1.423 + TInt i = 0;
1.424 +
1.425 + TInt r = fs.Connect();
1.426 +
1.427 + fs.SetSessionPath(gSessionPath);
1.428 +
1.429 + r = file.Open(fs,gFileA,EFileShareAny|EFileRead);
1.430 +
1.431 + client.Signal();
1.432 + FailIfError(r);
1.433 +
1.434 + FOREVER
1.435 + {
1.436 + randPos = Rand(64) * KOneK ;
1.437 + r = file.Seek(ESeekStart, randPos);
1.438 + FailIfError(r);
1.439 +
1.440 + blockSize = i;
1.441 +
1.442 + r = file.Read(dummy, blockSize); // Sync operation
1.443 + FailIfError(r);
1.444 + if(i >= 1023) i = 0;
1.445 + else i++;
1.446 + }
1.447 +}
1.448 +
1.449 +/** Read small blocks in gFileB
1.450 +
1.451 +*/
1.452 +LOCAL_C TInt ReadSmallB(TAny* )
1.453 + {
1.454 + RTest test(_L("test 2"));
1.455 + RFs fs;
1.456 + RFile file;
1.457 + TBuf8<1024> dummy(1024);
1.458 + TInt blockSize = 0;
1.459 + TInt randPos = 0;
1.460 + TInt i = 0;
1.461 +
1.462 + TInt r = fs.Connect();
1.463 +
1.464 + fs.SetSessionPath(gSessionPath);
1.465 + r = file.Open(fs, gFileB, EFileShareAny|EFileRead);
1.466 +
1.467 + client.Signal();
1.468 + FailIfError(r);
1.469 +
1.470 + FOREVER
1.471 + {
1.472 + randPos = Rand(64) * KOneK ;
1.473 + r = file.Seek(ESeekStart, randPos);
1.474 + FailIfError(r);
1.475 + blockSize = i;
1.476 +
1.477 + r = file.Read(dummy, blockSize); // Sync operation
1.478 + FailIfError(r);
1.479 + if(i >= 1023) i = 0;
1.480 + else i++;
1.481 + }
1.482 +}
1.483 +
1.484 +
1.485 +/** Read large blocks in gBaseFile
1.486 +
1.487 +*/
1.488 +LOCAL_C TInt ReadLargeBase(TAny* )
1.489 + {
1.490 + RTest test(_L("test 2"));
1.491 + RFs fs;
1.492 + RFile file;
1.493 + TInt pos = 0;
1.494 + TInt blockSize = 128 * KOneK;
1.495 +
1.496 + TInt r = fs.Connect();
1.497 +
1.498 + fs.SetSessionPath(gSessionPath);
1.499 + r = file.Open(fs,gBaseFile,EFileShareAny|EFileRead);
1.500 +
1.501 + client.Signal();
1.502 + FailIfError(r);
1.503 +
1.504 + FOREVER
1.505 + {
1.506 + r = file.Seek(ESeekStart, pos);
1.507 + FailIfError(r);
1.508 +
1.509 + r = file.Read(gBufReadBPtr, blockSize); // Sync operation
1.510 + FailIfError(r);
1.511 + }
1.512 +}
1.513 +
1.514 +/** Read large blocks in gFileA
1.515 +
1.516 +*/
1.517 +LOCAL_C TInt ReadLargeA(TAny* )
1.518 +{
1.519 + RTest test(_L("test 2"));
1.520 + RFs fs;
1.521 + RFile file;
1.522 + TInt blockSize = 128 * KOneK;
1.523 + TInt pos = 0;
1.524 +
1.525 + TInt r = fs.Connect();
1.526 +
1.527 + fs.SetSessionPath(gSessionPath);
1.528 +
1.529 + r = file.Open(fs,gFileA,EFileShareAny|EFileRead);
1.530 +
1.531 + client.Signal();
1.532 + FailIfError(r);
1.533 +
1.534 + FOREVER
1.535 + {
1.536 + r = file.Seek(ESeekStart, pos);
1.537 + FailIfError(r);
1.538 +
1.539 + r = file.Read(gBufReadBPtr, blockSize); // Sync operation
1.540 + FailIfError(r);
1.541 + }
1.542 +}
1.543 +
1.544 +/** Read large blocks in gFileB
1.545 +
1.546 +*/
1.547 +LOCAL_C TInt ReadLargeB(TAny* )
1.548 +{
1.549 + RTest test(_L("test 2"));
1.550 + RFs fs;
1.551 + RFile file;
1.552 + TInt blockSize = 128 * KOneK;
1.553 + TInt pos = 0;
1.554 +
1.555 + TInt r=fs.Connect();
1.556 + FailIfError(r);
1.557 +
1.558 + fs.SetSessionPath(gSessionPath);
1.559 +
1.560 + r = file.Open(fs,gFileB,EFileShareAny|EFileRead);
1.561 +
1.562 + client.Signal();
1.563 + FailIfError(r);
1.564 +
1.565 + FOREVER
1.566 + {
1.567 + r = file.Seek(ESeekStart, pos);
1.568 + FailIfError(r);
1.569 +
1.570 + r = file.Read(gBufReadBPtr, blockSize); // Sync operation
1.571 + FailIfError(r);
1.572 + }
1.573 +}
1.574 +
1.575 +/** Small reads from a file
1.576 +
1.577 + @param xMax Maximum position on the x axe
1.578 + @param yMax Maximum position on the y axe
1.579 + @param aCase Type of test. Possible values:
1.580 + - ENoThreads : isolated
1.581 + - ETwoThreadsSame : with two threads accessing same file
1.582 + - ETwoThreadsDif : with two threads accessing dif. files
1.583 +*/
1.584 +LOCAL_C void smallReads(TInt xMax, TInt yMax, TTestState aCase)
1.585 + {
1.586 + TInt i = 0;
1.587 + TInt j = 0;
1.588 + TInt r = 0;
1.589 + TInt timeRes = 0;
1.590 +
1.591 + CreateFile(gBaseFile, Pow(yMax-1));
1.592 +
1.593 + if(aCase == ETwoThreadsSame)
1.594 + { // Start two different threads accessing the same file
1.595 + TBuf<20> buf = _L("Speedy");
1.596 + buf.AppendNum(ThreadCount++);
1.597 + r = gSpeedy.Create(buf, ReadSmallBase, KDefaultStackSize, KHeapSize, KHeapSize, NULL);
1.598 + FailIfError(r);
1.599 +
1.600 + buf = _L("Speedy");
1.601 + buf.AppendNum(ThreadCount++);
1.602 +
1.603 + r = gSpeedyII.Create(buf, ReadSmallBase, KDefaultStackSize, KHeapSize, KHeapSize, NULL);
1.604 + FailIfError(r);
1.605 +
1.606 + gSpeedy.Resume();
1.607 + gSpeedyII.Resume();
1.608 +
1.609 + client.Wait();
1.610 + client.Wait();
1.611 + }
1.612 +
1.613 + if(aCase == ETwoThreadsDif)
1.614 + { // Start two different threads accessing different files
1.615 + CreateFile(gFileA, Pow(yMax-1));
1.616 + CreateFile(gFileB, Pow(yMax-1));
1.617 +
1.618 + TBuf<20> buf = _L("Speedy");
1.619 + buf.AppendNum(ThreadCount++);
1.620 + r = gSpeedy.Create(buf, ReadSmallA, KDefaultStackSize, KHeapSize, KHeapSize, NULL);
1.621 + FailIfError(r);
1.622 +
1.623 + buf = _L("Speedy");
1.624 + buf.AppendNum(ThreadCount++);
1.625 +
1.626 + r = gSpeedyII.Create(buf, ReadSmallB, KDefaultStackSize, KHeapSize, KHeapSize, NULL);
1.627 + FailIfError(r);
1.628 +
1.629 + gSpeedy.Resume();
1.630 + gSpeedyII.Resume();
1.631 +
1.632 + client.Wait();
1.633 + client.Wait();
1.634 + }
1.635 +
1.636 + while(i < xMax)
1.637 + { // Actual accesses and timing to the main file
1.638 + j = 0;
1.639 + PrintResult(i + 1, j + 1, Pow(i));
1.640 + while(j < yMax)
1.641 + {
1.642 + if(Pow(i) < KSmallThreshold)
1.643 + {
1.644 + timeRes = ReadFromFile(gBaseFile, Rand(Pow(yMax - 1)), Pow(i), Pow(j));
1.645 + }
1.646 + else
1.647 + { // Too small for only one time measure
1.648 + timeRes = ReadFromFileSeveralTimes(gBaseFile, yMax, Pow(i), Pow(j));
1.649 + }
1.650 +
1.651 + gWriting = ETrue;
1.652 + User::After(1000000);
1.653 +
1.654 + PrintResultTime(i + 1, j + 2, timeRes);
1.655 +
1.656 + gWriting = EFalse;
1.657 +
1.658 + j++;
1.659 + }
1.660 + i++;
1.661 + }
1.662 +
1.663 +
1.664 + if((aCase == ETwoThreadsSame) || (aCase == ETwoThreadsDif))
1.665 + { // Finish the threads
1.666 + DoTestKill();
1.667 + }
1.668 + }
1.669 +
1.670 +/** Large reads from a file
1.671 +
1.672 + @param xMax Maximum position on the x axe
1.673 + @param yMax Maximum position on the y axe
1.674 + @param aCase Type of test. Possible values:
1.675 + - ENoThreads : isolated
1.676 + - ETwoThreadsSame : with two threads accessing same file
1.677 + - ETwoThreadsDif : with two threads accessing dif. files
1.678 + - ETwoThreadsDifDif : with two threads accessing dif. files, different block sizes (big/small)
1.679 +*/
1.680 +LOCAL_C void largeReads(TInt xMax, TInt yMax, TTestState aCase)
1.681 +{
1.682 + TInt i = 0;
1.683 + TInt j = 0;
1.684 + TInt r = 0;
1.685 + TInt timeRes = 0;
1.686 +
1.687 + CreateFile(gBaseFile, 10 * KOneK * KOneK); // 10 Mb
1.688 +
1.689 + if(aCase == ETwoThreadsSame)
1.690 + { // Start two different threads accessing the same file
1.691 +
1.692 + TRAPD(res, gBufB = HBufC8::NewL(256 * KOneK));
1.693 + test(res == KErrNone && gBufB != NULL);
1.694 + gBufReadBPtr.Set(gBufSec->Des());
1.695 +
1.696 + TBuf<20> buf = _L("Speedy");
1.697 + buf.AppendNum(ThreadCount++);
1.698 + r = gSpeedy.Create(buf, ReadLargeBase, KDefaultStackSize, KHeapSize, KHeapSize, NULL);
1.699 + FailIfError(r);
1.700 +
1.701 + buf = _L("Speedy");
1.702 + buf.AppendNum(ThreadCount++);
1.703 +
1.704 + r = gSpeedyII.Create(buf, ReadLargeBase, KDefaultStackSize, KHeapSize, KHeapSize, NULL);
1.705 + FailIfError(r);
1.706 +
1.707 + gSpeedy.Resume();
1.708 + gSpeedyII.Resume();
1.709 +
1.710 + client.Wait();
1.711 + client.Wait();
1.712 + }
1.713 +
1.714 + if(aCase == ETwoThreadsDif)
1.715 + { // Start two different threads accessing different files
1.716 +
1.717 + CreateFile(gFileA, KOneK * KOneK);
1.718 + CreateFile(gFileB, KOneK * KOneK);
1.719 +
1.720 + TRAPD(res, gBufB = HBufC8::NewL(256 * KOneK));
1.721 + test(res == KErrNone && gBufB != NULL);
1.722 + gBufReadBPtr.Set(gBufSec->Des());
1.723 +
1.724 + TBuf<20> buf = _L("Speedy");
1.725 + buf.AppendNum(ThreadCount++);
1.726 + r = gSpeedy.Create(buf, ReadLargeA, KDefaultStackSize, KHeapSize, KHeapSize, NULL);
1.727 + FailIfError(r);
1.728 +
1.729 + buf = _L("Speedy");
1.730 + buf.AppendNum(ThreadCount++);
1.731 +
1.732 + r = gSpeedyII.Create(buf, ReadLargeB, KDefaultStackSize, KHeapSize, KHeapSize, NULL);
1.733 + FailIfError(r);
1.734 +
1.735 + gSpeedy.Resume();
1.736 + gSpeedyII.Resume();
1.737 +
1.738 + client.Wait();
1.739 + client.Wait();
1.740 + }
1.741 +
1.742 + if(aCase == ETwoThreadsDifDif)
1.743 + { // Start two different threads accessing different files
1.744 +
1.745 + CreateFile(gFileA, KOneK * KOneK);
1.746 + CreateFile(gFileB, KOneK * KOneK);
1.747 +
1.748 + TRAPD(res,gBufB = HBufC8::NewL(256 * KOneK));
1.749 + test(res == KErrNone && gBufB != NULL);
1.750 + gBufReadBPtr.Set(gBufSec->Des());
1.751 +
1.752 + TBuf<20> buf=_L("Speedy");
1.753 + buf.AppendNum(ThreadCount++);
1.754 + r = gSpeedy.Create(buf, ReadLargeA, KDefaultStackSize, KHeapSize, KHeapSize, NULL);
1.755 + FailIfError(r);
1.756 +
1.757 + buf = _L("Speedy");
1.758 + buf.AppendNum(ThreadCount++);
1.759 +
1.760 + r = gSpeedyII.Create(buf, ReadSmallB, KDefaultStackSize, KHeapSize, KHeapSize, NULL);
1.761 + FailIfError(r);
1.762 +
1.763 + gSpeedy.Resume();
1.764 + gSpeedyII.Resume();
1.765 +
1.766 + client.Wait();
1.767 + client.Wait();
1.768 + }
1.769 +
1.770 + i = 11;
1.771 + while(i < xMax )
1.772 + { // Actual accesses and timing to the main file
1.773 + j = 0;
1.774 + PrintResult(i - 10, j + 1, Pow(i));
1.775 + while(j < yMax)
1.776 + {
1.777 + TInt size=0;
1.778 + if(j == 0) size = 100 ; // 100 Kb
1.779 + if(j == 1) size = KOneK ; // 1 Mb
1.780 + if(j == 2) size = 10 * KOneK ; // 10 Mb
1.781 +
1.782 + timeRes = ReadFromFile(gBaseFile, 0, Pow(i), size);
1.783 +
1.784 + gWriting = ETrue;
1.785 + User::After(1000000);
1.786 +
1.787 + PrintResultTime(i - 10, j + 2, timeRes);
1.788 +
1.789 + gWriting = EFalse;
1.790 +
1.791 + j++;
1.792 + }
1.793 + i++;
1.794 + }
1.795 +
1.796 + if((aCase == ETwoThreadsSame) || (aCase == ETwoThreadsDif) || (aCase == ETwoThreadsDifDif))
1.797 + { // Finish the threads
1.798 + DoTestKill();
1.799 + delete gBufB;
1.800 + }
1.801 +
1.802 +}
1.803 +
1.804 +/** Large writes to a file
1.805 +
1.806 + @param xMax Maximum position on the x axe
1.807 + @param yMax Maximum position on the y axe
1.808 + @param aCase Type of test. Possible values:
1.809 + - ENoThreads : isolated
1.810 + - ETwoThreadsSame : with two threads accessing same file
1.811 + - ETwoThreadsDif : with two threads accessing dif. files
1.812 +*/
1.813 +LOCAL_C void largeWrites(TInt xMax, TInt yMax, TTestState aCase)
1.814 +{
1.815 + TInt i = 0;
1.816 + TInt j = 0;
1.817 + TInt r = 0;
1.818 + TInt timeRes = 0;
1.819 +
1.820 + CreateFile(gBaseFile, 10 * KOneK * KOneK); // 10 Mb
1.821 +
1.822 + if(aCase == ETwoThreadsSame)
1.823 + { // Start two different threads accessing the same file
1.824 +
1.825 + TRAPD(res, gBufB = HBufC8::NewL(256 * KOneK));
1.826 + test(res == KErrNone && gBufB != NULL);
1.827 + gBufReadBPtr.Set(gBufSec->Des());
1.828 +
1.829 + TBuf<20> buf = _L("Speedy");
1.830 + buf.AppendNum(ThreadCount++);
1.831 + r = gSpeedy.Create(buf, ReadLargeBase, KDefaultStackSize, KHeapSize, KHeapSize, NULL);
1.832 + FailIfError(r);
1.833 +
1.834 + buf = _L("Speedy");
1.835 + buf.AppendNum(ThreadCount++);
1.836 +
1.837 + r = gSpeedyII.Create(buf, ReadLargeBase, KDefaultStackSize, KHeapSize, KHeapSize, NULL);
1.838 + FailIfError(r);
1.839 +
1.840 + gSpeedy.Resume();
1.841 + gSpeedyII.Resume();
1.842 +
1.843 + client.Wait();
1.844 + client.Wait();
1.845 + }
1.846 +
1.847 + if(aCase == ETwoThreadsDif)
1.848 + { // Start two different threads accessing different files
1.849 +
1.850 + CreateFile(gFileA, KOneK * KOneK);
1.851 + CreateFile(gFileB, KOneK * KOneK);
1.852 +
1.853 + TRAPD(res, gBufB = HBufC8::NewL(256 * KOneK));
1.854 + test(res == KErrNone && gBufB != NULL);
1.855 + gBufReadBPtr.Set(gBufSec->Des());
1.856 +
1.857 + TBuf<20> buf = _L("Speedy");
1.858 + buf.AppendNum(ThreadCount++);
1.859 + r = gSpeedy.Create(buf, ReadLargeA, KDefaultStackSize, KHeapSize, KHeapSize, NULL);
1.860 + FailIfError(r);
1.861 +
1.862 + buf = _L("Speedy");
1.863 + buf.AppendNum(ThreadCount++);
1.864 +
1.865 + r = gSpeedyII.Create(buf, ReadLargeB, KDefaultStackSize, KHeapSize, KHeapSize, NULL);
1.866 + FailIfError(r);
1.867 +
1.868 + gSpeedy.Resume();
1.869 + gSpeedyII.Resume();
1.870 +
1.871 + client.Wait();
1.872 + client.Wait();
1.873 + }
1.874 +
1.875 + i = 11;
1.876 + while(i < xMax )
1.877 + { // Actual accesses and timing to the main file
1.878 + j = 0;
1.879 + PrintResult(i - 10 , j + 1, Pow(i));
1.880 + while(j < yMax)
1.881 + {
1.882 + TInt size=0;
1.883 + if(j == 0) size = 100 ; // 100 Kb
1.884 + if(j == 1) size = KOneK ; // 1 Mb
1.885 + if(j == 2) size = 10 * KOneK ; // 10 Mb
1.886 + timeRes = WriteToFile(gBaseFile, 0, Pow(i), size);
1.887 +
1.888 + gWriting = ETrue;
1.889 + User::After(1000000);
1.890 +
1.891 + PrintResultTime(i - 10, j + 2, timeRes);
1.892 +
1.893 + gWriting = EFalse;
1.894 + j++;
1.895 + }
1.896 + i++;
1.897 + }
1.898 +
1.899 + if((aCase == ETwoThreadsSame) || (aCase == ETwoThreadsDif) || (aCase == ETwoThreadsDifDif))
1.900 + { // Finish the threads
1.901 + DoTestKill();
1.902 + delete gBufB;
1.903 + }
1.904 +
1.905 +}
1.906 +
1.907 +/** Small writes to a file
1.908 +
1.909 + @param xMax Maximum position on the x axe
1.910 + @param yMax Maximum position on the y axe
1.911 + @param aCase Type of test. Possible values:
1.912 + - ENoThreads : isolated
1.913 + - ETwoThreadsSame : with two threads accessing same file
1.914 + - ETwoThreadsDif : with two threads accessing dif. files
1.915 +*/
1.916 +LOCAL_C void smallWrites(TInt xMax, TInt yMax, TTestState aCase)
1.917 +{
1.918 + TInt i = 0;
1.919 + TInt j = 0;
1.920 + TInt r = 0;
1.921 + TInt timeRes = 0;
1.922 +
1.923 + CreateFile(gBaseFile, Pow(yMax-1));
1.924 +
1.925 + if(aCase == ETwoThreadsSame)
1.926 + { // Start two different threads accessing the same file
1.927 + TBuf<20> buf = _L("Speedy");
1.928 + buf.AppendNum(ThreadCount++);
1.929 + r = gSpeedy.Create(buf, ReadSmallBase, KDefaultStackSize, KHeapSize, KHeapSize, NULL);
1.930 + FailIfError(r);
1.931 +
1.932 + buf = _L("Speedy");
1.933 + buf.AppendNum(ThreadCount++);
1.934 +
1.935 + r = gSpeedyII.Create(buf, ReadSmallBase, KDefaultStackSize, KHeapSize, KHeapSize, NULL);
1.936 + FailIfError(r);
1.937 +
1.938 + gSpeedy.Resume();
1.939 + gSpeedyII.Resume();
1.940 +
1.941 + client.Wait();
1.942 + client.Wait();
1.943 + }
1.944 +
1.945 + if(aCase == ETwoThreadsDif)
1.946 + { // Start two different threads accessing different files
1.947 + CreateFile(gFileA, Pow(yMax-1));
1.948 + CreateFile(gFileB, Pow(yMax-1));
1.949 +
1.950 + TBuf<20> buf = _L("Speedy");
1.951 + buf.AppendNum(ThreadCount++);
1.952 + r = gSpeedy.Create(buf, ReadSmallA, KDefaultStackSize, KHeapSize, KHeapSize, NULL);
1.953 + FailIfError(r);
1.954 +
1.955 + buf = _L("Speedy");
1.956 + buf.AppendNum(ThreadCount++);
1.957 +
1.958 + r = gSpeedyII.Create(buf, ReadSmallB, KDefaultStackSize, KHeapSize, KHeapSize, NULL);
1.959 + FailIfError(r);
1.960 +
1.961 + gSpeedy.Resume();
1.962 + gSpeedyII.Resume();
1.963 +
1.964 + client.Wait();
1.965 + client.Wait();
1.966 + }
1.967 +
1.968 + while(i < xMax)
1.969 + {
1.970 + j = 0;
1.971 + PrintResult(i + 1, j + 1, Pow(i));
1.972 + while(j < yMax)
1.973 + {
1.974 + if(Pow(i) < KSmallThreshold)
1.975 + {
1.976 + timeRes = WriteToFile(gBaseFile, Rand(Pow(yMax-1)), Pow(i), Pow(j));
1.977 + }
1.978 + else
1.979 + {
1.980 + timeRes = WriteToFileSeveralTimes(gBaseFile, yMax, Pow(i), Pow(j));
1.981 + }
1.982 +
1.983 + gWriting = ETrue;
1.984 + User::After(1000000);
1.985 +
1.986 + PrintResultTime(i + 1, j + 2, timeRes);
1.987 +
1.988 + gWriting = EFalse;
1.989 +
1.990 + j++;
1.991 + }
1.992 + i++;
1.993 + }
1.994 +
1.995 + if((aCase == ETwoThreadsSame) || (aCase == ETwoThreadsDif))
1.996 + { // Finish the threads
1.997 + DoTestKill();
1.998 + }
1.999 +
1.1000 +}
1.1001 +
1.1002 +/** This test benchmarks small random r/w (e.g. database access)
1.1003 +
1.1004 + @param aSelector Selection array for manual tests
1.1005 +*/
1.1006 +LOCAL_C TInt TestSmall(TAny* aSelector)
1.1007 +{
1.1008 +
1.1009 + Validate(aSelector);
1.1010 +
1.1011 + // Each test case of the suite has an identifyer for parsing purposes of the results
1.1012 + gTestHarness = 7;
1.1013 + gTestCase = 1;
1.1014 + gTimeUnit = 1;
1.1015 +
1.1016 + PrintHeaders(4, _L("t_fcachebm. Small Random r/w"));
1.1017 +
1.1018 + // Small reads
1.1019 + test.Printf(_L("#~TS_Title_%d,%d: Small reads, no threads \n"), gTestHarness, gTestCase);
1.1020 +
1.1021 + smallReads(KSmallRow, KSmallCol, ENoThreads);
1.1022 +
1.1023 + gTestCase++;
1.1024 + test.Printf(_L("#~TS_Title_%d,%d: Small reads, threads accessing same file \n"),
1.1025 + gTestHarness, gTestCase);
1.1026 +
1.1027 + smallReads(KSmallRow, KSmallCol, ETwoThreadsSame);
1.1028 +
1.1029 + gTestCase++;
1.1030 + test.Printf(_L("#~TS_Title_%d,%d: Small reads, threads accessing dif files \n"),
1.1031 + gTestHarness, gTestCase);
1.1032 +
1.1033 + smallReads(KSmallRow, KSmallCol, ETwoThreadsDif);
1.1034 +
1.1035 + gTestCase++;
1.1036 + DeleteAll(gSessionPath);
1.1037 +
1.1038 + // Small writes test case
1.1039 +
1.1040 + test.Printf(_L("#~TS_Title_%d,%d: Test small writes\n"), gTestHarness, gTestCase);
1.1041 +
1.1042 + smallWrites(KSmallRow, KSmallCol, ENoThreads);
1.1043 +
1.1044 + gTestCase++;
1.1045 + test.Printf(_L("#~TS_Title_%d,%d: Small writes, threads accessing same file \n"),
1.1046 + gTestHarness, gTestCase);
1.1047 + smallWrites(KSmallRow, KSmallCol, ETwoThreadsSame);
1.1048 +
1.1049 + gTestCase++;
1.1050 + test.Printf(_L("#~TS_Title_%d,%d: Small writes, threads accessing dif files \n"),
1.1051 + gTestHarness, gTestCase);
1.1052 + smallWrites(KSmallRow, KSmallCol, ETwoThreadsDif);
1.1053 +
1.1054 + gTestCase++;
1.1055 + DeleteAll(gSessionPath);
1.1056 + test.Printf(_L("#~TestEnd_%d\n"), gTestHarness);
1.1057 +
1.1058 + return(KErrNone);
1.1059 +}
1.1060 +
1.1061 +/** This test benchmarks large sequential r/w (e.g. MM)
1.1062 +
1.1063 + @param aSelector Selection array for manual tests
1.1064 +*/
1.1065 +LOCAL_C TInt TestLarge(TAny* aSelector)
1.1066 +{
1.1067 +
1.1068 + Validate(aSelector);
1.1069 +
1.1070 + // Each test case of the suite has an identifyer for parsing purposes of the results
1.1071 + gTestHarness = 8;
1.1072 + gTestCase = 1;
1.1073 + gTimeUnit = 1000;
1.1074 +
1.1075 + PrintHeaders(3, _L("t_fcachebm. Large sequential r/w"));
1.1076 +
1.1077 + // Large reads
1.1078 + test.Printf(_L("#~TS_Title_%d,%d: Large sequential reads\n"), gTestHarness, gTestCase);
1.1079 +
1.1080 + largeReads(KLargeRow, KLargeCol, ENoThreads);
1.1081 +
1.1082 + gTestCase++;
1.1083 + test.Printf(_L("#~TS_Title_%d,%d: Large sequential reads, threads accessing same file\n"),
1.1084 + gTestHarness, gTestCase);
1.1085 + largeReads(KLargeRow, KLargeCol, ETwoThreadsSame);
1.1086 +
1.1087 + gTestCase++;
1.1088 + test.Printf(_L("#~TS_Title_%d,%d: Large sequential reads, threads accessing dif files\n"),
1.1089 + gTestHarness, gTestCase);
1.1090 + largeReads(KLargeRow, KLargeCol, ETwoThreadsDif);
1.1091 +
1.1092 + gTestCase++;
1.1093 + test.Printf(_L("#~TS_Title_%d,%d: Large sequential reads, threads accessing dif files some big some small blocks\n"),
1.1094 + gTestHarness, gTestCase);
1.1095 + largeReads(KLargeRow, KLargeCol, ETwoThreadsDifDif);
1.1096 +
1.1097 + gTestCase++;
1.1098 + DeleteAll(gSessionPath);
1.1099 +
1.1100 + // Large writings
1.1101 + test.Printf(_L("#~TS_Title_%d,%d: Large sequential writes\n"), gTestHarness, gTestCase);
1.1102 +
1.1103 + largeWrites(KLargeRow, KLargeCol, ENoThreads);
1.1104 +
1.1105 + gTestCase++;
1.1106 + test.Printf(_L("#~TS_Title_%d,%d: Large sequential writes, threads accessing same file\n"),
1.1107 + gTestHarness, gTestCase);
1.1108 + largeWrites(KLargeRow, KLargeCol, ETwoThreadsSame);
1.1109 +
1.1110 + gTestCase++;
1.1111 + test.Printf(_L("#~TS_Title_%d,%d: Large sequential writes, threads accessing dif files\n"),
1.1112 + gTestHarness, gTestCase);
1.1113 + largeWrites(KLargeRow, KLargeCol, ETwoThreadsDif);
1.1114 +
1.1115 + gTestCase++;
1.1116 + DeleteAll(gSessionPath);
1.1117 + test.Printf(_L("#~TestEnd_%d\n"), gTestHarness);
1.1118 +
1.1119 + return(KErrNone);
1.1120 +}
1.1121 +
1.1122 +/** Writes aSize bytes of data in aBlockSize during aTime seconds
1.1123 + if the aSize bps is not met, it fails
1.1124 +
1.1125 + @param f File to write to
1.1126 + @param aSize Size in bytes of data to be written
1.1127 + @param aBlockSize Block size to be used
1.1128 + @param aTime Time during which the write has to happen in seconds
1.1129 +*/
1.1130 +LOCAL_C TBool writeStr( RFile f, TInt aSize, TInt aBlockSize, TInt aTime)
1.1131 +{
1.1132 + TInt r = 0, j = 0;
1.1133 + TTime startTime, endTime;
1.1134 + TTimeIntervalMicroSeconds timeTaken(0);
1.1135 + TTimeIntervalMicroSeconds32 timeLeft(0);
1.1136 + TBool onTarget = ETrue;
1.1137 +
1.1138 + TInt time;
1.1139 +
1.1140 + TInt i = 0;
1.1141 + while((i < aTime) && onTarget)
1.1142 + {
1.1143 + // If measuring the CPU time
1.1144 +
1.1145 + startTime.HomeTime();
1.1146 + j = 0;
1.1147 + while(j < aSize)
1.1148 + {
1.1149 + r = f.Write(gBufWritePtr, aBlockSize);
1.1150 + FailIfError(r);
1.1151 + j += aBlockSize;
1.1152 + }
1.1153 + endTime.HomeTime();
1.1154 +
1.1155 + timeTaken = endTime.MicroSecondsFrom(startTime);
1.1156 + time = I64LOW(timeTaken.Int64());
1.1157 + if(time > KOneSec)
1.1158 + {
1.1159 + onTarget = EFalse;
1.1160 + }
1.1161 +
1.1162 + timeLeft = KOneSec - time;
1.1163 + if(timeLeft.Int() >= 0)
1.1164 + {
1.1165 + User::After(timeLeft);
1.1166 + }
1.1167 + i++;
1.1168 + }
1.1169 +
1.1170 + return onTarget;
1.1171 +}
1.1172 +
1.1173 +/** Reads streaming
1.1174 +
1.1175 +*/
1.1176 +LOCAL_C TInt ReadStream(TAny*)
1.1177 +{
1.1178 + RTest test(_L("test 2"));
1.1179 + RFs fs;
1.1180 + RFile file;
1.1181 + TInt j = 0;
1.1182 + TTime startTime, endTime;
1.1183 + TTimeIntervalMicroSeconds timeTaken(0);
1.1184 + TTimeIntervalMicroSeconds32 timeLeft(0);
1.1185 + TInt time;
1.1186 + TInt size , currentPos = 0;
1.1187 +
1.1188 + TInt r = fs.Connect();
1.1189 +
1.1190 + fs.SetSessionPath(gSessionPath);
1.1191 +
1.1192 + r = file.Open(fs, gStreamFile, EFileShareAny|EFileRead);
1.1193 +
1.1194 + client.Signal();
1.1195 +
1.1196 + FailIfError(r);
1.1197 + r = file.Size(size);
1.1198 + FailIfError(r);
1.1199 +
1.1200 + FOREVER
1.1201 + {
1.1202 + startTime.HomeTime();
1.1203 + j = 0;
1.1204 + while(j < (gCurrentSpeed * KOneK))
1.1205 + {
1.1206 + r=file.Read(gBufReadPtr,gCurrentBS);
1.1207 + FailIfError(r);
1.1208 + j += gCurrentBS;
1.1209 + }
1.1210 + endTime.HomeTime();
1.1211 +
1.1212 + timeTaken = endTime.MicroSecondsFrom(startTime);
1.1213 + time = I64LOW(timeTaken.Int64());
1.1214 +
1.1215 + if(time > KOneSec)
1.1216 + {
1.1217 + test.Printf(_L("Background Thread: Speed failed to be achieved: %d kbps\n"), gCurrentSpeed);
1.1218 + }
1.1219 +
1.1220 +
1.1221 +
1.1222 + timeLeft = KOneSec - time;
1.1223 + User::After(timeLeft);
1.1224 + currentPos += (gCurrentSpeed * KOneK);
1.1225 + r = file.Size(size);
1.1226 + FailIfError(r);
1.1227 + if(currentPos > size )
1.1228 + {
1.1229 + currentPos = 0;
1.1230 + file.Seek(ESeekStart, currentPos);
1.1231 + }
1.1232 +
1.1233 + }
1.1234 +
1.1235 +}
1.1236 +
1.1237 +/** Test case layout, read/write at aSpeed during aWtime and aRTime
1.1238 +
1.1239 + @param aSpeed Target speed in kbps
1.1240 + @param aBlockSize Block size for the I/O operation
1.1241 + @param aWTime Writing time
1.1242 + @param aRTime Reading time
1.1243 +*/
1.1244 +LOCAL_C void streamIt ( TInt aSpeed, TInt aBlockSize, TInt aWTime, TInt aRTime, TInt aStep)
1.1245 +{
1.1246 + TInt iSize = (aSpeed * KTobps) / KByte; // Size in bytes
1.1247 + RFile file;
1.1248 + TInt pos = 0;
1.1249 + TInt r = 0;
1.1250 +
1.1251 + PrintResult(aStep, 1, aBlockSize);
1.1252 +
1.1253 + r = file.Replace(TheFs, gStreamFile, EFileShareAny|EFileWrite);
1.1254 + FailIfError(r);
1.1255 +
1.1256 + // Streaming to the media during aWTime seconds
1.1257 + if(writeStr(file, iSize, aBlockSize, aWTime))
1.1258 + { //Pass (1)
1.1259 + PrintResult(aStep, 2, 1);
1.1260 + }
1.1261 + else
1.1262 + { //Fail (0)
1.1263 + PrintResult(aStep, 2, 0);
1.1264 + }
1.1265 +
1.1266 + // Create a different thread for reading from the beginning during aRTime
1.1267 + TBuf<20> buf = _L("Speedy");
1.1268 + buf.AppendNum(ThreadCount++);
1.1269 +
1.1270 + gCurrentSpeed = aSpeed;
1.1271 + gCurrentBS = aBlockSize;
1.1272 + r = gSpeedy.Create(buf, ReadStream, KDefaultStackSize, KHeapSize, KHeapSize, NULL);
1.1273 + FailIfError(r);
1.1274 +
1.1275 + gSpeedy.Resume();
1.1276 + client.Wait();
1.1277 +
1.1278 + // Keep writing during the time the other thread is reading
1.1279 + if(writeStr(file, iSize, aBlockSize, aRTime))
1.1280 + { //Pass (1)
1.1281 + PrintResult(aStep, 3, 1);
1.1282 + }
1.1283 + else
1.1284 + { //Fail (0)
1.1285 + PrintResult(aStep, 3, 0);
1.1286 + }
1.1287 +
1.1288 + // Writing from the beginning again
1.1289 + file.Seek(ESeekStart, pos);
1.1290 + if(writeStr(file, iSize, aBlockSize, aRTime))
1.1291 + { //Pass (1)
1.1292 + PrintResult(aStep, 4, 1);
1.1293 + }
1.1294 + else
1.1295 + { //Fail (0)
1.1296 + PrintResult(aStep, 4, 0);
1.1297 + }
1.1298 +
1.1299 +
1.1300 + // Kill the thread for reading
1.1301 + gSpeedy.Kill(KErrNone);
1.1302 + FailIfError(r);
1.1303 + gSpeedy.Close();
1.1304 +
1.1305 + file.Close();
1.1306 +}
1.1307 +
1.1308 +/** Iterating through different blocksizes
1.1309 +
1.1310 + @param aSpeed Speed at which the test happens
1.1311 +*/
1.1312 +LOCAL_C void streaming(TInt aSpeed)
1.1313 +{
1.1314 + TInt i = 9; // Pow(i) = 512 bytes
1.1315 + TInt blockSize = 0;
1.1316 + TInt testStep = 1;
1.1317 +
1.1318 + while( i < 15 ) // Pow(i) = 16 Kb
1.1319 + {
1.1320 + blockSize = Pow(i) ;
1.1321 + streamIt(aSpeed, blockSize, 5 * 60, 15, testStep++); // 5 minutes writing , then 15 secs reading
1.1322 + i++;
1.1323 + }
1.1324 +}
1.1325 +
1.1326 +/** High level test routine. Different test cases executed
1.1327 +
1.1328 + @param aSelector Test case configuration in case of manual execution
1.1329 +*/
1.1330 +LOCAL_C TInt TestStreaming(TAny* aSelector)
1.1331 +{
1.1332 +
1.1333 + Validate(aSelector);
1.1334 + // Each test case of the suite has an identifyer for parsing purposes of the results
1.1335 + gTestHarness = 9;
1.1336 + gTestCase = 1;
1.1337 +
1.1338 +
1.1339 + PrintHeaders(5, _L("t_fcachebm. Streaming"));
1.1340 +
1.1341 + test.Printf(_L("#~TS_Title_%d,%d: Writing / reading at 100 kbps\n"),
1.1342 + gTestHarness, gTestCase);
1.1343 +
1.1344 + streaming(100);
1.1345 +
1.1346 + test.Printf(_L("#~TS_Title_%d,%d: Writing / reading at 200 kbps\n"),
1.1347 + gTestHarness, ++gTestCase);
1.1348 +
1.1349 + streaming(200);
1.1350 +
1.1351 + test.Printf(_L("#~TS_Title_%d,%d: Writing / reading at 500 kbps\n"),
1.1352 + gTestHarness, ++gTestCase);
1.1353 +
1.1354 + streaming(500);
1.1355 +
1.1356 +
1.1357 + DeleteAll(gSessionPath);
1.1358 +
1.1359 + // Start the small random reads in the background
1.1360 + CreateFile(gBaseFile, Pow(KSmallCol-1));
1.1361 +
1.1362 + TBuf<20> buf=_L("Speedy");
1.1363 + buf.AppendNum(ThreadCount++);
1.1364 +
1.1365 + TInt r = gSpeedyII.Create(buf, ReadSmallBase, KDefaultStackSize, KHeapSize, KHeapSize, NULL);
1.1366 + FailIfError(r);
1.1367 +
1.1368 + gSpeedyII.Resume();
1.1369 + client.Wait();
1.1370 +
1.1371 + // Measure the throughput with background activity
1.1372 + test.Printf(_L("#~TS_Title_%d,%d: Writing / reading at 100 kbps, while small reads\n"),
1.1373 + gTestHarness, ++gTestCase);
1.1374 +
1.1375 + streaming(100);
1.1376 +
1.1377 + test.Printf(_L("#~TS_Title_%d,%d: Writing / reading at 200 kbps, while small reads\n"),
1.1378 + gTestHarness, ++gTestCase);
1.1379 +
1.1380 + streaming(200);
1.1381 +
1.1382 + test.Printf(_L("#~TS_Title_%d,%d: Writing / reading at 500 kbps, while small reads\n"),
1.1383 + gTestHarness, ++gTestCase);
1.1384 +
1.1385 + streaming(500);
1.1386 +
1.1387 + // Kill the small random reads and writes
1.1388 + gSpeedyII.Kill(KErrNone);
1.1389 + FailIfError(r);
1.1390 +
1.1391 + gSpeedyII.Close();
1.1392 +
1.1393 + DeleteAll(gSessionPath);
1.1394 +
1.1395 + gTestCase++;
1.1396 + test.Printf(_L("#~TestEnd_%d\n"), gTestHarness);
1.1397 +
1.1398 + return(KErrNone);
1.1399 +}
1.1400 +
1.1401 +/** It goes automatically through all the options
1.1402 +
1.1403 + @param aSelector Configuration in case of manual execution
1.1404 +*/
1.1405 +LOCAL_C TInt TestAll(TAny* aSelector)
1.1406 +{
1.1407 + TestSmall(aSelector);
1.1408 + TestLarge(aSelector);
1.1409 + TestStreaming(aSelector);
1.1410 +
1.1411 + return(KErrNone);
1.1412 +}
1.1413 +
1.1414 +/** Call all tests
1.1415 +
1.1416 +*/
1.1417 +GLDEF_C void CallTestsL()
1.1418 +{
1.1419 + TBuf16<25> temp;
1.1420 +
1.1421 + TInt r=client.CreateLocal(0);
1.1422 + FailIfError(r);
1.1423 +
1.1424 + // Setting up the environment and creating the needed files
1.1425 + gSessionPath = _L("?:\\F32-TST\\");
1.1426 + gSessionPath[0] = (TText) gDriveToTest;
1.1427 +
1.1428 + FileNamesGeneration(temp, 8, 0, 1);
1.1429 + gBaseFile = gSessionPath;
1.1430 + gBaseFile.Append(temp);
1.1431 +
1.1432 + FileNamesGeneration(temp, 8, 1, 1);
1.1433 + gFileA = gSessionPath;
1.1434 + gFileA.Append(temp);
1.1435 +
1.1436 + FileNamesGeneration(temp, 8, 2, 1);
1.1437 + gFileB = gSessionPath;
1.1438 + gFileB.Append(temp);
1.1439 +
1.1440 + FileNamesGeneration(temp, 8, 3, 1);
1.1441 + gStreamFile = gSessionPath;
1.1442 + gStreamFile.Append(temp);
1.1443 +
1.1444 + TRAPD(res,gBuf = HBufC8::NewL(256 * KOneK));
1.1445 + test(res == KErrNone && gBuf != NULL);
1.1446 +
1.1447 + gBufWritePtr.Set(gBuf->Des());
1.1448 + FillBuffer(gBufWritePtr, 256 * KOneK, 'A');
1.1449 +
1.1450 + TRAPD(res2, gBufSec = HBufC8::NewL(256 * KOneK));
1.1451 + test(res2 == KErrNone && gBufSec != NULL);
1.1452 + gBufReadPtr.Set(gBufSec->Des());
1.1453 +
1.1454 + TVolumeInfo volInfo;
1.1455 + TInt drive;
1.1456 +
1.1457 + r = TheFs.CharToDrive(gDriveToTest,drive);
1.1458 + FailIfError(r);
1.1459 + r = TheFs.Volume(volInfo, drive);
1.1460 + FailIfError(r);
1.1461 +
1.1462 + gMediaSize = volInfo.iSize;
1.1463 +
1.1464 + FormatFat(gSessionPath[0]-'A');
1.1465 + TheFs.MkDirAll(gSessionPath);
1.1466 +
1.1467 + RThread noisy;
1.1468 + TBuf<20> buf = _L("Noisy");
1.1469 + r = noisy.Create(buf, noise, KDefaultStackSize, KHeapSize, KHeapSize, NULL);
1.1470 + FailIfError(r);
1.1471 +
1.1472 + noisy.Resume();
1.1473 +
1.1474 + CSelectionBox* TheSelector=CSelectionBox::NewL(test.Console());
1.1475 +
1.1476 + if(gMode == 0)
1.1477 + { // Manual
1.1478 + gSessionPath=_L("?:\\");
1.1479 + TCallBack smallOps(TestSmall, TheSelector);
1.1480 + TCallBack largeOps(TestLarge, TheSelector);
1.1481 + TCallBack simulOps(TestStreaming, TheSelector);
1.1482 + TCallBack tAll(TestAll, TheSelector);
1.1483 + TheSelector->AddDriveSelectorL(TheFs);
1.1484 + TheSelector->AddLineL(_L("Small random r/w"), smallOps);
1.1485 + TheSelector->AddLineL(_L("Large conseq r/w"), largeOps);
1.1486 + TheSelector->AddLineL(_L("Streaming"), simulOps);
1.1487 + TheSelector->AddLineL(_L("Execute all options"), tAll);
1.1488 + TheSelector->Run();
1.1489 + }
1.1490 + else
1.1491 + { // Automatic
1.1492 + TestAll(TheSelector);
1.1493 + }
1.1494 +
1.1495 + DeleteAll(gSessionPath);
1.1496 +
1.1497 + client.Close();
1.1498 + delete TheSelector;
1.1499 + delete gBuf;
1.1500 + delete gBufSec;
1.1501 + noisy.Kill(KErrNone);
1.1502 + noisy.Close();
1.1503 +}