Update contrib.
1 // Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
2 // All rights reserved.
3 // This component and the accompanying materials are made available
4 // under the terms of the License "Eclipse Public License v1.0"
5 // which accompanies this distribution, and is available
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // f32test\bench\t_fsropen.cpp
21 #include "..\server\t_server.h"
22 #include "t_benchmain.h"
24 GLDEF_D RTest test(_L("File Server Benchmarks, Open File"));
26 //----------------------------------------------------------------------------------------------
27 //! @SYMTestCaseID PBASE-T_FSROPEN-0275
30 //! @SYMTestCaseDesc This test case is measuring performance of the FAT implementation
31 //! @SYMTestActions 0. Expects the files to exist in order to successful execution
32 //! 1. Time the opening and read of 4 Kb of last.txt file in each directory
33 //! 2. Time the opening and read of 4 Kb of last.txt file in each directory
34 //! with two clients accessing the directory
35 //! 3. Time the opening and read of 4 Kb of last.txt file in each directory
36 //! with two clients accessing different directories
38 //! @SYMTestExpectedResults Finishes if the system behaves as expected, panics otherwise
39 //! @SYMTestPriority High
40 //! @SYMTestStatus Implemented
41 //----------------------------------------------------------------------------------------------
44 LOCAL_D RSemaphore client;
45 LOCAL_D const TInt KHeapSize=0x6000;
46 LOCAL_D TBuf8<4096> buf;
48 LOCAL_D TDriveList gDriveList;
49 LOCAL_D TFileName gFindEntryDir;
50 LOCAL_D TBuf<100> gFindDir;
52 LOCAL_D TFileName gFindEntryDir2;
53 LOCAL_D TBuf<100> gFindDir2;
59 LOCAL_D TInt ThreadCount=0;
61 _LIT(KDirMultipleName2, "dir%d_%d\\");
63 /** Find entry in directory
66 LOCAL_C TInt FindEntryAccess2(TAny*)
69 TInt r = fs.Connect();
70 RTest test(_L("test 2"));
72 r = fs.SetSessionPath(gSessionPath);
80 r = fs.Entry(gFindEntryDir2, entry);
83 r=fs.Entry(gFindDir2, entry);
88 /** Starts two concurrent client sessions in the same directory
91 LOCAL_C void DoTest(TThreadFunction aFunction)
93 TBuf<50> buf = _L("Speedy");
94 buf.AppendNum(ThreadCount++);
95 TInt r = gSpeedy.Create(buf, aFunction, KDefaultStackSize, KHeapSize, KHeapSize, NULL);
99 buf.AppendNum(ThreadCount++);
100 r = gSpeedyII.Create(buf, aFunction, KDefaultStackSize, KHeapSize, KHeapSize, NULL);
103 gSpeedy.SetPriority(EPriorityLess);
104 gSpeedyII.SetPriority(EPriorityLess);
113 /** Starts two concurrent client sessions in different directories
116 LOCAL_C void DoTest2(TThreadFunction aFunction)
118 TBuf<50> buf=_L("Speedy");
119 buf.AppendNum(ThreadCount++);
120 TInt r = gSpeedy.Create(buf, aFunction, KDefaultStackSize, KHeapSize, KHeapSize, NULL);
124 buf.AppendNum(ThreadCount++);
125 r = gSpeedyII.Create(buf, FindEntryAccess2, KDefaultStackSize, KHeapSize, KHeapSize, NULL);
128 gSpeedy.SetPriority(EPriorityLess);
129 gSpeedyII.SetPriority(EPriorityLess);
138 /** Kills the concurrent session
141 LOCAL_C void DoTestKill()
143 gSpeedy.Kill(KErrNone);
146 gSpeedyII.Kill(KErrNone);
150 /** Find entry in directory
153 LOCAL_C TInt FindEntryAccess(TAny*)
156 TInt r = fs.Connect();
157 RTest test(_L("test 2"));
159 fs.SetSessionPath(gSessionPath);
167 r = fs.Entry(gFindEntryDir, entry);
170 r = fs.Entry(gFindDir,entry);
175 /** Find last.txt by opening it and with two threads accessing the current directory
176 and looking for the same file
178 @param aN Number of files in the directory
179 @param aStep Test step
181 LOCAL_C void FindFileM2(TInt aN, TInt aStep)
192 TTimeIntervalMicroSeconds timeTaken(0);
194 TInt timeTaken1 = -1, timeTaken2 = -1, timeTaken3 = -1;
196 if(aN <= gFilesLimit)
202 dirtemp.Format(KDirMultipleName2, 1, aN);
203 dir1.Append(dirtemp);
206 dirtemp.Format(KDirMultipleName2, 2, aN);
207 dir2.Append(dirtemp);
209 dirtemp.Format(KDirMultipleName2, 3, aN);
210 dir3.Append(dirtemp);
212 dir1.Append(KCommonFile);
216 gFindEntryDir = dir1;
217 DoTest(FindEntryAccess);
220 startTime.HomeTime();
222 r = file.Open(TheFs, dir1, EFileShareAny|EFileWrite);
230 timeTaken = endTime.MicroSecondsFrom(startTime);
231 timeTaken1 = I64LOW(timeTaken.Int64() / gTimeUnit);
237 dir2.Append(KCommonFile);
238 gFindEntryDir = dir2;
240 DoTest(FindEntryAccess);
242 startTime.HomeTime();
244 r = file.Open(TheFs, dir2, EFileShareAny|EFileWrite);
252 timeTaken = endTime.MicroSecondsFrom(startTime);
253 timeTaken2 = I64LOW(timeTaken.Int64() / gTimeUnit);
259 dir3.Append(KCommonFile);
261 gFindEntryDir = dir3;
262 DoTest(FindEntryAccess);
265 startTime.HomeTime();
267 r=file.Open(TheFs, dir3, EFileShareAny|EFileWrite);
274 timeTaken = endTime.MicroSecondsFrom(startTime);
275 timeTaken3 = I64LOW(timeTaken.Int64() / gTimeUnit);
280 PrintResult(aStep, 1, aN);
281 PrintResultTime(aStep, 2, timeTaken1);
282 PrintResultTime(aStep, 3, timeTaken2);
283 PrintResultTime(aStep, 4, timeTaken3);
286 /** Find last.txt by opening it and without any other process
288 @param aN Number of files in the directory
289 @param aStep Test step
291 LOCAL_C void OpenFile(TInt aN, TInt aStep)
302 TTimeIntervalMicroSeconds timeTaken(0);
303 TInt timeTaken1 = -1, timeTaken2 = -1, timeTaken3 = -1;
306 if(aN <= gFilesLimit)
312 dirtemp.Format(KDirMultipleName, 1, aN);
313 dir1.Append(dirtemp);
315 dirtemp.Format(KDirMultipleName, 2, aN);
316 dir2.Append(dirtemp);
318 dirtemp.Format(KDirMultipleName, 3, aN);
319 dir3.Append(dirtemp);
321 dir1.Append(KCommonFile);
322 dir2.Append(KCommonFile);
323 dir3.Append(KCommonFile);
327 startTime.HomeTime();
329 r = file.Open(TheFs, dir1, EFileShareAny|EFileRead);
331 r = file.Seek(ESeekStart, pos);
339 timeTaken = endTime.MicroSecondsFrom(startTime);
340 timeTaken1 = I64LOW(timeTaken.Int64() / gTimeUnit);
346 startTime.HomeTime();
348 r = file.Open(TheFs, dir2, EFileShareAny|EFileRead);
350 r = file.Seek(ESeekStart,pos);
359 timeTaken = endTime.MicroSecondsFrom(startTime);
360 timeTaken2 = I64LOW(timeTaken.Int64() / gTimeUnit);
365 startTime.HomeTime();
367 r = file.Open(TheFs, dir3, EFileShareAny|EFileRead);
369 r = file.Seek(ESeekStart, pos);
377 timeTaken=endTime.MicroSecondsFrom(startTime);
378 timeTaken3 = I64LOW(timeTaken.Int64() / gTimeUnit);
382 PrintResult(aStep, 1, aN);
383 PrintResultTime(aStep, 2, timeTaken1);
384 PrintResultTime(aStep, 3, timeTaken2);
385 PrintResultTime(aStep, 4, timeTaken3);
389 /** Find last.txt with TFindFile and with two threads accessing the current directory and other one
391 @param aN Number of files in the directory
392 @param aStep Test step
394 LOCAL_C void FindFileMD1(TInt aN, TInt aStep)
403 TFindFile find(TheFs);
406 TTimeIntervalMicroSeconds timeTaken(0);
407 TInt timeTaken1 = -1, timeTaken2 = -1, timeTaken3 = -1;
409 if(aN <= gFilesLimit)
415 dirtemp.Format(KDirMultipleName2,1,aN);
416 dir1.Append(dirtemp);
419 dirtemp.Format(KDirMultipleName, 2, aN);
420 dir2.Append(dirtemp);
422 dirtemp.Format(KDirMultipleName, 3, aN);
423 dir3.Append(dirtemp);
426 dirtemp.Format(KDirMultipleName, 3, 300);
428 dir4.Append(dirtemp);
431 dir1.Append(KCommonFile);
432 dir2.Append(KCommonFile);
433 dir3.Append(KCommonFile);
434 dir4.Append(KCommonFile);
435 gFindEntryDir2 = dir4;
440 gFindEntryDir = dir1;
442 dir4.Format(KDirMultipleName, 1, aN);
444 DoTest2(FindEntryAccess);
445 startTime.HomeTime();
447 r = find.FindByPath(dir1, &dir4);
453 timeTaken = endTime.MicroSecondsFrom(startTime);
454 timeTaken1 = I64LOW(timeTaken.Int64() / gTimeUnit);
459 dir4.Format(KDirMultipleName, 2, aN);
463 DoTest2(FindEntryAccess);
465 startTime.HomeTime();
467 r = find.FindByPath(dir2,&dir4);
471 timeTaken = endTime.MicroSecondsFrom(startTime);
475 timeTaken2 = I64LOW(timeTaken.Int64() / gTimeUnit);
480 dir4.Format(KDirMultipleName, 3, aN);
481 gFindEntryDir = dir3;
483 DoTest2(FindEntryAccess);
485 startTime.HomeTime();
487 r = find.FindByPath(dir3,&dir4);
493 timeTaken = endTime.MicroSecondsFrom(startTime);
494 timeTaken3 = I64LOW(timeTaken.Int64() / gTimeUnit);
498 PrintResult(aStep, 1, aN);
499 PrintResultTime(aStep, 2, timeTaken1);
500 PrintResultTime(aStep, 3, timeTaken2);
501 PrintResultTime(aStep, 4, timeTaken3);
505 /** Find last.txt by opening the file and with two threads accessing the current directory and other one
507 @param aN Number of files in the directory
508 @param aStep Test step
510 LOCAL_C void FindFileMD2(TInt aN, TInt aStep)
522 TTimeIntervalMicroSeconds timeTaken(0);
523 TInt timeTaken1 = -1, timeTaken2 = -1, timeTaken3 = -1;
527 if(aN <= gFilesLimit)
534 dirtemp.Format(KDirMultipleName2, 1, aN);
535 dir1.Append(dirtemp);
538 dirtemp.Format(KDirMultipleName2, 2, aN);
539 dir2.Append(dirtemp);
541 dirtemp.Format(KDirMultipleName2, 3, aN);
542 dir3.Append(dirtemp);
544 dir1.Append(KCommonFile);
545 gFindEntryDir = dir1;
547 dirtemp.Format(KDirMultipleName, 3, 300);
548 dir4.Append(dirtemp);
550 dir4.Append(KCommonFile);
551 gFindEntryDir2 = dir4;
555 DoTest2(FindEntryAccess);
558 startTime.HomeTime();
560 r = file.Open(TheFs,dir1,EFileShareAny|EFileWrite);
568 timeTaken = endTime.MicroSecondsFrom(startTime);
569 timeTaken1 = I64LOW(timeTaken.Int64() / gTimeUnit);
575 dir2.Append(KCommonFile);
576 gFindEntryDir = dir2;
578 DoTest2(FindEntryAccess);
581 startTime.HomeTime();
583 r = file.Open(TheFs, dir2, EFileShareAny|EFileWrite);
591 timeTaken = endTime.MicroSecondsFrom(startTime);
592 timeTaken2 = I64LOW(timeTaken.Int64() / gTimeUnit);
598 dir3.Append(KCommonFile);
599 gFindEntryDir = dir3;
600 DoTest2(FindEntryAccess);
603 startTime.HomeTime();
605 r = file.Open(TheFs, dir3, EFileShareAny|EFileWrite);
612 timeTaken = endTime.MicroSecondsFrom(startTime);
613 timeTaken3 = I64LOW(timeTaken.Int64() / gTimeUnit);
617 PrintResult(aStep, 1, aN);
618 PrintResultTime(aStep, 2, timeTaken1);
619 PrintResultTime(aStep, 3, timeTaken2);
620 PrintResultTime(aStep, 4, timeTaken3);
623 /** Times the system when opening a file with multiple clients accessing the directory
624 Precondition: This test expects the drive already filled with files
626 @param aSelector Configuration in case of manual execution
628 LOCAL_C TInt TestOpenEntry(TAny* aSelector)
634 TTimeIntervalSeconds timeTaken;
638 test.Printf(_L("#~TS_Title_%d,%d: Open and read 4 Kb entry last.txt, RFile::Open \n"), gTestHarness, gTestCase);
639 startTime.HomeTime();
641 while(i <= KMaxFiles)
643 if(i == 100 || i == 1000 || i == 5000 || i == 10000)
644 OpenFile(i, testStep++);
651 r = endTime.SecondsFrom(startTime, timeTaken);
653 test.Printf(_L("#~TS_Timing_%d,%d=%d\n"), gTestHarness, gTestCase, timeTaken.Int());
658 /** Times the system when opening a file with multiple clients accessing the directory
659 Precondition: This test expects the drive already filled with files
661 @param aSelector Configuration in case of manual execution
663 LOCAL_C TInt TestOpenEntryMultipleClients(TAny* aSelector)
669 TTimeIntervalSeconds timeTaken;
673 test.Printf(_L("#~TS_Title_%d,%d: Find entry mult clients accessing same directory, RFile::Open \n"), gTestHarness, gTestCase);
674 startTime.HomeTime();
678 while(i <= KMaxFiles)
680 if(i == 100 || i == 1000 || i == 5000 || i == 10000)
681 FindFileM2(i, testStep++);
688 r = endTime.SecondsFrom(startTime, timeTaken);
690 test.Printf(_L("#~TS_Timing_%d,%d=%d\n"), gTestHarness, gTestCase, timeTaken.Int());
695 /** Times the system when opening a file with multiple clients accessing dif directory
696 Precondition: This test expects the drive already filled with files
698 @param aSelector Configuration in case of manual execution
700 LOCAL_C TInt TestOpenEntryMultipleClientsDD(TAny* aSelector)
706 TTimeIntervalSeconds timeTaken;
710 test.Printf(_L("#~TS_Title_%d,%d: Find entry mult clients accessing dif directory, TFindFile\n"), gTestHarness, gTestCase);
711 startTime.HomeTime();
714 while(i <= KMaxFiles)
716 if(i == 100 || i == 1000 || i == 5000 || i == 10000)
717 FindFileMD1(i, testStep++);
724 r = endTime.SecondsFrom(startTime, timeTaken);
726 test.Printf(_L("#~TS_Timing_%d,%d=%d\n"), gTestHarness, gTestCase, timeTaken.Int());
729 test.Printf(_L("#~TS_Title_%d,%d: Find entry mult clients accessing dif directory, RFile::Open \n"), gTestHarness, gTestCase);
730 startTime.HomeTime();
734 while(i <= KMaxFiles)
736 if(i == 100 || i == 1000 || i == 5000 || i == 10000)
737 FindFileMD2(i, testStep++);
744 r = endTime.SecondsFrom(startTime, timeTaken);
746 test.Printf(_L("#~TS_Timing_%d,%d=%d\n"), gTestHarness, gTestCase, timeTaken.Int());
751 /** It goes automatically through all the options
753 @param aSelector Configuration in case of manual execution
755 LOCAL_C TInt TestAll(TAny* aSelector)
759 TestOpenEntry(aSelector);
760 TestOpenEntryMultipleClients(aSelector);
761 TestOpenEntryMultipleClientsDD(aSelector);
769 GLDEF_C void CallTestsL()
771 TInt r = client.CreateLocal(0);
774 CSelectionBox* TheSelector = CSelectionBox::NewL(test.Console());
778 // Each test case of the suite has an identifyer for parsing purposes of the results
782 CreateDirWithNFiles(300, 3);
783 PrintHeaders(1, _L("t_fsropen. File Open"));
787 gSessionPath=_L("?:\\");
788 TCallBack createFiles(TestFileCreate, TheSelector);
789 TCallBack openFile(TestOpenEntry, TheSelector);
790 TCallBack openFileMC(TestOpenEntryMultipleClients, TheSelector);
791 TCallBack openFileMCDD(TestOpenEntryMultipleClientsDD, TheSelector);
792 TCallBack allOpen(TestAll,TheSelector);
793 TheSelector->AddDriveSelectorL(TheFs);
794 TheSelector->AddLineL(_L("Create all files"), createFiles);
795 TheSelector->AddLineL(_L("Open random file"), openFile);
796 TheSelector->AddLineL(_L("With mult clients same directory"), openFileMC);
797 TheSelector->AddLineL(_L("With mult clients dif large directories"), openFileMCDD);
798 TheSelector->AddLineL(_L("All options"), allOpen);
803 TestAll(TheSelector);
807 test.Printf(_L("#~TestEnd_%d\n"), gTestHarness);