First public contribution.
1 // Copyright (c) 1996-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 // File Name: f32test/bench/t_fat_perf.cpp
15 // This file contains implementation for the functions called
16 // by test cases from the command line to test FAT Performance on
17 // large number of files (PREQ 1885).
26 #include "t_fat_perf.h"
30 LOCAL_C void ClearCache(TInt);
32 RTest test(_L("T_FAT_PERF"));
35 TFileName gFileNameBase;
39 TInt gZeroPadFileNumberForFixedLengthFileNames = 0;
42 //-----------------------------------------------------------------------------
44 TNamingSchemeParam::TNamingSchemeParam()
45 : iConOrRan(EConsecutive), iUniOrAsc(EAscii), iZeroPadFileNumber(EFalse), iMaxFileNameLength(0), iMinStringLength(0)
47 iFileNameBase = _L("");
50 //-----------------------------------------------------------------------------
52 This function creates the files in the following directories
53 INITIAL CONDITION: FILL FOLLOWING SUB-DIRS WITH 1600 FILES
54 "\\DIR1\\"...2000 files ("ABCD1ABCD2ABCD3ABCD4ABCD5ABCD_1 ~ 2000.TXT")
55 "\\DIR1\\DIR11\\"...1600 files ("ABCD1ABCD2ABCD3ABCD4ABCD5ABCD_1 ~ 1600.TXT")
56 "\\DIR1\\DIR11\\DIR111\\"...1610 files ("ABCD1ABCD2ABCD3ABCD4ABCD5ABCD_1 ~ 1600.TXT") + "ANOTHERLONGFILENAME_1~10.TXT"
57 "\\DIR1\\DIR12RAN\\"...1600 files ("...random string (31~34)....TXT")
58 "\\DIR2\\"...1600 files ("ABCD1ABCD2ABCD3ABCD4ABCD5ABCD_1 ~ 1600.TXT")
60 //-----------------------------------------------------------------------------
62 LOCAL_C void DoTestCaseSetup()
64 test.Next(_L(" 'Test Setup' - 00"));
66 TMLUnitParam mlParam =
70 CMeasureAndLogUnit* measureAndLogUnit = CMeasureAndLogUnit::NewLC(mlParam);
71 CExecutionUnit* execUnit = CExecutionUnit::NewLC(measureAndLogUnit, gDriveToTest);
74 TInt err = TheFs.CharToDrive(gDriveToTest, curDriveNum);
75 test(KErrNone == err);
76 FormatFatDrive(TheFs,curDriveNum, EQuickFormat, NULL, EFalse);
78 /*-----------------------------------------------------------------------------
79 * Setup for "\\DIR1\\"
80 *-----------------------------------------------------------------------------*/
82 TNamingSchemeParam namingScheme;
83 namingScheme.iConOrRan = EConsecutive;
84 namingScheme.iUniOrAsc = EAscii;
85 namingScheme.iZeroPadFileNumber = EFalse;
86 namingScheme.iFileNameBase = _L("ABCD1ABCD2ABCD3ABCD4ABCD5ABCD_");
87 namingScheme.iMaxFileNameLength = 0;
88 namingScheme.iMinStringLength = 0;
90 TDirUnitParam dirParam1;
91 dirParam1.iPriority = 1;
92 dirParam1.iDirName = _L("?:\\DIR1\\");
94 dirParam1.iFilesPerRun = 2000;
95 dirParam1.iSampleInterval = 0;
96 dirParam1.iNamingScheme = namingScheme;
97 dirParam1.iFileOpMode = EFATPerfFileCreate;
99 execUnit->AddDirUnitL(dirParam1);
101 /*-----------------------------------------------------------------------------
102 * Setup for "\\DIR1\\DIR11\\"
103 *-----------------------------------------------------------------------------*/
105 TDirUnitParam dirParam11 = dirParam1;
106 dirParam11.iDirName = _L("?:\\DIR1\\DIR11\\");
107 dirParam11.iFilesPerRun = 1600;
108 dirParam11.iSampleInterval = 0;
110 execUnit->AddDirUnitL(dirParam11);
112 /*-----------------------------------------------------------------------------
113 * Setup for "\\DIR1\\DIR11\\DIR111\\"
114 *-----------------------------------------------------------------------------*/
116 TDirUnitParam dirParam111 = dirParam1;
117 dirParam111.iDirName = _L("?:\\DIR1\\DIR11\\DIR111\\");
118 dirParam111.iFilesPerRun = 1600;
119 dirParam111.iSampleInterval = 0;
121 execUnit->AddDirUnitL(dirParam111);
123 /*-----------------------------------------------------------------------------
124 * Test setup for "\\DIR1\\DIR11\\DIR111\\" with "ANOTHERLONGFILENAME_" file
125 *-----------------------------------------------------------------------------*/
127 TNamingSchemeParam namingScheme111A = namingScheme;
128 namingScheme111A.iFileNameBase = _L("ANOTHERLONGFILENAME_");
130 TDirUnitParam dirParam111A = dirParam1;
131 dirParam111A.iDirName = _L("?:\\DIR1\\DIR11\\DIR111\\");
132 dirParam111A.iFilesPerRun = 10;
133 dirParam111A.iSampleInterval = 0;
134 dirParam111A.iNamingScheme = namingScheme111A;
136 execUnit->AddDirUnitL(dirParam111A);
138 /*-----------------------------------------------------------------------------
139 * Setup for "\\DIR1\\DIR12RAN\\"
140 *-----------------------------------------------------------------------------*/
142 TNamingSchemeParam namingScheme12 = namingScheme;
143 namingScheme12.iConOrRan = ERandom;
144 namingScheme12.iZeroPadFileNumber = EFalse;
145 namingScheme12.iFileNameBase = _L("");
146 namingScheme12.iMaxFileNameLength = 34;
147 namingScheme12.iMinStringLength = 31;
149 TDirUnitParam dirParam12 = dirParam1;
150 dirParam12.iDirName = _L("?:\\DIR1\\DIR12RAN\\");
151 dirParam12.iFilesPerRun = 1600;
152 dirParam12.iSampleInterval = 0;
153 dirParam12.iNamingScheme = namingScheme12;
155 execUnit->AddDirUnitL(dirParam12);
157 /*-----------------------------------------------------------------------------
158 * Setup for "\\DIR2\\"
159 *-----------------------------------------------------------------------------*/
161 TDirUnitParam dirParam2 = dirParam1;
162 dirParam2.iDirName = _L("?:\\DIR2\\");
163 dirParam2.iFilesPerRun = 1600;
164 dirParam2.iSampleInterval = 0;
165 dirParam2.iNamingScheme = namingScheme;
167 execUnit->AddDirUnitL(dirParam2);
170 CleanupStack::PopAndDestroy(2);
173 //-----------------------------------------------------------------------------
175 This function creates a files in the valid directory path
177 //-----------------------------------------------------------------------------
178 LOCAL_C void DoTestCaseCreateFile()
180 test.Next(_L(" 'Create File' - 01"));
182 TMLUnitParam mlParam =
186 CMeasureAndLogUnit* measureAndLogUnit = CMeasureAndLogUnit::NewLC(mlParam);
187 CExecutionUnit* execUnit = CExecutionUnit::NewLC(measureAndLogUnit, gDriveToTest);
189 ClearCache(gCacheClear);
191 TNamingSchemeParam namingScheme;
192 namingScheme.iZeroPadFileNumber = gZeroPadFileNumberForFixedLengthFileNames;
194 TDirUnitParam dirParam1;
195 dirParam1.iPriority = 1;
196 dirParam1.iDirName = _L("");
198 dirParam1.iFilesPerRun = 0;
199 dirParam1.iSampleInterval = 1;
200 dirParam1.iNamingScheme = namingScheme;
201 dirParam1.iFileOpMode = EFATPerfFileCreate;
204 TFileName path = _L("?:\\");
206 if (path[path.Length() - 1] != '\\')
211 dirParam1.iDirName = path;
212 dirParam1.iFilesPerRun = gFileNo;
213 dirParam1.iNamingScheme.iFileNameBase = gFileNameBase;
215 execUnit->AddDirUnitL(dirParam1);
218 CleanupStack::PopAndDestroy(2);
222 //-----------------------------------------------------------------------------
224 This function opens file in the valid directoy path
226 //-----------------------------------------------------------------------------
228 LOCAL_C void DoTestCaseOpenFile()
230 test.Next(_L(" 'Open File' - 02"));
232 TMLUnitParam mlParam =
236 CMeasureAndLogUnit* measureAndLogUnit = CMeasureAndLogUnit::NewLC(mlParam);
237 CExecutionUnit* execUnit = CExecutionUnit::NewLC(measureAndLogUnit, gDriveToTest);
239 ClearCache(gCacheClear);
241 TNamingSchemeParam namingScheme;
242 namingScheme.iZeroPadFileNumber = gZeroPadFileNumberForFixedLengthFileNames;
244 TDirUnitParam dirParam1;
245 dirParam1.iPriority = 1;
246 dirParam1.iDirName = _L("");
248 dirParam1.iFilesPerRun = 0;
249 dirParam1.iSampleInterval = 1;
250 dirParam1.iNamingScheme = namingScheme;
251 dirParam1.iFileOpMode = EFATPerfFileOpen;
254 TFileName path = _L("?:\\");
256 if (path[path.Length() - 1] != '\\')
261 dirParam1.iDirName = path;
262 dirParam1.iFilesPerRun = gFileNo;
263 dirParam1.iNamingScheme.iFileNameBase = gFileNameBase;
265 execUnit->AddDirUnitL(dirParam1);
268 CleanupStack::PopAndDestroy(2);
272 //-----------------------------------------------------------------------------
274 This function deletes the files in the valid directory path
276 //-----------------------------------------------------------------------------
278 LOCAL_C void DoTestCaseDeleteFile()
280 test.Next(_L(" 'Delete File' - 03"));
282 TMLUnitParam mlParam =
286 CMeasureAndLogUnit* measureAndLogUnit = CMeasureAndLogUnit::NewLC(mlParam);
287 CExecutionUnit* execUnit = CExecutionUnit::NewLC(measureAndLogUnit, gDriveToTest);
289 ClearCache(gCacheClear);
291 TNamingSchemeParam namingScheme;
292 namingScheme.iZeroPadFileNumber = gZeroPadFileNumberForFixedLengthFileNames;
294 TDirUnitParam dirParam1;
295 dirParam1.iPriority = 1;
296 dirParam1.iDirName = _L("");
298 dirParam1.iFilesPerRun = 0;
299 dirParam1.iSampleInterval = 1;
300 dirParam1.iNamingScheme = namingScheme;
301 dirParam1.iFileOpMode = EFATPerfFileDelete;
303 TFileName path = _L("?:\\");
305 if (path[path.Length() - 1] != '\\')
310 dirParam1.iDirName = path;
311 dirParam1.iFilesPerRun = gFileNo;
312 dirParam1.iNamingScheme.iFileNameBase = gFileNameBase;
314 execUnit->AddDirUnitL(dirParam1);
317 CleanupStack::PopAndDestroy(2);
321 //-----------------------------------------------------------------------------
323 PREQ1885 - optional test case
324 This function writes data into the files in the valid directory path
326 //-----------------------------------------------------------------------------
328 LOCAL_C void DoTestCaseWriteFile()
330 test.Next(_L(" 'Write File' - 04 - Write 4KB of Data"));
332 TMLUnitParam mlParam =
336 CMeasureAndLogUnit* measureAndLogUnit = CMeasureAndLogUnit::NewLC(mlParam);
337 CExecutionUnit* execUnit = CExecutionUnit::NewLC(measureAndLogUnit, gDriveToTest);
339 ClearCache(gCacheClear);
341 TNamingSchemeParam namingScheme;
342 namingScheme.iZeroPadFileNumber = gZeroPadFileNumberForFixedLengthFileNames;
344 TDirUnitParam dirParam1;
345 dirParam1.iPriority = 1;
346 dirParam1.iDirName = _L("");
348 dirParam1.iFilesPerRun = 0;
349 dirParam1.iSampleInterval = 1;
350 dirParam1.iNamingScheme = namingScheme;
351 dirParam1.iFileOpMode = EFATPerfFileWrite;
353 TFileName path = _L("?:\\");
355 if (path[path.Length() - 1] != '\\')
360 dirParam1.iDirName = path;
361 dirParam1.iFilesPerRun = gFileNo;
362 dirParam1.iNamingScheme.iFileNameBase = gFileNameBase;
364 execUnit->AddDirUnitL(dirParam1);
367 CleanupStack::PopAndDestroy(2);
371 //-----------------------------------------------------------------------------
373 PREQ1885 - optional test case
374 This function Reads data from the files in the valid directory path
376 //-----------------------------------------------------------------------------
378 LOCAL_C void DoTestCaseReadFile()
380 test.Next(_L(" 'Read File' - 05 Read 4KB of data"));
382 TMLUnitParam mlParam =
386 CMeasureAndLogUnit* measureAndLogUnit = CMeasureAndLogUnit::NewLC(mlParam);
387 CExecutionUnit* execUnit = CExecutionUnit::NewLC(measureAndLogUnit, gDriveToTest);
389 ClearCache(gCacheClear);
391 TNamingSchemeParam namingScheme;
392 namingScheme.iZeroPadFileNumber = gZeroPadFileNumberForFixedLengthFileNames;
394 TDirUnitParam dirParam1;
395 dirParam1.iPriority = 1;
396 dirParam1.iDirName = _L("");
398 dirParam1.iFilesPerRun = 0;
399 dirParam1.iSampleInterval = 1;
400 dirParam1.iNamingScheme = namingScheme;
401 dirParam1.iFileOpMode = EFATPerfFileRead;
404 TFileName path = _L("?:\\");
406 if (path[path.Length() - 1] != '\\')
411 dirParam1.iDirName = path;
412 dirParam1.iFilesPerRun = gFileNo;
413 dirParam1.iNamingScheme.iFileNameBase = gFileNameBase;
415 execUnit->AddDirUnitL(dirParam1);
418 CleanupStack::PopAndDestroy(2);
422 //-----------------------------------------------------------------------------
424 This function Dumps the information about Directory Cache
427 LOCAL_C void DoTestCaseDirCacheInfo()
429 ClearCache(gCacheClear);
430 RDebug::Print(_L("Dumping DirCache Info - Only for DEBUG Mode \n"));
431 #if defined(_DEBUG) || defined(_DEBUG_RELEASE)
432 TInt ret = TheFs.ControlIo(CurrentDrive(), ETestFATDirCacheInfo); // For DirCache info
435 RDebug::Print(_L("RFs::ControlIo() returned %d when attempting to dump cache info"), ret);
437 ret = TheFs.ControlIo(CurrentDrive(), ETestDumpFATDirCache); // For Dumping DirCache contents
440 RDebug::Print(_L("RFs::ControlIo() returned %d when attempting to dump cache contents"), ret);
445 /* To clear the cache - remount drive */
447 LOCAL_C void ClearCache(TInt gCacheClear)
450 if (gCacheClear == 1)
452 // Remount the drive to clear the cache
453 rel = RemountFS (TheFs, CurrentDrive(), NULL);
456 RDebug::Print(_L("<<Error>>: Remounting: %d\n"), rel);
464 /* Function for command line arguments for the tests */
465 LOCAL_C void ParseMyCommandArguments()
468 User::CommandLine(cmd);
470 TPtrC token=lex.NextToken();
471 TFileName thisfile=RProcess().FileName();
472 if (token.MatchF(thisfile)==0)
474 token.Set(lex.NextToken());
476 test.Printf(_L("CLP=%S"),&token);
478 if(token.Length()!=0)
480 gDriveToTest=token[0];
481 gDriveToTest.UpperCase();
491 token.Set(lex.NextToken());
492 if (token.Compare(_L("-c")) == 0 || token.Compare(_L("-C")) == 0)
494 token.Set(lex.NextToken());
495 if (token.MatchF(_L("Setup"))==0)
498 gTestCase = EFATPerfSetup;
501 else if (token.MatchF(_L("Create"))==0)
504 gTestCase = EFATPerfCreate;
508 else if (token.MatchF(_L("Open"))==0)
511 gTestCase = EFATPerfOpen;
515 else if (token.MatchF(_L("Delete"))==0)
519 gTestCase = EFATPerfDelete;
523 else if (token.MatchF(_L("Write"))==0)
526 gTestCase = EFATPerfWrite;
530 else if (token.MatchF(_L("Read"))==0)
534 gTestCase = EFATPerfRead;
537 else if (token.MatchF(_L("Dumpinfo"))==0)
539 gTestCase = EFATPerfDirCacheInfo;
543 test.Printf(_L("Bad command syntax"));
548 if (token.Compare(_L("-p")) == 0 || token.Compare(_L("-P")) == 0)
550 token.Set(lex.NextToken());
551 if (token.Length() != 0)
557 test.Printf(_L("Bad command syntax"));
562 if (token.Compare(_L("-b")) == 0 || token.Compare(_L("-B")) == 0)
564 token.Set(lex.NextToken());
565 if (token.Length() != 0)
567 gFileNameBase = token;
571 test.Printf(_L("Bad command syntax"));
576 if (token.Compare(_L("-n")) == 0 || token.Compare(_L("-N")) == 0)
578 token.Set(lex.NextToken());
579 if (token.Length() != 0)
582 tokenLex.Assign(token);
589 test.Printf(_L("Bad command syntax"));
594 if (token.Compare(_L("-m")) == 0 || token.Compare(_L("-M")) == 0)
596 token.Set(lex.NextToken());
597 if (token.Length() != 0)
600 tokenLex.Assign(token);
607 test.Printf(_L("Bad command syntax"));
612 if (token.Compare(_L("-f")) == 0 || token.Compare(_L("-F")) == 0)
614 token.Set(lex.NextToken());
615 if (token.Length() != 0)
618 tokenLex.Assign(token);
621 gZeroPadFileNumberForFixedLengthFileNames = value;
625 test.Printf(_L("Bad command syntax"));
634 LOCAL_C void GetSystemInfo()
636 test.Next(_L("Get System Info"));
639 TInt err = TheFs.CharToDrive(gDriveToTest, drvNo);
640 test(err == KErrNone);
641 err = TheFs.FileSystemSubType(drvNo, fsName);
642 test(err == KErrNone);
643 test.Printf(_L("File System: [%S]\n"), &fsName);
644 TVolumeIOParamInfo ioParam;
645 err = TheFs.VolumeIOParam(drvNo, ioParam);
646 test(err == KErrNone);
647 test.Printf(_L("Sector Size: [%d Bytes]\n"), ioParam.iBlockSize);
648 test.Printf(_L("Cluster Size: [%d Bytes]\n"), ioParam.iClusterSize);
651 //-----------------------------------------------------------------------------
653 Main Function to call specific test features
655 //-----------------------------------------------------------------------------
659 //Interpreting Command Line Arguments
660 ParseMyCommandArguments();
663 // Get Drive Information
667 // Switch Case for Test Functions
681 DoTestCaseCreateFile();
688 DoTestCaseOpenFile();
695 DoTestCaseDeleteFile();
701 DoTestCaseWriteFile();
708 DoTestCaseReadFile();
711 // Print / Dump DirCache Info
712 case EFATPerfDirCacheInfo:
714 DoTestCaseDirCacheInfo();