31 namespace NUnitTesting_USBDI |
35 namespace NUnitTesting_USBDI |
32 { |
36 { |
33 |
37 |
34 CTestCaseController* CTestCaseController::NewL(CTestEngine& aTestEngine,TBool aHostRole) |
38 CTestCaseController* CTestCaseController::NewL(CTestEngine& aTestEngine,TBool aHostRole) |
35 { |
39 { |
|
40 OstTraceFunctionEntryExt( CTESTCASECONTROLLER_NEWL_ENTRY, 0 ); |
36 CTestCaseController* self = new (ELeave) CTestCaseController(aTestEngine,aHostRole); |
41 CTestCaseController* self = new (ELeave) CTestCaseController(aTestEngine,aHostRole); |
37 CleanupStack::PushL(self); |
42 CleanupStack::PushL(self); |
38 self->ConstructL(); |
43 self->ConstructL(); |
39 CleanupStack::Pop(self); |
44 CleanupStack::Pop(self); |
|
45 OstTraceFunctionExit1( CTESTCASECONTROLLER_NEWL_EXIT, ( TUint )( self ) ); |
40 return self; |
46 return self; |
41 } |
47 } |
42 |
48 |
43 |
49 |
44 CTestCaseController::CTestCaseController(CTestEngine& aTestEngine,TBool aHostRole) |
50 CTestCaseController::CTestCaseController(CTestEngine& aTestEngine,TBool aHostRole) |
45 : CActive(EPriorityStandard), |
51 : CActive(EPriorityStandard), |
46 iTestEngine(aTestEngine), |
52 iTestEngine(aTestEngine), |
47 iHostRole(aHostRole) |
53 iHostRole(aHostRole) |
48 { |
54 { |
|
55 OstTraceFunctionEntryExt( CTESTCASECONTROLLER_CTESTCASECONTROLLER_ENTRY, this ); |
49 // Add to current threads active scheduler |
56 // Add to current threads active scheduler |
50 CActiveScheduler::Add(this); |
57 CActiveScheduler::Add(this); |
|
58 OstTraceFunctionExit1( CTESTCASECONTROLLER_CTESTCASECONTROLLER_EXIT, this ); |
51 } |
59 } |
52 |
60 |
53 |
61 |
54 CTestCaseController::~CTestCaseController() |
62 CTestCaseController::~CTestCaseController() |
55 { |
63 { |
56 LOG_FUNC |
64 OstTraceFunctionEntry1( CTESTCASECONTROLLER_CTESTCASECONTROLLER_ENTRY_DUP01, this ); |
57 |
65 |
58 Cancel(); // Cancels any oustanding test cases |
66 Cancel(); // Cancels any oustanding test cases |
59 |
67 |
60 delete iTestPolicy; |
68 delete iTestPolicy; |
61 |
69 |
62 if(iHostRole) |
70 if(iHostRole) |
63 { |
71 { |
64 TInt err = User::FreeLogicalDevice(KHostDeviceInterfaceDriverName); |
72 TInt err = User::FreeLogicalDevice(KHostDeviceInterfaceDriverName); |
65 if(err != KErrNone) |
73 if(err != KErrNone) |
66 { |
74 { |
67 RDebug::Printf("<Error %d> Unable to unload driver: %S",err,&KHostDeviceInterfaceDriverName); |
75 OstTraceExt2(TRACE_NORMAL, CTESTCASECONTROLLER_DCTESTCASECONTROLLER, "<Error %d> Unable to unload driver: %S",err,KHostDeviceInterfaceDriverName()); |
68 } |
76 } |
69 |
77 |
70 err = User::FreeLogicalDevice(KHostDeviceDriverName); |
78 err = User::FreeLogicalDevice(KHostDeviceDriverName); |
71 if(err != KErrNone) |
79 if(err != KErrNone) |
72 { |
80 { |
73 RDebug::Printf("<Error %d> Unable to unload driver: %S",err,&KHostDeviceDriverName); |
81 OstTraceExt2(TRACE_NORMAL, CTESTCASECONTROLLER_DCTESTCASECONTROLLER_DUP01, "<Error %d> Unable to unload driver: %S",err,KHostDeviceDriverName()); |
74 } |
82 } |
75 |
83 |
76 err = User::FreeLogicalDevice(KOtgdiLddFileName); |
84 err = User::FreeLogicalDevice(KOtgdiLddFileName); |
77 if(err != KErrNone) |
85 if(err != KErrNone) |
78 { |
86 { |
79 RDebug::Printf("<Error %d> Unable to unload driver: %S",err,&KHostDeviceDriverName); |
87 OstTraceExt2(TRACE_NORMAL, CTESTCASECONTROLLER_DCTESTCASECONTROLLER_DUP02, "<Error %d> Unable to unload driver: %S",err,KHostDeviceDriverName()); |
80 } |
88 } |
81 } |
89 } |
82 else |
90 else |
83 { |
91 { |
84 TInt err(User::FreeLogicalDevice(KClientDeviceDriverName)); |
92 TInt err(User::FreeLogicalDevice(KClientDeviceDriverName)); |
85 if(err != KErrNone) |
93 if(err != KErrNone) |
86 { |
94 { |
87 RDebug::Printf("<Error %d> Unable to unload driver: %S",err,&KClientDeviceDriverName); |
95 OstTraceExt2(TRACE_NORMAL, CTESTCASECONTROLLER_DCTESTCASECONTROLLER_DUP03, "<Error %d> Unable to unload driver: %S",err,KClientDeviceDriverName()); |
88 } |
96 } |
89 } |
97 } |
|
98 OstTraceFunctionExit1( CTESTCASECONTROLLER_CTESTCASECONTROLLER_EXIT_DUP01, this ); |
90 } |
99 } |
91 |
100 |
92 void CTestCaseController::ConstructL() |
101 void CTestCaseController::ConstructL() |
93 { |
102 { |
94 LOG_FUNC |
103 OstTraceFunctionEntry1( CTESTCASECONTROLLER_CONSTRUCTL_ENTRY, this ); |
95 TInt err = KErrNone; |
104 TInt err = KErrNone; |
96 |
105 |
97 _LIT(KLoadingNamedDriverString,"loading driver: %S\n"); |
106 _LIT(KLoadingNamedDriverString,"loading driver: %S\n"); |
98 _LIT(KLoadedNamedDriverString,"loaded driver: %S\n"); |
107 _LIT(KLoadedNamedDriverString,"loaded driver: %S\n"); |
99 |
108 |
100 // loading drivers |
109 // loading drivers |
101 if(iHostRole) |
110 if(iHostRole) |
102 { |
111 { |
103 gtest.Printf(KLoadingNamedDriverString,&KHostDeviceDriverName); |
112 gtest.Printf(KLoadingNamedDriverString,&KHostDeviceDriverName); |
|
113 OstTraceExt1(TRACE_NORMAL, CTESTCASECONTROLLER_CONSTRUCTL, "loading driver: %S\n", KHostDeviceDriverName()); |
104 // Load both Host USB device drivers |
114 // Load both Host USB device drivers |
105 err = User::LoadLogicalDevice(KHostDeviceDriverName); |
115 err = User::LoadLogicalDevice(KHostDeviceDriverName); |
106 gtest((err == KErrNone) || (err == KErrAlreadyExists)); |
116 gtest((err == KErrNone) || (err == KErrAlreadyExists)); |
107 gtest.Printf(KLoadedNamedDriverString,&KHostDeviceDriverName); |
117 gtest.Printf(KLoadedNamedDriverString,&KHostDeviceDriverName); |
108 |
118 OstTraceExt1(TRACE_NORMAL, CTESTCASECONTROLLER_CONSTRUCTL_DUP01, "loaded driver: %S\n",KHostDeviceDriverName()); |
109 RDebug::Print(KLoadingNamedDriverString,&KHostDeviceInterfaceDriverName); |
119 |
|
120 OstTraceExt1(TRACE_NORMAL, CTESTCASECONTROLLER_CONSTRUCTL_DUP02, "loading driver: %S\n",KHostDeviceInterfaceDriverName()); |
110 err = User::LoadLogicalDevice(KHostDeviceInterfaceDriverName); |
121 err = User::LoadLogicalDevice(KHostDeviceInterfaceDriverName); |
111 gtest((err == KErrNone) || (err == KErrAlreadyExists)); |
122 gtest((err == KErrNone) || (err == KErrAlreadyExists)); |
112 gtest.Printf(KLoadedNamedDriverString,&KHostDeviceInterfaceDriverName); |
123 gtest.Printf(KLoadedNamedDriverString,&KHostDeviceInterfaceDriverName); |
|
124 OstTraceExt1(TRACE_NORMAL, CTESTCASECONTROLLER_CONSTRUCTL_DUP03, "loaded driver: %S\n",KHostDeviceInterfaceDriverName()); |
113 |
125 |
114 // If test cases are running USB host side actions |
126 // If test cases are running USB host side actions |
115 // then run each test case in its own thread |
127 // then run each test case in its own thread |
116 iTestPolicy = CThreadTestPolicy::NewL(); |
128 iTestPolicy = CThreadTestPolicy::NewL(); |
117 } |
129 } |
118 else |
130 else |
119 { |
131 { |
120 |
132 |
121 // Load the USB client driver |
133 // Load the USB client driver |
122 gtest.Printf(KLoadingNamedDriverString,&KClientDeviceDriverName); |
134 gtest.Printf(KLoadingNamedDriverString,&KClientDeviceDriverName); |
|
135 OstTraceExt1(TRACE_NORMAL, CTESTCASECONTROLLER_CONSTRUCTL_DUP04, "loading driver: %S\n",KClientDeviceDriverName()); |
123 err = User::LoadLogicalDevice(KClientDeviceDriverName); |
136 err = User::LoadLogicalDevice(KClientDeviceDriverName); |
124 gtest((err == KErrNone) || (err == KErrAlreadyExists)); |
137 gtest((err == KErrNone) || (err == KErrAlreadyExists)); |
125 gtest.Printf(KLoadedNamedDriverString,&KClientDeviceDriverName); |
138 gtest.Printf(KLoadedNamedDriverString,&KClientDeviceDriverName); |
|
139 OstTraceExt1(TRACE_NORMAL, CTESTCASECONTROLLER_CONSTRUCTL_DUP05, "loaded driver: %S\n",KClientDeviceDriverName()); |
126 |
140 |
127 // Run each test case in the main thread as its not new API |
141 // Run each test case in the main thread as its not new API |
128 // and not expected to panic |
142 // and not expected to panic |
129 iTestPolicy = CBasicTestPolicy::NewL(); |
143 iTestPolicy = CBasicTestPolicy::NewL(); |
130 } |
144 } |
134 gtest.Next(iTestCaseId); |
148 gtest.Next(iTestCaseId); |
135 |
149 |
136 // Run the test case |
150 // Run the test case |
137 iTestPolicy->RunTestCaseL(iTestCaseId,iStatus); |
151 iTestPolicy->RunTestCaseL(iTestCaseId,iStatus); |
138 SetActive(); |
152 SetActive(); |
|
153 OstTraceFunctionExit1( CTESTCASECONTROLLER_CONSTRUCTL_EXIT, this ); |
139 } |
154 } |
140 |
155 |
141 |
156 |
142 void CTestCaseController::DoCancel() |
157 void CTestCaseController::DoCancel() |
143 { |
158 { |
|
159 OstTraceFunctionEntry1( CTESTCASECONTROLLER_DOCANCEL_ENTRY, this ); |
144 // Cancel the outstanding test case running |
160 // Cancel the outstanding test case running |
145 |
161 |
146 iTestPolicy->Cancel(); |
162 iTestPolicy->Cancel(); |
|
163 OstTraceFunctionExit1( CTESTCASECONTROLLER_DOCANCEL_EXIT, this ); |
147 } |
164 } |
148 |
165 |
149 |
166 |
150 void CTestCaseController::RunL() |
167 void CTestCaseController::RunL() |
151 { |
168 { |
152 LOG_FUNC |
169 OstTraceFunctionEntry1( CTESTCASECONTROLLER_RUNL_ENTRY, this ); |
153 |
170 |
154 // Retrieve the completion code of the last test case run |
171 // Retrieve the completion code of the last test case run |
155 TInt err(iStatus.Int()); |
172 TInt err(iStatus.Int()); |
156 |
173 |
157 TBuf<64> log; |
174 TBuf<64> log; |
158 if(err != KErrNone) |
175 if(err != KErrNone) |
159 { |
176 { |
160 iTestCasesResults.Append(EFalse); |
177 iTestCasesResults.Append(EFalse); |
161 gtest.Printf(_L("FAILED err=%d\n"),err); |
178 gtest.Printf(_L("FAILED err=%d\n"),err); |
|
179 OstTrace1(TRACE_NORMAL, CTESTCASECONTROLLER_RUNL, "FAILED err=%d\n",err); |
162 } |
180 } |
163 else |
181 else |
164 { |
182 { |
165 iTestCasesResults.Append(ETrue); |
183 iTestCasesResults.Append(ETrue); |
166 gtest.Printf(_L("PASSED\n")); |
184 gtest.Printf(_L("PASSED\n")); |
|
185 OstTrace0(TRACE_NORMAL, CTESTCASECONTROLLER_RUNL_DUP01, "PASSED\n"); |
167 } |
186 } |
168 |
187 |
169 // Get the identity of the next test case to run |
188 // Get the identity of the next test case to run |
170 |
189 |
171 err = iTestEngine.NextTestCaseId(iTestCaseId); |
190 err = iTestEngine.NextTestCaseId(iTestCaseId); |
172 if(err == KErrNone) |
191 if(err == KErrNone) |
173 { |
192 { |
174 RDebug::Printf("\n"); |
193 OstTrace0(TRACE_NORMAL, CTESTCASECONTROLLER_RUNL_DUP02, "\n"); |
175 RDebug::Printf("\n"); |
194 OstTrace0(TRACE_NORMAL, CTESTCASECONTROLLER_RUNL_DUP03, "\n"); |
176 RDebug::Printf("\n"); |
195 OstTrace0(TRACE_NORMAL, CTESTCASECONTROLLER_RUNL_DUP04, "\n"); |
177 gtest.Next(iTestCaseId); |
196 gtest.Next(iTestCaseId); |
178 RDebug::Printf(" --------------------"); |
197 OstTrace0(TRACE_NORMAL, CTESTCASECONTROLLER_RUNL_DUP05, " --------------------"); |
179 RDebug::Printf("\n"); |
198 OstTrace0(TRACE_NORMAL, CTESTCASECONTROLLER_RUNL_DUP06, "\n"); |
180 RDebug::Printf("\n"); |
199 OstTrace0(TRACE_NORMAL, CTESTCASECONTROLLER_RUNL_DUP07, "\n"); |
181 RDebug::Printf("\n"); |
200 OstTrace0(TRACE_NORMAL, CTESTCASECONTROLLER_RUNL_DUP08, "\n"); |
182 |
201 |
183 // Run the next test case |
202 // Run the next test case |
184 |
203 |
185 iTestPolicy->RunTestCaseL(iTestCaseId,iStatus); |
204 iTestPolicy->RunTestCaseL(iTestCaseId,iStatus); |
186 SetActive(); |
205 SetActive(); |
187 } |
206 } |
188 else if(err == KErrNotFound) |
207 else if(err == KErrNotFound) |
189 { |
208 { |
190 RDebug::Printf("All specified test cases performed"); |
209 OstTrace0(TRACE_NORMAL, CTESTCASECONTROLLER_RUNL_DUP09, "All specified test cases performed"); |
191 RDebug::Printf("----------------------------------"); |
210 OstTrace0(TRACE_NORMAL, CTESTCASECONTROLLER_RUNL_DUP10, "----------------------------------"); |
192 |
211 |
193 |
212 |
194 // count nb failures |
213 // count nb failures |
195 TUint nbFailures = 0; |
214 TUint nbFailures = 0; |
196 for(TInt test = 0; test < iTestCasesResults.Count() ; test++) |
215 for(TInt test = 0; test < iTestCasesResults.Count() ; test++) |
200 // ...even if it is a repeat. |
219 // ...even if it is a repeat. |
201 { |
220 { |
202 nbFailures++; |
221 nbFailures++; |
203 } |
222 } |
204 } |
223 } |
205 RDebug::Printf("There are %d test case results, %d failures", iTestCasesResults.Count(), nbFailures); |
224 OstTraceExt2(TRACE_NORMAL, CTESTCASECONTROLLER_RUNL_DUP11, "There are %d test case results, %d failures", iTestCasesResults.Count(), nbFailures); |
206 |
225 |
207 // Number of tests that should have been run (including repeats) |
226 // Number of tests that should have been run (including repeats) |
208 TUint nbTests = iTestEngine.TestCasesIdentities().Count() * iTestEngine.NumRepeats(); |
227 TUint nbTests = iTestEngine.TestCasesIdentities().Count() * iTestEngine.NumRepeats(); |
209 if(nbTests!=iTestCasesResults.Count()) |
228 if(nbTests!=iTestCasesResults.Count()) |
210 { |
229 { |
211 RDebug::Printf("The number of tests that should have been run (%d) DOES NOT EQUAL the actual number of tests run (%d).", |
230 OstTraceExt2(TRACE_NORMAL, CTESTCASECONTROLLER_RUNL_DUP12, "The number of tests that should have been run (%d) DOES NOT EQUAL the actual number of tests run (%d).", |
212 nbTests, iTestCasesResults.Count()); |
231 nbTests, iTestCasesResults.Count()); |
213 RDebug::Printf("This test suite will now PANIC!"); |
232 OstTrace0(TRACE_NORMAL, CTESTCASECONTROLLER_RUNL_DUP13, "This test suite will now PANIC!"); |
214 } |
233 } |
215 ASSERT((nbTests==iTestCasesResults.Count())); |
234 ASSERT((nbTests==iTestCasesResults.Count())); |
216 |
235 |
217 |
236 |
218 for(TInt repeat = 0; repeat < iTestEngine.NumRepeats() ; repeat++) |
237 for(TInt repeat = 0; repeat < iTestEngine.NumRepeats() ; repeat++) |
219 { |
238 { |
220 if(iTestEngine.NumRepeats() > 1) |
239 if(iTestEngine.NumRepeats() > 1) |
221 { |
240 { |
222 RDebug::Printf("Test Case Loop %d..........", repeat+1); |
241 OstTrace1(TRACE_NORMAL, CTESTCASECONTROLLER_RUNL_DUP14, "Test Case Loop %d..........", repeat+1); |
223 } |
242 } |
224 for(TInt testIndex = 0; testIndex < iTestEngine.TestCasesIdentities().Count() ; testIndex++) |
243 for(TInt testIndex = 0; testIndex < iTestEngine.TestCasesIdentities().Count() ; testIndex++) |
225 { |
244 { |
226 if(iTestCasesResults[testIndex]) |
245 if(iTestCasesResults[testIndex]) |
227 { |
246 { |
228 RDebug::Print(_L("Test Case: %S : PASSED"), (iTestEngine.TestCasesIdentities())[testIndex]); |
247 OstTraceExt1(TRACE_NORMAL, CTESTCASECONTROLLER_RUNL_DUP15, "Test Case: %S : PASSED", *(iTestEngine.TestCasesIdentities())[testIndex]); |
229 } |
248 } |
230 else |
249 else |
231 { |
250 { |
232 RDebug::Print(_L("Test Case: %S : FAILED"), (iTestEngine.TestCasesIdentities())[testIndex]); |
251 OstTraceExt1(TRACE_NORMAL, CTESTCASECONTROLLER_RUNL_DUP16, "Test Case: %S : FAILED", *(iTestEngine.TestCasesIdentities())[testIndex]); |
233 } |
252 } |
234 } |
253 } |
235 } |
254 } |
236 |
255 |
237 RDebug::Printf("CActiveScheduler::Stop CTestCaseController::RunL"); |
256 OstTrace0(TRACE_NORMAL, CTESTCASECONTROLLER_RUNL_DUP17, "CActiveScheduler::Stop CTestCaseController::RunL"); |
238 CActiveScheduler::Stop(); |
257 CActiveScheduler::Stop(); |
239 } |
258 } |
240 else |
259 else |
241 { |
260 { |
242 RDebug::Printf("<Error %d> Unknown error from CTestEngine::NextTestCaseId",err); |
261 OstTrace1(TRACE_NORMAL, CTESTCASECONTROLLER_RUNL_DUP18, "<Error %d> Unknown error from CTestEngine::NextTestCaseId",err); |
243 User::Leave(err); |
262 User::Leave(err); |
244 } |
263 } |
|
264 OstTraceFunctionExit1( CTESTCASECONTROLLER_RUNL_EXIT, this ); |
245 } |
265 } |
246 |
266 |
247 |
267 |
248 TInt CTestCaseController::RunError(TInt aError) |
268 TInt CTestCaseController::RunError(TInt aError) |
249 { |
269 { |
250 LOG_FUNC |
270 OstTraceFunctionEntryExt( CTESTCASECONTROLLER_RUNERROR_ENTRY, this ); |
251 |
271 |
252 switch(aError) |
272 switch(aError) |
253 { |
273 { |
254 case KErrNoMemory: //follow through |
274 case KErrNoMemory: //follow through |
255 default: |
275 default: |
256 // Panic the test module |
276 // Panic the test module |
257 gtest(EFalse); |
277 gtest(EFalse); |
258 break; |
278 break; |
259 } |
279 } |
|
280 OstTraceFunctionExitExt( CTESTCASECONTROLLER_RUNERROR_EXIT, this, KErrNone ); |
260 return KErrNone; |
281 return KErrNone; |
261 } |
282 } |
262 |
283 |
263 |
284 |
264 } |
285 } |