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_fsrdirload.cpp
21 #include "..\server\t_server.h"
22 #include "t_benchmain.h"
25 GLDEF_D RTest test(_L("File Server Benchmarks, Dir Load"));
27 //----------------------------------------------------------------------------------------------
28 //! @SYMTestCaseID PBASE-T_FSRDIRLOAD-0273
31 //! @SYMTestCaseDesc This test case is measuring performance of the FAT implementation.
32 //! @SYMTestActions 0. Expects the files to exist in order to successful execution
33 //! 1. Time the listing of each directory sorted by name
34 //! 2. Time the listing of each directory sorted by extension
35 //! 3. Time the listing of each directory sorted by size
36 //! 4. Time the listing of each directory sorted by date
37 //! 5. Time the search of each file in a directory sorted by name
38 //! 6. Time the search of each file in a directory sorted by extension
39 //! 7. Time the search of each file in a directory sorted by size
40 //! 8. Time the search of each file in a directory sorted by date
42 //! @SYMTestExpectedResults Finishes if the system behaves as expected, panics otherwise
43 //! @SYMTestPriority High
44 //! @SYMTestStatus Implemented
45 //----------------------------------------------------------------------------------------------
48 LOCAL_D RSemaphore client;
49 LOCAL_D TRequestStatus stat;
50 LOCAL_D TBuf8<4096> buf;
52 LOCAL_D TDriveList gDriveList;
55 _LIT(KDirMultipleName2, "dir%d_%d\\");
57 /** Sort a directory with different criterias
59 @param aN Number of files in the directory
60 @param aKey Type of sorting to use
61 @param aStep Test step
63 LOCAL_C TInt SortFile(TInt aN, TEntryKey aKey, TInt aStep)
73 TTimeIntervalMicroSeconds timeTaken(0);
74 TInt timeTaken1 = -1, timeTaken2 = -1, timeTaken3 = -1;
84 temp.Format(KDirMultipleName2, 1, aN);
87 temp.Format(KDirMultipleName2, 2, aN);
90 temp.Format(KDirMultipleName2, 3, aN);
93 dir1.Append(_L("*.*"));
94 dir2.Append(_L("*.*"));
95 dir3.Append(_L("*.*"));
100 r = TheFs.GetDir(dir1,KEntryAttMaskSupported,ESortNone,dirPtr);
103 r = dirPtr->Sort(aKey);
109 timeTaken = endTime.MicroSecondsFrom(startTime);
110 timeTaken1 = I64LOW(timeTaken.Int64() / gTimeUnit);
115 startTime.HomeTime();
116 r = TheFs.GetDir(dir2,KEntryAttMaskSupported,ESortNone,dirPtr);
119 r = dirPtr->Sort(aKey);
123 timeTaken = endTime.MicroSecondsFrom(startTime);
125 timeTaken2 = I64LOW(timeTaken.Int64() / gTimeUnit);
130 startTime.HomeTime();
131 r = TheFs.GetDir(dir3,KEntryAttMaskSupported,ESortNone,dirPtr);
134 r = dirPtr->Sort(aKey);
138 timeTaken=endTime.MicroSecondsFrom(startTime);
139 timeTaken3 = I64LOW(timeTaken.Int64() / gTimeUnit);
144 PrintResult(aStep, 1, aN);
145 PrintResultTime(aStep, 2, timeTaken1);
146 PrintResultTime(aStep, 3, timeTaken2);
147 PrintResultTime(aStep, 4, timeTaken3);
152 /** Sort a directory with different type of files and find a particular one
154 @param aN Number of files in the directory
155 @param aKey Type of sorting to use
156 @param aStep Test step
158 LOCAL_C TInt SortFindFile(TInt aN, TEntryKey aKey, TInt aStep )
168 TTimeIntervalMicroSeconds timeTaken(0);
169 TInt timeTaken1 = -1, timeTaken2 = -1, timeTaken3 = -1;
171 if(aN <= gFilesLimit)
175 TBool found = EFalse;
181 temp.Format(KDirMultipleName2, 1, aN);
184 temp.Format(KDirMultipleName2, 2, aN);
187 temp.Format(KDirMultipleName2, 3, aN);
190 dir1.Append(_L("*.*"));
191 dir2.Append(_L("*.*"));
192 dir3.Append(_L("*.*"));
196 startTime.HomeTime();
197 r = TheFs.GetDir(dir1, KEntryAttMaskSupported, aKey, dirPtr);
202 while((i < dirPtr->Count()) && (!found))
204 TEntry e = (*dirPtr)[i];
205 if(e.iName == _L("last.txt")) found = ETrue;
212 timeTaken = endTime.MicroSecondsFrom(startTime);
213 timeTaken1 = I64LOW(timeTaken.Int64() / gTimeUnit);
218 startTime.HomeTime();
219 r = TheFs.GetDir(dir2, KEntryAttMaskSupported, aKey, dirPtr);
224 while((i < dirPtr->Count()) && (!found))
226 TEntry e = (*dirPtr)[i];
227 if(e.iName == _L("last.txt")) found = ETrue;
232 timeTaken = endTime.MicroSecondsFrom(startTime);
235 timeTaken2 = I64LOW(timeTaken.Int64() / gTimeUnit);
240 startTime.HomeTime();
241 r = TheFs.GetDir(dir3, KEntryAttMaskSupported, aKey, dirPtr);
246 while((i<dirPtr->Count()) && (!found))
248 TEntry e = (*dirPtr)[i];
249 if(e.iName == _L("last.txt")) found = ETrue;
254 timeTaken = endTime.MicroSecondsFrom(startTime);
255 timeTaken3 = I64LOW(timeTaken.Int64() / gTimeUnit);
260 PrintResult(aStep, 1, aN);
261 PrintResultTime(aStep, 2, timeTaken1);
262 PrintResultTime(aStep, 3, timeTaken2);
263 PrintResultTime(aStep, 4, timeTaken3);
269 /** Sort a directory and find a file opens it and reads first 4Kb and last 4Kb
271 @param aN Number of files in the directory
272 @param aKey Type of sorting to use
273 @param aStep Test step
275 LOCAL_C TInt SortFindFileAndOpen(TInt aN, TEntryKey aKey, TInt aStep )
285 TTimeIntervalMicroSeconds timeTaken(0);
286 TInt timeTaken1 = -1, timeTaken2 = -1, timeTaken3 = -1;
290 TBool found = EFalse;
293 if(aN <= gFilesLimit)
299 temp.Format(KDirMultipleName2, 1, aN);
302 temp.Format(KDirMultipleName2, 2, aN);
305 temp.Format(KDirMultipleName2, 3, aN);
308 dir1.Append(_L("*.*"));
309 dir2.Append(_L("*.*"));
310 dir3.Append(_L("*.*"));
315 startTime.HomeTime();
316 r = TheFs.GetDir(dir1, KEntryAttMaskSupported, aKey, dirPtr);
320 temp.Format(KDirMultipleName2, 1, aN);
322 dir1.Append(_L("LAST.TXT"));
326 while((i < dirPtr->Count()) && (!found))
328 TEntry e = (*dirPtr)[i];
329 if(e.iName == _L("LAST.TXT"))
341 file.Open(TheFs, dir1, EFileShareAny|EFileRead);
343 file.Seek(ESeekStart, pos);
346 pos = -4 * KOneK; // 4 KB before the end of the file
347 file.Seek(ESeekEnd, pos);
355 timeTaken = endTime.MicroSecondsFrom(startTime);
356 timeTaken1 = I64LOW(timeTaken.Int64() / gTimeUnit);
361 startTime.HomeTime();
362 r = TheFs.GetDir(dir2, KEntryAttMaskSupported, aKey, dirPtr);
366 temp.Format(KDirMultipleName2, 2, aN);
368 dir2.Append(_L("LAST.TXT"));
372 while((i < dirPtr->Count()) && (!found))
374 TEntry e = (*dirPtr)[i];
375 if(e.iName == _L("LAST.TXT"))
387 file.Open(TheFs, dir2, EFileShareAny|EFileRead);
389 file.Seek(ESeekStart, pos);
392 pos = -4 * KOneK; // 4 KB before the end of the file
393 file.Seek(ESeekEnd, pos);
398 timeTaken = endTime.MicroSecondsFrom(startTime);
402 timeTaken2 = I64LOW(timeTaken.Int64() / gTimeUnit);
407 startTime.HomeTime();
408 r = TheFs.GetDir(dir3, KEntryAttMaskSupported, aKey, dirPtr);
412 temp.Format(KDirMultipleName2, 3, aN);
414 dir3.Append(_L("LAST.TXT"));
418 while((i < dirPtr->Count()) && (!found))
420 TEntry e = (*dirPtr)[i];
421 if(e.iName == _L("LAST.TXT"))
431 file.Open(TheFs, dir3, EFileShareAny|EFileRead);
433 file.Seek(ESeekStart, pos);
436 pos = -4 * KOneK; // 4 KB before the end of the file
437 file.Seek(ESeekEnd, pos);
442 timeTaken = endTime.MicroSecondsFrom(startTime);
445 timeTaken3 = I64LOW(timeTaken.Int64() / gTimeUnit);
450 PrintResult(aStep, 1, aN);
451 PrintResultTime(aStep, 2, timeTaken1);
452 PrintResultTime(aStep, 3, timeTaken2);
453 PrintResultTime(aStep, 4, timeTaken3);
458 /** Times the directory listing sorted by name, extension, size and date
460 @param aSelector Configuration in case of manual execution
462 LOCAL_C TInt TestDirListing(TAny* aSelector)
469 test.Printf(_L("#~TS_Title_%d,%d: Directory listing sorted by name \n"), gTestHarness, gTestCase);
472 while(i <= KMaxFiles)
474 if(i == 100 || i == 1000 || i == 5000 || i == 10000)
476 SortFile(i, ESortByName, testStep++);
482 test.Printf(_L("#~TS_Title_%d,%d: Directory listing sorted by extension\n"), gTestHarness, gTestCase);
486 while(i <= KMaxFiles)
488 if(i == 100 || i == 1000 || i == 5000 || i == 10000)
490 SortFile(i, ESortByExt, testStep++);
496 test.Printf(_L("#~TS_Title_%d,%d: Directory listing sorted by size \n"), gTestHarness, gTestCase);
500 while(i <= KMaxFiles)
502 if(i == 100 || i == 1000 || i == 5000 || i == 10000)
504 SortFile(i, ESortBySize, testStep++);
510 test.Printf(_L("#~TS_Title_%d,%d: Directory listing sorted by date \n"), gTestHarness, gTestCase);
514 while(i <= KMaxFiles)
516 if(i == 100 || i == 1000 || i == 5000 || i == 10000)
518 SortFile(i, ESortByDate, testStep++);
527 /** Times the operations required to find a file ordering the list of files by orted by name,
528 extension, size and date
530 @param aSelector Configuration in case of manual execution
532 LOCAL_C TInt TestFindFile(TAny* aSelector)
539 test.Printf(_L("#~TS_Title_%d,%d: Find file when sorted by name \n"), gTestHarness, gTestCase);
543 while(i <= KMaxFiles)
545 if(i == 100 || i == 1000 || i == 5000 || i == 10000)
547 SortFindFile(i, ESortByName, testStep++);
553 test.Printf(_L("#~TS_Title_%d,%d: Find file when sorted by extension\n"), gTestHarness, gTestCase);
557 while(i <= KMaxFiles)
559 if(i == 100 || i == 1000 || i == 5000 || i == 10000)
561 SortFindFile(i, ESortByExt, testStep++);
567 test.Printf(_L("#~TS_Title_%d,%d: Find file when sorted by size \n"), gTestHarness, gTestCase);
571 while(i <= KMaxFiles)
573 if(i == 100 || i == 1000 || i == 5000 || i == 10000)
575 SortFindFile(i, ESortBySize, testStep++);
581 test.Printf(_L("#~TS_Title_%d,%d: Find file when sorted by date \n"), gTestHarness, gTestCase);
585 while(i <= KMaxFiles)
587 if(i == 100 || i == 1000 || i == 5000 || i == 10000)
589 SortFindFile(i, ESortByDate, testStep++);
599 /** Times the opening of a file and read of the first 4 Kb when sorted by name,
600 extension, size and date
602 @param aSelector Configuration in case of manual execution
604 LOCAL_C TInt TestOpenReadFile(TAny* aSelector)
611 test.Printf(_L("#~TS_Title_%d,%d: Open and read file when sorted by name \n"), gTestHarness, gTestCase);
615 while(i <= KMaxFiles)
617 if(i == 100 || i == 1000 || i == 5000 || i == 10000)
619 SortFindFileAndOpen(i, ESortByName, testStep++);
625 test.Printf(_L("#~TS_Title_%d,%d: Open and read file when sorted by extension\n"), gTestHarness, gTestCase);
629 while(i <= KMaxFiles)
631 if(i == 100 || i == 1000 || i == 5000 || i == 10000)
633 SortFindFileAndOpen(i, ESortByExt, testStep++);
639 test.Printf(_L("#~TS_Title_%d,%d: Open and read when sorted by size \n"), gTestHarness, gTestCase);
643 while(i <= KMaxFiles)
645 if(i == 100 || i == 1000 || i == 5000 || i == 10000)
647 SortFindFileAndOpen(i, ESortBySize, testStep++);
653 test.Printf(_L("#~TS_Title_%d,%d: Open and read file when sorted by date \n"), gTestHarness, gTestCase);
657 while(i <= KMaxFiles)
659 if(i == 100 || i == 1000 || i == 5000 || i == 10000)
661 SortFindFileAndOpen(i, ESortByDate, testStep++);
670 /** It goes automatically through all the options
672 @param aSelector Configuration in case of manual execution
674 LOCAL_C TInt TestAll(TAny* aSelector)
678 TestDirListing(aSelector);
679 TestFindFile(aSelector);
680 TestOpenReadFile(aSelector);
688 GLDEF_C void CallTestsL()
690 TInt r = client.CreateLocal(0);
693 CSelectionBox* TheSelector = CSelectionBox::NewL(test.Console());
697 // Each test case of the suite has an identifyer for parsing purposes of the results
701 PrintHeaders(1, _L("t_fsrdirload. Directory loading"));
705 gSessionPath = _L("?:\\");
706 TCallBack createFiles(TestFileCreate,TheSelector);
707 TCallBack dirListFile(TestDirListing,TheSelector);
708 TCallBack findFile(TestFindFile,TheSelector);
709 TCallBack openReadFile(TestOpenReadFile,TheSelector);
710 TCallBack allFile(TestAll,TheSelector);
711 TheSelector->AddDriveSelectorL(TheFs);
712 TheSelector->AddLineL(_L("Create all files"),createFiles);
713 TheSelector->AddLineL(_L("Directory listings"),dirListFile);
714 TheSelector->AddLineL(_L("Find file in the listing"),findFile);
715 TheSelector->AddLineL(_L("Open and read first and last 4KB "),openReadFile);
716 TheSelector->AddLineL(_L("Three last options together"),allFile);
721 TestAll(TheSelector);
725 test.Printf(_L("#~TestEnd_%d\n"), gTestHarness);