First public contribution.
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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
19 #include <e32std_private.h>
20 #include <u32std.h> // unicode builds
22 #include <e32base_private.h>
23 #include <e32Test.h> // RTest headder
24 #include "testcaseroot.h"
25 #include "testcasewd.h"
26 #include "testcase0675.h"
28 #define _REPEATS (oOpenIterations*3)
32 // the name below is used to add a pointer to our construction method to a pointer MAP in
34 _LIT(KTestCaseId,"PBASE-USB_OTGDI-0675");
35 const TTestCaseFactoryReceipt<CTestCase0675> CTestCase0675::iFactoryReceipt(KTestCaseId);
37 CTestCase0675* CTestCase0675::NewL(TBool aHost)
40 CTestCase0675* self = new (ELeave) CTestCase0675(aHost);
41 CleanupStack::PushL(self);
43 CleanupStack::Pop(self);
48 CTestCase0675::CTestCase0675(TBool aHost)
49 : CTestCaseRoot(KTestCaseId, aHost)
59 void CTestCase0675::ConstructL()
62 iWDTimer = CTestCaseWatchdog::NewL();
63 iRepeats = OPEN_REPEATS;
69 CTestCase0675::~CTestCase0675()
79 void CTestCase0675::ExecuteTestCaseL()
82 iCaseStep = EPreconditions;
84 iRepeats = KOperationRetriesMax; // VBus event rise retries
86 CActiveScheduler::Add(this);
92 void CTestCase0675::DoCancel()
101 void CTestCase0675::CancelKB(CTestCaseRoot *pThis)
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();
111 void CTestCase0675::CancelNotify(CTestCaseRoot *pThis)
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);
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()
124 test.Printf(_L("Insert 'A' connector beforehand.\n"));
128 void CTestCase0675::ContinueAfter(TTimeIntervalMicroSeconds32 aMicroSecs, TCaseSteps aStep)
130 LOG_VERBOSE2(_L("Wait %dms before drop VBus"), (TInt)(aMicroSecs.Int()/1000));
131 iTimer.After(iStatus, aMicroSecs);
136 // handle event completion
137 void CTestCase0675::RunStepL()
140 // Obtain the completion code for this CActive obj.
141 TInt completionCode(iStatus.Int());
142 TBuf<MAX_DSTRLEN> aDescription;
149 iCaseStep = ELoadLdd;
152 iCaseStep = ELoadLdd;
156 // prompt to insert connector
157 test.Printf(KInsertAConnectorPrompt);
158 test.Printf(KPressAnyKeyToContinue);
162 // 1. load the LDD and init.
169 iCaseStep = ELoopDriveVBus1;
171 iCaseStep = EDetectAPlug;
175 // 2. detect 'A' plug now
177 if (KTestCaseWatchdogTO == iStatus.Int())
179 return TestFailed(KErrAbort, _L("User response too slow - FAILED!"));
181 if (!otgIdPinPresent())
183 test.Printf(KInsertAConnectorPrompt);
184 test.Printf(KPressAnyKeyToContinue);
186 iCaseStep = EDetectAPlug;
190 iCaseStep = ELoopDriveVBus1;
195 // 3. Control/branch step in the loop
199 iCaseStep = ELoopDriveVBus1;
203 iCaseStep = EUnloadLdd;
209 case ELoopDriveVBus1:
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 );
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
222 return TestFailed(KErrAbort, _L("Raise Vbus - RUsbOtgDriver::BusRequest() FAILED!"));
224 iCaseStep = ELoopVerifyVBus1;
225 iWDTimer->IssueRequest(KDelayDurationForLocalTrigger, this, &CancelNotify);
229 // 5. get VBus rise event
230 case ELoopVerifyVBus1:
231 if (KTestCaseWatchdogTO == iStatus.Int())
233 return TestFailed(KErrAbort, _L("Vbus rise not signalled in time - FAILED!"));
237 // check using the API in a syncronous way too
238 if (!otgVbusPresent())
240 return TestFailed(KErrAbort, _L("Vbus syncronous call error - FAILED!"));
242 iCaseStep = ELoopWait;
246 // 6. DRIVE/claim VBUS 2nd time
247 case ELoopDriveVBus2:
249 test.Printf(_L("Drive VBus double, iteration %d/%d\n"), OPEN_REPEATS-iRepeats+1, OPEN_REPEATS);
251 err = otgBusRequest(); // duplicate turn on VBus, we expect an error
252 if (KErrUsbOtgVbusAlreadyRaised != err)
254 return TestFailed(KErrAbort, _L("Raise Vbus - RUsbOtgDriver::BusRequest() unexpected result!"));
256 iCaseStep = ELoopVerifyVBus2;
261 // 7 - make sure that the error did not end up killing the bus
262 case ELoopVerifyVBus2:
263 if (!otgVbusPresent())
265 return TestFailed(KErrAbort, _L("Raise Vbus twice resulted in session drop"));
267 iCaseStep = ELoopWait;
272 // 9. wait 50ms after applying Vbus before we are allowed to drop again
274 ContinueAfter(KDelayBeforeBusDropUs, ELoopDropVBus);
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
283 iCaseStep = ELoopVerifyDrop;
284 iWDTimer->IssueRequest(KDelayDurationForLocalTrigger, this, &CancelNotify);
287 case ELoopVerifyDrop:
288 // 11. get Vbus low event
289 if (KTestCaseWatchdogTO == iStatus.Int())
291 return TestFailed(KErrAbort, _L("Vbus drop not signalled in time - FAILED!"));
296 otgQueueOtgVbusNotification( iOTGVBus, iStatus );
297 otgCancelOtgVbusNotification();
298 User::WaitForRequest(iStatus);
300 if (iOTGVBus != RUsbOtgDriver::EVbusLow)
302 return TestFailed(KErrAbort, _L("Vbus drop NOT 'seen' - FAILED!"));
305 // test again using the 'syncronous' variation
306 if (otgVbusPresent())
308 return TestFailed(KErrAbort, _L("Vbus syncronous call error - FAILED!"));
311 // wait 50ms and then go back to beginning
312 ContinueAfter(KDelayBeforeBusDropUs, ELoopControl);
317 if (EFalse == StepUnloadLDD())
318 return TestFailed(KErrAbort,_L("unload Ldd failure"));
320 iCaseStep = ELastStep;
329 test.Printf(_L("<Error> unknown test step"));
331 return (TestFailed(KErrCorrupt, _L("<Error> unknown test step")));