Update contrib.
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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // Tests the functionality of the run mode debug device driver.
19 #include <e32base_private.h>
24 #include "d_rmdebugclient.h"
25 #include "d_rmdebugthread.h"
26 #include "t_rmdebug.h"
28 IMPORT_C TInt StartDebugThread(RThread& aServerThread);
29 IMPORT_D extern TInt TestData;
30 IMPORT_D extern TBuf8<SYMBIAN_RMDBG_MEMORYSIZE> gMemoryAccessBytes;
32 LOCAL_D RTest test(_L("T_RMDEBUG"));
34 CRunModeAgent::CRunModeAgent()
36 // CRunModeAgent constructor
41 CRunModeAgent* CRunModeAgent::NewL()
43 // CRunModeAgent::NewL
46 CRunModeAgent* self = new(ELeave) CRunModeAgent();
50 if (self->iState != ERunModeAgentRunning)
58 CRunModeAgent::~CRunModeAgent()
60 // CRunModeAgent destructor
65 iState = ERunModeAgentUnInit;
68 void CRunModeAgent::ConstructL()
70 // CRunModeAgent::ConstructL
74 err = StartDebugThread(iDebugThread);
78 if (iServSession.Open() == KErrNone)
80 iState = ERunModeAgentRunning;
84 iState = ERunModeAgentUnInit;
89 User::Panic(_L("Can't start debug thread"), err);
95 CRunModeAgent *RunModeAgent;
98 _LIT(ProcessName1,"T_RMDEBUG");
99 _LIT(ProcessName1a,"t_rmdebug");
100 //_LIT(ProcessName2,"ekern");
101 //_LIT(ProcessName3,"efile");
105 //---------------------------------------------
106 //! @SYMTestCaseID KBase-0185
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()
120 test.Next(_L("TestProcessList - Read Process List\n"));
122 TFindProcess find(KWildCard);
124 while(find.Next(name)==KErrNone)
127 err = process.Open(find);
130 if ((name.Find(ProcessName1) != KErrNotFound) ||
131 (name.Find(ProcessName1a) != KErrNotFound))
133 iProcessID = process.Id();
143 _LIT(ThreadName1,"DebugThread");
145 //---------------------------------------------
146 //! @SYMTestCaseID KBase-0186
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()
160 test.Next(_L("TestThreadList - Read Thread List\n"));
162 TFindThread find(KWildCard);
164 while(find.Next(name)==KErrNone)
167 err = thread.Open(find);
171 thread.Process(process);
172 if (((TUint32)process.Id() == iProcessID) &&
173 (name.Find(ThreadName1) != KErrNotFound))
176 iThreadID = thread.Id();
186 //---------------------------------------------
187 //! @SYMTestCaseID KBase-0187
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()
199 TMemoryInfo MemoryInfo;
202 test.Next(_L("TestMemoryAccess - Read Memory\n"));
204 for (i = 0; i < SYMBIAN_RMDBG_MEMORYSIZE; i++)
206 gMemoryAccessBytes.Append(i);
209 MemoryInfo.iAddress = (TUint32)(&gMemoryAccessBytes[0]);
210 MemoryInfo.iSize = SYMBIAN_RMDBG_MEMORYSIZE;
212 HBufC8 *data = HBufC8::NewLC(SYMBIAN_RMDBG_MEMORYSIZE);
213 TPtr8 ptr_memread(data->Des());
214 MemoryInfo.iDataPtr = &ptr_memread;
216 // test.Printf(_L("Read address = 0x%x Read size = 0x%x\n"),MemoryInfo.iAddress,MemoryInfo.iSize);
218 err = iServSession.ReadMemory(iThreadID, &MemoryInfo);
220 for (i = 0; i < MemoryInfo.iSize; i++)
222 if (ptr_memread.Ptr()[i] != gMemoryAccessBytes[i])
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);
234 // Now reset the buffer
235 for (i = 0; i < SYMBIAN_RMDBG_MEMORYSIZE; i++)
237 gMemoryAccessBytes[i] = 0;
240 // Write our data into the buffer
241 err = iServSession.WriteMemory(iThreadID, &MemoryInfo);
243 for (i = 0; i < MemoryInfo.iSize; i++)
245 if (ptr_memread.Ptr()[i] != gMemoryAccessBytes[i])
253 if (gMemoryAccessBytes[5] == 0)
258 CleanupStack::PopAndDestroy(data);
263 //---------------------------------------------
264 //! @SYMTestCaseID KBase-0188
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()
277 test.Next(_L("TestSuspendResume - Suspend\n"));
278 // Suspend the thread
279 err = iServSession.SuspendThread(iThreadID);
282 localtestdata = TestData;
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);
288 // Now check data hasnt changed
289 test(localtestdata==TestData);
292 test.Next(_L("TestSuspendResume - Resume\n"));
293 err = iServSession.ResumeThread(iThreadID);
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);
300 // Now check that the thread being controlled has resumed and is
301 // updating the variable
302 test(localtestdata!=TestData);
305 void CRunModeAgent::ClientAppL()
307 // Performs each test in turn
310 test.Start(_L("ClientAppL"));
319 GLDEF_C TInt E32Main()
321 // Entry point for run mode debug driver test
327 CTrapCleanup* trap = CTrapCleanup::New();
331 RunModeAgent = CRunModeAgent::NewL();
332 if (RunModeAgent != NULL)
337 TRAPD(r,RunModeAgent->ClientAppL());