|
1 // Copyright (c) 2008-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 // |
|
15 |
|
16 |
|
17 |
|
18 /** |
|
19 @file |
|
20 @internalTechnology |
|
21 */ |
|
22 |
|
23 #include "t_coredumpmonitor.h" |
|
24 |
|
25 //Names of functions to be tested - referenced from script file |
|
26 _LIT(KUntrustedAccessToSCMConfig, "UntrustedAccessToSCMConfig"); |
|
27 _LIT(KGatherTraceBuffer, "GatherTraceBuffer"); |
|
28 _LIT(KTrustedAccessToSCMConfig, "TrustedAccessToSCMConfig"); |
|
29 _LIT(KReadDefaultConfigValues, "ReadDefaultConfigValues"); |
|
30 _LIT(KValidateNewestCrash, "ValidateNewestCrash"); |
|
31 |
|
32 /** |
|
33 * Constructor for test wrapper |
|
34 */ |
|
35 CCoreDumpMonitorWrapper::CCoreDumpMonitorWrapper() |
|
36 { |
|
37 } |
|
38 |
|
39 /** |
|
40 * Destructor |
|
41 */ |
|
42 CCoreDumpMonitorWrapper::~CCoreDumpMonitorWrapper() |
|
43 { |
|
44 iCoreDumpSession.Close(); |
|
45 iCrashList.ResetAndDestroy(); |
|
46 iFsSession.Close(); |
|
47 } |
|
48 |
|
49 /** |
|
50 * Two phase constructor for CCoreDumpMonitorWrapper |
|
51 * @return CCoreDumpMonitorWrapper object |
|
52 * @leave |
|
53 */ |
|
54 CCoreDumpMonitorWrapper* CCoreDumpMonitorWrapper::NewL() |
|
55 { |
|
56 CCoreDumpMonitorWrapper* ret = new (ELeave) CCoreDumpMonitorWrapper(); |
|
57 CleanupStack::PushL(ret); |
|
58 ret->ConstructL(); |
|
59 CleanupStack::Pop(ret); |
|
60 return ret; |
|
61 } |
|
62 |
|
63 /** |
|
64 * Safe construction |
|
65 * @leave |
|
66 */ |
|
67 void CCoreDumpMonitorWrapper::ConstructL() |
|
68 { |
|
69 |
|
70 |
|
71 User::LeaveIfError(iCoreDumpSession.Connect()); |
|
72 User::LeaveIfError(iFsSession.Connect()); |
|
73 } |
|
74 |
|
75 /** |
|
76 * Assign the object |
|
77 * @param aObject TAny* to the object to test |
|
78 * @leave |
|
79 */ |
|
80 void CCoreDumpMonitorWrapper::SetObjectL(TAny* aObject) |
|
81 {} |
|
82 |
|
83 /** |
|
84 * Runs a test preamble |
|
85 */ |
|
86 void CCoreDumpMonitorWrapper::PrepareTestL() |
|
87 { |
|
88 SetBlockResult(EPass); |
|
89 INFO_PRINTF1(_L("CCoreDumpMonitorWrapper::Ready to start test")); |
|
90 } |
|
91 |
|
92 /** |
|
93 * Handle a command invoked from the script |
|
94 * @param aCommand Is the name of the command for a TBuf |
|
95 * @param aSection Is the .ini file section where parameters to the command are located |
|
96 * @param aAsyncErrorIndex Is used by the TEF Block framework to handle asynchronous commands. |
|
97 */ |
|
98 TBool CCoreDumpMonitorWrapper::DoCommandL(const TTEFFunction& aCommand, const TTEFSectionName& aSection, const TInt aAsyncErrorIndex) |
|
99 { |
|
100 //__UHEAP_MARK; |
|
101 PrepareTestL(); |
|
102 |
|
103 if (KUntrustedAccessToSCMConfig() == aCommand) |
|
104 { |
|
105 TestUntrustedAccessToCDSConfigL(); |
|
106 } |
|
107 else if(KGatherTraceBuffer() == aCommand) |
|
108 { |
|
109 TestTraceBufferAccessL(); |
|
110 } |
|
111 else if(KTrustedAccessToSCMConfig() ==aCommand) |
|
112 { |
|
113 TestTrustedAccessToCDSConfigL(); |
|
114 } |
|
115 else if (KReadDefaultConfigValues() == aCommand) |
|
116 { |
|
117 TestReadDefaultConfigValuesL(); |
|
118 } |
|
119 else if(KValidateNewestCrash() == aCommand) |
|
120 { |
|
121 TestValidateNewestCrashL(); |
|
122 } |
|
123 else |
|
124 { |
|
125 return EFalse; |
|
126 } |
|
127 |
|
128 //__UHEAP_MARKEND; |
|
129 |
|
130 return ETrue; |
|
131 } |
|
132 |
|
133 void CCoreDumpMonitorWrapper::TestTrustedAccessToCDSConfigL() |
|
134 { |
|
135 INFO_PRINTF1(_L("TestTrustedAccessToCDSConfigL")); |
|
136 |
|
137 INFO_PRINTF1(_L("Getting the number of config parameters")); |
|
138 |
|
139 TUint numConfigParams = 0; |
|
140 TRAPD(err, numConfigParams = iCoreDumpSession.GetNumberConfigParametersL()); |
|
141 if(KErrNone != err) |
|
142 { |
|
143 ERR_PRINTF2(_L("Unable to get the number of config parameters. Returned %d"), err); |
|
144 SetBlockResult(EFail); |
|
145 return; |
|
146 } |
|
147 |
|
148 INFO_PRINTF2(_L("Found %d params"), numConfigParams); |
|
149 TBool foundScmConfig = EFalse; |
|
150 |
|
151 for (TInt i = 0; i < numConfigParams; i++) |
|
152 { |
|
153 COptionConfig* conf; |
|
154 conf = iCoreDumpSession.GetConfigParameterL(i); |
|
155 |
|
156 if (conf->Source()== COptionConfig::ESCMConfig) |
|
157 { |
|
158 foundScmConfig = ETrue; |
|
159 } |
|
160 |
|
161 delete conf; |
|
162 } |
|
163 |
|
164 if(!foundScmConfig) |
|
165 { |
|
166 ERR_PRINTF1(_L("Not Able to retrieve a config param for the SCM")); |
|
167 SetBlockResult(EFail); |
|
168 return; |
|
169 } |
|
170 |
|
171 INFO_PRINTF1(_L("Looked at all config parameters and found some SCM params so that is a pass")); |
|
172 } |
|
173 |
|
174 /** |
|
175 * Tests that that CDS enforces that untrusted users cannot |
|
176 * access the CDS configuration |
|
177 */ |
|
178 void CCoreDumpMonitorWrapper::TestUntrustedAccessToCDSConfigL() |
|
179 { |
|
180 INFO_PRINTF1(_L("TestUntrustedAccessToCDSConfigL")); |
|
181 |
|
182 INFO_PRINTF1(_L("Getting the number of config parameters")); |
|
183 |
|
184 TUint numConfigParams = 0; |
|
185 TRAPD(err, numConfigParams = iCoreDumpSession.GetNumberConfigParametersL()); |
|
186 if(KErrNone != err) |
|
187 { |
|
188 ERR_PRINTF2(_L("Unable to get the number of config parameters. Returned %d"), err); |
|
189 SetBlockResult(EFail); |
|
190 return; |
|
191 } |
|
192 |
|
193 INFO_PRINTF2(_L("Found %d params"), numConfigParams); |
|
194 |
|
195 for (TInt i = 0; i < numConfigParams; i++) |
|
196 { |
|
197 COptionConfig* conf; |
|
198 conf = iCoreDumpSession.GetConfigParameterL(i); |
|
199 |
|
200 if (conf->Source()== COptionConfig::ESCMConfig) |
|
201 { |
|
202 ERR_PRINTF1(_L("Able to retrieve a config param for the SCM")); |
|
203 SetBlockResult(EFail); |
|
204 delete conf; |
|
205 return; |
|
206 } |
|
207 |
|
208 delete conf; |
|
209 } |
|
210 |
|
211 INFO_PRINTF1(_L("Looked at all config parameters and none were SCM params so that is a pass")); |
|
212 } |
|
213 |
|
214 void CCoreDumpMonitorWrapper::TestTraceBufferAccessL() |
|
215 { |
|
216 //Step 1: Load the UTRACE formatter and file writter |
|
217 INFO_PRINTF1(_L("CCoreDumpMonitorWrapper::TestTraceBufferAccessL loading UTRACE Formatter and File Writer")); |
|
218 |
|
219 TPluginRequest loadUtracePlugin; |
|
220 loadUtracePlugin.iPluginType = TPluginRequest::EFormatter; |
|
221 loadUtracePlugin.iLoad = ETrue; |
|
222 loadUtracePlugin.iUid = KUtraceUid; |
|
223 |
|
224 TPluginRequest loadWriterReq; |
|
225 loadWriterReq.iPluginType = TPluginRequest::EWriter; |
|
226 loadWriterReq.iLoad = ETrue; |
|
227 loadWriterReq.iUid = KUidFileWriter; |
|
228 |
|
229 // loading Symbian ELF formatter |
|
230 TRAPD(err, iCoreDumpSession.PluginRequestL(loadUtracePlugin)); |
|
231 if (err != KErrNone) |
|
232 { |
|
233 ERR_PRINTF2(_L("CCoreDumpMonitorWrapper::TestTraceBufferAccessL() Could not load UTRACE plugin!, err:%d\n"), err); |
|
234 SetBlockResult(EFail); |
|
235 User::Leave(err); |
|
236 } |
|
237 |
|
238 // loading Symbian File writer |
|
239 TRAP(err, iCoreDumpSession.PluginRequestL(loadWriterReq)); |
|
240 if (err != KErrNone) |
|
241 { |
|
242 ERR_PRINTF2(_L("CCoreDumpMonitorWrapper::TestTraceBufferAccessL() Could not load writer plugin!, err:%d\n"), err); |
|
243 SetBlockResult(EFail); |
|
244 User::Leave(err); |
|
245 } |
|
246 |
|
247 //Configuring the file writer plugin to have a specified crash file name |
|
248 TRAP(err, DoConfigureL((TInt)(CCrashDataSave::ECoreFilePath), |
|
249 KUidFileWriter.iUid, COptionConfig::EWriterPlugin, |
|
250 COptionConfig::ETFileName, KFilePathPrompt, 1, KNullDesC, 0, |
|
251 KCrashFileName, 0)); |
|
252 |
|
253 if (err != KErrNone) |
|
254 { |
|
255 ERR_PRINTF2(_L("CCoreDumpMonitorWrapper::TestTraceBufferAccessL()() for File Writer Error %d changing param"), |
|
256 err); |
|
257 SetBlockResult(EFail); |
|
258 User::Leave(err); |
|
259 } |
|
260 |
|
261 //List crashes in flash |
|
262 iCrashList.Reset(); |
|
263 TRAP(err, iCoreDumpSession.ListCrashesInFlashL(iCrashList)); |
|
264 if (err != KErrNone) |
|
265 { |
|
266 ERR_PRINTF2(_L("CCoreDumpMonitorWrapper::TestTraceBufferAccessL() Could not read Crashes in the Flash! err:%d\n"), err); |
|
267 SetBlockResult(EFail); |
|
268 User::Leave(err); |
|
269 } |
|
270 |
|
271 INFO_PRINTF2(_L("Number of crashes present: %d"), iCrashList.Count()); |
|
272 if(iCrashList.Count() == 0) |
|
273 { |
|
274 ERR_PRINTF1(_L("Failed to find any crashes in log for the analysing")); |
|
275 SetBlockResult(EFail); |
|
276 User::Leave(err); |
|
277 } |
|
278 |
|
279 //Step 2: Process the crash |
|
280 for (TInt i = 0; i < iCrashList.Count(); i++) |
|
281 { |
|
282 TRAP(err, iCoreDumpSession.ProcessCrashLogL(iCrashList[i]->iCrashId)); |
|
283 if (err != KErrNone) |
|
284 { |
|
285 ERR_PRINTF2(_L("CCoreDumpMonitorWrapper::TestTraceBufferAccessL() Could not process crash! err:%d\n"), err); |
|
286 SetBlockResult(EFail); |
|
287 User::Leave(err); |
|
288 } |
|
289 } |
|
290 |
|
291 INFO_PRINTF1(_L("Crashes Processed, Now looking for file generated")); |
|
292 |
|
293 //Step 3: Check the trace file has been generated |
|
294 //Use wildcard utilities to search for the UTRACE FIle Created |
|
295 TBuf<32> buf; |
|
296 buf = KDir; |
|
297 TUidType uid1; |
|
298 TUidType uid2(uid1.MostDerived()); |
|
299 |
|
300 CFindFileByType* obj = new(ELeave) CFindFileByType(iFsSession); |
|
301 CleanupStack::PushL(obj); |
|
302 |
|
303 err = obj->FindFirst(KCrashWildCard, buf, uid2); |
|
304 if (err != KErrNone) |
|
305 { |
|
306 ERR_PRINTF2( |
|
307 _L("CCoreDumpMonitorWrapper::TestTraceBufferAccessL() Error finding the UTRACE File %d"), |
|
308 err); |
|
309 SetBlockResult(EFail); |
|
310 User::Leave(err); |
|
311 } |
|
312 |
|
313 INFO_PRINTF2(_L("The UTRACE File Found is E:\\:%S "), &(obj->Entry().iName)); |
|
314 |
|
315 CleanupStack::PopAndDestroy(); //CFindFileByType |
|
316 |
|
317 |
|
318 //Future improvements: Check contents of file |
|
319 } |
|
320 |
|
321 /** |
|
322 * Tests that that after deletion of the entire partition |
|
323 * SCM config values should correspond to the default build time values |
|
324 */ |
|
325 void CCoreDumpMonitorWrapper::TestReadDefaultConfigValuesL() |
|
326 { |
|
327 INFO_PRINTF1(_L("CCoreDumpMonitorWrapper::TestReadDefaultConfigValuesL Match with Build time SCM config values")); |
|
328 |
|
329 TInt noConfigParams = 0; |
|
330 TInt scmConfigParams = 0; |
|
331 // this will ultimateley read the config |
|
332 TRAPD(err, noConfigParams = iCoreDumpSession.GetNumberConfigParametersL()); |
|
333 if(err != KErrNone) |
|
334 { |
|
335 ERR_PRINTF1(_L("Could not read number of config params")); |
|
336 SetBlockResult(EFail); |
|
337 User::Leave(KErrGeneral); |
|
338 } |
|
339 else |
|
340 { |
|
341 INFO_PRINTF2(_L("Found %d config params"), noConfigParams); |
|
342 |
|
343 for (TInt i = 0; i < noConfigParams; i++) |
|
344 { |
|
345 COptionConfig* conf = iCoreDumpSession.GetConfigParameterL(i); |
|
346 CleanupStack::PushL(conf); |
|
347 |
|
348 if (conf->Source()== COptionConfig::ESCMConfig) |
|
349 { |
|
350 //count number of SCM configurations |
|
351 scmConfigParams++; |
|
352 TConfigItem::TSCMDataType dataType = (TConfigItem::TSCMDataType) conf->Instance(); |
|
353 |
|
354 //Default SCM Configuration for TConfigItem::EThreadsUsrStack has priority = 0 |
|
355 if(dataType == TConfigItem::EThreadsUsrStack && conf->Value() != 0) |
|
356 { |
|
357 ERR_PRINTF3(_L("TConfigItem::EThreadsUsrStack did not match the ZERO Priority for config data type %d with priority %d"), dataType, conf->Value()); |
|
358 SetBlockResult(EFail); |
|
359 User::Leave(KErrGeneral); |
|
360 } |
|
361 //Default SCM Configuration for TConfigItem::EThreadsSvrStack has priority = 0 |
|
362 else if(dataType == TConfigItem::EThreadsSvrStack && conf->Value() != 0) |
|
363 { |
|
364 ERR_PRINTF3(_L("TConfigItem::EThreadsSvrStack did not match the ZERO Priority for config data type %d with priority %d"), dataType, conf->Value()); |
|
365 SetBlockResult(EFail); |
|
366 User::Leave(KErrGeneral); |
|
367 } |
|
368 else if (dataType == TConfigItem::EThreadsSvrStack || dataType == TConfigItem::EThreadsUsrStack) |
|
369 { |
|
370 INFO_PRINTF3(_L("VERIFIED ZERO priority for config data type %d priority %d"), dataType, conf->Value()); |
|
371 CleanupStack::PopAndDestroy(conf); |
|
372 continue; |
|
373 } |
|
374 |
|
375 //Default SCM Configuration for all has a priority value equal to thier postion in the list + 1 |
|
376 if(conf->Value() != (dataType + 1) ) |
|
377 { |
|
378 ERR_PRINTF3(_L("Did not match the DEFAULT Configurtion for config data type %d with priority %d"), dataType, conf->Value()); |
|
379 SetBlockResult(EFail); |
|
380 User::Leave(KErrGeneral); |
|
381 } |
|
382 |
|
383 //happy to print the value |
|
384 INFO_PRINTF3(_L("VERIFIED config data type %d has priority %d"), dataType, conf->Value()); |
|
385 |
|
386 } |
|
387 |
|
388 CleanupStack::PopAndDestroy(conf);//COptionConfig |
|
389 }//for loop for noConfigParams |
|
390 |
|
391 INFO_PRINTF2(_L("Match with DEFAULT config values Successful for %d SCM Configuration Parameters"),scmConfigParams); |
|
392 }//else for no errors GetNumberConfigParametersL |
|
393 |
|
394 } |
|
395 |
|
396 /** |
|
397 * @return void |
|
398 * @param aIndex Internal index to the component that owns the object |
|
399 * @param aUID UID of the component that owns the object |
|
400 * @param aSource Type of component that owns the object |
|
401 * @param aType Type of parameter |
|
402 * @param aPrompt Prompt to present to user |
|
403 * @param aNumOptions Number of options that the parameter can be set to. Only applies if type is ETMultiEntryEnum. |
|
404 * @param aOptions Comma separated list of options. Applies to ETMultiEntryEnum and ETBool |
|
405 * @param aVal Integer value. Applies to ETInt, ETUInt, ETBool |
|
406 * @param aStrValue String value. Applies to ETString, ETFileName, ETMultiEntry, ETBool |
|
407 */ |
|
408 void CCoreDumpMonitorWrapper::DoConfigureL(const TUint32& aIndex, |
|
409 const TUint32& aUID, const COptionConfig::TParameterSource& aSource, |
|
410 const COptionConfig::TOptionType& aType, const TDesC& aPrompt, |
|
411 const TUint32& aNumOptions, const TDesC& aOptions, const TInt32& aVal, |
|
412 const TDesC& aStrValue, const TUint aInstance) |
|
413 { |
|
414 COptionConfig * config; |
|
415 |
|
416 config = COptionConfig::NewL(aIndex, aUID, aSource, aType, aPrompt, |
|
417 aNumOptions, aOptions, aVal, aStrValue); |
|
418 |
|
419 CleanupStack::PushL(config); |
|
420 |
|
421 config->Instance(aInstance); |
|
422 |
|
423 //Configure now... |
|
424 iCoreDumpSession.SetConfigParameterL(*config); |
|
425 |
|
426 CleanupStack::PopAndDestroy(config); |
|
427 } |
|
428 |
|
429 |
|
430 void CCoreDumpMonitorWrapper::TestValidateNewestCrashL() |
|
431 { |
|
432 |
|
433 INFO_PRINTF1(_L("TestValidateNewestCrashL called")); |
|
434 |
|
435 //Do list all the Crash Information here |
|
436 TRAPD(err, iCoreDumpSession.ListCrashesInFlashL(iCrashList)); |
|
437 if (err != KErrNone) |
|
438 { |
|
439 ERR_PRINTF2( |
|
440 _L("TestValidateNewestCrashL Could not read Crashes in the Flash! err:%d\n"), |
|
441 err); |
|
442 SetBlockResult(EFail); |
|
443 return; |
|
444 //User::Leave(err); |
|
445 } |
|
446 |
|
447 INFO_PRINTF2(_L("TestValidateNewestCrashL Number of crash information present: %d"), |
|
448 iCrashList.Count()); |
|
449 |
|
450 TInt expectedNewestIndex = 0; |
|
451 |
|
452 if( iCrashList.Count() > 0) |
|
453 { |
|
454 // must be entries for test to potentially fail |
|
455 TInt newestIndex = 0; |
|
456 // start with first entry being newest time |
|
457 TUint64 newestTime = iCrashList[0]->iTime; |
|
458 |
|
459 for (TInt i = 0; i < iCrashList.Count(); i++) |
|
460 { |
|
461 INFO_PRINTF3(_L("Crash no: %d, CrashId %d"), i, iCrashList[i]->iCrashId); |
|
462 INFO_PRINTF3(_L("Crash no: %d, Type %ld"), i, iCrashList[i]->iType); |
|
463 INFO_PRINTF3(_L("Crash no: %d, Time %ld"), i, iCrashList[i]->iTime); |
|
464 INFO_PRINTF3(_L("Crash no: %d, Thread ID %ld"), i, iCrashList[i]->iTid); |
|
465 |
|
466 // crash time held in the header as TUint64 - highest value should be the newset crash |
|
467 if(iCrashList[i]->iTime > newestTime) |
|
468 { |
|
469 newestIndex = i; |
|
470 newestTime = iCrashList[i]->iTime; |
|
471 } |
|
472 } |
|
473 |
|
474 INFO_PRINTF2(_L("Newest crash is Crash no: %d"), newestIndex); |
|
475 if(newestIndex != expectedNewestIndex) |
|
476 { |
|
477 ERR_PRINTF3(_L("DoCmdValidateNewestCrashL newest crash was not in expected position expected (%d) actual(%d)") |
|
478 , expectedNewestIndex, newestIndex); |
|
479 SetBlockResult(EFail); |
|
480 //User::Leave(err); |
|
481 } |
|
482 } |
|
483 |
|
484 INFO_PRINTF1(_L("TestValidateNewestCrashL finished")); |
|
485 |
|
486 } |
|
487 |
|
488 //eof |