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