Update contrib.
1 // Copyright (c) 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_notify_perf.h
19 #include <f32file_private.h>
26 // File operation made in test path to trigger notifications
27 enum TNotifyPerfTestOperations
30 EOpEnd, // indicates that a series of operations ended
38 EOpManyChanges, // Large number changes to a single file
39 EOpManyFiles, // Small changes to large number of files
41 // Directory Operations
47 EOpMixed // A series of mixed operations involving both Files and Dirs
52 //////////////////////////////////////////////////////
53 // Lowest 4 bit reserved for notification treads ID //
54 //////////////////////////////////////////////////////
56 // Test with a lot of filters for enhanced notification - 1st bit
57 // set - on; unset - off
60 // Whether perform full directory scan and save the file changes to a list - 2nd bit
61 // set - perform; unset - not perform
64 // Whether use big buffer for enhanced notification- 3rd bit
65 // Set - big buffer(no overflow); unset - small(could have overflow)
68 // For multi clients test. Enhanced Notification Only!
69 // Mode 1: set a variety of different notifications, same on each clients - 4th bit
72 // For multi clients test. Enhanced Notification Only!
73 // Mode 2: set a variety of different notifications, in which some are different on each clients,
74 // and some are same on each clients, only support upto 4 clients - 5th bit
77 ENotPerfTestReserved6 = 0x0200,
78 ENotPerfTestReserved7 = 0x0400,
79 ENotPerfTestReserved8 = 0x0800,
81 // Notification type - 13th - 16th bits
82 ENoNotify = 0x1000, // Test without notification
83 EEnhanced = 0x2000, // Using enhanced notification APIs
84 EOriginal = 0x4000, // Using original notification APIs
85 EPlugin = 0x8000, // Using Nokia plug-in for notification
88 // Note for Plugin Test
89 // the plugin test can only be run manually because the plugin is not available in KHS code base
91 // 1. enable the MACRO above in the mmp
92 // 2. get a S60 environment
93 // 3. copy the MdsFileServerPlugin.ptx from the release(\Winscw or \Armv5 depend on what kind of test you want to run)
94 // directory of S60 to the equivalent folder of release directory of your epoc32
95 // 4. when build a rom, include the MdsFileServerPlugin.ptx file in the rom
96 // 5. then you can run
101 EMdsFSPOpRegisterNotification,
102 EMdsFSPOpAddNotificationPath,
103 EMdsFSPOpRemoveNotificationPath,
104 EMdsFSPOpAddIgnorePath,
105 EMdsFSPOpRemoveIgnorePath,
106 EMdsFSPOpNotificationCancel,
115 TFileName iNewFileName;
119 enum TMdsFileEventType
131 typedef TPckgBuf<TMdsFSPStatus> TMdsFSPStatusPckg;
133 const TInt KMdsFSPluginPosition = 0x200071CD;
134 _LIT(KPluginName, "MdsFileServerPlugin");
136 // the list of operations to be conducted during a test case
137 const TUint KDefaultOpList[] = {EOpCreate, EOpReplace, EOpChgAttr, EOpRename, EOpWrite, EOpResize, EOpDelete, EOpEnd};
138 const TUint KDefaultOpListDir[] = {EOpCreateDir, EOpRenameDir, EOpDeleteDir, EOpEnd};
140 const TUint KManyChangesOpList[] = {EOpManyChanges, EOpManyChanges, EOpManyChanges, EOpManyChanges, EOpManyChanges, EOpEnd};
141 const TUint KManyFilesOpList[] = {EOpManyFiles, EOpManyFiles, EOpManyFiles, EOpManyFiles, EOpManyFiles, EOpEnd};
142 const TUint KMixedOpTestList[] = {EOpMixed, EOpMixed, EOpMixed, EOpMixed, EOpMixed, EOpEnd};
144 const TUint16 KNotifyOptionMask = 0xF000;
145 const TUint16 KNotifyTreadIdMask = 0x000F;
147 // default time scale for timer
148 const TUint KDefaultTimeScale = 1000; // 1ms
149 const TInt KMaxHeapSize = 0x1000000;
152 const TInt KNoThreadId = -1;
154 // a Controllor of whether measure time and write loggs;
155 extern TBool gPerfMeasure;
157 extern TFileName gTestPath;
158 extern TFileName gLogFilePath;
161 extern RArray<RThread> gNotiThreads;
162 extern RThread gFileThread;
164 extern TBuf<50> gLogPostFix;
166 //-------------------------------------------------------------
170 // a wrapper for test settings
176 TTestSetting(TInt aNumFiles, TInt aNumCli, TUint16 aOpt, const TUint* aOpList);
183 const TUint* iOperationList;
187 // a wrapper of parameters for the main thread to pass into notification thread or file operation thread
190 TTestSetting iSetting;
191 RSemaphore* iSmphFT; // Semophore used by File Thread for waiting for signals from Notification Threads
192 RSemaphore* iSmphNT; // Semophore used by Notification Threads for waiting for signals from File Thread
193 CTimerLogger* iLogger; // Logger used by Notification Threads;
194 RPointerArray<CTimerLogger>* iLoggerArray; // a pointer to an array of pointers to CTimmerLoggger
197 // This is the controller of the plugin, it's a simplified copy of the plugin engine used in S60 internally
198 class CMdsPluginControl : public RPlugin
201 inline void RegisterNotification( TMdsFSPStatusPckg& aMdsFSPStatus, TRequestStatus& aStat);
202 inline void AddNotificationPath( const TDesC& aPath );
203 inline void RemoveNotificationPath( const TDesC& aPath );
204 inline TInt Enable();
205 inline TInt Disable();
206 inline void NotificationCancel();
209 // timer class, also responsible for writing logs
210 class CTimerLogger : public CBase
214 static CTimerLogger* NewL(const TFileName& aLogFile);
216 inline TInt MeasureStart();
217 inline TInt MeasureEnd();
218 inline TBool Timing();
219 TInt Log(const TDesC& aDes, TBool aIsLine = ETrue);
220 TInt LogAndPrint(const TDesC& aDes, TBool aIsLine = ETrue);
221 TInt LogSettingDescription(const TInt aNumFile, const TInt aNumCli, const TUint16 aOption, TBool aNumOpVaries = EFalse);
222 TInt LogTestStepTime(TUint aOp, TInt aNum);
226 void ConstructL(const TFileName& aLogFile);
237 // the conductor of test cases
238 class CTestExecutor : public CBase
242 CTestExecutor(TTestSetting& aSetting);
245 inline void SetTestSetting(TTestSetting& aSetting);
246 inline void LogDescription();
249 static void KillAllTestThreads();
252 TTestSetting iTestSetting;
256 // This class performs file operations
257 class CFileOperator : public CBase
261 CFileOperator(const TTestSetting& aSetting, RPointerArray<CTimerLogger>& aLoggerArray, RSemaphore* aSmphFT, RSemaphore* aSmphNT);
276 void DoMixedOperationsL();
278 void DoManyChangesOnSingleFileL();
279 void DoSmallChangesOnManyFilesL();
281 void MesureStartsAll();
282 void WaitForSignalsAll();
284 void TestStepPrepare(TUint aOp);
285 void TestStepFinish(TUint aOp);
288 // test case will use the number iFirstFile and iNumFiles to generate test file names.
290 // if iFirstFile = 0 and iNumFiles = 100, the test files will be 0000.tst, 0001.tst ... 0099.tst
291 // if iFirstFile = 21 and iNumFiles = 200, the test files will be 0021.tst, 0022.tst ... 0220.tst
293 // When doing rename or replace test, the new names for test will be the biggest existing file
294 // number + 1 to the number + iNumFiles.
295 // As a result, in the case of if iFirstFile = 0 and iNumFiles = 100:
296 // The exsting files should be 0000.tst ... 0099.tst
297 // Rename or Replace test will use the new names 0100.tst ... 0199.tst to replace or rename the
301 // Number of files for operating.
302 // Note: in "Large number changes to a single file" case, this indicates the number of changes made on the single file.
306 const TUint* iCurrentOp;
308 RPointerArray<CTimerLogger> iLoggers;
309 RSemaphore* iSmphS; // Use for signaling Notification threads
310 RSemaphore* iSmphW; // Use for waiting signal from Notification threads
315 // an operator to monitor notification watcher and test stopper
316 class CNotifyOperator : public CBase
320 CNotifyOperator(const TTestSetting& aSetting, RSemaphore* aSmphFT, RSemaphore* aSmphNT, CTimerLogger* aLogger);
323 void StartOperationL();
326 void LogNotificationNumbers(TInt aNumNoti, TInt aNumIter, TInt aNumOverflow);
327 void LogTestResult(TInt aCounter, TInt aMeanCounter, TInt aOFCounter);
328 void TestChangeReport(TInt aNumChanges);
333 const TUint* iCurrentOp;
335 CTimerLogger* iLogger;
336 RSemaphore* iSmphS; // Use for signaling file operation thread
337 RSemaphore* iSmphW; // Use for waiting signal from file operation thread
340 // this class is responsible for handling notifications
341 class CNotifyWatcher : public CActive
343 friend class CNotifyOperator;
346 static CNotifyWatcher* NewL(TInt aNumFiles, TUint16 aOption, TUint aCurrentOp, CTimerLogger* aLogger);
352 void RequestNotification();
354 void Reset(TUint aOp);
357 CNotifyWatcher(TInt aNumFiles, TUint16 aOption, TUint aCurrentOp, CTimerLogger* aLogger);
360 void FullDirectoryScanL(RArray<TEntry>& aArray);
361 void MakeChangeRecordL(RArray<TEntry>& aArray);
362 TBool CompareEntry(const TEntry& aEntry1, const TEntry& aEntry2);
364 void AddLotsOfFilters();
366 void RequestNotificationEnhanced();
367 void RequestNotificationOriginal();
369 void HandleNotification(TBool aLastTime);
371 void HandleNotificationEnhanced(TBool aLastTime);
372 void HandleNotificationOriginal(TBool aLastTime);
374 void ResetMdsFSPStatus();
375 void RequestNotificationPlugin();
376 void HandleNotificationPlugin(TBool aLastTime);
381 TInt iOverflowCounter;
387 RArray<TEntry> iEntries;
388 RArray<TFileName> iRecords; // this is the output we produce
390 CTimerLogger* iLogger;
394 TMdsFSPStatusPckg iPluginStatusPkg;
395 CMdsPluginControl iPlugin;
400 // An AO aims for stopping the Active Scheduler when test finish
401 class CTestStopper : public CActive
411 void StartWaitingForFile();
414 TFileName iTestEndFile;
418 #include "t_notify_perf.inl"