First public contribution.
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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // f32test/bench/t_fcachebm.cpp
22 #include "t_benchmain.h"
24 //----------------------------------------------------------------------------------------------
25 //! @SYMTestCaseID PBASE-T_RCACHE-0192
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 //----------------------------------------------------------------------------------------------
39 GLDEF_D RTest test(_L("File Cache BM"));
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
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;
53 LOCAL_D const TInt KLargeRow = 19;
54 LOCAL_D const TInt KLargeCol = 3;
56 LOCAL_D TInt gCurrentSpeed = 0;
57 LOCAL_D TInt gCurrentBS = 0;
60 LOCAL_D TBuf8<4096> buf;
61 LOCAL_D TDriveList gDriveList;
70 TBuf16<25> gStreamFile;
74 TPtr8 gBufReadPtr(NULL, 0);
75 HBufC8* gBufSec = NULL;
76 TPtr8 gBufWritePtr(NULL, 0);
80 TPtr8 gBufReadBPtr(NULL, 0);
81 TBool gWriting = EFalse;
83 LOCAL_D TInt ThreadCount=0;
87 ENoThreads, // No threads
88 ETwoThreadsDif, // Accessing to different files
89 ETwoThreadsDifDif, // Accessing to different files, different blocksizes
90 ETwoThreadsSame // Accessing the same file
98 LOCAL_C TInt Pow(TInt b)
103 /** Pseudo-random number generator, random enough for the purpose
105 @param aMax Upper limit of the number. The interval of generated numbers is [0,aMax)
107 LOCAL_C TInt Rand(TInt aMax)
109 return (Math::Random() % aMax);
113 /** Fills a buffer with character aC, aC+1, aC+2, ..., aC+32, aC, etc
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
119 LOCAL_C void FillBuffer(TDes8& aBuffer, TInt aLength, TChar aC)
121 test (aBuffer.MaxLength() >= aLength);
123 for(TInt i = 0; i < aLength; i++)
125 aBuffer.Append((i%32)+aC);
129 /** Send content through the RDebug for trgtest
130 not to hung, when the test is not writing
133 LOCAL_C TInt noise(TAny* )
137 User::After(2147483647); // max value, 35 minutes, 47 seconds
139 RDebug::Print(_L("."));
143 /** Delete content of directory
145 @param aDir Directory to be emptied
147 LOCAL_C TInt DeleteAll(TDes16& aDir)
150 CFileMan* fMan = CFileMan::NewL(TheFs);
154 dir.Append(_L("F*.*"));
155 r = fMan->Delete(dir);
162 /** Creates a file of aSize KBytes
164 @param aFile File name
165 @param aSize Size of the file to be created
167 LOCAL_C void CreateFile(TDes16& aFile, TInt aSize)
173 r = file.Replace(TheFs, aFile, EFileShareAny|EFileWrite);
179 r = file.Write(gBufWritePtr, KOneK);
186 /** Kills the concurrent session
189 LOCAL_C void DoTestKill()
193 gSpeedy.Kill(KErrNone);
197 gSpeedyII.Kill(KErrNone);
202 /** Read aSize KBs from aFile file in blocks of aBlockSize bytes
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
209 LOCAL_C TInt ReadFromFile(TDes16& aFile, TInt aPos, TInt aBlockSize, TInt aSize)
216 TInt size = aSize * KOneK;
217 TTimeIntervalMicroSeconds timeTaken(0);
219 r = file.Open(TheFs,aFile,EFileShareAny|EFileRead);
222 startTime.HomeTime();
223 r = file.Seek(ESeekStart, aPos);
228 r = file.Read(gBufReadPtr, aBlockSize);
235 timeTaken = endTime.MicroSecondsFrom(startTime);
237 return I64LOW(timeTaken.Int64() / gTimeUnit);
240 /** Read aSize KBs from aFile file in blocks of aBlockSize bytes several times
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
247 LOCAL_C TInt ReadFromFileSeveralTimes(TDes16& aFile, TInt ayMax, TInt aBlockSize, TInt aSize)
254 TInt size = aSize * KOneK;
255 TTimeIntervalMicroSeconds timeTaken(0);
259 r = file.Open(TheFs, aFile, EFileShareAny|EFileRead);
263 while( i < KSeveralTimes )
265 pos = Rand(Pow(ayMax - 1));
266 startTime.HomeTime();
267 r = file.Seek(ESeekStart, pos);
273 r = file.Read(gBufReadPtr, aBlockSize);
279 timeTaken = endTime.MicroSecondsFrom(startTime);
280 time += I64LOW(timeTaken.Int64());
286 return I64LOW((time / gTimeUnit) / KSeveralTimes); // Overflow not expected here, since the number is not big enough
290 /** Write aSize KBs to aFile file in blocks of aBlockSize bytes
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
297 LOCAL_C TInt WriteToFile(TDes16& aFile, TInt aPos, TInt aBlockSize, TInt aSize)
304 TInt size = aSize * KOneK;
305 TTimeIntervalMicroSeconds timeTaken(0);
307 r = file.Open(TheFs, aFile, EFileShareAny|EFileWrite);
310 startTime.HomeTime();
311 r = file.Seek(ESeekStart, aPos);
315 r = file.Write(gBufWritePtr, aBlockSize);
322 timeTaken = endTime.MicroSecondsFrom(startTime);
324 return I64LOW(timeTaken.Int64() / gTimeUnit);
327 /** Write aSize KBs to aFile file in blocks of aBlockSize bytes several times
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
334 LOCAL_C TInt WriteToFileSeveralTimes(TDes16& aFile, TInt ayMax, TInt aBlockSize, TInt aSize)
341 TInt size = aSize * KOneK;
342 TTimeIntervalMicroSeconds timeTaken(0);
345 r = file.Open(TheFs, aFile, EFileShareAny|EFileWrite);
349 while( i < KSeveralTimes )
351 pos = Rand(Pow(ayMax - 1));
352 startTime.HomeTime();
353 r = file.Seek(ESeekStart, pos);
359 r = file.Write(gBufWritePtr, aBlockSize);
365 timeTaken = endTime.MicroSecondsFrom(startTime);
366 time += I64LOW(timeTaken.Int64());
372 return I64LOW((time / gTimeUnit) / KSeveralTimes); // Overflow not expected here, since the number is not big enough
375 /** Read small blocks in the gBaseFile
378 LOCAL_C TInt ReadSmallBase(TAny* )
380 RTest test(_L("test 2"));
383 TBuf8<1024> dummy(1024);
388 TInt r = fs.Connect();
390 fs.SetSessionPath(gSessionPath);
391 r = file.Open(fs, gBaseFile, EFileShareAny|EFileRead);
398 randPos = Rand(64) * KOneK ;
399 r = file.Seek(ESeekStart, randPos);
403 r = file.Read(dummy, blockSize); // Sync operation
409 /** Read small blocks in gFileA
412 LOCAL_C TInt ReadSmallA(TAny* )
414 RTest test(_L("test 2"));
419 TBuf8<1024> dummy(1024);
422 TInt r = fs.Connect();
424 fs.SetSessionPath(gSessionPath);
426 r = file.Open(fs,gFileA,EFileShareAny|EFileRead);
433 randPos = Rand(64) * KOneK ;
434 r = file.Seek(ESeekStart, randPos);
439 r = file.Read(dummy, blockSize); // Sync operation
446 /** Read small blocks in gFileB
449 LOCAL_C TInt ReadSmallB(TAny* )
451 RTest test(_L("test 2"));
454 TBuf8<1024> dummy(1024);
459 TInt r = fs.Connect();
461 fs.SetSessionPath(gSessionPath);
462 r = file.Open(fs, gFileB, EFileShareAny|EFileRead);
469 randPos = Rand(64) * KOneK ;
470 r = file.Seek(ESeekStart, randPos);
474 r = file.Read(dummy, blockSize); // Sync operation
482 /** Read large blocks in gBaseFile
485 LOCAL_C TInt ReadLargeBase(TAny* )
487 RTest test(_L("test 2"));
491 TInt blockSize = 128 * KOneK;
493 TInt r = fs.Connect();
495 fs.SetSessionPath(gSessionPath);
496 r = file.Open(fs,gBaseFile,EFileShareAny|EFileRead);
503 r = file.Seek(ESeekStart, pos);
506 r = file.Read(gBufReadBPtr, blockSize); // Sync operation
511 /** Read large blocks in gFileA
514 LOCAL_C TInt ReadLargeA(TAny* )
516 RTest test(_L("test 2"));
519 TInt blockSize = 128 * KOneK;
522 TInt r = fs.Connect();
524 fs.SetSessionPath(gSessionPath);
526 r = file.Open(fs,gFileA,EFileShareAny|EFileRead);
533 r = file.Seek(ESeekStart, pos);
536 r = file.Read(gBufReadBPtr, blockSize); // Sync operation
541 /** Read large blocks in gFileB
544 LOCAL_C TInt ReadLargeB(TAny* )
546 RTest test(_L("test 2"));
549 TInt blockSize = 128 * KOneK;
555 fs.SetSessionPath(gSessionPath);
557 r = file.Open(fs,gFileB,EFileShareAny|EFileRead);
564 r = file.Seek(ESeekStart, pos);
567 r = file.Read(gBufReadBPtr, blockSize); // Sync operation
572 /** Small reads from a file
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
581 LOCAL_C void smallReads(TInt xMax, TInt yMax, TTestState aCase)
588 CreateFile(gBaseFile, Pow(yMax-1));
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);
598 buf.AppendNum(ThreadCount++);
600 r = gSpeedyII.Create(buf, ReadSmallBase, KDefaultStackSize, KHeapSize, KHeapSize, NULL);
610 if(aCase == ETwoThreadsDif)
611 { // Start two different threads accessing different files
612 CreateFile(gFileA, Pow(yMax-1));
613 CreateFile(gFileB, Pow(yMax-1));
615 TBuf<20> buf = _L("Speedy");
616 buf.AppendNum(ThreadCount++);
617 r = gSpeedy.Create(buf, ReadSmallA, KDefaultStackSize, KHeapSize, KHeapSize, NULL);
621 buf.AppendNum(ThreadCount++);
623 r = gSpeedyII.Create(buf, ReadSmallB, KDefaultStackSize, KHeapSize, KHeapSize, NULL);
634 { // Actual accesses and timing to the main file
636 PrintResult(i + 1, j + 1, Pow(i));
639 if(Pow(i) < KSmallThreshold)
641 timeRes = ReadFromFile(gBaseFile, Rand(Pow(yMax - 1)), Pow(i), Pow(j));
644 { // Too small for only one time measure
645 timeRes = ReadFromFileSeveralTimes(gBaseFile, yMax, Pow(i), Pow(j));
649 User::After(1000000);
651 PrintResultTime(i + 1, j + 2, timeRes);
661 if((aCase == ETwoThreadsSame) || (aCase == ETwoThreadsDif))
662 { // Finish the threads
667 /** Large reads from a file
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)
677 LOCAL_C void largeReads(TInt xMax, TInt yMax, TTestState aCase)
684 CreateFile(gBaseFile, 10 * KOneK * KOneK); // 10 Mb
686 if(aCase == ETwoThreadsSame)
687 { // Start two different threads accessing the same file
689 TRAPD(res, gBufB = HBufC8::NewL(256 * KOneK));
690 test(res == KErrNone && gBufB != NULL);
691 gBufReadBPtr.Set(gBufSec->Des());
693 TBuf<20> buf = _L("Speedy");
694 buf.AppendNum(ThreadCount++);
695 r = gSpeedy.Create(buf, ReadLargeBase, KDefaultStackSize, KHeapSize, KHeapSize, NULL);
699 buf.AppendNum(ThreadCount++);
701 r = gSpeedyII.Create(buf, ReadLargeBase, KDefaultStackSize, KHeapSize, KHeapSize, NULL);
711 if(aCase == ETwoThreadsDif)
712 { // Start two different threads accessing different files
714 CreateFile(gFileA, KOneK * KOneK);
715 CreateFile(gFileB, KOneK * KOneK);
717 TRAPD(res, gBufB = HBufC8::NewL(256 * KOneK));
718 test(res == KErrNone && gBufB != NULL);
719 gBufReadBPtr.Set(gBufSec->Des());
721 TBuf<20> buf = _L("Speedy");
722 buf.AppendNum(ThreadCount++);
723 r = gSpeedy.Create(buf, ReadLargeA, KDefaultStackSize, KHeapSize, KHeapSize, NULL);
727 buf.AppendNum(ThreadCount++);
729 r = gSpeedyII.Create(buf, ReadLargeB, KDefaultStackSize, KHeapSize, KHeapSize, NULL);
739 if(aCase == ETwoThreadsDifDif)
740 { // Start two different threads accessing different files
742 CreateFile(gFileA, KOneK * KOneK);
743 CreateFile(gFileB, KOneK * KOneK);
745 TRAPD(res,gBufB = HBufC8::NewL(256 * KOneK));
746 test(res == KErrNone && gBufB != NULL);
747 gBufReadBPtr.Set(gBufSec->Des());
749 TBuf<20> buf=_L("Speedy");
750 buf.AppendNum(ThreadCount++);
751 r = gSpeedy.Create(buf, ReadLargeA, KDefaultStackSize, KHeapSize, KHeapSize, NULL);
755 buf.AppendNum(ThreadCount++);
757 r = gSpeedyII.Create(buf, ReadSmallB, KDefaultStackSize, KHeapSize, KHeapSize, NULL);
769 { // Actual accesses and timing to the main file
771 PrintResult(i - 10, j + 1, Pow(i));
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
779 timeRes = ReadFromFile(gBaseFile, 0, Pow(i), size);
782 User::After(1000000);
784 PrintResultTime(i - 10, j + 2, timeRes);
793 if((aCase == ETwoThreadsSame) || (aCase == ETwoThreadsDif) || (aCase == ETwoThreadsDifDif))
794 { // Finish the threads
801 /** Large writes to a file
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
810 LOCAL_C void largeWrites(TInt xMax, TInt yMax, TTestState aCase)
817 CreateFile(gBaseFile, 10 * KOneK * KOneK); // 10 Mb
819 if(aCase == ETwoThreadsSame)
820 { // Start two different threads accessing the same file
822 TRAPD(res, gBufB = HBufC8::NewL(256 * KOneK));
823 test(res == KErrNone && gBufB != NULL);
824 gBufReadBPtr.Set(gBufSec->Des());
826 TBuf<20> buf = _L("Speedy");
827 buf.AppendNum(ThreadCount++);
828 r = gSpeedy.Create(buf, ReadLargeBase, KDefaultStackSize, KHeapSize, KHeapSize, NULL);
832 buf.AppendNum(ThreadCount++);
834 r = gSpeedyII.Create(buf, ReadLargeBase, KDefaultStackSize, KHeapSize, KHeapSize, NULL);
844 if(aCase == ETwoThreadsDif)
845 { // Start two different threads accessing different files
847 CreateFile(gFileA, KOneK * KOneK);
848 CreateFile(gFileB, KOneK * KOneK);
850 TRAPD(res, gBufB = HBufC8::NewL(256 * KOneK));
851 test(res == KErrNone && gBufB != NULL);
852 gBufReadBPtr.Set(gBufSec->Des());
854 TBuf<20> buf = _L("Speedy");
855 buf.AppendNum(ThreadCount++);
856 r = gSpeedy.Create(buf, ReadLargeA, KDefaultStackSize, KHeapSize, KHeapSize, NULL);
860 buf.AppendNum(ThreadCount++);
862 r = gSpeedyII.Create(buf, ReadLargeB, KDefaultStackSize, KHeapSize, KHeapSize, NULL);
874 { // Actual accesses and timing to the main file
876 PrintResult(i - 10 , j + 1, Pow(i));
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);
886 User::After(1000000);
888 PrintResultTime(i - 10, j + 2, timeRes);
896 if((aCase == ETwoThreadsSame) || (aCase == ETwoThreadsDif) || (aCase == ETwoThreadsDifDif))
897 { // Finish the threads
904 /** Small writes to a file
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
913 LOCAL_C void smallWrites(TInt xMax, TInt yMax, TTestState aCase)
920 CreateFile(gBaseFile, Pow(yMax-1));
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);
930 buf.AppendNum(ThreadCount++);
932 r = gSpeedyII.Create(buf, ReadSmallBase, KDefaultStackSize, KHeapSize, KHeapSize, NULL);
942 if(aCase == ETwoThreadsDif)
943 { // Start two different threads accessing different files
944 CreateFile(gFileA, Pow(yMax-1));
945 CreateFile(gFileB, Pow(yMax-1));
947 TBuf<20> buf = _L("Speedy");
948 buf.AppendNum(ThreadCount++);
949 r = gSpeedy.Create(buf, ReadSmallA, KDefaultStackSize, KHeapSize, KHeapSize, NULL);
953 buf.AppendNum(ThreadCount++);
955 r = gSpeedyII.Create(buf, ReadSmallB, KDefaultStackSize, KHeapSize, KHeapSize, NULL);
968 PrintResult(i + 1, j + 1, Pow(i));
971 if(Pow(i) < KSmallThreshold)
973 timeRes = WriteToFile(gBaseFile, Rand(Pow(yMax-1)), Pow(i), Pow(j));
977 timeRes = WriteToFileSeveralTimes(gBaseFile, yMax, Pow(i), Pow(j));
981 User::After(1000000);
983 PrintResultTime(i + 1, j + 2, timeRes);
992 if((aCase == ETwoThreadsSame) || (aCase == ETwoThreadsDif))
993 { // Finish the threads
999 /** This test benchmarks small random r/w (e.g. database access)
1001 @param aSelector Selection array for manual tests
1003 LOCAL_C TInt TestSmall(TAny* aSelector)
1006 Validate(aSelector);
1008 // Each test case of the suite has an identifyer for parsing purposes of the results
1013 PrintHeaders(4, _L("t_fcachebm. Small Random r/w"));
1016 test.Printf(_L("#~TS_Title_%d,%d: Small reads, no threads \n"), gTestHarness, gTestCase);
1018 smallReads(KSmallRow, KSmallCol, ENoThreads);
1021 test.Printf(_L("#~TS_Title_%d,%d: Small reads, threads accessing same file \n"),
1022 gTestHarness, gTestCase);
1024 smallReads(KSmallRow, KSmallCol, ETwoThreadsSame);
1027 test.Printf(_L("#~TS_Title_%d,%d: Small reads, threads accessing dif files \n"),
1028 gTestHarness, gTestCase);
1030 smallReads(KSmallRow, KSmallCol, ETwoThreadsDif);
1033 DeleteAll(gSessionPath);
1035 // Small writes test case
1037 test.Printf(_L("#~TS_Title_%d,%d: Test small writes\n"), gTestHarness, gTestCase);
1039 smallWrites(KSmallRow, KSmallCol, ENoThreads);
1042 test.Printf(_L("#~TS_Title_%d,%d: Small writes, threads accessing same file \n"),
1043 gTestHarness, gTestCase);
1044 smallWrites(KSmallRow, KSmallCol, ETwoThreadsSame);
1047 test.Printf(_L("#~TS_Title_%d,%d: Small writes, threads accessing dif files \n"),
1048 gTestHarness, gTestCase);
1049 smallWrites(KSmallRow, KSmallCol, ETwoThreadsDif);
1052 DeleteAll(gSessionPath);
1053 test.Printf(_L("#~TestEnd_%d\n"), gTestHarness);
1058 /** This test benchmarks large sequential r/w (e.g. MM)
1060 @param aSelector Selection array for manual tests
1062 LOCAL_C TInt TestLarge(TAny* aSelector)
1065 Validate(aSelector);
1067 // Each test case of the suite has an identifyer for parsing purposes of the results
1072 PrintHeaders(3, _L("t_fcachebm. Large sequential r/w"));
1075 test.Printf(_L("#~TS_Title_%d,%d: Large sequential reads\n"), gTestHarness, gTestCase);
1077 largeReads(KLargeRow, KLargeCol, ENoThreads);
1080 test.Printf(_L("#~TS_Title_%d,%d: Large sequential reads, threads accessing same file\n"),
1081 gTestHarness, gTestCase);
1082 largeReads(KLargeRow, KLargeCol, ETwoThreadsSame);
1085 test.Printf(_L("#~TS_Title_%d,%d: Large sequential reads, threads accessing dif files\n"),
1086 gTestHarness, gTestCase);
1087 largeReads(KLargeRow, KLargeCol, ETwoThreadsDif);
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);
1095 DeleteAll(gSessionPath);
1098 test.Printf(_L("#~TS_Title_%d,%d: Large sequential writes\n"), gTestHarness, gTestCase);
1100 largeWrites(KLargeRow, KLargeCol, ENoThreads);
1103 test.Printf(_L("#~TS_Title_%d,%d: Large sequential writes, threads accessing same file\n"),
1104 gTestHarness, gTestCase);
1105 largeWrites(KLargeRow, KLargeCol, ETwoThreadsSame);
1108 test.Printf(_L("#~TS_Title_%d,%d: Large sequential writes, threads accessing dif files\n"),
1109 gTestHarness, gTestCase);
1110 largeWrites(KLargeRow, KLargeCol, ETwoThreadsDif);
1113 DeleteAll(gSessionPath);
1114 test.Printf(_L("#~TestEnd_%d\n"), gTestHarness);
1119 /** Writes aSize bytes of data in aBlockSize during aTime seconds
1120 if the aSize bps is not met, it fails
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
1127 LOCAL_C TBool writeStr( RFile f, TInt aSize, TInt aBlockSize, TInt aTime)
1130 TTime startTime, endTime;
1131 TTimeIntervalMicroSeconds timeTaken(0);
1132 TTimeIntervalMicroSeconds32 timeLeft(0);
1133 TBool onTarget = ETrue;
1138 while((i < aTime) && onTarget)
1140 // If measuring the CPU time
1142 startTime.HomeTime();
1146 r = f.Write(gBufWritePtr, aBlockSize);
1152 timeTaken = endTime.MicroSecondsFrom(startTime);
1153 time = I64LOW(timeTaken.Int64());
1159 timeLeft = KOneSec - time;
1160 if(timeLeft.Int() >= 0)
1162 User::After(timeLeft);
1173 LOCAL_C TInt ReadStream(TAny*)
1175 RTest test(_L("test 2"));
1179 TTime startTime, endTime;
1180 TTimeIntervalMicroSeconds timeTaken(0);
1181 TTimeIntervalMicroSeconds32 timeLeft(0);
1183 TInt size , currentPos = 0;
1185 TInt r = fs.Connect();
1187 fs.SetSessionPath(gSessionPath);
1189 r = file.Open(fs, gStreamFile, EFileShareAny|EFileRead);
1194 r = file.Size(size);
1199 startTime.HomeTime();
1201 while(j < (gCurrentSpeed * KOneK))
1203 r=file.Read(gBufReadPtr,gCurrentBS);
1209 timeTaken = endTime.MicroSecondsFrom(startTime);
1210 time = I64LOW(timeTaken.Int64());
1214 test.Printf(_L("Background Thread: Speed failed to be achieved: %d kbps\n"), gCurrentSpeed);
1219 timeLeft = KOneSec - time;
1220 User::After(timeLeft);
1221 currentPos += (gCurrentSpeed * KOneK);
1222 r = file.Size(size);
1224 if(currentPos > size )
1227 file.Seek(ESeekStart, currentPos);
1234 /** Test case layout, read/write at aSpeed during aWtime and aRTime
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
1241 LOCAL_C void streamIt ( TInt aSpeed, TInt aBlockSize, TInt aWTime, TInt aRTime, TInt aStep)
1243 TInt iSize = (aSpeed * KTobps) / KByte; // Size in bytes
1248 PrintResult(aStep, 1, aBlockSize);
1250 r = file.Replace(TheFs, gStreamFile, EFileShareAny|EFileWrite);
1253 // Streaming to the media during aWTime seconds
1254 if(writeStr(file, iSize, aBlockSize, aWTime))
1256 PrintResult(aStep, 2, 1);
1260 PrintResult(aStep, 2, 0);
1263 // Create a different thread for reading from the beginning during aRTime
1264 TBuf<20> buf = _L("Speedy");
1265 buf.AppendNum(ThreadCount++);
1267 gCurrentSpeed = aSpeed;
1268 gCurrentBS = aBlockSize;
1269 r = gSpeedy.Create(buf, ReadStream, KDefaultStackSize, KHeapSize, KHeapSize, NULL);
1275 // Keep writing during the time the other thread is reading
1276 if(writeStr(file, iSize, aBlockSize, aRTime))
1278 PrintResult(aStep, 3, 1);
1282 PrintResult(aStep, 3, 0);
1285 // Writing from the beginning again
1286 file.Seek(ESeekStart, pos);
1287 if(writeStr(file, iSize, aBlockSize, aRTime))
1289 PrintResult(aStep, 4, 1);
1293 PrintResult(aStep, 4, 0);
1297 // Kill the thread for reading
1298 gSpeedy.Kill(KErrNone);
1305 /** Iterating through different blocksizes
1307 @param aSpeed Speed at which the test happens
1309 LOCAL_C void streaming(TInt aSpeed)
1311 TInt i = 9; // Pow(i) = 512 bytes
1315 while( i < 15 ) // Pow(i) = 16 Kb
1317 blockSize = Pow(i) ;
1318 streamIt(aSpeed, blockSize, 5 * 60, 15, testStep++); // 5 minutes writing , then 15 secs reading
1323 /** High level test routine. Different test cases executed
1325 @param aSelector Test case configuration in case of manual execution
1327 LOCAL_C TInt TestStreaming(TAny* aSelector)
1330 Validate(aSelector);
1331 // Each test case of the suite has an identifyer for parsing purposes of the results
1336 PrintHeaders(5, _L("t_fcachebm. Streaming"));
1338 test.Printf(_L("#~TS_Title_%d,%d: Writing / reading at 100 kbps\n"),
1339 gTestHarness, gTestCase);
1343 test.Printf(_L("#~TS_Title_%d,%d: Writing / reading at 200 kbps\n"),
1344 gTestHarness, ++gTestCase);
1348 test.Printf(_L("#~TS_Title_%d,%d: Writing / reading at 500 kbps\n"),
1349 gTestHarness, ++gTestCase);
1354 DeleteAll(gSessionPath);
1356 // Start the small random reads in the background
1357 CreateFile(gBaseFile, Pow(KSmallCol-1));
1359 TBuf<20> buf=_L("Speedy");
1360 buf.AppendNum(ThreadCount++);
1362 TInt r = gSpeedyII.Create(buf, ReadSmallBase, KDefaultStackSize, KHeapSize, KHeapSize, NULL);
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);
1374 test.Printf(_L("#~TS_Title_%d,%d: Writing / reading at 200 kbps, while small reads\n"),
1375 gTestHarness, ++gTestCase);
1379 test.Printf(_L("#~TS_Title_%d,%d: Writing / reading at 500 kbps, while small reads\n"),
1380 gTestHarness, ++gTestCase);
1384 // Kill the small random reads and writes
1385 gSpeedyII.Kill(KErrNone);
1390 DeleteAll(gSessionPath);
1393 test.Printf(_L("#~TestEnd_%d\n"), gTestHarness);
1398 /** It goes automatically through all the options
1400 @param aSelector Configuration in case of manual execution
1402 LOCAL_C TInt TestAll(TAny* aSelector)
1404 TestSmall(aSelector);
1405 TestLarge(aSelector);
1406 TestStreaming(aSelector);
1414 GLDEF_C void CallTestsL()
1418 TInt r=client.CreateLocal(0);
1421 // Setting up the environment and creating the needed files
1422 gSessionPath = _L("?:\\F32-TST\\");
1423 gSessionPath[0] = (TText) gDriveToTest;
1425 FileNamesGeneration(temp, 8, 0, 1);
1426 gBaseFile = gSessionPath;
1427 gBaseFile.Append(temp);
1429 FileNamesGeneration(temp, 8, 1, 1);
1430 gFileA = gSessionPath;
1431 gFileA.Append(temp);
1433 FileNamesGeneration(temp, 8, 2, 1);
1434 gFileB = gSessionPath;
1435 gFileB.Append(temp);
1437 FileNamesGeneration(temp, 8, 3, 1);
1438 gStreamFile = gSessionPath;
1439 gStreamFile.Append(temp);
1441 TRAPD(res,gBuf = HBufC8::NewL(256 * KOneK));
1442 test(res == KErrNone && gBuf != NULL);
1444 gBufWritePtr.Set(gBuf->Des());
1445 FillBuffer(gBufWritePtr, 256 * KOneK, 'A');
1447 TRAPD(res2, gBufSec = HBufC8::NewL(256 * KOneK));
1448 test(res2 == KErrNone && gBufSec != NULL);
1449 gBufReadPtr.Set(gBufSec->Des());
1451 TVolumeInfo volInfo;
1454 r = TheFs.CharToDrive(gDriveToTest,drive);
1456 r = TheFs.Volume(volInfo, drive);
1459 gMediaSize = volInfo.iSize;
1461 FormatFat(gSessionPath[0]-'A');
1462 TheFs.MkDirAll(gSessionPath);
1465 TBuf<20> buf = _L("Noisy");
1466 r = noisy.Create(buf, noise, KDefaultStackSize, KHeapSize, KHeapSize, NULL);
1471 CSelectionBox* TheSelector=CSelectionBox::NewL(test.Console());
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);
1489 TestAll(TheSelector);
1492 DeleteAll(gSessionPath);
1498 noisy.Kill(KErrNone);