|
1 // Copyright (c) 2005-2010 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 "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". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // |
|
15 // |
|
16 // |
|
17 #include <bautils.h> |
|
18 #include <test/tracedataparser.h> |
|
19 |
|
20 #include "te_tracecore_datawrapper.h" |
|
21 #include "te_processcreator.h" |
|
22 |
|
23 _LIT(KConstantsSectionName, "Constants"); |
|
24 |
|
25 _LIT(KCmdCopyFile, "CopyFile"); |
|
26 _LIT(KCmdDeleteFile, "DeleteFile"); |
|
27 _LIT(KCmdDeleteFileFromAllDrives, "DeleteFileFromAllDrives"); |
|
28 _LIT(KCmdDeleteEmptyFolder, "DeleteEmptyFolder"); |
|
29 _LIT(KCmdFileExists, "FileExists"); |
|
30 _LIT(KCmdRunProcess, "RunProcess"); |
|
31 _LIT(KCmdCheckFileSize, "CheckFileSize"); |
|
32 _LIT(KCmdCreateSubstDrive, "CreateSubstDrive"); |
|
33 _LIT(KCmdUnSubstDrive, "UnSubstDrive"); |
|
34 _LIT(KCmdCheckMaxFileSize, "CheckMaxFileSize"); |
|
35 _LIT(KCmdCheckFileIsAppended, "CheckFileIsAppended"); |
|
36 _LIT(KCmdVerifyTraceData, "VerifyTraceData"); |
|
37 _LIT(KCmdVerifyPrimingData, "VerifyPrimingData"); |
|
38 _LIT(KCmdVerifyDroppedTraces, "VerifyDroppedTraces"); |
|
39 _LIT(KCmdVerifySlot, "VerifySlot"); |
|
40 _LIT(KCmdFileChangeNotification, "FileChangeNotification"); |
|
41 _LIT(KCmdSetUpTraceOnActivation, "SetUpTraceOnActivation"); |
|
42 _LIT(KCmdRegisterNotifReceiver, "RegisterNotifReceiver"); |
|
43 _LIT(KCmdUnregisterNotifReceiver, "UnregisterNotifReceiver"); |
|
44 _LIT(KCmdCleanUpTraceOnActivation, "CleanUpTraceOnActivation"); |
|
45 _LIT(KCmdInstrumentTraceSequence, "InstrumentTraceSequence"); |
|
46 _LIT(KCmdSetUpTcLdd, "SetUpTcLdd"); |
|
47 _LIT(KCmdCleanUpTcLdd, "CleanUpTcLdd"); |
|
48 _LIT(KCmdSetUpTcOstLdd, "SetUpTcOstLdd"); |
|
49 _LIT(KCmdCleanUpTcOstLdd, "CleanUpTcOstLdd"); |
|
50 _LIT(KCmdActivateDeactivateTrace, "ActivateDeactivateTrace"); |
|
51 _LIT(KCmdReadTracesFromBuffer, "ReadTracesFromBuffer"); |
|
52 |
|
53 _LIT(KSrcFileKey, "src_file"); |
|
54 _LIT(KDstFileKey, "dst_file"); |
|
55 _LIT(KFileKey, "file"); |
|
56 _LIT(KExeNameKey, "exe_name"); |
|
57 _LIT(KArgsKey, "args"); |
|
58 _LIT(KNoOfCallsKey, "calls"); |
|
59 _LIT(KNoOfAllowedTimeoutsKey, "allowed_timeouts"); |
|
60 _LIT(KFolderPathKey, "path"); |
|
61 _LIT(KDriveKey, "drive"); |
|
62 _LIT(KSizeKey, "size"); |
|
63 _LIT(KMinSizeKey, "min_size"); |
|
64 _LIT(KMaxSizeKey, "max_size"); |
|
65 _LIT(KSystemDriveKey, "system_drive"); |
|
66 _LIT(KUnfetteredKey, "unfettered"); |
|
67 _LIT(KDurationKey, "duration"); |
|
68 _LIT(KMinIncreaseKey, "min_increase"); |
|
69 _LIT(KGroupIdKey, "group_id"); |
|
70 _LIT(KComponentIdKey, "component_id"); |
|
71 _LIT(KSlotNumberKey, "slot"); |
|
72 _LIT(KTracesSlotNumberKey, "traces_slot"); |
|
73 _LIT(KPrimingTracesSlotNumberKey, "priming_traces_slot"); |
|
74 _LIT(KSlotANumberKey, "slot_a"); |
|
75 _LIT(KSlotBNumberKey, "slot_b"); |
|
76 _LIT(KValueAKey, "value_a"); |
|
77 _LIT(KValueBKey, "value_b"); |
|
78 _LIT(KDifferenceKey, "difference"); |
|
79 _LIT(KMinDifferenceKey, "min_difference"); |
|
80 _LIT(KMaxDifferenceKey, "max_difference"); |
|
81 _LIT(KVerifyData, "verify_data"); |
|
82 _LIT(KFindStringKey, "find_string"); |
|
83 _LIT(KExpectedKey, "expected"); |
|
84 _LIT(KLengthKey, "length"); |
|
85 _LIT(KStringKey, "string"); |
|
86 _LIT(KActivateKey, "activate"); |
|
87 _LIT(KBufferSizeKey, "buffer_size"); |
|
88 _LIT(KAllowErrorKey, "allow_error"); |
|
89 _LIT(KSingleUseKey, "single_use"); |
|
90 _LIT(KOpenLddKey, "open_ldd"); |
|
91 _LIT(KCloseLddKey, "close_ldd"); |
|
92 |
|
93 _LIT(KSpace, " "); |
|
94 _LIT(KInt, "%d"); |
|
95 |
|
96 _LIT(KTcLdd, "TcLdd"); |
|
97 _LIT(KTraceCoreOstLdd, "TraceCoreOstLdd"); |
|
98 _LIT(KTraceOnActivationLdd, "d_traceonactivation.ldd"); |
|
99 |
|
100 const TInt KSecondsToMicroSeconds = 1000000; |
|
101 const TInt KDefaultBufferSize = 1024; |
|
102 const TInt KLongStringLength = 512; |
|
103 |
|
104 |
|
105 CTraceCoreDataWrapper::CTraceCoreDataWrapper() |
|
106 : iActiveFileChangeNotification(NULL) |
|
107 , iActiveFileChangeNotificationTimeout(NULL) |
|
108 , iTcLddLoadedAtStart(EFalse) |
|
109 , iTcOstLddLoadedAtStart(EFalse) |
|
110 , iTraceOnActivationLoadedAtStart(EFalse) |
|
111 { |
|
112 } |
|
113 |
|
114 CTraceCoreDataWrapper::~CTraceCoreDataWrapper() |
|
115 { |
|
116 delete iActiveFileChangeNotification; |
|
117 delete iActiveFileChangeNotificationTimeout; |
|
118 iFs.Close(); |
|
119 iTimer.Close(); |
|
120 iTraceBuffer.Close(); |
|
121 iTcLdd.Close(); |
|
122 iTraceCoreOstLdd.Close(); |
|
123 iTraceOnActivationLdd.Close(); |
|
124 } |
|
125 |
|
126 CTraceCoreDataWrapper* CTraceCoreDataWrapper::NewLC() |
|
127 { |
|
128 CTraceCoreDataWrapper* self = new (ELeave)CTraceCoreDataWrapper(); |
|
129 CleanupStack::PushL(self); |
|
130 self->ConstructL(); |
|
131 return self; |
|
132 } |
|
133 |
|
134 CTraceCoreDataWrapper* CTraceCoreDataWrapper::NewL() |
|
135 { |
|
136 CTraceCoreDataWrapper* self=CTraceCoreDataWrapper::NewLC(); |
|
137 CleanupStack::Pop(self); |
|
138 return self; |
|
139 } |
|
140 |
|
141 void CTraceCoreDataWrapper::ConstructL() |
|
142 { |
|
143 User::LeaveIfError(iFs.Connect()); |
|
144 User::LeaveIfError(iTimer.CreateLocal()); |
|
145 iActiveFileChangeNotification = CActiveCallback::NewL(*this); |
|
146 iActiveFileChangeNotificationTimeout = CActiveCallback::NewL(*this); |
|
147 } |
|
148 |
|
149 TAny* CTraceCoreDataWrapper::GetObject() |
|
150 { |
|
151 return this; |
|
152 } |
|
153 |
|
154 TBool CTraceCoreDataWrapper::GetStringFromConfig(const TDesC& aSectName, const TDesC& aKeyName, TPtrC& aResult) |
|
155 { |
|
156 TBool found = CDataWrapper::GetStringFromConfig(aSectName, aKeyName, aResult); |
|
157 if (found) |
|
158 { |
|
159 TPtrC constantName(aResult); |
|
160 CDataWrapper::GetStringFromConfig(KConstantsSectionName(), constantName, aResult); |
|
161 } |
|
162 return found; |
|
163 } |
|
164 |
|
165 TBool CTraceCoreDataWrapper::GetBoolFromConfig(const TDesC& aSectName, const TDesC& aKeyName, TBool& aResult) |
|
166 { |
|
167 TBool found = CDataWrapper::GetIntFromConfig(aSectName, aKeyName, aResult); |
|
168 if (!found) |
|
169 { |
|
170 TPtrC constantName; |
|
171 found = CDataWrapper::GetStringFromConfig(aSectName, aKeyName, constantName); |
|
172 if (found) |
|
173 { |
|
174 found = CDataWrapper::GetBoolFromConfig(KConstantsSectionName(), constantName, aResult); |
|
175 if (!found) |
|
176 { |
|
177 found = CDataWrapper::GetBoolFromConfig(aSectName, aKeyName, aResult); |
|
178 } |
|
179 } |
|
180 } |
|
181 return found; |
|
182 } |
|
183 |
|
184 TBool CTraceCoreDataWrapper::GetIntFromConfig(const TDesC& aSectName, const TDesC& aKeyName, TInt& aResult) |
|
185 { |
|
186 TBool found = CDataWrapper::GetIntFromConfig(aSectName, aKeyName, aResult); |
|
187 if (!found) |
|
188 { |
|
189 TPtrC constantName; |
|
190 found = CDataWrapper::GetStringFromConfig(aSectName, aKeyName, constantName); |
|
191 if (found) |
|
192 { |
|
193 found = CDataWrapper::GetIntFromConfig(KConstantsSectionName(), constantName, aResult); |
|
194 } |
|
195 } |
|
196 return found; |
|
197 } |
|
198 |
|
199 TBool CTraceCoreDataWrapper::GetHexFromConfig(const TDesC& aSectName, const TDesC& aKeyName, TInt& aResult) |
|
200 { |
|
201 TBool found = CDataWrapper::GetIntFromConfig(aSectName, aKeyName, aResult); |
|
202 if (!found) |
|
203 { |
|
204 TPtrC constantName; |
|
205 found = CDataWrapper::GetStringFromConfig(aSectName, aKeyName, constantName); |
|
206 if (found) |
|
207 { |
|
208 found = CDataWrapper::GetHexFromConfig(KConstantsSectionName(), constantName, aResult); |
|
209 if (!found) |
|
210 { |
|
211 found = CDataWrapper::GetHexFromConfig(aSectName, aKeyName, aResult); |
|
212 } |
|
213 } |
|
214 } |
|
215 else |
|
216 { |
|
217 found = CDataWrapper::GetHexFromConfig(aSectName, aKeyName, aResult); |
|
218 } |
|
219 return found; |
|
220 } |
|
221 |
|
222 TBool CTraceCoreDataWrapper::GetPathFromConfig(const TTEFSectionName& aSection, const TDesC& aPathKey, TFileName& aPath) |
|
223 { |
|
224 TBool found = EFalse; |
|
225 TPtrC file; |
|
226 if (GetStringFromConfig(aSection, aPathKey, file)) |
|
227 { |
|
228 found = ETrue; |
|
229 TBool useSysDrive = EFalse; |
|
230 GetBoolFromConfig(aSection, KSystemDriveKey(), useSysDrive); |
|
231 TPtrC driveString; |
|
232 if (GetStringFromConfig(aSection, KDriveKey(), driveString)) |
|
233 { |
|
234 aPath.Zero(); |
|
235 aPath.Append(driveString); |
|
236 aPath.Append(_L(":")); |
|
237 aPath.Append(file); |
|
238 } |
|
239 else if (useSysDrive) |
|
240 { |
|
241 aPath.Zero(); |
|
242 aPath.Append(RFs::GetSystemDriveChar()); |
|
243 aPath.Append(_L(":")); |
|
244 aPath.Append(file); |
|
245 } |
|
246 else |
|
247 { |
|
248 aPath.Copy(file); |
|
249 } |
|
250 } |
|
251 else |
|
252 { |
|
253 ERR_PRINTF2(_L("No %S in INI file"), &aPathKey); |
|
254 SetBlockResult(EFail); |
|
255 } |
|
256 return found; |
|
257 } |
|
258 |
|
259 TBool CTraceCoreDataWrapper::GetArgsFromConfig(const TTEFSectionName& aSection, TDes& aArgs) |
|
260 { |
|
261 TPtrC cmdLineArgs(KNullDesC); |
|
262 TBool found = GetStringFromConfig(aSection, KArgsKey(), cmdLineArgs); |
|
263 aArgs.Copy(cmdLineArgs); |
|
264 if (!found) |
|
265 { |
|
266 // Args may be seperated |
|
267 TInt argNumber = 0; |
|
268 TBuf<KTEFMaxNameLength> argKeyName; |
|
269 found = ETrue; |
|
270 |
|
271 while (found) |
|
272 { |
|
273 argNumber++; |
|
274 argKeyName.Copy(KArgsKey()); |
|
275 argKeyName.AppendFormat(KInt(), argNumber); |
|
276 found = GetStringFromConfig(aSection, argKeyName, cmdLineArgs); |
|
277 if (found) |
|
278 { |
|
279 if (argNumber > 1) |
|
280 { |
|
281 aArgs.Append(KSpace()); |
|
282 } |
|
283 aArgs.Append(cmdLineArgs); |
|
284 } |
|
285 } |
|
286 |
|
287 if (argNumber > 1) |
|
288 { |
|
289 found = ETrue; |
|
290 } |
|
291 } |
|
292 if (found) |
|
293 { |
|
294 INFO_PRINTF2(_L("Found args \"%S\" in INI file"), &aArgs); |
|
295 } |
|
296 return found; |
|
297 } |
|
298 |
|
299 TBool CTraceCoreDataWrapper::GetLongStringFromConfig(const TTEFSectionName& aSection, const TDesC& aKeyName, TDes& aResult) |
|
300 { |
|
301 TPtrC stringLine; |
|
302 TBool found = GetStringFromConfig(aSection, aKeyName, stringLine); |
|
303 if (found) |
|
304 { |
|
305 aResult.Copy(stringLine); |
|
306 } |
|
307 else |
|
308 { |
|
309 TInt lineNumber = 0; |
|
310 TBuf<KTEFMaxNameLength> keyName; |
|
311 found = ETrue; |
|
312 aResult.Zero(); |
|
313 |
|
314 while (found) |
|
315 { |
|
316 lineNumber++; |
|
317 keyName.Copy(aKeyName); |
|
318 keyName.AppendFormat(KInt(), lineNumber); |
|
319 found = GetStringFromConfig(aSection, keyName, stringLine); |
|
320 if (found) |
|
321 { |
|
322 aResult.Append(stringLine); |
|
323 } |
|
324 } |
|
325 |
|
326 if (lineNumber > 1) |
|
327 { |
|
328 found = ETrue; |
|
329 } |
|
330 } |
|
331 return found; |
|
332 } |
|
333 |
|
334 TBool CTraceCoreDataWrapper::DoCommandL(const TTEFFunction& aCommand, |
|
335 const TTEFSectionName& aSection, |
|
336 const TInt aAsyncErrorIndex) |
|
337 { |
|
338 TBool ret = ETrue; |
|
339 if (aCommand == KCmdCopyFile()) |
|
340 { |
|
341 DoCmdCopyFileL(aSection); |
|
342 } |
|
343 else if (aCommand == KCmdDeleteFile()) |
|
344 { |
|
345 DoCmdDeleteFileL(aSection); |
|
346 } |
|
347 else if (aCommand == KCmdDeleteFileFromAllDrives()) |
|
348 { |
|
349 DoCmdDeleteFileFromAllDrivesL(aSection); |
|
350 } |
|
351 else if (aCommand == KCmdDeleteEmptyFolder()) |
|
352 { |
|
353 DoCmdDeleteEmptyFolder(aSection); |
|
354 } |
|
355 else if (aCommand == KCmdFileExists()) |
|
356 { |
|
357 DoCmdFileExists(aSection); |
|
358 } |
|
359 else if (aCommand == KCmdCheckFileSize()) |
|
360 { |
|
361 DoCmdCheckFileSize(aSection); |
|
362 } |
|
363 else if (aCommand == KCmdRunProcess()) |
|
364 { |
|
365 DoCmdRunProcess(aSection); |
|
366 } |
|
367 else if (aCommand == KCmdCreateSubstDrive()) |
|
368 { |
|
369 DoCmdCreateSubstDrive(aSection); |
|
370 } |
|
371 else if (aCommand == KCmdUnSubstDrive()) |
|
372 { |
|
373 DoCmdUnSubstDrive(aSection); |
|
374 } |
|
375 else if (aCommand == KCmdCheckMaxFileSize()) |
|
376 { |
|
377 DoCmdCheckMaxFileSizeL(aSection); |
|
378 } |
|
379 else if (aCommand == KCmdCheckFileIsAppended()) |
|
380 { |
|
381 DoCmdCheckFileIsAppendedL(aSection); |
|
382 } |
|
383 else if (aCommand == KCmdVerifyTraceData()) |
|
384 { |
|
385 DoCmdVerifyTraceDataL(aSection); |
|
386 } |
|
387 else if (aCommand == KCmdVerifyPrimingData()) |
|
388 { |
|
389 DoCmdVerifyPrimingDataL(aSection); |
|
390 } |
|
391 else if (aCommand == KCmdVerifyDroppedTraces()) |
|
392 { |
|
393 DoCmdVerifyDroppedTracesL(aSection); |
|
394 } |
|
395 else if (aCommand == KCmdVerifySlot()) |
|
396 { |
|
397 DoCmdVerifySlot(aSection); |
|
398 } |
|
399 else if (aCommand == KCmdFileChangeNotification()) |
|
400 { |
|
401 DoCmdFileChangeNotification(aSection, aAsyncErrorIndex); |
|
402 } |
|
403 else if (aCommand == KCmdSetUpTraceOnActivation()) |
|
404 { |
|
405 DoCmdSetUpTraceOnActivation(aSection); |
|
406 } |
|
407 else if (aCommand == KCmdRegisterNotifReceiver()) |
|
408 { |
|
409 DoCmdRegisterNotifReceiver(aSection); |
|
410 } |
|
411 else if (aCommand == KCmdUnregisterNotifReceiver()) |
|
412 { |
|
413 DoCmdUnregisterNotifReceiver(aSection); |
|
414 } |
|
415 else if (aCommand == KCmdCleanUpTraceOnActivation()) |
|
416 { |
|
417 DoCmdCleanUpTraceOnActivation(aSection); |
|
418 } |
|
419 else if (aCommand == KCmdInstrumentTraceSequence()) |
|
420 { |
|
421 DoCmdInstrumentTraceSequence(aSection); |
|
422 } |
|
423 else if (aCommand == KCmdSetUpTcLdd()) |
|
424 { |
|
425 DoCmdSetUpTcLdd(aSection); |
|
426 } |
|
427 else if (aCommand == KCmdCleanUpTcLdd()) |
|
428 { |
|
429 DoCmdCleanUpTcLdd(aSection); |
|
430 } |
|
431 else if (aCommand == KCmdSetUpTcOstLdd()) |
|
432 { |
|
433 DoCmdSetUpTcOstLdd(aSection); |
|
434 } |
|
435 else if (aCommand == KCmdCleanUpTcOstLdd()) |
|
436 { |
|
437 DoCmdCleanUpTcOstLdd(aSection); |
|
438 } |
|
439 else if (aCommand == KCmdActivateDeactivateTrace()) |
|
440 { |
|
441 DoCmdActivateDeactivateTrace(aSection); |
|
442 } |
|
443 else if (aCommand == KCmdReadTracesFromBuffer()) |
|
444 { |
|
445 DoCmdReadTracesFromBuffer(); |
|
446 } |
|
447 else |
|
448 { |
|
449 ret = EFalse; |
|
450 } |
|
451 return ret; |
|
452 } |
|
453 |
|
454 void CTraceCoreDataWrapper::CopyFileL(const TDesC& aSrcFile, |
|
455 const TDesC& aDstFile) |
|
456 { |
|
457 INFO_PRINTF3(_L("CopyFile aSrcFile (%S) aDestFile (%S)"), &aSrcFile, &aDstFile); |
|
458 |
|
459 TInt err = KErrNone; |
|
460 |
|
461 // attempt to create the folder if it does not exist |
|
462 if (!BaflUtils::FolderExists(iFs, aDstFile)) |
|
463 { |
|
464 err = iFs.MkDirAll(aDstFile); |
|
465 if (err != KErrNone) |
|
466 { |
|
467 ERR_PRINTF3(_L("CopyFile MKDIRALL FAILED aDestFile (%S) err (%d)"), &aDstFile, err); |
|
468 SetError(err); |
|
469 } |
|
470 } |
|
471 |
|
472 CFileMan* fileMan = CFileMan::NewL(iFs); |
|
473 |
|
474 // Make file read-write |
|
475 err = fileMan->Attribs(aDstFile, 0, KEntryAttReadOnly, TTime(0), CFileMan::ERecurse); |
|
476 if (err != KErrNone && err != KErrNotFound) |
|
477 { |
|
478 ERR_PRINTF3(_L("CopyFile ATTRIBS FAILED aDestFile (%S) err (%d)"), &aDstFile, err); |
|
479 SetError(err); |
|
480 } |
|
481 |
|
482 err = fileMan->Copy(aSrcFile, aDstFile); |
|
483 if (err != KErrNone) |
|
484 { |
|
485 ERR_PRINTF4(_L("CopyFile COPY FAILED aSrcFile (%S) aDestFile (%S) err (%d)"), &aSrcFile, &aDstFile, err); |
|
486 SetError(err); |
|
487 } |
|
488 else |
|
489 { |
|
490 INFO_PRINTF3(_L("CopyFile copied file OK aSrcFile (%S) aDestFile (%S)"), &aSrcFile, &aDstFile); |
|
491 } |
|
492 |
|
493 delete fileMan; |
|
494 } |
|
495 |
|
496 void CTraceCoreDataWrapper::DeleteFileFromAllDrivesL(const TDesC& aFile) |
|
497 { |
|
498 INFO_PRINTF2(_L("DeleteFileFromAllDrives aFile (%S)"), &aFile); |
|
499 |
|
500 TDriveList driveList; |
|
501 TInt err = iFs.DriveList(driveList); |
|
502 if (err != KErrNone) |
|
503 { |
|
504 ERR_PRINTF2(_L("DeleteFileFromAllDrives DRIVELIST FAILED err (%d)"), err); |
|
505 SetError(err); |
|
506 } |
|
507 else |
|
508 { |
|
509 CFileMan* fileMan = CFileMan::NewL(iFs); |
|
510 TChar drives[] = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'}; |
|
511 for (TInt i=0; i<driveList.Size(); i++) |
|
512 { |
|
513 if (driveList[i]) |
|
514 { |
|
515 TFileName file; |
|
516 file.Zero(); |
|
517 file.Append(drives[i]); |
|
518 file.Append(_L(":")); |
|
519 file.Append(aFile); |
|
520 |
|
521 DeleteFileL(file, EFalse); |
|
522 } |
|
523 } |
|
524 delete fileMan; |
|
525 } |
|
526 } |
|
527 |
|
528 void CTraceCoreDataWrapper::DeleteFileL(const TDesC& aFile, TInt aStrictMode) |
|
529 { |
|
530 if (aStrictMode) |
|
531 { |
|
532 INFO_PRINTF2(_L("DeleteFile aFile (%S)"), &aFile); |
|
533 } |
|
534 |
|
535 CFileMan* fileMan = CFileMan::NewL(iFs); |
|
536 |
|
537 // Make file read-write |
|
538 TInt err = fileMan->Attribs(aFile, 0, KEntryAttReadOnly, TTime(0), CFileMan::ERecurse); |
|
539 if (err == KErrNone) |
|
540 { |
|
541 err = fileMan->Delete(aFile); |
|
542 if (err == KErrNone) |
|
543 { |
|
544 INFO_PRINTF2(_L("DeleteFile deleted file OK file (%S)"), &aFile); |
|
545 } |
|
546 else |
|
547 { |
|
548 ERR_PRINTF3(_L("DeleteFile DELETE FAILED file (%S) err (%d)"), &aFile, err); |
|
549 SetError(err); |
|
550 } |
|
551 } |
|
552 else if (err == KErrAccessDenied && !aStrictMode) |
|
553 { |
|
554 WARN_PRINTF2(_L("DeleteFile file (%S) READONLY"), &aFile); |
|
555 } |
|
556 else if (err == KErrNotReady && !aStrictMode) |
|
557 { |
|
558 WARN_PRINTF2(_L("DeleteFile file (%S) NOT READY"), &aFile); |
|
559 } |
|
560 else if (err != KErrNotFound && err != KErrPathNotFound) |
|
561 { |
|
562 ERR_PRINTF3(_L("DeleteFile ATTRIBS error (%d) file (%S)"), err, &aFile); |
|
563 SetError(err); |
|
564 } |
|
565 else if (aStrictMode) |
|
566 { |
|
567 INFO_PRINTF2(_L("DeleteFile aFile (%S) DOES NOT EXIST"), &aFile); |
|
568 } |
|
569 |
|
570 delete fileMan; |
|
571 } |
|
572 |
|
573 /** |
|
574 * Deletes an empty folder. If folder is not empty the current test is failed with KErrInUse |
|
575 */ |
|
576 void CTraceCoreDataWrapper::DeleteEmptyFolder(const TDesC& aFolder) |
|
577 { |
|
578 INFO_PRINTF2(_L("DeleteEmptyFolder aFolder (%S)"), &aFolder); |
|
579 |
|
580 if (BaflUtils::PathExists(iFs, aFolder)) |
|
581 { |
|
582 TInt err = iFs.SetAtt(aFolder, 0, KEntryAttReadOnly); |
|
583 if (err != KErrNone) |
|
584 { |
|
585 ERR_PRINTF3(_L("DeleteEmptyFolder SETATT FAILED aFolder (%S) err (%d)"), &aFolder, err); |
|
586 SetError(err); |
|
587 } |
|
588 else |
|
589 { |
|
590 err = iFs.RmDir(aFolder); |
|
591 if (err != KErrNone) |
|
592 { |
|
593 ERR_PRINTF3(_L("DeleteEmptyFolder DELETE FAILED aFolder (%S) err (%d)"), &aFolder, err); |
|
594 SetError(err); |
|
595 } |
|
596 else |
|
597 { |
|
598 INFO_PRINTF2(_L("DeleteEmptyFolder deleted folder OK aFolder (%S)"), &aFolder); |
|
599 } |
|
600 } |
|
601 } |
|
602 else |
|
603 { |
|
604 INFO_PRINTF2(_L("DeleteEmptyFolder aFolder DOES NOT EXIST (%S)"), &aFolder); |
|
605 } |
|
606 } |
|
607 |
|
608 TBool CTraceCoreDataWrapper::FileExists(const TDesC& aFile) |
|
609 { |
|
610 INFO_PRINTF2(_L("FileExists aFile (%S)"), &aFile); |
|
611 TBool fileExists = EFalse; |
|
612 |
|
613 if (BaflUtils::FileExists(iFs, aFile)) |
|
614 { |
|
615 INFO_PRINTF2(_L("FileExists file exists OK aFile (%S)"), &aFile); |
|
616 fileExists = ETrue; |
|
617 } |
|
618 else |
|
619 { |
|
620 ERR_PRINTF2(_L("FileExists aFile DOES NOT EXIST (%S)"), &aFile); |
|
621 SetError(KErrNotFound); |
|
622 } |
|
623 |
|
624 return fileExists; |
|
625 } |
|
626 |
|
627 /** |
|
628 * Checks that a given file has size within given limits |
|
629 * |
|
630 * @return Size of file on success otherwise symbian error code |
|
631 * |
|
632 */ |
|
633 TInt CTraceCoreDataWrapper::CheckFileSize(const TDesC& aFile, TInt aMinSize, TInt aMaxSize) |
|
634 { |
|
635 INFO_PRINTF2(_L("CheckFileSize aFile (%S)"), &aFile); |
|
636 TInt result = KErrNotFound; |
|
637 |
|
638 if (FileExists(aFile)) |
|
639 { |
|
640 TEntry entry; |
|
641 result = iFs.Entry(aFile, entry); |
|
642 if (result != KErrNone) |
|
643 { |
|
644 ERR_PRINTF3(_L("CheckFileSize ENTRY FAILED aFile (%S) err (%d)"), &aFile, result); |
|
645 } |
|
646 else |
|
647 { |
|
648 TInt fileSize = entry.iSize; |
|
649 INFO_PRINTF3(_L("CheckFileSize aFile (%S) fileSize (%d)"), &aFile, fileSize); |
|
650 if ( (aMinSize == -1) && (aMaxSize == -1) ) |
|
651 { |
|
652 ERR_PRINTF2(_L("CheckFileSize failed - need to specify max and / or min"), result); |
|
653 result = KErrArgument; |
|
654 } |
|
655 else if ( (aMinSize == -1 || fileSize >= aMinSize) && |
|
656 (aMaxSize == -1 || fileSize <= aMaxSize) ) |
|
657 { |
|
658 INFO_PRINTF3(_L("CheckFileSize file size OK aFile (%S) fileSize (%d)"), &aFile, fileSize); |
|
659 result = fileSize; |
|
660 } |
|
661 else |
|
662 { |
|
663 ERR_PRINTF3(_L("CheckFileSize FAILED aFile (%S) fileSize (%d)"), &aFile, fileSize); |
|
664 result = KErrGeneral; |
|
665 } |
|
666 } |
|
667 } |
|
668 |
|
669 if (result < 0) |
|
670 { |
|
671 SetError(result); |
|
672 } |
|
673 |
|
674 return result; |
|
675 } |
|
676 |
|
677 void CTraceCoreDataWrapper::RunProcess(const TDesC& aProgramName, const TDesC& aCmdLineArgs, TInt aNoOfCalls, TInt aAllowedErrorCode) |
|
678 { |
|
679 for (TInt i=0; i<aNoOfCalls; i++) |
|
680 { |
|
681 TProcessCreatorResults res = CProcessCreator::StartProgram(aProgramName, aCmdLineArgs); |
|
682 if (res.iCode == KErrNone || res.iCode == aAllowedErrorCode) |
|
683 { |
|
684 INFO_PRINTF7(_L("\"%S %S\" executes with code: %d, exitType: %d, desc: \"%S\" on call number %d"), &aProgramName, &aCmdLineArgs, res.iCode, res.iExitType, &(res.iDesc), i+1); |
|
685 } |
|
686 else |
|
687 { |
|
688 ERR_PRINTF7(_L("\"%S %S\" executes with code: %d, exitType: %d, desc: \"%S\" on call number %d"), &aProgramName, &aCmdLineArgs, res.iCode, res.iExitType, &(res.iDesc), i+1); |
|
689 SetError(res.iCode); |
|
690 } |
|
691 } |
|
692 } |
|
693 |
|
694 void CTraceCoreDataWrapper::CreateSubstDrive(const TDesC& aFolderPath, TDriveNumber aDrive) |
|
695 { |
|
696 TInt err = KErrNone; |
|
697 |
|
698 // attempt to create the folder if it does not exist |
|
699 if (!BaflUtils::FolderExists(iFs, aFolderPath)) |
|
700 { |
|
701 err = iFs.MkDirAll(aFolderPath); |
|
702 if (err != KErrNone) |
|
703 { |
|
704 ERR_PRINTF3(_L("CreateSubstDrive MKDIRALL FAILED aFile (%S) err (%d)"), &aFolderPath, err); |
|
705 SetError(err); |
|
706 } |
|
707 } |
|
708 |
|
709 if (err == KErrNone) |
|
710 { |
|
711 err = iFs.SetSubst(aFolderPath, aDrive); |
|
712 if (err != KErrNone) |
|
713 { |
|
714 ERR_PRINTF4(_L("CreateSubstDrive SETSUBST FAILED aFolderPath (%S) aDrive (%d) err (%d)"), &aFolderPath, aDrive, err); |
|
715 SetError(err); |
|
716 } |
|
717 else |
|
718 { |
|
719 INFO_PRINTF3(_L("CreateSubstDrive substed drive OK aFolderPath (%S) aDrive (%d)"), &aFolderPath, aDrive); |
|
720 } |
|
721 } |
|
722 } |
|
723 |
|
724 void CTraceCoreDataWrapper::UnSubstDrive(TDriveNumber aDrive) |
|
725 { |
|
726 TInt err = iFs.SetSubst(KNullDesC, aDrive); |
|
727 if (err != KErrNone) |
|
728 { |
|
729 ERR_PRINTF3(_L("UnSubstDrive SETSUBST FAILED aDrive (%d) err (%d)"), aDrive, err); |
|
730 SetError(err); |
|
731 } |
|
732 else |
|
733 { |
|
734 INFO_PRINTF2(_L("UnSubstDrive unsubsted drive OK aDrive (%d)"), aDrive); |
|
735 } |
|
736 } |
|
737 |
|
738 |
|
739 // Macro for matching drive letter |
|
740 #define DRIVE_CONDITION(aDrv) if (aDriveString == _L(#aDrv)) { aDriveNumber = EDrive##aDrv; found = ETrue; } |
|
741 |
|
742 TBool CTraceCoreDataWrapper::DriveNumberFromString(const TDesC& aDriveString, TDriveNumber& aDriveNumber) |
|
743 { |
|
744 TBool found = EFalse; |
|
745 |
|
746 DRIVE_CONDITION(A) |
|
747 DRIVE_CONDITION(B) |
|
748 DRIVE_CONDITION(C) |
|
749 DRIVE_CONDITION(D) |
|
750 DRIVE_CONDITION(E) |
|
751 DRIVE_CONDITION(F) |
|
752 DRIVE_CONDITION(G) |
|
753 DRIVE_CONDITION(H) |
|
754 DRIVE_CONDITION(I) |
|
755 DRIVE_CONDITION(J) |
|
756 DRIVE_CONDITION(K) |
|
757 DRIVE_CONDITION(L) |
|
758 DRIVE_CONDITION(M) |
|
759 DRIVE_CONDITION(N) |
|
760 DRIVE_CONDITION(O) |
|
761 DRIVE_CONDITION(P) |
|
762 DRIVE_CONDITION(Q) |
|
763 DRIVE_CONDITION(R) |
|
764 DRIVE_CONDITION(S) |
|
765 DRIVE_CONDITION(T) |
|
766 DRIVE_CONDITION(U) |
|
767 DRIVE_CONDITION(V) |
|
768 DRIVE_CONDITION(W) |
|
769 DRIVE_CONDITION(X) |
|
770 DRIVE_CONDITION(Y) |
|
771 DRIVE_CONDITION(Z) |
|
772 |
|
773 return found; |
|
774 } |
|
775 |
|
776 void CTraceCoreDataWrapper::DoCmdCopyFileL(const TTEFSectionName& aSection) |
|
777 { |
|
778 TPtrC srcFile; |
|
779 if (GetStringFromConfig(aSection, KSrcFileKey(), srcFile)) |
|
780 { |
|
781 TFileName dstFile; |
|
782 if (GetPathFromConfig(aSection, KDstFileKey(), dstFile)) |
|
783 { |
|
784 CopyFileL(srcFile, dstFile); |
|
785 } |
|
786 } |
|
787 else |
|
788 { |
|
789 ERR_PRINTF2(_L("No %S in INI file"), &KSrcFileKey()); |
|
790 SetBlockResult(EFail); |
|
791 } |
|
792 } |
|
793 |
|
794 void CTraceCoreDataWrapper::DoCmdDeleteFileFromAllDrivesL(const TTEFSectionName& aSection) |
|
795 { |
|
796 TFileName file; |
|
797 if (GetPathFromConfig(aSection, KFileKey(), file)) |
|
798 { |
|
799 DeleteFileFromAllDrivesL(file); |
|
800 } |
|
801 } |
|
802 |
|
803 void CTraceCoreDataWrapper::DoCmdDeleteFileL(const TTEFSectionName& aSection) |
|
804 { |
|
805 TFileName file; |
|
806 if (GetPathFromConfig(aSection, KFileKey(), file)) |
|
807 { |
|
808 DeleteFileL(file); |
|
809 } |
|
810 } |
|
811 |
|
812 void CTraceCoreDataWrapper::DoCmdDeleteEmptyFolder(const TTEFSectionName& aSection) |
|
813 { |
|
814 TFileName folder; |
|
815 if (GetPathFromConfig(aSection, KFolderPathKey(), folder)) |
|
816 { |
|
817 DeleteEmptyFolder(folder); |
|
818 } |
|
819 } |
|
820 |
|
821 void CTraceCoreDataWrapper::DoCmdFileExists(const TTEFSectionName& aSection) |
|
822 { |
|
823 TFileName file; |
|
824 if (GetPathFromConfig(aSection, KFileKey(), file)) |
|
825 { |
|
826 FileExists(file); |
|
827 } |
|
828 } |
|
829 |
|
830 void CTraceCoreDataWrapper::DoCmdCheckFileSize(const TTEFSectionName& aSection) |
|
831 { |
|
832 TFileName file; |
|
833 if (GetPathFromConfig(aSection, KFileKey(), file)) |
|
834 { |
|
835 TInt minSize = -1; |
|
836 TInt maxSize = -1; |
|
837 TInt size = -1; |
|
838 if (GetIntFromConfig(aSection, KSizeKey(), size)) |
|
839 { |
|
840 minSize = size; |
|
841 maxSize = size; |
|
842 } |
|
843 else |
|
844 { |
|
845 GetIntFromConfig(aSection, KMinSizeKey(), minSize); |
|
846 GetIntFromConfig(aSection, KMaxSizeKey(), maxSize); |
|
847 } |
|
848 TInt fileSize = CheckFileSize(file, minSize, maxSize); |
|
849 |
|
850 // Store number in slot for future use, if slot number is given |
|
851 TInt slotNumber; |
|
852 if (GetIntFromConfig(aSection, KSlotNumberKey(), slotNumber)) |
|
853 { |
|
854 StoreInSlot(fileSize, slotNumber); |
|
855 } |
|
856 } |
|
857 } |
|
858 |
|
859 void CTraceCoreDataWrapper::DoCmdRunProcess(const TTEFSectionName& aSection) |
|
860 { |
|
861 TPtrC programName; |
|
862 if (GetStringFromConfig(aSection, KExeNameKey(), programName)) |
|
863 { |
|
864 TBuf<KTEFMaxNameLength> cmdLineArgs; |
|
865 GetArgsFromConfig(aSection, cmdLineArgs); |
|
866 TInt noOfCalls = 1; |
|
867 GetIntFromConfig(aSection, KNoOfCallsKey(), noOfCalls); |
|
868 TInt allowedErrorCode = KErrNone; |
|
869 GetIntFromConfig(aSection, KAllowErrorKey(), allowedErrorCode); |
|
870 RunProcess(programName, cmdLineArgs, noOfCalls, allowedErrorCode); |
|
871 } |
|
872 else |
|
873 { |
|
874 ERR_PRINTF2(_L("No %S in INI file"), &KExeNameKey()); |
|
875 SetBlockResult(EFail); |
|
876 } |
|
877 } |
|
878 |
|
879 void CTraceCoreDataWrapper::DoCmdCreateSubstDrive(const TTEFSectionName& aSection) |
|
880 { |
|
881 TPtrC folderPath; |
|
882 if (GetStringFromConfig(aSection, KFolderPathKey(), folderPath)) |
|
883 { |
|
884 TPtrC driveString; |
|
885 if (GetStringFromConfig(aSection, KDriveKey(), driveString)) |
|
886 { |
|
887 TDriveNumber driveNumber; |
|
888 if (DriveNumberFromString(driveString, driveNumber)) |
|
889 { |
|
890 CreateSubstDrive(folderPath, driveNumber); |
|
891 } |
|
892 else |
|
893 { |
|
894 ERR_PRINTF2(_L("Could not parse drive %S in INI file"), &driveString); |
|
895 SetBlockResult(EFail); |
|
896 } |
|
897 } |
|
898 else |
|
899 { |
|
900 ERR_PRINTF2(_L("No %S in INI file"), &KDriveKey()); |
|
901 SetBlockResult(EFail); |
|
902 } |
|
903 } |
|
904 else |
|
905 { |
|
906 ERR_PRINTF2(_L("No %S in INI file"), &KFolderPathKey()); |
|
907 SetBlockResult(EFail); |
|
908 } |
|
909 } |
|
910 |
|
911 void CTraceCoreDataWrapper::DoCmdUnSubstDrive(const TTEFSectionName& aSection) |
|
912 { |
|
913 TPtrC driveString; |
|
914 if (GetStringFromConfig(aSection, KDriveKey(), driveString)) |
|
915 { |
|
916 TDriveNumber driveNumber; |
|
917 if (DriveNumberFromString(driveString, driveNumber)) |
|
918 { |
|
919 UnSubstDrive(driveNumber); |
|
920 } |
|
921 else |
|
922 { |
|
923 ERR_PRINTF2(_L("Could not parse drive %S in INI file"), &driveString); |
|
924 SetBlockResult(EFail); |
|
925 } |
|
926 } |
|
927 else |
|
928 { |
|
929 ERR_PRINTF2(_L("No %S in INI file"), &KDriveKey()); |
|
930 SetBlockResult(EFail); |
|
931 } |
|
932 } |
|
933 |
|
934 /** |
|
935 * Test command to verify the max file size of output file |
|
936 * |
|
937 * Tracing needs to be started for this command to complete |
|
938 * |
|
939 */ |
|
940 void CTraceCoreDataWrapper::DoCmdCheckMaxFileSizeL(const TTEFSectionName& aSection) |
|
941 { |
|
942 TFileName file; |
|
943 TInt maxSize; |
|
944 TPtrC programName; |
|
945 // Get all required parameters from INI file |
|
946 if ( GetPathFromConfig(aSection, KFileKey(), file) && |
|
947 GetIntFromConfig(aSection, KMaxSizeKey(), maxSize) && |
|
948 GetStringFromConfig(aSection, KExeNameKey(), programName) ) |
|
949 { |
|
950 // Get optional params from INI file |
|
951 TBool unfetteredSize = EFalse; |
|
952 GetBoolFromConfig(aSection, KUnfetteredKey(), unfetteredSize); |
|
953 TBuf<KTEFMaxNameLength> cmdLineArgs; |
|
954 GetArgsFromConfig(aSection, cmdLineArgs); |
|
955 TInt noOfCalls = 1; |
|
956 GetIntFromConfig(aSection, KNoOfCallsKey(), noOfCalls); |
|
957 TInt minSize = 0; |
|
958 if (!unfetteredSize) |
|
959 { |
|
960 GetIntFromConfig(aSection, KMinSizeKey(), minSize); |
|
961 } |
|
962 |
|
963 // Number of seconds to perform test for (for unfettered case) |
|
964 TBool useTimer = EFalse; |
|
965 RTimer timer; |
|
966 TRequestStatus timerStatus(KRequestPending); |
|
967 TInt duration; |
|
968 if (unfetteredSize && GetIntFromConfig(aSection, KDurationKey(), duration)) |
|
969 { |
|
970 TInt err = timer.CreateLocal(); |
|
971 CleanupClosePushL(timer); |
|
972 if (err == KErrNone) |
|
973 { |
|
974 useTimer = ETrue; |
|
975 INFO_PRINTF2(_L("Running timer for %d seconds"), duration); |
|
976 timer.After(timerStatus, duration * KSecondsToMicroSeconds); |
|
977 } |
|
978 else |
|
979 { |
|
980 ERR_PRINTF2(_L("Error in creating timer %d"), err); |
|
981 SetBlockResult(EFail); |
|
982 } |
|
983 } |
|
984 |
|
985 // Keep calling an EXE so that trace data is appended to output file |
|
986 // Tracing must be started and the EXE must generate trace data for the config file used |
|
987 TBool finished = EFalse; |
|
988 TInt lastFileSize = 0; |
|
989 TInt currentFileSize = 0; |
|
990 while (!finished) |
|
991 { |
|
992 // Call the EXE |
|
993 RunProcess(programName, cmdLineArgs, noOfCalls); |
|
994 if (unfetteredSize) |
|
995 { |
|
996 // Get the size of output file |
|
997 currentFileSize = CheckFileSize(file, 0, -1); |
|
998 } |
|
999 else |
|
1000 { |
|
1001 // Check the size of output file is smaller than max file size |
|
1002 currentFileSize = CheckFileSize(file, 0, maxSize); |
|
1003 } |
|
1004 if (currentFileSize < 0) |
|
1005 { |
|
1006 // An error has occurred in checking the file size. Stop and fail the test |
|
1007 ERR_PRINTF2(_L("Error in file size %d"), currentFileSize); |
|
1008 SetBlockResult(EFail); |
|
1009 finished = ETrue; |
|
1010 } |
|
1011 else if (currentFileSize < lastFileSize) |
|
1012 { |
|
1013 // Output file size has decreased rather than increased. Stop and fail the test |
|
1014 ERR_PRINTF2(_L("File size (%d) has decreased rather than increased"), currentFileSize); |
|
1015 SetBlockResult(EFail); |
|
1016 finished = ETrue; |
|
1017 } |
|
1018 else if (unfetteredSize) |
|
1019 { |
|
1020 if (currentFileSize > maxSize) |
|
1021 { |
|
1022 // File size got to required size. Test has passed. |
|
1023 INFO_PRINTF1(_L("File size checking completed successfully")); |
|
1024 finished = ETrue; |
|
1025 } |
|
1026 else if (currentFileSize == lastFileSize) |
|
1027 { |
|
1028 // File size has not increased. Print a warning and continue |
|
1029 WARN_PRINTF2(_L("File size (%d) has not increased"), currentFileSize); |
|
1030 } |
|
1031 } |
|
1032 else if (currentFileSize == lastFileSize) |
|
1033 { |
|
1034 if (currentFileSize < minSize) |
|
1035 { |
|
1036 // File size has not reached required minimum. Stop and fail the test |
|
1037 ERR_PRINTF3(_L("File size (%d) has not met the minimum required (%d)"), currentFileSize, minSize); |
|
1038 SetBlockResult(EFail); |
|
1039 } |
|
1040 else |
|
1041 { |
|
1042 // File size got to minimum required and has stopped increasing, staying below required max size. Test has passed. |
|
1043 INFO_PRINTF1(_L("File size checking completed successfully")); |
|
1044 } |
|
1045 finished = ETrue; |
|
1046 } |
|
1047 lastFileSize = currentFileSize; |
|
1048 if (useTimer && timerStatus == KErrNone) |
|
1049 { |
|
1050 // File size has been increasing for required number of seconds. Test has passed. |
|
1051 INFO_PRINTF2(_L("File size checking completed successfully after %d seconds"), duration); |
|
1052 finished = ETrue; |
|
1053 } |
|
1054 } |
|
1055 if (useTimer) |
|
1056 { |
|
1057 timer.Cancel(); |
|
1058 CleanupStack::PopAndDestroy(&timer); |
|
1059 } |
|
1060 } |
|
1061 else |
|
1062 { |
|
1063 ERR_PRINTF3(_L("Need %S and %S in INI file"), &KMaxSizeKey(), &KExeNameKey()); |
|
1064 SetBlockResult(EFail); |
|
1065 } |
|
1066 } |
|
1067 |
|
1068 /** |
|
1069 * Test command to verify the output file is appended to and not overwritten |
|
1070 * |
|
1071 * Tracing needs to be started for this command to complete and |
|
1072 * an output file containing some data must exist |
|
1073 * |
|
1074 */ |
|
1075 void CTraceCoreDataWrapper::DoCmdCheckFileIsAppendedL(const TTEFSectionName& aSection) |
|
1076 { |
|
1077 TFileName file; |
|
1078 TPtrC programName; |
|
1079 TInt maxSize; |
|
1080 TInt duration; |
|
1081 // Get all required parameters from INI file |
|
1082 if ( GetPathFromConfig(aSection, KFileKey(), file) && |
|
1083 GetIntFromConfig(aSection, KMaxSizeKey(), maxSize) && |
|
1084 GetIntFromConfig(aSection, KDurationKey(), duration) && |
|
1085 GetStringFromConfig(aSection, KExeNameKey(), programName) ) |
|
1086 { |
|
1087 // Get optional params from INI file |
|
1088 TBuf<KTEFMaxNameLength> cmdLineArgs; |
|
1089 GetArgsFromConfig(aSection, cmdLineArgs); |
|
1090 TInt noOfCalls = 1; |
|
1091 GetIntFromConfig(aSection, KNoOfCallsKey(), noOfCalls); |
|
1092 TInt minSize = 1; |
|
1093 GetIntFromConfig(aSection, KMinSizeKey(), minSize); |
|
1094 TInt noOfAllowedTimeouts = 0; |
|
1095 GetIntFromConfig(aSection, KNoOfAllowedTimeoutsKey(), noOfAllowedTimeouts); |
|
1096 TInt minIncrease = 0; |
|
1097 GetIntFromConfig(aSection, KMinIncreaseKey(), minIncrease); |
|
1098 |
|
1099 // Create timer for time-outs |
|
1100 RTimer timer; |
|
1101 TInt err = timer.CreateLocal(); |
|
1102 CleanupClosePushL(timer); |
|
1103 if (err != KErrNone) |
|
1104 { |
|
1105 ERR_PRINTF2(_L("Create timer error %d"), err); |
|
1106 SetBlockResult(EFail); |
|
1107 } |
|
1108 |
|
1109 // Keep calling an EXE so that trace data is created in output file |
|
1110 // Tracing must be started and the EXE must generate trace data for the config file used |
|
1111 // The output file must exist and already contain some data |
|
1112 // Get current size of output file, and check it is non-zero or min provided |
|
1113 TInt originalFileSize = CheckFileSize(file, minSize, -1); |
|
1114 if (originalFileSize < 0) |
|
1115 { |
|
1116 // An error has occurred in checking the file size. Stop and fail the test |
|
1117 ERR_PRINTF2(_L("Error in file size %d"), originalFileSize); |
|
1118 SetBlockResult(EFail); |
|
1119 } |
|
1120 else |
|
1121 { |
|
1122 TInt currentFileSize = 0; |
|
1123 TInt noOfTimeouts = 0; |
|
1124 while (currentFileSize < maxSize) |
|
1125 { |
|
1126 TRequestStatus notifyStatus(KRequestPending); |
|
1127 TRequestStatus timerStatus(KRequestPending); |
|
1128 // Start timeout timer |
|
1129 timer.After(timerStatus, duration * KSecondsToMicroSeconds); |
|
1130 // Request notification of file change |
|
1131 iFs.NotifyChange(ENotifyAll, notifyStatus, file); |
|
1132 |
|
1133 // Call the EXE |
|
1134 RunProcess(programName, cmdLineArgs, noOfCalls); |
|
1135 |
|
1136 // Wait for file to update or timeout |
|
1137 User::WaitForRequest(notifyStatus, timerStatus); |
|
1138 |
|
1139 if (timerStatus == KErrNone) |
|
1140 { |
|
1141 // We have timed out |
|
1142 noOfTimeouts++; |
|
1143 WARN_PRINTF3(_L("Have not received notification of file change in %d seconds (%d tries remaining)"), duration, noOfAllowedTimeouts-noOfTimeouts+1); |
|
1144 } |
|
1145 else |
|
1146 { |
|
1147 // Cancel timer |
|
1148 timer.Cancel(); |
|
1149 } |
|
1150 |
|
1151 if (notifyStatus == KErrNone) |
|
1152 { |
|
1153 // We have received file change notification |
|
1154 INFO_PRINTF2(_L("Have received notification of file change (%S)"), &file); |
|
1155 } |
|
1156 else |
|
1157 { |
|
1158 // Cancel file change notification |
|
1159 iFs.NotifyChangeCancel(); |
|
1160 } |
|
1161 |
|
1162 // We get a timeout when output file is not updated and so there are dropped traces. |
|
1163 // This test is only checking append functionality so we allow this for a user-defined number of times. |
|
1164 if (noOfTimeouts > noOfAllowedTimeouts) |
|
1165 { |
|
1166 // We have timed out too many times, so fail the test |
|
1167 ERR_PRINTF2(_L("File has not been updated %d times"), noOfTimeouts); |
|
1168 SetBlockResult(EFail); |
|
1169 break; |
|
1170 } |
|
1171 |
|
1172 // Check the size of output file is expected size |
|
1173 currentFileSize = CheckFileSize(file, originalFileSize + minIncrease, -1); |
|
1174 if (currentFileSize < 0) |
|
1175 { |
|
1176 // An error has occurred in checking the file size. Stop and fail the test |
|
1177 ERR_PRINTF2(_L("Error in file size %d"), currentFileSize); |
|
1178 SetBlockResult(EFail); |
|
1179 break; |
|
1180 } |
|
1181 originalFileSize = currentFileSize; |
|
1182 } |
|
1183 } |
|
1184 CleanupStack::PopAndDestroy(&timer); // close timer |
|
1185 } |
|
1186 else |
|
1187 { |
|
1188 ERR_PRINTF4(_L("Need %S, %S and %S in INI file"), &KMaxSizeKey(), &KExeNameKey(), &KDurationKey()); |
|
1189 SetBlockResult(EFail); |
|
1190 } |
|
1191 } |
|
1192 |
|
1193 /** |
|
1194 * Test command to verify the trace buffer contains the expected number of given printf traces |
|
1195 */ |
|
1196 void CTraceCoreDataWrapper::DoCmdVerifyTraceDataL(const TTEFSectionName& aSection) |
|
1197 { |
|
1198 TBuf<KLongStringLength> findString; |
|
1199 // Get all required parameters from INI file |
|
1200 if (GetLongStringFromConfig(aSection, KFindStringKey(), findString)) |
|
1201 { |
|
1202 TInt expectedNumFound = 1; |
|
1203 GetIntFromConfig(aSection, KExpectedKey(), expectedNumFound); |
|
1204 TInt numFound = 0; |
|
1205 BufferHasPrintfStringL(iTraceBuffer, findString, numFound); |
|
1206 if (numFound != expectedNumFound) |
|
1207 { |
|
1208 ERR_PRINTF3(_L("Expected printf %d times, found it %d times"), expectedNumFound, numFound); |
|
1209 if (numFound == 0) |
|
1210 { |
|
1211 SetError(KErrNotFound); |
|
1212 } |
|
1213 else |
|
1214 { |
|
1215 SetError(KErrGeneral); |
|
1216 } |
|
1217 } |
|
1218 } |
|
1219 else |
|
1220 { |
|
1221 ERR_PRINTF2(_L("Need %S in INI file"), &KFindStringKey()); |
|
1222 SetBlockResult(EFail); |
|
1223 } |
|
1224 } |
|
1225 |
|
1226 /** |
|
1227 * Test command to verify the output file contains the expected number of traces / priming traces |
|
1228 * and optionally validates that the priming data contains the correct values |
|
1229 * |
|
1230 * This function gets the number of traces / priming traces and stores them in the required slots |
|
1231 * so the values can be verified later |
|
1232 */ |
|
1233 void CTraceCoreDataWrapper::DoCmdVerifyPrimingDataL(const TTEFSectionName& aSection) |
|
1234 { |
|
1235 TFileName filePath; |
|
1236 TInt groupId; |
|
1237 // Get all required parameters from INI file |
|
1238 if ( GetPathFromConfig(aSection, KFileKey(), filePath) && |
|
1239 GetIntFromConfig(aSection, KGroupIdKey(), groupId) ) |
|
1240 { |
|
1241 // Get optional params from INI file |
|
1242 TBool verifyData = EFalse; |
|
1243 GetBoolFromConfig(aSection, KVerifyData(), verifyData); |
|
1244 |
|
1245 TInt numTraces = 0; |
|
1246 TInt numPrimingTraces = 0; |
|
1247 VerifyPrimingDataL(filePath, groupId, verifyData, numTraces, numPrimingTraces); |
|
1248 |
|
1249 // Store numbers in slots for future use, if slot numbers are given |
|
1250 TInt slotNumber; |
|
1251 if (GetIntFromConfig(aSection, KTracesSlotNumberKey(), slotNumber)) |
|
1252 { |
|
1253 StoreInSlot(numTraces, slotNumber); |
|
1254 } |
|
1255 if (GetIntFromConfig(aSection, KPrimingTracesSlotNumberKey(), slotNumber)) |
|
1256 { |
|
1257 StoreInSlot(numPrimingTraces, slotNumber); |
|
1258 } |
|
1259 } |
|
1260 else |
|
1261 { |
|
1262 ERR_PRINTF2(_L("Need %S in INI file"), &KGroupIdKey()); |
|
1263 SetBlockResult(EFail); |
|
1264 } |
|
1265 } |
|
1266 |
|
1267 /** |
|
1268 * This function gets the number of traces / priming traces from the data file given for the required GID |
|
1269 * It optionally validates that the priming data contains the correct values |
|
1270 */ |
|
1271 void CTraceCoreDataWrapper::VerifyPrimingDataL(const TDesC& aFile, TInt aGroupId, TBool aVerifyData, TInt& aNumTraces, TInt& aNumPrimingTraces) |
|
1272 { |
|
1273 INFO_PRINTF3(_L("VerifyPrimingData aFile (%S) aGroupId (%d)"), &aFile, aGroupId); |
|
1274 |
|
1275 aNumTraces = 0; |
|
1276 aNumPrimingTraces = 0; |
|
1277 |
|
1278 INFO_PRINTF3(_L("Calling TTraceDataParser::ParsePrimingDataL(%S, %d)"), &aFile, aGroupId); |
|
1279 TInt err = TTraceDataParser::ParsePrimingDataL(aFile, iFs, aGroupId, aNumPrimingTraces, aNumTraces, aVerifyData); |
|
1280 INFO_PRINTF3(_L("Number of traces for GID %d: %d"), aGroupId, aNumTraces); |
|
1281 INFO_PRINTF3(_L("Number of priming traces for GID %d: %d"), aGroupId, aNumPrimingTraces); |
|
1282 if (err != KErrNone) |
|
1283 { |
|
1284 ERR_PRINTF2(_L("ParsePrimingDataL() error %d"), err); |
|
1285 SetError(err); |
|
1286 } |
|
1287 } |
|
1288 |
|
1289 /** |
|
1290 * Test command to verify the output file contains the expected sequence of traces |
|
1291 * and checks that any dropped traces are correctly handled |
|
1292 */ |
|
1293 void CTraceCoreDataWrapper::DoCmdVerifyDroppedTracesL(const TTEFSectionName& aSection) |
|
1294 { |
|
1295 TFileName filePath; |
|
1296 // Get all required parameters from INI file |
|
1297 if (GetPathFromConfig(aSection, KFileKey(), filePath)) |
|
1298 { |
|
1299 TInt lastNumberFound = 0; |
|
1300 TInt numDroppedTraces = 0; |
|
1301 |
|
1302 TPtrC findString; |
|
1303 // Look to see if we have a string to fing |
|
1304 if (GetStringFromConfig(aSection, KFindStringKey(), findString)) |
|
1305 { |
|
1306 VerifyDroppedPrintfTracesL(filePath, findString, lastNumberFound, numDroppedTraces); |
|
1307 } |
|
1308 else |
|
1309 { |
|
1310 TInt groupId = 0; |
|
1311 GetIntFromConfig(aSection, KGroupIdKey(), groupId); |
|
1312 TInt componentId = 0; |
|
1313 GetHexFromConfig(aSection, KComponentIdKey(), componentId); |
|
1314 VerifyDroppedBinaryTracesL(filePath, groupId, componentId, lastNumberFound, numDroppedTraces); |
|
1315 } |
|
1316 |
|
1317 TInt expectedLastNumberFound; |
|
1318 if (GetIntFromConfig(aSection, KExpectedKey(), expectedLastNumberFound)) |
|
1319 { |
|
1320 if (expectedLastNumberFound == lastNumberFound) |
|
1321 { |
|
1322 INFO_PRINTF2(_L("Last number found (%d) as expected"), lastNumberFound); |
|
1323 } |
|
1324 else |
|
1325 { |
|
1326 ERR_PRINTF3(_L("Last number found (%d) not as expected (%d)"), lastNumberFound, expectedLastNumberFound); |
|
1327 SetBlockResult(EFail); |
|
1328 } |
|
1329 } |
|
1330 } |
|
1331 } |
|
1332 |
|
1333 /** |
|
1334 * This function verifies the given file contains the expected sequence of printf traces |
|
1335 * and checks that any dropped traces are correctly handled |
|
1336 */ |
|
1337 void CTraceCoreDataWrapper::VerifyDroppedPrintfTracesL(const TDesC& aFile, const TDesC& aFindString, TInt& aLastNumberFound, TInt& aNumDroppedTraces) |
|
1338 { |
|
1339 INFO_PRINTF3(_L("VerifyDroppedPrintfTracesL aFile (%S) aFindString (%S)"), &aFile, &aFindString); |
|
1340 |
|
1341 aLastNumberFound = 0; |
|
1342 aNumDroppedTraces = 0; |
|
1343 |
|
1344 TBuf8<KTEFMaxNameLength> findString; |
|
1345 findString.Copy(aFindString); |
|
1346 INFO_PRINTF3(_L("Calling TTraceDataParser::DataHasTraceSequenceL(%S, \"%S\")"), &aFile, &aFindString); |
|
1347 TInt err = TTraceDataParser::DataHasTraceSequenceL(aFile, iFs, aLastNumberFound, aNumDroppedTraces, &findString); |
|
1348 INFO_PRINTF3(_L("Last number found is %d, (%d dropped traces)"), aLastNumberFound, aNumDroppedTraces); |
|
1349 if (err != KErrNone) |
|
1350 { |
|
1351 ERR_PRINTF2(_L("DataHasTraceSequenceL() error %d"), err); |
|
1352 SetError(err); |
|
1353 } |
|
1354 } |
|
1355 |
|
1356 /** |
|
1357 * This function verifies the given file contains the expected sequence of binary traces |
|
1358 * and checks that any dropped traces are correctly handled |
|
1359 */ |
|
1360 void CTraceCoreDataWrapper::VerifyDroppedBinaryTracesL(const TDesC& aFile, TInt aGroupId, TInt aComponentId, TInt& aLastNumberFound, TInt& aNumDroppedTraces) |
|
1361 { |
|
1362 INFO_PRINTF4(_L("VerifyDroppedBinaryTracesL aFile (%S) aGroupId (%d) aComponentId (0x%x)"), &aFile, aGroupId, aComponentId); |
|
1363 |
|
1364 aLastNumberFound = 0; |
|
1365 aNumDroppedTraces = 0; |
|
1366 |
|
1367 INFO_PRINTF4(_L("Calling TTraceDataParser::DataHasTraceSequenceL(%S, %d, 0x%x)"), &aFile, aGroupId, aComponentId); |
|
1368 TInt err = TTraceDataParser::DataHasTraceSequenceL(aFile, iFs, aLastNumberFound, aNumDroppedTraces, NULL, aGroupId, aComponentId); |
|
1369 INFO_PRINTF3(_L("Last number found is %d, (%d dropped traces)"), aLastNumberFound, aNumDroppedTraces); |
|
1370 if (err != KErrNone) |
|
1371 { |
|
1372 ERR_PRINTF2(_L("DataHasTraceSequenceL() error %d"), err); |
|
1373 SetError(err); |
|
1374 } |
|
1375 } |
|
1376 |
|
1377 /** |
|
1378 * This function checks if printf traces in the data file given contain a given string |
|
1379 */ |
|
1380 void CTraceCoreDataWrapper::FileHasPrintfStringL(const TDesC& aFile, const TDesC& aFindString, TInt& aNumFound) |
|
1381 { |
|
1382 INFO_PRINTF3(_L("FileHasPrintfStringL aFile (%S) aFindString (%S)"), &aFile, &aFindString); |
|
1383 aNumFound = 0; |
|
1384 TBuf8<KTEFMaxNameLength> findString; |
|
1385 findString.Copy(aFindString); |
|
1386 INFO_PRINTF3(_L("Calling TTraceDataParser::DataHasPrintfStringL(%S, \"%S\")"), &aFile, &aFindString); |
|
1387 TInt err = TTraceDataParser::DataHasPrintfStringL(aFile, iFs, findString, aNumFound); |
|
1388 INFO_PRINTF2(_L("Data in file contains string %d times"), aNumFound); |
|
1389 if (err != KErrNone) |
|
1390 { |
|
1391 ERR_PRINTF2(_L("DataHasPrintfString() error %d"), err); |
|
1392 SetError(err); |
|
1393 } |
|
1394 } |
|
1395 |
|
1396 /** |
|
1397 * This function checks if printf traces in the data buffer given contain a given string |
|
1398 */ |
|
1399 void CTraceCoreDataWrapper::BufferHasPrintfStringL(TDesC8& aBuffer, const TDesC& aFindString, TInt& aNumFound) |
|
1400 { |
|
1401 INFO_PRINTF2(_L("BufferHasPrintfStringL aFindString (%S)"), &aFindString); |
|
1402 aNumFound = 0; |
|
1403 TBuf8<KTEFMaxNameLength> findString; |
|
1404 findString.Copy(aFindString); |
|
1405 INFO_PRINTF2(_L("Calling TTraceDataParser::DataHasPrintfString(\"%S\")"), &aFindString); |
|
1406 TInt err = TTraceDataParser::DataHasPrintfString(aBuffer, findString, aNumFound); |
|
1407 INFO_PRINTF2(_L("Data in buffer contains string %d times"), aNumFound); |
|
1408 if (err != KErrNone) |
|
1409 { |
|
1410 ERR_PRINTF2(_L("DataHasPrintfString() error %d"), err); |
|
1411 SetError(err); |
|
1412 } |
|
1413 } |
|
1414 |
|
1415 TInt CTraceCoreDataWrapper::GetSlotValue(const TTEFSectionName& aSection, const TDesC& aValueKey, const TDesC& aSlotNumberKey) |
|
1416 { |
|
1417 TInt value = 0; |
|
1418 TInt slot; |
|
1419 if (GetIntFromConfig(aSection, aValueKey, value)) |
|
1420 { |
|
1421 // Value given directly in INI file, so don't need slot number |
|
1422 if (GetIntFromConfig(aSection, aSlotNumberKey, slot)) |
|
1423 { |
|
1424 ERR_PRINTF3(_L("Cannot have %S and %S in INI file"), &aValueKey, &aSlotNumberKey); |
|
1425 SetBlockResult(EFail); |
|
1426 } |
|
1427 } |
|
1428 else if (GetIntFromConfig(aSection, aSlotNumberKey, slot)) |
|
1429 { |
|
1430 // Slot number given in INI file, so get value from it |
|
1431 value = ReadFromSlot(slot); |
|
1432 } |
|
1433 else |
|
1434 { |
|
1435 ERR_PRINTF3(_L("Need %S or %S in INI file"), &aValueKey, &aSlotNumberKey); |
|
1436 SetBlockResult(EFail); |
|
1437 } |
|
1438 return value; |
|
1439 } |
|
1440 |
|
1441 void CTraceCoreDataWrapper::DoCmdVerifySlot(const TTEFSectionName& aSection) |
|
1442 { |
|
1443 // Get values to compare |
|
1444 TInt valueA = GetSlotValue(aSection, KValueAKey(), KSlotANumberKey()); |
|
1445 TInt valueB = GetSlotValue(aSection, KValueBKey(), KSlotBNumberKey()); |
|
1446 |
|
1447 // Compare the values |
|
1448 INFO_PRINTF3(_L("Comparing value A (%d) with value B (%d)"), valueA, valueB); |
|
1449 |
|
1450 TInt difference = 0; |
|
1451 TInt minDifference = -1; |
|
1452 TInt maxDifference = -1; |
|
1453 if (GetIntFromConfig(aSection, KDifferenceKey(), difference)) |
|
1454 { |
|
1455 if (difference != 0) |
|
1456 { |
|
1457 minDifference = difference; |
|
1458 maxDifference = difference; |
|
1459 } |
|
1460 } |
|
1461 else |
|
1462 { |
|
1463 GetIntFromConfig(aSection, KMinDifferenceKey(), minDifference); |
|
1464 GetIntFromConfig(aSection, KMaxDifferenceKey(), maxDifference); |
|
1465 } |
|
1466 if ( (minDifference == -1) && (maxDifference == -1) && (valueA != valueB) ) |
|
1467 { |
|
1468 ERR_PRINTF1(_L("Values are not the same")); |
|
1469 SetBlockResult(EFail); |
|
1470 } |
|
1471 else if ( (minDifference != -1 && valueB - valueA < minDifference) || |
|
1472 (maxDifference != -1 && valueB - valueA > maxDifference) ) |
|
1473 { |
|
1474 ERR_PRINTF1(_L("Difference in values not in given range")); |
|
1475 SetBlockResult(EFail); |
|
1476 } |
|
1477 else |
|
1478 { |
|
1479 INFO_PRINTF1(_L("Slot value successfully verified")); |
|
1480 } |
|
1481 } |
|
1482 |
|
1483 void CTraceCoreDataWrapper::StoreInSlot(TInt aEntry, TInt aSlot) |
|
1484 { |
|
1485 if (aSlot >= 1 && aSlot <= iSlots.Count()) |
|
1486 { |
|
1487 iSlots[aSlot-1] = aEntry; |
|
1488 INFO_PRINTF3(_L("Storing number %d in slot %d"), aEntry, aSlot); |
|
1489 } |
|
1490 else |
|
1491 { |
|
1492 ERR_PRINTF3(_L("Cannot store number in slot %d - not in range [1,%d]"), aSlot, iSlots.Count()); |
|
1493 SetBlockResult(EFail); |
|
1494 } |
|
1495 } |
|
1496 |
|
1497 TInt CTraceCoreDataWrapper::ReadFromSlot(TInt aSlot) |
|
1498 { |
|
1499 TInt entry = 0; |
|
1500 if (aSlot >= 1 && aSlot <= iSlots.Count()) |
|
1501 { |
|
1502 entry = iSlots[aSlot-1]; |
|
1503 INFO_PRINTF3(_L("Reading number %d from slot %d"), entry, aSlot); |
|
1504 } |
|
1505 else |
|
1506 { |
|
1507 ERR_PRINTF3(_L("Cannot read number from slot %d - not in range [1,%d]"), aSlot, iSlots.Count()); |
|
1508 SetBlockResult(EFail); |
|
1509 } |
|
1510 return entry; |
|
1511 } |
|
1512 |
|
1513 void CTraceCoreDataWrapper::DoCmdFileChangeNotification(const TTEFSectionName& aSection, const TInt aAsyncErrorIndex) |
|
1514 { |
|
1515 TFileName file; |
|
1516 TInt duration; |
|
1517 // Get all required parameters from INI file |
|
1518 if ( GetPathFromConfig(aSection, KFileKey(), file) && |
|
1519 GetIntFromConfig(aSection, KDurationKey(), duration) ) |
|
1520 { |
|
1521 INFO_PRINTF2(_L("Requesting file change notification for file %S"), &file); |
|
1522 // Request notification of file change |
|
1523 iFs.NotifyChange(ENotifyAll, iActiveFileChangeNotification->iStatus, file); |
|
1524 iActiveFileChangeNotification->Activate(aAsyncErrorIndex); |
|
1525 IncOutstanding(); |
|
1526 // Start timeout timer |
|
1527 iTimer.After(iActiveFileChangeNotificationTimeout->iStatus, duration * KSecondsToMicroSeconds); |
|
1528 iActiveFileChangeNotificationTimeout->Activate(aAsyncErrorIndex); |
|
1529 IncOutstanding(); |
|
1530 iCurrentSectionName.Set(aSection); |
|
1531 } |
|
1532 else |
|
1533 { |
|
1534 ERR_PRINTF2(_L("Need %S in INI file"), &KDurationKey()); |
|
1535 SetBlockResult(EFail); |
|
1536 } |
|
1537 } |
|
1538 |
|
1539 void CTraceCoreDataWrapper::RunL(CActive* aActive, TInt aIndex) |
|
1540 { |
|
1541 if (aActive == iActiveFileChangeNotification) |
|
1542 { |
|
1543 TInt err = iActiveFileChangeNotification->iStatus.Int(); |
|
1544 if (err == KErrNone) |
|
1545 { |
|
1546 INFO_PRINTF1(_L("Received file change notification")); |
|
1547 } |
|
1548 else |
|
1549 { |
|
1550 WARN_PRINTF2(_L("File change notification error %d"), err); |
|
1551 } |
|
1552 |
|
1553 TBool fileReady = ETrue; |
|
1554 if (err != KErrNone) |
|
1555 { |
|
1556 fileReady = EFalse; |
|
1557 } |
|
1558 TPtrC findString; |
|
1559 // Look to see if we have a string to find |
|
1560 if (GetStringFromConfig(iCurrentSectionName, KFindStringKey(), findString)) |
|
1561 { |
|
1562 fileReady = EFalse; |
|
1563 TFileName file; |
|
1564 if (GetPathFromConfig(iCurrentSectionName, KFileKey(), file)) |
|
1565 { |
|
1566 // The file is ready if it contains the string given in the INI file |
|
1567 TInt expectedNumFound = 1; |
|
1568 GetIntFromConfig(iCurrentSectionName, KExpectedKey(), expectedNumFound); |
|
1569 TInt numFound = 0; |
|
1570 FileHasPrintfStringL(file, findString, numFound); |
|
1571 if (numFound == expectedNumFound) |
|
1572 { |
|
1573 fileReady = ETrue; |
|
1574 } |
|
1575 } |
|
1576 if (!fileReady && err == KErrNone) |
|
1577 { |
|
1578 // File isn't ready, so request notification again |
|
1579 // Keep doing this until file is ready or it times out |
|
1580 INFO_PRINTF2(_L("Requesting file change notification for file %S"), &file); |
|
1581 iFs.NotifyChange(ENotifyAll, iActiveFileChangeNotification->iStatus, file); |
|
1582 iActiveFileChangeNotification->Activate(aIndex); |
|
1583 IncOutstanding(); |
|
1584 } |
|
1585 } |
|
1586 if (fileReady) |
|
1587 { |
|
1588 // Cancel file change notification timeout |
|
1589 iTimer.Cancel(); |
|
1590 } |
|
1591 else if (err != KErrNone) |
|
1592 { |
|
1593 ERR_PRINTF2(_L("File change notification error %d"), err); |
|
1594 SetAsyncError(aIndex, err); |
|
1595 } |
|
1596 DecOutstanding(); |
|
1597 } |
|
1598 else if (aActive == iActiveFileChangeNotificationTimeout) |
|
1599 { |
|
1600 TInt err = iActiveFileChangeNotificationTimeout->iStatus.Int(); |
|
1601 if (err == KErrNone) |
|
1602 { |
|
1603 INFO_PRINTF1(_L("File change notification has timed out")); |
|
1604 // Cancel file change notification |
|
1605 iFs.NotifyChangeCancel(); |
|
1606 } |
|
1607 else if (err != KErrCancel) |
|
1608 { |
|
1609 ERR_PRINTF2(_L("File change notification timeout error %d"), err); |
|
1610 SetAsyncError(aIndex, err); |
|
1611 } |
|
1612 DecOutstanding(); |
|
1613 } |
|
1614 else |
|
1615 { |
|
1616 ERR_PRINTF1(_L("Stray signal")); |
|
1617 SetBlockResult(EFail); |
|
1618 } |
|
1619 } |
|
1620 |
|
1621 void CTraceCoreDataWrapper::DoCancel(CActive* aActive, TInt /*aIndex*/) |
|
1622 { |
|
1623 if (aActive == iActiveFileChangeNotification) |
|
1624 { |
|
1625 INFO_PRINTF1(_L("File change notification cancelled")); |
|
1626 } |
|
1627 else if (aActive == iActiveFileChangeNotificationTimeout) |
|
1628 { |
|
1629 INFO_PRINTF1(_L("File change notification timeout cancelled")); |
|
1630 } |
|
1631 else |
|
1632 { |
|
1633 ERR_PRINTF1(_L("Stray signal")); |
|
1634 SetBlockResult(EFail); |
|
1635 } |
|
1636 } |
|
1637 |
|
1638 void CTraceCoreDataWrapper::DoCmdRegisterNotifReceiver(const TTEFSectionName& aSection) |
|
1639 { |
|
1640 TInt groupId; |
|
1641 TInt componentId; |
|
1642 // Get all required parameters from INI file |
|
1643 if ( GetIntFromConfig(aSection, KGroupIdKey(), groupId) && |
|
1644 GetHexFromConfig(aSection, KComponentIdKey(), componentId) ) |
|
1645 { |
|
1646 TTraceOnActivationParams traceOnActivationParams; |
|
1647 traceOnActivationParams.iGroupId = groupId; |
|
1648 traceOnActivationParams.iComponentId = componentId; |
|
1649 |
|
1650 TInt err = iTraceOnActivationLdd.RegisterNotificationReceiver(traceOnActivationParams); |
|
1651 if (err != KErrNone) |
|
1652 { |
|
1653 ERR_PRINTF4(_L("RegisterNotificationReceiver(%d,0x%x) error %d"), groupId, componentId, err); |
|
1654 SetError(err); |
|
1655 } |
|
1656 else |
|
1657 { |
|
1658 INFO_PRINTF3(_L("RegisterNotificationReceiver(%d,0x%x) returns no error"), groupId, componentId); |
|
1659 } |
|
1660 } |
|
1661 else |
|
1662 { |
|
1663 ERR_PRINTF3(_L("Need %S and %S in INI file"), &KGroupIdKey(), &KComponentIdKey()); |
|
1664 SetBlockResult(EFail); |
|
1665 } |
|
1666 } |
|
1667 |
|
1668 void CTraceCoreDataWrapper::DoCmdUnregisterNotifReceiver(const TTEFSectionName& aSection) |
|
1669 { |
|
1670 TInt groupId; |
|
1671 TInt componentId; |
|
1672 // Get all required parameters from INI file |
|
1673 if ( GetIntFromConfig(aSection, KGroupIdKey(), groupId) && |
|
1674 GetHexFromConfig(aSection, KComponentIdKey(), componentId) ) |
|
1675 { |
|
1676 TTraceOnActivationParams traceOnActivationParams; |
|
1677 traceOnActivationParams.iGroupId = groupId; |
|
1678 traceOnActivationParams.iComponentId = componentId; |
|
1679 |
|
1680 TInt err = iTraceOnActivationLdd.UnregisterNotificationReceiver(traceOnActivationParams); |
|
1681 if (err != KErrNone) |
|
1682 { |
|
1683 ERR_PRINTF4(_L("UnregisterNotificationReceiver(%d,0x%x) error %d"), groupId, componentId, err); |
|
1684 SetError(err); |
|
1685 } |
|
1686 else |
|
1687 { |
|
1688 INFO_PRINTF3(_L("UnregisterNotificationReceiver(%d,0x%x) returns no error"), groupId, componentId); |
|
1689 } |
|
1690 } |
|
1691 else |
|
1692 { |
|
1693 ERR_PRINTF3(_L("Need %S and %S in INI file"), &KGroupIdKey(), &KComponentIdKey()); |
|
1694 SetBlockResult(EFail); |
|
1695 } |
|
1696 } |
|
1697 |
|
1698 void CTraceCoreDataWrapper::InstrumentBinaryTracePoint(TInt aGroupId, TInt aComponentId, TInt aData, TInt aTraceId) |
|
1699 { |
|
1700 TComponentId KOstTraceComponentID = aComponentId; |
|
1701 // Calculate trace word from Group ID |
|
1702 TUint32 traceWord = (aGroupId << GROUPIDSHIFT) | aTraceId; |
|
1703 OstTrace1(aGroupId, traceWord, "You will only see this text in Trace Viewer: %d", aData); |
|
1704 } |
|
1705 |
|
1706 void CTraceCoreDataWrapper::InstrumentBinaryTraceSequence(TInt aSequenceLength, TInt aGroupId, TInt aComponentId) |
|
1707 { |
|
1708 for (TInt i=1; i<=aSequenceLength; i++) |
|
1709 { |
|
1710 InstrumentBinaryTracePoint(aGroupId, aComponentId, i, i); |
|
1711 } |
|
1712 } |
|
1713 |
|
1714 void CTraceCoreDataWrapper::InstrumentPrintfTraceSequence(TInt aSequenceLength, const TDesC& aString) |
|
1715 { |
|
1716 INFO_PRINTF3(_L("InstrumentPrintfTraceSequence(%d, \"%S\""), aSequenceLength, &aString); |
|
1717 TBuf8<KTEFMaxNameLength> givenString; |
|
1718 givenString.Copy(aString); |
|
1719 for (TInt i=1; i<=aSequenceLength; i++) |
|
1720 { |
|
1721 TBuf8<KTEFMaxNameLength> formattedString; |
|
1722 formattedString.Format(givenString, i); |
|
1723 RDebug::Printf("%S", &formattedString); |
|
1724 } |
|
1725 } |
|
1726 |
|
1727 void CTraceCoreDataWrapper::DoCmdInstrumentTraceSequence(const TTEFSectionName& aSection) |
|
1728 { |
|
1729 TInt sequenceLength; |
|
1730 // Get all required parameters from INI file |
|
1731 if (GetIntFromConfig(aSection, KLengthKey(), sequenceLength)) |
|
1732 { |
|
1733 TPtrC printfString; |
|
1734 if (GetStringFromConfig(aSection, KStringKey(), printfString)) |
|
1735 { |
|
1736 InstrumentPrintfTraceSequence(sequenceLength, printfString); |
|
1737 } |
|
1738 else |
|
1739 { |
|
1740 TInt groupId = 0; |
|
1741 GetIntFromConfig(aSection, KGroupIdKey(), groupId); |
|
1742 TInt componentId = 0; |
|
1743 GetHexFromConfig(aSection, KComponentIdKey(), componentId); |
|
1744 InstrumentBinaryTraceSequence(sequenceLength, groupId, componentId); |
|
1745 } |
|
1746 } |
|
1747 else |
|
1748 { |
|
1749 ERR_PRINTF2(_L("Need %S in INI file"), &KLengthKey()); |
|
1750 SetBlockResult(EFail); |
|
1751 } |
|
1752 } |
|
1753 |
|
1754 TInt CTraceCoreDataWrapper::LoadLdd(const TDesC& aLddName, TBool aSingleUse) |
|
1755 { |
|
1756 TInt err = User::LoadLogicalDevice(aLddName); |
|
1757 if (err == KErrNone) |
|
1758 { |
|
1759 INFO_PRINTF2(_L("LDD %S successfully loaded with no error"), &aLddName); |
|
1760 } |
|
1761 else if (err == KErrAlreadyExists && !aSingleUse) |
|
1762 { |
|
1763 INFO_PRINTF2(_L("LDD %S was already loaded"), &aLddName); |
|
1764 } |
|
1765 else |
|
1766 { |
|
1767 ERR_PRINTF3(_L("LoadLogicalDevice(%S) error %d"), &aLddName, err); |
|
1768 SetError(err); |
|
1769 } |
|
1770 return err; |
|
1771 } |
|
1772 |
|
1773 TBool CTraceCoreDataWrapper::LoadLdd(const TDesC& aLddName, const TTEFSectionName& aSection) |
|
1774 { |
|
1775 TBool singleUse = EFalse; |
|
1776 GetBoolFromConfig(aSection, KSingleUseKey(), singleUse); |
|
1777 |
|
1778 TBool isLoadedAlready = EFalse; |
|
1779 TInt err = LoadLdd(aLddName, singleUse); |
|
1780 if (!singleUse) |
|
1781 { |
|
1782 isLoadedAlready = (err == KErrAlreadyExists); |
|
1783 } |
|
1784 |
|
1785 return isLoadedAlready; |
|
1786 } |
|
1787 |
|
1788 TInt CTraceCoreDataWrapper::FreeLdd(const TDesC& aLddName) |
|
1789 { |
|
1790 TInt err = User::FreeLogicalDevice(aLddName); |
|
1791 if (err == KErrNone) |
|
1792 { |
|
1793 INFO_PRINTF2(_L("LDD %S successfully freed with no error"), &aLddName); |
|
1794 } |
|
1795 else |
|
1796 { |
|
1797 ERR_PRINTF3(_L("FreeLogicalDevice(%S) error %d"), &aLddName, err); |
|
1798 //Won't set error from this until |
|
1799 //issue with always returning KErrInUse |
|
1800 //User::FreeLogicalDevice() is resolved |
|
1801 //SetError(err); |
|
1802 } |
|
1803 return err; |
|
1804 } |
|
1805 |
|
1806 template <class T> |
|
1807 TInt CTraceCoreDataWrapper::OpenLdd(const TDesC& aLddName, T& aLdd) |
|
1808 { |
|
1809 TInt err = aLdd.Open(); |
|
1810 if (err != KErrNone) |
|
1811 { |
|
1812 ERR_PRINTF3(_L("%S Open() error %d"), &aLddName, err); |
|
1813 SetError(err); |
|
1814 } |
|
1815 else |
|
1816 { |
|
1817 INFO_PRINTF2(_L("%S successfully set up"), &aLddName); |
|
1818 } |
|
1819 return err; |
|
1820 } |
|
1821 |
|
1822 template <class T> |
|
1823 TBool CTraceCoreDataWrapper::OpenLdd(const TDesC& aLddName, T& aLdd, const TTEFSectionName& aSection) |
|
1824 { |
|
1825 TBool openLdd = ETrue; |
|
1826 GetBoolFromConfig(aSection, KOpenLddKey(), openLdd); |
|
1827 |
|
1828 if (openLdd) |
|
1829 { |
|
1830 OpenLdd(aLddName, aLdd); |
|
1831 } |
|
1832 |
|
1833 return openLdd; |
|
1834 } |
|
1835 |
|
1836 void CTraceCoreDataWrapper::DoCmdSetUpTcLdd(const TTEFSectionName& aSection) |
|
1837 { |
|
1838 iTcLddLoadedAtStart = LoadLdd(KTcLdd(), aSection); |
|
1839 |
|
1840 OpenLdd(KTcLdd(), iTcLdd, aSection); |
|
1841 } |
|
1842 |
|
1843 void CTraceCoreDataWrapper::DoCmdCleanUpTcLdd(const TTEFSectionName& aSection) |
|
1844 { |
|
1845 TBool closeLdd = ETrue; |
|
1846 GetBoolFromConfig(aSection, KCloseLddKey(), closeLdd); |
|
1847 |
|
1848 if (closeLdd) |
|
1849 { |
|
1850 iTcLdd.Close(); |
|
1851 } |
|
1852 |
|
1853 if (!iTcLddLoadedAtStart) |
|
1854 { |
|
1855 FreeLdd(KTcLdd()); |
|
1856 } |
|
1857 } |
|
1858 |
|
1859 void CTraceCoreDataWrapper::DoCmdSetUpTcOstLdd(const TTEFSectionName& aSection) |
|
1860 { |
|
1861 iTcOstLddLoadedAtStart = LoadLdd(KTraceCoreOstLdd(), aSection); |
|
1862 |
|
1863 if (OpenLdd(KTraceCoreOstLdd(), iTraceCoreOstLdd, aSection)) |
|
1864 { |
|
1865 //Switch to OstMemoryWriter |
|
1866 TUint32 writer(1); |
|
1867 iTraceCoreOstLdd.ChangeWriter(writer); |
|
1868 |
|
1869 TUint32 handle; |
|
1870 TInt err = iTraceCoreOstLdd.GetChunkHandle(handle); |
|
1871 if (err != KErrNone) |
|
1872 { |
|
1873 ERR_PRINTF2(_L("GetChunkHandle() error %d"), err); |
|
1874 SetError(err); |
|
1875 } |
|
1876 |
|
1877 TInt bufferSize = KDefaultBufferSize; |
|
1878 GetIntFromConfig(aSection, KBufferSizeKey(), bufferSize); |
|
1879 INFO_PRINTF2(_L("Calling SetBufferSize(%d)"), bufferSize); |
|
1880 err = iTraceCoreOstLdd.SetBufferSize((TUint32&) bufferSize); |
|
1881 if (err != KErrNone) |
|
1882 { |
|
1883 ERR_PRINTF2(_L("SetBufferSize() error %d"), err); |
|
1884 SetError(err); |
|
1885 } |
|
1886 } |
|
1887 } |
|
1888 |
|
1889 void CTraceCoreDataWrapper::DoCmdCleanUpTcOstLdd(const TTEFSectionName& aSection) |
|
1890 { |
|
1891 TBool closeLdd = ETrue; |
|
1892 GetBoolFromConfig(aSection, KCloseLddKey(), closeLdd); |
|
1893 |
|
1894 if (closeLdd) |
|
1895 { |
|
1896 iTraceBuffer.Close(); |
|
1897 //Switch back to XtiWriter |
|
1898 TUint32 writer(0); |
|
1899 iTraceCoreOstLdd.ChangeWriter(writer); |
|
1900 iTraceCoreOstLdd.Close(); |
|
1901 } |
|
1902 |
|
1903 if (!iTcOstLddLoadedAtStart) |
|
1904 { |
|
1905 FreeLdd(KTraceCoreOstLdd()); |
|
1906 } |
|
1907 } |
|
1908 |
|
1909 void CTraceCoreDataWrapper::DoCmdSetUpTraceOnActivation(const TTEFSectionName& aSection) |
|
1910 { |
|
1911 iTraceOnActivationLoadedAtStart = LoadLdd(KTraceOnActivationLdd(), aSection); |
|
1912 |
|
1913 OpenLdd(KTraceOnActivationLdd(), iTraceOnActivationLdd, aSection); |
|
1914 } |
|
1915 |
|
1916 void CTraceCoreDataWrapper::DoCmdCleanUpTraceOnActivation(const TTEFSectionName& aSection) |
|
1917 { |
|
1918 TBool closeLdd = ETrue; |
|
1919 GetBoolFromConfig(aSection, KCloseLddKey(), closeLdd); |
|
1920 |
|
1921 if (closeLdd) |
|
1922 { |
|
1923 iTraceOnActivationLdd.Close(); |
|
1924 } |
|
1925 |
|
1926 if (!iTraceOnActivationLoadedAtStart) |
|
1927 { |
|
1928 FreeLdd(KTraceOnActivationLdd()); |
|
1929 } |
|
1930 } |
|
1931 |
|
1932 void CTraceCoreDataWrapper::DoCmdActivateDeactivateTrace(const TTEFSectionName& aSection) |
|
1933 { |
|
1934 TInt groupId; |
|
1935 TInt componentId; |
|
1936 TBool activate; |
|
1937 // Get all required parameters from INI file |
|
1938 if ( GetIntFromConfig(aSection, KGroupIdKey(), groupId) && |
|
1939 GetHexFromConfig(aSection, KComponentIdKey(), componentId) && |
|
1940 GetBoolFromConfig(aSection, KActivateKey(), activate) ) |
|
1941 { |
|
1942 RTcDriverParameters tcDriverParameters; |
|
1943 tcDriverParameters.iGroupId = groupId; |
|
1944 tcDriverParameters.iComponentId = componentId; |
|
1945 tcDriverParameters.iActivation = EFalse; |
|
1946 TInt err = KErrNone; |
|
1947 if (activate) |
|
1948 { |
|
1949 INFO_PRINTF3(_L("Calling ActivateTrace(%d,0x%x)"), groupId, componentId); |
|
1950 err = iTcLdd.ActivateTrace(tcDriverParameters); |
|
1951 if (err != KErrNone) |
|
1952 { |
|
1953 ERR_PRINTF4(_L("ActivateTrace(%d,0x%x) error %d"), groupId, componentId, err); |
|
1954 SetError(err); |
|
1955 } |
|
1956 } |
|
1957 else |
|
1958 { |
|
1959 INFO_PRINTF3(_L("Calling DeactivateTrace(%d,0x%x)"), groupId, componentId); |
|
1960 err = iTcLdd.DeactivateTrace(tcDriverParameters); |
|
1961 if (err != KErrNone) |
|
1962 { |
|
1963 ERR_PRINTF4(_L("DeactivateTrace(%d,0x%x) error %d"), groupId, componentId, err); |
|
1964 SetError(err); |
|
1965 } |
|
1966 } |
|
1967 } |
|
1968 else |
|
1969 { |
|
1970 ERR_PRINTF4(_L("Need %S, %S and %S in INI file"), &KGroupIdKey(), &KComponentIdKey(), &KActivateKey()); |
|
1971 SetBlockResult(EFail); |
|
1972 } |
|
1973 } |
|
1974 |
|
1975 void CTraceCoreDataWrapper::DoCmdReadTracesFromBuffer() |
|
1976 { |
|
1977 iTraceBuffer.Close(); |
|
1978 TInt bufferSize = iTraceCoreOstLdd.GetBufferSize(); |
|
1979 |
|
1980 TInt err = iTraceBuffer.ReAlloc(bufferSize); |
|
1981 if (err != KErrNone) |
|
1982 { |
|
1983 ERR_PRINTF3(_L("ReAlloc(%d) error %d"), bufferSize, err); |
|
1984 SetError(err); |
|
1985 } |
|
1986 |
|
1987 INFO_PRINTF2(_L("Calling ReadNTraces() with buffer size %d"), bufferSize); |
|
1988 err = iTraceCoreOstLdd.ReadNTraces(iTraceBuffer); |
|
1989 if (err != KErrNone) |
|
1990 { |
|
1991 ERR_PRINTF2(_L("ReadNTraces() error %d"), err); |
|
1992 SetError(err); |
|
1993 } |
|
1994 else |
|
1995 { |
|
1996 INFO_PRINTF2(_L("%d bytes of trace data read"), iTraceBuffer.Size()); |
|
1997 // Print the trace data to the log, if there's not too much of it |
|
1998 if (iTraceBuffer.Size() <= KDefaultBufferSize && iTraceBuffer.Size() > 0) |
|
1999 { |
|
2000 TBuf<KDefaultBufferSize> tempBuffer; |
|
2001 tempBuffer.Copy(iTraceBuffer); |
|
2002 INFO_PRINTF2(_L("Trace data:\r\n%S"), &tempBuffer); |
|
2003 } |
|
2004 } |
|
2005 |
|
2006 err = iTraceCoreOstLdd.ClearBuffer(); |
|
2007 if (err != KErrNone) |
|
2008 { |
|
2009 ERR_PRINTF2(_L("ClearBuffer() error %d"), err); |
|
2010 SetError(err); |
|
2011 } |
|
2012 } |