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_util.cpp
18 #include "t_notify_perf.h"
24 while (count < gNotiThreads.Count())
26 gNotiThreads[count].Kill(KErrGeneral);
29 gFileThread.Kill(KErrGeneral);
32 // Safe way of checking in sub threads, it leaves when check fails, Main thread will catch the error and exit.
33 // if use test() directly in sub-threads, the threads may hang if check fails
34 void SafeTestL(TBool aResult, TInt aId, TInt aLine, TText* aFile)
40 RDebug::Print(_L("NotificationThread%02d: Failed check in %s at line %d"), aId, aFile, aLine);
42 else if (aId == KNoThreadId)
44 RDebug::Print(_L("Failed check in %s at line %d"), aFile, aLine);
46 CTestExecutor::KillAllTestThreads();
50 void SafeTestL(TInt aResult, TInt aExpected, TInt aId, TInt aLine, TText* aFile)
52 if (aResult != aExpected)
56 RDebug::Print(_L("NotificationThread%02d: Failed check in %s at line %d, expected %d, got %d"), aId, aFile, aLine, aExpected, aResult);
58 else if (aId == KNoThreadId)
60 RDebug::Print(_L("Failed check in %s at line %d, expected %d, got %d"), aFile, aLine, aExpected, aResult);
62 CTestExecutor::KillAllTestThreads();
71 gTestPath.Append(gDriveToTest);
72 gTestPath.Append(_L(":\\F32-TST\\T_Notify_Perf\\"));
75 gLogFilePath.Append(gDriveToTest);
77 gLogFilePath.Append((TChar)'C'); //If emulator lets stick it on C: (\epoc32\wisncw\c\)
80 gLogFilePath.Append(_L(":\\F32-TST\\NPTestLog\\"));
82 gLogFilePath.Append(_L(":\\F32-TST\\Temp\\"));
85 // Mapping from file operations to notification types
86 TUint OpNotifyMapping(TUint16& aOption, TInt aOperation)
88 if (aOption & EEnhanced)
94 return TFsNotification::ECreate;
98 return TFsNotification::ERename;
100 return TFsNotification::EAttribute;
105 return TFsNotification::EFileChange;
108 return TFsNotification::EDelete;
110 return (TUint) (TFsNotification::EAllOps & (~TFsNotification::EOverflow));
112 return (TUint) TFsNotification::EAllOps;
115 else if (aOption & EOriginal)
125 return ENotifyAttributes;
141 else if (aOption & EPlugin)
146 return EMdsFileCreated;
148 return EMdsFileReplaced;
150 return EMdsFileRenamed;
152 return EMdsFileDeleted;
154 return EMdsDirRenamed;
156 // All other operations are not testable
157 return EMdsFileUnknown;
163 // generate file names for testing
164 void FileNameGen(TFileName& aName, TInt aNum, TBool aIsFile = ETrue)
167 aName.Copy(gTestPath);
169 aName.AppendFormat(_L("%04d.tst"), aNum);
171 aName.AppendFormat(_L("DIR%04d\\"), aNum);
174 void ClearTestPathL()
176 RDebug::Print(_L("Clearing test path..."));
178 User::LeaveIfError(fs.Connect());
179 CFileMan* fm = CFileMan::NewL(fs);
180 TInt r = fm->RmDir(gTestPath);
181 test(r==KErrNone || r==KErrPathNotFound || r==KErrNotFound);
182 r = fs.MkDirAll(gTestPath);
183 test(r==KErrNone || r==KErrAlreadyExists);
189 void DeleteLogFilesL()
191 RDebug::Print(_L("Clearing test logs if exist..."));
193 User::LeaveIfError(fs.Connect());
194 CFileMan* fm = CFileMan::NewL(fs);
197 logFiles.Copy(gLogFilePath);
198 logFiles.Append('*');
199 logFiles.Append(gLogPostFix);
201 TInt r = fm->Delete(logFiles);
202 test(r==KErrNone || r==KErrPathNotFound || r==KErrNotFound);
205 r = fs.MkDirAll(gLogFilePath);
206 test(r==KErrNone || r==KErrAlreadyExists);
213 // Copy log files from test drive to MMC
217 User::LeaveIfError(fs.Connect());
218 CFileMan* fm = CFileMan::NewL(fs);
221 path.Append(_L("D:\\NPTLogs\\"));
222 TInt r = fs.MkDirAll(path);
223 test(r == KErrNone || r == KErrAlreadyExists);
224 fm->Copy(gLogFilePath, path);
230 // compare the name of two entries
231 TBool CompareEntryName(const TEntry& aEntry1, const TEntry& aEntry2)
233 return (aEntry1.iName.Compare(aEntry2.iName) == 0);
236 // start file operations
237 void DoFileOperationL(TThreadParam* aParam)
239 CFileOperator fileOperator(aParam->iSetting, *(aParam->iLoggerArray), aParam->iSmphFT, aParam->iSmphNT);
240 fileOperator.DoChangesL();
243 // start monitoring notification
244 void DoNotificationOperationL(TThreadParam* aParam)
246 CActiveScheduler* sch = new(ELeave) CActiveScheduler();
247 CleanupStack::PushL(sch);
248 CActiveScheduler::Install(sch);
250 CNotifyOperator notifyOperator(aParam->iSetting, aParam->iSmphFT, aParam->iSmphNT, aParam->iLogger);
251 aParam->iSmphFT->Signal();
252 notifyOperator.StartOperationL();
254 CleanupStack::PopAndDestroy();
257 // entry function of file operaton thread
258 TInt FileOperationThread(TAny* aParam)
260 CTrapCleanup* cleanup;
261 cleanup = CTrapCleanup::New();
263 TRAPD(r, DoFileOperationL(static_cast<TThreadParam*>(aParam)));
270 // entry function of notification thread
271 TInt NotificationOperationThread(TAny* aParam)
273 CTrapCleanup* cleanup;
274 cleanup = CTrapCleanup::New();
276 TRAPD(r, DoNotificationOperationL(static_cast<TThreadParam*>(aParam)));
283 TInt KillerThread(TAny*)
285 CTrapCleanup* cleanup;
286 cleanup = CTrapCleanup::New();
288 TRAPD(r, DoKillThreadsL());