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