|
1 // Copyright (c) 2005-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 "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 // Example CTestStep derived implementation |
|
15 // |
|
16 |
|
17 |
|
18 |
|
19 /** |
|
20 @file DEXECStep.cpp |
|
21 @internalTechnology |
|
22 */ |
|
23 #include "DEXCusersidestep.h" |
|
24 #include "tcoredumpserversuitedefs.h" |
|
25 #include "tcoredumpserversuiteserver.h" |
|
26 #include <e32property.h> |
|
27 #include <crashdatasave.h> |
|
28 #include <e32std.h> |
|
29 #include <coredumpserverapi.h> |
|
30 |
|
31 CDEXECUserSideStep::~CDEXECUserSideStep() |
|
32 /** |
|
33 * Destructor |
|
34 */ |
|
35 { |
|
36 } |
|
37 |
|
38 CDEXECUserSideStep::CDEXECUserSideStep() |
|
39 /** |
|
40 * Constructor |
|
41 */ |
|
42 { |
|
43 // **MUST** call SetTestStepName in the constructor as the controlling |
|
44 // framework uses the test step name immediately following construction to set |
|
45 // up the step's unique logging ID. |
|
46 SetTestStepName(KDEXECUserSideStep); |
|
47 } |
|
48 |
|
49 TVerdict CDEXECUserSideStep::doTestStepPreambleL() |
|
50 /** |
|
51 * @return - TVerdict code |
|
52 * Override of base class virtual |
|
53 */ |
|
54 { |
|
55 |
|
56 TInt ret = KErrNone; |
|
57 ret = iSess.Connect(); |
|
58 if(ret != KErrNone) |
|
59 { |
|
60 SetTestStepResult( EFail ); |
|
61 INFO_PRINTF2(_L("Error %d from iSess->Connect()/n"), ret); |
|
62 } |
|
63 else |
|
64 { |
|
65 SetTestStepResult(EPass); |
|
66 } |
|
67 |
|
68 ret = iFs.Connect(); |
|
69 if(ret != KErrNone) |
|
70 { |
|
71 SetTestStepResult( EFail ); |
|
72 INFO_PRINTF2(_L("Error %d from iFs->Connect()/n"), ret); |
|
73 } |
|
74 else |
|
75 { |
|
76 SetTestStepResult(EPass); |
|
77 } |
|
78 |
|
79 return TestStepResult(); |
|
80 } |
|
81 |
|
82 |
|
83 TVerdict CDEXECUserSideStep::doTestStepL() |
|
84 /** |
|
85 * @return - TVerdict code |
|
86 * Override of base class pure virtual |
|
87 * Our implementation only gets called if the base class doTestStepPreambleL() did |
|
88 * not leave. That being the case, the current test result value will be EPass. |
|
89 */ |
|
90 { |
|
91 |
|
92 if (TestStepResult()==EPass) |
|
93 { |
|
94 TInt ret = KErrNone; |
|
95 |
|
96 __UHEAP_MARK; |
|
97 |
|
98 TRAP(ret, ClientAppL()); |
|
99 if(KErrNone != ret) |
|
100 { |
|
101 SetTestStepResult(EFail); |
|
102 INFO_PRINTF2(_L("Error %d from CDEXECStep->ClientAppL()"), ret); |
|
103 } |
|
104 |
|
105 __UHEAP_MARKEND; |
|
106 |
|
107 } |
|
108 return TestStepResult(); |
|
109 } |
|
110 |
|
111 void CDEXECUserSideStep::ClientAppL() |
|
112 /** |
|
113 * @return void |
|
114 * This calls each stage of the test |
|
115 */ |
|
116 { |
|
117 INFO_PRINTF1(_L("Starting DEXEC Test Suite") ); |
|
118 HandleCrashL(); |
|
119 CheckParametersL(); |
|
120 } |
|
121 |
|
122 void CDEXECUserSideStep::HandleCrashL() |
|
123 /** |
|
124 * @return void |
|
125 * Tests handling a crash |
|
126 */ |
|
127 { |
|
128 |
|
129 if(TestStepResult()==EPass) |
|
130 { |
|
131 TPtrC crashAppParam; |
|
132 TPtrC crashFileName; |
|
133 TPtrC writerToUse; |
|
134 |
|
135 if(!GetStringFromConfig(ConfigSection(), KTe_CrashAppParam, crashAppParam) || |
|
136 !GetStringFromConfig(ConfigSection(), KTe_CrashFileName, crashFileName) || |
|
137 !GetStringFromConfig(ConfigSection(), KWriterToUse, writerToUse)) |
|
138 { |
|
139 INFO_PRINTF1(_L("Failed to get data from ini file")); |
|
140 SetTestStepResult(EFail); |
|
141 User::Leave(KErrGeneral); |
|
142 } |
|
143 |
|
144 INFO_PRINTF4(_L("The CrashApp Param is %S, The Filename is is %S, The writer is %S"), &crashAppParam, &crashFileName,&writerToUse); // Block end |
|
145 |
|
146 //Convert writer config to hex |
|
147 TLex luther(writerToUse); |
|
148 TUint32 writer; |
|
149 luther.Val(writer, EHex); |
|
150 |
|
151 //Start the process that we intend to crash.... |
|
152 RProcess crashProcess; |
|
153 CleanupClosePushL(crashProcess); |
|
154 |
|
155 TInt ret = crashProcess.Create( KCrashAppFileName, crashAppParam); |
|
156 if(ret != KErrNone) |
|
157 { |
|
158 INFO_PRINTF2(_L("Error %d from RProcess .Create(z:\\sys\\bin\\crashapp.exe)/n"), ret); |
|
159 SetTestStepResult(EFail); |
|
160 User::Leave(ret); |
|
161 } |
|
162 |
|
163 INFO_PRINTF1(_L("Started userside crash app")); |
|
164 |
|
165 //Load DEXEC Formatter |
|
166 LoadDEXECFormatterL(); |
|
167 |
|
168 TPluginRequest req; |
|
169 TUid writerUid = TUid::Uid(writer); |
|
170 req.iUid = writerUid; |
|
171 req.iPluginType = TPluginRequest::EWriter; |
|
172 req.iLoad = ETrue; |
|
173 |
|
174 TRAP(ret, iSess.PluginRequestL( req )); |
|
175 if(ret != KErrNone) |
|
176 { |
|
177 INFO_PRINTF2(_L("Failed to load writer plugin, error = %d"), ret); |
|
178 SetTestStepResult(EFail); |
|
179 User::Leave(ret); |
|
180 } |
|
181 |
|
182 INFO_PRINTF1(_L("Loaded writer plugin successfully")); |
|
183 |
|
184 //Now we configure CDS and writer |
|
185 _LIT( KFilePathPrompt, "not_important" ); |
|
186 |
|
187 DoConfigureL(CCrashDataSave::ECoreFilePath, writerUid.iUid, COptionConfig::EWriterPlugin, COptionConfig::ETFileName, |
|
188 KFilePathPrompt, 1, KNullDesC, 0, crashFileName, 0); |
|
189 |
|
190 // Observe the process and wait for a crash |
|
191 TRAP(ret, iSess.ObservationRequestL( KCrashAppFileName, KCrashAppFileName, ETrue) ); |
|
192 if(ret != KErrNone) |
|
193 { |
|
194 INFO_PRINTF2(_L("Error %d iSess.ObservationRequestL(z:\\sys\\bin\\crashapp.exe)\n"), ret); |
|
195 SetTestStepResult(EFail); |
|
196 User::Leave( ret ); |
|
197 } |
|
198 |
|
199 //start the crash process |
|
200 crashProcess.Resume(); |
|
201 CleanupStack::PopAndDestroy(&crashProcess); //this is for crashProcess |
|
202 |
|
203 //Monitor the progress of the crash file being generated... |
|
204 MonitorProgressL(); |
|
205 |
|
206 //Check dump has been generated...and is valid |
|
207 CDir *fileList = NULL; |
|
208 TFindFile fileFinder(iFs); |
|
209 TRAP(ret, fileList = CTe_coredumpserverSuite::DoesFileExistL(crashFileName, fileFinder)); |
|
210 |
|
211 if((ret != KErrNone) || (fileList == NULL)) |
|
212 { |
|
213 INFO_PRINTF2(_L("Expected crash file was not generated: %d"), ret); |
|
214 SetTestStepResult(EFail); |
|
215 User::Leave( ret ); |
|
216 } |
|
217 |
|
218 CleanupStack::PushL(fileList); |
|
219 for(TInt i = 0; i < fileList->Count(); i++) |
|
220 { |
|
221 TParse fullName; |
|
222 fullName.Set((*fileList)[i].iName, &fileFinder.File(), NULL); |
|
223 User::LeaveIfError(iFs.Delete(fullName.FullName())); |
|
224 } |
|
225 CleanupStack::PopAndDestroy(fileList); |
|
226 |
|
227 INFO_PRINTF1(_L("Expected crash file was generated successfully")); |
|
228 |
|
229 RProcessPointerList procList; |
|
230 TCleanupItem cleanupProcesses(CTe_coredumpserverSuite::CleanupProcessList, (TAny*)&procList); |
|
231 CleanupStack::PushL(cleanupProcesses); |
|
232 |
|
233 iSess.GetProcessesL( procList ); |
|
234 |
|
235 INFO_PRINTF1(_L("Looking through the procList")); |
|
236 for(TInt i=0; i < procList.Count(); i++ ) |
|
237 { |
|
238 if(procList[i]->Name() == KCrashAppFileName) |
|
239 { |
|
240 SetTestStepResult( EFail ); |
|
241 INFO_PRINTF1(_L("Crash application was not killed as expected after crash")); |
|
242 User::Leave(KErrGeneral); |
|
243 } |
|
244 } |
|
245 CleanupStack::PopAndDestroy(&procList); |
|
246 } |
|
247 |
|
248 } |
|
249 |
|
250 void CDEXECUserSideStep::CheckParametersL() |
|
251 /** |
|
252 * This checks the DEXEC parameters - are we creating a stack file and text file? |
|
253 */ |
|
254 { |
|
255 if(TestStepResult()==EPass) |
|
256 { |
|
257 //Start the process that we intend to crash.... |
|
258 RProcess crashProcess; |
|
259 CleanupClosePushL(crashProcess); |
|
260 |
|
261 _LIT(KCrashAppParam, "-c4 -d1"); |
|
262 TInt ret = crashProcess.Create( KCrashAppFileName, KCrashAppParam); |
|
263 if(ret != KErrNone) |
|
264 { |
|
265 INFO_PRINTF2(_L("Error %d from RProcess .Create(z:\\sys\\bin\\crashapp.exe)/n"), ret); |
|
266 SetTestStepResult(EFail); |
|
267 User::Leave(ret); |
|
268 } |
|
269 |
|
270 LoadDEXECFormatterL(); |
|
271 LoadDEXECFormatterL(); |
|
272 LoadDEXECFormatterL(); |
|
273 |
|
274 LoadFileWriterL(); |
|
275 LoadFileWriterL(); |
|
276 LoadFileWriterL(); |
|
277 |
|
278 BindPluginsL(3); |
|
279 |
|
280 _LIT(KTrue, "True"); |
|
281 _LIT(KFalse, "False"); |
|
282 |
|
283 //no stack file |
|
284 DoConfigureL(0, DEXEC_UID.iUid, COptionConfig::EFormatterPlugin, COptionConfig::ETString, |
|
285 KNullDesC, 1, KNullDesC,0, KFalse, 0); |
|
286 |
|
287 //binary stack file |
|
288 DoConfigureL(0, DEXEC_UID.iUid, COptionConfig::EFormatterPlugin, COptionConfig::ETString, |
|
289 KNullDesC, 1, KNullDesC,0, KTrue, 1); |
|
290 |
|
291 DoConfigureL(1, DEXEC_UID.iUid, COptionConfig::EFormatterPlugin, COptionConfig::ETString, |
|
292 KNullDesC, 1, KNullDesC,0, KFalse, 1); |
|
293 |
|
294 //ascii stack file |
|
295 DoConfigureL(0, DEXEC_UID.iUid, COptionConfig::EFormatterPlugin, COptionConfig::ETString, |
|
296 KNullDesC, 1, KNullDesC,0, KTrue, 2); |
|
297 |
|
298 DoConfigureL(1, DEXEC_UID.iUid, COptionConfig::EFormatterPlugin, COptionConfig::ETString, |
|
299 KNullDesC, 1, KNullDesC,0, KTrue, 2); |
|
300 |
|
301 TUid writerUid = TUid::Uid(0x102831E4);//file writer |
|
302 _LIT( KCrashFileName, "C:\\dexec_chkparam"); |
|
303 TBuf<63> fileName; |
|
304 for(TInt i = 0; i < 3; i++) |
|
305 { |
|
306 fileName = KCrashFileName; |
|
307 fileName.AppendFormat(_L("%d"), i); |
|
308 DoConfigureL(CCrashDataSave::ECoreFilePath, writerUid.iUid, COptionConfig::EWriterPlugin, COptionConfig::ETFileName, |
|
309 KNullDesC, 1, KNullDesC, 0, fileName, i); |
|
310 } |
|
311 |
|
312 // Observe the process and wait for a crash |
|
313 TRAP(ret, iSess.ObservationRequestL( KCrashAppFileName, KCrashAppFileName, ETrue)); |
|
314 if(ret != KErrNone) |
|
315 { |
|
316 ERR_PRINTF2(_L("Error %d iSess.ObservationRequestL(z:\\sys\\bin\\crashapp.exe)\n"), ret); |
|
317 SetTestStepResult(EFail); |
|
318 User::Leave( ret ); |
|
319 } |
|
320 |
|
321 //start the crash process |
|
322 crashProcess.Resume(); |
|
323 INFO_PRINTF1(_L("Started userside crash app")); |
|
324 CleanupStack::PopAndDestroy(); //this is for crashProcess |
|
325 |
|
326 //Monitor the progress of the crash file being generated... |
|
327 MonitorProgressL(); |
|
328 |
|
329 //Check dumps have been generated... |
|
330 CDir *fileList = NULL; |
|
331 TFindFile fileFinder(iFs); |
|
332 TRAP(ret, fileList = CTe_coredumpserverSuite::DoesFileExistL(KCrashFileName, fileFinder)); |
|
333 CleanupStack::PushL(fileList); |
|
334 |
|
335 if( (ret != KErrNone) || (fileList == NULL) ) |
|
336 { |
|
337 ERR_PRINTF2(_L("Expected crash files were not generated: %d"), ret); |
|
338 SetTestStepResult(EFail); |
|
339 User::Leave( ret ); |
|
340 } |
|
341 |
|
342 TInt txtFiles = 0; |
|
343 TInt stkFiles = 0; |
|
344 for(TInt i = 0; i < fileList->Count(); i++) |
|
345 { |
|
346 TParse fullName; |
|
347 fullName.Set((*fileList)[i].iName, &fileFinder.File(), NULL); |
|
348 if(fullName.Ext() == _L(".txt")) |
|
349 txtFiles++; |
|
350 if(fullName.Ext() == _L(".stk")) |
|
351 stkFiles++; |
|
352 INFO_PRINTF2(_L("%S"), &fullName.FullName()); |
|
353 User::LeaveIfError(iFs.Delete(fullName.FullName())); |
|
354 } |
|
355 CleanupStack::PopAndDestroy(fileList); |
|
356 |
|
357 if( (txtFiles != 3) || (stkFiles != 2) ) |
|
358 { |
|
359 ERR_PRINTF1(_L("Expected crash files were not generated")); |
|
360 SetTestStepResult(EFail); |
|
361 User::Leave(KErrNotFound); |
|
362 } |
|
363 |
|
364 RProcessPointerList procList; |
|
365 TCleanupItem cleanupProcesses(CTe_coredumpserverSuite::CleanupProcessList, (TAny*)&procList); |
|
366 CleanupStack::PushL(cleanupProcesses); |
|
367 |
|
368 iSess.GetProcessesL( procList ); |
|
369 |
|
370 INFO_PRINTF1(_L("Looking through the procList")); |
|
371 for(TInt i=0; i < procList.Count(); i++ ) |
|
372 { |
|
373 if(procList[i]->Name() == KCrashAppFileName) |
|
374 { |
|
375 SetTestStepResult( EFail ); |
|
376 ERR_PRINTF1(_L("Crash application was not killed as expected after crash")); |
|
377 User::Leave(KErrGeneral); |
|
378 } |
|
379 } |
|
380 CleanupStack::PopAndDestroy(&procList); |
|
381 } |
|
382 } |
|
383 |
|
384 void CDEXECUserSideStep::DoConfigureL(const TUint32& aIndex, |
|
385 const TUint32& aUID, |
|
386 const COptionConfig::TParameterSource& aSource, |
|
387 const COptionConfig::TOptionType& aType, |
|
388 const TDesC& aPrompt, |
|
389 const TUint32& aNumOptions, |
|
390 const TDesC& aOptions, |
|
391 const TInt32& aVal, |
|
392 const TDesC& aStrValue, |
|
393 const TUint aInstance ) |
|
394 /** |
|
395 * @return void |
|
396 * @param aIndex Internal index to the component that owns the object |
|
397 * @param aUID UID of the component that owns the object |
|
398 * @param aSource Type of component that owns the object |
|
399 * @param aType Type of parameter |
|
400 * @param aPrompt Prompt to present to user |
|
401 * @param aNumOptions Number of options that the parameter can be set to. Only applies if type is ETMultiEntryEnum. |
|
402 * @param aOptions Comma separated list of options. Applies to ETMultiEntryEnum and ETBool |
|
403 * @param aVal Integer value. Applies to ETInt, ETUInt, ETBool |
|
404 * @param aStrValue String value. Applies to ETString, ETFileName, ETMultiEntry, ETBool |
|
405 */ |
|
406 { |
|
407 COptionConfig * config; |
|
408 |
|
409 config = COptionConfig::NewL( aIndex, |
|
410 aUID, |
|
411 aSource, |
|
412 aType, |
|
413 aPrompt, |
|
414 aNumOptions, |
|
415 aOptions, |
|
416 aVal, |
|
417 aStrValue); |
|
418 |
|
419 CleanupStack::PushL(config); |
|
420 |
|
421 config->Instance(aInstance); |
|
422 |
|
423 //Configure now... |
|
424 TRAPD(ret, iSess.SetConfigParameterL(*config) ); |
|
425 if(ret != KErrNone) |
|
426 { |
|
427 INFO_PRINTF2(_L("Error %d changing param/n"), ret ); |
|
428 SetTestStepResult(EFail); |
|
429 User::Leave(ret); |
|
430 } |
|
431 |
|
432 CleanupStack::PopAndDestroy(config); |
|
433 } |
|
434 |
|
435 void CDEXECUserSideStep::LoadFileWriterL() |
|
436 { |
|
437 TPluginRequest req; |
|
438 TUid writerUid = TUid::Uid(0x102831E4);//file writer |
|
439 req.iUid = writerUid; |
|
440 req.iPluginType = TPluginRequest::EWriter; |
|
441 req.iLoad = ETrue; |
|
442 |
|
443 TRAPD(ret, iSess.PluginRequestL( req )); |
|
444 if(ret != KErrNone) |
|
445 { |
|
446 ERR_PRINTF2(_L("Failed to load writer plugin, error = %d"), ret); |
|
447 SetTestStepResult(EFail); |
|
448 User::Leave(ret); |
|
449 } |
|
450 |
|
451 } |
|
452 |
|
453 void CDEXECUserSideStep::LoadDEXECFormatterL() |
|
454 /** |
|
455 * @return void |
|
456 * Utility function to load the SELF formatter |
|
457 */ |
|
458 { |
|
459 |
|
460 INFO_PRINTF1(_L("Attempting to load DEXEC Plugin")); |
|
461 |
|
462 TPluginRequest req; |
|
463 req.iPluginType = TPluginRequest::EFormatter; |
|
464 req.iLoad = ETrue; |
|
465 req.iUid = DEXEC_UID; |
|
466 |
|
467 TRAPD(ret, iSess.PluginRequestL( req )); |
|
468 if(ret != KErrNone) |
|
469 { |
|
470 ERR_PRINTF2(_L("Failed to load writer plugin, error = %d"), ret); |
|
471 SetTestStepResult(EFail); |
|
472 User::Leave(ret); |
|
473 } |
|
474 } |
|
475 |
|
476 void CDEXECUserSideStep::BindPluginsL(const TInt aCount) |
|
477 /** |
|
478 * @return void |
|
479 * Utility function to load the SELF formatter |
|
480 */ |
|
481 { |
|
482 INFO_PRINTF1(_L("Attempting to bind plugins")); |
|
483 |
|
484 TPluginRequest req; |
|
485 req.iPluginType = TPluginRequest::EFormatter; |
|
486 req.iUid = TUid::Uid(0); |
|
487 |
|
488 for(TInt i = 0; i < aCount; i++) |
|
489 { |
|
490 req.iIndex = req.iPair = i; |
|
491 TRAPD(ret, iSess.PluginRequestL( req )); |
|
492 |
|
493 if(ret != KErrNone) |
|
494 { |
|
495 ERR_PRINTF2(_L("Failed to bind plugin pair=%d"), i); |
|
496 SetTestStepResult(EFail); |
|
497 User::Leave(ret); |
|
498 } |
|
499 } |
|
500 } |
|
501 |
|
502 void CDEXECUserSideStep::MonitorProgressL() |
|
503 /** |
|
504 * @return void |
|
505 * This method monitors the RProperty for the crash progress. There are several states of this but we are |
|
506 * only interested in the start and finish of these properties |
|
507 */ |
|
508 { |
|
509 RProperty crashProgress; |
|
510 User::LeaveIfError(crashProgress.Attach(KCoreDumpServUid, ECrashProgress)); |
|
511 |
|
512 TBuf<50> crashProg; |
|
513 |
|
514 TRequestStatus status; |
|
515 crashProgress.Subscribe(status); |
|
516 User::WaitForRequest(status); |
|
517 //Subscribe for next one again... |
|
518 crashProgress.Subscribe(status); |
|
519 |
|
520 //First one should be the start string = KStartOfDEXECProc |
|
521 User::LeaveIfError(crashProgress.Get(crashProg )); |
|
522 if(crashProg != KStartOfDEXECProc) |
|
523 { |
|
524 INFO_PRINTF1(_L("DEXEC formatter has not started processing the data")); |
|
525 } |
|
526 |
|
527 INFO_PRINTF1(_L("DEXEC formatters have started processing the data")); |
|
528 INFO_PRINTF1(_L("Waiting to be notified of the timeout of the processing. A timeout here is a fail")); |
|
529 //Now we wait until its finished |
|
530 do |
|
531 { |
|
532 User::WaitForRequest(status); |
|
533 crashProgress.Subscribe(status); |
|
534 |
|
535 User::LeaveIfError(crashProgress.Get(crashProg )); |
|
536 } |
|
537 while(crashProg != KEndOfProcessing); |
|
538 |
|
539 INFO_PRINTF1(_L("DEXEC formatter has finished processing the data")); |
|
540 } |
|
541 |
|
542 |
|
543 TVerdict CDEXECUserSideStep::doTestStepPostambleL() |
|
544 /** |
|
545 * @return - TVerdict code |
|
546 * Override of base class virtual |
|
547 */ |
|
548 { |
|
549 iSess.Disconnect(); |
|
550 User::After(7000000); //ensure we give enough time for session to close |
|
551 iFs.Close(); |
|
552 return EPass; |
|
553 } |