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_benchmain.cpp
23 #include "t_benchmain.h"
27 TFileName gSessionPath;
28 TFileName gExeFileName(RProcess().FileName());
29 TInt gAllocFailOff=KAllocFailureOff;
30 TInt gAllocFailOn=KAllocFailureOff;
35 TInt gFormat = EFalse;
37 TInt gFileSize = 0; // In Kbytes
39 TInt gTestHarness = 0;
41 TInt gTimeUnit = 1000; // values: 1 - us, 1000 - ms, 1000000 - s
44 TChar gDriveToTest = ' ';
47 ////////////////////////////////////////////////////////////
48 // Template functions encapsulating ControlIo magic
52 TInt controlIo(RFs &fs, TInt drv, TInt fkn, C &c)
54 TPtr8 ptrC((TUint8 *)&c, sizeof(C), sizeof(C));
56 TInt r = fs.ControlIo(drv, fkn, ptrC);
61 /** Prints headers of FAT32 and File Cache benchmarking
63 @param aType type of test (FAT32 = 1/2 or File Cache = 3/4/5)
66 void PrintHeaders(TInt aType, TPtrC16 aTitle )
68 TBuf16<250> title = _L("#~TestTitle_%d: ");
71 title.Append(_L("\n"));
73 test.Printf(_L("#~TestId=%d\n"), gTestHarness);
74 test.Printf(title, gTestHarness);
75 test.Printf(_L("#~Report Variant: \n"));
76 test.Printf(_L("#~Report Description: \n"));
78 _LIT(KSeconds,"seconds");
79 _LIT(KMilliSecs,"milliseconds");
80 _LIT(KMicroSecs,"microseconds");
84 timeUnit.Set(KMicroSecs);
85 else if (gTimeUnit == 1000)
86 timeUnit.Set(KMilliSecs);
87 else if (gTimeUnit == 1000000)
88 timeUnit.Set(KSeconds);
91 test.Printf(_L("Please, check gTimeUnit value\n"));
97 { // All FAT32 tests but t_fsrrepeat
98 test.Printf(_L("#~TestParam_%d: MaxFiles=%d, type=%d, mode=%d, timeUnit=%S\n"), gTestHarness, gFilesLimit, gTypes, gMode, &timeUnit);
100 test.Printf(_L("#~TestRows_%d: 4\n"), gTestHarness);
101 test.Printf(_L("#~TestColumns_%d: 4, NFiles, 8_3, 20_chars, 50_50\n"), gTestHarness);
105 test.Printf(_L("#~TestParam_%d: MaxFiles=%d, type=%d, mode=%d, timeUnit=%S\n"), gTestHarness, gFilesLimit, gTypes, gMode, &timeUnit);
107 test.Printf(_L("#~TestRows_%d: 12\n"), gTestHarness);
108 test.Printf(_L("#~TestColumns_%d: 4, DirName, 1st, 2nd, 3rd\n"), gTestHarness);
111 { // Large sequential reads/writes
112 test.Printf(_L("#~TestParam_%d: mode=%d, timeUnit=%S\n"), gTestHarness, gMode, &timeUnit);
114 test.Printf(_L("#~TestRows_%d: 8\n"), gTestHarness);
115 test.Printf(_L("#~TestColumns_%d: 4, bsize, 100KB, 1MB, 10MB\n"), gTestHarness);
118 { // Small random reads/writes
119 test.Printf(_L("#~TestParam_%d: mode=%d, timeUnit=%S\n"), gTestHarness, gMode, &timeUnit);
121 test.Printf(_L("#~TestRows_%d: 11\n"), gTestHarness);
122 test.Printf(_L("#~TestColumns_%d: 8, bsize, 1KB, 2KB, 4KB, 8KB, 16KB, 32KB, 64KB\n"), gTestHarness);
126 test.Printf(_L("#~TestParam_%d: mode=%d, timeUnit=%S\n"), gTestHarness, gMode, &timeUnit);
128 test.Printf(_L("#~TestRows_%d: 6\n"), gTestHarness);
129 test.Printf(_L("#~TestColumns_%d: 4, bsize, 5m_w, 15s_w_r, 15s_w_r \n"), gTestHarness);
133 test.Printf(_L("Check the function PrintHeaders() in t_benchmain.cpp, which wasn't called with the right parameters\n"));
139 /** Prints a line of results
141 @param aPosX Row of the table
142 @param aPosY Column of the table
143 @param aValue Value figure for that position
145 void PrintResultTime( TInt aPosX, TInt aPosY, TInt aValue)
147 test.Printf(_L("#~TS_Res_%d,%d,[%d,%d]=%d\n "), gTestHarness, gTestCase, aPosX, aPosY, aValue );
151 /** Prints any other type of data
153 @param aPosX Row of the table
154 @param aPosY Column of the table
155 @param aValue Value figure for that position
157 void PrintResult( TInt aPosX, TInt aPosY, TInt aValue)
159 test.Printf(_L("#~TS_Res_%d,%d,[%d,%d]=%d\n "), gTestHarness, gTestCase, aPosX, aPosY, aValue);
164 @param aPosX Row of the table
165 @param aPosY Column of the table
166 @param aValue Value figure for that position
168 void PrintResultS( TInt aPosX, TInt aPosY, TDes16& aValue)
170 TBuf16<250> buffer = _L("#~TS_Res_%d,%d,[%d,%d]=");
172 buffer.Append(aValue);
173 buffer.Append(_L("\n"));
174 test.Printf(buffer, gTestHarness, gTestCase, aPosX, aPosY);
177 /** Call all RFormat methods
179 @param aDrive Drive to be formatted
181 void FormatFat(TDriveUnit aDrive)
184 TPckgBuf<TInt> count;
185 TInt r = format.Open(TheFs, aDrive.Name(), EQuickFormat, count());
188 test(count() == 100);
189 TRequestStatus status;
192 format.Next(count, status);
193 User::WaitForRequest(status);
194 test(status == KErrNone || status == KErrNotSupported);
198 test.Printf(_L("Drive formatted\n"));
201 /** Validates the drive selection
203 @param aDrive Drive to be validated
204 @param aTest Type of test
206 TInt ValidateDriveSelection(TDriveUnit aDrive,TSelectedTest aTest)
208 if ((aDrive == EDriveZ) || ((aDrive == EDriveC) && (aTest == ELocalDriveTest)))
210 test.Printf(_L("Test not available for this drive\n"));
211 test.Printf(_L("Press any key to continue...\n"));
212 return (KErrNotSupported);
218 /** Validates the selection for this tests and update appropriate variables
220 @param aSelector This object is meant to give information about what needs
221 to be tests in manual mode
223 TInt Validate(TAny* aSelector)
227 if (((CSelectionBox*)aSelector)->CurrentKeyPress() != EKeyEnter)
230 TInt r = ValidateDriveSelection(((CSelectionBox*)aSelector)->CurrentDrive(),EFileSeekTest);
231 if (r == KErrNotSupported)
234 TDriveUnit drive = ((CSelectionBox*)aSelector)->CurrentDrive();
235 gSessionPath[0] = TUint8('A' + drive);
236 r = TheFs.SetSessionPath(gSessionPath);
243 /** Prints current volume information
251 r = TheFs.Volume(volInfo);
254 test.Printf(_L("DriveAtt:0x%X, MediaAtt:0x%X, Free:%d KBytes\n"), volInfo.iDrive.iDriveAtt, volInfo.iDrive.iMediaAtt, (TUint32)(volInfo.iFree / 1024));
257 /** Create directory with a number of files, with specified file name type
259 @param aN number of files to create
260 @param aType file names type : 1 - 8.3, 2 - 20 characters, 3 - 50/50
262 TInt CreateDirWithNFiles(TInt aN, TInt aType)
267 TBuf16<50> directory;
271 TBuf16<50> buffer(50);
273 dirtemp.Format(KDirMultipleName,aType, aN);
274 directory=gSessionPath;
275 directory.Append(dirtemp);
277 r = TheFs.MkDir(directory);
278 test(r == KErrNone || r == KErrAlreadyExists);
280 const TUint KNumFilesPrintTreshold = 100;
281 const TInt KFileSize = gFileSize * 1024;
288 // generate file name depending on type required
291 case 1: // 8.3 filemnames
292 FileNamesGeneration(buffer, 8, i, i%3+1);
295 case 2: // 20 characrer filenames
296 FileNamesGeneration(buffer, 20, i, i%3+1);
301 FileNamesGeneration(buffer, 8, i, i%3+1) ;
303 FileNamesGeneration(buffer, 20, i, i%3+1) ;
312 // create or replace a file
313 r = file.Replace(TheFs, path, EFileShareAny|EFileWrite);
317 test.Printf(_L("Error creating file: %S, %d\n"), &path, r);
321 // set file size if required, file contents doesn't matter
324 r = file.SetSize(KFileSize);
328 test.Printf(_L("Error setting file size: %S, %d, err:%d\n"), &path, KFileSize, r);
335 if(i > 0 && ((i+1)%KNumFilesPrintTreshold) == 0)
337 test.Printf(_L("created %d files, type:%d\n"), i + 1, aType);
344 // write "last.txt" file to the end of directory
346 path.Append(KCommonFile);
347 r = file.Replace(TheFs,path,EFileShareAny|EFileWrite);
351 test.Printf(_L("Error creating file: %S, %d\n"), &path, r);
355 // put random content to the "last.txt" file if specified length of files > 0
358 r = file.SetSize(gFileSize * 1024); // gFileSize is in KBytes
362 test.Printf(_L("Error setting file size: %S, %d\n"), &path, r);
374 Creates 12 directories with different sort of files and namefiles
375 100 files with 8.3, 20 chars and 50/50
376 1000 files with 8.3, 20 chars and 50/50
377 5000 files with 8.3, 20 chars and 50/50
378 10000 files with 8.3, 20 chars and 50/50
380 TInt TestFileCreate(TAny* aSelector)
386 while(i <= gFilesLimit)
392 CreateDirWithNFiles(100, j++);
398 CreateDirWithNFiles(1000, j++);
404 CreateDirWithNFiles(5000, j++);
410 CreateDirWithNFiles(10000, j++);
418 /** Generate a filename according to the parameters configuration
420 @param aBuffer Buffer where the name of the file will be returned
421 @param aLong Length of the name of the file
422 @param aPos Number to be attached to the name of the file
423 @param ext Type of extension (1/2/3)
425 void FileNamesGeneration(TDes16& aBuffer, TInt aLong, TInt aPos,TInt ext)
432 tempbuf.Format(KNumber, aPos);
433 padding = aLong - tempbuf.Size() / 2;
441 _LIT(KExtension1, ".TXT");
442 _LIT(KExtension2, ".HTM");
443 _LIT(KExtension3, ".LOG");
445 aBuffer.Append(tempbuf);
448 case 1: aBuffer.Append(KExtension1);break;
449 case 2: aBuffer.Append(KExtension2);break;
450 case 3: aBuffer.Append(KExtension3);break;
451 default: aBuffer.Append(KExtension1);break;
455 /** Do a checkdisk and report failure
460 test.Next(_L("Check Disk"));
461 TInt r = TheFs.CheckDisk(gSessionPath);
462 if (r != KErrNone && r != KErrNotSupported && r != KErrPermissionDenied)
463 ReportCheckDiskFailure(r);
466 /** Report a disk failure
468 @param aRet The error will be returned in this variable
470 void ReportCheckDiskFailure(TInt aRet)
472 test.Printf(_L("CHECKDISK FAILED: "));
475 case 1: test.Printf(_L("File cluster chain contains a bad value (<2 or >maxCluster)\n")); break;
476 case 2: test.Printf(_L("Two files are linked to the same cluster\n")); break;
477 case 3: test.Printf(_L("Unallocated cluster contains a value != 0\n")); break;
478 case 4: test.Printf(_L("Size of file != number of clusters in chain\n")); break;
479 default: test.Printf(_L("Undefined Error value %d\n"),aRet);
484 /** Expand the cleanup stack
492 CleanupStack::PushL((CBase*)NULL);
494 CleanupStack::Pop(1000);
497 /** Do testing on aDrive
499 @param aDrive Drive for the testing
501 void DoTests(TInt aDrive)
504 gSessionPath=_L("?:\\");
506 TInt r = TheFs.DriveToChar(aDrive, driveLetter);
508 gSessionPath[0] = (TText)driveLetter;
509 r = TheFs.SetSessionPath(gSessionPath);
512 test.Printf(_L("DoTests() Session Path: %S\n"),&gSessionPath);
514 CheckMountLFFS(TheFs,driveLetter);
516 User::After(1000000);
518 r = TheFs.MkDirAll(gSessionPath);
519 if (r != KErrNone && r != KErrAlreadyExists)
521 test.Printf(_L("MkDirAll() r %d\n"),r);
524 TheFs.ResourceCountMarkStart();
525 TRAP(r,CallTestsL());
527 TheFs.ResourceCountMarkEnd();
530 test.Printf(_L("Error: Leave %d\n"),r);
537 /** Syntax of the test
539 @param aOption option 1 is related to FAT32 testing/option 2 relates to the file caching
541 void syntax (TInt aOption)
543 _LIT(KBad, "Wrong argument");
547 test.Printf(_L("Usage: \n testname <drive> <100/1000/5000/10000 number of files> <1/2/3 type of files> <mode 0 manual, 1 automatic>\n "));
549 else if (aOption == 2)
551 test.Printf(_L("Usage: \n t_fcachebm <drive> <mode 0 manual, 1 automatic>\n "));
554 User::Panic(KBad,KErrArgument);
560 1) t_name drive maxfiles filetypes manual/automatic
561 maxfiles can be: 100, 1000, 5000 or 10000
562 filetypes can be 1 for 8.3, 2 for 20 chars as well and 3 for all
563 manual 0 and automatic 1
564 2) t_fcachebm drive manua/automatic
567 void ParseCommandArguments()
570 User::CommandLine(cmd);
572 test.Printf(_L("Command line:\n"));
574 test.Printf(_L("\n"));
580 TFileName thisfile=RProcess().FileName();
584 TBool finish = EFalse;
585 _LIT(KCacheBM, "Z:\\sys\\bin\\t_fcachebm.exe");
586 _LIT(KCreate, "Z:\\sys\\bin\\t_fsrcreatefiles.exe");
588 test.Printf(KCacheBM);
589 test.Printf(thisfile);
590 while((!finish) && (i <= 5))
595 if((thisfile != KCacheBM) && (thisfile != KCreate)) // FAT32 tests
597 else if(thisfile == KCreate) // FAT32 test files creation
599 else // File Cache (PREQ914) performance tests
603 test.Printf(_L("\nCLP=%S\n"), &token);
604 if(token.Length() != 0)
606 gDriveToTest = token[0];
607 gDriveToTest.UpperCase();
609 gSessionPath[0] = (TText)gDriveToTest;
617 if((testcase == 1) || (testcase == 3)) // testcase == 1 || testcase == 3
619 if(token.Length() != 0)
621 test.Printf(_L("Number of files=%S\n"),&token);
627 if(token[0] == '1' && token.Length() == 3) gFilesLimit = 100;
628 else if(token[0] == '1' && token.Length() == 4) gFilesLimit = 1000;
629 else if(token[0] == '1' && token.Length() == 5) gFilesLimit = 10000;
630 else syntax(testcase);
633 gFilesLimit = 10000 ;
636 else // (testcase == 2)
638 if(token.Length() == 1)
641 test.Printf(_L("0 manual/1 automatic ? %S\n"),&token);
642 if(c.IsDigit() && ((c == '0') || (c == '1')))
643 gMode = c.GetNumericValue();
644 else syntax(testcase);
651 if((testcase == 1) || (testcase == 3))
653 if(token.Length() == 1)
656 test.Printf(_L("File type=%S\n"), &token);
657 if(c.IsDigit() &&((c == '1') || (c == '2') || (c == '3')))
658 gTypes = c.GetNumericValue();
659 else syntax(testcase);
661 else // Default value
666 if((testcase == 1) || (testcase == 3))
669 if(token.Length() == 1)
671 test.Printf(_L("0 manual/1 automatic ? %S\n"),&token);
672 if(c.IsDigit() && ((c == '0') || (c == '1')))
673 gMode = c.GetNumericValue();
685 gFileSize = c.GetNumericValue();
694 token.Set(lex.NextToken());
701 @return KErrNone if everything was ok, panics otherwise
705 CTrapCleanup* cleanup;
706 cleanup = CTrapCleanup::New();
707 TRAPD(r,PushLotsL());
711 test.Start(_L("Starting benchmarking tests..."));
713 ParseCommandArguments(); //need this for drive letter to test and all the parameters
717 TheFs.SetAllocFailure(gAllocFailOn);
721 TheFs.SessionPath(sessionp);
725 r = TheFs.CharToDrive(gDriveToTest,theDrive);
728 PrintDrvInfo(TheFs, theDrive);
730 #if defined(_DEBUG) || defined(_DEBUG_RELEASE)
731 TPckgBuf<TIOCacheValues> pkgOrgValues;
732 TIOCacheValues& orgValues=pkgOrgValues();
733 r = controlIo(TheFs,theDrive, KControlIoCacheCount, orgValues);
736 test.Printf(_L("\nNumber of items on close list at beginning=%d\n"), orgValues.iCloseCount);
737 test.Printf(_L("Number of items on free list at beginning=%d\n"), orgValues.iFreeCount);
738 test.Printf(_L("Number of items allocated at beginning=%d\n"), orgValues.iAllocated);
745 TTimeIntervalSeconds timeTakenC;
746 r = endTimeC.SecondsFrom(timerC,timeTakenC);
751 FormatFat(gSessionPath[0]-'A');
754 test.Printf(_L("#~T_Timing_%d: %d S\n"), gTestHarness, timeTakenC.Int());
755 TheFs.SetAllocFailure(gAllocFailOff);
757 #if defined(_DEBUG) || defined(_DEBUG_RELEASE)
758 TPckgBuf<TIOCacheValues> pkgValues;
759 TIOCacheValues& values=pkgValues();
760 r = controlIo(TheFs,theDrive, KControlIoCacheCount, values);
763 test.Printf(_L("\nNumber of items on close list at end=%d\n"),values.iCloseCount);
764 test.Printf(_L("Number of items on free list at end=%d\n"),values.iFreeCount);
765 test.Printf(_L("Number of items allocated at the end=%d\n"),values.iAllocated);
767 test(orgValues.iCloseCount==values.iCloseCount);
768 test(orgValues.iAllocated == values.iAllocated);