|
1 // Copyright (c) 2007-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 // @internalComponent |
|
15 // |
|
16 // |
|
17 |
|
18 #include <e32std.h> |
|
19 #include <e32std_private.h> |
|
20 #include <u32std.h> // unicode builds |
|
21 #include <e32base.h> |
|
22 #include <e32base_private.h> |
|
23 #include <e32Test.h> // RTest headder |
|
24 #include "testcaseroot.h" |
|
25 #include "testcasewd.h" |
|
26 #include "testcase0675.h" |
|
27 |
|
28 #define _REPEATS (oOpenIterations*3) |
|
29 |
|
30 |
|
31 |
|
32 // the name below is used to add a pointer to our construction method to a pointer MAP in |
|
33 // the class factory |
|
34 _LIT(KTestCaseId,"PBASE-USB_OTGDI-0675"); |
|
35 const TTestCaseFactoryReceipt<CTestCase0675> CTestCase0675::iFactoryReceipt(KTestCaseId); |
|
36 |
|
37 CTestCase0675* CTestCase0675::NewL(TBool aHost) |
|
38 { |
|
39 LOG_FUNC |
|
40 CTestCase0675* self = new (ELeave) CTestCase0675(aHost); |
|
41 CleanupStack::PushL(self); |
|
42 self->ConstructL(); |
|
43 CleanupStack::Pop(self); |
|
44 return self; |
|
45 } |
|
46 |
|
47 |
|
48 CTestCase0675::CTestCase0675(TBool aHost) |
|
49 : CTestCaseRoot(KTestCaseId, aHost) |
|
50 { |
|
51 LOG_FUNC |
|
52 |
|
53 } |
|
54 |
|
55 |
|
56 /** |
|
57 ConstructL |
|
58 */ |
|
59 void CTestCase0675::ConstructL() |
|
60 { |
|
61 LOG_FUNC |
|
62 iWDTimer = CTestCaseWatchdog::NewL(); |
|
63 iRepeats = OPEN_REPEATS; |
|
64 |
|
65 BaseConstructL(); |
|
66 } |
|
67 |
|
68 |
|
69 CTestCase0675::~CTestCase0675() |
|
70 { |
|
71 LOG_FUNC |
|
72 |
|
73 Cancel(); |
|
74 delete iWDTimer; |
|
75 |
|
76 } |
|
77 |
|
78 |
|
79 void CTestCase0675::ExecuteTestCaseL() |
|
80 { |
|
81 LOG_FUNC |
|
82 iCaseStep = EPreconditions; |
|
83 |
|
84 iRepeats = KOperationRetriesMax; // VBus event rise retries |
|
85 |
|
86 CActiveScheduler::Add(this); |
|
87 SelfComplete(); |
|
88 |
|
89 } |
|
90 |
|
91 |
|
92 void CTestCase0675::DoCancel() |
|
93 { |
|
94 LOG_FUNC |
|
95 |
|
96 // cancel our timer |
|
97 iTimer.Cancel(); |
|
98 } |
|
99 |
|
100 |
|
101 void CTestCase0675::CancelKB(CTestCaseRoot *pThis) |
|
102 { |
|
103 LOG_FUNC |
|
104 CTestCase0675 * p = REINTERPRET_CAST(CTestCase0675 *,pThis); |
|
105 // cancel any pending call, and then complete our active obj with a cancel value |
|
106 p->iConsole->ReadCancel(); |
|
107 |
|
108 } |
|
109 |
|
110 |
|
111 void CTestCase0675::CancelNotify(CTestCaseRoot *pThis) |
|
112 { |
|
113 LOG_FUNC |
|
114 CTestCase0675 * p = REINTERPRET_CAST(CTestCase0675 *,pThis); |
|
115 // cancel any pending call, and then complete our active obj with a timeout value |
|
116 p->otgCancelOtgVbusNotification(); |
|
117 p->SelfComplete(KTestCaseWatchdogTO); |
|
118 } |
|
119 |
|
120 |
|
121 // This test result depends on all the ID detection tests and the VBus driving and dropping tests have not yet passed |
|
122 void CTestCase0675::DescribePreconditions() |
|
123 { |
|
124 test.Printf(_L("Insert 'A' connector beforehand.\n")); |
|
125 |
|
126 } |
|
127 |
|
128 void CTestCase0675::ContinueAfter(TTimeIntervalMicroSeconds32 aMicroSecs, TCaseSteps aStep) |
|
129 { |
|
130 LOG_VERBOSE2(_L("Wait %dms before drop VBus"), (TInt)(aMicroSecs.Int()/1000)); |
|
131 iTimer.After(iStatus, aMicroSecs); |
|
132 iCaseStep = aStep; |
|
133 SetActive(); |
|
134 } |
|
135 |
|
136 // handle event completion |
|
137 void CTestCase0675::RunStepL() |
|
138 { |
|
139 LOG_FUNC |
|
140 // Obtain the completion code for this CActive obj. |
|
141 TInt completionCode(iStatus.Int()); |
|
142 TBuf<MAX_DSTRLEN> aDescription; |
|
143 TInt err(0); |
|
144 |
|
145 |
|
146 switch(iCaseStep) |
|
147 { |
|
148 case EPreconditions: |
|
149 iCaseStep = ELoadLdd; |
|
150 if (iAutomated) |
|
151 { |
|
152 iCaseStep = ELoadLdd; |
|
153 SelfComplete(); |
|
154 break; |
|
155 } |
|
156 // prompt to insert connector |
|
157 test.Printf(KInsertAConnectorPrompt); |
|
158 test.Printf(KPressAnyKeyToContinue); |
|
159 RequestCharacter(); |
|
160 break; |
|
161 |
|
162 // 1. load the LDD and init. |
|
163 case ELoadLdd: |
|
164 if (!StepLoadLDD()) |
|
165 { |
|
166 break; |
|
167 } |
|
168 if (iAutomated) |
|
169 iCaseStep = ELoopDriveVBus1; |
|
170 else |
|
171 iCaseStep = EDetectAPlug; |
|
172 SelfComplete(); |
|
173 break; |
|
174 |
|
175 // 2. detect 'A' plug now |
|
176 case EDetectAPlug: |
|
177 if (KTestCaseWatchdogTO == iStatus.Int()) |
|
178 { |
|
179 return TestFailed(KErrAbort, _L("User response too slow - FAILED!")); |
|
180 } |
|
181 if (!otgIdPinPresent()) |
|
182 { |
|
183 test.Printf(KInsertAConnectorPrompt); |
|
184 test.Printf(KPressAnyKeyToContinue); |
|
185 RequestCharacter(); |
|
186 iCaseStep = EDetectAPlug; |
|
187 } |
|
188 else |
|
189 { |
|
190 iCaseStep = ELoopDriveVBus1; |
|
191 SelfComplete(); |
|
192 } |
|
193 break; |
|
194 |
|
195 // 3. Control/branch step in the loop |
|
196 case ELoopControl: |
|
197 if (--iRepeats) |
|
198 { |
|
199 iCaseStep = ELoopDriveVBus1; |
|
200 } |
|
201 else |
|
202 { |
|
203 iCaseStep = EUnloadLdd; |
|
204 } |
|
205 SelfComplete(); |
|
206 break; |
|
207 |
|
208 // 4. DRIVE VBUS |
|
209 case ELoopDriveVBus1: |
|
210 iWDTimer->Cancel(); |
|
211 test.Printf(_L("Drive VBus, iteration %d/%d\n"), OPEN_REPEATS-iRepeats+1, OPEN_REPEATS); |
|
212 // test for VBus rise next |
|
213 test.Printf(_L("Waiting for VBus Event\n")); |
|
214 iStatus = KRequestPending; |
|
215 otgQueueOtgVbusNotification( iOTGVBus, iStatus ); |
|
216 SetActive(); |
|
217 |
|
218 // turn on VBus, since the call is not a Queing a-sync call we do this after the async call |
|
219 err = otgBusRequest(); // ok to turn on VBus now |
|
220 if (KErrNone != err) |
|
221 { |
|
222 return TestFailed(KErrAbort, _L("Raise Vbus - RUsbOtgDriver::BusRequest() FAILED!")); |
|
223 } |
|
224 iCaseStep = ELoopVerifyVBus1; |
|
225 iWDTimer->IssueRequest(KDelayDurationForLocalTrigger, this, &CancelNotify); |
|
226 |
|
227 break; |
|
228 |
|
229 // 5. get VBus rise event |
|
230 case ELoopVerifyVBus1: |
|
231 if (KTestCaseWatchdogTO == iStatus.Int()) |
|
232 { |
|
233 return TestFailed(KErrAbort, _L("Vbus rise not signalled in time - FAILED!")); |
|
234 } |
|
235 iWDTimer->Cancel(); |
|
236 |
|
237 // check using the API in a syncronous way too |
|
238 if (!otgVbusPresent()) |
|
239 { |
|
240 return TestFailed(KErrAbort, _L("Vbus syncronous call error - FAILED!")); |
|
241 } |
|
242 iCaseStep = ELoopWait; |
|
243 SelfComplete(); |
|
244 break; |
|
245 |
|
246 // 6. DRIVE/claim VBUS 2nd time |
|
247 case ELoopDriveVBus2: |
|
248 iWDTimer->Cancel(); |
|
249 test.Printf(_L("Drive VBus double, iteration %d/%d\n"), OPEN_REPEATS-iRepeats+1, OPEN_REPEATS); |
|
250 |
|
251 err = otgBusRequest(); // duplicate turn on VBus, we expect an error |
|
252 if (KErrUsbOtgVbusAlreadyRaised != err) |
|
253 { |
|
254 return TestFailed(KErrAbort, _L("Raise Vbus - RUsbOtgDriver::BusRequest() unexpected result!")); |
|
255 } |
|
256 iCaseStep = ELoopVerifyVBus2; |
|
257 SelfComplete(); |
|
258 SetActive(); |
|
259 break; |
|
260 |
|
261 // 7 - make sure that the error did not end up killing the bus |
|
262 case ELoopVerifyVBus2: |
|
263 if (!otgVbusPresent()) |
|
264 { |
|
265 return TestFailed(KErrAbort, _L("Raise Vbus twice resulted in session drop")); |
|
266 } |
|
267 iCaseStep = ELoopWait; |
|
268 SelfComplete(); |
|
269 SetActive(); |
|
270 break; |
|
271 |
|
272 // 9. wait 50ms after applying Vbus before we are allowed to drop again |
|
273 case ELoopWait: |
|
274 ContinueAfter(KDelayBeforeBusDropUs, ELoopDropVBus); |
|
275 break; |
|
276 |
|
277 case ELoopDropVBus: |
|
278 // 10. drop Bus |
|
279 otgQueueOtgVbusNotification(iOTGVBus, iStatus ); |
|
280 // drop Vbus now, since the call is not a Queing a-sync call we do this after the async call |
|
281 otgBusDrop(); |
|
282 SetActive(); |
|
283 iCaseStep = ELoopVerifyDrop; |
|
284 iWDTimer->IssueRequest(KDelayDurationForLocalTrigger, this, &CancelNotify); |
|
285 break; |
|
286 |
|
287 case ELoopVerifyDrop: |
|
288 // 11. get Vbus low event |
|
289 if (KTestCaseWatchdogTO == iStatus.Int()) |
|
290 { |
|
291 return TestFailed(KErrAbort, _L("Vbus drop not signalled in time - FAILED!")); |
|
292 } |
|
293 iWDTimer->Cancel(); |
|
294 |
|
295 // fetch the value |
|
296 otgQueueOtgVbusNotification( iOTGVBus, iStatus ); |
|
297 otgCancelOtgVbusNotification(); |
|
298 User::WaitForRequest(iStatus); |
|
299 |
|
300 if (iOTGVBus != RUsbOtgDriver::EVbusLow) |
|
301 { |
|
302 return TestFailed(KErrAbort, _L("Vbus drop NOT 'seen' - FAILED!")); |
|
303 } |
|
304 |
|
305 // test again using the 'syncronous' variation |
|
306 if (otgVbusPresent()) |
|
307 { |
|
308 return TestFailed(KErrAbort, _L("Vbus syncronous call error - FAILED!")); |
|
309 } |
|
310 |
|
311 // wait 50ms and then go back to beginning |
|
312 ContinueAfter(KDelayBeforeBusDropUs, ELoopControl); |
|
313 break; |
|
314 |
|
315 case EUnloadLdd: |
|
316 // 12. unload |
|
317 if (EFalse == StepUnloadLDD()) |
|
318 return TestFailed(KErrAbort,_L("unload Ldd failure")); |
|
319 |
|
320 iCaseStep = ELastStep; |
|
321 SelfComplete(); |
|
322 break; |
|
323 |
|
324 case ELastStep: |
|
325 TestPassed(); |
|
326 break; |
|
327 |
|
328 default: |
|
329 test.Printf(_L("<Error> unknown test step")); |
|
330 Cancel(); |
|
331 return (TestFailed(KErrCorrupt, _L("<Error> unknown test step"))); |
|
332 } |
|
333 } |
|
334 |
|
335 |