19 #include "TestPolicy.h" |
19 #include "TestPolicy.h" |
20 #include "TestCaseFactory.h" |
20 #include "TestCaseFactory.h" |
21 #include "BaseTestCase.h" |
21 #include "BaseTestCase.h" |
22 #include "TestCaseFactory.h" |
22 #include "TestCaseFactory.h" |
23 #include "testdebug.h" |
23 #include "testdebug.h" |
|
24 #include "OstTraceDefinitions.h" |
|
25 #ifdef OST_TRACE_COMPILER_IN_USE |
|
26 #include "TestPolicyTraces.h" |
|
27 #endif |
24 |
28 |
25 namespace NUnitTesting_USBDI |
29 namespace NUnitTesting_USBDI |
26 { |
30 { |
27 |
31 |
28 CBasicTestPolicy* CBasicTestPolicy::NewL() |
32 CBasicTestPolicy* CBasicTestPolicy::NewL() |
29 { |
33 { |
|
34 OstTraceFunctionEntry0( CBASICTESTPOLICY_NEWL_ENTRY ); |
30 CBasicTestPolicy* self = new (ELeave) CBasicTestPolicy; |
35 CBasicTestPolicy* self = new (ELeave) CBasicTestPolicy; |
31 CleanupStack::PushL(self); |
36 CleanupStack::PushL(self); |
32 self->ConstructL(); |
37 self->ConstructL(); |
33 CleanupStack::Pop(self); |
38 CleanupStack::Pop(self); |
|
39 OstTraceFunctionExit1( CBASICTESTPOLICY_NEWL_EXIT, ( TUint )( self ) ); |
34 return self; |
40 return self; |
35 } |
41 } |
36 |
42 |
37 |
43 |
38 CBasicTestPolicy::CBasicTestPolicy() |
44 CBasicTestPolicy::CBasicTestPolicy() |
39 : CActive(EPriorityStandard) |
45 : CActive(EPriorityStandard) |
40 { |
46 { |
|
47 OstTraceFunctionEntry1( CBASICTESTPOLICY_CBASICTESTPOLICY_ENTRY, this ); |
41 CActiveScheduler::Add(this); |
48 CActiveScheduler::Add(this); |
|
49 OstTraceFunctionExit1( CBASICTESTPOLICY_CBASICTESTPOLICY_EXIT, this ); |
42 } |
50 } |
43 |
51 |
44 |
52 |
45 CBasicTestPolicy::~CBasicTestPolicy() |
53 CBasicTestPolicy::~CBasicTestPolicy() |
46 { |
54 { |
47 LOG_FUNC |
55 OstTraceFunctionEntry1( CBASICTESTPOLICY_CBASICTESTPOLICY_ENTRY_DUP01, this ); |
48 |
56 |
49 Cancel(); |
57 Cancel(); |
|
58 OstTraceFunctionExit1( CBASICTESTPOLICY_CBASICTESTPOLICY_EXIT_DUP01, this ); |
50 } |
59 } |
51 |
60 |
52 |
61 |
53 void CBasicTestPolicy::ConstructL() |
62 void CBasicTestPolicy::ConstructL() |
54 { |
63 { |
|
64 OstTraceFunctionEntry1( CBASICTESTPOLICY_CONSTRUCTL_ENTRY, this ); |
|
65 OstTraceFunctionExit1( CBASICTESTPOLICY_CONSTRUCTL_EXIT, this ); |
55 } |
66 } |
56 |
67 |
57 |
68 |
58 void CBasicTestPolicy::RunTestCaseL(const TDesC& aTestCaseId,TRequestStatus& aNotifierStatus) |
69 void CBasicTestPolicy::RunTestCaseL(const TDesC& aTestCaseId,TRequestStatus& aNotifierStatus) |
59 { |
70 { |
60 LOG_FUNC |
71 OstTraceFunctionEntryExt( CBASICTESTPOLICY_RUNTESTCASEL_ENTRY, this ); |
61 |
72 |
62 iNotifierStatus = &aNotifierStatus; |
73 iNotifierStatus = &aNotifierStatus; |
63 |
74 |
64 // Create the specified test case |
75 // Create the specified test case |
65 |
76 |
69 |
80 |
70 // Set the request of the notifier to pending |
81 // Set the request of the notifier to pending |
71 |
82 |
72 *iNotifierStatus = iStatus = KRequestPending; |
83 *iNotifierStatus = iStatus = KRequestPending; |
73 SetActive(); |
84 SetActive(); |
|
85 OstTraceFunctionExit1( CBASICTESTPOLICY_RUNTESTCASEL_EXIT, this ); |
74 } |
86 } |
75 |
87 |
76 |
88 |
77 void CBasicTestPolicy::DoCancel() |
89 void CBasicTestPolicy::DoCancel() |
78 { |
90 { |
79 LOG_FUNC |
91 OstTraceFunctionEntry1( CBASICTESTPOLICY_DOCANCEL_ENTRY, this ); |
80 |
92 |
81 // Cancel running the test cases |
93 // Cancel running the test cases |
82 |
94 |
83 iTestCase->Cancel(); |
95 iTestCase->Cancel(); |
84 |
96 |
85 // Notify the test case controller that test case execution was cancelled |
97 // Notify the test case controller that test case execution was cancelled |
86 |
98 |
87 User::RequestComplete(iNotifierStatus,KErrCancel); |
99 User::RequestComplete(iNotifierStatus,KErrCancel); |
|
100 OstTraceFunctionExit1( CBASICTESTPOLICY_DOCANCEL_EXIT, this ); |
88 } |
101 } |
89 |
102 |
90 |
103 |
91 void CBasicTestPolicy::SignalTestComplete(TInt aCompletionCode) |
104 void CBasicTestPolicy::SignalTestComplete(TInt aCompletionCode) |
92 { |
105 { |
93 LOG_FUNC |
106 OstTraceFunctionEntryExt( CBASICTESTPOLICY_SIGNALTESTCOMPLETE_ENTRY, this ); |
94 |
107 |
95 // Complete the test policy request with the test case completion code |
108 // Complete the test policy request with the test case completion code |
96 // (Basically self completion) |
109 // (Basically self completion) |
97 |
110 |
98 TRequestStatus* s = &iStatus; |
111 TRequestStatus* s = &iStatus; |
99 User::RequestComplete(s,aCompletionCode); |
112 User::RequestComplete(s,aCompletionCode); |
|
113 OstTraceFunctionExit1( CBASICTESTPOLICY_SIGNALTESTCOMPLETE_EXIT, this ); |
100 } |
114 } |
101 |
115 |
102 |
116 |
103 void CBasicTestPolicy::RunL() |
117 void CBasicTestPolicy::RunL() |
104 { |
118 { |
105 LOG_FUNC |
119 OstTraceFunctionEntry1( CBASICTESTPOLICY_RUNL_ENTRY, this ); |
106 |
120 |
107 // Complete the request of the notifier with the test case |
121 // Complete the request of the notifier with the test case |
108 // completion code |
122 // completion code |
109 |
123 |
110 User::RequestComplete(iNotifierStatus,iStatus.Int()); |
124 User::RequestComplete(iNotifierStatus,iStatus.Int()); |
111 |
125 |
112 // Destroy the test case |
126 // Destroy the test case |
113 |
127 |
114 delete iTestCase; |
128 delete iTestCase; |
|
129 OstTraceFunctionExit1( CBASICTESTPOLICY_RUNL_EXIT, this ); |
115 } |
130 } |
116 |
131 |
117 |
132 |
118 TInt CBasicTestPolicy::RunError(TInt aError) |
133 TInt CBasicTestPolicy::RunError(TInt aError) |
119 { |
134 { |
120 LOG_FUNC |
135 OstTraceFunctionEntryExt( CBASICTESTPOLICY_RUNERROR_ENTRY, this ); |
121 |
136 |
122 aError = KErrNone; |
137 aError = KErrNone; |
|
138 OstTraceFunctionExitExt( CBASICTESTPOLICY_RUNERROR_EXIT, this, aError ); |
123 return aError; |
139 return aError; |
124 } |
140 } |
125 |
141 |
126 CThreadTestPolicy* CThreadTestPolicy::NewL() |
142 CThreadTestPolicy* CThreadTestPolicy::NewL() |
127 { |
143 { |
|
144 OstTraceFunctionEntry0( CTHREADTESTPOLICY_NEWL_ENTRY ); |
128 CThreadTestPolicy* self = new (ELeave) CThreadTestPolicy; |
145 CThreadTestPolicy* self = new (ELeave) CThreadTestPolicy; |
129 CleanupStack::PushL(self); |
146 CleanupStack::PushL(self); |
130 self->ConstructL(); |
147 self->ConstructL(); |
131 CleanupStack::Pop(self); |
148 CleanupStack::Pop(self); |
|
149 OstTraceFunctionExit1( CTHREADTESTPOLICY_NEWL_EXIT, ( TUint )( self ) ); |
132 return self; |
150 return self; |
133 } |
151 } |
134 |
152 |
135 |
153 |
136 CThreadTestPolicy::CThreadTestPolicy() |
154 CThreadTestPolicy::CThreadTestPolicy() |
137 { |
155 { |
|
156 OstTraceFunctionEntry1( CTHREADTESTPOLICY_CTHREADTESTPOLICY_ENTRY, this ); |
|
157 OstTraceFunctionExit1( CTHREADTESTPOLICY_CTHREADTESTPOLICY_EXIT, this ); |
138 } |
158 } |
139 |
159 |
140 |
160 |
141 CThreadTestPolicy::~CThreadTestPolicy() |
161 CThreadTestPolicy::~CThreadTestPolicy() |
142 { |
162 { |
|
163 OstTraceFunctionEntry1( CTHREADTESTPOLICY_CTHREADTESTPOLICY_ENTRY_DUP01, this ); |
143 iTestThread.Close(); |
164 iTestThread.Close(); |
144 if(iTestCaseId) |
165 if(iTestCaseId) |
145 { |
166 { |
146 delete iTestCaseId; |
167 delete iTestCaseId; |
147 iTestCaseId = NULL; |
168 iTestCaseId = NULL; |
148 } |
169 } |
|
170 OstTraceFunctionExit1( CTHREADTESTPOLICY_CTHREADTESTPOLICY_EXIT_DUP01, this ); |
149 } |
171 } |
150 |
172 |
151 void CThreadTestPolicy::ConstructL() |
173 void CThreadTestPolicy::ConstructL() |
152 { |
174 { |
|
175 OstTraceFunctionEntry1( CTHREADTESTPOLICY_CONSTRUCTL_ENTRY, this ); |
|
176 OstTraceFunctionExit1( CTHREADTESTPOLICY_CONSTRUCTL_EXIT, this ); |
153 } |
177 } |
154 |
178 |
155 void CThreadTestPolicy::RunTestCaseL(const TDesC& aTestCaseId,TRequestStatus& aNotifierStatus) |
179 void CThreadTestPolicy::RunTestCaseL(const TDesC& aTestCaseId,TRequestStatus& aNotifierStatus) |
156 { |
180 { |
157 LOG_FUNC |
181 OstTraceFunctionEntryExt( CTHREADTESTPOLICY_RUNTESTCASEL_ENTRY, this ); |
158 |
182 |
159 iNotifierStatus = &aNotifierStatus; |
183 iNotifierStatus = &aNotifierStatus; |
160 RDebug::Printf("Creating thread for test case '%S'",&aTestCaseId); |
184 OstTraceExt1(TRACE_NORMAL, CTHREADTESTPOLICY_RUNTESTCASEL, "Creating thread for test case '%S'",aTestCaseId); |
161 |
185 |
162 if(iTestCaseId) |
186 if(iTestCaseId) |
163 { |
187 { |
164 delete iTestCaseId; |
188 delete iTestCaseId; |
165 iTestCaseId = NULL; |
189 iTestCaseId = NULL; |
171 TInt err(iTestThread.Create(aTestCaseId,CThreadTestPolicy::ThreadFunction, |
195 TInt err(iTestThread.Create(aTestCaseId,CThreadTestPolicy::ThreadFunction, |
172 KDefaultStackSize,NULL,reinterpret_cast<TAny*>(iTestCaseId))); |
196 KDefaultStackSize,NULL,reinterpret_cast<TAny*>(iTestCaseId))); |
173 |
197 |
174 if(err != KErrNone) |
198 if(err != KErrNone) |
175 { |
199 { |
176 RDebug::Printf("Test thread creation unsuccessful: %d",err); |
200 OstTrace1(TRACE_NORMAL, CTHREADTESTPOLICY_RUNTESTCASEL_DUP01, "Test thread creation unsuccessful: %d",err); |
177 User::Leave(err); |
201 User::Leave(err); |
178 } |
202 } |
179 |
203 |
180 RDebug::Printf("Test thread '%S' created",&aTestCaseId); |
204 OstTraceExt1(TRACE_NORMAL, CTHREADTESTPOLICY_RUNTESTCASEL_DUP02, "Test thread '%S' created",aTestCaseId); |
181 // Start the test case in the thread |
205 // Start the test case in the thread |
182 iTestThread.Logon(iStatus); |
206 iTestThread.Logon(iStatus); |
183 SetActive(); |
207 SetActive(); |
184 iTestThread.Resume(); |
208 iTestThread.Resume(); |
185 *iNotifierStatus = KRequestPending; |
209 *iNotifierStatus = KRequestPending; |
|
210 OstTraceFunctionExit1( CTHREADTESTPOLICY_RUNTESTCASEL_EXIT, this ); |
186 } |
211 } |
187 |
212 |
188 |
213 |
189 void CThreadTestPolicy::SignalTestComplete(TInt aCompletionCode) |
214 void CThreadTestPolicy::SignalTestComplete(TInt aCompletionCode) |
190 { |
215 { |
191 LOG_FUNC |
216 OstTraceFunctionEntryExt( CTHREADTESTPOLICY_SIGNALTESTCOMPLETE_ENTRY, this ); |
192 |
217 |
193 if(aCompletionCode == KErrNone) |
218 if(aCompletionCode == KErrNone) |
194 { |
219 { |
195 RDebug::Printf("CActiveScheduler::Stop CThreadTestPolicy::SignalTestComplete"); |
220 OstTrace0(TRACE_NORMAL, CTHREADTESTPOLICY_SIGNALTESTCOMPLETE, "CActiveScheduler::Stop CThreadTestPolicy::SignalTestComplete"); |
196 CActiveScheduler::Stop(); |
221 CActiveScheduler::Stop(); |
197 } |
222 } |
198 else |
223 else |
199 { |
224 { |
200 RDebug::Printf("Killing thread with: %d",aCompletionCode); |
225 OstTrace1(TRACE_NORMAL, CTHREADTESTPOLICY_SIGNALTESTCOMPLETE_DUP01, "Killing thread with: %d",aCompletionCode); |
201 iTestThread.Kill(aCompletionCode); |
226 iTestThread.Kill(aCompletionCode); |
202 } |
227 } |
|
228 OstTraceFunctionExit1( CTHREADTESTPOLICY_SIGNALTESTCOMPLETE_EXIT, this ); |
203 } |
229 } |
204 |
230 |
205 void CThreadTestPolicy::DoCancel() |
231 void CThreadTestPolicy::DoCancel() |
206 { |
232 { |
207 LOG_FUNC |
233 OstTraceFunctionEntry1( CTHREADTESTPOLICY_DOCANCEL_ENTRY, this ); |
208 |
234 |
209 iTestCase->Cancel(); |
235 iTestCase->Cancel(); |
210 LOG_POINT(1) |
236 OstTrace0(TRACE_NORMAL, CTHREADTESTPOLICY_DOCANCEL, ">> Debug point: 1"); |
211 TInt err(iTestThread.LogonCancel(iStatus)); |
237 TInt err(iTestThread.LogonCancel(iStatus)); |
212 if(err != KErrNone) |
238 if(err != KErrNone) |
213 { |
239 { |
214 RDebug::Printf("Unable to cancel thread logon: %d",err); |
240 OstTrace1(TRACE_NORMAL, CTHREADTESTPOLICY_DOCANCEL_DUP01, "Unable to cancel thread logon: %d",err); |
215 } |
241 } |
216 LOG_POINT(2) |
242 OstTrace0(TRACE_NORMAL, CTHREADTESTPOLICY_DOCANCEL_DUP02, ">> Debug point: 2"); |
217 TRequestStatus cancelStatus; |
243 TRequestStatus cancelStatus; |
218 iTestThread.Logon(cancelStatus); |
244 iTestThread.Logon(cancelStatus); |
219 LOG_POINT(3) |
245 OstTrace0(TRACE_NORMAL, CTHREADTESTPOLICY_DOCANCEL_DUP03, ">> Debug point: 3"); |
220 iTestThread.Kill(KErrCancel); |
246 iTestThread.Kill(KErrCancel); |
221 LOG_POINT(4) |
247 OstTrace0(TRACE_NORMAL, CTHREADTESTPOLICY_DOCANCEL_DUP04, ">> Debug point: 4"); |
222 User::RequestComplete(iNotifierStatus,cancelStatus.Int()); |
248 User::RequestComplete(iNotifierStatus,cancelStatus.Int()); |
|
249 OstTraceFunctionExit1( CTHREADTESTPOLICY_DOCANCEL_EXIT, this ); |
223 } |
250 } |
224 |
251 |
225 TInt CThreadTestPolicy::ThreadFunction(TAny* aThreadParameter) |
252 TInt CThreadTestPolicy::ThreadFunction(TAny* aThreadParameter) |
226 { |
253 { |
227 LOG_CFUNC |
254 OstTraceFunctionEntry0( CTHREADTESTPOLICY_THREADFUNCTION_ENTRY); |
228 |
255 |
229 TInt err(KErrNone); |
256 TInt err(KErrNone); |
230 TInt leaveCode(KErrNone); |
257 TInt leaveCode(KErrNone); |
231 |
258 |
232 HBufC* testCaseId = reinterpret_cast<HBufC*>(aThreadParameter); |
259 HBufC* testCaseId = reinterpret_cast<HBufC*>(aThreadParameter); |
233 |
260 |
234 // Create the cleanup stack for this thread |
261 // Create the cleanup stack for this thread |
235 CTrapCleanup* cleanup = CTrapCleanup::New(); |
262 CTrapCleanup* cleanup = CTrapCleanup::New(); |
236 if(cleanup == NULL) |
263 if(cleanup == NULL) |
237 { |
264 { |
|
265 OstTraceFunctionExitExt( CTHREADTESTPOLICY_THREADFUNCTION_EXIT, 0, KErrNoMemory ); |
238 return KErrNoMemory; |
266 return KErrNoMemory; |
239 } |
267 } |
240 |
268 |
241 TRAP(leaveCode,err = CThreadTestPolicy::DoTestL(*testCaseId)); |
269 TRAP(leaveCode,err = CThreadTestPolicy::DoTestL(*testCaseId)); |
242 if(leaveCode != KErrNone) |
270 if(leaveCode != KErrNone) |
243 { |
271 { |
244 RDebug::Printf("<Error %d> Thread '%S' DoTest",leaveCode,&testCaseId); |
272 OstTraceExt2(TRACE_NORMAL, CTHREADTESTPOLICY_THREADFUNCTION, "<Error %d> Thread '%S' DoTest",leaveCode, *testCaseId); |
245 err = leaveCode; |
273 err = leaveCode; |
246 } |
274 } |
247 |
275 |
248 delete cleanup; |
276 delete cleanup; |
|
277 OstTraceFunctionExitExt( CTHREADTESTPOLICY_THREADFUNCTION_EXIT_DUP01, 0, err ); |
249 return err; |
278 return err; |
250 } |
279 } |
251 |
280 |
252 |
281 |
253 TInt CThreadTestPolicy::DoTestL(const TDesC& aTestCaseId) |
282 TInt CThreadTestPolicy::DoTestL(const TDesC& aTestCaseId) |
254 { |
283 { |
255 LOG_CFUNC |
284 OstTraceFunctionEntryExt( CTHREADTESTPOLICY_DOTESTL_ENTRY, 0 ); |
256 TInt err(KErrNone); |
285 TInt err(KErrNone); |
257 |
286 |
258 // Create a new active scheduler for this thread |
287 // Create a new active scheduler for this thread |
259 CActiveScheduler* sched = new (ELeave) CActiveScheduler; |
288 CActiveScheduler* sched = new (ELeave) CActiveScheduler; |
260 CleanupStack::PushL(sched); |
289 CleanupStack::PushL(sched); |
279 CleanupStack::PopAndDestroy(testCase); |
308 CleanupStack::PopAndDestroy(testCase); |
280 |
309 |
281 // Destroy the active scheduler |
310 // Destroy the active scheduler |
282 CleanupStack::PopAndDestroy(sched); |
311 CleanupStack::PopAndDestroy(sched); |
283 |
312 |
|
313 OstTraceFunctionExitExt( CTHREADTESTPOLICY_DOTESTL_EXIT, 0, err ); |
284 return err; |
314 return err; |
285 } |
315 } |
286 |
316 |
287 void CThreadTestPolicy::RunL() |
317 void CThreadTestPolicy::RunL() |
288 { |
318 { |
289 LOG_FUNC |
319 OstTraceFunctionEntry1( CTHREADTESTPOLICY_RUNL_ENTRY, this ); |
290 TInt completionCode(iStatus.Int()); |
320 TInt completionCode(iStatus.Int()); |
291 |
321 |
292 TExitType exitType(iTestThread.ExitType()); |
322 TExitType exitType(iTestThread.ExitType()); |
293 TExitCategoryName exitName(iTestThread.ExitCategory()); |
323 TExitCategoryName exitName(iTestThread.ExitCategory()); |
294 TInt exitReason(iTestThread.ExitReason()); |
324 TInt exitReason(iTestThread.ExitReason()); |
295 RDebug::Printf("Test thread '%S' completed with completion code %d",&iTestThread.Name(),completionCode); |
325 OstTraceExt2(TRACE_NORMAL, CTHREADTESTPOLICY_RUNL, "Test thread '%S' completed with completion code %d",iTestThread.Name(),completionCode); |
296 |
326 |
297 switch(exitType) |
327 switch(exitType) |
298 { |
328 { |
299 // The test thread has panicked |
329 // The test thread has panicked |
300 // This will occur if test API panics or RTest expression is false (i.e. test case fails) |
330 // This will occur if test API panics or RTest expression is false (i.e. test case fails) |
301 case EExitPanic: |
331 case EExitPanic: |
302 { |
332 { |
303 RDebug::Printf("Test thread '%S' has panicked with category '%S' reason %d", |
333 OstTraceExt3(TRACE_NORMAL, CTHREADTESTPOLICY_RUNL_DUP01, "Test thread '%S' has panicked with category '%S' reason %d", |
304 &iTestThread.Name(),&exitName,exitReason); |
334 iTestThread.Name(),exitName,exitReason); |
305 // May require to stop and start host/client USB depending on what panic category it is |
335 // May require to stop and start host/client USB depending on what panic category it is |
306 // can no longer trust RUsbHubDriver/RDevUsbcClient to be in good state |
336 // can no longer trust RUsbHubDriver/RDevUsbcClient to be in good state |
307 completionCode = KErrAbort; |
337 completionCode = KErrAbort; |
308 } |
338 } |
309 break; |
339 break; |
310 |
340 |
311 // The thread has been terminated |
341 // The thread has been terminated |
312 case EExitTerminate: |
342 case EExitTerminate: |
313 { |
343 { |
314 RDebug::Printf("Test thread '%S' terminated with category %s reason %d", |
344 OstTraceExt3(TRACE_NORMAL, CTHREADTESTPOLICY_RUNL_DUP02, "Test thread '%S' terminated with category %s reason %d", |
315 &iTestThread.Name(),&exitName,exitReason); |
345 iTestThread.Name(),exitName,exitReason); |
316 } |
346 } |
317 break; |
347 break; |
318 |
348 |
319 // The thread has been killed |
349 // The thread has been killed |
320 // This will occur when the test thread executes normally or is cancelled |
350 // This will occur when the test thread executes normally or is cancelled |
321 case EExitKill: |
351 case EExitKill: |
322 { |
352 { |
323 RDebug::Printf("Test thread '%S' has been killed with reason %d",&iTestThread.Name(),exitReason); |
353 OstTraceExt2(TRACE_NORMAL, CTHREADTESTPOLICY_RUNL_DUP03, "Test thread '%S' has been killed with reason %d",iTestThread.Name(),exitReason); |
324 } |
354 } |
325 break; |
355 break; |
326 |
356 |
327 // These cases should not occur at this stage |
357 // These cases should not occur at this stage |
328 case EExitPending: //follow through |
358 case EExitPending: //follow through |