0
|
1 |
// Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
2 |
// All rights reserved.
|
|
3 |
// This component and the accompanying materials are made available
|
|
4 |
// under the terms of the License "Eclipse Public License v1.0"
|
|
5 |
// which accompanies this distribution, and is available
|
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
7 |
//
|
|
8 |
// Initial Contributors:
|
|
9 |
// Nokia Corporation - initial contribution.
|
|
10 |
//
|
|
11 |
// Contributors:
|
|
12 |
//
|
|
13 |
// Description:
|
|
14 |
// Tests the functionality of the run mode debug device driver.
|
|
15 |
//
|
|
16 |
//
|
|
17 |
|
|
18 |
#include <e32base.h>
|
|
19 |
#include <e32base_private.h>
|
|
20 |
#include <e32cons.h>
|
|
21 |
#include <e32test.h>
|
|
22 |
#include <e32ldr.h>
|
|
23 |
#include <e32cmn.h>
|
|
24 |
#include <e32cmn_private.h>
|
|
25 |
#include <f32dbg.h>
|
|
26 |
#include <f32file.h>
|
|
27 |
#include <hal.h>
|
|
28 |
#include <u32hal.h>
|
|
29 |
#include <e32property.h>
|
|
30 |
|
|
31 |
#include "t_rmdebug_dll.h"
|
|
32 |
|
|
33 |
#include <rm_debug_api.h>
|
|
34 |
#include "d_rmdebugthread2.h"
|
|
35 |
#include "t_rmdebug2.h"
|
|
36 |
#include "t_rmdebug_app.h"
|
|
37 |
|
|
38 |
#ifdef __MARM_ARMV4__
|
|
39 |
#include "d_rmdebug_step_test_armv4.h"
|
|
40 |
#endif
|
|
41 |
|
|
42 |
#ifdef __MARM_ARMV5__
|
|
43 |
#include "d_rmdebug_step_test.h"
|
|
44 |
#endif
|
|
45 |
|
|
46 |
#include "d_demand_paging.h"
|
|
47 |
|
|
48 |
#ifdef KERNEL_OOM_TESTING
|
|
49 |
#ifdef USER_OOM_TESTING
|
|
50 |
#error "Cannot define both KERNEL_OOM_TESTING and USER_OOM_TESTING"
|
|
51 |
#endif
|
|
52 |
#endif
|
|
53 |
|
|
54 |
_LIT8(KCrashDummyData, "This is a sample write");
|
|
55 |
|
|
56 |
using namespace Debug;
|
|
57 |
|
|
58 |
const TVersion securityServerVersion(0,1,1);
|
|
59 |
|
|
60 |
const TVersion testVersion(2,1,0);
|
|
61 |
|
|
62 |
IMPORT_C TInt StartDebugThread(RThread& aServerThread, const TDesC& aDebugThreadName);
|
|
63 |
IMPORT_D extern TInt TestData;
|
|
64 |
IMPORT_D extern TTestFunction FunctionChooser;
|
|
65 |
IMPORT_D extern TBuf8<SYMBIAN_RMDBG_MEMORYSIZE> gMemoryAccessBytes;
|
|
66 |
IMPORT_C TInt TestFunction();
|
|
67 |
IMPORT_C void TestPagedCode();
|
|
68 |
IMPORT_C extern TInt RMDebugDemandPagingTest();
|
|
69 |
|
|
70 |
// Device driver name
|
|
71 |
_LIT(KDebugDriverFileName,"rm_debug.ldd");
|
|
72 |
|
|
73 |
#ifdef SYMBIAN_STANDARDDEBUG
|
|
74 |
LOCAL_D RTest test(_L("T_RMDEBUG2"));
|
|
75 |
#endif
|
|
76 |
|
|
77 |
#ifdef SYMBIAN_OEMDEBUG
|
|
78 |
LOCAL_D RTest test(_L("T_RMDEBUG2_OEM"));
|
|
79 |
#endif
|
|
80 |
|
|
81 |
#ifdef SYMBIAN_OEM2DEBUG
|
|
82 |
LOCAL_D RTest test(_L("T_RMDEBUG2_OEM2"));
|
|
83 |
#endif
|
|
84 |
|
|
85 |
CRunModeAgent::CRunModeAgent()
|
|
86 |
//
|
|
87 |
// CRunModeAgent constructor
|
|
88 |
//
|
|
89 |
{
|
|
90 |
FillArray();
|
|
91 |
RProcess thisProcess;
|
|
92 |
iFileName = thisProcess.FileName();
|
|
93 |
thisProcess.Close();
|
|
94 |
}
|
|
95 |
|
|
96 |
CRunModeAgent* CRunModeAgent::NewL()
|
|
97 |
//
|
|
98 |
// CRunModeAgent::NewL
|
|
99 |
//
|
|
100 |
{
|
|
101 |
CRunModeAgent* self = new(ELeave) CRunModeAgent();
|
|
102 |
|
|
103 |
self->ConstructL();
|
|
104 |
|
|
105 |
return self;
|
|
106 |
}
|
|
107 |
|
|
108 |
CRunModeAgent::~CRunModeAgent()
|
|
109 |
//
|
|
110 |
// CRunModeAgent destructor
|
|
111 |
//
|
|
112 |
{
|
|
113 |
User::FreeLogicalDevice(KDebugDriverFileName);
|
|
114 |
iServSession.Close();
|
|
115 |
iDebugThread.Close();
|
|
116 |
}
|
|
117 |
|
|
118 |
void CRunModeAgent::ConstructL()
|
|
119 |
//
|
|
120 |
// CRunModeAgent::ConstructL
|
|
121 |
//
|
|
122 |
{
|
|
123 |
// nothing to do here
|
|
124 |
}
|
|
125 |
|
|
126 |
void CRunModeAgent::SetupAndAttachToDSS()
|
|
127 |
//
|
|
128 |
// CRunModeAgent::SetupAndAttachToDSS
|
|
129 |
//
|
|
130 |
{
|
|
131 |
TInt err = StartDebugThread(iDebugThread, KDebugThreadName);
|
|
132 |
|
|
133 |
// get the thread id for use in the tests
|
|
134 |
iThreadID = iDebugThread.Id();
|
|
135 |
|
|
136 |
if (err != KErrNone)
|
|
137 |
{
|
|
138 |
User::Panic(_L("Can't start debug thread"), err);
|
|
139 |
}
|
|
140 |
|
|
141 |
err = iServSession.Connect(securityServerVersion);
|
|
142 |
if (err != KErrNone)
|
|
143 |
{
|
|
144 |
User::Panic(_L("Can't open server session"), err);
|
|
145 |
}
|
|
146 |
}
|
|
147 |
|
|
148 |
CRunModeAgent *RunModeAgent;
|
|
149 |
|
|
150 |
// helper function to check whether the listing of type aListId is supported for a scope of aListScope
|
|
151 |
TBool CRunModeAgent::ListingSupported(const TListId aListId, const TListScope aListScope)
|
|
152 |
{
|
|
153 |
TTag tag = GetTag(ETagHeaderList, aListId);
|
|
154 |
|
|
155 |
return (tag.iValue) & aListScope;
|
|
156 |
}
|
|
157 |
|
|
158 |
//---------------------------------------------
|
|
159 |
//! @SYMTestCaseID KBase-T-RMDEBUG2-0426
|
|
160 |
//! @SYMTestType
|
|
161 |
//! @SYMPREQ PREQ1426
|
|
162 |
//! @SYMTestCaseDesc Test getting the list of XIP libraries
|
|
163 |
//! @SYMTestActions The XIP library list should be successfully obtained
|
|
164 |
//! @SYMTestExpectedResults The specified ldd file should be present in the obtained listing
|
|
165 |
//! @SYMTestPriority High
|
|
166 |
//! @SYMTestStatus Implemented
|
|
167 |
//---------------------------------------------
|
|
168 |
void CRunModeAgent::TestGetXipLibrariesList()
|
|
169 |
{
|
|
170 |
test.Next(_L("TestGetXipLibrariesList\n"));
|
|
171 |
|
|
172 |
test(ListingSupported(EXipLibraries, EScopeGlobal));
|
|
173 |
test(!ListingSupported(EXipLibraries, EScopeProcessSpecific));
|
|
174 |
test(!ListingSupported(EXipLibraries, EScopeThreadSpecific));
|
|
175 |
|
|
176 |
//allocate a very small buffer so the GetList call initially fails
|
|
177 |
RBuf8 buffer;
|
|
178 |
test(KErrNone == buffer.Create(1));
|
|
179 |
TUint32 size = 0;
|
|
180 |
|
|
181 |
//get the list data
|
|
182 |
DoGetList(EXipLibraries, EScopeGlobal, buffer, size);
|
|
183 |
|
|
184 |
//search the buffer for entry corresponding to the debug kernel driver
|
|
185 |
//which should be in the rom
|
|
186 |
_LIT(KRmDebugLddName, "z:\\sys\\bin\\rm_debug.ldd");
|
|
187 |
|
|
188 |
//iterate through the buffer and set found to ETrue if we find the driver
|
|
189 |
TBool found = EFalse;
|
|
190 |
TUint8* ptr = (TUint8*)buffer.Ptr();
|
|
191 |
const TUint8* ptrEnd = ptr + size;
|
|
192 |
while(ptr < ptrEnd)
|
|
193 |
{
|
|
194 |
TXipLibraryListEntry& xipLibrary = *(TXipLibraryListEntry*)ptr;
|
|
195 |
|
|
196 |
//get the name of the library
|
|
197 |
TPtr name(&xipLibrary.iName[0], xipLibrary.iNameLength, xipLibrary.iNameLength);
|
|
198 |
if(name.CompareF(KRmDebugLddName()) == 0)
|
|
199 |
{
|
|
200 |
//found the library but continue reading the rest of the buffer to
|
|
201 |
//check nothing bad happens towards the end
|
|
202 |
found = ETrue;
|
|
203 |
}
|
|
204 |
//move pointer on to next library
|
|
205 |
ptr += Align4(xipLibrary.GetSize());
|
|
206 |
}
|
|
207 |
test(found);
|
|
208 |
|
|
209 |
//do cleanup
|
|
210 |
buffer.Close();
|
|
211 |
}
|
|
212 |
|
|
213 |
//---------------------------------------------
|
|
214 |
//! @SYMTestCaseID KBase-T-RMDEBUG2-0427
|
|
215 |
//! @SYMTestType
|
|
216 |
//! @SYMPREQ PREQ1426
|
|
217 |
//! @SYMTestCaseDesc Test getting the list of executables
|
|
218 |
//! @SYMTestActions The list of debuggable executable files should be obtained
|
|
219 |
//! @SYMTestExpectedResults The client exe should appear in the list
|
|
220 |
//! @SYMTestPriority High
|
|
221 |
//! @SYMTestStatus Implemented
|
|
222 |
//---------------------------------------------
|
|
223 |
void CRunModeAgent::TestGetExecutablesList()
|
|
224 |
{
|
|
225 |
test.Next(_L("TestGetExecutablesList\n"));
|
|
226 |
|
|
227 |
test(ListingSupported(EExecutables, EScopeGlobal));
|
|
228 |
test(!ListingSupported(EExecutables, EScopeProcessSpecific));
|
|
229 |
test(!ListingSupported(EExecutables, EScopeThreadSpecific));
|
|
230 |
|
|
231 |
//allocate a very small buffer so the GetList call initially fails
|
|
232 |
RBuf8 buffer;
|
|
233 |
test(KErrNone == buffer.Create(1));
|
|
234 |
TUint32 size = 0;
|
|
235 |
|
|
236 |
test(KErrNone == iServSession.AttachExecutable(iFileName, EFalse));
|
|
237 |
|
|
238 |
//get the list data
|
|
239 |
DoGetList(EExecutables, EScopeGlobal, buffer, size);
|
|
240 |
|
|
241 |
//get this process' name
|
|
242 |
RProcess thisProcess;
|
|
243 |
TFileName thisProcessName = thisProcess.FileName();
|
|
244 |
|
|
245 |
//look through the buffer and check if the target debug thread is there
|
|
246 |
TBool found = EFalse;
|
|
247 |
TUint8* ptr = (TUint8*)buffer.Ptr();
|
|
248 |
const TUint8* ptrEnd = ptr + size;
|
|
249 |
while(ptr < ptrEnd)
|
|
250 |
{
|
|
251 |
TExecutablesListEntry& entry = *(TExecutablesListEntry*)ptr;
|
|
252 |
//get name
|
|
253 |
TPtr name(&entry.iName[0], entry.iNameLength, entry.iNameLength);
|
|
254 |
if( (entry.iIsActivelyDebugged != 0) && (0 == thisProcessName.CompareF(name)) )
|
|
255 |
{
|
|
256 |
//found this process and asserted it is being actively debugged
|
|
257 |
found = ETrue;
|
|
258 |
}
|
|
259 |
//move pointer on to next entry
|
|
260 |
ptr += Align4(entry.GetSize());
|
|
261 |
}
|
|
262 |
test(found);
|
|
263 |
|
|
264 |
//clean up
|
|
265 |
buffer.Close();
|
|
266 |
|
|
267 |
test(KErrNone == iServSession.DetachExecutable(iFileName));
|
|
268 |
}
|
|
269 |
|
|
270 |
//---------------------------------------------
|
|
271 |
//! @SYMTestCaseID KBase-T-RMDEBUG2-0428
|
|
272 |
//! @SYMTestType
|
|
273 |
//! @SYMPREQ PREQ1426
|
|
274 |
//! @SYMTestCaseDesc Test error conditions for the GetList calls
|
|
275 |
//! @SYMTestActions Multiple calls to test calling GetList with bad arguments
|
|
276 |
//! @SYMTestExpectedResults All tests should fail with the appropriate error codes
|
|
277 |
//! @SYMTestPriority High
|
|
278 |
//! @SYMTestStatus Implemented
|
|
279 |
//---------------------------------------------
|
|
280 |
void CRunModeAgent::TestGetListInvalidData()
|
|
281 |
{
|
|
282 |
test.Next(_L("TestGetListInvalidData\n"));
|
|
283 |
|
|
284 |
//allocate a buffer, the size should not matter as expecting all calls to fail
|
|
285 |
RBuf8 buffer;
|
|
286 |
test(KErrNone == buffer.Create(1));
|
|
287 |
TUint32 size = 0;
|
|
288 |
|
|
289 |
//test what happens if we ask for an unsupported list type globally
|
|
290 |
test(KErrNotSupported == iServSession.GetList((TListId)1234, buffer, size));
|
|
291 |
|
|
292 |
//test what happens if we ask for an unsupported list type
|
|
293 |
test(KErrNotSupported == iServSession.GetList(RThread().Id(), (TListId)1234, buffer, size));
|
|
294 |
|
|
295 |
//test what happens if we try to get a non-global libraries list
|
|
296 |
test(KErrArgument == iServSession.GetList(RThread().Id(), EXipLibraries, buffer, size));
|
|
297 |
|
|
298 |
//test what happens if we try to get a non-global executables list
|
|
299 |
test(KErrArgument == iServSession.GetList(RThread().Id(), EExecutables, buffer, size));
|
|
300 |
|
|
301 |
//test what happens if we try to get a non-global process list
|
|
302 |
test(KErrArgument == iServSession.GetList(RThread().Id(), EProcesses, buffer, size));
|
|
303 |
|
|
304 |
//check that using a process id fails
|
|
305 |
test(KErrArgument == iServSession.GetList(RProcess().Id(), EProcesses, buffer, size));
|
|
306 |
|
|
307 |
//check that specifying a non-existant thread id fails
|
|
308 |
test(KErrArgument == iServSession.GetList((TThreadId)0x12345678, EThreads, buffer, size));
|
|
309 |
|
|
310 |
//check that specifying a non-existant process id fails
|
|
311 |
test(KErrArgument == iServSession.GetList((TProcessId)0x12345678, EThreads, buffer, size));
|
|
312 |
|
|
313 |
//check that specifying a non-existant thread id fails
|
|
314 |
test(KErrArgument == iServSession.GetList((TThreadId)0x12345678, ECodeSegs, buffer, size));
|
|
315 |
|
|
316 |
//check that specifying a non-existant process id fails
|
|
317 |
test(KErrArgument == iServSession.GetList((TProcessId)0x12345678, ECodeSegs, buffer, size));
|
|
318 |
|
|
319 |
//cleanup
|
|
320 |
buffer.Close();
|
|
321 |
}
|
|
322 |
|
|
323 |
//---------------------------------------------
|
|
324 |
//! @SYMTestCaseID KBase-T-RMDEBUG2-0429
|
|
325 |
//! @SYMTestType
|
|
326 |
//! @SYMPREQ PREQ1426
|
|
327 |
//! @SYMTestCaseDesc Test getting the process list
|
|
328 |
//! @SYMTestActions Get the process listing
|
|
329 |
//! @SYMTestExpectedResults The process listing should be successfully obtained and the current process should be present in the list
|
|
330 |
//! @SYMTestPriority High
|
|
331 |
//! @SYMTestStatus Implemented
|
|
332 |
//---------------------------------------------
|
|
333 |
void CRunModeAgent::TestGetProcessList()
|
|
334 |
{
|
|
335 |
test.Next(_L("TestGetProcessList\n"));
|
|
336 |
|
|
337 |
test(ListingSupported(EProcesses, EScopeGlobal));
|
|
338 |
test(!ListingSupported(EProcesses, EScopeProcessSpecific));
|
|
339 |
test(!ListingSupported(EProcesses, EScopeThreadSpecific));
|
|
340 |
|
|
341 |
//allocate a very small buffer so the GetList call fails
|
|
342 |
RBuf8 buffer;
|
|
343 |
test(KErrNone == buffer.Create(1));
|
|
344 |
TUint32 size = 0;
|
|
345 |
|
|
346 |
//get the list data
|
|
347 |
DoGetList(EProcesses, EScopeGlobal, buffer, size);
|
|
348 |
|
|
349 |
//initialise data about the target debug thread to compare the kernel's data against
|
|
350 |
RProcess thisProcess;
|
|
351 |
TFileName thisProcessName = thisProcess.FileName();
|
|
352 |
TUint32 processId = thisProcess.Id().Id();
|
|
353 |
|
|
354 |
//look through the buffer and check if the target debug thread is there
|
|
355 |
TBool found = EFalse;
|
|
356 |
TUint8* ptr = (TUint8*)buffer.Ptr();
|
|
357 |
const TUint8* ptrEnd = ptr + size;
|
|
358 |
while(ptr < ptrEnd)
|
|
359 |
{
|
|
360 |
TProcessListEntry& entry = *(TProcessListEntry*)ptr;
|
|
361 |
if( (RProcess().Id().Id() == entry.iProcessId) &&
|
|
362 |
(0 == thisProcessName.CompareF(TPtr(&(entry.iNames[0]), entry.iFileNameLength, entry.iFileNameLength))) &&
|
|
363 |
(0 == thisProcess.FullName().CompareF(TPtr(&(entry.iNames[0]) + entry.iFileNameLength, entry.iDynamicNameLength, entry.iDynamicNameLength))) &&
|
|
364 |
0x4321bbbb /* Magic */ == entry.iUid3)
|
|
365 |
{
|
|
366 |
//if all match then we've found it
|
|
367 |
found = ETrue;
|
|
368 |
}
|
|
369 |
ptr += Align4(entry.GetSize());
|
|
370 |
}
|
|
371 |
|
|
372 |
//check whether the expected result happened
|
|
373 |
test(found);
|
|
374 |
|
|
375 |
//clean up
|
|
376 |
buffer.Close();
|
|
377 |
}
|
|
378 |
|
|
379 |
//---------------------------------------------
|
|
380 |
//! @SYMTestCaseID KBase-T-RMDEBUG2-0430
|
|
381 |
//! @SYMTestType
|
|
382 |
//! @SYMPREQ PREQ1426
|
|
383 |
//! @SYMTestCaseDesc Test getting the thread list
|
|
384 |
//! @SYMTestActions Get the thread listing globally and for a specified thread or process
|
|
385 |
//! @SYMTestExpectedResults The thread listings should all be successfully obtained and the current thread should be present in all listings
|
|
386 |
//! @SYMTestPriority High
|
|
387 |
//! @SYMTestStatus Implemented
|
|
388 |
//---------------------------------------------
|
|
389 |
void CRunModeAgent::TestGetThreadList()
|
|
390 |
{
|
|
391 |
test.Next(_L("TestGetThreadList\n"));
|
|
392 |
|
|
393 |
test(ListingSupported(EThreads, EScopeGlobal));
|
|
394 |
test(ListingSupported(EThreads, EScopeProcessSpecific));
|
|
395 |
test(ListingSupported(EThreads, EScopeThreadSpecific));
|
|
396 |
|
|
397 |
test(KErrNone == iServSession.AttachExecutable(iFileName, EFalse));
|
|
398 |
test(KErrNone == iServSession.SuspendThread(iThreadID));
|
|
399 |
|
|
400 |
//test getting the global list, ETrue as should find the target debug thread
|
|
401 |
DoTestGetThreadList(ETrue, EScopeGlobal);
|
|
402 |
|
|
403 |
//test getting this thread's thread list, ETrue as should find the target debug thread
|
|
404 |
DoTestGetThreadList(ETrue, EScopeThreadSpecific, RThread().Id().Id());
|
|
405 |
|
|
406 |
//test getting this process's thread list, ETrue as should find the target debug thread
|
|
407 |
DoTestGetThreadList(ETrue, EScopeProcessSpecific, RProcess().Id().Id());
|
|
408 |
|
|
409 |
test(KErrNone == iServSession.ResumeThread(iThreadID));
|
|
410 |
test(KErrNone == iServSession.DetachExecutable(iFileName));
|
|
411 |
}
|
|
412 |
|
|
413 |
void CRunModeAgent::DoTestGetThreadList(const TBool aShouldPass, const TListScope aListScope, const TUint64 aTargetId)
|
|
414 |
{
|
|
415 |
test.Next(_L("DoTestGetThreadList\n"));
|
|
416 |
|
|
417 |
//create data to pass
|
|
418 |
RBuf8 buffer;
|
|
419 |
TUint32 size = 0;
|
|
420 |
|
|
421 |
//perform the call to get the Code segs
|
|
422 |
DoGetList(EThreads, aListScope, buffer, size, aTargetId);
|
|
423 |
|
|
424 |
//initialise data about the target debug thread to compare the kernel's data against
|
|
425 |
TFileName name = iDebugThread.FullName();
|
|
426 |
RProcess thisProcess;
|
|
427 |
TUint64 processId = thisProcess.Id();
|
|
428 |
TUint64 threadId = iDebugThread.Id();
|
|
429 |
|
|
430 |
//look through the buffer and check if the target debug thread is there
|
|
431 |
TBool found = EFalse;
|
|
432 |
TUint8* ptr = (TUint8*)buffer.Ptr();
|
|
433 |
const TUint8* ptrEnd = ptr + size;
|
|
434 |
while(ptr < ptrEnd)
|
|
435 |
{
|
|
436 |
TThreadListEntry* entry = (TThreadListEntry*)ptr;
|
|
437 |
TPtr entryName(&(entry->iName[0]), entry->iNameLength, entry->iNameLength);
|
|
438 |
if( (threadId == entry->iThreadId) && (processId == entry->iProcessId) && (0 == name.CompareF(entryName)) )
|
|
439 |
{
|
|
440 |
test(entry->iSupervisorStackBaseValid);
|
|
441 |
test(entry->iSupervisorStackSizeValid);
|
|
442 |
//if all match then we've found it
|
|
443 |
found = ETrue;
|
|
444 |
}
|
|
445 |
|
|
446 |
ptr += Align4(entry->GetSize());
|
|
447 |
}
|
|
448 |
|
|
449 |
//check whether the expected result happened
|
|
450 |
test(found == aShouldPass);
|
|
451 |
|
|
452 |
//clean up
|
|
453 |
buffer.Close();
|
|
454 |
|
|
455 |
}
|
|
456 |
|
|
457 |
//---------------------------------------------
|
|
458 |
//! @SYMTestCaseID KBase-T-RMDEBUG2-0431
|
|
459 |
//! @SYMTestType
|
|
460 |
//! @SYMPREQ PREQ1426
|
|
461 |
//! @SYMTestCaseDesc Test getting the code segment list
|
|
462 |
//! @SYMTestActions Get the code segment list global and for a specified thread
|
|
463 |
//! @SYMTestExpectedResults The listings should be returned successfully
|
|
464 |
//! @SYMTestPriority High
|
|
465 |
//! @SYMTestStatus Implemented
|
|
466 |
//---------------------------------------------
|
|
467 |
void CRunModeAgent::TestGetCodeSegsList()
|
|
468 |
{
|
|
469 |
test.Next(_L("TestGetCodeSegsList\n"));
|
|
470 |
|
|
471 |
test(ListingSupported(ECodeSegs, EScopeGlobal));
|
|
472 |
test(ListingSupported(ECodeSegs, EScopeProcessSpecific));
|
|
473 |
test(ListingSupported(ECodeSegs, EScopeThreadSpecific));
|
|
474 |
|
|
475 |
// Cannot perform this test with OEM2 debug token, as the t_rmdebug2 app
|
|
476 |
// needs AllFiles, and the OEM2 debug token does not authorise this.
|
|
477 |
// It seems reasonable to suppose that it would work anyway
|
|
478 |
|
|
479 |
#ifndef SYMBIAN_OEM2DEBUG
|
|
480 |
test(KErrNone == iServSession.AttachExecutable(iFileName, EFalse));
|
|
481 |
|
|
482 |
//test getting the global list, ETrue as should find this process' main codeSeg
|
|
483 |
DoTestGetCodeSegsList(ETrue, EScopeGlobal);
|
|
484 |
|
|
485 |
//test getting this process' codeSegs, ETrue as should find this process' main codeSeg
|
|
486 |
DoTestGetCodeSegsList(ETrue, EScopeProcessSpecific, RProcess().Id().Id());
|
|
487 |
|
|
488 |
//test getting this thread's codeSegs, ETrue as should find this process' main codeSeg
|
|
489 |
DoTestGetCodeSegsList(ETrue, EScopeThreadSpecific, RThread().Id().Id());
|
|
490 |
|
|
491 |
test(KErrNone == iServSession.DetachExecutable(iFileName));
|
|
492 |
#endif // SYMBIAN_OEM2DEBUG
|
|
493 |
|
|
494 |
}
|
|
495 |
|
|
496 |
void CRunModeAgent::DoTestGetCodeSegsList(const TBool aShouldPass, const TListScope aListScope, const TUint64 aTargetId)
|
|
497 |
{
|
|
498 |
//create data to pass
|
|
499 |
RBuf8 buffer;
|
|
500 |
TUint32 size = 0;
|
|
501 |
|
|
502 |
//perform the call to get the Code segs
|
|
503 |
DoGetList(ECodeSegs, aListScope, buffer, size, aTargetId);
|
|
504 |
|
|
505 |
//create memoryInfo to contain info about this process
|
|
506 |
RProcess thisProcess;
|
|
507 |
TModuleMemoryInfo memoryInfo;
|
|
508 |
test(KErrNone == thisProcess.GetMemoryInfo(memoryInfo));
|
|
509 |
|
|
510 |
// check whether this process came from a file in ROM so we know whether to
|
|
511 |
// expect the code seg to be XIP or not.
|
|
512 |
RFs fs;
|
|
513 |
test(KErrNone == fs.Connect());
|
|
514 |
TBool thisFileIsInRom = EFalse;
|
|
515 |
if(fs.IsFileInRom(iFileName))
|
|
516 |
{
|
|
517 |
thisFileIsInRom = ETrue;
|
|
518 |
}
|
|
519 |
|
|
520 |
//look through the buffer to find this process' main code seg
|
|
521 |
TBool found = EFalse;
|
|
522 |
TUint8* ptr = (TUint8*)buffer.Ptr();
|
|
523 |
const TUint8* ptrEnd = ptr + size;
|
|
524 |
while(ptr < ptrEnd)
|
|
525 |
{
|
|
526 |
TCodeSegListEntry* codeSeg = (TCodeSegListEntry*)ptr;
|
|
527 |
|
|
528 |
if( (codeSeg->iIsXip == thisFileIsInRom) && (0 == iFileName.CompareF(TPtr(&(codeSeg->iName[0]), codeSeg->iNameLength, codeSeg->iNameLength))) )
|
|
529 |
{
|
|
530 |
if( (memoryInfo.iCodeBase == codeSeg->iCodeBase) &&
|
|
531 |
(memoryInfo.iCodeSize == codeSeg->iCodeSize) &&
|
|
532 |
(memoryInfo.iConstDataSize == codeSeg->iConstDataSize) &&
|
|
533 |
(memoryInfo.iInitialisedDataBase == codeSeg->iInitialisedDataBase) &&
|
|
534 |
(memoryInfo.iInitialisedDataSize == codeSeg->iInitialisedDataSize) &&
|
|
535 |
(memoryInfo.iUninitialisedDataSize == codeSeg->iUninitialisedDataSize))
|
|
536 |
{
|
|
537 |
//all matched so means we've found the codeSeg we're looking for
|
|
538 |
found = ETrue;
|
|
539 |
}
|
|
540 |
}
|
|
541 |
ptr += Align4(codeSeg->GetSize());
|
|
542 |
}
|
|
543 |
|
|
544 |
//check whether the result was as expected
|
|
545 |
test(found == aShouldPass);
|
|
546 |
|
|
547 |
// only care about rm_debug.ldd if we have global scope (belongs to the system not this process)
|
|
548 |
if (aListScope == EScopeGlobal)
|
|
549 |
{
|
|
550 |
// Search for rm_debug.ldd library and check its UID3 is correct
|
|
551 |
found = EFalse;
|
|
552 |
|
|
553 |
_LIT(KRMDebugDriverFileName,"Z:\\sys\bin\\rm_debug.ldd");
|
|
554 |
|
|
555 |
TFileName rmdebugFilename(KRMDebugDriverFileName);
|
|
556 |
|
|
557 |
// reset the Ptr
|
|
558 |
ptr = (TUint8*)buffer.Ptr();
|
|
559 |
ptrEnd = ptr+size;
|
|
560 |
while(ptr < ptrEnd)
|
|
561 |
{
|
|
562 |
TCodeSegListEntry* codeSeg = (TCodeSegListEntry*)ptr;
|
|
563 |
|
|
564 |
if( rmdebugFilename.CompareF(TPtr(&(codeSeg->iName[0]), codeSeg->iNameLength, codeSeg->iNameLength)))
|
|
565 |
{
|
|
566 |
if(codeSeg->iUid3 == 0x101f7157 /* Magic */)
|
|
567 |
{
|
|
568 |
//all matched so means we've found the codeSeg we're looking for
|
|
569 |
found = ETrue;
|
|
570 |
}
|
|
571 |
}
|
|
572 |
ptr += Align4(codeSeg->GetSize());
|
|
573 |
}
|
|
574 |
test((TUint32)found == (TUint32)ETrue);
|
|
575 |
}
|
|
576 |
|
|
577 |
//clean up
|
|
578 |
buffer.Close();
|
|
579 |
|
|
580 |
}
|
|
581 |
|
|
582 |
void CRunModeAgent::DoGetList(const TListId aListId, const TListScope aListScope, RBuf8& aBuffer, TUint32& aSize, const TUint64 aTargetId)
|
|
583 |
{
|
|
584 |
//close the buffer in case there's stuff allocated in it
|
|
585 |
aBuffer.Close();
|
|
586 |
//initialise it to be one byte big, which will guarantee data won't fit in it
|
|
587 |
test(KErrNone == aBuffer.Create(1));
|
|
588 |
aSize = 0;
|
|
589 |
|
|
590 |
//should pass this test (assuming we've passed in sensible arguments above...)
|
|
591 |
if(EScopeGlobal == aListScope)
|
|
592 |
{
|
|
593 |
test(KErrTooBig == iServSession.GetList(aListId, aBuffer, aSize));
|
|
594 |
}
|
|
595 |
else if(EScopeThreadSpecific == aListScope)
|
|
596 |
{
|
|
597 |
test(KErrTooBig == iServSession.GetList((TThreadId)aTargetId, aListId, aBuffer, aSize));
|
|
598 |
}
|
|
599 |
else if(EScopeProcessSpecific == aListScope)
|
|
600 |
{
|
|
601 |
test(KErrTooBig == iServSession.GetList((TProcessId)aTargetId, aListId, aBuffer, aSize));
|
|
602 |
}
|
|
603 |
else
|
|
604 |
{
|
|
605 |
// unknown list scope
|
|
606 |
test(0);
|
|
607 |
}
|
|
608 |
|
|
609 |
//keep allocating larger buffers, beginning with the aSize returned by the above call,
|
|
610 |
//and hopefully we'll eventually make a large enough one
|
|
611 |
test(KErrNone == aBuffer.ReAlloc(aSize));
|
|
612 |
|
|
613 |
for(;;)
|
|
614 |
{
|
|
615 |
TInt err = KErrNone;
|
|
616 |
if(EScopeGlobal == aListScope)
|
|
617 |
{
|
|
618 |
err = iServSession.GetList(aListId, aBuffer, aSize);
|
|
619 |
}
|
|
620 |
else if(EScopeThreadSpecific == aListScope)
|
|
621 |
{
|
|
622 |
err = iServSession.GetList((TThreadId)aTargetId, aListId, aBuffer, aSize);
|
|
623 |
}
|
|
624 |
else if(EScopeProcessSpecific == aListScope)
|
|
625 |
{
|
|
626 |
err = iServSession.GetList((TProcessId)aTargetId, aListId, aBuffer, aSize);
|
|
627 |
}
|
|
628 |
else
|
|
629 |
{
|
|
630 |
// unknown list scope
|
|
631 |
test(0);
|
|
632 |
}
|
|
633 |
if(err == KErrTooBig)
|
|
634 |
{
|
|
635 |
//wasn't big enough so double it
|
|
636 |
aSize = aSize << 1;
|
|
637 |
err = aBuffer.ReAlloc(aSize);
|
|
638 |
if(err != KErrNone)
|
|
639 |
{
|
|
640 |
//print out a message if couldn't allocate memory and quit
|
|
641 |
test.Printf(_L("Out ot memory when attempting to allocate %d bytes."), aSize);
|
|
642 |
test(KErrNone == err);
|
|
643 |
}
|
|
644 |
|
|
645 |
//fairly arbitrary test, we don't have a max size for these calls.
|
|
646 |
//In reality a list would have to have many thousands of elements
|
|
647 |
//to break this test which shouldn't really happen
|
|
648 |
test(aSize <= 0x4000);
|
|
649 |
}
|
|
650 |
else
|
|
651 |
{
|
|
652 |
test(KErrNone == err);
|
|
653 |
test(aBuffer.Length() == aSize);
|
|
654 |
//break out of the loop if the list has been successfully read in
|
|
655 |
break;
|
|
656 |
}
|
|
657 |
}
|
|
658 |
}
|
|
659 |
|
|
660 |
//---------------------------------------------
|
|
661 |
//! @SYMTestCaseID KBase-T-RMDEBUG2-0432
|
|
662 |
//! @SYMTestType
|
|
663 |
//! @SYMPREQ PREQ1426
|
|
664 |
//! @SYMTestCaseDesc Test reading and writing memory
|
|
665 |
//! @SYMTestActions Multiple calls to read and write memory, with various sizes and at various locations.
|
|
666 |
//! Also test that bad input values cause appropriate errors to be returned.
|
|
667 |
//! @SYMTestExpectedResults All tests should pass and the target process should be left unaffected
|
|
668 |
//! @SYMTestPriority High
|
|
669 |
//! @SYMTestStatus Implemented
|
|
670 |
//---------------------------------------------
|
|
671 |
void CRunModeAgent::TestMemoryAccess()
|
|
672 |
{
|
|
673 |
TInt err;
|
|
674 |
|
|
675 |
test.Next(_L("TestMemoryAccess - Read Memory\n"));
|
|
676 |
|
|
677 |
//initialise buffer
|
|
678 |
gMemoryAccessBytes.SetLength(0);
|
|
679 |
for (TInt i=0; i<SYMBIAN_RMDBG_MEMORYSIZE; i++)
|
|
680 |
{
|
|
681 |
gMemoryAccessBytes.Append(i);
|
|
682 |
}
|
|
683 |
|
|
684 |
TUint32 address = (TUint32)(&gMemoryAccessBytes[0]);
|
|
685 |
TUint32 dataSize = SYMBIAN_RMDBG_MEMORYSIZE;
|
|
686 |
|
|
687 |
//create size for buffer that is rounded up to nearest 4 bytes if not
|
|
688 |
//already 4 byte aligned
|
|
689 |
TUint32 size = dataSize;
|
|
690 |
if(size % 4 != 0)
|
|
691 |
{
|
|
692 |
size += (4 - (size % 4));
|
|
693 |
}
|
|
694 |
|
|
695 |
RBuf8 dataBlock;
|
|
696 |
err = dataBlock.Create(size);
|
|
697 |
test(err==KErrNone);
|
|
698 |
test(KErrNone == iServSession.AttachExecutable(iFileName, EFalse));
|
|
699 |
|
|
700 |
//suspend the thread prior to memory operations
|
|
701 |
test(KErrNone == iServSession.SuspendThread(iThreadID));
|
|
702 |
|
|
703 |
err = iServSession.ReadMemory(iThreadID, address, size, dataBlock, EAccess32, EEndLE8);
|
|
704 |
test(err==KErrNone);
|
|
705 |
|
|
706 |
for (TInt i=0; i<dataSize; i++)
|
|
707 |
{
|
|
708 |
test(dataBlock.Ptr()[i] == gMemoryAccessBytes[i]);
|
|
709 |
}
|
|
710 |
|
|
711 |
test.Next(_L("TestMemoryAccess - Write Memory\n"));
|
|
712 |
|
|
713 |
// Now reset the buffer
|
|
714 |
for (TInt i=0; i<dataSize; i++)
|
|
715 |
{
|
|
716 |
gMemoryAccessBytes[i] = 0;
|
|
717 |
}
|
|
718 |
|
|
719 |
// Write our data into the buffer
|
|
720 |
err = iServSession.WriteMemory(iThreadID, address, size, dataBlock, EAccess32, EEndLE8);
|
|
721 |
test(err==KErrNone);
|
|
722 |
|
|
723 |
for (TInt i=0; i<dataSize; i++)
|
|
724 |
{
|
|
725 |
test(dataBlock.Ptr()[i] == gMemoryAccessBytes[i]);
|
|
726 |
}
|
|
727 |
|
|
728 |
//final test that everything's not been going wrong
|
|
729 |
test(gMemoryAccessBytes[5] != 0);
|
|
730 |
|
|
731 |
test.Next(_L("TestMemoryAccess - Invalid arguments\n"));
|
|
732 |
test.Printf(_L("This test may emit crash-like information. This is intended.\n"));
|
|
733 |
|
|
734 |
//test address that is not 32 bit aligned
|
|
735 |
err = iServSession.ReadMemory(iThreadID, address + 1, size, dataBlock, EAccess32, EEndLE8);
|
|
736 |
test(err == KErrArgument);
|
|
737 |
|
|
738 |
//test size that is not multiple of 4 bytes
|
|
739 |
err = iServSession.WriteMemory(iThreadID, address, size + 2, dataBlock, EAccess32, EEndLE8);
|
|
740 |
test(err == KErrArgument);
|
|
741 |
|
|
742 |
//test size > max block size
|
|
743 |
err = iServSession.ReadMemory(iThreadID, address, (1<<15), dataBlock, EAccess32, EEndLE8);
|
|
744 |
test(err == KErrArgument);
|
|
745 |
|
|
746 |
//test access size == 2 bytes
|
|
747 |
err = iServSession.ReadMemory(iThreadID, address, size, dataBlock, EAccess16, EEndLE8);
|
|
748 |
test(err == KErrNotSupported);
|
|
749 |
|
|
750 |
//test access size == 1 byte
|
|
751 |
err = iServSession.WriteMemory(iThreadID, address, size, dataBlock, EAccess8, EEndLE8);
|
|
752 |
test(err == KErrNotSupported);
|
|
753 |
|
|
754 |
//test endianess == EEndBE8
|
|
755 |
err = iServSession.ReadMemory(iThreadID, address, size, dataBlock, EAccess32, EEndBE8);
|
|
756 |
test(err == KErrNotSupported);
|
|
757 |
|
|
758 |
//test endianess == EEndBE32
|
|
759 |
err = iServSession.WriteMemory(iThreadID, address, size, dataBlock, EAccess32, EEndBE32);
|
|
760 |
test(err == KErrNotSupported);
|
|
761 |
|
|
762 |
//test reading off end of memory
|
|
763 |
err = iServSession.ReadMemory(iThreadID, 0xffffff00, 0x00000101, dataBlock, EAccess32, EEndLE8);
|
|
764 |
test(err == KErrArgument);
|
|
765 |
|
|
766 |
//The following three tests check that edge conditions in the range check are handled correctly.
|
|
767 |
err = iServSession.ReadMemory(iThreadID, 0xffffff00, 0x000000FF, dataBlock, EAccess32, EEndLE8);
|
|
768 |
test(err == KErrArgument);
|
|
769 |
|
|
770 |
err = iServSession.ReadMemory(iThreadID, 0xffffff00, 0x000000F0, dataBlock, EAccess32, EEndLE8);
|
|
771 |
test(err == KErrBadDescriptor);
|
|
772 |
|
|
773 |
//Third range check test. Check that range check is handled correctly even when base + size wraps to 0.
|
|
774 |
err = iServSession.ReadMemory(iThreadID, 0xffffff00, 0x00000100, dataBlock, EAccess32, EEndLE8);
|
|
775 |
test(err == KErrBadDescriptor);
|
|
776 |
//end of range check tests
|
|
777 |
|
|
778 |
//test size == 0
|
|
779 |
err = iServSession.WriteMemory(iThreadID, address, 0, dataBlock, EAccess32, EEndLE8);
|
|
780 |
test(err == KErrArgument);
|
|
781 |
|
|
782 |
//attempt to write to address outside of process data segments,
|
|
783 |
//this address corresponds to the vectors so shouldn't be able to write
|
|
784 |
err = iServSession.WriteMemory(iThreadID, 0xffff0000, size, dataBlock, EAccess32, EEndLE8);
|
|
785 |
test(err == KErrBadDescriptor);
|
|
786 |
|
|
787 |
//attempt to read and write to address in process code segment
|
|
788 |
|
|
789 |
//open a handle to the thread
|
|
790 |
RThread debugThread;
|
|
791 |
test(debugThread.Open(iThreadID) == KErrNone);
|
|
792 |
|
|
793 |
//get a reference to the debug process
|
|
794 |
RProcess debugProcess;
|
|
795 |
test(debugThread.Process(debugProcess) == KErrNone);
|
|
796 |
|
|
797 |
//get the memory info for the process
|
|
798 |
TProcessMemoryInfo info;
|
|
799 |
test(debugProcess.GetMemoryInfo(info) == KErrNone);
|
|
800 |
|
|
801 |
address = info.iCodeBase;
|
|
802 |
if(size <= info.iCodeSize)
|
|
803 |
{
|
|
804 |
test(KErrNone == iServSession.ReadMemory(iThreadID, address, size, dataBlock, EAccess32, EEndLE8));
|
|
805 |
test(KErrBadDescriptor == iServSession.WriteMemory(iThreadID, address, size, dataBlock, EAccess32, EEndLE8));
|
|
806 |
}
|
|
807 |
|
|
808 |
// Some performance tests now
|
|
809 |
TUint32 bytesRead = 0;
|
|
810 |
|
|
811 |
// Allocate a data buffer
|
|
812 |
TUint32* p = (TUint32*)User::Alloc(size);
|
|
813 |
test(p != 0);
|
|
814 |
|
|
815 |
TInt nanokernel_tick_period;
|
|
816 |
HAL::Get(HAL::ENanoTickPeriod, nanokernel_tick_period);
|
|
817 |
test (nanokernel_tick_period != 0);
|
|
818 |
|
|
819 |
static const TInt KOneMillion = 1000000;
|
|
820 |
|
|
821 |
TInt nkTicksPerSecond = KOneMillion/nanokernel_tick_period;
|
|
822 |
|
|
823 |
TUint32 stopTickCount = User::NTickCount() + nkTicksPerSecond;
|
|
824 |
|
|
825 |
while (User::NTickCount() < stopTickCount)
|
|
826 |
{
|
|
827 |
err = iServSession.ReadMemory(iThreadID, (TUint32)p, size, dataBlock, EAccess32, EEndLE8);
|
|
828 |
test(err==KErrNone);
|
|
829 |
|
|
830 |
// Increase the count of bytes read
|
|
831 |
bytesRead += size;
|
|
832 |
}
|
|
833 |
|
|
834 |
test(bytesRead != 0);
|
|
835 |
iMemoryReadKbytesPerSecond = bytesRead/1024;
|
|
836 |
|
|
837 |
// write memory test
|
|
838 |
TUint32 bytesWritten = 0;
|
|
839 |
|
|
840 |
stopTickCount = User::NTickCount() + nkTicksPerSecond;
|
|
841 |
|
|
842 |
while (User::NTickCount() < stopTickCount)
|
|
843 |
{
|
|
844 |
err = iServSession.WriteMemory(iThreadID, (TUint32)p, size, dataBlock, EAccess32, EEndLE8);
|
|
845 |
test(err==KErrNone);
|
|
846 |
|
|
847 |
// Increase the count of bytes read
|
|
848 |
bytesWritten += size;
|
|
849 |
}
|
|
850 |
|
|
851 |
test (bytesWritten != 0);
|
|
852 |
iMemoryWriteKbytesPerSecond = bytesWritten/1024;
|
|
853 |
|
|
854 |
User::Free(p);
|
|
855 |
|
|
856 |
//resume the thread
|
|
857 |
test(KErrNone == iServSession.ResumeThread(iThreadID));
|
|
858 |
|
|
859 |
debugThread.Close();
|
|
860 |
dataBlock.Close();
|
|
861 |
|
|
862 |
test(KErrNone == iServSession.DetachExecutable(iFileName));
|
|
863 |
}
|
|
864 |
|
|
865 |
//---------------------------------------------
|
|
866 |
//! @SYMTestCaseID KBase-T-RMDEBUG2-0433
|
|
867 |
//! @SYMTestType
|
|
868 |
//! @SYMPREQ PREQ1426
|
|
869 |
//! @SYMTestCaseDesc Test suspending and resuming threads
|
|
870 |
//! @SYMTestActions Multiple calls to suspend and resume threads with and without attaching to the thread
|
|
871 |
//! @SYMTestExpectedResults All tests should pass and the target process should be left unaffected
|
|
872 |
//! @SYMTestPriority High
|
|
873 |
//! @SYMTestStatus Implemented
|
|
874 |
//---------------------------------------------
|
|
875 |
void CRunModeAgent::TestSuspendResume()
|
|
876 |
{
|
|
877 |
TInt err;
|
|
878 |
|
|
879 |
test.Next(_L("TestSuspendResume - Suspend\n"));
|
|
880 |
|
|
881 |
test(KErrNone == iServSession.AttachExecutable(iFileName, EFalse));
|
|
882 |
// Suspend the thread
|
|
883 |
err = iServSession.SuspendThread(iThreadID);
|
|
884 |
test(err==KErrNone);
|
|
885 |
TInt localtestdata;
|
|
886 |
localtestdata = TestData;
|
|
887 |
|
|
888 |
// Wait 3 seconds (suspends this thread) and hopefully resumes the
|
|
889 |
// thread we are controlling via the iServSession.SuspendThread request
|
|
890 |
User::After(3000000);
|
|
891 |
|
|
892 |
// Now check data hasnt changed
|
|
893 |
test(localtestdata==TestData);
|
|
894 |
|
|
895 |
// Resume the thread
|
|
896 |
test.Next(_L("TestSuspendResume - Resume\n"));
|
|
897 |
err = iServSession.ResumeThread(iThreadID);
|
|
898 |
test(err==KErrNone);
|
|
899 |
|
|
900 |
test(KErrNone == iServSession.DetachExecutable(iFileName));
|
|
901 |
|
|
902 |
// Wait 3 seconds (suspends this thread) and hopefully resumes the
|
|
903 |
// thread we are controlling via the iServSession.SuspendThread request
|
|
904 |
User::After(3000000);
|
|
905 |
|
|
906 |
// Now check that the thread being controlled has resumed and is
|
|
907 |
// updating the variable
|
|
908 |
test(localtestdata!=TestData);
|
|
909 |
|
|
910 |
// check that agent can resume thread which it previously detached from
|
|
911 |
test(KErrNone == iServSession.AttachExecutable(iFileName, EFalse));
|
|
912 |
test(KErrNone == iServSession.SuspendThread(iThreadID));
|
|
913 |
test(KErrNone == iServSession.DetachExecutable(iFileName));
|
|
914 |
test(KErrNone == iServSession.AttachExecutable(iFileName, EFalse));
|
|
915 |
test(KErrNone == iServSession.ResumeThread(iThreadID));
|
|
916 |
test(KErrNone == iServSession.DetachExecutable(iFileName));
|
|
917 |
|
|
918 |
// check that agent cannot suspend thread which it previously suspended and then detached from
|
|
919 |
test(KErrNone == iServSession.AttachExecutable(iFileName, EFalse));
|
|
920 |
test(KErrNone == iServSession.SuspendThread(iThreadID));
|
|
921 |
test(KErrNone == iServSession.DetachExecutable(iFileName));
|
|
922 |
test(KErrNone == iServSession.AttachExecutable(iFileName, EFalse));
|
|
923 |
test(KErrAlreadyExists == iServSession.SuspendThread(iThreadID));
|
|
924 |
test(KErrNone == iServSession.ResumeThread(iThreadID));
|
|
925 |
test(KErrNone == iServSession.DetachExecutable(iFileName));
|
|
926 |
}
|
|
927 |
|
|
928 |
//---------------------------------------------
|
|
929 |
//! @SYMTestCaseID KBase-T-RMDEBUG2-0434
|
|
930 |
//! @SYMTestType
|
|
931 |
//! @SYMPREQ PREQ1426
|
|
932 |
//! @SYMTestCaseDesc Test getting the debug functionality from the driver
|
|
933 |
//! @SYMTestActions Get the size and contents of the debug functionality block
|
|
934 |
//! @SYMTestExpectedResults All tests should pass and the expected data should appear in the functionality block
|
|
935 |
//! @SYMTestPriority High
|
|
936 |
//! @SYMTestStatus Implemented
|
|
937 |
//---------------------------------------------
|
|
938 |
void CRunModeAgent::TestDebugFunctionality()
|
|
939 |
{
|
|
940 |
|
|
941 |
TInt err;
|
|
942 |
|
|
943 |
test.Next(_L("TestDebugFunctionality - GetDebugFunctionalityBufSize\n"));
|
|
944 |
|
|
945 |
TUint32 bufsize = 0; // Safe default size
|
|
946 |
|
|
947 |
// Get functionality block size
|
|
948 |
err = iServSession.GetDebugFunctionalityBufSize(&bufsize);
|
|
949 |
test(err==KErrNone);
|
|
950 |
test.Next(_L("TestDebugFunctionality - GetDebugFunctionality\n"));
|
|
951 |
|
|
952 |
// Ensure we have a finite buffer size
|
|
953 |
test(bufsize!=0);
|
|
954 |
|
|
955 |
// Allocate space for the functionality data
|
|
956 |
HBufC8* dftext = HBufC8::NewLC(bufsize);
|
|
957 |
|
|
958 |
// create an empty TPtr8 refering to dftext
|
|
959 |
TPtr8 dftextPtr(dftext->Des());
|
|
960 |
|
|
961 |
// Get the functionality block
|
|
962 |
err = iServSession.GetDebugFunctionality(dftextPtr);
|
|
963 |
test(err==KErrNone);
|
|
964 |
|
|
965 |
// Check that the first entry is correct
|
|
966 |
TTagHeader RefHdr =
|
|
967 |
{
|
|
968 |
ETagHeaderIdCore,ECoreLast,
|
|
969 |
};
|
|
970 |
|
|
971 |
// First header passed from rm_debug.ldd
|
|
972 |
TTagHeader* TestHdr = (TTagHeader*)dftextPtr.Ptr();
|
|
973 |
|
|
974 |
// Check
|
|
975 |
test(RefHdr.iTagHdrId==TestHdr->iTagHdrId);
|
|
976 |
// this test might fail if the agent is used with a Debug Security Server different from
|
|
977 |
// the one it was compiled against. So removing it for now.
|
|
978 |
//test(RefHdr.iNumTags==TestHdr->iNumTags);
|
|
979 |
|
|
980 |
// read a value from the data to check it has come through as expected
|
|
981 |
TTagHeader* header = GetTagHdr(dftext->Des(), ETagHeaderIdApiConstants);
|
|
982 |
test(header != NULL);
|
|
983 |
TTag* tag = GetTag(header, EApiConstantsTEventInfoSize);
|
|
984 |
test(tag != NULL);
|
|
985 |
// this test might fail if the agent is used with a Debug Security Server different from
|
|
986 |
// the one it was compiled against. So removing it for now.
|
|
987 |
//test(sizeof(TEventInfo) == tag->iValue);
|
|
988 |
|
|
989 |
// Remove our temporary buffer
|
|
990 |
CleanupStack::PopAndDestroy(dftext);
|
|
991 |
}
|
|
992 |
|
|
993 |
//---------------------------------------------
|
|
994 |
//! @SYMTestCaseID KBase-T-RMDEBUG2-0435
|
|
995 |
//! @SYMTestType
|
|
996 |
//! @SYMPREQ PREQ1426
|
|
997 |
//! @SYMTestCaseDesc Test setting and clearing consecutive breakpoints
|
|
998 |
//! @SYMTestActions Set and clear consecutive breakpoints of all combinations of breakpoint types
|
|
999 |
//! @SYMTestExpectedResults All breakpoints should be set and cleared without error
|
|
1000 |
//! @SYMTestPriority High
|
|
1001 |
//! @SYMTestStatus Implemented
|
|
1002 |
//---------------------------------------------
|
|
1003 |
void CRunModeAgent::TestConsecutiveBreakPoints()
|
|
1004 |
{
|
|
1005 |
test.Next(_L("TestConsecutiveBreakPoints\n"));
|
|
1006 |
|
|
1007 |
test(KErrNone == iServSession.SuspendThread(iThreadID));
|
|
1008 |
|
|
1009 |
// just a temporary structure for storing info about a breakpoint
|
|
1010 |
struct TBreakPoint
|
|
1011 |
{
|
|
1012 |
public:
|
|
1013 |
TBreakPoint()
|
|
1014 |
:iId(0),
|
|
1015 |
iMode((TArchitectureMode)0),
|
|
1016 |
iAddress(0)
|
|
1017 |
{}
|
|
1018 |
TBreakId iId;
|
|
1019 |
TArchitectureMode iMode;
|
|
1020 |
TUint32 iAddress;
|
|
1021 |
inline TInt Size() { return (EArmMode == iMode) ? 4 : 2; }
|
|
1022 |
};
|
|
1023 |
|
|
1024 |
//an address in the target debug thread
|
|
1025 |
TUint32 address = (TUint32)(&TestFunction);
|
|
1026 |
|
|
1027 |
// there are six orders in which three breakpoints can be set, these are looped
|
|
1028 |
// through below to check setting and clearing consecutive breakpoints works
|
|
1029 |
TUint8 order[6][3] =
|
|
1030 |
{
|
|
1031 |
{0,1,2},
|
|
1032 |
{0,2,1},
|
|
1033 |
{1,0,2},
|
|
1034 |
{1,2,0},
|
|
1035 |
{2,0,1},
|
|
1036 |
{2,1,0}
|
|
1037 |
};
|
|
1038 |
|
|
1039 |
// The following code checks that setting and clearing consecutive breakpoints works correctly:
|
|
1040 |
// It checks that setting all combinations of three arm and thumb breakpoints succeeds, and check that the
|
|
1041 |
// breakpoints can be set in any order, and then cleared in any order
|
|
1042 |
|
|
1043 |
// the 3 least significant bits of i control whether each of the three breakpoints should be arm or thumb
|
|
1044 |
for(TInt i=0; i<8; i++)
|
|
1045 |
{
|
|
1046 |
// controls the order in which the breakpoints should be set
|
|
1047 |
for(TInt j=0; j<6; j++)
|
|
1048 |
{
|
|
1049 |
// create the three breakpoints and set their modes
|
|
1050 |
TBreakPoint bp[3];
|
|
1051 |
bp[0].iMode = (i&1) ? EArmMode : EThumbMode;
|
|
1052 |
bp[1].iMode = (i&2) ? EArmMode : EThumbMode;
|
|
1053 |
bp[2].iMode = (i&4) ? EArmMode : EThumbMode;
|
|
1054 |
|
|
1055 |
// set the address of each of the breakpoints
|
|
1056 |
bp[0].iAddress = address;
|
|
1057 |
if(EArmMode == bp[0].iMode)
|
|
1058 |
{ // if an arm breakpoint then must be on a four byte boundary
|
|
1059 |
bp[0].iAddress = Align4(bp[0].iAddress);
|
|
1060 |
}
|
|
1061 |
bp[1].iAddress = bp[0].iAddress + bp[0].Size();
|
|
1062 |
if(EArmMode == bp[1].iMode)
|
|
1063 |
{ // if an arm breakpoint then must be on a four byte boundary
|
|
1064 |
bp[1].iAddress = Align4(bp[1].iAddress);
|
|
1065 |
}
|
|
1066 |
bp[2].iAddress = bp[1].iAddress + bp[1].Size();
|
|
1067 |
if(EArmMode == bp[2].iMode)
|
|
1068 |
{ // if an arm breakpoint then must be on a four byte boundary
|
|
1069 |
bp[2].iAddress = Align4(bp[2].iAddress);
|
|
1070 |
}
|
|
1071 |
for(TInt k=0; k<6; k++)
|
|
1072 |
{
|
|
1073 |
// set the three breakpoints in the order defined by j and then clear them in the order defined by k
|
|
1074 |
test(KErrNone==iServSession.SetBreak(bp[order[j][0]].iId, iThreadID, bp[order[j][0]].iAddress, bp[order[j][0]].iMode));
|
|
1075 |
test(KErrNone==iServSession.SetBreak(bp[order[j][1]].iId, iThreadID, bp[order[j][1]].iAddress, bp[order[j][1]].iMode));
|
|
1076 |
test(KErrNone==iServSession.SetBreak(bp[order[j][2]].iId, iThreadID, bp[order[j][2]].iAddress, bp[order[j][2]].iMode));
|
|
1077 |
test(KErrNone==iServSession.ClearBreak(bp[order[k][0]].iId));
|
|
1078 |
test(KErrNone==iServSession.ClearBreak(bp[order[k][1]].iId));
|
|
1079 |
test(KErrNone==iServSession.ClearBreak(bp[order[k][2]].iId));
|
|
1080 |
}
|
|
1081 |
}
|
|
1082 |
}
|
|
1083 |
|
|
1084 |
// resume the thread
|
|
1085 |
test(KErrNone == iServSession.ResumeThread(iThreadID));
|
|
1086 |
}
|
|
1087 |
|
|
1088 |
//---------------------------------------------
|
|
1089 |
//! @SYMTestCaseID KBase-T-RMDEBUG2-0436
|
|
1090 |
//! @SYMTestType
|
|
1091 |
//! @SYMPREQ PREQ1426
|
|
1092 |
//! @SYMTestCaseDesc Test breakpoint functionality
|
|
1093 |
//! @SYMTestActions Multiple calls to set and clear breakpoints. Checking bad input produces appropriate errors.
|
|
1094 |
//! @SYMTestExpectedResults All tests should pass and the target debug thread should be left unaffected
|
|
1095 |
//! @SYMTestPriority High
|
|
1096 |
//! @SYMTestStatus Implemented
|
|
1097 |
//---------------------------------------------
|
|
1098 |
void CRunModeAgent::TestBreakPoints()
|
|
1099 |
{
|
|
1100 |
TInt err;
|
|
1101 |
|
|
1102 |
test.Next(_L("TestBreakPoints - Set\n"));
|
|
1103 |
|
|
1104 |
test(KErrNone == iServSession.AttachExecutable(iFileName, EFalse));
|
|
1105 |
|
|
1106 |
TestConsecutiveBreakPoints();
|
|
1107 |
|
|
1108 |
//an address in the target debug thread
|
|
1109 |
TUint32 address = (TUint32)(&TestFunction);
|
|
1110 |
|
|
1111 |
/*
|
|
1112 |
* Ensure that breakpoint operations don't
|
|
1113 |
* affect memory read/write by checking that reads/writes
|
|
1114 |
* in locations containing breakpoints don't change behaviour
|
|
1115 |
* because of the breakpoints.
|
|
1116 |
*/
|
|
1117 |
|
|
1118 |
TUint32 size = SYMBIAN_RMDBG_MEMORYSIZE;
|
|
1119 |
|
|
1120 |
RBuf8 originalDataBlock;
|
|
1121 |
err = originalDataBlock.Create(size);
|
|
1122 |
test(err==KErrNone);
|
|
1123 |
|
|
1124 |
//suspend the thread
|
|
1125 |
test(KErrNone == iServSession.SuspendThread(iThreadID));
|
|
1126 |
|
|
1127 |
err = iServSession.ReadMemory(iThreadID, address, size, originalDataBlock, EAccess32, EEndLE8);
|
|
1128 |
test(err==KErrNone);
|
|
1129 |
|
|
1130 |
// Test data block for comparison
|
|
1131 |
RBuf8 testDataBlock;
|
|
1132 |
err = testDataBlock.Create(size);
|
|
1133 |
test(err==KErrNone);
|
|
1134 |
|
|
1135 |
/*
|
|
1136 |
* set an arm breakpoint
|
|
1137 |
*/
|
|
1138 |
TBreakId armBreakId = 0;
|
|
1139 |
err = iServSession.SetBreak(armBreakId, iThreadID, address, EArmMode);
|
|
1140 |
test(err == KErrNone);
|
|
1141 |
|
|
1142 |
// Ensure that memory read is not corrupted
|
|
1143 |
err = iServSession.ReadMemory(iThreadID, address, size, testDataBlock, EAccess32, EEndLE8);
|
|
1144 |
test(err==KErrNone);
|
|
1145 |
|
|
1146 |
test (testDataBlock == originalDataBlock);
|
|
1147 |
|
|
1148 |
/*
|
|
1149 |
* set a thumb breakpoint
|
|
1150 |
*/
|
|
1151 |
TBreakId thumbBreakId = 0;
|
|
1152 |
err = iServSession.SetBreak(thumbBreakId, iThreadID, address+4, EThumbMode);
|
|
1153 |
test(err == KErrNone);
|
|
1154 |
|
|
1155 |
/*
|
|
1156 |
* set a thumb2EE breakpoint
|
|
1157 |
*/
|
|
1158 |
TBreakId thumb2EEBreakId = 0;
|
|
1159 |
err = iServSession.SetBreak(thumb2EEBreakId, iThreadID, address+8, EThumb2EEMode);
|
|
1160 |
test(err == KErrNotSupported);
|
|
1161 |
|
|
1162 |
/*
|
|
1163 |
* overlapping breakpoint (same address/threadId/mode)
|
|
1164 |
*/
|
|
1165 |
TBreakId overlapBreakId = 0;
|
|
1166 |
err = iServSession.SetBreak(overlapBreakId, iThreadID, address, EArmMode);
|
|
1167 |
test(err == KErrAlreadyExists);
|
|
1168 |
|
|
1169 |
/*
|
|
1170 |
* overlapping breakpoint (different address/same threadId/different mode)
|
|
1171 |
*
|
|
1172 |
* address - EArmBreakpoint
|
|
1173 |
* address+2 - EThumbBreakpoint
|
|
1174 |
*/
|
|
1175 |
TBreakId overlap2BreakId = 0;
|
|
1176 |
err = iServSession.SetBreak(overlap2BreakId, iThreadID, address+2, EThumbMode);
|
|
1177 |
test(err == KErrAlreadyExists);
|
|
1178 |
|
|
1179 |
/*
|
|
1180 |
* Un-aligned address (arm)
|
|
1181 |
*/
|
|
1182 |
TBreakId armUnalignedBreakId = 0;
|
|
1183 |
err = iServSession.SetBreak(armUnalignedBreakId, iThreadID, address+6, EArmMode);
|
|
1184 |
test(err == KErrArgument);
|
|
1185 |
|
|
1186 |
/*
|
|
1187 |
* Un-aligned address (thumb)
|
|
1188 |
*/
|
|
1189 |
TBreakId thumbUnalignedBreakId = 0;
|
|
1190 |
err = iServSession.SetBreak(thumbUnalignedBreakId, iThreadID, address+7, EThumbMode);
|
|
1191 |
test(err == KErrArgument);
|
|
1192 |
|
|
1193 |
/*
|
|
1194 |
* Invalid address (arm)
|
|
1195 |
*/
|
|
1196 |
TBreakId armBadAddressBreakId = 0;
|
|
1197 |
err = iServSession.SetBreak(armBadAddressBreakId, iThreadID, 0 /* address */, EThumbMode);
|
|
1198 |
test(err == KErrBadDescriptor);
|
|
1199 |
|
|
1200 |
/*
|
|
1201 |
* Different thread, same address. Should fail for the same process, but succeed
|
|
1202 |
* for a different process.
|
|
1203 |
*/
|
|
1204 |
|
|
1205 |
/*
|
|
1206 |
* Invalid thread
|
|
1207 |
*/
|
|
1208 |
TBreakId invalidThreadBreakId = 0;
|
|
1209 |
err = iServSession.SetBreak(invalidThreadBreakId, 0xbabababa, address, EThumbMode);
|
|
1210 |
test(err == KErrPermissionDenied);
|
|
1211 |
|
|
1212 |
// Clear the ARM breakpoint
|
|
1213 |
err = iServSession.ClearBreak(armBreakId);
|
|
1214 |
test(err == KErrNone);
|
|
1215 |
|
|
1216 |
// Clear the Thumb breakpoint
|
|
1217 |
err = iServSession.ClearBreak(thumbBreakId);
|
|
1218 |
test(err == KErrNone);
|
|
1219 |
|
|
1220 |
// to do : two threads at the same address
|
|
1221 |
// to do : two processes at the same address
|
|
1222 |
|
|
1223 |
// Ensure that memory read is not corrupted after clearing the breakpoints
|
|
1224 |
err = iServSession.ReadMemory(iThreadID, address, size, testDataBlock, EAccess32, EEndLE8);
|
|
1225 |
test(err==KErrNone);
|
|
1226 |
|
|
1227 |
test (testDataBlock == originalDataBlock);
|
|
1228 |
|
|
1229 |
/*
|
|
1230 |
* How fast can we set breakpoints?
|
|
1231 |
*
|
|
1232 |
* Measure the time by setting/clearing breakpoints for 1 second.
|
|
1233 |
*/
|
|
1234 |
TInt nanokernel_tick_period;
|
|
1235 |
HAL::Get(HAL::ENanoTickPeriod, nanokernel_tick_period);
|
|
1236 |
test (nanokernel_tick_period != 0);
|
|
1237 |
|
|
1238 |
TInt nkTicksPerSecond = HelpTicksPerSecond();
|
|
1239 |
|
|
1240 |
TInt breaksPerSecond = 0;
|
|
1241 |
|
|
1242 |
TUint32 stopTickCount = User::NTickCount() + nkTicksPerSecond;
|
|
1243 |
|
|
1244 |
while (User::NTickCount() < stopTickCount)
|
|
1245 |
{
|
|
1246 |
// set the breakpoint
|
|
1247 |
TBreakId armBreakId = 0;
|
|
1248 |
err = iServSession.SetBreak(armBreakId, iThreadID, address, EArmMode);
|
|
1249 |
test(err == KErrNone);
|
|
1250 |
|
|
1251 |
// Clear the breakpoint
|
|
1252 |
err = iServSession.ClearBreak(armBreakId);
|
|
1253 |
test(err == KErrNone);
|
|
1254 |
|
|
1255 |
// Update the count of breakpoints
|
|
1256 |
breaksPerSecond++;
|
|
1257 |
|
|
1258 |
// Gone wrong if we wrap to negative breakpoints (cannot set 2billion/second!)
|
|
1259 |
test(breaksPerSecond >0);
|
|
1260 |
}
|
|
1261 |
|
|
1262 |
// Store the results for later
|
|
1263 |
iBreakpointsPerSecond = breaksPerSecond;
|
|
1264 |
|
|
1265 |
/*
|
|
1266 |
* How many breakpoints can we set?
|
|
1267 |
*/
|
|
1268 |
|
|
1269 |
TBool done = EFalse;
|
|
1270 |
|
|
1271 |
// We assume all the breakpoints id's are issued in ascending order
|
|
1272 |
TInt maxBreakPoints = 0;
|
|
1273 |
|
|
1274 |
// Temporary buffer
|
|
1275 |
RArray<TBreakId> breakIdList;
|
|
1276 |
|
|
1277 |
TUint32 testAddress = address;
|
|
1278 |
|
|
1279 |
while(!done)
|
|
1280 |
{
|
|
1281 |
TBreakId breakId = 0;
|
|
1282 |
|
|
1283 |
// set the breakpoint
|
|
1284 |
testAddress += 4; // ensure the addresses don't overlap
|
|
1285 |
|
|
1286 |
err = iServSession.SetBreak(breakId, iThreadID, testAddress, EArmMode);
|
|
1287 |
test (err == KErrNone || err == KErrOverflow);
|
|
1288 |
if (err != KErrNone)
|
|
1289 |
{
|
|
1290 |
// we've reached the limit of the number of breaks we can set
|
|
1291 |
done = ETrue;
|
|
1292 |
break;
|
|
1293 |
}
|
|
1294 |
|
|
1295 |
// store the id of this breakpoint
|
|
1296 |
breakIdList.Append(breakId);
|
|
1297 |
|
|
1298 |
// Increase the count of breakpoints
|
|
1299 |
maxBreakPoints++;
|
|
1300 |
test(maxBreakPoints > 0);
|
|
1301 |
}
|
|
1302 |
|
|
1303 |
// How many breakpoints can we set?
|
|
1304 |
iMaxBreakpoints = maxBreakPoints;
|
|
1305 |
|
|
1306 |
// now clear all those breakpoints again
|
|
1307 |
while(breakIdList.Count() != 0)
|
|
1308 |
{
|
|
1309 |
// Place it into a TBreakId
|
|
1310 |
TBreakId id = breakIdList[0];
|
|
1311 |
|
|
1312 |
err = iServSession.ClearBreak(id);
|
|
1313 |
test(err == KErrNone);
|
|
1314 |
|
|
1315 |
// next id
|
|
1316 |
breakIdList.Remove(0);
|
|
1317 |
}
|
|
1318 |
|
|
1319 |
breakIdList.Close();
|
|
1320 |
|
|
1321 |
// close our temporary buffers
|
|
1322 |
originalDataBlock.Close();
|
|
1323 |
testDataBlock.Close();
|
|
1324 |
|
|
1325 |
err = iServSession.ResumeThread(iThreadID);
|
|
1326 |
test (err == KErrNone);
|
|
1327 |
|
|
1328 |
test(KErrNone == iServSession.DetachExecutable(iFileName));
|
|
1329 |
}
|
|
1330 |
|
|
1331 |
//---------------------------------------------
|
|
1332 |
//! @SYMTestCaseID KBase-T-RMDEBUG2-0437
|
|
1333 |
//! @SYMTestType
|
|
1334 |
//! @SYMPREQ PREQ1426
|
|
1335 |
//! @SYMTestCaseDesc Test modifying breakpoints
|
|
1336 |
//! @SYMTestActions Several calls to modify breakpoints
|
|
1337 |
//! @SYMTestExpectedResults Valid requests should result in the breakpoints being changed, invalid requests should return errors
|
|
1338 |
//! @SYMTestPriority High
|
|
1339 |
//! @SYMTestStatus Implemented
|
|
1340 |
//---------------------------------------------
|
|
1341 |
void CRunModeAgent::TestModifyBreak()
|
|
1342 |
{
|
|
1343 |
test.Next(_L("TestModifyBreak\n"));
|
|
1344 |
|
|
1345 |
DoTestModifyBreak(ETrue);
|
|
1346 |
DoTestModifyBreak(EFalse);
|
|
1347 |
}
|
|
1348 |
|
|
1349 |
void CRunModeAgent::DoTestModifyBreak(TBool aThreadSpecific)
|
|
1350 |
{
|
|
1351 |
test.Printf(_L("DoTestModifyBreak: aThreadSpecific: %d\n"), aThreadSpecific?1:0);
|
|
1352 |
|
|
1353 |
TInt err;
|
|
1354 |
|
|
1355 |
RProcess process;
|
|
1356 |
TProcessId processId = process.Id();
|
|
1357 |
process.Close();
|
|
1358 |
|
|
1359 |
test(KErrNone == iServSession.AttachExecutable(iFileName, EFalse));
|
|
1360 |
|
|
1361 |
//suspend the thread
|
|
1362 |
test(KErrNone == iServSession.SuspendThread(iThreadID));
|
|
1363 |
|
|
1364 |
//an address in the target debug thread
|
|
1365 |
TUint32 address = (TUint32)(&TestFunction);
|
|
1366 |
|
|
1367 |
//set an arm mode break point
|
|
1368 |
TBreakId armBreakId = 0;
|
|
1369 |
err = aThreadSpecific
|
|
1370 |
? iServSession.SetBreak(armBreakId, iThreadID, address, EArmMode)
|
|
1371 |
: iServSession.SetProcessBreak(armBreakId, processId, address, EArmMode);
|
|
1372 |
test(err == KErrNone);
|
|
1373 |
|
|
1374 |
/*
|
|
1375 |
* Invalid thread
|
|
1376 |
*/
|
|
1377 |
err = aThreadSpecific
|
|
1378 |
? iServSession.ModifyBreak(armBreakId, 0xbabababa, address, EArmMode)
|
|
1379 |
: iServSession.ModifyProcessBreak(armBreakId, 0xbabababa, address, EArmMode);
|
|
1380 |
test(err == KErrPermissionDenied);
|
|
1381 |
|
|
1382 |
/*
|
|
1383 |
* Valid address
|
|
1384 |
*/
|
|
1385 |
err = aThreadSpecific
|
|
1386 |
? iServSession.ModifyBreak(armBreakId, iThreadID, address+4, EArmMode)
|
|
1387 |
: iServSession.ModifyProcessBreak(armBreakId, processId, address+4, EArmMode);
|
|
1388 |
test(err == KErrNone);
|
|
1389 |
|
|
1390 |
/*
|
|
1391 |
* Invalid address
|
|
1392 |
*/
|
|
1393 |
err = aThreadSpecific
|
|
1394 |
? iServSession.ModifyBreak(armBreakId, iThreadID, 0, EArmMode)
|
|
1395 |
: iServSession.ModifyProcessBreak(armBreakId, processId, 0, EArmMode);
|
|
1396 |
test(err == KErrBadDescriptor);
|
|
1397 |
|
|
1398 |
/*
|
|
1399 |
* Thumb mode
|
|
1400 |
*/
|
|
1401 |
err = aThreadSpecific
|
|
1402 |
? iServSession.ModifyBreak(armBreakId, iThreadID, address, EThumbMode)
|
|
1403 |
: iServSession.ModifyProcessBreak(armBreakId, processId, address, EThumbMode);
|
|
1404 |
test(err == KErrNone);
|
|
1405 |
|
|
1406 |
/*
|
|
1407 |
* Thumb2EE mode
|
|
1408 |
*/
|
|
1409 |
err = aThreadSpecific
|
|
1410 |
? iServSession.ModifyBreak(armBreakId, iThreadID, address, EThumb2EEMode)
|
|
1411 |
: iServSession.ModifyProcessBreak(armBreakId, processId, address, EThumb2EEMode);
|
|
1412 |
test(err == KErrNotSupported);
|
|
1413 |
|
|
1414 |
/*
|
|
1415 |
* Arm mode
|
|
1416 |
*/
|
|
1417 |
err = aThreadSpecific
|
|
1418 |
? iServSession.ModifyBreak(armBreakId, iThreadID, address, EArmMode)
|
|
1419 |
: iServSession.ModifyProcessBreak(armBreakId, processId, address, EArmMode);
|
|
1420 |
test(err == KErrNone);
|
|
1421 |
|
|
1422 |
// Finally, clear the breakpoint
|
|
1423 |
err = iServSession.ClearBreak(armBreakId);
|
|
1424 |
test(err == KErrNone);
|
|
1425 |
|
|
1426 |
//resume the thread
|
|
1427 |
test(KErrNone == iServSession.ResumeThread(iThreadID));
|
|
1428 |
test(KErrNone == iServSession.DetachExecutable(iFileName));
|
|
1429 |
}
|
|
1430 |
|
|
1431 |
//---------------------------------------------
|
|
1432 |
//! @SYMTestCaseID KBase-T-RMDEBUG2-0438
|
|
1433 |
//! @SYMTestType
|
|
1434 |
//! @SYMPREQ PREQ1426
|
|
1435 |
//! @SYMTestCaseDesc Test extracting information about breakpoints
|
|
1436 |
//! @SYMTestActions Several calls to get information about breakpoints
|
|
1437 |
//! @SYMTestExpectedResults All tests should pass and the target process should be left unaffected
|
|
1438 |
//! @SYMTestPriority High
|
|
1439 |
//! @SYMTestStatus Implemented
|
|
1440 |
//---------------------------------------------
|
|
1441 |
void CRunModeAgent::TestBreakInfo()
|
|
1442 |
{
|
|
1443 |
test.Next(_L("TestBreakInfo\n"));
|
|
1444 |
|
|
1445 |
DoTestBreakInfo(ETrue);
|
|
1446 |
DoTestBreakInfo(EFalse);
|
|
1447 |
}
|
|
1448 |
|
|
1449 |
void CRunModeAgent::DoTestBreakInfo(TBool aThreadSpecific)
|
|
1450 |
{
|
|
1451 |
test.Printf(_L("DoTestModifyBreak: aThreadSpecific: %d\n"), aThreadSpecific?1:0);
|
|
1452 |
|
|
1453 |
TInt err;
|
|
1454 |
|
|
1455 |
RProcess process;
|
|
1456 |
TProcessId processId = process.Id();
|
|
1457 |
process.Close();
|
|
1458 |
|
|
1459 |
//an address in the target debug thread
|
|
1460 |
TUint32 address = (TUint32)(&TestFunction);
|
|
1461 |
|
|
1462 |
test(KErrNone == iServSession.AttachExecutable(iFileName, EFalse));
|
|
1463 |
|
|
1464 |
//suspend thread
|
|
1465 |
test(KErrNone == iServSession.SuspendThread(iThreadID));
|
|
1466 |
|
|
1467 |
//set an arm mode break point
|
|
1468 |
TBreakId armBreakId = 0;
|
|
1469 |
err = aThreadSpecific
|
|
1470 |
? iServSession.SetBreak(armBreakId, iThreadID, address, EArmMode)
|
|
1471 |
: iServSession.SetProcessBreak(armBreakId, processId, address, EArmMode);
|
|
1472 |
test(err == KErrNone);
|
|
1473 |
|
|
1474 |
// Read back the information and check it is correct
|
|
1475 |
TThreadId testThreadId = TThreadId(0);
|
|
1476 |
TProcessId testProcessId = TProcessId(0);
|
|
1477 |
TUint32 testAddress = 0;
|
|
1478 |
TArchitectureMode testMode = EArmMode;
|
|
1479 |
|
|
1480 |
err = aThreadSpecific
|
|
1481 |
? iServSession.BreakInfo(armBreakId,testThreadId,testAddress, testMode)
|
|
1482 |
: iServSession.ProcessBreakInfo(armBreakId, testProcessId, testAddress, testMode);
|
|
1483 |
test (err == KErrNone);
|
|
1484 |
test (aThreadSpecific ? (testThreadId == iThreadID) : (testProcessId == processId));
|
|
1485 |
test (testAddress == address);
|
|
1486 |
test (testMode == EArmMode);
|
|
1487 |
|
|
1488 |
//change the address
|
|
1489 |
TUint32 changeAddress = address + 64;
|
|
1490 |
err = aThreadSpecific
|
|
1491 |
? iServSession.ModifyBreak(armBreakId, iThreadID, changeAddress,EArmMode)
|
|
1492 |
: iServSession.ModifyProcessBreak(armBreakId, processId, changeAddress, EArmMode);
|
|
1493 |
test(err == KErrNone);
|
|
1494 |
|
|
1495 |
// Check the address has changed
|
|
1496 |
err = aThreadSpecific
|
|
1497 |
? iServSession.BreakInfo(armBreakId,testThreadId,testAddress, testMode)
|
|
1498 |
: iServSession.ProcessBreakInfo(armBreakId, testProcessId, testAddress, testMode);
|
|
1499 |
test (err == KErrNone);
|
|
1500 |
test (testAddress == changeAddress);
|
|
1501 |
|
|
1502 |
// change the architecture type
|
|
1503 |
TArchitectureMode checkMode = EThumbMode;
|
|
1504 |
err = aThreadSpecific
|
|
1505 |
? iServSession.ModifyBreak(armBreakId, iThreadID, address,checkMode)
|
|
1506 |
: iServSession.ModifyProcessBreak(armBreakId, processId, address, checkMode);
|
|
1507 |
test (err == KErrNone);
|
|
1508 |
|
|
1509 |
// Check the mode has changed
|
|
1510 |
err = aThreadSpecific
|
|
1511 |
? iServSession.BreakInfo(armBreakId,testThreadId,testAddress,testMode)
|
|
1512 |
: iServSession.ProcessBreakInfo(armBreakId, testProcessId, testAddress, testMode);
|
|
1513 |
test (err == KErrNone);
|
|
1514 |
test (testMode == checkMode);
|
|
1515 |
|
|
1516 |
// clear the breakpoint again
|
|
1517 |
err = iServSession.ClearBreak(armBreakId);
|
|
1518 |
test (err == KErrNone);
|
|
1519 |
|
|
1520 |
//resume thread
|
|
1521 |
test(KErrNone == iServSession.ResumeThread(iThreadID));
|
|
1522 |
test(KErrNone == iServSession.DetachExecutable(iFileName));
|
|
1523 |
}
|
|
1524 |
|
|
1525 |
// Needed for the RunToBreak test
|
|
1526 |
IMPORT_C extern void RMDebug_BranchTst1();
|
|
1527 |
IMPORT_C extern void RMDebug_BranchTst2();
|
|
1528 |
|
|
1529 |
//---------------------------------------------
|
|
1530 |
//! @SYMTestCaseID KBase-T-RMDEBUG2-0439
|
|
1531 |
//! @SYMTestType
|
|
1532 |
//! @SYMPREQ PREQ1426
|
|
1533 |
//! @SYMTestCaseDesc Test hitting various types of breakpoints
|
|
1534 |
//! @SYMTestActions Several calls to register to observe breakpoints and to hit breakpoints of different types
|
|
1535 |
//! @SYMTestExpectedResults All tests should pass and the target process should be left unaffected
|
|
1536 |
//! @SYMTestPriority High
|
|
1537 |
//! @SYMTestStatus Implemented
|
|
1538 |
//---------------------------------------------
|
|
1539 |
void CRunModeAgent::TestRunToBreak()
|
|
1540 |
{
|
|
1541 |
test.Next(_L("TestRunToBreak\n"));
|
|
1542 |
|
|
1543 |
DoTestRunToBreak(ETrue);
|
|
1544 |
DoTestRunToBreak(EFalse);
|
|
1545 |
}
|
|
1546 |
|
|
1547 |
void CRunModeAgent::DoTestRunToBreak(TBool aThreadSpecific)
|
|
1548 |
{
|
|
1549 |
test.Printf(_L("DoTestRunToBreak: aThreadSpecific: %d\n"), aThreadSpecific?1:0);
|
|
1550 |
|
|
1551 |
TInt err = KErrNone;
|
|
1552 |
|
|
1553 |
RProcess process;
|
|
1554 |
TProcessId processId = process.Id();
|
|
1555 |
process.Close();
|
|
1556 |
|
|
1557 |
test(KErrNone == iServSession.AttachExecutable(iFileName, EFalse));
|
|
1558 |
// we should suspend the thread first, then set the breakpoint
|
|
1559 |
err = iServSession.SuspendThread(iThreadID);
|
|
1560 |
test (err == KErrNone);
|
|
1561 |
|
|
1562 |
// Try to set the breakpoint
|
|
1563 |
TBreakId armBreakId;
|
|
1564 |
TUint32 address = (TUint32)(&RMDebug_BranchTst1);
|
|
1565 |
|
|
1566 |
err = aThreadSpecific
|
|
1567 |
? iServSession.SetBreak(armBreakId,iThreadID,address,EArmMode)
|
|
1568 |
: iServSession.SetProcessBreak(armBreakId, processId, address, EArmMode);
|
|
1569 |
test(err == KErrNone);
|
|
1570 |
|
|
1571 |
err = aThreadSpecific
|
|
1572 |
? iServSession.SetEventAction(iFileName,EEventsBreakPoint, EActionContinue)
|
|
1573 |
: iServSession.SetEventAction(iFileName,EEventsProcessBreakPoint, EActionContinue);
|
|
1574 |
test (err == KErrNone);
|
|
1575 |
|
|
1576 |
// Continue the thread
|
|
1577 |
err = iServSession.ResumeThread(iThreadID);
|
|
1578 |
test (err == KErrNone);
|
|
1579 |
|
|
1580 |
// wait for the breakpoint to be hit
|
|
1581 |
TEventInfo info;
|
|
1582 |
static TRequestStatus status;
|
|
1583 |
|
|
1584 |
TPtr8 infoPtr((TUint8*)&info,0,sizeof(TEventInfo));
|
|
1585 |
|
|
1586 |
iServSession.GetEvent(iFileName,status,infoPtr);
|
|
1587 |
|
|
1588 |
// Wait for notification of the breakpoint hit event
|
|
1589 |
User::WaitForRequest(status);
|
|
1590 |
test(status==KErrNone);
|
|
1591 |
|
|
1592 |
// info should now be filled with the details
|
|
1593 |
test(info.iEventType == (aThreadSpecific ? EEventsBreakPoint : EEventsProcessBreakPoint));
|
|
1594 |
test(info.iThreadBreakPointInfo.iRmdArmExcInfo.iR15 == address);
|
|
1595 |
test(info.iProcessIdValid);
|
|
1596 |
test(info.iThreadIdValid);
|
|
1597 |
|
|
1598 |
// Not interested in breakpoint events any more
|
|
1599 |
err = aThreadSpecific
|
|
1600 |
? iServSession.SetEventAction(iFileName,EEventsBreakPoint, EActionIgnore)
|
|
1601 |
: iServSession.SetEventAction(iFileName, EEventsProcessBreakPoint, EActionIgnore);
|
|
1602 |
test (err == KErrNone);
|
|
1603 |
|
|
1604 |
// Clear the breakpoint again
|
|
1605 |
err = iServSession.ClearBreak(armBreakId);
|
|
1606 |
test(err == KErrNone);
|
|
1607 |
|
|
1608 |
// continue the thread again
|
|
1609 |
err = iServSession.ResumeThread(iThreadID);
|
|
1610 |
test (err == KErrNone);
|
|
1611 |
test(KErrNone == iServSession.DetachExecutable(iFileName));
|
|
1612 |
}
|
|
1613 |
|
|
1614 |
//----------------------------------------------------------------------------------------------
|
|
1615 |
//! @SYMTestCaseID KBase-T-RMDEBUG2-0440
|
|
1616 |
//! @SYMTestType
|
|
1617 |
//! @SYMPREQ PREQ1426
|
|
1618 |
//! @SYMTestCaseDesc Test access to target user-side registers.
|
|
1619 |
//! @SYMTestActions Suspends a target thread, and reads/writes target thread register contents
|
|
1620 |
//!
|
|
1621 |
//! @SYMTestExpectedResults KErrNone. Should access target registers without problems.
|
|
1622 |
//! @SYMTestPriority High
|
|
1623 |
//! @SYMTestStatus Implemented
|
|
1624 |
//----------------------------------------------------------------------------------------------
|
|
1625 |
|
|
1626 |
void CRunModeAgent::TestRegisterAccess()
|
|
1627 |
{
|
|
1628 |
TInt err;
|
|
1629 |
|
|
1630 |
test.Next(_L("TestRegisterAccess - Read\n"));
|
|
1631 |
|
|
1632 |
test(KErrNone == iServSession.AttachExecutable(iFileName, EFalse));
|
|
1633 |
|
|
1634 |
//suspend the thread to read registers
|
|
1635 |
err = iServSession.SuspendThread(iThreadID);
|
|
1636 |
test(err==KErrNone);
|
|
1637 |
|
|
1638 |
//we'll try to read/write registers ERegisterR0 - ERegisterCPSR and ERegisterR13_IRQ
|
|
1639 |
//this way should get valid register values back, invalid ones and not supported ones, and it
|
|
1640 |
//means that the register IDs are not completely contiguous
|
|
1641 |
|
|
1642 |
TInt firstRegister = 0;
|
|
1643 |
TInt lastRegister = 17;
|
|
1644 |
TInt numberOfRegisters = (lastRegister - firstRegister) + 1;
|
|
1645 |
|
|
1646 |
RBuf8 ids;
|
|
1647 |
err = ids.Create(numberOfRegisters * sizeof(TRegisterInfo));
|
|
1648 |
test(err == KErrNone);
|
|
1649 |
|
|
1650 |
for(TInt i=0; i<numberOfRegisters - 1; i++)
|
|
1651 |
{
|
|
1652 |
TRegisterInfo reg = (TRegisterInfo)((i + firstRegister)<<8);
|
|
1653 |
ids.Append(reinterpret_cast<const TUint8*>(®), sizeof(TRegisterInfo));
|
|
1654 |
}
|
|
1655 |
|
|
1656 |
TRegisterInfo reg = ERegisterR13Irq;
|
|
1657 |
ids.Append(reinterpret_cast<const TUint8*>(®), sizeof(TRegisterInfo));
|
|
1658 |
|
|
1659 |
//create a buffer to store the register values in
|
|
1660 |
RBuf8 originalValues;
|
|
1661 |
err = originalValues.Create(numberOfRegisters*sizeof(TUint32));
|
|
1662 |
test(err == KErrNone);
|
|
1663 |
|
|
1664 |
//create a buffer to store the register flags in
|
|
1665 |
RBuf8 originalFlags;
|
|
1666 |
err = originalFlags.Create(numberOfRegisters*sizeof(TUint8));
|
|
1667 |
test(err == KErrNone);
|
|
1668 |
|
|
1669 |
//read register values
|
|
1670 |
err = iServSession.ReadRegisters(iThreadID, ids, originalValues, originalFlags);
|
|
1671 |
test(err == KErrNone);
|
|
1672 |
|
|
1673 |
//create a buffer containing data to write into the registers
|
|
1674 |
RBuf8 tempValues;
|
|
1675 |
err = tempValues.Create(numberOfRegisters*sizeof(TUint32));
|
|
1676 |
test(err == KErrNone);
|
|
1677 |
|
|
1678 |
TUint cpsrId = 16;
|
|
1679 |
for(TUint8 i=0; i<numberOfRegisters*sizeof(TUint32); i++)
|
|
1680 |
{
|
|
1681 |
if(i/sizeof(TUint32) == cpsrId)
|
|
1682 |
{
|
|
1683 |
//For the CPSR we wish to write data that makes sense - for USR mode we are
|
|
1684 |
//allowed change all except the mode, ie. we must stay in usr mode. We try that here
|
|
1685 |
//(allowedCPSRValue[4:0] = 10000) thus not changing the mode.
|
|
1686 |
TUint32 allowedCPSRValue = 0x50000010;
|
|
1687 |
tempValues.Append((TUint8*)&allowedCPSRValue, 4);
|
|
1688 |
i += 3;
|
|
1689 |
}
|
|
1690 |
else
|
|
1691 |
{
|
|
1692 |
tempValues.Append(&i, 1);
|
|
1693 |
}
|
|
1694 |
}
|
|
1695 |
|
|
1696 |
test.Next(_L("TestRegisterAccess - Write\n"));
|
|
1697 |
|
|
1698 |
//create a buffer to store the register flags in
|
|
1699 |
RBuf8 tempWriteFlags;
|
|
1700 |
err = tempWriteFlags.Create(numberOfRegisters*sizeof(TUint8));
|
|
1701 |
test(err == KErrNone);
|
|
1702 |
|
|
1703 |
//write the temp data into the registers
|
|
1704 |
err = iServSession.WriteRegisters(iThreadID, ids, tempValues, tempWriteFlags);
|
|
1705 |
test(err == KErrNone);
|
|
1706 |
|
|
1707 |
//create another buffer to store the register flags in
|
|
1708 |
RBuf8 tempReadFlags;
|
|
1709 |
err = tempReadFlags.Create(numberOfRegisters*sizeof(TUint8));
|
|
1710 |
test(err == KErrNone);
|
|
1711 |
|
|
1712 |
RBuf8 tempReadValues;
|
|
1713 |
err = tempReadValues.Create(numberOfRegisters*sizeof(TUint32));
|
|
1714 |
test(err == KErrNone);
|
|
1715 |
|
|
1716 |
//read the temp data out again
|
|
1717 |
err = iServSession.ReadRegisters(iThreadID, ids, tempReadValues, tempReadFlags);
|
|
1718 |
test(err == KErrNone);
|
|
1719 |
|
|
1720 |
//check values are correct
|
|
1721 |
for(TInt i=0; i<numberOfRegisters; i++)
|
|
1722 |
{
|
|
1723 |
TRegisterFlag writeFlag;
|
|
1724 |
err = GetFlag(tempWriteFlags, i, writeFlag);
|
|
1725 |
test(err == KErrNone);
|
|
1726 |
|
|
1727 |
TRegisterFlag readFlag;
|
|
1728 |
err = GetFlag(tempReadFlags, i, readFlag);
|
|
1729 |
test(err == KErrNone);
|
|
1730 |
|
|
1731 |
if((writeFlag == EValid) && (readFlag == EValid))
|
|
1732 |
{
|
|
1733 |
TUint8 offset = i * sizeof(TUint32);
|
|
1734 |
for(TUint j = offset; j< offset + sizeof(TUint32); j++)
|
|
1735 |
{
|
|
1736 |
test(tempValues.Ptr()[j] == tempReadValues.Ptr()[j]);
|
|
1737 |
}
|
|
1738 |
}
|
|
1739 |
}
|
|
1740 |
|
|
1741 |
//write the original data into the registers
|
|
1742 |
err = iServSession.WriteRegisters(iThreadID, ids, originalValues, originalFlags);
|
|
1743 |
test(err == KErrNone);
|
|
1744 |
|
|
1745 |
//read the data out again
|
|
1746 |
err = iServSession.ReadRegisters(iThreadID, ids, tempValues, tempReadFlags);
|
|
1747 |
test(err == KErrNone);
|
|
1748 |
|
|
1749 |
//check values are correct
|
|
1750 |
for(TInt i=0; i<numberOfRegisters; i++)
|
|
1751 |
{
|
|
1752 |
TRegisterFlag writeFlag;
|
|
1753 |
err = GetFlag(originalFlags, i, writeFlag);
|
|
1754 |
test(err == KErrNone);
|
|
1755 |
|
|
1756 |
TRegisterFlag readFlag;
|
|
1757 |
err = GetFlag(tempReadFlags, i, readFlag);
|
|
1758 |
test(err == KErrNone);
|
|
1759 |
|
|
1760 |
if((writeFlag == EValid) && (readFlag == EValid))
|
|
1761 |
{
|
|
1762 |
TUint8 offset = i * sizeof(TUint32);
|
|
1763 |
for(TUint j = offset; j< offset + sizeof(TUint32); j++)
|
|
1764 |
{
|
|
1765 |
test(tempValues.Ptr()[j] == originalValues.Ptr()[j]);
|
|
1766 |
}
|
|
1767 |
}
|
|
1768 |
}
|
|
1769 |
|
|
1770 |
test.Next(_L("TestRegisterAccess - Invalid data\n"));
|
|
1771 |
|
|
1772 |
//create a buffer of max size 1
|
|
1773 |
RBuf8 emptyBuffer;
|
|
1774 |
emptyBuffer.Create(1);
|
|
1775 |
|
|
1776 |
//test register IDs buffer not being a multiple of sizeof(TRegisterInfo)
|
|
1777 |
err = iServSession.ReadRegisters(iThreadID, emptyBuffer, tempValues, tempReadFlags);
|
|
1778 |
test(err == KErrArgument);
|
|
1779 |
|
|
1780 |
//test register values buffer not being a multiple of sizeof(TUint32)
|
|
1781 |
err = iServSession.ReadRegisters(iThreadID, ids, emptyBuffer, tempReadFlags);
|
|
1782 |
test(err == KErrArgument);
|
|
1783 |
|
|
1784 |
//test flags buffer being representing different number of registers from other two
|
|
1785 |
err = iServSession.ReadRegisters(iThreadID, ids, tempValues, emptyBuffer);
|
|
1786 |
test(err == KErrArgument);
|
|
1787 |
|
|
1788 |
//set max length to 0
|
|
1789 |
emptyBuffer.ReAlloc(0);
|
|
1790 |
|
|
1791 |
//test ids buffer being of 0 max length
|
|
1792 |
err = iServSession.ReadRegisters(iThreadID, emptyBuffer, tempValues, tempReadFlags);
|
|
1793 |
test(err == KErrArgument);
|
|
1794 |
|
|
1795 |
//do cleanup
|
|
1796 |
emptyBuffer.Close();
|
|
1797 |
tempValues.Close();
|
|
1798 |
tempWriteFlags.Close();
|
|
1799 |
tempReadFlags.Close();
|
|
1800 |
tempReadValues.Close();
|
|
1801 |
|
|
1802 |
test.Next(_L("TestRegisterAccess - Setting PC value\n"));
|
|
1803 |
|
|
1804 |
//create buffer containing PC register ID
|
|
1805 |
RBuf8 pcId;
|
|
1806 |
err = pcId.Create(sizeof(TRegisterInfo));
|
|
1807 |
test(err == KErrNone);
|
|
1808 |
TRegisterInfo reg1 = (TRegisterInfo)0x00000f00;
|
|
1809 |
pcId.Append(reinterpret_cast<const TUint8*>(®1), sizeof(TRegisterInfo));
|
|
1810 |
|
|
1811 |
//create buffer containing desired PC value
|
|
1812 |
RBuf8 pcValue;
|
|
1813 |
err = pcValue.Create(sizeof(TUint32));
|
|
1814 |
test(err == KErrNone);
|
|
1815 |
TUint32 address = (TUint32)(&TestFunction);
|
|
1816 |
pcValue.Append(reinterpret_cast<const TUint8*>(&address), sizeof(TUint32));
|
|
1817 |
|
|
1818 |
//craete buffer for PC flag value
|
|
1819 |
RBuf8 pcFlag;
|
|
1820 |
err = pcFlag.Create(sizeof(TUint8));
|
|
1821 |
|
|
1822 |
//write the new PC value
|
|
1823 |
err = iServSession.WriteRegisters(iThreadID, pcId, pcValue, pcFlag);
|
|
1824 |
test(err==KErrNone);
|
|
1825 |
|
|
1826 |
//get the flag and check the PC value was written ok
|
|
1827 |
TRegisterFlag flag = ENotSupported;
|
|
1828 |
err = GetFlag(pcFlag, 0, flag);
|
|
1829 |
test(err==KErrNone);
|
|
1830 |
|
|
1831 |
//if the PC value was successfully changed then resume the thread and
|
|
1832 |
//the value of TestData will hopefully be changed to our specified
|
|
1833 |
//value
|
|
1834 |
if(flag == EValid)
|
|
1835 |
{
|
|
1836 |
err = iServSession.ResumeThread(iThreadID);
|
|
1837 |
test(err==KErrNone);
|
|
1838 |
|
|
1839 |
User::After(500000);
|
|
1840 |
|
|
1841 |
err = iServSession.SuspendThread(iThreadID);
|
|
1842 |
test(err==KErrNone);
|
|
1843 |
|
|
1844 |
test(TestData == 0xffeeddcc);
|
|
1845 |
}
|
|
1846 |
|
|
1847 |
//Make sure we cannot change the CPSR
|
|
1848 |
test.Next(_L("Verifying we cannot change the CPSR mode from USR Mode"));
|
|
1849 |
|
|
1850 |
TUint32 disallowedCpsr = 0x50000013;
|
|
1851 |
|
|
1852 |
RBuf8 cpsrRegId;
|
|
1853 |
err = cpsrRegId.Create(sizeof(TUint32));
|
|
1854 |
test(err == KErrNone);
|
|
1855 |
|
|
1856 |
TRegisterInfo cpsr = (TRegisterInfo)((cpsrId + firstRegister)<<8);
|
|
1857 |
cpsrRegId.Append(reinterpret_cast<const TUint8*>(&cpsr), sizeof(TRegisterInfo));
|
|
1858 |
|
|
1859 |
RBuf8 cpsrRegFlags;
|
|
1860 |
err = cpsrRegFlags.Create(sizeof(TUint8));
|
|
1861 |
test(err == KErrNone);
|
|
1862 |
|
|
1863 |
RBuf8 cpsrVal;
|
|
1864 |
err = cpsrVal.Create(sizeof(TUint32));
|
|
1865 |
test(err == KErrNone);
|
|
1866 |
|
|
1867 |
cpsrVal.Append((TUint8*)&disallowedCpsr, 4);
|
|
1868 |
|
|
1869 |
//attempt to write disallowed CPSR in
|
|
1870 |
err = iServSession.WriteRegisters(iThreadID, cpsrRegId, cpsrVal, cpsrRegFlags);
|
|
1871 |
test(err == KErrNone);
|
|
1872 |
|
|
1873 |
RBuf8 cpsrReadVal;
|
|
1874 |
err = cpsrReadVal.Create(sizeof(TUint32));
|
|
1875 |
test(err == KErrNone);
|
|
1876 |
|
|
1877 |
//Read back the CPSR
|
|
1878 |
err = iServSession.ReadRegisters(iThreadID, cpsrRegId, cpsrReadVal, cpsrRegFlags);
|
|
1879 |
test(err == KErrNone);
|
|
1880 |
|
|
1881 |
//Make sure we havent switched modes ie. its not what we wrote
|
|
1882 |
TUint32* readVal = (TUint32*)cpsrReadVal.Ptr();
|
|
1883 |
test(*readVal != disallowedCpsr);
|
|
1884 |
|
|
1885 |
cpsrRegId.Close();
|
|
1886 |
cpsrRegFlags.Close();
|
|
1887 |
cpsrVal.Close();
|
|
1888 |
cpsrReadVal.Close();
|
|
1889 |
|
|
1890 |
//write the original values back into here
|
|
1891 |
err = iServSession.WriteRegisters(iThreadID, ids, originalValues, originalFlags);
|
|
1892 |
test(err == KErrNone);
|
|
1893 |
|
|
1894 |
// Resume the thread
|
|
1895 |
err = iServSession.ResumeThread(iThreadID);
|
|
1896 |
test(err==KErrNone);
|
|
1897 |
|
|
1898 |
test(KErrNone == iServSession.DetachExecutable(iFileName));
|
|
1899 |
|
|
1900 |
//do cleanup
|
|
1901 |
pcId.Close();
|
|
1902 |
pcValue.Close();
|
|
1903 |
pcFlag.Close();
|
|
1904 |
ids.Close();
|
|
1905 |
originalValues.Close();
|
|
1906 |
originalFlags.Close();
|
|
1907 |
}
|
|
1908 |
|
|
1909 |
//----------------------------------------------------------------------------------------------
|
|
1910 |
//! @SYMTestCaseID KBase-T-RMDEBUG2-0441
|
|
1911 |
//! @SYMTestType
|
|
1912 |
//! @SYMPREQ PREQ1426
|
|
1913 |
//! @SYMTestCaseDesc Test registration/de-registration of debug interest in target exe with the Debug Security Server
|
|
1914 |
//! @SYMTestActions As per description
|
|
1915 |
//!
|
|
1916 |
//! @SYMTestExpectedResults KErrNone.
|
|
1917 |
//! @SYMTestPriority High
|
|
1918 |
//! @SYMTestStatus Implemented
|
|
1919 |
//----------------------------------------------------------------------------------------------
|
|
1920 |
|
|
1921 |
void CRunModeAgent::TestAttachExecutable()
|
|
1922 |
{
|
|
1923 |
|
|
1924 |
test.Next(_L("TestAttachExecutable - Attach\n"));
|
|
1925 |
|
|
1926 |
//attach to process passively
|
|
1927 |
test(KErrNone == iServSession.AttachExecutable(iFileName, ETrue));
|
|
1928 |
|
|
1929 |
//make a thread id for a non-existent thread
|
|
1930 |
TThreadId threadId(0x12345678);
|
|
1931 |
|
|
1932 |
//get a handle to the target thread
|
|
1933 |
RThread targetThread;
|
|
1934 |
TInt err = targetThread.Open(threadId);
|
|
1935 |
test(err != KErrNone);
|
|
1936 |
|
|
1937 |
//not registered for this thread's process (as it doesn't exist)
|
|
1938 |
//so should fail security check
|
|
1939 |
err = iServSession.ResumeThread(threadId);
|
|
1940 |
test(err==KErrPermissionDenied);
|
|
1941 |
|
|
1942 |
//try to attach to the same process (and fail)
|
|
1943 |
test(KErrAlreadyExists == iServSession.AttachExecutable(iFileName, EFalse));
|
|
1944 |
|
|
1945 |
test.Next(_L("TestAttachExecutable - Detach\n"));
|
|
1946 |
|
|
1947 |
//detach from process
|
|
1948 |
test(KErrNone == iServSession.DetachExecutable(iFileName));
|
|
1949 |
|
|
1950 |
//attach non-passively
|
|
1951 |
test(KErrNone == iServSession.AttachExecutable(iFileName, EFalse));
|
|
1952 |
|
|
1953 |
//not registered for this thread's process (as it doesn't exist)
|
|
1954 |
//so should fail security check
|
|
1955 |
err = iServSession.ResumeThread(0x12345678);
|
|
1956 |
test(err==KErrPermissionDenied);
|
|
1957 |
test(KErrNone == iServSession.DetachExecutable(iFileName));
|
|
1958 |
}
|
|
1959 |
|
|
1960 |
//----------------------------------------------------------------------------------------------
|
|
1961 |
//! @SYMTestCaseID KBase-T-RMDEBUG2-0442
|
|
1962 |
//! @SYMTestType
|
|
1963 |
//! @SYMPREQ PREQ1426
|
|
1964 |
//! @SYMTestCaseDesc Tests single-stepping target threads.
|
|
1965 |
//! @SYMTestActions Steps target thread assembly level instructions, mainly branch/change PC
|
|
1966 |
//!
|
|
1967 |
//! @SYMTestExpectedResults KErrNone.
|
|
1968 |
//! @SYMTestPriority High
|
|
1969 |
//! @SYMTestStatus Implemented
|
|
1970 |
//----------------------------------------------------------------------------------------------
|
|
1971 |
|
|
1972 |
void CRunModeAgent::TestStep()
|
|
1973 |
{
|
|
1974 |
//Dont run the test for an SMP System
|
|
1975 |
if (UserSvr::HalFunction(EHalGroupKernel, EKernelHalSmpSupported, 0, 0) == KErrNone)
|
|
1976 |
return;
|
|
1977 |
|
|
1978 |
test.Next(_L("TestStep\n"));
|
|
1979 |
|
|
1980 |
DoTestStep(EFalse);
|
|
1981 |
DoTestStep(ETrue);
|
|
1982 |
}
|
|
1983 |
|
|
1984 |
void CRunModeAgent::DoTestStep(TBool aThreadSpecific)
|
|
1985 |
{
|
|
1986 |
test.Printf(_L("DoTestStep: aThreadSpecific: %d\n"), aThreadSpecific?1:0);
|
|
1987 |
|
|
1988 |
TInt err = KErrNone;
|
|
1989 |
|
|
1990 |
RProcess process;
|
|
1991 |
TProcessId processId = process.Id();
|
|
1992 |
process.Close();
|
|
1993 |
|
|
1994 |
test(KErrNone == iServSession.AttachExecutable(iFileName, EFalse));
|
|
1995 |
//set the target thread to execute the stepping functions
|
|
1996 |
test(KErrNone == SwitchTestFunction(EStepFunction));
|
|
1997 |
|
|
1998 |
err = iServSession.SetEventAction(iFileName,EEventsBreakPoint, EActionContinue);
|
|
1999 |
test (err == KErrNone);
|
|
2000 |
|
|
2001 |
if(!aThreadSpecific)
|
|
2002 |
{
|
|
2003 |
err = iServSession.SetEventAction(iFileName, EEventsProcessBreakPoint, EActionContinue);
|
|
2004 |
test (err == KErrNone);
|
|
2005 |
}
|
|
2006 |
|
|
2007 |
TUint32 startAddress;
|
|
2008 |
TUint32 endAddress;
|
|
2009 |
|
|
2010 |
/*
|
|
2011 |
* RMDebug_StepTest_Non_PC_Modifying
|
|
2012 |
*/
|
|
2013 |
test.Next(_L("TestStep - Non-PC modifying\n"));
|
|
2014 |
|
|
2015 |
startAddress = (TUint32)(&RMDebug_StepTest_Non_PC_Modifying);
|
|
2016 |
|
|
2017 |
endAddress = (TUint32)(&RMDebug_StepTest_Non_PC_Modifying_OK);
|
|
2018 |
|
|
2019 |
err = aThreadSpecific
|
|
2020 |
? HelpTestStep(iThreadID,startAddress,endAddress,EArmMode,1)
|
|
2021 |
: HelpTestStep(iThreadID,startAddress,endAddress,EArmMode,1, EFalse, processId);
|
|
2022 |
test(err==KErrNone);
|
|
2023 |
|
|
2024 |
/*
|
|
2025 |
* RMDebug_StepTest_Branch
|
|
2026 |
*/
|
|
2027 |
test.Next(_L("TestStep - Branch\n"));
|
|
2028 |
|
|
2029 |
startAddress = (TUint32)(&RMDebug_StepTest_Branch);
|
|
2030 |
|
|
2031 |
endAddress = (TUint32)(&RMDebug_StepTest_Branch_1);
|
|
2032 |
|
|
2033 |
err = aThreadSpecific
|
|
2034 |
? HelpTestStep(iThreadID,startAddress,endAddress,EArmMode,1)
|
|
2035 |
: HelpTestStep(iThreadID,startAddress,endAddress,EArmMode,1, EFalse, processId);
|
|
2036 |
test(err==KErrNone);
|
|
2037 |
|
|
2038 |
/*
|
|
2039 |
* RMDebug_StepTest_Branch_And_Link
|
|
2040 |
*/
|
|
2041 |
test.Next(_L("TestStep - Branch_And_Link\n"));
|
|
2042 |
|
|
2043 |
startAddress = (TUint32)(&RMDebug_StepTest_Branch_And_Link_1);
|
|
2044 |
|
|
2045 |
endAddress = (TUint32)(&RMDebug_StepTest_Branch_And_Link_2);
|
|
2046 |
|
|
2047 |
err = aThreadSpecific
|
|
2048 |
? HelpTestStep(iThreadID,startAddress,endAddress,EArmMode,1)
|
|
2049 |
: HelpTestStep(iThreadID,startAddress,endAddress,EArmMode,1, EFalse, processId);
|
|
2050 |
test(err==KErrNone);
|
|
2051 |
|
|
2052 |
/*
|
|
2053 |
* RMDebug_StepTest_MOV_PC
|
|
2054 |
*/
|
|
2055 |
test.Next(_L("TestStep - MOV PC,X\n"));
|
|
2056 |
|
|
2057 |
startAddress = (TUint32)(&RMDebug_StepTest_MOV_PC_1);
|
|
2058 |
|
|
2059 |
endAddress = (TUint32)(&RMDebug_StepTest_MOV_PC_2);
|
|
2060 |
|
|
2061 |
err = aThreadSpecific
|
|
2062 |
? HelpTestStep(iThreadID,startAddress,endAddress,EArmMode,1)
|
|
2063 |
: HelpTestStep(iThreadID,startAddress,endAddress,EArmMode,1, EFalse, processId);
|
|
2064 |
test(err==KErrNone);
|
|
2065 |
|
|
2066 |
/*
|
|
2067 |
* RMDebug_StepTest_LDR_PC
|
|
2068 |
*/
|
|
2069 |
test.Next(_L("TestStep - LDR PC\n"));
|
|
2070 |
|
|
2071 |
startAddress = (TUint32)(&RMDebug_StepTest_LDR_PC);
|
|
2072 |
|
|
2073 |
endAddress = (TUint32)(&RMDebug_StepTest_LDR_PC_1);
|
|
2074 |
|
|
2075 |
err = aThreadSpecific
|
|
2076 |
? HelpTestStep(iThreadID,startAddress,endAddress,EArmMode,1)
|
|
2077 |
: HelpTestStep(iThreadID,startAddress,endAddress,EArmMode,1, EFalse, processId);
|
|
2078 |
test(err==KErrNone);
|
|
2079 |
|
|
2080 |
// thumb and interworking tests are not supported on armv4
|
|
2081 |
#ifdef __MARM_ARMV5__
|
|
2082 |
|
|
2083 |
/*
|
|
2084 |
* RMDebug_StepTest_Thumb_Non_PC_Modifying
|
|
2085 |
*/
|
|
2086 |
test.Next(_L("TestStep - Thumb Non PC-Modifying\n"));
|
|
2087 |
|
|
2088 |
startAddress = (TUint32)(&RMDebug_StepTest_Thumb_Non_PC_Modifying_1);
|
|
2089 |
|
|
2090 |
endAddress = (TUint32)(&RMDebug_StepTest_Thumb_Non_PC_Modifying_2);
|
|
2091 |
|
|
2092 |
err = aThreadSpecific
|
|
2093 |
? HelpTestStep(iThreadID,startAddress,endAddress,EThumbMode,1)
|
|
2094 |
: HelpTestStep(iThreadID,startAddress,endAddress,EThumbMode,1, EFalse, processId);
|
|
2095 |
test(err==KErrNone);
|
|
2096 |
|
|
2097 |
/*
|
|
2098 |
* RMDebug_StepTest_Thumb_Branch
|
|
2099 |
*/
|
|
2100 |
test.Next(_L("TestStep - Thumb Branch\n"));
|
|
2101 |
|
|
2102 |
startAddress = (TUint32)(&RMDebug_StepTest_Thumb_Branch_1);
|
|
2103 |
|
|
2104 |
endAddress = (TUint32)(&RMDebug_StepTest_Thumb_Branch_2);
|
|
2105 |
|
|
2106 |
err = aThreadSpecific
|
|
2107 |
? HelpTestStep(iThreadID,startAddress,endAddress,EThumbMode,1)
|
|
2108 |
: HelpTestStep(iThreadID,startAddress,endAddress,EThumbMode,1, EFalse, processId);
|
|
2109 |
test(err==KErrNone);
|
|
2110 |
|
|
2111 |
/*
|
|
2112 |
* RMDebug_StepTest_Thumb_Branch_And_Link
|
|
2113 |
*/
|
|
2114 |
test.Next(_L("TestStep - Thumb Branch_And_Link\n"));
|
|
2115 |
|
|
2116 |
startAddress = (TUint32)(&RMDebug_StepTest_Thumb_Branch_And_Link_2);
|
|
2117 |
|
|
2118 |
endAddress = (TUint32)(&RMDebug_StepTest_Thumb_Branch_And_Link_3);
|
|
2119 |
|
|
2120 |
TInt muid=0;
|
|
2121 |
test(HAL::Get(HAL::EMachineUid, muid)==KErrNone);
|
|
2122 |
|
|
2123 |
// check if running on ARMv7 core
|
|
2124 |
if(muid==HAL::EMachineUid_OmapH6 || muid==HAL::EMachineUid_OmapZoom || muid==HAL::EMachineUid_EmuBoard)
|
|
2125 |
{
|
|
2126 |
// Note: ARMv7 treats BL instructions as single 32-bit instructions
|
|
2127 |
err = aThreadSpecific
|
|
2128 |
? HelpTestStep(iThreadID,startAddress,endAddress,EThumbMode,1)
|
|
2129 |
: HelpTestStep(iThreadID,startAddress,endAddress,EThumbMode,1, EFalse, processId);
|
|
2130 |
}
|
|
2131 |
else
|
|
2132 |
{
|
|
2133 |
// Note: Due to the fact that the stepper treats BL instructions
|
|
2134 |
// as two instructions (as the hardware does), then we must step
|
|
2135 |
// the first half instruction first)
|
|
2136 |
|
|
2137 |
err = aThreadSpecific
|
|
2138 |
? HelpTestStep(iThreadID,startAddress,startAddress+2,EThumbMode,1)
|
|
2139 |
: HelpTestStep(iThreadID,startAddress,startAddress+2,EThumbMode,1, EFalse, processId);
|
|
2140 |
test(err==KErrNone);
|
|
2141 |
|
|
2142 |
// Now we actually do the BL
|
|
2143 |
err = aThreadSpecific
|
|
2144 |
? HelpTestStep(iThreadID,startAddress+2,endAddress,EThumbMode,1)
|
|
2145 |
: HelpTestStep(iThreadID,startAddress+2,endAddress,EThumbMode,1, EFalse, processId);
|
|
2146 |
}
|
|
2147 |
test(err==KErrNone);
|
|
2148 |
|
|
2149 |
/*
|
|
2150 |
* RMDebug_StepTest_Thumb_Back_Branch_And_Link
|
|
2151 |
*/
|
|
2152 |
test.Next(_L("TestStep - Thumb Back_Branch_And_Link\n"));
|
|
2153 |
|
|
2154 |
startAddress = (TUint32)(&RMDebug_StepTest_Thumb_Back_Branch_And_Link_2);
|
|
2155 |
|
|
2156 |
endAddress = (TUint32)(&RMDebug_StepTest_Thumb_Back_Branch_And_Link_3);
|
|
2157 |
|
|
2158 |
// check if running on ARMv7 core
|
|
2159 |
if(muid==HAL::EMachineUid_OmapH6 || muid==HAL::EMachineUid_OmapZoom || muid==HAL::EMachineUid_EmuBoard)
|
|
2160 |
{
|
|
2161 |
// Note: ARMv7 treats BL instructions as single 32-bit instructions
|
|
2162 |
err = aThreadSpecific
|
|
2163 |
? HelpTestStep(iThreadID,startAddress,endAddress,EThumbMode,1)
|
|
2164 |
: HelpTestStep(iThreadID,startAddress,endAddress,EThumbMode,1, EFalse, processId);
|
|
2165 |
}
|
|
2166 |
else
|
|
2167 |
{
|
|
2168 |
// Note: Due to the fact that the stepper treats BL instructions
|
|
2169 |
// as two instructions (as the hardware does), then we must step
|
|
2170 |
// the first half instruction first)
|
|
2171 |
|
|
2172 |
err = aThreadSpecific
|
|
2173 |
? HelpTestStep(iThreadID,startAddress,startAddress+2,EThumbMode,1)
|
|
2174 |
: HelpTestStep(iThreadID,startAddress,startAddress+2,EThumbMode,1, EFalse, processId);
|
|
2175 |
test(err==KErrNone);
|
|
2176 |
|
|
2177 |
// Now we actually do the BL
|
|
2178 |
err = aThreadSpecific
|
|
2179 |
? HelpTestStep(iThreadID,startAddress+2,endAddress,EThumbMode,1)
|
|
2180 |
: HelpTestStep(iThreadID,startAddress+2,endAddress,EThumbMode,1, EFalse, processId);
|
|
2181 |
}
|
|
2182 |
test(err==KErrNone);
|
|
2183 |
|
|
2184 |
/*
|
|
2185 |
* RMDebug_StepTest_Thumb_AddPC
|
|
2186 |
*/
|
|
2187 |
test.Next(_L("TestStep - Thumb ADD PC, PC, R0\n"));
|
|
2188 |
|
|
2189 |
startAddress = (TUint32)(&RMDebug_StepTest_Thumb_AddPC_2);
|
|
2190 |
|
|
2191 |
endAddress = (TUint32)(&RMDebug_StepTest_Thumb_AddPC_3);
|
|
2192 |
|
|
2193 |
err = aThreadSpecific
|
|
2194 |
? HelpTestStep(iThreadID,startAddress,endAddress,EThumbMode,1)
|
|
2195 |
: HelpTestStep(iThreadID,startAddress,endAddress,EThumbMode,1, EFalse, processId);
|
|
2196 |
test(err==KErrNone);
|
|
2197 |
|
|
2198 |
/*
|
|
2199 |
* RMDebug_StepTest_Interwork ARM to Thumb
|
|
2200 |
*/
|
|
2201 |
test.Next(_L("TestStep - Interworking ARM to Thumb - BLX \n"));
|
|
2202 |
|
|
2203 |
startAddress = (TUint32)(&RMDebug_StepTest_Interwork_1);
|
|
2204 |
|
|
2205 |
endAddress = (TUint32)(&RMDebug_StepTest_Interwork_2);
|
|
2206 |
|
|
2207 |
err = aThreadSpecific // nb initial breakpoint in ARM code
|
|
2208 |
? HelpTestStep(iThreadID,startAddress,endAddress,EArmMode,1)
|
|
2209 |
: HelpTestStep(iThreadID,startAddress,endAddress,EArmMode,1, EFalse, processId);
|
|
2210 |
|
|
2211 |
test(err==KErrNone);
|
|
2212 |
|
|
2213 |
/*
|
|
2214 |
* RMDebug_StepTest_Interwork Thumb to ARM
|
|
2215 |
*/
|
|
2216 |
test.Next(_L("TestStep - Interworking Thumb to ARM - BLX\n"));
|
|
2217 |
|
|
2218 |
startAddress = (TUint32)(&RMDebug_StepTest_Interwork_2);
|
|
2219 |
|
|
2220 |
endAddress = (TUint32)(&RMDebug_StepTest_Interwork_3);
|
|
2221 |
|
|
2222 |
// check if running on ARMv7 core
|
|
2223 |
if(muid==HAL::EMachineUid_OmapH6 || muid==HAL::EMachineUid_OmapZoom || muid==HAL::EMachineUid_EmuBoard)
|
|
2224 |
{
|
|
2225 |
// ARMv7 treats BLX instructions as single 32-bit instructions
|
|
2226 |
err = aThreadSpecific
|
|
2227 |
? HelpTestStep(iThreadID,startAddress,endAddress,EThumbMode,1)
|
|
2228 |
: HelpTestStep(iThreadID,startAddress,endAddress,EThumbMode,1, EFalse, processId);
|
|
2229 |
}
|
|
2230 |
else
|
|
2231 |
{
|
|
2232 |
// Stepper treats this as a two-stage instruction (just like the hardware)
|
|
2233 |
err = aThreadSpecific
|
|
2234 |
? HelpTestStep(iThreadID,startAddress,startAddress+2,EThumbMode,1)
|
|
2235 |
: HelpTestStep(iThreadID,startAddress,startAddress+2,EThumbMode,1, EFalse, processId);
|
|
2236 |
test(err == KErrNone);
|
|
2237 |
|
|
2238 |
err = aThreadSpecific
|
|
2239 |
? HelpTestStep(iThreadID,startAddress+2,endAddress,EThumbMode,1)
|
|
2240 |
: HelpTestStep(iThreadID,startAddress+2,endAddress,EThumbMode,1, EFalse, processId);
|
|
2241 |
}
|
|
2242 |
test(err == KErrNone);
|
|
2243 |
|
|
2244 |
#endif // __MARM_ARMV5__
|
|
2245 |
|
|
2246 |
/*
|
|
2247 |
* Test multiple-step of ARM code
|
|
2248 |
*/
|
|
2249 |
test.Next(_L("TestStep - ARM Multiple instruction step\n"));
|
|
2250 |
|
|
2251 |
startAddress = (TUint32)(&RMDebug_StepTest_ARM_Step_Multiple);
|
|
2252 |
|
|
2253 |
endAddress = (TUint32)(&RMDebug_StepTest_ARM_Step_Multiple_1);
|
|
2254 |
|
|
2255 |
err = aThreadSpecific
|
|
2256 |
? HelpTestStep(iThreadID,startAddress,endAddress,EArmMode,5)
|
|
2257 |
: HelpTestStep(iThreadID,startAddress,endAddress,EArmMode,5, EFalse, processId);
|
|
2258 |
test(err == KErrNone);
|
|
2259 |
// stepping performance
|
|
2260 |
test.Next(_L("TestStep - Steps per second\n"));
|
|
2261 |
|
|
2262 |
// run until we reach RMDebug_StepTest_Count_1
|
|
2263 |
TBreakId stepBreakId;
|
|
2264 |
startAddress = (TUint32)(&RMDebug_StepTest_Count_1);
|
|
2265 |
endAddress = (TUint32)(&RMDebug_StepTest_Count_2);
|
|
2266 |
|
|
2267 |
err = aThreadSpecific
|
|
2268 |
? HelpTestStepSetBreak(stepBreakId,iThreadID,startAddress,EArmMode)
|
|
2269 |
: HelpTestStepSetBreak(stepBreakId,iThreadID,startAddress,EArmMode,EFalse,processId);
|
|
2270 |
test (err == KErrNone);
|
|
2271 |
|
|
2272 |
// wait until we hit the breakpoint
|
|
2273 |
TEventInfo info;
|
|
2274 |
err = HelpTestStepWaitForBreak(iFileName,info);
|
|
2275 |
test (err == KErrNone);
|
|
2276 |
|
|
2277 |
// Now clear the breakpoint
|
|
2278 |
err = iServSession.ClearBreak(stepBreakId);
|
|
2279 |
test(err == KErrNone);
|
|
2280 |
|
|
2281 |
if(aThreadSpecific)
|
|
2282 |
{
|
|
2283 |
// now step the code
|
|
2284 |
TInt stepsPerSecond = 0;
|
|
2285 |
|
|
2286 |
TUint32 stopTickCount = User::NTickCount() + HelpTicksPerSecond();
|
|
2287 |
|
|
2288 |
while (User::NTickCount() < stopTickCount)
|
|
2289 |
{
|
|
2290 |
err = iServSession.Step(iThreadID,1);
|
|
2291 |
test (err == KErrNone);
|
|
2292 |
|
|
2293 |
// we need to wait now until the step completes before asking for the next step
|
|
2294 |
{
|
|
2295 |
TEventInfo info;
|
|
2296 |
static TRequestStatus status;
|
|
2297 |
|
|
2298 |
TPtr8 infoPtr((TUint8*)&info,0,sizeof(TEventInfo));
|
|
2299 |
|
|
2300 |
iServSession.GetEvent(iFileName,status,infoPtr);
|
|
2301 |
|
|
2302 |
// Wait for notification of the breakpoint hit event
|
|
2303 |
User::WaitForRequest(status);
|
|
2304 |
test(status==KErrNone);
|
|
2305 |
}
|
|
2306 |
|
|
2307 |
// Update the count of steps
|
|
2308 |
stepsPerSecond += 1;
|
|
2309 |
|
|
2310 |
// Gone wrong if we do too many
|
|
2311 |
test(stepsPerSecond < 10000);
|
|
2312 |
}
|
|
2313 |
|
|
2314 |
iStepsPerSecond = stepsPerSecond;
|
|
2315 |
test(iStepsPerSecond != 0);
|
|
2316 |
}
|
|
2317 |
|
|
2318 |
// finally resume the thread
|
|
2319 |
err = iServSession.ResumeThread(iThreadID);
|
|
2320 |
test (err == KErrNone);
|
|
2321 |
|
|
2322 |
err = iServSession.SetEventAction(iFileName,EEventsBreakPoint, EActionIgnore);
|
|
2323 |
test (err == KErrNone);
|
|
2324 |
|
|
2325 |
if(!aThreadSpecific)
|
|
2326 |
{
|
|
2327 |
err = iServSession.SetEventAction(iFileName, EEventsProcessBreakPoint, EActionIgnore);
|
|
2328 |
test (err == KErrNone);
|
|
2329 |
}
|
|
2330 |
|
|
2331 |
test(KErrNone == iServSession.DetachExecutable(iFileName));
|
|
2332 |
}
|
|
2333 |
|
|
2334 |
//----------------------------------------------------------------------------------------------
|
|
2335 |
//! @SYMTestCaseID KBase-T-RMDEBUG2-0443
|
|
2336 |
//! @SYMTestType
|
|
2337 |
//! @SYMPREQ PREQ1426
|
|
2338 |
//! @SYMTestCaseDesc Tests registration and occurrence of target thread event (in this case panic)
|
|
2339 |
//! @SYMTestActions Registers for a panic in the target thread, causes it, and catches the panic notification.
|
|
2340 |
//!
|
|
2341 |
//! @SYMTestExpectedResults KErrNone.
|
|
2342 |
//! @SYMTestPriority High
|
|
2343 |
//! @SYMTestStatus Implemented
|
|
2344 |
//----------------------------------------------------------------------------------------------
|
|
2345 |
|
|
2346 |
void CRunModeAgent::TestEvents()
|
|
2347 |
{
|
|
2348 |
TInt err = KErrNone;
|
|
2349 |
|
|
2350 |
test.Next(_L("TestEvents\n"));
|
|
2351 |
|
|
2352 |
TInt panicReason = 12345;
|
|
2353 |
|
|
2354 |
test.Printf(_L("Thread t_rmdebug.exe::DebugThread should panic with reason %d.\n"), panicReason);
|
|
2355 |
|
|
2356 |
//attach non-passively
|
|
2357 |
test(KErrNone == iServSession.AttachExecutable(iFileName, EFalse));
|
|
2358 |
|
|
2359 |
RThread threadToPanic;
|
|
2360 |
test(KErrNone == StartDebugThread(threadToPanic, _L("EventsThread")));
|
|
2361 |
TThreadId threadToPanicId = threadToPanic.Id();
|
|
2362 |
TEventInfo info;
|
|
2363 |
|
|
2364 |
// Set things up to wait for a thread kill event
|
|
2365 |
err = iServSession.SetEventAction(iFileName, EEventsKillThread, EActionContinue);
|
|
2366 |
test(err==KErrNone);
|
|
2367 |
|
|
2368 |
// Wait for an event to occur in this process - nothing should have happened yet.
|
|
2369 |
static TRequestStatus status;
|
|
2370 |
|
|
2371 |
TPtr8 infoPtr((TUint8*)&info,0,sizeof(TEventInfo));
|
|
2372 |
|
|
2373 |
iServSession.GetEvent(iFileName,status,infoPtr);
|
|
2374 |
|
|
2375 |
// Test Request cancellation
|
|
2376 |
err = iServSession.CancelGetEvent(iFileName);
|
|
2377 |
test (err==KErrNone);
|
|
2378 |
|
|
2379 |
// Again wait for an event to occur in our process - we will provoke the
|
|
2380 |
// thread kill event by panic'ing the test thread.
|
|
2381 |
iServSession.GetEvent(iFileName,status,infoPtr);
|
|
2382 |
|
|
2383 |
// Panic the debug thread to cause a thread kill event
|
|
2384 |
threadToPanic.Panic(_L("t_rmdebug panic thread test"), panicReason);
|
|
2385 |
|
|
2386 |
// Wait for notification of the Thread Kill event
|
|
2387 |
User::WaitForRequest(status);
|
|
2388 |
test(status==KErrNone);
|
|
2389 |
|
|
2390 |
// Check we are really recieving information about the panic
|
|
2391 |
test(info.iProcessIdValid);
|
|
2392 |
test(info.iThreadIdValid);
|
|
2393 |
test(info.iProcessId==RProcess().Id());
|
|
2394 |
test(info.iThreadId==threadToPanicId);
|
|
2395 |
test(info.iEventType==EEventsKillThread);
|
|
2396 |
test(info.iThreadKillInfo.iExitType==EExitPanic);
|
|
2397 |
|
|
2398 |
// Ignore other panic events
|
|
2399 |
err = iServSession.SetEventAction(iFileName, EEventsKillThread, EActionIgnore);
|
|
2400 |
test(err==KErrNone);
|
|
2401 |
|
|
2402 |
test(KErrNone == iServSession.DetachExecutable(iFileName));
|
|
2403 |
}
|
|
2404 |
|
|
2405 |
//----------------------------------------------------------------------------------------------
|
|
2406 |
//! @SYMTestCaseID KBase-T-RMDEBUG2-0444
|
|
2407 |
//! @SYMTestType
|
|
2408 |
//! @SYMPREQ PREQ1426
|
|
2409 |
//! @SYMTestCaseDesc Tests registration and occurence of target thread events in separate process.
|
|
2410 |
//! @SYMTestActions Registers for a hardware exception and kill thread events, and receives them.
|
|
2411 |
//!
|
|
2412 |
//! @SYMTestExpectedResults KErrNone.
|
|
2413 |
//! @SYMTestPriority High
|
|
2414 |
//! @SYMTestStatus Implemented
|
|
2415 |
//----------------------------------------------------------------------------------------------
|
|
2416 |
void CRunModeAgent::TestEventsForExternalProcess()
|
|
2417 |
{
|
|
2418 |
//Dont run the test for an SMP System
|
|
2419 |
if (UserSvr::HalFunction(EHalGroupKernel, EKernelHalSmpSupported, 0, 0) == KErrNone)
|
|
2420 |
return;
|
|
2421 |
|
|
2422 |
test.Next(_L("TestEventsForExternalProcess\n"));
|
|
2423 |
|
|
2424 |
for(TInt main=0; main<3; main++)
|
|
2425 |
{
|
|
2426 |
for(TInt extra=0; extra<3; extra++)
|
|
2427 |
{
|
|
2428 |
TestEventsWithExtraThreads((TKernelEventAction)main, (TKernelEventAction)extra, 0);
|
|
2429 |
TestEventsWithExtraThreads((TKernelEventAction)main, (TKernelEventAction)extra, 2);
|
|
2430 |
}
|
|
2431 |
}
|
|
2432 |
}
|
|
2433 |
|
|
2434 |
void CRunModeAgent::TestEventsWithExtraThreads(TKernelEventAction aActionMain, TKernelEventAction aActionExtra, TUint32 aExtraThreads)
|
|
2435 |
{
|
|
2436 |
const TInt KNumberOfTypes = 8;
|
|
2437 |
struct TEventStruct
|
|
2438 |
{
|
|
2439 |
public:
|
|
2440 |
TDebugFunctionType iDebugFunctionType;
|
|
2441 |
TEventType iEventType;
|
|
2442 |
};
|
|
2443 |
|
|
2444 |
TEventStruct type[KNumberOfTypes] =
|
|
2445 |
{
|
|
2446 |
{EStackOverflowFunction, EEventsHwExc},
|
|
2447 |
{EUserPanicFunction, EEventsKillThread},
|
|
2448 |
{EPrefetchAbortFunction, EEventsHwExc},
|
|
2449 |
{EDataAbortFunction, EEventsHwExc},
|
|
2450 |
{EUndefInstructionFunction, EEventsHwExc},
|
|
2451 |
{EDataReadErrorFunction, EEventsHwExc},
|
|
2452 |
{EDataWriteErrorFunction, EEventsHwExc},
|
|
2453 |
{EUserExceptionFunction, EEventsSwExc},
|
|
2454 |
};
|
|
2455 |
|
|
2456 |
for(TInt j=0; j<KNumberOfTypes; j++)
|
|
2457 |
{
|
|
2458 |
//RDebug::Printf("**** type: %d, main action: %d, extra action: %d, extraThreads: %d", j, (TUint32)aActionMain, (TUint32)aActionExtra, aExtraThreads);
|
|
2459 |
|
|
2460 |
// do this check as it seems to hard to do these cases with the current set up
|
|
2461 |
if(EEventsKillThread == type[j].iEventType)
|
|
2462 |
{
|
|
2463 |
if(EActionSuspend != aActionMain)
|
|
2464 |
{
|
|
2465 |
if(aActionMain != aActionExtra)
|
|
2466 |
{
|
|
2467 |
return;
|
|
2468 |
}
|
|
2469 |
}
|
|
2470 |
}
|
|
2471 |
// attach to KRMDebugTestApplication
|
|
2472 |
test(KErrNone == iServSession.AttachExecutable(KRMDebugTestApplication, EFalse));
|
|
2473 |
|
|
2474 |
// Set things up to wait for the expected exception in KRMDebugTestApplication
|
|
2475 |
test(KErrNone == iServSession.SetEventAction(KRMDebugTestApplication, type[j].iEventType, aActionMain));
|
|
2476 |
|
|
2477 |
if(EActionSuspend != aActionMain)
|
|
2478 |
{
|
|
2479 |
test(KErrNone == iServSession.SetEventAction(KRMDebugTestApplication, EEventsKillThread, aActionExtra));
|
|
2480 |
}
|
|
2481 |
|
|
2482 |
// declare a TRequestStatus object for asynchronous calls
|
|
2483 |
TRequestStatus status;
|
|
2484 |
|
|
2485 |
TEventInfo info;
|
|
2486 |
TPtr8 infoBuffer = TPtr8((TUint8*)&info,0,sizeof(TEventInfo));
|
|
2487 |
if(EActionIgnore != aActionMain)
|
|
2488 |
{
|
|
2489 |
iServSession.GetEvent(KRMDebugTestApplication(), status, infoBuffer);
|
|
2490 |
}
|
|
2491 |
|
|
2492 |
// launch the target process to trigger the expected exception
|
|
2493 |
RProcess targetProcess;
|
|
2494 |
test(KErrNone == LaunchProcess(targetProcess, KRMDebugTestApplication(), type[j].iDebugFunctionType, 0, aExtraThreads));
|
|
2495 |
TProcessId processId(targetProcess.Id());
|
|
2496 |
targetProcess.Close();
|
|
2497 |
|
|
2498 |
if(EActionIgnore != aActionMain)
|
|
2499 |
{
|
|
2500 |
// wait for notification of the exception
|
|
2501 |
User::WaitForRequest(status);
|
|
2502 |
test(KErrNone == status.Int());
|
|
2503 |
|
|
2504 |
// check that this is the event we were expecting
|
|
2505 |
test(info.iProcessIdValid);
|
|
2506 |
test(info.iThreadIdValid);
|
|
2507 |
test(info.iProcessId==processId);
|
|
2508 |
test(info.iEventType==type[j].iEventType);
|
|
2509 |
}
|
|
2510 |
|
|
2511 |
if(EActionSuspend == aActionMain)
|
|
2512 |
{
|
|
2513 |
// read the thread list, partly to check the call works, and partly to check the thread still exists
|
|
2514 |
test(ThreadExistsForProcess(info.iThreadId, info.iProcessId));
|
|
2515 |
|
|
2516 |
// register to catch all the thread kills which will occur
|
|
2517 |
test(KErrNone == iServSession.SetEventAction(KRMDebugTestApplication, EEventsKillThread, aActionExtra));
|
|
2518 |
// we specified EActionSuspend earlier so need to call resume on this thread
|
|
2519 |
test(KErrNone == iServSession.ResumeThread(info.iThreadId));
|
|
2520 |
}
|
|
2521 |
|
|
2522 |
// find out how many threads there are in the process and catch all the thread kill events,
|
|
2523 |
// the number of kill thread events should correspond to the number of extra threads launched,
|
|
2524 |
// plus one if the main thread panicked with a Sw/Hw exception
|
|
2525 |
if(EActionIgnore != aActionExtra)
|
|
2526 |
{
|
|
2527 |
TInt dyingThreads = aExtraThreads + ( (type[j].iEventType != EEventsKillThread) ? 1 : 0);
|
|
2528 |
for(TInt k=0; k<dyingThreads; k++)
|
|
2529 |
{
|
|
2530 |
iServSession.GetEvent(KRMDebugTestApplication(), status, infoBuffer);
|
|
2531 |
// wait for notification of the kill thread
|
|
2532 |
User::WaitForRequest(status);
|
|
2533 |
test(KErrNone == status.Int());
|
|
2534 |
|
|
2535 |
// check that this is the event we were expecting
|
|
2536 |
test(info.iProcessIdValid);
|
|
2537 |
test(info.iThreadIdValid);
|
|
2538 |
test(info.iProcessId==processId);
|
|
2539 |
test(info.iEventType==EEventsKillThread);
|
|
2540 |
if(EActionSuspend == aActionExtra)
|
|
2541 |
{
|
|
2542 |
// do some calls to check listings work ok at this stage
|
|
2543 |
test(ProcessExists(info.iProcessId));
|
|
2544 |
test(ThreadExistsForProcess(info.iThreadId, info.iProcessId));
|
|
2545 |
// we specified EActionSuspend earlier so need to call resume on this thread
|
|
2546 |
test(KErrNone == iServSession.ResumeThread(info.iThreadId));
|
|
2547 |
}
|
|
2548 |
}
|
|
2549 |
}
|
|
2550 |
// reset the thread kill event
|
|
2551 |
test(KErrNone == iServSession.SetEventAction(KRMDebugTestApplication(), EEventsKillThread, EActionIgnore));
|
|
2552 |
|
|
2553 |
// reset events for KRMDebugTestApplication
|
|
2554 |
test(KErrNone == iServSession.SetEventAction(KRMDebugTestApplication(), type[j].iEventType, EActionIgnore));
|
|
2555 |
|
|
2556 |
// finished debugging KRMDebugTestApplication so detach
|
|
2557 |
test(KErrNone == iServSession.DetachExecutable(KRMDebugTestApplication()));
|
|
2558 |
|
|
2559 |
// want to validate that the process has really exited, i.e. we're not accidentally keeping a handle to it...
|
|
2560 |
if(ProcessExists(processId))
|
|
2561 |
{
|
|
2562 |
// wait a little while and try again, just in case the process was still being shut down when we tried the first time
|
|
2563 |
User::After(1000000);
|
|
2564 |
test(!ProcessExists(processId));
|
|
2565 |
}
|
|
2566 |
}
|
|
2567 |
}
|
|
2568 |
|
|
2569 |
// helper function to check whether a thread with id aThreadId exists in the process with id aProcessId
|
|
2570 |
TBool CRunModeAgent::ThreadExistsForProcess(const TThreadId aThreadId, const TProcessId aProcessId)
|
|
2571 |
{
|
|
2572 |
TUint32 size;
|
|
2573 |
RBuf8 buffer;
|
|
2574 |
test(KErrNone == buffer.Create(1024));
|
|
2575 |
TInt err = iServSession.GetList(aProcessId, EThreads, buffer, size);
|
|
2576 |
while(KErrTooBig == err)
|
|
2577 |
{
|
|
2578 |
size*=2;
|
|
2579 |
test(size<=16*1024);
|
|
2580 |
test(KErrNone == buffer.ReAlloc(size));
|
|
2581 |
err = iServSession.GetList(aProcessId, EThreads, buffer, size);
|
|
2582 |
}
|
|
2583 |
test(KErrNone == err);
|
|
2584 |
|
|
2585 |
//look through the buffer and check if the target debug thread is there
|
|
2586 |
TUint8* ptr = (TUint8*)buffer.Ptr();
|
|
2587 |
const TUint8* ptrEnd = ptr + size;
|
|
2588 |
while(ptr < ptrEnd)
|
|
2589 |
{
|
|
2590 |
TThreadListEntry& entry = *(TThreadListEntry*)ptr;
|
|
2591 |
if(aThreadId.Id() == entry.iThreadId)
|
|
2592 |
{
|
|
2593 |
buffer.Close();
|
|
2594 |
return ETrue;
|
|
2595 |
}
|
|
2596 |
ptr += Align4(entry.GetSize());
|
|
2597 |
}
|
|
2598 |
buffer.Close();
|
|
2599 |
return EFalse;
|
|
2600 |
}
|
|
2601 |
|
|
2602 |
// helper function to check whether a process with id aProcessId exists
|
|
2603 |
TBool CRunModeAgent::ProcessExists(const TProcessId aProcessId)
|
|
2604 |
{
|
|
2605 |
TUint32 size;
|
|
2606 |
RBuf8 buffer;
|
|
2607 |
test(KErrNone == buffer.Create(1024));
|
|
2608 |
TInt err = iServSession.GetList(EProcesses, buffer, size);
|
|
2609 |
while(KErrTooBig == err)
|
|
2610 |
{
|
|
2611 |
size*=2;
|
|
2612 |
test(size<=16*1024);
|
|
2613 |
test(KErrNone == buffer.ReAlloc(size));
|
|
2614 |
err = iServSession.GetList(EProcesses, buffer, size);
|
|
2615 |
}
|
|
2616 |
test(KErrNone == err);
|
|
2617 |
|
|
2618 |
//look through the buffer and check if the target debug thread is there
|
|
2619 |
TUint8* ptr = (TUint8*)buffer.Ptr();
|
|
2620 |
const TUint8* ptrEnd = ptr + size;
|
|
2621 |
while(ptr < ptrEnd)
|
|
2622 |
{
|
|
2623 |
TProcessListEntry& entry = *(TProcessListEntry*)ptr;
|
|
2624 |
if(aProcessId.Id() == entry.iProcessId)
|
|
2625 |
{
|
|
2626 |
buffer.Close();
|
|
2627 |
return ETrue;
|
|
2628 |
}
|
|
2629 |
ptr += Align4(entry.GetSize());
|
|
2630 |
}
|
|
2631 |
buffer.Close();
|
|
2632 |
return EFalse;
|
|
2633 |
}
|
|
2634 |
|
|
2635 |
//----------------------------------------------------------------------------------------------
|
|
2636 |
//! @SYMTestCaseID KBase-T-RMDEBUG2-0445
|
|
2637 |
//! @SYMTestType
|
|
2638 |
//! @SYMPREQ PREQ1426
|
|
2639 |
//! @SYMTestCaseDesc Tests basic debug functions work on demand-paged target threads
|
|
2640 |
//! @SYMTestActions Checks it can r/w memory, set breakpoints etc in a demand paged target.
|
|
2641 |
//!
|
|
2642 |
//! @SYMTestExpectedResults KErrNone.
|
|
2643 |
//! @SYMTestPriority High
|
|
2644 |
//! @SYMTestStatus Implemented
|
|
2645 |
//----------------------------------------------------------------------------------------------
|
|
2646 |
|
|
2647 |
void CRunModeAgent::TestDemandPaging(void)
|
|
2648 |
{
|
|
2649 |
test.Next(_L("TestDemandPaging\n"));
|
|
2650 |
|
|
2651 |
test(KErrNone == iServSession.AttachExecutable(iFileName, EFalse));
|
|
2652 |
test(KErrNone == iServSession.SuspendThread(iThreadID));
|
|
2653 |
|
|
2654 |
// get the address of a function in code that will be paged in
|
|
2655 |
TUint32 address = (TUint32)(&RMDebugDemandPagingTest);
|
|
2656 |
const TUint32 armInstSize = 4;
|
|
2657 |
|
|
2658 |
// read the memory at &RMDebugDemandPagingTest to check that reading memory in demand paged code works
|
|
2659 |
TUint32 demandPagedInst = 0;
|
|
2660 |
TPtr8 demandPagedInstBuf((TUint8*)&demandPagedInst, armInstSize);
|
|
2661 |
test(KErrNone == iServSession.ReadMemory(iThreadID, address, armInstSize, demandPagedInstBuf, EAccess32, EEndLE8));
|
|
2662 |
|
|
2663 |
// this is the MOVS instruction that we expect to find in RMDebugDemandPagingTest
|
|
2664 |
TUint32 expectedDemandPagedInst = 0xe1b02000;
|
|
2665 |
|
|
2666 |
// check that the instruction we read is as expected
|
|
2667 |
test(demandPagedInst == expectedDemandPagedInst);
|
|
2668 |
|
|
2669 |
// set event action for break points
|
|
2670 |
test(KErrNone == iServSession.SetEventAction(RProcess().FileName(), EEventsBreakPoint, EActionContinue));
|
|
2671 |
|
|
2672 |
// set an arm breakpoint on RMDebugDemandPagingTest
|
|
2673 |
TBreakId armBreakId = 0;
|
|
2674 |
test(KErrNone == iServSession.SetBreak(armBreakId, iThreadID, address, EArmMode));
|
|
2675 |
|
|
2676 |
// Ensure that after setting the breakpoint the memory read returns the correct value
|
|
2677 |
TUint32 demandPagedInstWithBreakPoint = 0;
|
|
2678 |
TPtr8 spinForeverInstWithBreakPointBuf((TUint8*)&demandPagedInstWithBreakPoint, armInstSize);
|
|
2679 |
test(KErrNone == iServSession.ReadMemory(iThreadID, address, armInstSize, spinForeverInstWithBreakPointBuf, EAccess32, EEndLE8));
|
|
2680 |
test(demandPagedInst == demandPagedInstWithBreakPoint);
|
|
2681 |
|
|
2682 |
// switch the target thread to run the demand paging function
|
|
2683 |
test(KErrNone == SwitchTestFunction(EDemandPagingFunction));
|
|
2684 |
|
|
2685 |
// set up event watcher to catch breakpoint being hit in demand paged code
|
|
2686 |
TEventInfo info;
|
|
2687 |
static TRequestStatus status;
|
|
2688 |
TPtr8 infoPtr((TUint8*)&info,sizeof(TEventInfo));
|
|
2689 |
iServSession.GetEvent(RProcess().FileName(), status, infoPtr);
|
|
2690 |
|
|
2691 |
// resume the thread
|
|
2692 |
test(KErrNone == iServSession.ResumeThread(iThreadID));
|
|
2693 |
// wait for notification of the breakpoint hit event
|
|
2694 |
User::WaitForRequest(status);
|
|
2695 |
test(status==KErrNone);
|
|
2696 |
|
|
2697 |
// info should now be filled with the details
|
|
2698 |
test(info.iProcessIdValid);
|
|
2699 |
test(info.iThreadIdValid);
|
|
2700 |
test(info.iEventType == EEventsBreakPoint);
|
|
2701 |
test(info.iThreadBreakPointInfo.iRmdArmExcInfo.iR15 == address);
|
|
2702 |
|
|
2703 |
// remove the break point and resume the thread
|
|
2704 |
test(KErrNone == iServSession.ClearBreak(armBreakId));
|
|
2705 |
|
|
2706 |
// switch the target thread to run the default function
|
|
2707 |
test(KErrNone == SwitchTestFunction(EDefaultFunction));
|
|
2708 |
|
|
2709 |
test(KErrNone == iServSession.ResumeThread(iThreadID));
|
|
2710 |
test(KErrNone == iServSession.DetachExecutable(iFileName));
|
|
2711 |
}
|
|
2712 |
|
|
2713 |
// Names of some test programs used for testing security
|
|
2714 |
_LIT(KRMDebugSecurity0FileName,"z:\\sys\\bin\\t_rmdebug_security0.exe"); // Debuggable
|
|
2715 |
_LIT(KRMDebugSecurity1FileName,"z:\\sys\\bin\\t_rmdebug_security1.exe"); // Not debuggable
|
|
2716 |
_LIT(KRMDebugSecurity2FileName,"z:\\sys\\bin\\t_rmdebug_security2.exe"); // AllFiles
|
|
2717 |
_LIT(KRMDebugSecurity3FileName,"z:\\sys\\bin\\t_rmdebug_security3.exe"); // TCB AllFiles
|
|
2718 |
|
|
2719 |
// include the test header file here
|
|
2720 |
#include "rm_debug_kerneldriver.h"
|
|
2721 |
|
|
2722 |
//----------------------------------------------------------------------------------------------
|
|
2723 |
//! @SYMTestCaseID KBase-T-RMDEBUG2-0446
|
|
2724 |
//! @SYMTestType
|
|
2725 |
//! @SYMPREQ PREQ1426
|
|
2726 |
//! @SYMTestCaseDesc Tests Debug Device Driver is locked to the SID of the Debug Security Svr.
|
|
2727 |
//! @SYMTestActions Loads rm-debug.ldd and tries to open a handle to it. This should fail.
|
|
2728 |
//!
|
|
2729 |
//! @SYMTestExpectedResults KErrPermissionDenied.
|
|
2730 |
//! @SYMTestPriority High
|
|
2731 |
//! @SYMTestStatus Implemented
|
|
2732 |
//----------------------------------------------------------------------------------------------
|
|
2733 |
|
|
2734 |
void CRunModeAgent::TestDriverSecurity(void)
|
|
2735 |
{
|
|
2736 |
test.Next(_L("TestDriverSecurity\n"));
|
|
2737 |
|
|
2738 |
RRM_DebugDriver kernelDriver;
|
|
2739 |
|
|
2740 |
// Load the debug device driver
|
|
2741 |
TInt err = User::LoadLogicalDevice( KDebugDriverFileName );
|
|
2742 |
test((KErrNone == err) || (KErrAlreadyExists == err));
|
|
2743 |
|
|
2744 |
// we were allowed to load the driver, or its already loaded.
|
|
2745 |
|
|
2746 |
// Try to open a handle to the driver - this should return KErrPermissionDenied as we don't have the DSS SID
|
|
2747 |
TRM_DebugDriverInfo driverInfo;
|
|
2748 |
driverInfo.iUserLibraryEnd = 0;
|
|
2749 |
err = kernelDriver.Open(driverInfo);
|
|
2750 |
test((err == KErrInUse) || (err == KErrPermissionDenied));
|
|
2751 |
|
|
2752 |
}
|
|
2753 |
|
|
2754 |
//----------------------------------------------------------------------------------------------
|
|
2755 |
//! @SYMTestCaseID KBase-T-RMDEBUG2-0447
|
|
2756 |
//! @SYMTestType
|
|
2757 |
//! @SYMPREQ PREQ1426
|
|
2758 |
//! @SYMTestCaseDesc Tests Debug driver can only be access via the DSS. Also tests DSS cannot
|
|
2759 |
//! be subverted. Tests functionality of two representative OEM Debug Tokens.
|
|
2760 |
//! @SYMTestActions Tries to open rm_debug.ldd (should fail). Tries to debug various processes
|
|
2761 |
//! (only debuggable one should succeed).
|
|
2762 |
//!
|
|
2763 |
//! @SYMTestExpectedResults KErrPermissionDenied.
|
|
2764 |
//! @SYMTestPriority High
|
|
2765 |
//! @SYMTestStatus Implemented
|
|
2766 |
//----------------------------------------------------------------------------------------------
|
|
2767 |
|
|
2768 |
void CRunModeAgent::TestSecurity(void)
|
|
2769 |
{
|
|
2770 |
// Things to test
|
|
2771 |
//
|
|
2772 |
// try to use debug driver directly ( should have the wrong UID/SID value!)
|
|
2773 |
test.Next(_L("TestSecurity - Bypass Debug Security Server to Debug Device Driver - DSS running\n"));
|
|
2774 |
|
|
2775 |
// Things to test
|
|
2776 |
//
|
|
2777 |
// Load the debug device driver
|
|
2778 |
RRM_DebugDriver kernelDriver;
|
|
2779 |
TInt err = User::LoadLogicalDevice( KDebugDriverFileName );
|
|
2780 |
test((KErrNone == err) || (KErrAlreadyExists == err));
|
|
2781 |
|
|
2782 |
// we were allowed to load the driver, or its already loaded.
|
|
2783 |
|
|
2784 |
// Try to open handle a to the driver - this should return KErrPermission/KErrInUse as we don't have the DSS SID
|
|
2785 |
// and we expect the DSS to already be using it.
|
|
2786 |
TRM_DebugDriverInfo driverInfo;
|
|
2787 |
driverInfo.iUserLibraryEnd = 0;
|
|
2788 |
err = kernelDriver.Open(driverInfo);
|
|
2789 |
test(err == KErrInUse);
|
|
2790 |
|
|
2791 |
//
|
|
2792 |
// Attach to the Debug Security Server (passive)
|
|
2793 |
//
|
|
2794 |
test.Next(_L("TestSecurity - Attach to the Debug Security Server (passive)\n"));
|
|
2795 |
|
|
2796 |
_LIT(KSecurityServerProcessName, "z:\\sys\\bin\\rm_debug_svr.exe");
|
|
2797 |
|
|
2798 |
test(KErrPermissionDenied == iServSession.AttachExecutable(KSecurityServerProcessName, ETrue));
|
|
2799 |
|
|
2800 |
//
|
|
2801 |
// Attach to the Debug Security Server (active)
|
|
2802 |
//
|
|
2803 |
test.Next(_L("TestSecurity - Attach to the Debug Security Server (active)\n"));
|
|
2804 |
|
|
2805 |
test(KErrPermissionDenied == iServSession.AttachExecutable(KSecurityServerProcessName, EFalse));
|
|
2806 |
|
|
2807 |
//
|
|
2808 |
// Attach to Process 0
|
|
2809 |
//
|
|
2810 |
// Target: Debuggable
|
|
2811 |
//
|
|
2812 |
test.Next(_L("TestSecurity - Attach to test process 0\n"));
|
|
2813 |
|
|
2814 |
// Agent can debug the target app as it is marked debuggable - ie capabilities are ignored)
|
|
2815 |
HelpTestSecurityAttachDetachExecutable(KRMDebugSecurity0FileName,ETrue);
|
|
2816 |
|
|
2817 |
//
|
|
2818 |
// Attach to Process - 1
|
|
2819 |
//
|
|
2820 |
// Target: Non-debuggable for ordinary debug agent, debuggable for OEM/OEM2 token authorised agent
|
|
2821 |
//
|
|
2822 |
// Note: This target app has no PlatSec capabilities
|
|
2823 |
//
|
|
2824 |
// Agent cannot debug the app unless it has an OEM/OEM2 Debug Token
|
|
2825 |
test.Next(_L("TestSecurity - Attach to test process 1\n"));
|
|
2826 |
|
|
2827 |
#ifdef SYMBIAN_STANDARDDEBUG
|
|
2828 |
HelpTestSecurityAttachDetachExecutable(KRMDebugSecurity1FileName,EFalse);
|
|
2829 |
#endif
|
|
2830 |
|
|
2831 |
#ifdef SYMBIAN_OEMDEBUG
|
|
2832 |
HelpTestSecurityAttachDetachExecutable(KRMDebugSecurity1FileName,ETrue);
|
|
2833 |
#endif
|
|
2834 |
|
|
2835 |
#ifdef SYMBIAN_OEM2DEBUG
|
|
2836 |
HelpTestSecurityAttachDetachExecutable(KRMDebugSecurity1FileName,ETrue);
|
|
2837 |
#endif
|
|
2838 |
|
|
2839 |
//
|
|
2840 |
// Attach to Process - 2
|
|
2841 |
//
|
|
2842 |
// Target: Non-debuggable for ordinary debug agent, non-debuggable for OEM2 authorised agent (insufficient caps)
|
|
2843 |
//
|
|
2844 |
// Note: This target app has AllFiles capability
|
|
2845 |
//
|
|
2846 |
// Agent cannot debug the app unless it has an OEM Debug Token
|
|
2847 |
test.Next(_L("TestSecurity - Attach to test process 2\n"));
|
|
2848 |
|
|
2849 |
#ifdef SYMBIAN_STANDARDDEBUG
|
|
2850 |
HelpTestSecurityAttachDetachExecutable(KRMDebugSecurity2FileName,EFalse);
|
|
2851 |
#endif
|
|
2852 |
|
|
2853 |
#ifdef SYMBIAN_OEMDEBUG
|
|
2854 |
HelpTestSecurityAttachDetachExecutable(KRMDebugSecurity2FileName,ETrue);
|
|
2855 |
#endif
|
|
2856 |
|
|
2857 |
#ifdef SYMBIAN_OEM2DEBUG
|
|
2858 |
HelpTestSecurityAttachDetachExecutable(KRMDebugSecurity2FileName,EFalse);
|
|
2859 |
#endif
|
|
2860 |
|
|
2861 |
//
|
|
2862 |
// Attach to Process - 3
|
|
2863 |
//
|
|
2864 |
// Target: Non-debuggable for ordinary debug agent, non-debuggable for OEM authorised agent (insufficient caps)
|
|
2865 |
//
|
|
2866 |
// Note: This target app has AllFiles and TCB and NetworkControl capabilities
|
|
2867 |
//
|
|
2868 |
test.Next(_L("TestSecurity - Attach to test process 3\n"));
|
|
2869 |
|
|
2870 |
HelpTestSecurityAttachDetachExecutable(KRMDebugSecurity3FileName,EFalse);
|
|
2871 |
|
|
2872 |
}
|
|
2873 |
|
|
2874 |
//----------------------------------------------------------------------------------------------
|
|
2875 |
//! @SYMTestCaseID KBase-T-RMDEBUG2-0543
|
|
2876 |
//! @SYMTestType
|
|
2877 |
//! @SYMPREQ PREQ1426
|
|
2878 |
//! @SYMTestCaseDesc Validates that a dll can be built which #include's the rm_debug_api.h header, i.e. rm_debug_api.h contains no static data.
|
|
2879 |
//! @SYMTestActions Calls a dummy function in t_rmdebug_dll.dll which implies the dll has been built correctly.
|
|
2880 |
//!
|
|
2881 |
//! @SYMTestExpectedResults KErrNone.
|
|
2882 |
//! @SYMTestPriority High
|
|
2883 |
//! @SYMTestStatus Implemented
|
|
2884 |
//----------------------------------------------------------------------------------------------
|
|
2885 |
void CRunModeAgent::TestDllUsage(void)
|
|
2886 |
{
|
|
2887 |
test.Next(_L("TestDllUsage\n"));
|
|
2888 |
test(KUidDebugSecurityServer == GetDSSUid());
|
|
2889 |
}
|
|
2890 |
|
|
2891 |
//----------------------------------------------------------------------------------------------
|
|
2892 |
//! @SYMTestCaseID KBase-T-RMDEBUG2-0812
|
|
2893 |
//! @SYMTestType
|
|
2894 |
//! @SYMPREQ PREQ1700
|
|
2895 |
//! @SYMTestCaseDesc Writes a known data to the crash flash and validates the data written
|
|
2896 |
//! using the read operation and finally erase the data. In the absence
|
|
2897 |
//! of an OEM debug token, access to the crash partition should not be allowed
|
|
2898 |
//! @SYMTestActions Invoke the flash write method in DSS and call the read method in DSS
|
|
2899 |
//! to validate the data is written correctly and then erase the written area
|
|
2900 |
//!
|
|
2901 |
//! @SYMTestExpectedResults KErrNone.
|
|
2902 |
//! @SYMTestPriority High
|
|
2903 |
//! @SYMTestStatus Implemented
|
|
2904 |
//----------------------------------------------------------------------------------------------
|
|
2905 |
void CRunModeAgent::TestCrashFlash(void)
|
|
2906 |
{
|
|
2907 |
#if defined (SYMBIAN_STANDARDDEBUG) || defined (SYMBIAN_OEM2DEBUG)
|
|
2908 |
|
|
2909 |
test.Next(_L("@SYMTestCaseID:DT-debug-securityserver-006 Testing We cannot Erase the Crash Flash with insufficient privileges"));
|
|
2910 |
|
|
2911 |
TUint32 size = 0;
|
|
2912 |
TInt err = iServSession.EraseCrashLog(0, 1);
|
|
2913 |
test(KErrPermissionDenied == err);
|
|
2914 |
|
|
2915 |
test.Next(_L("@SYMTestCaseID:DT-debug-securityserver-005 Testing We can't Write to the Crash Flash with insufficient privileges"));
|
|
2916 |
|
|
2917 |
err = iServSession.WriteCrashConfig(0, KCrashDummyData, size);
|
|
2918 |
test(KErrPermissionDenied == err);
|
|
2919 |
test(size == 0);
|
|
2920 |
|
|
2921 |
test.Next(_L("@SYMTestCaseID:DT-debug-securityserver-008 Testing We can't Read from the Crash Flash with insufficient privileges"));
|
|
2922 |
|
|
2923 |
TUint32 readSize = 0x10;
|
|
2924 |
RBuf8 buf;
|
|
2925 |
buf.CleanupClosePushL();
|
|
2926 |
err = buf.Create(readSize);
|
|
2927 |
|
|
2928 |
test(err == KErrNone);
|
|
2929 |
|
|
2930 |
err = iServSession.ReadCrashLog(0, buf, readSize);
|
|
2931 |
test(KErrPermissionDenied == err);
|
|
2932 |
|
|
2933 |
test.Next(_L("@SYMTestCaseID:DT-debug-securityserver-004 Testing Writing To an invalid location"));
|
|
2934 |
|
|
2935 |
TUint32 writeSize = 0;
|
|
2936 |
err = iServSession.WriteCrashConfig(0xFFFFFFFF, KCrashDummyData, writeSize);
|
|
2937 |
|
|
2938 |
test(err == KErrPermissionDenied);
|
|
2939 |
|
|
2940 |
test.Next(_L("@SYMTestCaseID:DT-debug-securityserver-003 Testing Reading from an invalid location"));
|
|
2941 |
|
|
2942 |
buf.FillZ();
|
|
2943 |
err = iServSession.ReadCrashLog(0, buf, writeSize);
|
|
2944 |
|
|
2945 |
test(err == KErrPermissionDenied);
|
|
2946 |
|
|
2947 |
CleanupStack::PopAndDestroy(&buf);
|
|
2948 |
|
|
2949 |
#endif
|
|
2950 |
|
|
2951 |
#ifdef SYMBIAN_OEMDEBUG
|
|
2952 |
|
|
2953 |
TInt err = KErrNone;
|
|
2954 |
|
|
2955 |
test.Next(_L("@SYMTestCaseID:DT-debug-securityserver-007 Testing We can Erase the Crash Flash with sufficient privileges"));
|
|
2956 |
|
|
2957 |
err = iServSession.EraseCrashLog(0, 1);
|
|
2958 |
|
|
2959 |
//For platforms without a flash partition we get KErrNotFound - this is still a pass
|
|
2960 |
if(KErrNotFound == err)
|
|
2961 |
{
|
|
2962 |
test.Printf(_L("Platform has no flash partition - continue"));
|
|
2963 |
return;
|
|
2964 |
}
|
|
2965 |
|
|
2966 |
test(KErrNone == err);
|
|
2967 |
|
|
2968 |
//Read back the start of the block to make sure its 0xFFFFFFFF
|
|
2969 |
const TUint numBytesToCheck = 0x80; //We dont know the block size
|
|
2970 |
TBuf8<numBytesToCheck> eraseCheck;
|
|
2971 |
eraseCheck.SetLength(numBytesToCheck);
|
|
2972 |
|
|
2973 |
err = iServSession.ReadCrashLog(0, eraseCheck, numBytesToCheck);
|
|
2974 |
test(err == KErrNone);
|
|
2975 |
|
|
2976 |
TBool dataIsOk = ETrue;
|
|
2977 |
for(TUint cnt = 0; cnt < numBytesToCheck; cnt++)
|
|
2978 |
{
|
|
2979 |
if(eraseCheck[cnt] != 0xFF)
|
|
2980 |
{
|
|
2981 |
dataIsOk = EFalse;
|
|
2982 |
}
|
|
2983 |
}
|
|
2984 |
|
|
2985 |
test(dataIsOk);
|
|
2986 |
|
|
2987 |
test.Next(_L("@SYMTestCaseID:DT-debug-securityserver-002 Testing We can Write to the Crash Flash with sufficient privileges"));
|
|
2988 |
|
|
2989 |
TUint32 writeSize = 0;
|
|
2990 |
err = iServSession.WriteCrashConfig(0, KCrashDummyData, writeSize);
|
|
2991 |
|
|
2992 |
test(writeSize == KCrashDummyData().Length());
|
|
2993 |
|
|
2994 |
test.Next(_L("@SYMTestCaseID:DT-debug-securityserver-001 Testing We can Read from the Crash Flash with sufficient privileges"));
|
|
2995 |
|
|
2996 |
RBuf8 buf;
|
|
2997 |
buf.CleanupClosePushL();
|
|
2998 |
err = buf.Create(writeSize);
|
|
2999 |
|
|
3000 |
test(err == KErrNone);
|
|
3001 |
|
|
3002 |
buf.FillZ();
|
|
3003 |
|
|
3004 |
err = iServSession.ReadCrashLog(0, buf, writeSize);
|
|
3005 |
|
|
3006 |
test(0 == buf.Compare(KCrashDummyData));
|
|
3007 |
|
|
3008 |
test.Next(_L("@SYMTestCaseID:DT-debug-securityserver-004 Testing Writing To an invalid location"));
|
|
3009 |
|
|
3010 |
writeSize = 0;
|
|
3011 |
err = iServSession.WriteCrashConfig(0xFFFFFFFF, KCrashDummyData, writeSize);
|
|
3012 |
|
|
3013 |
test(err == KErrArgument);
|
|
3014 |
|
|
3015 |
test.Next(_L("@SYMTestCaseID:DT-debug-securityserver-003 Testing Reading from an invalid location"));
|
|
3016 |
|
|
3017 |
buf.FillZ();
|
|
3018 |
err = iServSession.ReadCrashLog(0xFFFFFFFF, buf, writeSize);
|
|
3019 |
|
|
3020 |
test(err == KErrArgument);
|
|
3021 |
|
|
3022 |
CleanupStack::PopAndDestroy(&buf);
|
|
3023 |
|
|
3024 |
#endif
|
|
3025 |
}
|
|
3026 |
//----------------------------------------------------------------------------------------------
|
|
3027 |
//! @SYMTestCaseID KBase-T-RMDEBUG2-0735
|
|
3028 |
//! @SYMTestType
|
|
3029 |
//! @SYMPREQ PREQ1426
|
|
3030 |
//! @SYMTestCaseDesc Tests the Kill Process functionality. Only can kill a debuggable process.
|
|
3031 |
//! @SYMTestActions Launches a debuggable and non-debuggable process and tries to kill both.
|
|
3032 |
//!
|
|
3033 |
//! @SYMTestExpectedResults KErrNone.
|
|
3034 |
//! @SYMTestPriority High
|
|
3035 |
//! @SYMTestStatus Implemented
|
|
3036 |
//----------------------------------------------------------------------------------------------
|
|
3037 |
void CRunModeAgent::TestKillProcess(void)
|
|
3038 |
{
|
|
3039 |
test.Next(_L("TestKillProcess\n"));
|
|
3040 |
|
|
3041 |
// Kill a debuggable process
|
|
3042 |
|
|
3043 |
// check that killing a process is supported
|
|
3044 |
TTag tag = GetTag(ETagHeaderIdKillObjects, EFunctionalityKillProcess);
|
|
3045 |
test(tag.iValue);
|
|
3046 |
// check that killing a thread is not supported
|
|
3047 |
tag = GetTag(ETagHeaderIdKillObjects, EFunctionalityKillThread);
|
|
3048 |
test(!tag.iValue);
|
|
3049 |
|
|
3050 |
// attach first!
|
|
3051 |
TInt err = iServSession.AttachExecutable(KRMDebugTestApplication, EFalse /* Active */);
|
|
3052 |
test(err == KErrNone);
|
|
3053 |
|
|
3054 |
// first launch a debuggable process
|
|
3055 |
RProcess process;
|
|
3056 |
err = LaunchProcess(process, KRMDebugTestApplication(),ESpinForever, 0, 0);
|
|
3057 |
test (err == KErrNone);
|
|
3058 |
|
|
3059 |
// try to find the process in the list
|
|
3060 |
_LIT(KRMDebugAppName, "t_rmdebug_app");
|
|
3061 |
|
|
3062 |
TBool found = ProcessExists(KRMDebugAppName);
|
|
3063 |
test (found);
|
|
3064 |
|
|
3065 |
// program now running, so try to kill it
|
|
3066 |
err = iServSession.KillProcess(process.Id(), 0 /* kill reason */);
|
|
3067 |
test(err == KErrNone);
|
|
3068 |
|
|
3069 |
process.Close();
|
|
3070 |
|
|
3071 |
User::After(2000000); // should die within two seconds.
|
|
3072 |
|
|
3073 |
// can we still find it? Should be gone
|
|
3074 |
found = ProcessExists(KRMDebugAppName);
|
|
3075 |
test (!found);
|
|
3076 |
|
|
3077 |
// release the program again.
|
|
3078 |
err = iServSession.DetachExecutable(KRMDebugTestApplication);
|
|
3079 |
test(err == KErrNone);
|
|
3080 |
|
|
3081 |
// Try to kill a non-debuggable process and fail.
|
|
3082 |
|
|
3083 |
// first launch a non-debuggable process
|
|
3084 |
RProcess process2;
|
|
3085 |
err = LaunchProcess(process2, KRMDebugSecurity1FileName(),ESpinForever, 0, 0);
|
|
3086 |
test (err == KErrNone);
|
|
3087 |
|
|
3088 |
// try to find the process in the list
|
|
3089 |
_LIT(KRMDebugAppName2, "t_rmdebug_security1");
|
|
3090 |
|
|
3091 |
TBool found2 = ProcessExists(KRMDebugAppName2);
|
|
3092 |
test (found2);
|
|
3093 |
|
|
3094 |
// program now running, so try to kill it
|
|
3095 |
err = iServSession.KillProcess(process2.Id(), 0 /* kill reason */);
|
|
3096 |
test(err == KErrPermissionDenied);
|
|
3097 |
|
|
3098 |
process2.Close();
|
|
3099 |
|
|
3100 |
User::After(2000000); // should die within two seconds if it is going to die.
|
|
3101 |
|
|
3102 |
// can we still find it? Should be still around!
|
|
3103 |
found2 = ProcessExists(KRMDebugAppName2);
|
|
3104 |
test (found2);
|
|
3105 |
|
|
3106 |
}
|
|
3107 |
|
|
3108 |
//----------------------------------------------------------------------------------------------
|
|
3109 |
//! @SYMTestCaseID KBase-T-RMDEBUG2-1388
|
|
3110 |
//! @SYMTestType
|
|
3111 |
//! @SYMPREQ PREQ1426
|
|
3112 |
//! @SYMTestCaseDesc Tests the correct operation of the AddProcess and Remove Process
|
|
3113 |
//! @SYMTestActions 1. Registers for AddProcess and Remove Process events
|
|
3114 |
//! 2. Starts a test process z:\sys\bin\t_rmdebug_security0.exe
|
|
3115 |
//! 3. Wait for the AddProcess event to be reported
|
|
3116 |
//! 4. Kill the newly started test process
|
|
3117 |
//! 5. Wait for the RemoveProcess event to be reported
|
|
3118 |
//! 6. Tell the DSS it is no longer interested in AddProcess and RemoveProcess events
|
|
3119 |
//!
|
|
3120 |
//! @SYMTestExpectedResults KErrNone.
|
|
3121 |
//! @SYMTestPriority High
|
|
3122 |
//! @SYMTestStatus Implemented
|
|
3123 |
//----------------------------------------------------------------------------------------------
|
|
3124 |
|
|
3125 |
void CRunModeAgent::TestAddRemoveProcessEvents()
|
|
3126 |
{
|
|
3127 |
test.Next(_L("TestAddRemoveProcessEvents\n"));
|
|
3128 |
|
|
3129 |
// attach to a process (e.g. one of the simple security test programs)
|
|
3130 |
// launch the security program
|
|
3131 |
// wait for the add event
|
|
3132 |
// continue the program.
|
|
3133 |
// wait for the remove event
|
|
3134 |
// detach process
|
|
3135 |
|
|
3136 |
test(KErrNone == iServSession.AttachExecutable(KRMDebugSecurity0FileName, EFalse));
|
|
3137 |
|
|
3138 |
test(KErrNone == iServSession.SetEventAction(KRMDebugSecurity0FileName,EEventsAddProcess, EActionContinue));
|
|
3139 |
|
|
3140 |
test(KErrNone == iServSession.SetEventAction(KRMDebugSecurity0FileName,EEventsRemoveProcess, EActionContinue));
|
|
3141 |
|
|
3142 |
// Creator thread ID of the current thread (to be creator of test application)
|
|
3143 |
TInt creatorThreadId = RThread().Id();
|
|
3144 |
|
|
3145 |
RProcess process;
|
|
3146 |
TInt err = process.Create(KRMDebugSecurity0FileName, KNullDesC, EOwnerProcess);
|
|
3147 |
test (err == KErrNone);
|
|
3148 |
|
|
3149 |
// Rendezvous with process
|
|
3150 |
TRequestStatus status;
|
|
3151 |
process.Rendezvous(status);
|
|
3152 |
|
|
3153 |
// Start the test program
|
|
3154 |
process.Resume();
|
|
3155 |
User::WaitForRequest(status);
|
|
3156 |
test(status==KErrNone);
|
|
3157 |
|
|
3158 |
// Wait for the addprocess event
|
|
3159 |
TEventInfo info;
|
|
3160 |
TPtr8 infoPtr((TUint8*)&info,0,sizeof(TEventInfo));
|
|
3161 |
|
|
3162 |
iServSession.GetEvent(KRMDebugSecurity0FileName,status,infoPtr);
|
|
3163 |
|
|
3164 |
// Wait for notification of the addprocess hit event
|
|
3165 |
User::WaitForRequest(status);
|
|
3166 |
test(status==KErrNone);
|
|
3167 |
|
|
3168 |
// Check this was the right kind of event
|
|
3169 |
test(info.iEventType == EEventsAddProcess);
|
|
3170 |
|
|
3171 |
const TInt uid3offset = 2;
|
|
3172 |
|
|
3173 |
// Get UID3 for current process
|
|
3174 |
TUint32 Uid3 = process.Type()[uid3offset].iUid;
|
|
3175 |
|
|
3176 |
// Check correct UID3 is returned from the driver
|
|
3177 |
test(info.iAddProcessInfo.iUid3 == Uid3);
|
|
3178 |
|
|
3179 |
// Check correct creator ID for test application is returned from the driver
|
|
3180 |
test(info.iAddProcessInfo.iCreatorThreadId == creatorThreadId);
|
|
3181 |
|
|
3182 |
// Kill the process, as we don't need it anymore
|
|
3183 |
process.Kill(KErrNone);
|
|
3184 |
|
|
3185 |
// Wait for the remove process event
|
|
3186 |
iServSession.GetEvent(KRMDebugSecurity0FileName,status,infoPtr);
|
|
3187 |
|
|
3188 |
// Wait for notification of the remove process hit event
|
|
3189 |
User::WaitForRequest(status);
|
|
3190 |
test(status==KErrNone);
|
|
3191 |
|
|
3192 |
// Check this was the right kind of event
|
|
3193 |
test(info.iEventType == EEventsRemoveProcess);
|
|
3194 |
|
|
3195 |
test(KErrNone == iServSession.SetEventAction(KRMDebugSecurity0FileName,EEventsRemoveProcess, EActionIgnore));
|
|
3196 |
|
|
3197 |
test(KErrNone == iServSession.SetEventAction(KRMDebugSecurity0FileName,EEventsAddProcess, EActionIgnore));
|
|
3198 |
|
|
3199 |
test(KErrNone == iServSession.DetachExecutable(KRMDebugSecurity0FileName));
|
|
3200 |
|
|
3201 |
}
|
|
3202 |
|
|
3203 |
//----------------------------------------------------------------------------------------------
|
|
3204 |
//! @SYMTestCaseID KBase-T-RMDEBUG2-0736
|
|
3205 |
//! @SYMTestType
|
|
3206 |
//! @SYMPREQ PREQ1426
|
|
3207 |
//! @SYMTestCaseDesc Checks that process break points can be set, and that they can co-exist alongside thread breakpoints
|
|
3208 |
//! @SYMTestActions Checks that process break points can be set, and that they can co-exist alongside thread breakpoints
|
|
3209 |
//!
|
|
3210 |
//! @SYMTestExpectedResults KErrNone.
|
|
3211 |
//! @SYMTestPriority High
|
|
3212 |
//! @SYMTestStatus Implemented
|
|
3213 |
//----------------------------------------------------------------------------------------------
|
|
3214 |
void CRunModeAgent::TestProcessBreakPoints(void)
|
|
3215 |
{
|
|
3216 |
test.Next(_L("TestProcessBreakPoints\n"));
|
|
3217 |
|
|
3218 |
// check that process breakpoints are supported
|
|
3219 |
TTag tag = GetTag(ETagHeaderIdBreakpoints, EBreakpointProcess);
|
|
3220 |
test(tag.iValue);
|
|
3221 |
|
|
3222 |
test(KErrNone == iServSession.AttachExecutable(iFileName, EFalse));
|
|
3223 |
test(KErrNone == iServSession.SuspendThread(iThreadID));
|
|
3224 |
|
|
3225 |
// Try to set the breakpoint
|
|
3226 |
TBreakId breakId;
|
|
3227 |
TUint32 address = (TUint32)(&RMDebug_BranchTst1);
|
|
3228 |
RProcess process;
|
|
3229 |
TProcessId processId = process.Id();
|
|
3230 |
process.Close();
|
|
3231 |
|
|
3232 |
test(KErrNone == iServSession.SetProcessBreak(breakId, processId, address, EArmMode));
|
|
3233 |
test(KErrAlreadyExists == iServSession.SetBreak(breakId, iThreadID, address, EArmMode));
|
|
3234 |
test(KErrAlreadyExists == iServSession.SetBreak(breakId, iThreadID, address, EThumbMode));
|
|
3235 |
test(KErrAlreadyExists == iServSession.SetProcessBreak(breakId, processId, address, EArmMode));
|
|
3236 |
test(KErrAlreadyExists == iServSession.SetProcessBreak(breakId, processId, address, EThumbMode));
|
|
3237 |
test(KErrNone == iServSession.ClearBreak(breakId));
|
|
3238 |
|
|
3239 |
test(KErrNone == iServSession.SetBreak(breakId, iThreadID, address, EArmMode));
|
|
3240 |
test(KErrAlreadyExists == iServSession.SetProcessBreak(breakId, processId, address, EArmMode));
|
|
3241 |
test(KErrAlreadyExists == iServSession.SetProcessBreak(breakId, processId, address, EThumbMode));
|
|
3242 |
test(KErrNone == iServSession.ClearBreak(breakId));
|
|
3243 |
|
|
3244 |
test(KErrNone == iServSession.ResumeThread(iThreadID));
|
|
3245 |
|
|
3246 |
test(KErrNone == iServSession.DetachExecutable(iFileName));
|
|
3247 |
}
|
|
3248 |
|
|
3249 |
//----------------------------------------------------------------------------------------------
|
|
3250 |
//! @SYMTestCaseID KBase-T-RMDEBUG2-1309
|
|
3251 |
//! @SYMTestType
|
|
3252 |
//! @SYMPREQ PREQ1426
|
|
3253 |
//! @SYMTestCaseDesc Checks that in the case of multiple low priority events (user traces in this case) we can still receive higher
|
|
3254 |
//! priority events should the buffer reach a critical level
|
|
3255 |
//! @SYMTestActions Run to first breakpoint in our test code. Then multiple trace events are issued. We should still be able to hit
|
|
3256 |
//! the second breakpoint
|
|
3257 |
//!
|
|
3258 |
//! @SYMTestExpectedResults KErrNone.
|
|
3259 |
//! @SYMTestPriority High
|
|
3260 |
//! @SYMTestStatus Implemented
|
|
3261 |
//----------------------------------------------------------------------------------------------
|
|
3262 |
|
|
3263 |
void CRunModeAgent::TestMultipleTraceEvents(void)
|
|
3264 |
{
|
|
3265 |
//Dont run the test for an SMP System
|
|
3266 |
if (UserSvr::HalFunction(EHalGroupKernel, EKernelHalSmpSupported, 0, 0) == KErrNone)
|
|
3267 |
return;
|
|
3268 |
|
|
3269 |
test.Next(_L("TestMultipleTraceEvents\n"));
|
|
3270 |
|
|
3271 |
//attach to target debug process
|
|
3272 |
test(KErrNone == iServSession.AttachExecutable(iFileName, EFalse));
|
|
3273 |
|
|
3274 |
//and suspend the thread
|
|
3275 |
test(KErrNone == iServSession.SuspendThread(iThreadID));
|
|
3276 |
|
|
3277 |
//register interest in BP's & trace events and trace ignored events
|
|
3278 |
test(KErrNone == iServSession.SetEventAction(iFileName,EEventsBreakPoint, EActionSuspend));
|
|
3279 |
test(KErrNone == iServSession.SetEventAction(iFileName,EEventsUserTrace, EActionContinue));
|
|
3280 |
test(KErrNone == iServSession.SetEventAction(iFileName,EEventsUserTracesLost, EActionContinue));
|
|
3281 |
|
|
3282 |
// Try to set the breakpoints
|
|
3283 |
TBreakId armBreakId;
|
|
3284 |
TBreakId armBreakId2;
|
|
3285 |
TUint32 address = (TUint32)(&RMDebug_BranchTst1);
|
|
3286 |
TUint32 address2 = (TUint32)(&RMDebug_StepTest_Non_PC_Modifying);
|
|
3287 |
|
|
3288 |
test(KErrNone == iServSession.SetBreak(armBreakId,iThreadID,address,EArmMode));
|
|
3289 |
test(KErrNone == iServSession.SetBreak(armBreakId2,iThreadID,address2,EArmMode));
|
|
3290 |
|
|
3291 |
//set the target thread to execute the trace test function
|
|
3292 |
test(KErrNone == SwitchTestFunction(EMultipleTraceCalls));
|
|
3293 |
|
|
3294 |
// Continue the thread
|
|
3295 |
test(KErrNone == iServSession.ResumeThread(iThreadID));
|
|
3296 |
|
|
3297 |
// wait for the breakpoint to be hit
|
|
3298 |
TEventInfo info;
|
|
3299 |
static TRequestStatus status;
|
|
3300 |
|
|
3301 |
TPtr8 infoPtr((TUint8*)&info,0,sizeof(TEventInfo));
|
|
3302 |
iServSession.GetEvent(iFileName,status,infoPtr);
|
|
3303 |
|
|
3304 |
// Wait for notification of the 1st breakpoint hit event
|
|
3305 |
User::WaitForRequest(status);
|
|
3306 |
test(status==KErrNone);
|
|
3307 |
|
|
3308 |
// info should now be filled with the details
|
|
3309 |
test(info.iEventType == EEventsBreakPoint);
|
|
3310 |
test(info.iThreadBreakPointInfo.iRmdArmExcInfo.iR15 == address);
|
|
3311 |
test(info.iProcessIdValid);
|
|
3312 |
test(info.iThreadIdValid);
|
|
3313 |
|
|
3314 |
// Continue the thread
|
|
3315 |
test(KErrNone == iServSession.ResumeThread(iThreadID));
|
|
3316 |
|
|
3317 |
//Now we try to hit the second breakpoint. This will occur after a number of trace calls. If we hit this breakpoint it
|
|
3318 |
//means many trace calls are not preventing us hitting breakpoints.
|
|
3319 |
iServSession.GetEvent(iFileName,status,infoPtr);
|
|
3320 |
|
|
3321 |
// Wait for notification of the 2nd breakpoint hit event
|
|
3322 |
User::WaitForRequest(status);
|
|
3323 |
test(status==KErrNone);
|
|
3324 |
|
|
3325 |
TBool receivedTracesLost = EFalse;
|
|
3326 |
|
|
3327 |
while(info.iEventType == EEventsUserTrace || info.iEventType == EEventsUserTracesLost)
|
|
3328 |
{
|
|
3329 |
//ensure we get told traces are being thrown away - we generate enough to flood the buffer
|
|
3330 |
if(info.iEventType == EEventsUserTracesLost)
|
|
3331 |
{
|
|
3332 |
receivedTracesLost = ETrue;
|
|
3333 |
}
|
|
3334 |
|
|
3335 |
iServSession.GetEvent(iFileName,status,infoPtr);
|
|
3336 |
|
|
3337 |
// Wait for notification of the 2nd breakpoint hit event
|
|
3338 |
User::WaitForRequest(status);
|
|
3339 |
test(status==KErrNone);
|
|
3340 |
}
|
|
3341 |
|
|
3342 |
//make sure we got told traces were lost
|
|
3343 |
test(receivedTracesLost != EFalse);
|
|
3344 |
|
|
3345 |
// info should now be filled with the details of our breakpoint.
|
|
3346 |
test(info.iEventType == EEventsBreakPoint);
|
|
3347 |
test(info.iThreadBreakPointInfo.iRmdArmExcInfo.iR15 == address2);
|
|
3348 |
test(info.iProcessIdValid);
|
|
3349 |
test(info.iThreadIdValid);
|
|
3350 |
|
|
3351 |
//dont care for breakpoints or trace events no more
|
|
3352 |
test(KErrNone == iServSession.SetEventAction(iFileName,EEventsBreakPoint, EActionIgnore));
|
|
3353 |
test(KErrNone == iServSession.SetEventAction(iFileName,EEventsUserTrace, EActionIgnore));
|
|
3354 |
test(KErrNone == iServSession.SetEventAction(iFileName,EEventsUserTracesLost, EActionIgnore));
|
|
3355 |
|
|
3356 |
//clear the breaks we set
|
|
3357 |
test(KErrNone == iServSession.ClearBreak(armBreakId));
|
|
3358 |
test(KErrNone == iServSession.ClearBreak(armBreakId2));
|
|
3359 |
|
|
3360 |
// Continue the thread
|
|
3361 |
test(KErrNone == iServSession.ResumeThread(iThreadID));
|
|
3362 |
|
|
3363 |
//attach to target debug process
|
|
3364 |
test(KErrNone == iServSession.DetachExecutable(iFileName));
|
|
3365 |
|
|
3366 |
}
|
|
3367 |
|
|
3368 |
//----------------------------------------------------------------------------------------------
|
|
3369 |
//! @SYMTestCaseID KBase-T-RMDEBUG2-2441
|
|
3370 |
//! @SYMTestType
|
|
3371 |
//! @SYMPREQ PREQ1426
|
|
3372 |
//! @SYMTestCaseDesc Test clearing of a process breakpoint once the process has been killed.
|
|
3373 |
//! @SYMTestActions Creates a new process then tries to set a process breakpoint and then kills the process which should clear the previously set breakpoint. Then repeat the step once again.
|
|
3374 |
//! @SYMTestExpectedResults KErrNone
|
|
3375 |
//! @SYMTestPriority High
|
|
3376 |
//! @SYMTestStatus Implemented
|
|
3377 |
//----------------------------------------------------------------------------------------------
|
|
3378 |
|
|
3379 |
void CRunModeAgent::TestProcessKillBreakpoint(void)
|
|
3380 |
{
|
|
3381 |
//Dont run the test for an SMP System
|
|
3382 |
if (UserSvr::HalFunction(EHalGroupKernel, EKernelHalSmpSupported, 0, 0) == KErrNone)
|
|
3383 |
return;
|
|
3384 |
|
|
3385 |
test.Next(_L("TestProcessKillBreakpoint\n"));
|
|
3386 |
//SID retrieved, used in Define/Attach of the property
|
|
3387 |
iMySid.iUid = RProcess().SecureId();
|
|
3388 |
|
|
3389 |
static _LIT_SECURITY_POLICY_PASS(KAllowAllPolicy);
|
|
3390 |
|
|
3391 |
//define a property to pass on the address from the other process we would try to debug
|
|
3392 |
test ( KErrNone == RProperty::Define(iMySid, EMyPropertyInteger, RProperty::EInt, KAllowAllPolicy, KAllowAllPolicy));
|
|
3393 |
//define a global semaphore to synchronise with debuggable process publishing the property
|
|
3394 |
test ( KErrNone == iAddressGlobSem.CreateGlobal(_L("RMDebugGlobSem"), 0) );
|
|
3395 |
|
|
3396 |
DoTestProcessKillBreakpoint();
|
|
3397 |
// called once again
|
|
3398 |
// to check if we can set the breakpoint once again after the process gets killed
|
|
3399 |
DoTestProcessKillBreakpoint();
|
|
3400 |
|
|
3401 |
//delete the property
|
|
3402 |
test ( KErrNone == RProperty::Delete(iMySid, EMyPropertyInteger));
|
|
3403 |
//close the semaphore
|
|
3404 |
iAddressGlobSem.Close();
|
|
3405 |
}
|
|
3406 |
|
|
3407 |
void CRunModeAgent::DoTestProcessKillBreakpoint()
|
|
3408 |
{
|
|
3409 |
test.Printf(_L("\nDoTestProcessKillBreakpoint\n"));
|
|
3410 |
|
|
3411 |
TInt err = KErrNone;
|
|
3412 |
|
|
3413 |
// check that killing a process is supported
|
|
3414 |
TTag tag = GetTag(ETagHeaderIdKillObjects, EFunctionalityKillProcess);
|
|
3415 |
test(tag.iValue);
|
|
3416 |
// check that killing a thread is not supported
|
|
3417 |
tag = GetTag(ETagHeaderIdKillObjects, EFunctionalityKillThread);
|
|
3418 |
test(!tag.iValue);
|
|
3419 |
|
|
3420 |
// attach first!
|
|
3421 |
test ( KErrNone == iServSession.AttachExecutable(KRMDebugTestApplication, EFalse/* Active */));
|
|
3422 |
|
|
3423 |
// first launch a debuggable process
|
|
3424 |
RProcess processDebug;
|
|
3425 |
test ( KErrNone == LaunchProcess(processDebug, KRMDebugTestApplication(),ESpinForeverWithBreakPoint, 0, 0));
|
|
3426 |
|
|
3427 |
// try to find the process in the list
|
|
3428 |
_LIT(KRMDebugAppName, "t_rmdebug_app");
|
|
3429 |
TBool found = ProcessExists(KRMDebugAppName);
|
|
3430 |
test (found);
|
|
3431 |
|
|
3432 |
//search for the main thread created
|
|
3433 |
_LIT(KThreadWildCard, "t_rmdebug_app*");
|
|
3434 |
TProcessId processDebugId = processDebug.Id();
|
|
3435 |
TThreadId threadDebugId;
|
|
3436 |
|
|
3437 |
TFindThread find(KThreadWildCard);
|
|
3438 |
TFullName name;
|
|
3439 |
found = EFalse;
|
|
3440 |
while(find.Next(name)==KErrNone && !found)
|
|
3441 |
{
|
|
3442 |
RThread thread;
|
|
3443 |
err = thread.Open(find);
|
|
3444 |
if (err == KErrNone)
|
|
3445 |
{
|
|
3446 |
RProcess process;
|
|
3447 |
thread.Process(process);
|
|
3448 |
if (((TUint32)process.Id() == processDebugId))
|
|
3449 |
{
|
|
3450 |
TFullName fullname = thread.FullName();
|
|
3451 |
test.Printf(_L("Match Found Name %lS Process ID%ld Thread Id %ld"), &fullname, process.Id().Id(), thread.Id().Id());
|
|
3452 |
found = ETrue;
|
|
3453 |
threadDebugId = thread.Id();
|
|
3454 |
}
|
|
3455 |
process.Close();
|
|
3456 |
}
|
|
3457 |
thread.Close();
|
|
3458 |
}
|
|
3459 |
|
|
3460 |
test (found); //check if we actually found the thread we want to debug
|
|
3461 |
|
|
3462 |
//get the value(property) for the breakpoint address for the process to debug
|
|
3463 |
TInt address;
|
|
3464 |
RProperty integerProperty;
|
|
3465 |
test ( KErrNone == integerProperty.Attach(iMySid, EMyPropertyInteger, EOwnerThread));
|
|
3466 |
|
|
3467 |
//waiting on semaphore to be sure that the property is set
|
|
3468 |
iAddressGlobSem.Wait();
|
|
3469 |
|
|
3470 |
test ( KErrNone == integerProperty.Get(address));
|
|
3471 |
integerProperty.Close();
|
|
3472 |
|
|
3473 |
test.Printf(_L("Address retrieved to set breakpoint 0x%8x"), address);
|
|
3474 |
|
|
3475 |
//suspend the thread before we set a breakpoint
|
|
3476 |
test ( KErrNone == iServSession.SuspendThread(threadDebugId));
|
|
3477 |
|
|
3478 |
//set a process breakpoint
|
|
3479 |
TBreakId breakId;
|
|
3480 |
test(KErrNone == iServSession.SetProcessBreak(breakId, processDebugId, address, EArmMode));
|
|
3481 |
|
|
3482 |
test(KErrNone ==iServSession.SetEventAction(KRMDebugTestApplication,EEventsProcessBreakPoint, EActionContinue));
|
|
3483 |
|
|
3484 |
//resume the thread now
|
|
3485 |
test(KErrNone == iServSession.ResumeThread(threadDebugId));
|
|
3486 |
|
|
3487 |
// wait for the breakpoint to be hit
|
|
3488 |
static TRequestStatus status;
|
|
3489 |
TEventInfo info;
|
|
3490 |
TPtr8 infoPtr((TUint8*)&info,0,sizeof(TEventInfo));
|
|
3491 |
iServSession.GetEvent(KRMDebugTestApplication,status,infoPtr);
|
|
3492 |
// Wait for notification of the breakpoint hit event
|
|
3493 |
User::WaitForRequest(status);
|
|
3494 |
test(status==KErrNone);
|
|
3495 |
|
|
3496 |
// info should now be filled with the details
|
|
3497 |
test(info.iEventType == EEventsProcessBreakPoint);
|
|
3498 |
test(info.iThreadBreakPointInfo.iRmdArmExcInfo.iR15 == address);
|
|
3499 |
test(info.iProcessIdValid);
|
|
3500 |
test(info.iThreadIdValid);
|
|
3501 |
|
|
3502 |
// Not interested in breakpoint events any more
|
|
3503 |
test(KErrNone == iServSession.SetEventAction(KRMDebugTestApplication, EEventsProcessBreakPoint, EActionIgnore));
|
|
3504 |
|
|
3505 |
// program now running, so try to kill it which should clear all the breakpoints
|
|
3506 |
test(KErrNone == iServSession.KillProcess(processDebugId, 0 /* kill reason */ ));
|
|
3507 |
|
|
3508 |
processDebug.Close();
|
|
3509 |
User::After(2000000); // should die within two seconds.
|
|
3510 |
|
|
3511 |
// can we still find it? Should be gone
|
|
3512 |
found = ProcessExists(KRMDebugAppName);
|
|
3513 |
test (!found);
|
|
3514 |
|
|
3515 |
// release the program again
|
|
3516 |
test(KErrNone == iServSession.DetachExecutable(KRMDebugTestApplication));
|
|
3517 |
|
|
3518 |
}
|
|
3519 |
|
|
3520 |
void CRunModeAgent::HelpTestSecurityAttachDetachExecutable(const TDesC& aProcessName, TBool aExpectSuccess)
|
|
3521 |
{
|
|
3522 |
RProcess process;
|
|
3523 |
TInt err = process.Create(aProcessName, KNullDesC, EOwnerProcess);
|
|
3524 |
test (err == KErrNone);
|
|
3525 |
|
|
3526 |
// rendezvous with process
|
|
3527 |
TRequestStatus status;
|
|
3528 |
process.Rendezvous(status);
|
|
3529 |
|
|
3530 |
// start the test program
|
|
3531 |
process.Resume();
|
|
3532 |
User::WaitForRequest(status);
|
|
3533 |
test(status==KErrNone);
|
|
3534 |
|
|
3535 |
// attach to the program (passively)
|
|
3536 |
err = iServSession.AttachExecutable(aProcessName, EFalse);
|
|
3537 |
|
|
3538 |
// Do we expect to successfully attach
|
|
3539 |
if (aExpectSuccess)
|
|
3540 |
{
|
|
3541 |
// Yes
|
|
3542 |
test(KErrNone == err);
|
|
3543 |
|
|
3544 |
// Now detach again
|
|
3545 |
test(KErrNone == iServSession.DetachExecutable(aProcessName));
|
|
3546 |
}
|
|
3547 |
else
|
|
3548 |
{
|
|
3549 |
// No
|
|
3550 |
test(KErrPermissionDenied == err);
|
|
3551 |
|
|
3552 |
// Just to be sure, try active attachment
|
|
3553 |
test(KErrPermissionDenied == iServSession.AttachExecutable(aProcessName, ETrue));
|
|
3554 |
}
|
|
3555 |
|
|
3556 |
// Kill the process, as we don't need it anymore
|
|
3557 |
process.Kill(KErrNone);
|
|
3558 |
}
|
|
3559 |
|
|
3560 |
void CRunModeAgent::ReportPerformance(void)
|
|
3561 |
//
|
|
3562 |
// Reports performance metrics from all the tests
|
|
3563 |
//
|
|
3564 |
{
|
|
3565 |
test.Printf(_L("\nPerformance\n"));
|
|
3566 |
test.Printf(_L("========================\n"));
|
|
3567 |
|
|
3568 |
// Memory
|
|
3569 |
test.Printf(_L("Memory read: %d KBytes/sec\n"),iMemoryReadKbytesPerSecond);
|
|
3570 |
test.Printf(_L("Memory write: %d KBytes/sec\n"),iMemoryWriteKbytesPerSecond);
|
|
3571 |
|
|
3572 |
// Registers
|
|
3573 |
// to do
|
|
3574 |
|
|
3575 |
// events
|
|
3576 |
// to do
|
|
3577 |
|
|
3578 |
// Breakpoints
|
|
3579 |
test.Printf(_L("Breakpoint set/clear: %d/sec\n"),iBreakpointsPerSecond);
|
|
3580 |
test.Printf(_L("Maximum number of breakpoints: %d\n"),iMaxBreakpoints);
|
|
3581 |
|
|
3582 |
// Stepping
|
|
3583 |
test.Printf(_L("Stepping speed: %d/sec\n"),iStepsPerSecond);
|
|
3584 |
|
|
3585 |
// Runtime
|
|
3586 |
TInt ticks = HelpGetTestTicks();
|
|
3587 |
test (ticks != 0);
|
|
3588 |
|
|
3589 |
TInt nkTicksPerSecond = HelpTicksPerSecond();
|
|
3590 |
test (nkTicksPerSecond != 0);
|
|
3591 |
|
|
3592 |
test.Printf(_L("Total test runtime: %d seconds\n"),ticks/nkTicksPerSecond);
|
|
3593 |
|
|
3594 |
// Final sizes of executables/rom/ram etc
|
|
3595 |
// to do
|
|
3596 |
|
|
3597 |
test.Printf(_L("\n"));
|
|
3598 |
}
|
|
3599 |
|
|
3600 |
/**
|
|
3601 |
* Helper code for the stepping tests. Sets a breakpoint in a running thread.
|
|
3602 |
* It suspends the thread, sets the breakpoint, and resumes the thread.
|
|
3603 |
*
|
|
3604 |
* @param aBreakId - Reference to a TBreakId which will be set when the breakpoint is set
|
|
3605 |
* @param aThreadId - The thread id for which we should set the breakpoint.
|
|
3606 |
* @param aBreakAddress - The address to set the breakpoint
|
|
3607 |
* @param aMode - The architecture of the breakpoint to be set (ARM/Thumb/Thumb2EE)
|
|
3608 |
* @return KErrNone if successful. One of the other system wide error codes otherwise.
|
|
3609 |
*/
|
|
3610 |
TInt CRunModeAgent::HelpTestStepSetBreak(TBreakId& aBreakId, TThreadId aThreadId, const TUint32 aBreakAddress, TArchitectureMode aMode, TBool aThreadSpecific, TProcessId aProcessId)
|
|
3611 |
{
|
|
3612 |
TInt err = KErrNone;
|
|
3613 |
|
|
3614 |
// Suspend the thread
|
|
3615 |
err = iServSession.SuspendThread(aThreadId);
|
|
3616 |
if (err != KErrNone)
|
|
3617 |
{
|
|
3618 |
test.Printf(_L("HelpTestStepSetBreak - Failed to suspend thread\n"));
|
|
3619 |
return err;
|
|
3620 |
}
|
|
3621 |
|
|
3622 |
// Set the breakpoint
|
|
3623 |
err = aThreadSpecific
|
|
3624 |
? iServSession.SetBreak(aBreakId,aThreadId,aBreakAddress,aMode)
|
|
3625 |
: iServSession.SetProcessBreak(aBreakId, aProcessId, aBreakAddress, aMode);
|
|
3626 |
if (err != KErrNone)
|
|
3627 |
{
|
|
3628 |
test.Printf(_L("HelpTestStepSetBreak - Failed to set breakpoint\n"));
|
|
3629 |
return err;
|
|
3630 |
}
|
|
3631 |
|
|
3632 |
// Continue the thread
|
|
3633 |
err = iServSession.ResumeThread(aThreadId);
|
|
3634 |
if (err != KErrNone)
|
|
3635 |
{
|
|
3636 |
test.Printf(_L("HelpTestStepSetBreak - Failed to resume thread\n"));
|
|
3637 |
return err;
|
|
3638 |
}
|
|
3639 |
|
|
3640 |
return KErrNone;
|
|
3641 |
}
|
|
3642 |
|
|
3643 |
/**
|
|
3644 |
* Helper code for the stepping tests. Clears a breakpoint in a running thread.
|
|
3645 |
* It suspends the thread, clears the breakpoint, and resumes the thread.
|
|
3646 |
*
|
|
3647 |
* @param aBreakId - Reference to a TBreakId which will be set when the breakpoint is set
|
|
3648 |
* @return KErrNone if successful. One of the other system wide error codes otherwise.
|
|
3649 |
*/
|
|
3650 |
TInt CRunModeAgent::HelpTestStepClearBreak(TBreakId aBreakId, const TThreadId aThreadId, TBool aThreadSpecific)
|
|
3651 |
{
|
|
3652 |
TInt err = KErrNone;
|
|
3653 |
|
|
3654 |
// Find out what thread id we need to suspend
|
|
3655 |
TThreadId threadId;
|
|
3656 |
TProcessId processId;
|
|
3657 |
TUint32 address;
|
|
3658 |
TArchitectureMode mode;
|
|
3659 |
|
|
3660 |
err = aThreadSpecific
|
|
3661 |
? iServSession.BreakInfo(aBreakId, threadId, address, mode)
|
|
3662 |
: iServSession.ProcessBreakInfo(aBreakId, processId, address, mode);
|
|
3663 |
if (err != KErrNone )
|
|
3664 |
{
|
|
3665 |
test.Printf(_L("HelpTestStepClearBreak - failed to obtain information for breakpoint\n"));
|
|
3666 |
return err;
|
|
3667 |
}
|
|
3668 |
if(aThreadSpecific && aThreadId != threadId)
|
|
3669 |
{
|
|
3670 |
test.Printf(_L("HelpTestStepClearBreak - mismatched thread Ids\n"));
|
|
3671 |
return KErrGeneral;
|
|
3672 |
}
|
|
3673 |
|
|
3674 |
// Suspend the thread
|
|
3675 |
err = iServSession.SuspendThread(aThreadId);
|
|
3676 |
if (!(err == KErrNone || err == KErrAlreadyExists))
|
|
3677 |
{
|
|
3678 |
test.Printf(_L("HelpTestStepClearBreak - failed to suspend thread\n"));
|
|
3679 |
return err;
|
|
3680 |
}
|
|
3681 |
|
|
3682 |
// Clear the breakpoint
|
|
3683 |
err = iServSession.ClearBreak(aBreakId);
|
|
3684 |
if (err != KErrNone)
|
|
3685 |
{
|
|
3686 |
test.Printf(_L("HelpTestStepClearBreak - failed to clear breakpoint\n"));
|
|
3687 |
return err;
|
|
3688 |
}
|
|
3689 |
|
|
3690 |
// Continue the thread
|
|
3691 |
err = iServSession.ResumeThread(aThreadId);
|
|
3692 |
if (!(err == KErrNone || err == KErrNotFound))
|
|
3693 |
{
|
|
3694 |
test.Printf(_L("HelpTestStepClearBreak - failed to resume thread\n"));
|
|
3695 |
return err;
|
|
3696 |
}
|
|
3697 |
|
|
3698 |
return KErrNone;
|
|
3699 |
}
|
|
3700 |
|
|
3701 |
/**
|
|
3702 |
* Helper code for the stepping tests. Waits for a previously set breakpoint to be hit.
|
|
3703 |
*
|
|
3704 |
* @param aProcessName - The name of the process in which the breakpoint is set. E.g. z:\sys\bin\app.exe
|
|
3705 |
* @param aEventInfo - The event information block which is filled in when the breakpoint is hit.
|
|
3706 |
* @return KErrNone if successful. One of the other system wide error codes otherwise.
|
|
3707 |
*/
|
|
3708 |
TInt CRunModeAgent::HelpTestStepWaitForBreak(const TDesC& aProcessName, TEventInfo& aEventInfo)
|
|
3709 |
{
|
|
3710 |
static TRequestStatus status;
|
|
3711 |
|
|
3712 |
TPtr8 infoPtr((TUint8*)&aEventInfo,0,sizeof(TEventInfo));
|
|
3713 |
|
|
3714 |
iServSession.GetEvent(aProcessName,status,infoPtr);
|
|
3715 |
|
|
3716 |
// Wait for notification of the breakpoint hit event
|
|
3717 |
User::WaitForRequest(status);
|
|
3718 |
if (status == KErrNone)
|
|
3719 |
{
|
|
3720 |
return KErrNone;
|
|
3721 |
}
|
|
3722 |
else
|
|
3723 |
{
|
|
3724 |
return KErrGeneral;
|
|
3725 |
}
|
|
3726 |
}
|
|
3727 |
|
|
3728 |
/**
|
|
3729 |
* Helper code for the stepping tests. Reads the current target PC for a given thread.
|
|
3730 |
*
|
|
3731 |
* @param aThreadId - Thread id for which to read the current target PC.
|
|
3732 |
* @param aPc - Reference to a TUint32 which will be set to the current target PC.
|
|
3733 |
* @return KErrNone if successful. One of the other system wide error codes otherwise.
|
|
3734 |
*/
|
|
3735 |
TInt CRunModeAgent::HelpTestStepReadPC(TThreadId aThreadId, TUint32& aPC)
|
|
3736 |
{
|
|
3737 |
TInt err = KErrNone;
|
|
3738 |
|
|
3739 |
//create buffer containing PC register ID
|
|
3740 |
RBuf8 pcId;
|
|
3741 |
err = pcId.Create(sizeof(TRegisterInfo));
|
|
3742 |
if (err != KErrNone)
|
|
3743 |
{
|
|
3744 |
return err;
|
|
3745 |
}
|
|
3746 |
|
|
3747 |
TRegisterInfo reg1 = (TRegisterInfo)0x00000f00;
|
|
3748 |
pcId.Append(reinterpret_cast<const TUint8*>(®1), sizeof(TRegisterInfo));
|
|
3749 |
|
|
3750 |
//create buffer containing desired PC value
|
|
3751 |
TPtr8 pcValue((TUint8*)&aPC,4,4);
|
|
3752 |
|
|
3753 |
//create buffer for PC flag value
|
|
3754 |
RBuf8 pcFlag;
|
|
3755 |
err = pcFlag.Create(sizeof(TUint8));
|
|
3756 |
|
|
3757 |
//read the new PC value
|
|
3758 |
err = iServSession.ReadRegisters(aThreadId, pcId, pcValue, pcFlag);
|
|
3759 |
if (err != KErrNone)
|
|
3760 |
{
|
|
3761 |
//delete temporary buffers
|
|
3762 |
pcId.Close();
|
|
3763 |
pcFlag.Close();
|
|
3764 |
return err;
|
|
3765 |
}
|
|
3766 |
|
|
3767 |
//get the flag and check the PC value was read ok
|
|
3768 |
TRegisterFlag flag = ENotSupported;
|
|
3769 |
err = GetFlag(pcFlag, 0, flag);
|
|
3770 |
if (err != KErrNone)
|
|
3771 |
{
|
|
3772 |
//delete temporary buffers
|
|
3773 |
pcId.Close();
|
|
3774 |
pcFlag.Close();
|
|
3775 |
return err;
|
|
3776 |
}
|
|
3777 |
|
|
3778 |
if (flag == EValid)
|
|
3779 |
{
|
|
3780 |
//delete temporary buffers
|
|
3781 |
pcId.Close();
|
|
3782 |
pcFlag.Close();
|
|
3783 |
return KErrNone;
|
|
3784 |
}
|
|
3785 |
else
|
|
3786 |
{
|
|
3787 |
//delete temporary buffers
|
|
3788 |
pcId.Close();
|
|
3789 |
pcFlag.Close();
|
|
3790 |
return err;
|
|
3791 |
}
|
|
3792 |
}
|
|
3793 |
|
|
3794 |
/**
|
|
3795 |
* Helper code for the stepping tests. Single steps a given thread from aStartAddress to aEndAddress. Note
|
|
3796 |
* that it reaches aStartAddress by setting a breakpoint at that address and waiting until it is hit.
|
|
3797 |
*
|
|
3798 |
* @param aThreadId - Thread id for which to read the current target PC.
|
|
3799 |
* @param aStartAddress - The target address at which stepping will start.
|
|
3800 |
* @param aEndAddress - The target address at which stepping will end.
|
|
3801 |
* @param aMode - The architecture of the breakpoint which must be set at the start address (ARM/Thumb/Thumb2EE).
|
|
3802 |
* @return KErrNone if successful. One of the other system wide error codes otherwise.
|
|
3803 |
*/
|
|
3804 |
TInt CRunModeAgent::HelpTestStep(TThreadId aThreadId, TUint32 aStartAddress, TUint32 aEndAddress, TArchitectureMode aMode, TUint aNumSteps, TBool aThreadSpecific, TProcessId aProcessId)
|
|
3805 |
{
|
|
3806 |
TInt err = KErrNone;
|
|
3807 |
|
|
3808 |
// Ensure that the supplied addresses are word/half-word aligned as appropriate.
|
|
3809 |
if (aMode == EArmMode)
|
|
3810 |
{
|
|
3811 |
// ARM breakpoints must be word-aligned (2 lsb must be zero)
|
|
3812 |
aStartAddress &= 0xFFFFFFFC;
|
|
3813 |
aEndAddress &= 0xFFFFFFFC;
|
|
3814 |
}
|
|
3815 |
else if (aMode == EThumbMode)
|
|
3816 |
{
|
|
3817 |
// Thumb breakpoints must be half-word aligned (lsb must be zero)
|
|
3818 |
aStartAddress &= 0xFFFFFFFE;
|
|
3819 |
aEndAddress &= 0xFFFFFFFE;
|
|
3820 |
}
|
|
3821 |
else if (aMode == EThumb2EEMode)
|
|
3822 |
{
|
|
3823 |
// Thumb2EE breakpoints are not currently supported
|
|
3824 |
return KErrNotSupported;
|
|
3825 |
}
|
|
3826 |
|
|
3827 |
// Set breakpoint at the start address
|
|
3828 |
TBreakId tempBreakId;
|
|
3829 |
TEventInfo info;
|
|
3830 |
|
|
3831 |
err = HelpTestStepSetBreak(tempBreakId,aThreadId,aStartAddress,aMode,aThreadSpecific,aProcessId);
|
|
3832 |
if (err != KErrNone)
|
|
3833 |
{
|
|
3834 |
test.Printf(_L("HelpTestStep - Failed to set breakpoint at aStartAddress 0x%08x\n"),aStartAddress);
|
|
3835 |
return err;
|
|
3836 |
}
|
|
3837 |
|
|
3838 |
// wait for the breakpoint to be hit
|
|
3839 |
err = HelpTestStepWaitForBreak(iFileName,info);
|
|
3840 |
if (err != KErrNone)
|
|
3841 |
{
|
|
3842 |
test.Printf(_L("HelpTestStep - Failed to hit the breakpoint at aStartAddress 0x%08x\n"),aStartAddress);
|
|
3843 |
return err;
|
|
3844 |
}
|
|
3845 |
|
|
3846 |
// Check the PC == aStartAddress
|
|
3847 |
TUint32 pc = 0;
|
|
3848 |
err = HelpTestStepReadPC(aThreadId,pc);
|
|
3849 |
if (err != KErrNone)
|
|
3850 |
{
|
|
3851 |
test.Printf(_L("HelpTestStep - Failed to read the PC after hitting breakpoint at aStartAddress 0x%08x\n"),aStartAddress);
|
|
3852 |
return err;
|
|
3853 |
}
|
|
3854 |
|
|
3855 |
if (pc != aStartAddress)
|
|
3856 |
{
|
|
3857 |
test.Printf(_L("HelpTestStep - Incorrect PC value after hitting breakpoint (expected 0x%08x actual 0x%08x)\n"),aStartAddress,pc);
|
|
3858 |
return KErrGeneral;
|
|
3859 |
}
|
|
3860 |
|
|
3861 |
err = iServSession.Step(aThreadId,aNumSteps);
|
|
3862 |
if (err != KErrNone)
|
|
3863 |
{
|
|
3864 |
test.Printf(_L("HelpTestStep - Failed to do step from 0x%08x to 0x%08x\n"),aStartAddress,aEndAddress,aNumSteps);
|
|
3865 |
return err;
|
|
3866 |
}
|
|
3867 |
|
|
3868 |
// only one 'completed step' event in the buffer.
|
|
3869 |
err = HelpTestStepWaitForBreak(iFileName,info);
|
|
3870 |
if (err != KErrNone)
|
|
3871 |
{
|
|
3872 |
test.Printf(_L("HelpTestStep - Could not read breakpoint event info after stepping"));
|
|
3873 |
return err;
|
|
3874 |
}
|
|
3875 |
// end
|
|
3876 |
|
|
3877 |
// Check PC == aEndAddress
|
|
3878 |
err = HelpTestStepReadPC(aThreadId,pc);
|
|
3879 |
if (err != KErrNone)
|
|
3880 |
{
|
|
3881 |
test.Printf(_L("HelpTestStep - failed read the PC after stepping\n"));
|
|
3882 |
return err;
|
|
3883 |
}
|
|
3884 |
if (pc != aEndAddress)
|
|
3885 |
{
|
|
3886 |
test.Printf(_L("HelpTestStep - Incorrect PC value after stepping (expected 0x%08x actual 0x%08x)\n"),aEndAddress,pc);
|
|
3887 |
return KErrGeneral;
|
|
3888 |
}
|
|
3889 |
|
|
3890 |
// Clear the breakpoint
|
|
3891 |
err = HelpTestStepClearBreak(tempBreakId, aThreadId, aThreadSpecific);
|
|
3892 |
if (err != KErrNone)
|
|
3893 |
{
|
|
3894 |
test.Printf(_L("HelpTestStep - failed to clear temporary breakpoint\n"));
|
|
3895 |
return err;
|
|
3896 |
}
|
|
3897 |
|
|
3898 |
return KErrNone;
|
|
3899 |
}
|
|
3900 |
|
|
3901 |
/**
|
|
3902 |
* Helper code for the stepping tests. Returns the number of nanokernel ticks in one second.
|
|
3903 |
*
|
|
3904 |
* @return Number of nanokernel ticks. 0 if unsuccesful.
|
|
3905 |
*/
|
|
3906 |
TInt CRunModeAgent::HelpTicksPerSecond(void)
|
|
3907 |
{
|
|
3908 |
TInt nanokernel_tick_period;
|
|
3909 |
HAL::Get(HAL::ENanoTickPeriod, nanokernel_tick_period);
|
|
3910 |
|
|
3911 |
ASSERT(nanokernel_tick_period != 0);
|
|
3912 |
|
|
3913 |
static const TInt KOneMillion = 1000000;
|
|
3914 |
|
|
3915 |
return KOneMillion/nanokernel_tick_period;
|
|
3916 |
}
|
|
3917 |
|
|
3918 |
/**
|
|
3919 |
Given aTestNumber runs the appropriate test inside heap markers
|
|
3920 |
|
|
3921 |
@param aTestNumber test to run, corresponds to an entry in iTestArray
|
|
3922 |
|
|
3923 |
@panic Panic if aTestNumber is not in valid range
|
|
3924 |
*/
|
|
3925 |
void CRunModeAgent::RunTest(TInt aTestNumber)
|
|
3926 |
{
|
|
3927 |
if( (aTestNumber<0) || (aTestNumber>=KMaxTests) )
|
|
3928 |
{
|
|
3929 |
User::Panic(_L("Test number out of range"), aTestNumber);
|
|
3930 |
}
|
|
3931 |
__UHEAP_MARK;
|
|
3932 |
(this->*(iTestArray[aTestNumber].iFunctionPtr))();
|
|
3933 |
__UHEAP_MARKEND;
|
|
3934 |
}
|
|
3935 |
|
|
3936 |
void CRunModeAgent::PrintVersion()
|
|
3937 |
{
|
|
3938 |
test.Printf(_L("\nt_rmdebug2.exe\nVersion: %S\n"), &(testVersion.Name()));
|
|
3939 |
test.Printf(_L("Press any key...\n"));
|
|
3940 |
test.Getch();
|
|
3941 |
}
|
|
3942 |
|
|
3943 |
void CRunModeAgent::PrintUsage()
|
|
3944 |
{
|
|
3945 |
test.Printf(_L("Invoke with arguments:\n"));
|
|
3946 |
test.Printf(_L("-r: run specified tests in reverse order\n"));
|
|
3947 |
test.Printf(_L("-h: display usage information\n"));
|
|
3948 |
test.Printf(_L("-v: display version\n"));
|
|
3949 |
test.Printf(_L("<number>: test number to run, can specify more than one from the following list:\n"));
|
|
3950 |
test.Printf(_L("Press any key for list...\n"));
|
|
3951 |
test.Getch();
|
|
3952 |
// if there are too many of these they won't fit on the screen! Stick another Getch() in if there get too many
|
|
3953 |
for(TInt i=0; i<KMaxTests; i++)
|
|
3954 |
{
|
|
3955 |
test.Printf(_L("%2d: %S\n"), i, &(iTestArray[i].iFunctionName));
|
|
3956 |
}
|
|
3957 |
test.Printf(_L("Press any key...\n"));
|
|
3958 |
test.Getch();
|
|
3959 |
}
|
|
3960 |
|
|
3961 |
/**
|
|
3962 |
Parse the command line, see CRunModeAgent::PrintUsage for syntax
|
|
3963 |
*/
|
|
3964 |
void CRunModeAgent::ParseCommandLineL(TUint32& aMode, RArray<TInt>& aTests)
|
|
3965 |
{
|
|
3966 |
// get the length of the command line arguments
|
|
3967 |
TInt argc = User::CommandLineLength();
|
|
3968 |
|
|
3969 |
// allocate a buffer for the command line arguments and extract the data to it
|
|
3970 |
HBufC* commandLine = HBufC::NewLC(argc);
|
|
3971 |
TPtr commandLineBuffer = commandLine->Des();
|
|
3972 |
User::CommandLine(commandLineBuffer);
|
|
3973 |
|
|
3974 |
// reset mode
|
|
3975 |
aMode = (TTestMode)0;
|
|
3976 |
|
|
3977 |
// create a lexer and read through the command line
|
|
3978 |
TLex lex(*commandLine);
|
|
3979 |
while (!lex.Eos())
|
|
3980 |
{
|
|
3981 |
// expecting the first character to be a '-'
|
|
3982 |
if (lex.Get() == '-')
|
|
3983 |
{
|
|
3984 |
TChar arg = lex.Get();
|
|
3985 |
switch (arg)
|
|
3986 |
{
|
|
3987 |
case 'v':
|
|
3988 |
//print out the help
|
|
3989 |
aMode |= EModeVersion;
|
|
3990 |
break;
|
|
3991 |
case 'h':
|
|
3992 |
//print out the help
|
|
3993 |
aMode |= EModeHelp;
|
|
3994 |
break;
|
|
3995 |
case 'r':
|
|
3996 |
//store the fact that we want to run in reverse
|
|
3997 |
aMode |= EModeReverse;
|
|
3998 |
break;
|
|
3999 |
default:
|
|
4000 |
// unknown argument so leave
|
|
4001 |
User::Leave(KErrArgument);
|
|
4002 |
}
|
|
4003 |
}
|
|
4004 |
else
|
|
4005 |
{
|
|
4006 |
lex.UnGet();
|
|
4007 |
TInt testNumber;
|
|
4008 |
User::LeaveIfError(lex.Val(testNumber));
|
|
4009 |
if( (testNumber<0) || (testNumber>=KMaxTests) )
|
|
4010 |
{
|
|
4011 |
User::Leave(KErrArgument);
|
|
4012 |
}
|
|
4013 |
aTests.AppendL(testNumber);
|
|
4014 |
}
|
|
4015 |
lex.SkipSpace();
|
|
4016 |
}
|
|
4017 |
// if no tests specified then run them all
|
|
4018 |
if(aTests.Count() == 0)
|
|
4019 |
{
|
|
4020 |
aMode |= EModeAll;
|
|
4021 |
}
|
|
4022 |
|
|
4023 |
// do clean up
|
|
4024 |
CleanupStack::PopAndDestroy(commandLine);
|
|
4025 |
}
|
|
4026 |
|
|
4027 |
void CRunModeAgent::ClientAppL()
|
|
4028 |
//
|
|
4029 |
// Performs each test in turn
|
|
4030 |
//
|
|
4031 |
{
|
|
4032 |
test.Start(_L("ClientAppL"));
|
|
4033 |
|
|
4034 |
RArray<TInt> testsToRun;
|
|
4035 |
TUint32 testMode = 0;
|
|
4036 |
ParseCommandLineL(testMode, testsToRun);
|
|
4037 |
|
|
4038 |
//if help or version mode specified then just print out the relevant stuff and quit
|
|
4039 |
if((testMode & EModeHelp) || (testMode & EModeVersion))
|
|
4040 |
{
|
|
4041 |
if(testMode & EModeHelp)
|
|
4042 |
{
|
|
4043 |
PrintUsage();
|
|
4044 |
}
|
|
4045 |
if(testMode & EModeVersion)
|
|
4046 |
{
|
|
4047 |
PrintVersion();
|
|
4048 |
}
|
|
4049 |
test.End();
|
|
4050 |
return;
|
|
4051 |
}
|
|
4052 |
|
|
4053 |
if(testMode & EModeAll)
|
|
4054 |
{
|
|
4055 |
for(TInt i=0; i<KMaxTests; i++)
|
|
4056 |
{
|
|
4057 |
testsToRun.AppendL(i);
|
|
4058 |
}
|
|
4059 |
}
|
|
4060 |
|
|
4061 |
// if EModeReverse specified then reverse the array elements
|
|
4062 |
TInt numberOfTests = testsToRun.Count();
|
|
4063 |
if(testMode & EModeReverse)
|
|
4064 |
{
|
|
4065 |
for(TInt i=0; i<(numberOfTests>>1); i++)
|
|
4066 |
{
|
|
4067 |
TInt temp = testsToRun[i];
|
|
4068 |
testsToRun[i] = testsToRun[numberOfTests - (i+1)];
|
|
4069 |
testsToRun[numberOfTests - (i+1)] = temp;
|
|
4070 |
}
|
|
4071 |
}
|
|
4072 |
|
|
4073 |
__UHEAP_MARK;
|
|
4074 |
SetupAndAttachToDSS();
|
|
4075 |
__UHEAP_MARKEND;
|
|
4076 |
|
|
4077 |
HelpStartTestTimer();
|
|
4078 |
for(TInt i=0; i<numberOfTests; i++)
|
|
4079 |
{
|
|
4080 |
RunTest(testsToRun[i]);
|
|
4081 |
}
|
|
4082 |
testsToRun.Close();
|
|
4083 |
|
|
4084 |
HelpStopTestTimer();
|
|
4085 |
|
|
4086 |
ReportPerformance();
|
|
4087 |
|
|
4088 |
test.End();
|
|
4089 |
}
|
|
4090 |
|
|
4091 |
/**
|
|
4092 |
Fill the test array with pointers to each test.
|
|
4093 |
*/
|
|
4094 |
void CRunModeAgent::FillArray()
|
|
4095 |
{
|
|
4096 |
iTestArray[0].iFunctionPtr = &CRunModeAgent::TestDriverSecurity;
|
|
4097 |
iTestArray[0].iFunctionName = _L("TestDriverSecurity");
|
|
4098 |
iTestArray[1].iFunctionPtr = &CRunModeAgent::TestDllUsage;
|
|
4099 |
iTestArray[1].iFunctionName = _L("TestDllUsage");
|
|
4100 |
iTestArray[2].iFunctionPtr = &CRunModeAgent::TestSecurity;
|
|
4101 |
iTestArray[2].iFunctionName = _L("TestSecurity");
|
|
4102 |
iTestArray[3].iFunctionPtr = &CRunModeAgent::TestAttachExecutable;
|
|
4103 |
iTestArray[3].iFunctionName = _L("TestAttachExecutable");
|
|
4104 |
iTestArray[4].iFunctionPtr = &CRunModeAgent::TestGetExecutablesList;
|
|
4105 |
iTestArray[4].iFunctionName = _L("TestGetExecutablesList");
|
|
4106 |
iTestArray[5].iFunctionPtr = &CRunModeAgent::TestGetProcessList;
|
|
4107 |
iTestArray[5].iFunctionName = _L("TestGetProcessList");
|
|
4108 |
iTestArray[6].iFunctionPtr = &CRunModeAgent::TestGetXipLibrariesList;
|
|
4109 |
iTestArray[6].iFunctionName = _L("TestGetXipLibrariesList");
|
|
4110 |
iTestArray[7].iFunctionPtr = &CRunModeAgent::TestGetThreadList;
|
|
4111 |
iTestArray[7].iFunctionName = _L("TestGetThreadList");
|
|
4112 |
iTestArray[8].iFunctionPtr = &CRunModeAgent::TestGetCodeSegsList;
|
|
4113 |
iTestArray[8].iFunctionName = _L("TestGetCodeSegsList");
|
|
4114 |
iTestArray[9].iFunctionPtr = &CRunModeAgent::TestGetListInvalidData;
|
|
4115 |
iTestArray[9].iFunctionName = _L("TestGetListInvalidData");
|
|
4116 |
iTestArray[10].iFunctionPtr = &CRunModeAgent::TestMemoryAccess;
|
|
4117 |
iTestArray[10].iFunctionName = _L("TestMemoryAccess");
|
|
4118 |
iTestArray[11].iFunctionPtr = &CRunModeAgent::TestDebugFunctionality;
|
|
4119 |
iTestArray[11].iFunctionName = _L("TestDebugFunctionality");
|
|
4120 |
iTestArray[12].iFunctionPtr = &CRunModeAgent::TestSuspendResume;
|
|
4121 |
iTestArray[12].iFunctionName = _L("TestSuspendResume");
|
|
4122 |
iTestArray[13].iFunctionPtr = &CRunModeAgent::TestBreakPoints;
|
|
4123 |
iTestArray[13].iFunctionName = _L("TestBreakPoints");
|
|
4124 |
iTestArray[14].iFunctionPtr = &CRunModeAgent::TestModifyBreak;
|
|
4125 |
iTestArray[14].iFunctionName = _L("TestModifyBreak");
|
|
4126 |
iTestArray[15].iFunctionPtr = &CRunModeAgent::TestBreakInfo;
|
|
4127 |
iTestArray[15].iFunctionName = _L("TestBreakInfo");
|
|
4128 |
iTestArray[16].iFunctionPtr = &CRunModeAgent::TestRunToBreak;
|
|
4129 |
iTestArray[16].iFunctionName = _L("TestRunToBreak");
|
|
4130 |
iTestArray[17].iFunctionPtr = &CRunModeAgent::TestRegisterAccess;
|
|
4131 |
iTestArray[17].iFunctionName = _L("TestRegisterAccess");
|
|
4132 |
iTestArray[18].iFunctionPtr = &CRunModeAgent::TestStep;
|
|
4133 |
iTestArray[18].iFunctionName = _L("TestStep");
|
|
4134 |
iTestArray[19].iFunctionPtr = &CRunModeAgent::TestDemandPaging;
|
|
4135 |
iTestArray[19].iFunctionName = _L("TestDemandPaging");
|
|
4136 |
iTestArray[20].iFunctionPtr = &CRunModeAgent::TestEventsForExternalProcess;
|
|
4137 |
iTestArray[20].iFunctionName = _L("TestEventsForExternalProcess");
|
|
4138 |
iTestArray[21].iFunctionPtr = &CRunModeAgent::TestEvents;
|
|
4139 |
iTestArray[21].iFunctionName = _L("TestEvents");
|
|
4140 |
iTestArray[22].iFunctionPtr = &CRunModeAgent::TestKillProcess;
|
|
4141 |
iTestArray[22].iFunctionName = _L("TestKillProcess");
|
|
4142 |
iTestArray[23].iFunctionPtr = &CRunModeAgent::TestProcessBreakPoints;
|
|
4143 |
iTestArray[23].iFunctionName = _L("TestProcessBreakPoints");
|
|
4144 |
iTestArray[24].iFunctionPtr = &CRunModeAgent::TestMultipleTraceEvents;
|
|
4145 |
iTestArray[24].iFunctionName = _L("TestMultipleTraceEvents");
|
|
4146 |
iTestArray[25].iFunctionPtr = &CRunModeAgent::TestAddRemoveProcessEvents;
|
|
4147 |
iTestArray[25].iFunctionName = _L("TestAddRemoveProcessEvents");
|
|
4148 |
iTestArray[26].iFunctionPtr = &CRunModeAgent::TestCrashFlash;
|
|
4149 |
iTestArray[26].iFunctionName = _L("TestCrashFlash");
|
|
4150 |
iTestArray[27].iFunctionPtr = &CRunModeAgent::TestProcessKillBreakpoint;
|
|
4151 |
iTestArray[27].iFunctionName = _L("TestProcessKillBreakpoint");
|
|
4152 |
};
|
|
4153 |
|
|
4154 |
GLDEF_C TInt E32Main()
|
|
4155 |
//
|
|
4156 |
// Entry point for run mode debug driver test
|
|
4157 |
//
|
|
4158 |
{
|
|
4159 |
TInt ret = KErrNone;
|
|
4160 |
|
|
4161 |
// client
|
|
4162 |
CTrapCleanup* trap = CTrapCleanup::New();
|
|
4163 |
if (!trap)
|
|
4164 |
return KErrNoMemory;
|
|
4165 |
test.Title();
|
|
4166 |
RunModeAgent = CRunModeAgent::NewL();
|
|
4167 |
if (RunModeAgent != NULL)
|
|
4168 |
{
|
|
4169 |
__UHEAP_MARK;
|
|
4170 |
TRAP(ret,RunModeAgent->ClientAppL());
|
|
4171 |
__UHEAP_MARKEND;
|
|
4172 |
|
|
4173 |
delete RunModeAgent;
|
|
4174 |
}
|
|
4175 |
|
|
4176 |
delete trap;
|
|
4177 |
|
|
4178 |
return ret;
|
|
4179 |
}
|
|
4180 |
|
|
4181 |
/**
|
|
4182 |
Helper function to get the aOffset'th value from aFlags
|
|
4183 |
|
|
4184 |
@param aFlags descriptor containing TRegisterFlag type flags
|
|
4185 |
@param aOffset index of flag value to extract from aFlags
|
|
4186 |
@param aFlagValue the flag value if function returned successfully
|
|
4187 |
|
|
4188 |
@return KErrNone if value was read successfully, KErrTooBig if aOffset is
|
|
4189 |
greater than aFlags.Length()
|
|
4190 |
*/
|
|
4191 |
TInt CRunModeAgent::GetFlag(const TDes8& aFlags, const TUint aOffset, TRegisterFlag &aFlagValue) const
|
|
4192 |
{
|
|
4193 |
//get pointer to data
|
|
4194 |
const TUint8 *ptr = aFlags.Ptr();
|
|
4195 |
|
|
4196 |
//check aOffset is valid
|
|
4197 |
TUint length = aFlags.Length();
|
|
4198 |
if(aOffset >= length)
|
|
4199 |
return KErrTooBig;
|
|
4200 |
|
|
4201 |
//get flag value
|
|
4202 |
aFlagValue = (TRegisterFlag)ptr[aOffset];
|
|
4203 |
return KErrNone;
|
|
4204 |
}
|
|
4205 |
|
|
4206 |
/**
|
|
4207 |
Helper function to set the value of FunctionChooser in the target debug thread.
|
|
4208 |
|
|
4209 |
@param aTestFunction TTestFunction enum to set FunctionChooser to
|
|
4210 |
|
|
4211 |
@return KErrNone if the value was set correctly, or one of the other system wide error codes
|
|
4212 |
*/
|
|
4213 |
TInt CRunModeAgent::SwitchTestFunction(TTestFunction aTestFunction)
|
|
4214 |
{
|
|
4215 |
//suspend the target thread
|
|
4216 |
TInt suspendError = iServSession.SuspendThread(iThreadID);
|
|
4217 |
if(! ( (suspendError == KErrNone) || (suspendError == KErrAlreadyExists) ) )
|
|
4218 |
{
|
|
4219 |
//the thread is not suspended so exit
|
|
4220 |
return suspendError;
|
|
4221 |
}
|
|
4222 |
|
|
4223 |
//get the address of FunctionChooser
|
|
4224 |
TUint32 functionChooserAddress = (TUint32)&FunctionChooser;
|
|
4225 |
//put the new value for FunctionChooser into a descriptor
|
|
4226 |
TPtr8 functionBuf((TUint8*)&aTestFunction, sizeof(TTestFunction), sizeof(TTestFunction));
|
|
4227 |
//write the new value into the target thread
|
|
4228 |
TInt writeError = iServSession.WriteMemory(iThreadID, functionChooserAddress, sizeof(TTestFunction), functionBuf, EAccess32, EEndLE8);
|
|
4229 |
|
|
4230 |
if(KErrNone == suspendError)
|
|
4231 |
{
|
|
4232 |
//if this function suspended the target thread then we need to resume it
|
|
4233 |
TInt resumeError = iServSession.ResumeThread(iThreadID);
|
|
4234 |
if(KErrNone != resumeError)
|
|
4235 |
{
|
|
4236 |
//resuming failed so return the error
|
|
4237 |
return resumeError;
|
|
4238 |
}
|
|
4239 |
}
|
|
4240 |
|
|
4241 |
//suspending and resuming was successful so return the error code from the WriteMemory call
|
|
4242 |
return writeError;
|
|
4243 |
}
|
|
4244 |
|
|
4245 |
/**
|
|
4246 |
Launch a separate process to debug.
|
|
4247 |
|
|
4248 |
@param aProcess the RProcess object to use to create the process
|
|
4249 |
@param aFileName file name of the executable to create the process from
|
|
4250 |
@param aFunctionType function that the target process should call on execution
|
|
4251 |
@param aDelay delay before the new process should call the function represented by aFunctionType
|
|
4252 |
@param aExtraThreads number of extra threads to create in the child process
|
|
4253 |
|
|
4254 |
@return KErrNone on success, or one of the other system wide error codes
|
|
4255 |
*/
|
|
4256 |
TInt CRunModeAgent::LaunchProcess(RProcess& aProcess, const TDesC& aFileName, TDebugFunctionType aFunctionType, TUint32 aDelay, TUint32 aExtraThreads)
|
|
4257 |
{
|
|
4258 |
// at the moment we support two arguments, this number might have to be increased to support arguments
|
|
4259 |
const TUint KMaxCommandLineLength = 32;
|
|
4260 |
|
|
4261 |
// create a command line buffer
|
|
4262 |
RBuf commandLine;
|
|
4263 |
commandLine.Create(KMaxCommandLineLength);
|
|
4264 |
|
|
4265 |
// append the command line arguments to the buffer
|
|
4266 |
_LIT(KFArg, "-f");
|
|
4267 |
commandLine.Append(KFArg());
|
|
4268 |
commandLine.AppendNum(aFunctionType);
|
|
4269 |
|
|
4270 |
_LIT(KSpace, " ");
|
|
4271 |
commandLine.Append(KSpace());
|
|
4272 |
|
|
4273 |
_LIT(KDArg, "-d");
|
|
4274 |
commandLine.Append(KDArg());
|
|
4275 |
commandLine.AppendNum(aDelay);
|
|
4276 |
|
|
4277 |
commandLine.Append(KSpace());
|
|
4278 |
|
|
4279 |
_LIT(KEArg, "-e");
|
|
4280 |
commandLine.Append(KEArg());
|
|
4281 |
commandLine.AppendNum(aExtraThreads);
|
|
4282 |
|
|
4283 |
// create the new process, matching on file name only, not specifying uid values
|
|
4284 |
TInt err = aProcess.Create(aFileName, commandLine); // owned by the process
|
|
4285 |
|
|
4286 |
// check that there was no error raised
|
|
4287 |
if(err != KErrNone)
|
|
4288 |
{
|
|
4289 |
commandLine.Close();
|
|
4290 |
return err;
|
|
4291 |
}
|
|
4292 |
|
|
4293 |
TRequestStatus status = KRequestPending;
|
|
4294 |
aProcess.Rendezvous(status);
|
|
4295 |
|
|
4296 |
commandLine.Close(); // after target thread starts
|
|
4297 |
|
|
4298 |
if(KRequestPending != status.Int())
|
|
4299 |
{
|
|
4300 |
// startup failed so kill the process
|
|
4301 |
aProcess.Kill(KErrNone);
|
|
4302 |
return status.Int();
|
|
4303 |
}
|
|
4304 |
else
|
|
4305 |
{
|
|
4306 |
// start up succeeded so resume the process
|
|
4307 |
aProcess.Resume();
|
|
4308 |
User::WaitForRequest(status);
|
|
4309 |
if(KErrNone != status.Int())
|
|
4310 |
{
|
|
4311 |
aProcess.Kill(KErrNone);
|
|
4312 |
}
|
|
4313 |
return status.Int();
|
|
4314 |
}
|
|
4315 |
}
|
|
4316 |
|
|
4317 |
/**
|
|
4318 |
Helper function to read a tag header from a debug functionality block
|
|
4319 |
|
|
4320 |
@param aDebugFunctionalityBlock block to read header from
|
|
4321 |
@param aTagHdrId header type to find
|
|
4322 |
|
|
4323 |
@return pointer to the header, or NULL if not available
|
|
4324 |
*/
|
|
4325 |
TTagHeader* CRunModeAgent::GetTagHdr(const TDesC8& aDebugFunctionalityBlock, const TTagHeaderId aTagHdrId) const
|
|
4326 |
{
|
|
4327 |
TUint8* ptr = (TUint8*) aDebugFunctionalityBlock.Ptr();
|
|
4328 |
TUint8* blockEnd = ptr + aDebugFunctionalityBlock.Size();
|
|
4329 |
|
|
4330 |
while(ptr < blockEnd)
|
|
4331 |
{
|
|
4332 |
TTagHeader* header = (TTagHeader*)ptr;
|
|
4333 |
if(header->iTagHdrId == aTagHdrId)
|
|
4334 |
{
|
|
4335 |
return header;
|
|
4336 |
}
|
|
4337 |
ptr += sizeof(TTagHeader) + (header->iNumTags * sizeof(TTag));
|
|
4338 |
}
|
|
4339 |
return NULL;
|
|
4340 |
}
|
|
4341 |
|
|
4342 |
/**
|
|
4343 |
Helper function to read a tag from a debug functionality block
|
|
4344 |
|
|
4345 |
@param aTagHdr pointer to a tag header in a debug functionality block
|
|
4346 |
@param aElement element to return from the header's data
|
|
4347 |
|
|
4348 |
@return pointer to the tag, or NULL if not available
|
|
4349 |
*/
|
|
4350 |
TTag* CRunModeAgent::GetTag(const TTagHeader* aTagHdr, const TInt aElement) const
|
|
4351 |
{
|
|
4352 |
TUint8* ptr = (TUint8*)aTagHdr + sizeof(TTagHeader);
|
|
4353 |
TUint8* blockEnd = ptr + (aTagHdr->iNumTags * sizeof(TTag));
|
|
4354 |
|
|
4355 |
while(ptr < blockEnd)
|
|
4356 |
{
|
|
4357 |
TTag* tag = (TTag*)ptr;
|
|
4358 |
if(tag->iTagId == aElement)
|
|
4359 |
{
|
|
4360 |
return tag;
|
|
4361 |
}
|
|
4362 |
ptr += sizeof(TTag);
|
|
4363 |
}
|
|
4364 |
return NULL;
|
|
4365 |
}
|
|
4366 |
|
|
4367 |
TTag CRunModeAgent::GetTag(const TTagHeaderId aTagHdrId, const TInt aElement)
|
|
4368 |
{
|
|
4369 |
TUint32 bufsize = 0; // Safe default size
|
|
4370 |
|
|
4371 |
// Get functionality block size
|
|
4372 |
test(KErrNone == iServSession.GetDebugFunctionalityBufSize(&bufsize));
|
|
4373 |
|
|
4374 |
// Ensure we have a finite buffer size
|
|
4375 |
test(bufsize!=0);
|
|
4376 |
|
|
4377 |
// Allocate space for the functionality data
|
|
4378 |
HBufC8* dftext = HBufC8::NewLC(bufsize);
|
|
4379 |
|
|
4380 |
// create an empty TPtr8 refering to dftext
|
|
4381 |
TPtr8 dftextPtr(dftext->Des());
|
|
4382 |
|
|
4383 |
// Get the functionality block
|
|
4384 |
test(KErrNone == iServSession.GetDebugFunctionality(dftextPtr));
|
|
4385 |
|
|
4386 |
// read a value from the data to check it has come through as expected
|
|
4387 |
TTagHeader* header = GetTagHdr(dftext->Des(), aTagHdrId);
|
|
4388 |
test(header != NULL);
|
|
4389 |
TTag* tag = GetTag(header, aElement);
|
|
4390 |
test(tag != NULL);
|
|
4391 |
|
|
4392 |
TTag tagToReturn = *tag;
|
|
4393 |
|
|
4394 |
// Remove our temporary buffer
|
|
4395 |
CleanupStack::PopAndDestroy(dftext);
|
|
4396 |
|
|
4397 |
return tagToReturn;
|
|
4398 |
}
|
|
4399 |
|
|
4400 |
/**
|
|
4401 |
Helper function which returns a Boolean indicating with a process with the
|
|
4402 |
specified name is currently running.
|
|
4403 |
|
|
4404 |
@param aProcessName - Name of the process to find
|
|
4405 |
@return ETrue if found, EFalse otherwise
|
|
4406 |
*/
|
|
4407 |
TBool CRunModeAgent::ProcessExists(const TDesC& aProcessName)
|
|
4408 |
{
|
|
4409 |
TInt err=KErrNone;
|
|
4410 |
TBool found = FALSE;
|
|
4411 |
|
|
4412 |
_LIT(KWildCard,"*");
|
|
4413 |
|
|
4414 |
TFindProcess find(KWildCard);
|
|
4415 |
TFullName name;
|
|
4416 |
while(find.Next(name)==KErrNone)
|
|
4417 |
{
|
|
4418 |
RProcess process;
|
|
4419 |
err = process.Open(find);
|
|
4420 |
if (err == KErrNone)
|
|
4421 |
{
|
|
4422 |
if (name.Find(aProcessName) != KErrNotFound)
|
|
4423 |
{
|
|
4424 |
found = TRUE;
|
|
4425 |
}
|
|
4426 |
process.Close();
|
|
4427 |
}
|
|
4428 |
}
|
|
4429 |
|
|
4430 |
return found;
|
|
4431 |
}
|