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: // Implements a debug thread for testing. sl@0: // sl@0: // sl@0: sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: #include "d_rmdebugthread2.h" sl@0: sl@0: #include "d_rmdebug_step_test.h" sl@0: #include "d_demand_paging.h" sl@0: sl@0: EXPORT_C TBuf8 gMemoryAccessBytes; sl@0: IMPORT_C extern void RMDebug_BranchTst1(); sl@0: IMPORT_C extern TInt RMDebugDemandPagingTest(); sl@0: sl@0: EXPORT_C TInt TestData; sl@0: EXPORT_C TTestFunction FunctionChooser; sl@0: sl@0: const TInt NUMBER_TRACE_CALLS = 200; sl@0: sl@0: EXPORT_C TInt TestFunction() sl@0: { sl@0: //set TestData to an arbitrary value which we check for in t_rmdebug sl@0: TestData = 0xffeeddcc; sl@0: sl@0: User::After(3000000); // pause three seconds. sl@0: sl@0: return 0; sl@0: } sl@0: sl@0: /** sl@0: Wrapper around RMDebugDemandPagingTest, need to pause for a short time to sl@0: allow time in t_rmdebug.cpp to issue a User::WaitForRequest to catch the break point sl@0: */ sl@0: EXPORT_C void TestPagedCode() sl@0: { sl@0: User::After(100000); sl@0: sl@0: // call the function in paged code sl@0: RMDebugDemandPagingTest(); sl@0: } sl@0: sl@0: EXPORT_C void TestMultipleTraceCalls() sl@0: { sl@0: //arbitrary function to set a BP on sl@0: RMDebug_BranchTst1(); sl@0: sl@0: for(TInt cnt = NUMBER_TRACE_CALLS; cnt>0; cnt--) sl@0: { sl@0: RDebug::Printf("Trace event"); sl@0: } sl@0: sl@0: //another arbitrary function to set a BP on sl@0: RMDebug_StepTest_Non_PC_Modifying(); sl@0: } sl@0: sl@0: CDebugServThread::CDebugServThread() sl@0: // sl@0: // Empty constructor sl@0: // sl@0: { sl@0: } sl@0: sl@0: GLDEF_C TInt CDebugServThread::ThreadFunction(TAny*) sl@0: // sl@0: // Generic thread function for testing sl@0: // sl@0: { sl@0: // set FunctionChooser to run the default function sl@0: FunctionChooser = EDefaultFunction; sl@0: sl@0: CTrapCleanup* cleanup=CTrapCleanup::New(); sl@0: if (cleanup == NULL) sl@0: { sl@0: User::Leave(KErrNoMemory); sl@0: } sl@0: sl@0: RThread::Rendezvous(KErrNone); sl@0: sl@0: TestData = 1; sl@0: sl@0: while(TestData != 0xFFFFFFFF) sl@0: { sl@0: switch(FunctionChooser) sl@0: { sl@0: case EDemandPagingFunction: sl@0: TestPagedCode(); sl@0: break; sl@0: case EDefaultFunction: sl@0: // the default function is the stepping test functions sl@0: case EStepFunction: sl@0: { sl@0: RMDebug_BranchTst1(); sl@0: sl@0: // Single stepping test support code sl@0: sl@0: // ARM tests sl@0: RMDebug_StepTest_Non_PC_Modifying(); sl@0: sl@0: RMDebug_StepTest_Branch(); sl@0: sl@0: RMDebug_StepTest_Branch_And_Link(); sl@0: sl@0: RMDebug_StepTest_MOV_PC(); sl@0: sl@0: RMDebug_StepTest_LDR_PC(); sl@0: sl@0: // thumb/interworking tests not supported on armv4 sl@0: #ifdef __MARM_ARMV5__ sl@0: sl@0: // Thumb tests sl@0: RMDebug_StepTest_Thumb_Non_PC_Modifying(); sl@0: sl@0: RMDebug_StepTest_Thumb_Branch(); sl@0: sl@0: RMDebug_StepTest_Thumb_Branch_And_Link(); sl@0: sl@0: RMDebug_StepTest_Thumb_Back_Branch_And_Link(); sl@0: sl@0: // ARM <-> Thumb interworking tests sl@0: RMDebug_StepTest_Interwork(); sl@0: sl@0: RMDebug_StepTest_Thumb_AddPC(); sl@0: sl@0: #endif // __MARM_ARMV5__ sl@0: sl@0: // Single-stepping performance sl@0: RMDebug_StepTest_Count(); sl@0: sl@0: // multiple step test sl@0: RMDebug_StepTest_ARM_Step_Multiple(); sl@0: sl@0: TestData++; sl@0: sl@0: // Wait 50mSecs. // (suspends this thread) sl@0: User::After(50000); sl@0: sl@0: break; sl@0: } sl@0: case EMultipleTraceCalls: sl@0: TestMultipleTraceCalls(); sl@0: break; sl@0: default: sl@0: //do nothing sl@0: break; sl@0: } sl@0: } sl@0: sl@0: delete cleanup; sl@0: sl@0: return (KErrNone); sl@0: } sl@0: sl@0: EXPORT_C TInt StartDebugThread(RThread& aDebugThread, const TDesC& aDebugThreadName) sl@0: // sl@0: // Starts a test thread sl@0: // sl@0: { sl@0: TInt res=KErrNone; sl@0: sl@0: // Create the thread sl@0: res = aDebugThread.Create( aDebugThreadName, sl@0: CDebugServThread::ThreadFunction, sl@0: KDefaultStackSize, sl@0: KDebugThreadDefaultHeapSize, sl@0: KDebugThreadDefaultHeapSize, sl@0: NULL sl@0: ); sl@0: sl@0: // Check that the creation worked sl@0: if (res == KErrNone) sl@0: { sl@0: TRequestStatus rendezvousStatus; sl@0: sl@0: aDebugThread.SetPriority(EPriorityNormal); sl@0: // Make a request for a rendezvous sl@0: aDebugThread.Rendezvous(rendezvousStatus); sl@0: // Set the thread as ready for execution sl@0: aDebugThread.Resume(); sl@0: // Wait for the resumption sl@0: User::WaitForRequest(rendezvousStatus); sl@0: } sl@0: else sl@0: { sl@0: // Close the handle. sl@0: aDebugThread.Close(); sl@0: } sl@0: sl@0: return res; sl@0: }