kerneltest/e32test/rm_debug/d_rmdebugthread2.cpp
changeset 0 a41df078684a
equal deleted inserted replaced
-1:000000000000 0:a41df078684a
       
     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 // Implements a debug thread for testing.
       
    15 // 
       
    16 //
       
    17 
       
    18 #include <e32base.h>
       
    19 #include <e32base_private.h>
       
    20 #include <e32cons.h>
       
    21 #include <e32debug.h>
       
    22 #include "d_rmdebugthread2.h"
       
    23 
       
    24 #include "d_rmdebug_step_test.h"
       
    25 #include "d_demand_paging.h"
       
    26 
       
    27 EXPORT_C TBuf8<SYMBIAN_RMDBG_MEMORYSIZE> gMemoryAccessBytes;
       
    28 IMPORT_C extern void RMDebug_BranchTst1();
       
    29 IMPORT_C extern TInt RMDebugDemandPagingTest();
       
    30 
       
    31 EXPORT_C TInt TestData;
       
    32 EXPORT_C TTestFunction FunctionChooser;
       
    33 
       
    34 const TInt NUMBER_TRACE_CALLS = 200;
       
    35 
       
    36 EXPORT_C TInt TestFunction()
       
    37 	{
       
    38 	//set TestData to an arbitrary value which we check for in t_rmdebug 
       
    39 	TestData = 0xffeeddcc;
       
    40 
       
    41 	User::After(3000000);	// pause three seconds.
       
    42 
       
    43 	return 0;
       
    44 	}
       
    45 
       
    46 /**
       
    47   Wrapper around RMDebugDemandPagingTest, need to pause for a short time to
       
    48   allow time in t_rmdebug.cpp to issue a User::WaitForRequest to catch the break point
       
    49   */
       
    50 EXPORT_C void TestPagedCode()
       
    51 	{
       
    52 	User::After(100000);
       
    53 
       
    54 	// call the function in paged code
       
    55 	RMDebugDemandPagingTest();
       
    56 	}
       
    57 
       
    58 EXPORT_C void TestMultipleTraceCalls()
       
    59 	{
       
    60 	//arbitrary function to set a BP on
       
    61 	RMDebug_BranchTst1();
       
    62 	
       
    63 	for(TInt cnt = NUMBER_TRACE_CALLS; cnt>0; cnt--)
       
    64 		{
       
    65 		RDebug::Printf("Trace event");
       
    66 		}
       
    67 	
       
    68 	//another arbitrary function to set a BP on
       
    69 	RMDebug_StepTest_Non_PC_Modifying();
       
    70 	}
       
    71 
       
    72 CDebugServThread::CDebugServThread()
       
    73 //
       
    74 // Empty constructor
       
    75 //
       
    76 	{
       
    77 	}
       
    78 
       
    79 GLDEF_C TInt CDebugServThread::ThreadFunction(TAny*)
       
    80 //
       
    81 // Generic thread function for testing
       
    82 //
       
    83 	{
       
    84 	// set FunctionChooser to run the default function
       
    85 	FunctionChooser = EDefaultFunction;
       
    86 
       
    87 	CTrapCleanup* cleanup=CTrapCleanup::New();
       
    88 	if (cleanup == NULL)
       
    89 		{
       
    90 		User::Leave(KErrNoMemory);
       
    91 		}
       
    92 
       
    93 	RThread::Rendezvous(KErrNone);
       
    94 
       
    95 	TestData = 1;
       
    96 
       
    97 	while(TestData != 0xFFFFFFFF)
       
    98 		{
       
    99 		switch(FunctionChooser)
       
   100 			{
       
   101 			case EDemandPagingFunction:
       
   102 				TestPagedCode();
       
   103 				break;
       
   104 			case EDefaultFunction:
       
   105 				// the default function is the stepping test functions
       
   106 			case EStepFunction:
       
   107 				{
       
   108 				RMDebug_BranchTst1();
       
   109 
       
   110 				// Single stepping test support code
       
   111 
       
   112 				// ARM tests
       
   113 				RMDebug_StepTest_Non_PC_Modifying();
       
   114 
       
   115 				RMDebug_StepTest_Branch();
       
   116 
       
   117 				RMDebug_StepTest_Branch_And_Link();
       
   118 
       
   119 				RMDebug_StepTest_MOV_PC();
       
   120 
       
   121 				RMDebug_StepTest_LDR_PC();
       
   122  
       
   123 // thumb/interworking tests not supported on armv4
       
   124 #ifdef __MARM_ARMV5__
       
   125 
       
   126 				// Thumb tests
       
   127 				RMDebug_StepTest_Thumb_Non_PC_Modifying();
       
   128 
       
   129 				RMDebug_StepTest_Thumb_Branch();
       
   130 
       
   131 				RMDebug_StepTest_Thumb_Branch_And_Link();
       
   132 
       
   133 				RMDebug_StepTest_Thumb_Back_Branch_And_Link();
       
   134 
       
   135 				// ARM <-> Thumb interworking tests
       
   136 				RMDebug_StepTest_Interwork();
       
   137 
       
   138 				RMDebug_StepTest_Thumb_AddPC();
       
   139 
       
   140 #endif	// __MARM_ARMV5__
       
   141 				
       
   142 				// Single-stepping performance
       
   143 				RMDebug_StepTest_Count();
       
   144 
       
   145 				// multiple step test
       
   146 				RMDebug_StepTest_ARM_Step_Multiple();
       
   147 
       
   148 				TestData++;
       
   149 
       
   150 				// Wait 50mSecs. // (suspends this thread)
       
   151 				User::After(50000);
       
   152 
       
   153 				break;
       
   154 				}
       
   155 			case EMultipleTraceCalls:
       
   156 				TestMultipleTraceCalls();
       
   157 				break;
       
   158 			default:
       
   159 				//do nothing
       
   160 				break;
       
   161 			}
       
   162 		}
       
   163 
       
   164 	delete cleanup;
       
   165 
       
   166 	return (KErrNone);
       
   167 	}
       
   168 
       
   169 EXPORT_C TInt StartDebugThread(RThread& aDebugThread, const TDesC& aDebugThreadName)
       
   170 //
       
   171 // Starts a test thread
       
   172 //
       
   173 {
       
   174 	TInt res=KErrNone;
       
   175 
       
   176 	// Create the thread
       
   177 	res = aDebugThread.Create(	aDebugThreadName,
       
   178 								CDebugServThread::ThreadFunction,
       
   179 								KDefaultStackSize,
       
   180 								KDebugThreadDefaultHeapSize,
       
   181 								KDebugThreadDefaultHeapSize,
       
   182 								NULL
       
   183 								);
       
   184 
       
   185 	// Check that the creation worked
       
   186 	if (res == KErrNone)
       
   187 		{
       
   188 		TRequestStatus rendezvousStatus;
       
   189 
       
   190 		aDebugThread.SetPriority(EPriorityNormal);
       
   191 		// Make a request for a rendezvous
       
   192 		aDebugThread.Rendezvous(rendezvousStatus);
       
   193 		// Set the thread as ready for execution
       
   194 		aDebugThread.Resume();
       
   195 		// Wait for the resumption
       
   196 		User::WaitForRequest(rendezvousStatus);
       
   197 		}                                 
       
   198 	else
       
   199 		{
       
   200 		// Close the handle.
       
   201 		aDebugThread.Close();
       
   202 		}
       
   203 
       
   204 	return res;
       
   205 	}