sl@0: // Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of the License "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // f32test/bench/t_fcachebm.cpp sl@0: // sl@0: // sl@0: sl@0: #include sl@0: #include sl@0: #include sl@0: #include "t_select.h" sl@0: #include "t_benchmain.h" sl@0: sl@0: //---------------------------------------------------------------------------------------------- sl@0: //! @SYMTestCaseID PBASE-T_RCACHE-0192 sl@0: //! @SYMTestType CIT sl@0: //! @SYMPREQ PREQ914 sl@0: //! @SYMTestCaseDesc This test case is testing performance of the File Server Cache. sl@0: //! @SYMTestActions 0 setup the environment to execute the tests sl@0: //! 1 small random reads/writes sl@0: //! 2 large sequential reads/writes sl@0: //! 3 streaming test (100, 200 and 500 kbps) sl@0: //! @SYMTestExpectedResults Finishes if the system behaves as expected, panics otherwise sl@0: //! @SYMTestPriority High sl@0: //! @SYMTestStatus Implemented sl@0: //---------------------------------------------------------------------------------------------- sl@0: sl@0: sl@0: GLDEF_D RTest test(_L("File Cache BM")); sl@0: sl@0: LOCAL_D RSemaphore client; sl@0: LOCAL_D const TInt KHeapSize = 0x4000; sl@0: LOCAL_D const TInt KTobps = 1000; sl@0: LOCAL_D const TInt KByte = 8; sl@0: LOCAL_D const TInt KOneSec = 1000000; // One second in microseconds sl@0: sl@0: // Tests setup sl@0: LOCAL_D const TInt KSmallRow = 11; sl@0: LOCAL_D const TInt KSmallCol = 7; sl@0: LOCAL_D const TInt KSmallThreshold = 64; sl@0: LOCAL_D const TInt KSeveralTimes = 10; sl@0: sl@0: LOCAL_D const TInt KLargeRow = 19; sl@0: LOCAL_D const TInt KLargeCol = 3; sl@0: sl@0: LOCAL_D TInt gCurrentSpeed = 0; sl@0: LOCAL_D TInt gCurrentBS = 0; sl@0: sl@0: sl@0: LOCAL_D TBuf8<4096> buf; sl@0: LOCAL_D TDriveList gDriveList; sl@0: sl@0: // Concurrent thread sl@0: RThread gSpeedy; sl@0: RThread gSpeedyII; sl@0: sl@0: TBuf16<25> gBaseFile; sl@0: TBuf16<25> gFileA; sl@0: TBuf16<25> gFileB; sl@0: TBuf16<25> gStreamFile; sl@0: TInt64 gMediaSize; sl@0: sl@0: HBufC8* gBuf = NULL; sl@0: TPtr8 gBufReadPtr(NULL, 0); sl@0: HBufC8* gBufSec = NULL; sl@0: TPtr8 gBufWritePtr(NULL, 0); sl@0: sl@0: sl@0: HBufC8* gBufB = NULL; sl@0: TPtr8 gBufReadBPtr(NULL, 0); sl@0: TBool gWriting = EFalse; sl@0: sl@0: LOCAL_D TInt ThreadCount=0; sl@0: sl@0: enum TTestState sl@0: { sl@0: ENoThreads, // No threads sl@0: ETwoThreadsDif, // Accessing to different files sl@0: ETwoThreadsDifDif, // Accessing to different files, different blocksizes sl@0: ETwoThreadsSame // Accessing the same file sl@0: }; sl@0: sl@0: sl@0: /** 2 ^ b sl@0: sl@0: @param b Power sl@0: */ sl@0: LOCAL_C TInt Pow(TInt b) sl@0: { sl@0: return 1 << b; sl@0: } sl@0: sl@0: /** Pseudo-random number generator, random enough for the purpose sl@0: sl@0: @param aMax Upper limit of the number. The interval of generated numbers is [0,aMax) sl@0: */ sl@0: LOCAL_C TInt Rand(TInt aMax) sl@0: { sl@0: return (Math::Random() % aMax); sl@0: } sl@0: sl@0: sl@0: /** Fills a buffer with character aC, aC+1, aC+2, ..., aC+32, aC, etc sl@0: sl@0: @param aBuffer Buffer to fill out sl@0: @param aLength Length to be filled with characters sl@0: @param aC Base character to fill the buffer sl@0: */ sl@0: LOCAL_C void FillBuffer(TDes8& aBuffer, TInt aLength, TChar aC) sl@0: { sl@0: test (aBuffer.MaxLength() >= aLength); sl@0: sl@0: for(TInt i = 0; i < aLength; i++) sl@0: { sl@0: aBuffer.Append((i%32)+aC); sl@0: } sl@0: } sl@0: sl@0: /** Send content through the RDebug for trgtest sl@0: not to hung, when the test is not writing sl@0: sl@0: */ sl@0: LOCAL_C TInt noise(TAny* ) sl@0: { sl@0: FOREVER sl@0: { sl@0: User::After(2147483647); // max value, 35 minutes, 47 seconds sl@0: if(!gWriting) sl@0: RDebug::Print(_L(".")); sl@0: } sl@0: } sl@0: sl@0: /** Delete content of directory sl@0: sl@0: @param aDir Directory to be emptied sl@0: */ sl@0: LOCAL_C TInt DeleteAll(TDes16& aDir) sl@0: { sl@0: TBuf16<100> dir; sl@0: CFileMan* fMan = CFileMan::NewL(TheFs); sl@0: TInt r = 0; sl@0: sl@0: dir = aDir; sl@0: dir.Append(_L("F*.*")); sl@0: r = fMan->Delete(dir); sl@0: sl@0: delete fMan; sl@0: return r; sl@0: } sl@0: sl@0: sl@0: /** Creates a file of aSize KBytes sl@0: sl@0: @param aFile File name sl@0: @param aSize Size of the file to be created sl@0: */ sl@0: LOCAL_C void CreateFile(TDes16& aFile, TInt aSize) sl@0: { sl@0: TInt r = 0; sl@0: RFile file; sl@0: sl@0: sl@0: r = file.Replace(TheFs, aFile, EFileShareAny|EFileWrite); sl@0: FailIfError(r); sl@0: sl@0: TInt j = 0; sl@0: while(j <= aSize) sl@0: { sl@0: r = file.Write(gBufWritePtr, KOneK); sl@0: FailIfError(r); sl@0: j += KOneK; sl@0: } sl@0: file.Close(); sl@0: } sl@0: sl@0: /** Kills the concurrent session sl@0: sl@0: */ sl@0: LOCAL_C void DoTestKill() sl@0: { sl@0: TInt r = 0; sl@0: sl@0: gSpeedy.Kill(KErrNone); sl@0: FailIfError(r); sl@0: gSpeedy.Close(); sl@0: sl@0: gSpeedyII.Kill(KErrNone); sl@0: FailIfError(r); sl@0: gSpeedyII.Close(); sl@0: } sl@0: sl@0: /** Read aSize KBs from aFile file in blocks of aBlockSize bytes sl@0: sl@0: @param aFile Name of the file sl@0: @param aPos Position from where the read starts within the file sl@0: @param aBlockSize Block size for the I/O operation sl@0: @param aSize sl@0: */ sl@0: LOCAL_C TInt ReadFromFile(TDes16& aFile, TInt aPos, TInt aBlockSize, TInt aSize) sl@0: { sl@0: TInt r = 0; sl@0: TTime startTime; sl@0: TTime endTime; sl@0: RFile file; sl@0: TInt j = 0; sl@0: TInt size = aSize * KOneK; sl@0: TTimeIntervalMicroSeconds timeTaken(0); sl@0: sl@0: r = file.Open(TheFs,aFile,EFileShareAny|EFileRead); sl@0: FailIfError(r); sl@0: sl@0: startTime.HomeTime(); sl@0: r = file.Seek(ESeekStart, aPos); sl@0: FailIfError(r); sl@0: sl@0: while(j <= size) sl@0: { sl@0: r = file.Read(gBufReadPtr, aBlockSize); sl@0: FailIfError(r); sl@0: j += aBlockSize; sl@0: } sl@0: endTime.HomeTime(); sl@0: sl@0: file.Close(); sl@0: timeTaken = endTime.MicroSecondsFrom(startTime); sl@0: sl@0: return I64LOW(timeTaken.Int64() / gTimeUnit); sl@0: } sl@0: sl@0: /** Read aSize KBs from aFile file in blocks of aBlockSize bytes several times sl@0: sl@0: @param aFile Name of the file sl@0: @param ayMax Maximum for the position sl@0: @param aBlockSize Block size for the I/O operation sl@0: @param aSize Size of the file in KB sl@0: */ sl@0: LOCAL_C TInt ReadFromFileSeveralTimes(TDes16& aFile, TInt ayMax, TInt aBlockSize, TInt aSize) sl@0: { sl@0: TInt r = 0; sl@0: TTime startTime; sl@0: TTime endTime; sl@0: RFile file; sl@0: TInt j = 0, i, pos; sl@0: TInt size = aSize * KOneK; sl@0: TTimeIntervalMicroSeconds timeTaken(0); sl@0: TInt64 time = 0; sl@0: sl@0: sl@0: r = file.Open(TheFs, aFile, EFileShareAny|EFileRead); sl@0: FailIfError(r); sl@0: sl@0: i = 0; sl@0: while( i < KSeveralTimes ) sl@0: { sl@0: pos = Rand(Pow(ayMax - 1)); sl@0: startTime.HomeTime(); sl@0: r = file.Seek(ESeekStart, pos); sl@0: FailIfError(r); sl@0: sl@0: j = 0; sl@0: while(j <= size) sl@0: { sl@0: r = file.Read(gBufReadPtr, aBlockSize); sl@0: FailIfError(r); sl@0: j += aBlockSize; sl@0: } sl@0: endTime.HomeTime(); sl@0: sl@0: timeTaken = endTime.MicroSecondsFrom(startTime); sl@0: time += I64LOW(timeTaken.Int64()); sl@0: i++; sl@0: } sl@0: sl@0: file.Close(); sl@0: sl@0: return I64LOW((time / gTimeUnit) / KSeveralTimes); // Overflow not expected here, since the number is not big enough sl@0: } sl@0: sl@0: sl@0: /** Write aSize KBs to aFile file in blocks of aBlockSize bytes sl@0: sl@0: @param aFile Name of the file sl@0: @param aPos Position from where the read starts within the file sl@0: @param aBlockSize Block size for the I/O operation sl@0: @param aSize Size of the file in KB sl@0: */ sl@0: LOCAL_C TInt WriteToFile(TDes16& aFile, TInt aPos, TInt aBlockSize, TInt aSize) sl@0: { sl@0: TInt r = 0; sl@0: TTime startTime; sl@0: TTime endTime; sl@0: RFile file; sl@0: TInt j = 0; sl@0: TInt size = aSize * KOneK; sl@0: TTimeIntervalMicroSeconds timeTaken(0); sl@0: sl@0: r = file.Open(TheFs, aFile, EFileShareAny|EFileWrite); sl@0: FailIfError(r); sl@0: sl@0: startTime.HomeTime(); sl@0: r = file.Seek(ESeekStart, aPos); sl@0: FailIfError(r); sl@0: while(j <= size) sl@0: { sl@0: r = file.Write(gBufWritePtr, aBlockSize); sl@0: FailIfError(r); sl@0: j += aBlockSize; sl@0: } sl@0: endTime.HomeTime(); sl@0: sl@0: file.Close(); sl@0: timeTaken = endTime.MicroSecondsFrom(startTime); sl@0: sl@0: return I64LOW(timeTaken.Int64() / gTimeUnit); sl@0: } sl@0: sl@0: /** Write aSize KBs to aFile file in blocks of aBlockSize bytes several times sl@0: sl@0: @param aFile Name of the file sl@0: @param ayMax Maximum for the position sl@0: @param aBlockSize Block size for the I/O operation sl@0: @param aSize Size of the file in KB sl@0: */ sl@0: LOCAL_C TInt WriteToFileSeveralTimes(TDes16& aFile, TInt ayMax, TInt aBlockSize, TInt aSize) sl@0: { sl@0: TInt r = 0; sl@0: TTime startTime; sl@0: TTime endTime; sl@0: RFile file; sl@0: TInt i, j = 0, pos; sl@0: TInt size = aSize * KOneK; sl@0: TTimeIntervalMicroSeconds timeTaken(0); sl@0: TInt64 time = 0; sl@0: sl@0: r = file.Open(TheFs, aFile, EFileShareAny|EFileWrite); sl@0: FailIfError(r); sl@0: sl@0: i = 0; sl@0: while( i < KSeveralTimes ) sl@0: { sl@0: pos = Rand(Pow(ayMax - 1)); sl@0: startTime.HomeTime(); sl@0: r = file.Seek(ESeekStart, pos); sl@0: FailIfError(r); sl@0: sl@0: j = 0; sl@0: while(j <= size) sl@0: { sl@0: r = file.Write(gBufWritePtr, aBlockSize); sl@0: FailIfError(r); sl@0: j += aBlockSize; sl@0: } sl@0: endTime.HomeTime(); sl@0: sl@0: timeTaken = endTime.MicroSecondsFrom(startTime); sl@0: time += I64LOW(timeTaken.Int64()); sl@0: i++; sl@0: } sl@0: sl@0: file.Close(); sl@0: sl@0: return I64LOW((time / gTimeUnit) / KSeveralTimes); // Overflow not expected here, since the number is not big enough sl@0: } sl@0: sl@0: /** Read small blocks in the gBaseFile sl@0: sl@0: */ sl@0: LOCAL_C TInt ReadSmallBase(TAny* ) sl@0: { sl@0: RTest test(_L("test 2")); sl@0: RFs fs; sl@0: RFile file; sl@0: TBuf8<1024> dummy(1024); sl@0: TInt blockSize = 0; sl@0: TInt randPos = 0; sl@0: TInt i = 0; sl@0: sl@0: TInt r = fs.Connect(); sl@0: sl@0: fs.SetSessionPath(gSessionPath); sl@0: r = file.Open(fs, gBaseFile, EFileShareAny|EFileRead); sl@0: client.Signal(); sl@0: sl@0: FailIfError(r); sl@0: sl@0: FOREVER sl@0: { sl@0: randPos = Rand(64) * KOneK ; sl@0: r = file.Seek(ESeekStart, randPos); sl@0: FailIfError(r); sl@0: blockSize = i; sl@0: sl@0: r = file.Read(dummy, blockSize); // Sync operation sl@0: if(i >= 1023) i = 0; sl@0: else i++; sl@0: } sl@0: } sl@0: sl@0: /** Read small blocks in gFileA sl@0: sl@0: */ sl@0: LOCAL_C TInt ReadSmallA(TAny* ) sl@0: { sl@0: RTest test(_L("test 2")); sl@0: RFs fs; sl@0: RFile file; sl@0: TInt blockSize = 0; sl@0: TInt randPos = 0; sl@0: TBuf8<1024> dummy(1024); sl@0: TInt i = 0; sl@0: sl@0: TInt r = fs.Connect(); sl@0: sl@0: fs.SetSessionPath(gSessionPath); sl@0: sl@0: r = file.Open(fs,gFileA,EFileShareAny|EFileRead); sl@0: sl@0: client.Signal(); sl@0: FailIfError(r); sl@0: sl@0: FOREVER sl@0: { sl@0: randPos = Rand(64) * KOneK ; sl@0: r = file.Seek(ESeekStart, randPos); sl@0: FailIfError(r); sl@0: sl@0: blockSize = i; sl@0: sl@0: r = file.Read(dummy, blockSize); // Sync operation sl@0: FailIfError(r); sl@0: if(i >= 1023) i = 0; sl@0: else i++; sl@0: } sl@0: } sl@0: sl@0: /** Read small blocks in gFileB sl@0: sl@0: */ sl@0: LOCAL_C TInt ReadSmallB(TAny* ) sl@0: { sl@0: RTest test(_L("test 2")); sl@0: RFs fs; sl@0: RFile file; sl@0: TBuf8<1024> dummy(1024); sl@0: TInt blockSize = 0; sl@0: TInt randPos = 0; sl@0: TInt i = 0; sl@0: sl@0: TInt r = fs.Connect(); sl@0: sl@0: fs.SetSessionPath(gSessionPath); sl@0: r = file.Open(fs, gFileB, EFileShareAny|EFileRead); sl@0: sl@0: client.Signal(); sl@0: FailIfError(r); sl@0: sl@0: FOREVER sl@0: { sl@0: randPos = Rand(64) * KOneK ; sl@0: r = file.Seek(ESeekStart, randPos); sl@0: FailIfError(r); sl@0: blockSize = i; sl@0: sl@0: r = file.Read(dummy, blockSize); // Sync operation sl@0: FailIfError(r); sl@0: if(i >= 1023) i = 0; sl@0: else i++; sl@0: } sl@0: } sl@0: sl@0: sl@0: /** Read large blocks in gBaseFile sl@0: sl@0: */ sl@0: LOCAL_C TInt ReadLargeBase(TAny* ) sl@0: { sl@0: RTest test(_L("test 2")); sl@0: RFs fs; sl@0: RFile file; sl@0: TInt pos = 0; sl@0: TInt blockSize = 128 * KOneK; sl@0: sl@0: TInt r = fs.Connect(); sl@0: sl@0: fs.SetSessionPath(gSessionPath); sl@0: r = file.Open(fs,gBaseFile,EFileShareAny|EFileRead); sl@0: sl@0: client.Signal(); sl@0: FailIfError(r); sl@0: sl@0: FOREVER sl@0: { sl@0: r = file.Seek(ESeekStart, pos); sl@0: FailIfError(r); sl@0: sl@0: r = file.Read(gBufReadBPtr, blockSize); // Sync operation sl@0: FailIfError(r); sl@0: } sl@0: } sl@0: sl@0: /** Read large blocks in gFileA sl@0: sl@0: */ sl@0: LOCAL_C TInt ReadLargeA(TAny* ) sl@0: { sl@0: RTest test(_L("test 2")); sl@0: RFs fs; sl@0: RFile file; sl@0: TInt blockSize = 128 * KOneK; sl@0: TInt pos = 0; sl@0: sl@0: TInt r = fs.Connect(); sl@0: sl@0: fs.SetSessionPath(gSessionPath); sl@0: sl@0: r = file.Open(fs,gFileA,EFileShareAny|EFileRead); sl@0: sl@0: client.Signal(); sl@0: FailIfError(r); sl@0: sl@0: FOREVER sl@0: { sl@0: r = file.Seek(ESeekStart, pos); sl@0: FailIfError(r); sl@0: sl@0: r = file.Read(gBufReadBPtr, blockSize); // Sync operation sl@0: FailIfError(r); sl@0: } sl@0: } sl@0: sl@0: /** Read large blocks in gFileB sl@0: sl@0: */ sl@0: LOCAL_C TInt ReadLargeB(TAny* ) sl@0: { sl@0: RTest test(_L("test 2")); sl@0: RFs fs; sl@0: RFile file; sl@0: TInt blockSize = 128 * KOneK; sl@0: TInt pos = 0; sl@0: sl@0: TInt r=fs.Connect(); sl@0: FailIfError(r); sl@0: sl@0: fs.SetSessionPath(gSessionPath); sl@0: sl@0: r = file.Open(fs,gFileB,EFileShareAny|EFileRead); sl@0: sl@0: client.Signal(); sl@0: FailIfError(r); sl@0: sl@0: FOREVER sl@0: { sl@0: r = file.Seek(ESeekStart, pos); sl@0: FailIfError(r); sl@0: sl@0: r = file.Read(gBufReadBPtr, blockSize); // Sync operation sl@0: FailIfError(r); sl@0: } sl@0: } sl@0: sl@0: /** Small reads from a file sl@0: sl@0: @param xMax Maximum position on the x axe sl@0: @param yMax Maximum position on the y axe sl@0: @param aCase Type of test. Possible values: sl@0: - ENoThreads : isolated sl@0: - ETwoThreadsSame : with two threads accessing same file sl@0: - ETwoThreadsDif : with two threads accessing dif. files sl@0: */ sl@0: LOCAL_C void smallReads(TInt xMax, TInt yMax, TTestState aCase) sl@0: { sl@0: TInt i = 0; sl@0: TInt j = 0; sl@0: TInt r = 0; sl@0: TInt timeRes = 0; sl@0: sl@0: CreateFile(gBaseFile, Pow(yMax-1)); sl@0: sl@0: if(aCase == ETwoThreadsSame) sl@0: { // Start two different threads accessing the same file sl@0: TBuf<20> buf = _L("Speedy"); sl@0: buf.AppendNum(ThreadCount++); sl@0: r = gSpeedy.Create(buf, ReadSmallBase, KDefaultStackSize, KHeapSize, KHeapSize, NULL); sl@0: FailIfError(r); sl@0: sl@0: buf = _L("Speedy"); sl@0: buf.AppendNum(ThreadCount++); sl@0: sl@0: r = gSpeedyII.Create(buf, ReadSmallBase, KDefaultStackSize, KHeapSize, KHeapSize, NULL); sl@0: FailIfError(r); sl@0: sl@0: gSpeedy.Resume(); sl@0: gSpeedyII.Resume(); sl@0: sl@0: client.Wait(); sl@0: client.Wait(); sl@0: } sl@0: sl@0: if(aCase == ETwoThreadsDif) sl@0: { // Start two different threads accessing different files sl@0: CreateFile(gFileA, Pow(yMax-1)); sl@0: CreateFile(gFileB, Pow(yMax-1)); sl@0: sl@0: TBuf<20> buf = _L("Speedy"); sl@0: buf.AppendNum(ThreadCount++); sl@0: r = gSpeedy.Create(buf, ReadSmallA, KDefaultStackSize, KHeapSize, KHeapSize, NULL); sl@0: FailIfError(r); sl@0: sl@0: buf = _L("Speedy"); sl@0: buf.AppendNum(ThreadCount++); sl@0: sl@0: r = gSpeedyII.Create(buf, ReadSmallB, KDefaultStackSize, KHeapSize, KHeapSize, NULL); sl@0: FailIfError(r); sl@0: sl@0: gSpeedy.Resume(); sl@0: gSpeedyII.Resume(); sl@0: sl@0: client.Wait(); sl@0: client.Wait(); sl@0: } sl@0: sl@0: while(i < xMax) sl@0: { // Actual accesses and timing to the main file sl@0: j = 0; sl@0: PrintResult(i + 1, j + 1, Pow(i)); sl@0: while(j < yMax) sl@0: { sl@0: if(Pow(i) < KSmallThreshold) sl@0: { sl@0: timeRes = ReadFromFile(gBaseFile, Rand(Pow(yMax - 1)), Pow(i), Pow(j)); sl@0: } sl@0: else sl@0: { // Too small for only one time measure sl@0: timeRes = ReadFromFileSeveralTimes(gBaseFile, yMax, Pow(i), Pow(j)); sl@0: } sl@0: sl@0: gWriting = ETrue; sl@0: User::After(1000000); sl@0: sl@0: PrintResultTime(i + 1, j + 2, timeRes); sl@0: sl@0: gWriting = EFalse; sl@0: sl@0: j++; sl@0: } sl@0: i++; sl@0: } sl@0: sl@0: sl@0: if((aCase == ETwoThreadsSame) || (aCase == ETwoThreadsDif)) sl@0: { // Finish the threads sl@0: DoTestKill(); sl@0: } sl@0: } sl@0: sl@0: /** Large reads from a file sl@0: sl@0: @param xMax Maximum position on the x axe sl@0: @param yMax Maximum position on the y axe sl@0: @param aCase Type of test. Possible values: sl@0: - ENoThreads : isolated sl@0: - ETwoThreadsSame : with two threads accessing same file sl@0: - ETwoThreadsDif : with two threads accessing dif. files sl@0: - ETwoThreadsDifDif : with two threads accessing dif. files, different block sizes (big/small) sl@0: */ sl@0: LOCAL_C void largeReads(TInt xMax, TInt yMax, TTestState aCase) sl@0: { sl@0: TInt i = 0; sl@0: TInt j = 0; sl@0: TInt r = 0; sl@0: TInt timeRes = 0; sl@0: sl@0: CreateFile(gBaseFile, 10 * KOneK * KOneK); // 10 Mb sl@0: sl@0: if(aCase == ETwoThreadsSame) sl@0: { // Start two different threads accessing the same file sl@0: sl@0: TRAPD(res, gBufB = HBufC8::NewL(256 * KOneK)); sl@0: test(res == KErrNone && gBufB != NULL); sl@0: gBufReadBPtr.Set(gBufSec->Des()); sl@0: sl@0: TBuf<20> buf = _L("Speedy"); sl@0: buf.AppendNum(ThreadCount++); sl@0: r = gSpeedy.Create(buf, ReadLargeBase, KDefaultStackSize, KHeapSize, KHeapSize, NULL); sl@0: FailIfError(r); sl@0: sl@0: buf = _L("Speedy"); sl@0: buf.AppendNum(ThreadCount++); sl@0: sl@0: r = gSpeedyII.Create(buf, ReadLargeBase, KDefaultStackSize, KHeapSize, KHeapSize, NULL); sl@0: FailIfError(r); sl@0: sl@0: gSpeedy.Resume(); sl@0: gSpeedyII.Resume(); sl@0: sl@0: client.Wait(); sl@0: client.Wait(); sl@0: } sl@0: sl@0: if(aCase == ETwoThreadsDif) sl@0: { // Start two different threads accessing different files sl@0: sl@0: CreateFile(gFileA, KOneK * KOneK); sl@0: CreateFile(gFileB, KOneK * KOneK); sl@0: sl@0: TRAPD(res, gBufB = HBufC8::NewL(256 * KOneK)); sl@0: test(res == KErrNone && gBufB != NULL); sl@0: gBufReadBPtr.Set(gBufSec->Des()); sl@0: sl@0: TBuf<20> buf = _L("Speedy"); sl@0: buf.AppendNum(ThreadCount++); sl@0: r = gSpeedy.Create(buf, ReadLargeA, KDefaultStackSize, KHeapSize, KHeapSize, NULL); sl@0: FailIfError(r); sl@0: sl@0: buf = _L("Speedy"); sl@0: buf.AppendNum(ThreadCount++); sl@0: sl@0: r = gSpeedyII.Create(buf, ReadLargeB, KDefaultStackSize, KHeapSize, KHeapSize, NULL); sl@0: FailIfError(r); sl@0: sl@0: gSpeedy.Resume(); sl@0: gSpeedyII.Resume(); sl@0: sl@0: client.Wait(); sl@0: client.Wait(); sl@0: } sl@0: sl@0: if(aCase == ETwoThreadsDifDif) sl@0: { // Start two different threads accessing different files sl@0: sl@0: CreateFile(gFileA, KOneK * KOneK); sl@0: CreateFile(gFileB, KOneK * KOneK); sl@0: sl@0: TRAPD(res,gBufB = HBufC8::NewL(256 * KOneK)); sl@0: test(res == KErrNone && gBufB != NULL); sl@0: gBufReadBPtr.Set(gBufSec->Des()); sl@0: sl@0: TBuf<20> buf=_L("Speedy"); sl@0: buf.AppendNum(ThreadCount++); sl@0: r = gSpeedy.Create(buf, ReadLargeA, KDefaultStackSize, KHeapSize, KHeapSize, NULL); sl@0: FailIfError(r); sl@0: sl@0: buf = _L("Speedy"); sl@0: buf.AppendNum(ThreadCount++); sl@0: sl@0: r = gSpeedyII.Create(buf, ReadSmallB, KDefaultStackSize, KHeapSize, KHeapSize, NULL); sl@0: FailIfError(r); sl@0: sl@0: gSpeedy.Resume(); sl@0: gSpeedyII.Resume(); sl@0: sl@0: client.Wait(); sl@0: client.Wait(); sl@0: } sl@0: sl@0: i = 11; sl@0: while(i < xMax ) sl@0: { // Actual accesses and timing to the main file sl@0: j = 0; sl@0: PrintResult(i - 10, j + 1, Pow(i)); sl@0: while(j < yMax) sl@0: { sl@0: TInt size=0; sl@0: if(j == 0) size = 100 ; // 100 Kb sl@0: if(j == 1) size = KOneK ; // 1 Mb sl@0: if(j == 2) size = 10 * KOneK ; // 10 Mb sl@0: sl@0: timeRes = ReadFromFile(gBaseFile, 0, Pow(i), size); sl@0: sl@0: gWriting = ETrue; sl@0: User::After(1000000); sl@0: sl@0: PrintResultTime(i - 10, j + 2, timeRes); sl@0: sl@0: gWriting = EFalse; sl@0: sl@0: j++; sl@0: } sl@0: i++; sl@0: } sl@0: sl@0: if((aCase == ETwoThreadsSame) || (aCase == ETwoThreadsDif) || (aCase == ETwoThreadsDifDif)) sl@0: { // Finish the threads sl@0: DoTestKill(); sl@0: delete gBufB; sl@0: } sl@0: sl@0: } sl@0: sl@0: /** Large writes to a file sl@0: sl@0: @param xMax Maximum position on the x axe sl@0: @param yMax Maximum position on the y axe sl@0: @param aCase Type of test. Possible values: sl@0: - ENoThreads : isolated sl@0: - ETwoThreadsSame : with two threads accessing same file sl@0: - ETwoThreadsDif : with two threads accessing dif. files sl@0: */ sl@0: LOCAL_C void largeWrites(TInt xMax, TInt yMax, TTestState aCase) sl@0: { sl@0: TInt i = 0; sl@0: TInt j = 0; sl@0: TInt r = 0; sl@0: TInt timeRes = 0; sl@0: sl@0: CreateFile(gBaseFile, 10 * KOneK * KOneK); // 10 Mb sl@0: sl@0: if(aCase == ETwoThreadsSame) sl@0: { // Start two different threads accessing the same file sl@0: sl@0: TRAPD(res, gBufB = HBufC8::NewL(256 * KOneK)); sl@0: test(res == KErrNone && gBufB != NULL); sl@0: gBufReadBPtr.Set(gBufSec->Des()); sl@0: sl@0: TBuf<20> buf = _L("Speedy"); sl@0: buf.AppendNum(ThreadCount++); sl@0: r = gSpeedy.Create(buf, ReadLargeBase, KDefaultStackSize, KHeapSize, KHeapSize, NULL); sl@0: FailIfError(r); sl@0: sl@0: buf = _L("Speedy"); sl@0: buf.AppendNum(ThreadCount++); sl@0: sl@0: r = gSpeedyII.Create(buf, ReadLargeBase, KDefaultStackSize, KHeapSize, KHeapSize, NULL); sl@0: FailIfError(r); sl@0: sl@0: gSpeedy.Resume(); sl@0: gSpeedyII.Resume(); sl@0: sl@0: client.Wait(); sl@0: client.Wait(); sl@0: } sl@0: sl@0: if(aCase == ETwoThreadsDif) sl@0: { // Start two different threads accessing different files sl@0: sl@0: CreateFile(gFileA, KOneK * KOneK); sl@0: CreateFile(gFileB, KOneK * KOneK); sl@0: sl@0: TRAPD(res, gBufB = HBufC8::NewL(256 * KOneK)); sl@0: test(res == KErrNone && gBufB != NULL); sl@0: gBufReadBPtr.Set(gBufSec->Des()); sl@0: sl@0: TBuf<20> buf = _L("Speedy"); sl@0: buf.AppendNum(ThreadCount++); sl@0: r = gSpeedy.Create(buf, ReadLargeA, KDefaultStackSize, KHeapSize, KHeapSize, NULL); sl@0: FailIfError(r); sl@0: sl@0: buf = _L("Speedy"); sl@0: buf.AppendNum(ThreadCount++); sl@0: sl@0: r = gSpeedyII.Create(buf, ReadLargeB, KDefaultStackSize, KHeapSize, KHeapSize, NULL); sl@0: FailIfError(r); sl@0: sl@0: gSpeedy.Resume(); sl@0: gSpeedyII.Resume(); sl@0: sl@0: client.Wait(); sl@0: client.Wait(); sl@0: } sl@0: sl@0: i = 11; sl@0: while(i < xMax ) sl@0: { // Actual accesses and timing to the main file sl@0: j = 0; sl@0: PrintResult(i - 10 , j + 1, Pow(i)); sl@0: while(j < yMax) sl@0: { sl@0: TInt size=0; sl@0: if(j == 0) size = 100 ; // 100 Kb sl@0: if(j == 1) size = KOneK ; // 1 Mb sl@0: if(j == 2) size = 10 * KOneK ; // 10 Mb sl@0: timeRes = WriteToFile(gBaseFile, 0, Pow(i), size); sl@0: sl@0: gWriting = ETrue; sl@0: User::After(1000000); sl@0: sl@0: PrintResultTime(i - 10, j + 2, timeRes); sl@0: sl@0: gWriting = EFalse; sl@0: j++; sl@0: } sl@0: i++; sl@0: } sl@0: sl@0: if((aCase == ETwoThreadsSame) || (aCase == ETwoThreadsDif) || (aCase == ETwoThreadsDifDif)) sl@0: { // Finish the threads sl@0: DoTestKill(); sl@0: delete gBufB; sl@0: } sl@0: sl@0: } sl@0: sl@0: /** Small writes to a file sl@0: sl@0: @param xMax Maximum position on the x axe sl@0: @param yMax Maximum position on the y axe sl@0: @param aCase Type of test. Possible values: sl@0: - ENoThreads : isolated sl@0: - ETwoThreadsSame : with two threads accessing same file sl@0: - ETwoThreadsDif : with two threads accessing dif. files sl@0: */ sl@0: LOCAL_C void smallWrites(TInt xMax, TInt yMax, TTestState aCase) sl@0: { sl@0: TInt i = 0; sl@0: TInt j = 0; sl@0: TInt r = 0; sl@0: TInt timeRes = 0; sl@0: sl@0: CreateFile(gBaseFile, Pow(yMax-1)); sl@0: sl@0: if(aCase == ETwoThreadsSame) sl@0: { // Start two different threads accessing the same file sl@0: TBuf<20> buf = _L("Speedy"); sl@0: buf.AppendNum(ThreadCount++); sl@0: r = gSpeedy.Create(buf, ReadSmallBase, KDefaultStackSize, KHeapSize, KHeapSize, NULL); sl@0: FailIfError(r); sl@0: sl@0: buf = _L("Speedy"); sl@0: buf.AppendNum(ThreadCount++); sl@0: sl@0: r = gSpeedyII.Create(buf, ReadSmallBase, KDefaultStackSize, KHeapSize, KHeapSize, NULL); sl@0: FailIfError(r); sl@0: sl@0: gSpeedy.Resume(); sl@0: gSpeedyII.Resume(); sl@0: sl@0: client.Wait(); sl@0: client.Wait(); sl@0: } sl@0: sl@0: if(aCase == ETwoThreadsDif) sl@0: { // Start two different threads accessing different files sl@0: CreateFile(gFileA, Pow(yMax-1)); sl@0: CreateFile(gFileB, Pow(yMax-1)); sl@0: sl@0: TBuf<20> buf = _L("Speedy"); sl@0: buf.AppendNum(ThreadCount++); sl@0: r = gSpeedy.Create(buf, ReadSmallA, KDefaultStackSize, KHeapSize, KHeapSize, NULL); sl@0: FailIfError(r); sl@0: sl@0: buf = _L("Speedy"); sl@0: buf.AppendNum(ThreadCount++); sl@0: sl@0: r = gSpeedyII.Create(buf, ReadSmallB, KDefaultStackSize, KHeapSize, KHeapSize, NULL); sl@0: FailIfError(r); sl@0: sl@0: gSpeedy.Resume(); sl@0: gSpeedyII.Resume(); sl@0: sl@0: client.Wait(); sl@0: client.Wait(); sl@0: } sl@0: sl@0: while(i < xMax) sl@0: { sl@0: j = 0; sl@0: PrintResult(i + 1, j + 1, Pow(i)); sl@0: while(j < yMax) sl@0: { sl@0: if(Pow(i) < KSmallThreshold) sl@0: { sl@0: timeRes = WriteToFile(gBaseFile, Rand(Pow(yMax-1)), Pow(i), Pow(j)); sl@0: } sl@0: else sl@0: { sl@0: timeRes = WriteToFileSeveralTimes(gBaseFile, yMax, Pow(i), Pow(j)); sl@0: } sl@0: sl@0: gWriting = ETrue; sl@0: User::After(1000000); sl@0: sl@0: PrintResultTime(i + 1, j + 2, timeRes); sl@0: sl@0: gWriting = EFalse; sl@0: sl@0: j++; sl@0: } sl@0: i++; sl@0: } sl@0: sl@0: if((aCase == ETwoThreadsSame) || (aCase == ETwoThreadsDif)) sl@0: { // Finish the threads sl@0: DoTestKill(); sl@0: } sl@0: sl@0: } sl@0: sl@0: /** This test benchmarks small random r/w (e.g. database access) sl@0: sl@0: @param aSelector Selection array for manual tests sl@0: */ sl@0: LOCAL_C TInt TestSmall(TAny* aSelector) sl@0: { sl@0: sl@0: Validate(aSelector); sl@0: sl@0: // Each test case of the suite has an identifyer for parsing purposes of the results sl@0: gTestHarness = 7; sl@0: gTestCase = 1; sl@0: gTimeUnit = 1; sl@0: sl@0: PrintHeaders(4, _L("t_fcachebm. Small Random r/w")); sl@0: sl@0: // Small reads sl@0: test.Printf(_L("#~TS_Title_%d,%d: Small reads, no threads \n"), gTestHarness, gTestCase); sl@0: sl@0: smallReads(KSmallRow, KSmallCol, ENoThreads); sl@0: sl@0: gTestCase++; sl@0: test.Printf(_L("#~TS_Title_%d,%d: Small reads, threads accessing same file \n"), sl@0: gTestHarness, gTestCase); sl@0: sl@0: smallReads(KSmallRow, KSmallCol, ETwoThreadsSame); sl@0: sl@0: gTestCase++; sl@0: test.Printf(_L("#~TS_Title_%d,%d: Small reads, threads accessing dif files \n"), sl@0: gTestHarness, gTestCase); sl@0: sl@0: smallReads(KSmallRow, KSmallCol, ETwoThreadsDif); sl@0: sl@0: gTestCase++; sl@0: DeleteAll(gSessionPath); sl@0: sl@0: // Small writes test case sl@0: sl@0: test.Printf(_L("#~TS_Title_%d,%d: Test small writes\n"), gTestHarness, gTestCase); sl@0: sl@0: smallWrites(KSmallRow, KSmallCol, ENoThreads); sl@0: sl@0: gTestCase++; sl@0: test.Printf(_L("#~TS_Title_%d,%d: Small writes, threads accessing same file \n"), sl@0: gTestHarness, gTestCase); sl@0: smallWrites(KSmallRow, KSmallCol, ETwoThreadsSame); sl@0: sl@0: gTestCase++; sl@0: test.Printf(_L("#~TS_Title_%d,%d: Small writes, threads accessing dif files \n"), sl@0: gTestHarness, gTestCase); sl@0: smallWrites(KSmallRow, KSmallCol, ETwoThreadsDif); sl@0: sl@0: gTestCase++; sl@0: DeleteAll(gSessionPath); sl@0: test.Printf(_L("#~TestEnd_%d\n"), gTestHarness); sl@0: sl@0: return(KErrNone); sl@0: } sl@0: sl@0: /** This test benchmarks large sequential r/w (e.g. MM) sl@0: sl@0: @param aSelector Selection array for manual tests sl@0: */ sl@0: LOCAL_C TInt TestLarge(TAny* aSelector) sl@0: { sl@0: sl@0: Validate(aSelector); sl@0: sl@0: // Each test case of the suite has an identifyer for parsing purposes of the results sl@0: gTestHarness = 8; sl@0: gTestCase = 1; sl@0: gTimeUnit = 1000; sl@0: sl@0: PrintHeaders(3, _L("t_fcachebm. Large sequential r/w")); sl@0: sl@0: // Large reads sl@0: test.Printf(_L("#~TS_Title_%d,%d: Large sequential reads\n"), gTestHarness, gTestCase); sl@0: sl@0: largeReads(KLargeRow, KLargeCol, ENoThreads); sl@0: sl@0: gTestCase++; sl@0: test.Printf(_L("#~TS_Title_%d,%d: Large sequential reads, threads accessing same file\n"), sl@0: gTestHarness, gTestCase); sl@0: largeReads(KLargeRow, KLargeCol, ETwoThreadsSame); sl@0: sl@0: gTestCase++; sl@0: test.Printf(_L("#~TS_Title_%d,%d: Large sequential reads, threads accessing dif files\n"), sl@0: gTestHarness, gTestCase); sl@0: largeReads(KLargeRow, KLargeCol, ETwoThreadsDif); sl@0: sl@0: gTestCase++; sl@0: test.Printf(_L("#~TS_Title_%d,%d: Large sequential reads, threads accessing dif files some big some small blocks\n"), sl@0: gTestHarness, gTestCase); sl@0: largeReads(KLargeRow, KLargeCol, ETwoThreadsDifDif); sl@0: sl@0: gTestCase++; sl@0: DeleteAll(gSessionPath); sl@0: sl@0: // Large writings sl@0: test.Printf(_L("#~TS_Title_%d,%d: Large sequential writes\n"), gTestHarness, gTestCase); sl@0: sl@0: largeWrites(KLargeRow, KLargeCol, ENoThreads); sl@0: sl@0: gTestCase++; sl@0: test.Printf(_L("#~TS_Title_%d,%d: Large sequential writes, threads accessing same file\n"), sl@0: gTestHarness, gTestCase); sl@0: largeWrites(KLargeRow, KLargeCol, ETwoThreadsSame); sl@0: sl@0: gTestCase++; sl@0: test.Printf(_L("#~TS_Title_%d,%d: Large sequential writes, threads accessing dif files\n"), sl@0: gTestHarness, gTestCase); sl@0: largeWrites(KLargeRow, KLargeCol, ETwoThreadsDif); sl@0: sl@0: gTestCase++; sl@0: DeleteAll(gSessionPath); sl@0: test.Printf(_L("#~TestEnd_%d\n"), gTestHarness); sl@0: sl@0: return(KErrNone); sl@0: } sl@0: sl@0: /** Writes aSize bytes of data in aBlockSize during aTime seconds sl@0: if the aSize bps is not met, it fails sl@0: sl@0: @param f File to write to sl@0: @param aSize Size in bytes of data to be written sl@0: @param aBlockSize Block size to be used sl@0: @param aTime Time during which the write has to happen in seconds sl@0: */ sl@0: LOCAL_C TBool writeStr( RFile f, TInt aSize, TInt aBlockSize, TInt aTime) sl@0: { sl@0: TInt r = 0, j = 0; sl@0: TTime startTime, endTime; sl@0: TTimeIntervalMicroSeconds timeTaken(0); sl@0: TTimeIntervalMicroSeconds32 timeLeft(0); sl@0: TBool onTarget = ETrue; sl@0: sl@0: TInt time; sl@0: sl@0: TInt i = 0; sl@0: while((i < aTime) && onTarget) sl@0: { sl@0: // If measuring the CPU time sl@0: sl@0: startTime.HomeTime(); sl@0: j = 0; sl@0: while(j < aSize) sl@0: { sl@0: r = f.Write(gBufWritePtr, aBlockSize); sl@0: FailIfError(r); sl@0: j += aBlockSize; sl@0: } sl@0: endTime.HomeTime(); sl@0: sl@0: timeTaken = endTime.MicroSecondsFrom(startTime); sl@0: time = I64LOW(timeTaken.Int64()); sl@0: if(time > KOneSec) sl@0: { sl@0: onTarget = EFalse; sl@0: } sl@0: sl@0: timeLeft = KOneSec - time; sl@0: if(timeLeft.Int() >= 0) sl@0: { sl@0: User::After(timeLeft); sl@0: } sl@0: i++; sl@0: } sl@0: sl@0: return onTarget; sl@0: } sl@0: sl@0: /** Reads streaming sl@0: sl@0: */ sl@0: LOCAL_C TInt ReadStream(TAny*) sl@0: { sl@0: RTest test(_L("test 2")); sl@0: RFs fs; sl@0: RFile file; sl@0: TInt j = 0; sl@0: TTime startTime, endTime; sl@0: TTimeIntervalMicroSeconds timeTaken(0); sl@0: TTimeIntervalMicroSeconds32 timeLeft(0); sl@0: TInt time; sl@0: TInt size , currentPos = 0; sl@0: sl@0: TInt r = fs.Connect(); sl@0: sl@0: fs.SetSessionPath(gSessionPath); sl@0: sl@0: r = file.Open(fs, gStreamFile, EFileShareAny|EFileRead); sl@0: sl@0: client.Signal(); sl@0: sl@0: FailIfError(r); sl@0: r = file.Size(size); sl@0: FailIfError(r); sl@0: sl@0: FOREVER sl@0: { sl@0: startTime.HomeTime(); sl@0: j = 0; sl@0: while(j < (gCurrentSpeed * KOneK)) sl@0: { sl@0: r=file.Read(gBufReadPtr,gCurrentBS); sl@0: FailIfError(r); sl@0: j += gCurrentBS; sl@0: } sl@0: endTime.HomeTime(); sl@0: sl@0: timeTaken = endTime.MicroSecondsFrom(startTime); sl@0: time = I64LOW(timeTaken.Int64()); sl@0: sl@0: if(time > KOneSec) sl@0: { sl@0: test.Printf(_L("Background Thread: Speed failed to be achieved: %d kbps\n"), gCurrentSpeed); sl@0: } sl@0: sl@0: sl@0: sl@0: timeLeft = KOneSec - time; sl@0: User::After(timeLeft); sl@0: currentPos += (gCurrentSpeed * KOneK); sl@0: r = file.Size(size); sl@0: FailIfError(r); sl@0: if(currentPos > size ) sl@0: { sl@0: currentPos = 0; sl@0: file.Seek(ESeekStart, currentPos); sl@0: } sl@0: sl@0: } sl@0: sl@0: } sl@0: sl@0: /** Test case layout, read/write at aSpeed during aWtime and aRTime sl@0: sl@0: @param aSpeed Target speed in kbps sl@0: @param aBlockSize Block size for the I/O operation sl@0: @param aWTime Writing time sl@0: @param aRTime Reading time sl@0: */ sl@0: LOCAL_C void streamIt ( TInt aSpeed, TInt aBlockSize, TInt aWTime, TInt aRTime, TInt aStep) sl@0: { sl@0: TInt iSize = (aSpeed * KTobps) / KByte; // Size in bytes sl@0: RFile file; sl@0: TInt pos = 0; sl@0: TInt r = 0; sl@0: sl@0: PrintResult(aStep, 1, aBlockSize); sl@0: sl@0: r = file.Replace(TheFs, gStreamFile, EFileShareAny|EFileWrite); sl@0: FailIfError(r); sl@0: sl@0: // Streaming to the media during aWTime seconds sl@0: if(writeStr(file, iSize, aBlockSize, aWTime)) sl@0: { //Pass (1) sl@0: PrintResult(aStep, 2, 1); sl@0: } sl@0: else sl@0: { //Fail (0) sl@0: PrintResult(aStep, 2, 0); sl@0: } sl@0: sl@0: // Create a different thread for reading from the beginning during aRTime sl@0: TBuf<20> buf = _L("Speedy"); sl@0: buf.AppendNum(ThreadCount++); sl@0: sl@0: gCurrentSpeed = aSpeed; sl@0: gCurrentBS = aBlockSize; sl@0: r = gSpeedy.Create(buf, ReadStream, KDefaultStackSize, KHeapSize, KHeapSize, NULL); sl@0: FailIfError(r); sl@0: sl@0: gSpeedy.Resume(); sl@0: client.Wait(); sl@0: sl@0: // Keep writing during the time the other thread is reading sl@0: if(writeStr(file, iSize, aBlockSize, aRTime)) sl@0: { //Pass (1) sl@0: PrintResult(aStep, 3, 1); sl@0: } sl@0: else sl@0: { //Fail (0) sl@0: PrintResult(aStep, 3, 0); sl@0: } sl@0: sl@0: // Writing from the beginning again sl@0: file.Seek(ESeekStart, pos); sl@0: if(writeStr(file, iSize, aBlockSize, aRTime)) sl@0: { //Pass (1) sl@0: PrintResult(aStep, 4, 1); sl@0: } sl@0: else sl@0: { //Fail (0) sl@0: PrintResult(aStep, 4, 0); sl@0: } sl@0: sl@0: sl@0: // Kill the thread for reading sl@0: gSpeedy.Kill(KErrNone); sl@0: FailIfError(r); sl@0: gSpeedy.Close(); sl@0: sl@0: file.Close(); sl@0: } sl@0: sl@0: /** Iterating through different blocksizes sl@0: sl@0: @param aSpeed Speed at which the test happens sl@0: */ sl@0: LOCAL_C void streaming(TInt aSpeed) sl@0: { sl@0: TInt i = 9; // Pow(i) = 512 bytes sl@0: TInt blockSize = 0; sl@0: TInt testStep = 1; sl@0: sl@0: while( i < 15 ) // Pow(i) = 16 Kb sl@0: { sl@0: blockSize = Pow(i) ; sl@0: streamIt(aSpeed, blockSize, 5 * 60, 15, testStep++); // 5 minutes writing , then 15 secs reading sl@0: i++; sl@0: } sl@0: } sl@0: sl@0: /** High level test routine. Different test cases executed sl@0: sl@0: @param aSelector Test case configuration in case of manual execution sl@0: */ sl@0: LOCAL_C TInt TestStreaming(TAny* aSelector) sl@0: { sl@0: sl@0: Validate(aSelector); sl@0: // Each test case of the suite has an identifyer for parsing purposes of the results sl@0: gTestHarness = 9; sl@0: gTestCase = 1; sl@0: sl@0: sl@0: PrintHeaders(5, _L("t_fcachebm. Streaming")); sl@0: sl@0: test.Printf(_L("#~TS_Title_%d,%d: Writing / reading at 100 kbps\n"), sl@0: gTestHarness, gTestCase); sl@0: sl@0: streaming(100); sl@0: sl@0: test.Printf(_L("#~TS_Title_%d,%d: Writing / reading at 200 kbps\n"), sl@0: gTestHarness, ++gTestCase); sl@0: sl@0: streaming(200); sl@0: sl@0: test.Printf(_L("#~TS_Title_%d,%d: Writing / reading at 500 kbps\n"), sl@0: gTestHarness, ++gTestCase); sl@0: sl@0: streaming(500); sl@0: sl@0: sl@0: DeleteAll(gSessionPath); sl@0: sl@0: // Start the small random reads in the background sl@0: CreateFile(gBaseFile, Pow(KSmallCol-1)); sl@0: sl@0: TBuf<20> buf=_L("Speedy"); sl@0: buf.AppendNum(ThreadCount++); sl@0: sl@0: TInt r = gSpeedyII.Create(buf, ReadSmallBase, KDefaultStackSize, KHeapSize, KHeapSize, NULL); sl@0: FailIfError(r); sl@0: sl@0: gSpeedyII.Resume(); sl@0: client.Wait(); sl@0: sl@0: // Measure the throughput with background activity sl@0: test.Printf(_L("#~TS_Title_%d,%d: Writing / reading at 100 kbps, while small reads\n"), sl@0: gTestHarness, ++gTestCase); sl@0: sl@0: streaming(100); sl@0: sl@0: test.Printf(_L("#~TS_Title_%d,%d: Writing / reading at 200 kbps, while small reads\n"), sl@0: gTestHarness, ++gTestCase); sl@0: sl@0: streaming(200); sl@0: sl@0: test.Printf(_L("#~TS_Title_%d,%d: Writing / reading at 500 kbps, while small reads\n"), sl@0: gTestHarness, ++gTestCase); sl@0: sl@0: streaming(500); sl@0: sl@0: // Kill the small random reads and writes sl@0: gSpeedyII.Kill(KErrNone); sl@0: FailIfError(r); sl@0: sl@0: gSpeedyII.Close(); sl@0: sl@0: DeleteAll(gSessionPath); sl@0: sl@0: gTestCase++; sl@0: test.Printf(_L("#~TestEnd_%d\n"), gTestHarness); sl@0: sl@0: return(KErrNone); sl@0: } sl@0: sl@0: /** It goes automatically through all the options sl@0: sl@0: @param aSelector Configuration in case of manual execution sl@0: */ sl@0: LOCAL_C TInt TestAll(TAny* aSelector) sl@0: { sl@0: TestSmall(aSelector); sl@0: TestLarge(aSelector); sl@0: TestStreaming(aSelector); sl@0: sl@0: return(KErrNone); sl@0: } sl@0: sl@0: /** Call all tests sl@0: sl@0: */ sl@0: GLDEF_C void CallTestsL() sl@0: { sl@0: TBuf16<25> temp; sl@0: sl@0: TInt r=client.CreateLocal(0); sl@0: FailIfError(r); sl@0: sl@0: // Setting up the environment and creating the needed files sl@0: gSessionPath = _L("?:\\F32-TST\\"); sl@0: gSessionPath[0] = (TText) gDriveToTest; sl@0: sl@0: FileNamesGeneration(temp, 8, 0, 1); sl@0: gBaseFile = gSessionPath; sl@0: gBaseFile.Append(temp); sl@0: sl@0: FileNamesGeneration(temp, 8, 1, 1); sl@0: gFileA = gSessionPath; sl@0: gFileA.Append(temp); sl@0: sl@0: FileNamesGeneration(temp, 8, 2, 1); sl@0: gFileB = gSessionPath; sl@0: gFileB.Append(temp); sl@0: sl@0: FileNamesGeneration(temp, 8, 3, 1); sl@0: gStreamFile = gSessionPath; sl@0: gStreamFile.Append(temp); sl@0: sl@0: TRAPD(res,gBuf = HBufC8::NewL(256 * KOneK)); sl@0: test(res == KErrNone && gBuf != NULL); sl@0: sl@0: gBufWritePtr.Set(gBuf->Des()); sl@0: FillBuffer(gBufWritePtr, 256 * KOneK, 'A'); sl@0: sl@0: TRAPD(res2, gBufSec = HBufC8::NewL(256 * KOneK)); sl@0: test(res2 == KErrNone && gBufSec != NULL); sl@0: gBufReadPtr.Set(gBufSec->Des()); sl@0: sl@0: TVolumeInfo volInfo; sl@0: TInt drive; sl@0: sl@0: r = TheFs.CharToDrive(gDriveToTest,drive); sl@0: FailIfError(r); sl@0: r = TheFs.Volume(volInfo, drive); sl@0: FailIfError(r); sl@0: sl@0: gMediaSize = volInfo.iSize; sl@0: sl@0: FormatFat(gSessionPath[0]-'A'); sl@0: TheFs.MkDirAll(gSessionPath); sl@0: sl@0: RThread noisy; sl@0: TBuf<20> buf = _L("Noisy"); sl@0: r = noisy.Create(buf, noise, KDefaultStackSize, KHeapSize, KHeapSize, NULL); sl@0: FailIfError(r); sl@0: sl@0: noisy.Resume(); sl@0: sl@0: CSelectionBox* TheSelector=CSelectionBox::NewL(test.Console()); sl@0: sl@0: if(gMode == 0) sl@0: { // Manual sl@0: gSessionPath=_L("?:\\"); sl@0: TCallBack smallOps(TestSmall, TheSelector); sl@0: TCallBack largeOps(TestLarge, TheSelector); sl@0: TCallBack simulOps(TestStreaming, TheSelector); sl@0: TCallBack tAll(TestAll, TheSelector); sl@0: TheSelector->AddDriveSelectorL(TheFs); sl@0: TheSelector->AddLineL(_L("Small random r/w"), smallOps); sl@0: TheSelector->AddLineL(_L("Large conseq r/w"), largeOps); sl@0: TheSelector->AddLineL(_L("Streaming"), simulOps); sl@0: TheSelector->AddLineL(_L("Execute all options"), tAll); sl@0: TheSelector->Run(); sl@0: } sl@0: else sl@0: { // Automatic sl@0: TestAll(TheSelector); sl@0: } sl@0: sl@0: DeleteAll(gSessionPath); sl@0: sl@0: client.Close(); sl@0: delete TheSelector; sl@0: delete gBuf; sl@0: delete gBufSec; sl@0: noisy.Kill(KErrNone); sl@0: noisy.Close(); sl@0: }