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 <f32dbg.h>
|
|
24 |
#include "d_rmdebugclient.h"
|
|
25 |
#include "d_rmdebugthread.h"
|
|
26 |
#include "t_rmdebug.h"
|
|
27 |
|
|
28 |
IMPORT_C TInt StartDebugThread(RThread& aServerThread);
|
|
29 |
IMPORT_D extern TInt TestData;
|
|
30 |
IMPORT_D extern TBuf8<SYMBIAN_RMDBG_MEMORYSIZE> gMemoryAccessBytes;
|
|
31 |
|
|
32 |
LOCAL_D RTest test(_L("T_RMDEBUG"));
|
|
33 |
|
|
34 |
CRunModeAgent::CRunModeAgent()
|
|
35 |
//
|
|
36 |
// CRunModeAgent constructor
|
|
37 |
//
|
|
38 |
{
|
|
39 |
}
|
|
40 |
|
|
41 |
CRunModeAgent* CRunModeAgent::NewL()
|
|
42 |
//
|
|
43 |
// CRunModeAgent::NewL
|
|
44 |
//
|
|
45 |
{
|
|
46 |
CRunModeAgent* self = new(ELeave) CRunModeAgent();
|
|
47 |
|
|
48 |
self->ConstructL();
|
|
49 |
|
|
50 |
if (self->iState != ERunModeAgentRunning)
|
|
51 |
{
|
|
52 |
delete self;
|
|
53 |
self = NULL;
|
|
54 |
}
|
|
55 |
return self;
|
|
56 |
}
|
|
57 |
|
|
58 |
CRunModeAgent::~CRunModeAgent()
|
|
59 |
//
|
|
60 |
// CRunModeAgent destructor
|
|
61 |
//
|
|
62 |
{
|
|
63 |
iServSession.Close();
|
|
64 |
iDebugThread.Close();
|
|
65 |
iState = ERunModeAgentUnInit;
|
|
66 |
}
|
|
67 |
|
|
68 |
void CRunModeAgent::ConstructL()
|
|
69 |
//
|
|
70 |
// CRunModeAgent::ConstructL
|
|
71 |
//
|
|
72 |
{
|
|
73 |
TInt err;
|
|
74 |
err = StartDebugThread(iDebugThread);
|
|
75 |
|
|
76 |
if (err == KErrNone)
|
|
77 |
{
|
|
78 |
if (iServSession.Open() == KErrNone)
|
|
79 |
{
|
|
80 |
iState = ERunModeAgentRunning;
|
|
81 |
}
|
|
82 |
else
|
|
83 |
{
|
|
84 |
iState = ERunModeAgentUnInit;
|
|
85 |
}
|
|
86 |
}
|
|
87 |
else
|
|
88 |
{
|
|
89 |
User::Panic(_L("Can't start debug thread"), err);
|
|
90 |
}
|
|
91 |
}
|
|
92 |
|
|
93 |
|
|
94 |
|
|
95 |
CRunModeAgent *RunModeAgent;
|
|
96 |
|
|
97 |
// Test process names
|
|
98 |
_LIT(ProcessName1,"T_RMDEBUG");
|
|
99 |
_LIT(ProcessName1a,"t_rmdebug");
|
|
100 |
//_LIT(ProcessName2,"ekern");
|
|
101 |
//_LIT(ProcessName3,"efile");
|
|
102 |
_LIT(KWildCard,"*");
|
|
103 |
|
|
104 |
|
|
105 |
//---------------------------------------------
|
|
106 |
//! @SYMTestCaseID KBase-0185
|
|
107 |
//! @SYMTestType
|
|
108 |
//! @SYMPREQ PREQ1426
|
|
109 |
//! @SYMTestCaseDesc Test reading process list
|
|
110 |
//! @SYMTestActions Several calls to read the process list
|
|
111 |
//! @SYMTestExpectedResults KErrNone and the owning process ID set
|
|
112 |
//! @SYMTestPriority High
|
|
113 |
//! @SYMTestStatus Implemented
|
|
114 |
//---------------------------------------------
|
|
115 |
void CRunModeAgent::TestProcessList()
|
|
116 |
{
|
|
117 |
TInt err=KErrNone;
|
|
118 |
TBool found = FALSE;
|
|
119 |
|
|
120 |
test.Next(_L("TestProcessList - Read Process List\n"));
|
|
121 |
|
|
122 |
TFindProcess find(KWildCard);
|
|
123 |
TFullName name;
|
|
124 |
while(find.Next(name)==KErrNone)
|
|
125 |
{
|
|
126 |
RProcess process;
|
|
127 |
err = process.Open(find);
|
|
128 |
if (err == KErrNone)
|
|
129 |
{
|
|
130 |
if ((name.Find(ProcessName1) != KErrNotFound) ||
|
|
131 |
(name.Find(ProcessName1a) != KErrNotFound))
|
|
132 |
{
|
|
133 |
iProcessID = process.Id();
|
|
134 |
found = TRUE;
|
|
135 |
}
|
|
136 |
process.Close();
|
|
137 |
}
|
|
138 |
}
|
|
139 |
test(found== TRUE);
|
|
140 |
}
|
|
141 |
|
|
142 |
// Test thread name
|
|
143 |
_LIT(ThreadName1,"DebugThread");
|
|
144 |
|
|
145 |
//---------------------------------------------
|
|
146 |
//! @SYMTestCaseID KBase-0186
|
|
147 |
//! @SYMTestType
|
|
148 |
//! @SYMPREQ PREQ1426
|
|
149 |
//! @SYMTestCaseDesc Test reading thread list
|
|
150 |
//! @SYMTestActions Several calls to read the thread list
|
|
151 |
//! @SYMTestExpectedResults KErrNone and the debug thread ID set
|
|
152 |
//! @SYMTestPriority High
|
|
153 |
//! @SYMTestStatus Implemented
|
|
154 |
//---------------------------------------------
|
|
155 |
void CRunModeAgent::TestThreadList()
|
|
156 |
{
|
|
157 |
TInt err=KErrNone;
|
|
158 |
TBool found = FALSE;
|
|
159 |
|
|
160 |
test.Next(_L("TestThreadList - Read Thread List\n"));
|
|
161 |
|
|
162 |
TFindThread find(KWildCard);
|
|
163 |
TFullName name;
|
|
164 |
while(find.Next(name)==KErrNone)
|
|
165 |
{
|
|
166 |
RThread thread;
|
|
167 |
err = thread.Open(find);
|
|
168 |
if (err == KErrNone)
|
|
169 |
{
|
|
170 |
RProcess process;
|
|
171 |
thread.Process(process);
|
|
172 |
if (((TUint32)process.Id() == iProcessID) &&
|
|
173 |
(name.Find(ThreadName1) != KErrNotFound))
|
|
174 |
{
|
|
175 |
found = TRUE;
|
|
176 |
iThreadID = thread.Id();
|
|
177 |
}
|
|
178 |
}
|
|
179 |
thread.Close();
|
|
180 |
}
|
|
181 |
|
|
182 |
test(found==TRUE);
|
|
183 |
}
|
|
184 |
|
|
185 |
|
|
186 |
//---------------------------------------------
|
|
187 |
//! @SYMTestCaseID KBase-0187
|
|
188 |
//! @SYMTestType
|
|
189 |
//! @SYMPREQ PREQ1426
|
|
190 |
//! @SYMTestCaseDesc Test reading and writing thread memory
|
|
191 |
//! @SYMTestActions Several call to read and write blocks of thread memory
|
|
192 |
//! @SYMTestExpectedResults KErrNone
|
|
193 |
//! @SYMTestPriority High
|
|
194 |
//! @SYMTestStatus Implemented
|
|
195 |
//---------------------------------------------
|
|
196 |
void CRunModeAgent::TestMemoryAccess()
|
|
197 |
{
|
|
198 |
TInt err=KErrNone;
|
|
199 |
TMemoryInfo MemoryInfo;
|
|
200 |
TInt i;
|
|
201 |
|
|
202 |
test.Next(_L("TestMemoryAccess - Read Memory\n"));
|
|
203 |
|
|
204 |
for (i = 0; i < SYMBIAN_RMDBG_MEMORYSIZE; i++)
|
|
205 |
{
|
|
206 |
gMemoryAccessBytes.Append(i);
|
|
207 |
}
|
|
208 |
|
|
209 |
MemoryInfo.iAddress = (TUint32)(&gMemoryAccessBytes[0]);
|
|
210 |
MemoryInfo.iSize = SYMBIAN_RMDBG_MEMORYSIZE;
|
|
211 |
|
|
212 |
HBufC8 *data = HBufC8::NewLC(SYMBIAN_RMDBG_MEMORYSIZE);
|
|
213 |
TPtr8 ptr_memread(data->Des());
|
|
214 |
MemoryInfo.iDataPtr = &ptr_memread;
|
|
215 |
|
|
216 |
// test.Printf(_L("Read address = 0x%x Read size = 0x%x\n"),MemoryInfo.iAddress,MemoryInfo.iSize);
|
|
217 |
|
|
218 |
err = iServSession.ReadMemory(iThreadID, &MemoryInfo);
|
|
219 |
|
|
220 |
for (i = 0; i < MemoryInfo.iSize; i++)
|
|
221 |
{
|
|
222 |
if (ptr_memread.Ptr()[i] != gMemoryAccessBytes[i])
|
|
223 |
{
|
|
224 |
err = KErrCorrupt;
|
|
225 |
}
|
|
226 |
}
|
|
227 |
|
|
228 |
|
|
229 |
// Test out writing memory.
|
|
230 |
test.Next(_L("TestMemoryAccess - Write Memory\n"));
|
|
231 |
// test.Printf(_L("Write address = 0x%x Write size = 0x%x\n"),MemoryInfo.iAddress,MemoryInfo.iSize);
|
|
232 |
if (err== KErrNone)
|
|
233 |
{
|
|
234 |
// Now reset the buffer
|
|
235 |
for (i = 0; i < SYMBIAN_RMDBG_MEMORYSIZE; i++)
|
|
236 |
{
|
|
237 |
gMemoryAccessBytes[i] = 0;
|
|
238 |
}
|
|
239 |
|
|
240 |
// Write our data into the buffer
|
|
241 |
err = iServSession.WriteMemory(iThreadID, &MemoryInfo);
|
|
242 |
|
|
243 |
for (i = 0; i < MemoryInfo.iSize; i++)
|
|
244 |
{
|
|
245 |
if (ptr_memread.Ptr()[i] != gMemoryAccessBytes[i])
|
|
246 |
{
|
|
247 |
err = KErrCorrupt;
|
|
248 |
}
|
|
249 |
}
|
|
250 |
|
|
251 |
}
|
|
252 |
|
|
253 |
if (gMemoryAccessBytes[5] == 0)
|
|
254 |
{
|
|
255 |
err = KErrCorrupt;
|
|
256 |
}
|
|
257 |
|
|
258 |
CleanupStack::PopAndDestroy(data);
|
|
259 |
test(err==KErrNone);
|
|
260 |
}
|
|
261 |
|
|
262 |
|
|
263 |
//---------------------------------------------
|
|
264 |
//! @SYMTestCaseID KBase-0188
|
|
265 |
//! @SYMTestType
|
|
266 |
//! @SYMPREQ PREQ1426
|
|
267 |
//! @SYMTestCaseDesc Test suspending and resuming a task
|
|
268 |
//! @SYMTestActions Suspends a thread checks the contents of a variable then waits and tests it hasnt changed
|
|
269 |
//! @SYMTestExpectedResults KErrNone
|
|
270 |
//! @SYMTestPriority High
|
|
271 |
//! @SYMTestStatus Implemented
|
|
272 |
//---------------------------------------------
|
|
273 |
void CRunModeAgent::TestSuspendResume()
|
|
274 |
{
|
|
275 |
TInt err;
|
|
276 |
|
|
277 |
test.Next(_L("TestSuspendResume - Suspend\n"));
|
|
278 |
// Suspend the thread
|
|
279 |
err = iServSession.SuspendThread(iThreadID);
|
|
280 |
test(err==KErrNone);
|
|
281 |
TInt localtestdata;
|
|
282 |
localtestdata = TestData;
|
|
283 |
|
|
284 |
// Wait 3 seconds (suspends this thread) and hopefully resumes the
|
|
285 |
// thread we are controlling via the iServSession.SuspendThread request
|
|
286 |
User::After(3000000);
|
|
287 |
|
|
288 |
// Now check data hasnt changed
|
|
289 |
test(localtestdata==TestData);
|
|
290 |
|
|
291 |
// Resume the thread
|
|
292 |
test.Next(_L("TestSuspendResume - Resume\n"));
|
|
293 |
err = iServSession.ResumeThread(iThreadID);
|
|
294 |
test(err==KErrNone);
|
|
295 |
|
|
296 |
// Wait 3 seconds (suspends this thread) and hopefully resumes the
|
|
297 |
// thread we are controlling via the iServSession.SuspendThread request
|
|
298 |
User::After(3000000);
|
|
299 |
|
|
300 |
// Now check that the thread being controlled has resumed and is
|
|
301 |
// updating the variable
|
|
302 |
test(localtestdata!=TestData);
|
|
303 |
}
|
|
304 |
|
|
305 |
void CRunModeAgent::ClientAppL()
|
|
306 |
//
|
|
307 |
// Performs each test in turn
|
|
308 |
//
|
|
309 |
{
|
|
310 |
test.Start(_L("ClientAppL"));
|
|
311 |
|
|
312 |
TestProcessList();
|
|
313 |
TestThreadList();
|
|
314 |
TestMemoryAccess();
|
|
315 |
TestSuspendResume();
|
|
316 |
test.End();
|
|
317 |
}
|
|
318 |
|
|
319 |
GLDEF_C TInt E32Main()
|
|
320 |
//
|
|
321 |
// Entry point for run mode debug driver test
|
|
322 |
//
|
|
323 |
{
|
|
324 |
TInt ret = KErrNone;
|
|
325 |
|
|
326 |
// client
|
|
327 |
CTrapCleanup* trap = CTrapCleanup::New();
|
|
328 |
if (!trap)
|
|
329 |
return KErrNoMemory;
|
|
330 |
|
|
331 |
RunModeAgent = CRunModeAgent::NewL();
|
|
332 |
if (RunModeAgent != NULL)
|
|
333 |
{
|
|
334 |
test.Title();
|
|
335 |
|
|
336 |
__UHEAP_MARK;
|
|
337 |
TRAPD(r,RunModeAgent->ClientAppL());
|
|
338 |
ret = r;
|
|
339 |
__UHEAP_MARKEND;
|
|
340 |
|
|
341 |
delete RunModeAgent;
|
|
342 |
}
|
|
343 |
|
|
344 |
delete trap;
|
|
345 |
|
|
346 |
return ret;
|
|
347 |
}
|