kerneltest/e32test/rm_debug/debug_targets/d_rmdebugthread2.cpp
branchRCL_3
changeset 21 e7d2d738d3c2
child 22 2f92ad2dc5db
equal deleted inserted replaced
20:597aaf25e343 21:e7d2d738d3c2
       
     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 	KNumberOfTraceCalls = 50;
       
    35 
       
    36 EXPORT_C TInt TestFunction()
       
    37 	{
       
    38 	// Set TestData to an arbitrary value that can be checked by a tester
       
    39 	TestData = 0xffeeddcc;
       
    40 	RMDebug_BranchTst1();
       
    41 	
       
    42 	// Code here may not be executed because tests can change the PC value
       
    43 	// at any time, typically once the test passes
       
    44 	return 0;
       
    45 	}
       
    46 
       
    47 /**
       
    48   Wrapper around RMDebugDemandPagingTest, need to pause for a short time to
       
    49   allow time in t_rmdebug.cpp to issue a User::WaitForRequest to catch the break point
       
    50   */
       
    51 EXPORT_C void TestPagedCode()
       
    52 	{
       
    53 	User::After(100000);
       
    54 
       
    55 	// call the function in paged code
       
    56 	RMDebugDemandPagingTest();
       
    57 	}
       
    58 
       
    59 EXPORT_C void TestMultipleTraceCalls()
       
    60 	{
       
    61 	//arbitrary function to set a BP on
       
    62 	RMDebug_BranchTst1();
       
    63 
       
    64 	// The tester will change FunctionChooser once it gets what it needs out of the test
       
    65 	for(TInt cnt = KNumberOfTraceCalls; cnt>0 && (FunctionChooser==EMultipleTraceCalls); cnt--)
       
    66 		{
       
    67 		RDebug::Printf("T");
       
    68 		RDebug::Printf("R");
       
    69 		RDebug::Printf("A");
       
    70 		RDebug::Printf("C");
       
    71 		RDebug::Printf("E");
       
    72 		}
       
    73 	
       
    74 	//another arbitrary function to set a BP on
       
    75 	RMDebug_StepTest_Non_PC_Modifying();
       
    76 	}
       
    77 
       
    78 CDebugServThread::CDebugServThread()
       
    79 //
       
    80 // Empty constructor
       
    81 //
       
    82 	{
       
    83 	}
       
    84 
       
    85 GLDEF_C TInt CDebugServThread::ThreadFunction(TAny*)
       
    86 //
       
    87 // Generic thread function for testing
       
    88 //
       
    89 	{
       
    90 	// set FunctionChooser to run the default function
       
    91 	FunctionChooser = EDefaultFunction;
       
    92 
       
    93 	CTrapCleanup* cleanup=CTrapCleanup::New();
       
    94 	if (cleanup == NULL)
       
    95 		{
       
    96 		User::Leave(KErrNoMemory);
       
    97 		}
       
    98 
       
    99 	RThread::Rendezvous(KErrNone);
       
   100 
       
   101 	TestData = 1;
       
   102 
       
   103 	/* Beware of adding printf or other debug-generating events in this loop because
       
   104 	* they interfere with the tests
       
   105 	*/
       
   106 	while(TestData != 0xFFFFFFFF)
       
   107 		{
       
   108 		switch(FunctionChooser)
       
   109 			{
       
   110 			case EDemandPagingFunction:
       
   111 				TestPagedCode();
       
   112 				break;
       
   113 			case EDefaultFunction:
       
   114 				// the default function is the stepping test functions
       
   115 			case EStepFunction:
       
   116 				{
       
   117 				RMDebug_BranchTst1();
       
   118 
       
   119 				// Single stepping test support code
       
   120 
       
   121 				// ARM tests
       
   122 				RMDebug_StepTest_Non_PC_Modifying();
       
   123 
       
   124 				RMDebug_StepTest_Branch();
       
   125 
       
   126 				RMDebug_StepTest_Branch_And_Link();
       
   127 
       
   128 				RMDebug_StepTest_MOV_PC();
       
   129 
       
   130 				RMDebug_StepTest_LDR_PC();
       
   131  
       
   132 // thumb/interworking tests not supported on armv4
       
   133 #ifdef __MARM_ARMV5__
       
   134 
       
   135 				// Thumb tests
       
   136 				RMDebug_StepTest_Thumb_Non_PC_Modifying();
       
   137 
       
   138 				RMDebug_StepTest_Thumb_Branch();
       
   139 
       
   140 				RMDebug_StepTest_Thumb_Branch_And_Link();
       
   141 
       
   142 				RMDebug_StepTest_Thumb_Back_Branch_And_Link();
       
   143 
       
   144 				// ARM <-> Thumb interworking tests
       
   145 				RMDebug_StepTest_Interwork();
       
   146 
       
   147 				RMDebug_StepTest_Thumb_AddPC();
       
   148 
       
   149 #endif	// __MARM_ARMV5__
       
   150 				
       
   151 				// Single-stepping performance
       
   152 				RMDebug_StepTest_Count();
       
   153 
       
   154 				// multiple step test
       
   155 				RMDebug_StepTest_ARM_Step_Multiple();
       
   156 
       
   157 				TestData++;
       
   158 
       
   159 				// Wait 50mSecs. // (suspends this thread)
       
   160 				User::After(50000);
       
   161 
       
   162 				break;
       
   163 				}
       
   164 			case EMultipleTraceCalls:
       
   165 				TestMultipleTraceCalls();
       
   166 				break;
       
   167 			default:
       
   168 				//do nothing
       
   169 				break;
       
   170 			}
       
   171 		}
       
   172 
       
   173 	delete cleanup;
       
   174 
       
   175 	return (KErrNone);
       
   176 	}
       
   177 
       
   178 EXPORT_C TInt StartDebugThread(RThread& aDebugThread, const TDesC& aDebugThreadName)
       
   179 //
       
   180 // Starts a test thread
       
   181 //
       
   182 {
       
   183 	TInt res=KErrNone;
       
   184 
       
   185 	// Create the thread
       
   186 	res = aDebugThread.Create(	aDebugThreadName,
       
   187 								CDebugServThread::ThreadFunction,
       
   188 								KDefaultStackSize,
       
   189 								KDebugThreadDefaultHeapSize,
       
   190 								KDebugThreadDefaultHeapSize,
       
   191 								NULL
       
   192 								);
       
   193 
       
   194 	// Check that the creation worked
       
   195 	if (res == KErrNone)
       
   196 		{
       
   197 		TRequestStatus rendezvousStatus;
       
   198 
       
   199 		aDebugThread.SetPriority(EPriorityNormal);
       
   200 		// Make a request for a rendezvous
       
   201 		aDebugThread.Rendezvous(rendezvousStatus);
       
   202 		// Set the thread as ready for execution
       
   203 		aDebugThread.Resume();
       
   204 		// Wait for the resumption
       
   205 		User::WaitForRequest(rendezvousStatus);
       
   206 		}                                 
       
   207 	else
       
   208 		{
       
   209 		// Close the handle.
       
   210 		aDebugThread.Close();
       
   211 		}
       
   212 
       
   213 	return res;
       
   214 	}