|
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 @file |
|
18 @internalTechnology |
|
19 */ |
|
20 |
|
21 #include "t_coredumpserver.h" |
|
22 #include "flashdatasource.h" |
|
23 |
|
24 //Names of functions to be tested - referenced from script file |
|
25 _LIT(KDataViaDataSource, "DataViaDataSource"); |
|
26 _LIT(KTraceViaDataSource, "TraceViaDataSource"); |
|
27 _LIT(KUntrustedAccess, "UntrustedDataAccess"); |
|
28 /** |
|
29 * Constructor for test wrapper |
|
30 */ |
|
31 CCoreDumpServerWrapper::CCoreDumpServerWrapper() |
|
32 { |
|
33 } |
|
34 |
|
35 /** |
|
36 * Destructor |
|
37 */ |
|
38 CCoreDumpServerWrapper::~CCoreDumpServerWrapper() |
|
39 { |
|
40 iCoreDumpSession.Close(); |
|
41 iSecSess.Close(); |
|
42 } |
|
43 |
|
44 /** |
|
45 * Two phase constructor for CCoreDumpServerWrapper |
|
46 * @return CProcessCrashWrapper object |
|
47 * @leave |
|
48 */ |
|
49 CCoreDumpServerWrapper* CCoreDumpServerWrapper::NewL() |
|
50 { |
|
51 CCoreDumpServerWrapper* ret = new (ELeave) CCoreDumpServerWrapper(); |
|
52 CleanupStack::PushL(ret); |
|
53 ret->ConstructL(); |
|
54 CleanupStack::Pop(ret); |
|
55 return ret; |
|
56 } |
|
57 |
|
58 /** |
|
59 * Safe construction |
|
60 * @leave |
|
61 */ |
|
62 void CCoreDumpServerWrapper::ConstructL() |
|
63 { |
|
64 User::LeaveIfError(iCoreDumpSession.Connect()); |
|
65 |
|
66 TVersion secVers(Debug::KDebugServMajorVersionNumber, Debug::KDebugServMinorVersionNumber, Debug::KDebugServPatchVersionNumber); |
|
67 User::LeaveIfError(iSecSess.Connect(secVers)); |
|
68 } |
|
69 |
|
70 /** |
|
71 * Assign the object |
|
72 * @param aObject TAny* to the object to test |
|
73 * @leave |
|
74 */ |
|
75 void CCoreDumpServerWrapper::SetObjectL(TAny* aObject) |
|
76 {} |
|
77 |
|
78 /** |
|
79 * Runs a test preamble |
|
80 */ |
|
81 void CCoreDumpServerWrapper::PrepareTestL() |
|
82 { |
|
83 SetBlockResult(EPass); |
|
84 INFO_PRINTF1(_L("CCoreDumpMonitorWrapper::Ready to start test")); |
|
85 } |
|
86 |
|
87 /** |
|
88 * Handle a command invoked from the script |
|
89 * @param aCommand Is the name of the command for a TBuf |
|
90 * @param aSection Is the .ini file section where parameters to the command are located |
|
91 * @param aAsyncErrorIndex Is used by the TEF Block framework to handle asynchronous commands. |
|
92 */ |
|
93 TBool CCoreDumpServerWrapper::DoCommandL(const TTEFFunction& aCommand, const TTEFSectionName& aSection, const TInt aAsyncErrorIndex) |
|
94 { |
|
95 //__UHEAP_MARK; |
|
96 |
|
97 PrepareTestL(); |
|
98 |
|
99 if (KDataViaDataSource() == aCommand) |
|
100 { |
|
101 TestDataSourceReturnsSystemCrashDataL(); |
|
102 } |
|
103 else if(KTraceViaDataSource() == aCommand) |
|
104 { |
|
105 TestDataSourceReturnsTraceDataL(); |
|
106 } |
|
107 else if(KUntrustedAccess() == aCommand) |
|
108 { |
|
109 TestUntrustedServerAccessL(); |
|
110 } |
|
111 else |
|
112 { |
|
113 return EFalse; |
|
114 } |
|
115 |
|
116 //__UHEAP_MARKEND; |
|
117 |
|
118 return ETrue; |
|
119 } |
|
120 |
|
121 /** |
|
122 * This makes sure a formatter can retrieve data via the flash data source |
|
123 */ |
|
124 void CCoreDumpServerWrapper::TestDataSourceReturnsSystemCrashDataL() |
|
125 { |
|
126 INFO_PRINTF1(_L("TestDataSourceReturnsSystemCrashData")); |
|
127 |
|
128 //Load Test Formatter |
|
129 CFlashDataSource* src = CFlashDataSource::NewL(iSecSess); |
|
130 CleanupStack::PushL(src); |
|
131 |
|
132 RCrashInfoPointerList* crashList = new(ELeave)RCrashInfoPointerList; |
|
133 TCleanupItem listCleanup(CCoreDumpServerWrapper::CleanupCrashList, (TAny*)crashList); |
|
134 CleanupStack::PushL(listCleanup); |
|
135 |
|
136 //Get the crashes from the flash partition |
|
137 iCoreDumpSession.ListCrashesInFlashL(*crashList); |
|
138 |
|
139 if(crashList->Count() == 0) |
|
140 { |
|
141 ERR_PRINTF1(_L("Failed to find any crashes in the flash that we could check out")); |
|
142 SetBlockResult(EFail); |
|
143 CleanupStack::PopAndDestroy(2); |
|
144 return; |
|
145 } |
|
146 |
|
147 INFO_PRINTF2(_L("Found [%d] crash(es) on the partition"), crashList->Count()); |
|
148 |
|
149 INFO_PRINTF1(_L("Analysing crash 0")); |
|
150 src->AnalyseCrashL(((*crashList)[0])->iCrashId); |
|
151 |
|
152 INFO_PRINTF1(_L("Analysis successful")); |
|
153 |
|
154 //Now we try and read back the core header via the flash data source |
|
155 const TCrashInfoHeader& header = src->GetCrashHeader(); |
|
156 |
|
157 //There isn't much checking we can do here as a lot of the things are determinable. |
|
158 //Its only a smoke test anyway to make sure the data source is functioning |
|
159 INFO_PRINTF1(_L("Checking the process ID that crashed was 1")); |
|
160 if(header.iPid != 0x1) |
|
161 { |
|
162 ERR_PRINTF1(_L("Failed to retrieve proper crashed process ID")); |
|
163 SetBlockResult(EFail); |
|
164 CleanupStack::PopAndDestroy(2); |
|
165 return; |
|
166 } |
|
167 |
|
168 INFO_PRINTF1(_L("Checking a valid crashed process ID")); |
|
169 if(header.iTid <= 0x1) |
|
170 { |
|
171 ERR_PRINTF1(_L("Failed to retrieve proper crashed process ID")); |
|
172 SetBlockResult(EFail); |
|
173 CleanupStack::PopAndDestroy(2); |
|
174 return; |
|
175 } |
|
176 |
|
177 const TRmdArmExcInfo registers = src->GetCrashContext(); |
|
178 |
|
179 const TUint32 cpsr = registers.iCpsr; |
|
180 |
|
181 INFO_PRINTF1(_L("Checking a valid CPSR and were in SVR mode when we crashed")); |
|
182 if(KCPSRUsrMode == (cpsr & 0x1F)) |
|
183 { |
|
184 ERR_PRINTF2(_L("CPSR = 0x%X --> Not in SVR mode"), cpsr); |
|
185 SetBlockResult(EFail); |
|
186 CleanupStack::PopAndDestroy(2); |
|
187 return; |
|
188 } |
|
189 |
|
190 //Now, erase the partition |
|
191 |
|
192 TRAPD(err, iCoreDumpSession.DeleteCrashPartitionL()); |
|
193 if(KErrNone != err) |
|
194 { |
|
195 RDebug::Printf("\ndeleteing failed with %d", err); |
|
196 } |
|
197 |
|
198 INFO_PRINTF1(_L("Negative test. Testing flash data source does as expected when there is no data in partition")); |
|
199 |
|
200 TRAP(err, src->AnalyseCrashL(0)); |
|
201 if(KErrNone == err) |
|
202 { |
|
203 ERR_PRINTF1(_L("Were able to analyse a non existant crash with KErrNone")); |
|
204 SetBlockResult(EFail); |
|
205 CleanupStack::PopAndDestroy(2); |
|
206 return; |
|
207 } |
|
208 |
|
209 INFO_PRINTF2(_L("Analysis gave %d as expected"), err); |
|
210 |
|
211 CleanupStack::PopAndDestroy(2); |
|
212 } |
|
213 |
|
214 /** |
|
215 * Testing we can retrieve trace data when it is present |
|
216 */ |
|
217 void CCoreDumpServerWrapper::TestDataSourceReturnsTraceDataL() |
|
218 { |
|
219 INFO_PRINTF1(_L("TestDataSourceReturnsTraceDataL")); |
|
220 |
|
221 //Load Test Formatter |
|
222 CFlashDataSource* src = CFlashDataSource::NewL(iSecSess); |
|
223 CleanupStack::PushL(src); |
|
224 |
|
225 RCrashInfoPointerList* crashList = new(ELeave)RCrashInfoPointerList; |
|
226 TCleanupItem listCleanup(CCoreDumpServerWrapper::CleanupCrashList, (TAny*)crashList); |
|
227 CleanupStack::PushL(listCleanup); |
|
228 |
|
229 //Get the crashes from the flash partition |
|
230 iCoreDumpSession.ListCrashesInFlashL(*crashList); |
|
231 |
|
232 if(crashList->Count() == 0) |
|
233 { |
|
234 ERR_PRINTF1(_L("Failed to find any crashes in the flash that we could check out")); |
|
235 SetBlockResult(EFail); |
|
236 CleanupStack::PopAndDestroy(2); |
|
237 return; |
|
238 } |
|
239 |
|
240 INFO_PRINTF2(_L("Found [%d] crash(es) on the partition"), crashList->Count()); |
|
241 |
|
242 INFO_PRINTF1(_L("Analysing crash 0")); |
|
243 src->AnalyseCrashL(((*crashList)[0])->iCrashId); |
|
244 |
|
245 INFO_PRINTF1(_L("Analysis successful")); |
|
246 |
|
247 TUint sizeToRead = 0x100; |
|
248 RBuf8 traceData; |
|
249 traceData.CreateL(sizeToRead); |
|
250 traceData.CleanupClosePushL(); |
|
251 |
|
252 INFO_PRINTF1(_L("Reading the trace buffer")); |
|
253 |
|
254 TRAPD(err, src->ReadTraceBufferL(traceData)); |
|
255 if(err != KErrNone) |
|
256 { |
|
257 ERR_PRINTF1(_L("Failed to get trace data")); |
|
258 SetBlockResult(EFail); |
|
259 CleanupStack::PopAndDestroy(3); |
|
260 return; |
|
261 } |
|
262 |
|
263 INFO_PRINTF1(_L("Making sure the trace data is correct")); |
|
264 |
|
265 //Can't analyse this data, just make sure its there |
|
266 if(sizeToRead != traceData.Length()) |
|
267 { |
|
268 ERR_PRINTF1(_L("Didnt read all the trace data there")); |
|
269 SetBlockResult(EFail); |
|
270 CleanupStack::PopAndDestroy(3); |
|
271 return; |
|
272 } |
|
273 |
|
274 INFO_PRINTF1(_L("Trying to read with a zero sized buffer")); |
|
275 |
|
276 //See what happens when we put in a zero size buffer |
|
277 RBuf8 buf; |
|
278 buf.CreateL(0); |
|
279 buf.CleanupClosePushL(); |
|
280 |
|
281 TRAP(err, src->ReadTraceBufferL(buf)); |
|
282 if(err != KErrNone) |
|
283 { |
|
284 ERR_PRINTF1(_L("Failed to get trace data with a zero size buffer")); |
|
285 SetBlockResult(EFail); |
|
286 CleanupStack::PopAndDestroy(4); |
|
287 return; |
|
288 } |
|
289 |
|
290 CleanupStack::PopAndDestroy(4); |
|
291 } |
|
292 |
|
293 /** |
|
294 * This tests that untrusted clients cannot do things with the CDS that they shouldnt |
|
295 */ |
|
296 void CCoreDumpServerWrapper::TestUntrustedServerAccessL() |
|
297 { |
|
298 INFO_PRINTF1(_L("TestUntrustedServerAccessL")); |
|
299 |
|
300 INFO_PRINTF1(_L("Testing we can't list crashes from the flash partition")); |
|
301 |
|
302 RCrashInfoPointerList* crashList = new(ELeave)RCrashInfoPointerList; |
|
303 TRAPD(err, iCoreDumpSession.ListCrashesInFlashL(*crashList)); |
|
304 if(err != KErrPermissionDenied) |
|
305 { |
|
306 delete crashList; |
|
307 ERR_PRINTF1(_L("Allowed to List crashes - shouldnt be. Are you sure the CDS token isn't in the ROM or on the device?")); |
|
308 SetBlockResult(EFail); |
|
309 return; |
|
310 } |
|
311 |
|
312 delete crashList; |
|
313 |
|
314 INFO_PRINTF1(_L("Testing we can't delete the flash partition")); |
|
315 TRAP(err, iCoreDumpSession.DeleteCrashPartitionL()); |
|
316 if(err != KErrPermissionDenied) |
|
317 { |
|
318 ERR_PRINTF1(_L("Allowed to delete flash partition - shouldnt be. Are you sure the CDS token isn't in the ROM or on the device?")); |
|
319 SetBlockResult(EFail); |
|
320 return; |
|
321 } |
|
322 |
|
323 INFO_PRINTF1(_L("Testing we can't process crash logs")); |
|
324 TRAP(err, iCoreDumpSession.ProcessCrashLogL(0)); |
|
325 if(err != KErrPermissionDenied) |
|
326 { |
|
327 ERR_PRINTF2(_L("Allowed to process crash logs (%d) - shouldn't be. Are you sure the CDS token isn't in the ROM or on the device?"), err); |
|
328 SetBlockResult(EFail); |
|
329 return; |
|
330 } |
|
331 |
|
332 INFO_PRINTF1(_L("All is good. Move along, nothing to see here")); |
|
333 } |
|
334 |
|
335 /** |
|
336 * Cleanup item implementation for RCrashInfoPointerList |
|
337 * @param aArray pointer to the list that is supposed to be freed |
|
338 */ |
|
339 void CCoreDumpServerWrapper::CleanupCrashList(TAny *aArray) |
|
340 { |
|
341 RCrashInfoPointerList* crashList = static_cast<RCrashInfoPointerList*> (aArray); |
|
342 crashList->ResetAndDestroy(); |
|
343 crashList->Close(); |
|
344 delete crashList; |
|
345 } |
|
346 |
|
347 //eof |