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 "testcase0676.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-0676");
35 const TTestCaseFactoryReceipt<CTestCase0676> CTestCase0676::iFactoryReceipt(KTestCaseId);
37 CTestCase0676* CTestCase0676::NewL(TBool aHost)
40 CTestCase0676* self = new (ELeave) CTestCase0676(aHost);
41 CleanupStack::PushL(self);
43 CleanupStack::Pop(self);
48 CTestCase0676::CTestCase0676(TBool aHost)
49 : CTestCaseRoot(KTestCaseId, aHost)
59 void CTestCase0676::ConstructL()
62 iWDTimer = CTestCaseWatchdog::NewL();
63 iRepeats = OPEN_REPEATS;
69 CTestCase0676::~CTestCase0676()
79 void CTestCase0676::ExecuteTestCaseL()
82 iCaseStep = EPreconditions;
84 iRepeats = KOperationRetriesMax; // VBus event rise retries
86 CActiveScheduler::Add(this);
92 void CTestCase0676::DoCancel()
101 void CTestCase0676::CancelKB(CTestCaseRoot *pThis)
104 CTestCase0676 * p = REINTERPRET_CAST(CTestCase0676 *,pThis);
105 // cancel any pending call, and then complete our active obj with a cancel value
106 p->iConsole->ReadCancel();
111 void CTestCase0676::CancelNotify(CTestCaseRoot *pThis)
114 CTestCase0676 * p = REINTERPRET_CAST(CTestCase0676 *,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 CTestCase0676::DescribePreconditions()
124 test.Printf(_L("Insert 'A' connector beforehand.\n"));
127 void CTestCase0676::ContinueAfter(TTimeIntervalMicroSeconds32 aMicroSecs, TCaseSteps aStep)
129 LOG_VERBOSE2(_L("Wait %dms before drop VBus"), (TInt)(aMicroSecs.Int()/1000));
130 iTimer.After(iStatus, aMicroSecs);
135 // handle event completion
136 void CTestCase0676::RunStepL()
139 // Obtain the completion code for this CActive obj.
140 TInt completionCode(iStatus.Int());
141 TBuf<MAX_DSTRLEN> aDescription;
148 iCaseStep = ELoadLdd;
151 iCaseStep = ELoadLdd;
155 // prompt to insert connector
156 test.Printf(KInsertAConnectorPrompt);
157 test.Printf(KPressAnyKeyToContinue);
162 // 1. load the LDD and init.
167 iCaseStep = EDetectAPlug;
171 // 2. detect 'A' plug now
173 if (KTestCaseWatchdogTO == iStatus.Int())
175 return TestFailed(KErrAbort, _L("User response too slow - FAILED!"));
178 // if doing this test in /AUTO mode, we would fail this now
179 // however if we can control ID_PIN through an API in future, we turn in on now.
180 if (!otgIdPinPresent())
182 test.Printf(KInsertAConnectorPrompt);
183 test.Printf(KPressAnyKeyToContinue);
186 iCaseStep = EDetectAPlug;
190 iCaseStep = ELoopDriveVBus;
195 // 3. Control/branch step in the loop
199 iCaseStep = ELoopDriveVBus;
203 iCaseStep = EUnloadLdd;
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 );
217 // turn on VBus, since the call is not a Queing a-sync call we do this after the async call
218 err = otgBusRequest(); // ok to turn on VBus now
221 return TestFailed(KErrAbort, _L("Raise Vbus - RUsbOtgDriver::BusRequest() FAILED!"));
223 iCaseStep = ELoopVerifyVBus;
224 iWDTimer->IssueRequest(KDelayDurationForLocalTrigger, this, &CancelNotify);
228 case ELoopVerifyVBus:
229 // 5. get VBus rise event
230 if (KTestCaseWatchdogTO == iStatus.Int())
232 return TestFailed(KErrAbort, _L("Vbus rise not signalled in time - FAILED!"));
236 otgQueueOtgVbusNotification( iOTGVBus, iStatus );
237 otgCancelOtgVbusNotification();
238 User::WaitForRequest(iStatus);
241 if (iOTGVBus != RUsbOtgDriver::EVbusHigh)
244 return TestFailed(KErrAbort, _L("Vbus rise NOT 'seen' - FAILED!"));
247 // Double-check using the API in a syncronous way too
248 // NOTE: once again this is to explore timing issues
249 if (!otgVbusPresent())
251 return TestFailed(KErrAbort, _L("Vbus syncronous call error - FAILED!"));
253 iCaseStep = ELoopWait;
257 case ELoopWait: // 6. wait 50ms after applying Vbus before we are allowed to
258 ContinueAfter(KDelayBeforeBusDropUs, ELoopDropVBus);
263 otgQueueOtgVbusNotification(iOTGVBus, iStatus );
264 // drop Vbus now, since the call is not a Queing a-sync call we do this after the async call
267 iCaseStep = ELoopVerifyDrop;
268 iWDTimer->IssueRequest(KDelayDurationForLocalTrigger, this, &CancelNotify);
271 case ELoopVerifyDrop:
272 // 8. get Vbus low event
273 if (KTestCaseWatchdogTO == iStatus.Int())
275 return TestFailed(KErrAbort, _L("Vbus drop not signalled in time - FAILED!"));
280 otgQueueOtgVbusNotification( iOTGVBus, iStatus );
281 otgCancelOtgVbusNotification();
282 User::WaitForRequest(iStatus);
284 if (iOTGVBus != RUsbOtgDriver::EVbusLow)
286 return TestFailed(KErrAbort, _L("Vbus drop NOT 'seen' - FAILED!"));
289 // test again using the 'syncronous' variation
290 if (otgVbusPresent())
292 return TestFailed(KErrAbort, _L("Vbus syncronous call error - FAILED!"));
295 // wait 50ms and then go back to beginning
296 ContinueAfter(KDelayBeforeBusDropUs, ELoopControl);
301 if (EFalse == StepUnloadLDD())
302 return TestFailed(KErrAbort,_L("unload Ldd failure"));
304 iCaseStep = ELastStep;
313 test.Printf(_L("<Error> unknown test step"));
315 return (TestFailed(KErrCorrupt, _L("<Error> unknown test step")));