sl@0: // Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of the License "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // Tests the functionality of the run mode debug device driver. sl@0: // sl@0: // sl@0: sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: #include "d_rmdebugclient.h" sl@0: #include "d_rmdebugthread.h" sl@0: #include "t_rmdebug.h" sl@0: sl@0: IMPORT_C TInt StartDebugThread(RThread& aServerThread); sl@0: IMPORT_D extern TInt TestData; sl@0: IMPORT_D extern TBuf8 gMemoryAccessBytes; sl@0: sl@0: LOCAL_D RTest test(_L("T_RMDEBUG")); sl@0: sl@0: CRunModeAgent::CRunModeAgent() sl@0: // sl@0: // CRunModeAgent constructor sl@0: // sl@0: { sl@0: } sl@0: sl@0: CRunModeAgent* CRunModeAgent::NewL() sl@0: // sl@0: // CRunModeAgent::NewL sl@0: // sl@0: { sl@0: CRunModeAgent* self = new(ELeave) CRunModeAgent(); sl@0: sl@0: self->ConstructL(); sl@0: sl@0: if (self->iState != ERunModeAgentRunning) sl@0: { sl@0: delete self; sl@0: self = NULL; sl@0: } sl@0: return self; sl@0: } sl@0: sl@0: CRunModeAgent::~CRunModeAgent() sl@0: // sl@0: // CRunModeAgent destructor sl@0: // sl@0: { sl@0: iServSession.Close(); sl@0: iDebugThread.Close(); sl@0: iState = ERunModeAgentUnInit; sl@0: } sl@0: sl@0: void CRunModeAgent::ConstructL() sl@0: // sl@0: // CRunModeAgent::ConstructL sl@0: // sl@0: { sl@0: TInt err; sl@0: err = StartDebugThread(iDebugThread); sl@0: sl@0: if (err == KErrNone) sl@0: { sl@0: if (iServSession.Open() == KErrNone) sl@0: { sl@0: iState = ERunModeAgentRunning; sl@0: } sl@0: else sl@0: { sl@0: iState = ERunModeAgentUnInit; sl@0: } sl@0: } sl@0: else sl@0: { sl@0: User::Panic(_L("Can't start debug thread"), err); sl@0: } sl@0: } sl@0: sl@0: sl@0: sl@0: CRunModeAgent *RunModeAgent; sl@0: sl@0: // Test process names sl@0: _LIT(ProcessName1,"T_RMDEBUG"); sl@0: _LIT(ProcessName1a,"t_rmdebug"); sl@0: //_LIT(ProcessName2,"ekern"); sl@0: //_LIT(ProcessName3,"efile"); sl@0: _LIT(KWildCard,"*"); sl@0: sl@0: sl@0: //--------------------------------------------- sl@0: //! @SYMTestCaseID KBase-0185 sl@0: //! @SYMTestType sl@0: //! @SYMPREQ PREQ1426 sl@0: //! @SYMTestCaseDesc Test reading process list sl@0: //! @SYMTestActions Several calls to read the process list sl@0: //! @SYMTestExpectedResults KErrNone and the owning process ID set sl@0: //! @SYMTestPriority High sl@0: //! @SYMTestStatus Implemented sl@0: //--------------------------------------------- sl@0: void CRunModeAgent::TestProcessList() sl@0: { sl@0: TInt err=KErrNone; sl@0: TBool found = FALSE; sl@0: sl@0: test.Next(_L("TestProcessList - Read Process List\n")); sl@0: sl@0: TFindProcess find(KWildCard); sl@0: TFullName name; sl@0: while(find.Next(name)==KErrNone) sl@0: { sl@0: RProcess process; sl@0: err = process.Open(find); sl@0: if (err == KErrNone) sl@0: { sl@0: if ((name.Find(ProcessName1) != KErrNotFound) || sl@0: (name.Find(ProcessName1a) != KErrNotFound)) sl@0: { sl@0: iProcessID = process.Id(); sl@0: found = TRUE; sl@0: } sl@0: process.Close(); sl@0: } sl@0: } sl@0: test(found== TRUE); sl@0: } sl@0: sl@0: // Test thread name sl@0: _LIT(ThreadName1,"DebugThread"); sl@0: sl@0: //--------------------------------------------- sl@0: //! @SYMTestCaseID KBase-0186 sl@0: //! @SYMTestType sl@0: //! @SYMPREQ PREQ1426 sl@0: //! @SYMTestCaseDesc Test reading thread list sl@0: //! @SYMTestActions Several calls to read the thread list sl@0: //! @SYMTestExpectedResults KErrNone and the debug thread ID set sl@0: //! @SYMTestPriority High sl@0: //! @SYMTestStatus Implemented sl@0: //--------------------------------------------- sl@0: void CRunModeAgent::TestThreadList() sl@0: { sl@0: TInt err=KErrNone; sl@0: TBool found = FALSE; sl@0: sl@0: test.Next(_L("TestThreadList - Read Thread List\n")); sl@0: sl@0: TFindThread find(KWildCard); sl@0: TFullName name; sl@0: while(find.Next(name)==KErrNone) sl@0: { sl@0: RThread thread; sl@0: err = thread.Open(find); sl@0: if (err == KErrNone) sl@0: { sl@0: RProcess process; sl@0: thread.Process(process); sl@0: if (((TUint32)process.Id() == iProcessID) && sl@0: (name.Find(ThreadName1) != KErrNotFound)) sl@0: { sl@0: found = TRUE; sl@0: iThreadID = thread.Id(); sl@0: } sl@0: } sl@0: thread.Close(); sl@0: } sl@0: sl@0: test(found==TRUE); sl@0: } sl@0: sl@0: sl@0: //--------------------------------------------- sl@0: //! @SYMTestCaseID KBase-0187 sl@0: //! @SYMTestType sl@0: //! @SYMPREQ PREQ1426 sl@0: //! @SYMTestCaseDesc Test reading and writing thread memory sl@0: //! @SYMTestActions Several call to read and write blocks of thread memory sl@0: //! @SYMTestExpectedResults KErrNone sl@0: //! @SYMTestPriority High sl@0: //! @SYMTestStatus Implemented sl@0: //--------------------------------------------- sl@0: void CRunModeAgent::TestMemoryAccess() sl@0: { sl@0: TInt err=KErrNone; sl@0: TMemoryInfo MemoryInfo; sl@0: TInt i; sl@0: sl@0: test.Next(_L("TestMemoryAccess - Read Memory\n")); sl@0: sl@0: for (i = 0; i < SYMBIAN_RMDBG_MEMORYSIZE; i++) sl@0: { sl@0: gMemoryAccessBytes.Append(i); sl@0: } sl@0: sl@0: MemoryInfo.iAddress = (TUint32)(&gMemoryAccessBytes[0]); sl@0: MemoryInfo.iSize = SYMBIAN_RMDBG_MEMORYSIZE; sl@0: sl@0: HBufC8 *data = HBufC8::NewLC(SYMBIAN_RMDBG_MEMORYSIZE); sl@0: TPtr8 ptr_memread(data->Des()); sl@0: MemoryInfo.iDataPtr = &ptr_memread; sl@0: sl@0: // test.Printf(_L("Read address = 0x%x Read size = 0x%x\n"),MemoryInfo.iAddress,MemoryInfo.iSize); sl@0: sl@0: err = iServSession.ReadMemory(iThreadID, &MemoryInfo); sl@0: sl@0: for (i = 0; i < MemoryInfo.iSize; i++) sl@0: { sl@0: if (ptr_memread.Ptr()[i] != gMemoryAccessBytes[i]) sl@0: { sl@0: err = KErrCorrupt; sl@0: } sl@0: } sl@0: sl@0: sl@0: // Test out writing memory. sl@0: test.Next(_L("TestMemoryAccess - Write Memory\n")); sl@0: // test.Printf(_L("Write address = 0x%x Write size = 0x%x\n"),MemoryInfo.iAddress,MemoryInfo.iSize); sl@0: if (err== KErrNone) sl@0: { sl@0: // Now reset the buffer sl@0: for (i = 0; i < SYMBIAN_RMDBG_MEMORYSIZE; i++) sl@0: { sl@0: gMemoryAccessBytes[i] = 0; sl@0: } sl@0: sl@0: // Write our data into the buffer sl@0: err = iServSession.WriteMemory(iThreadID, &MemoryInfo); sl@0: sl@0: for (i = 0; i < MemoryInfo.iSize; i++) sl@0: { sl@0: if (ptr_memread.Ptr()[i] != gMemoryAccessBytes[i]) sl@0: { sl@0: err = KErrCorrupt; sl@0: } sl@0: } sl@0: sl@0: } sl@0: sl@0: if (gMemoryAccessBytes[5] == 0) sl@0: { sl@0: err = KErrCorrupt; sl@0: } sl@0: sl@0: CleanupStack::PopAndDestroy(data); sl@0: test(err==KErrNone); sl@0: } sl@0: sl@0: sl@0: //--------------------------------------------- sl@0: //! @SYMTestCaseID KBase-0188 sl@0: //! @SYMTestType sl@0: //! @SYMPREQ PREQ1426 sl@0: //! @SYMTestCaseDesc Test suspending and resuming a task sl@0: //! @SYMTestActions Suspends a thread checks the contents of a variable then waits and tests it hasnt changed sl@0: //! @SYMTestExpectedResults KErrNone sl@0: //! @SYMTestPriority High sl@0: //! @SYMTestStatus Implemented sl@0: //--------------------------------------------- sl@0: void CRunModeAgent::TestSuspendResume() sl@0: { sl@0: TInt err; sl@0: sl@0: test.Next(_L("TestSuspendResume - Suspend\n")); sl@0: // Suspend the thread sl@0: err = iServSession.SuspendThread(iThreadID); sl@0: test(err==KErrNone); sl@0: TInt localtestdata; sl@0: localtestdata = TestData; sl@0: sl@0: // Wait 3 seconds (suspends this thread) and hopefully resumes the sl@0: // thread we are controlling via the iServSession.SuspendThread request sl@0: User::After(3000000); sl@0: sl@0: // Now check data hasnt changed sl@0: test(localtestdata==TestData); sl@0: sl@0: // Resume the thread sl@0: test.Next(_L("TestSuspendResume - Resume\n")); sl@0: err = iServSession.ResumeThread(iThreadID); sl@0: test(err==KErrNone); sl@0: sl@0: // Wait 3 seconds (suspends this thread) and hopefully resumes the sl@0: // thread we are controlling via the iServSession.SuspendThread request sl@0: User::After(3000000); sl@0: sl@0: // Now check that the thread being controlled has resumed and is sl@0: // updating the variable sl@0: test(localtestdata!=TestData); sl@0: } sl@0: sl@0: void CRunModeAgent::ClientAppL() sl@0: // sl@0: // Performs each test in turn sl@0: // sl@0: { sl@0: test.Start(_L("ClientAppL")); sl@0: sl@0: TestProcessList(); sl@0: TestThreadList(); sl@0: TestMemoryAccess(); sl@0: TestSuspendResume(); sl@0: test.End(); sl@0: } sl@0: sl@0: GLDEF_C TInt E32Main() sl@0: // sl@0: // Entry point for run mode debug driver test sl@0: // sl@0: { sl@0: TInt ret = KErrNone; sl@0: sl@0: // client sl@0: CTrapCleanup* trap = CTrapCleanup::New(); sl@0: if (!trap) sl@0: return KErrNoMemory; sl@0: sl@0: RunModeAgent = CRunModeAgent::NewL(); sl@0: if (RunModeAgent != NULL) sl@0: { sl@0: test.Title(); sl@0: sl@0: __UHEAP_MARK; sl@0: TRAPD(r,RunModeAgent->ClientAppL()); sl@0: ret = r; sl@0: __UHEAP_MARKEND; sl@0: sl@0: delete RunModeAgent; sl@0: } sl@0: sl@0: delete trap; sl@0: sl@0: return ret; sl@0: }