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 "testcase0468.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-0468");
35 const TTestCaseFactoryReceipt<CTestCase0468> CTestCase0468::iFactoryReceipt(KTestCaseId);
37 CTestCase0468* CTestCase0468::NewL(TBool aHost)
40 CTestCase0468* self = new (ELeave) CTestCase0468(aHost);
41 CleanupStack::PushL(self);
43 CleanupStack::Pop(self);
48 CTestCase0468::CTestCase0468(TBool aHost)
49 : CTestCaseRoot(KTestCaseId, aHost)
59 void CTestCase0468::ConstructL()
62 iWDTimer = CTestCaseWatchdog::NewL();
63 iRepeats = OPEN_REPEATS;
69 CTestCase0468::~CTestCase0468()
79 void CTestCase0468::ExecuteTestCaseL()
82 iCaseStep = EPreconditions;
84 iRepeats = KOperationRetriesMax; // VBus event rise retries
86 CActiveScheduler::Add(this);
92 void CTestCase0468::DoCancel()
101 void CTestCase0468::CancelKB(CTestCaseRoot *pThis)
104 CTestCase0468 * p = REINTERPRET_CAST(CTestCase0468 *,pThis);
105 // cancel any pending call, and then complete our active obj with a cancel value
106 p->iConsole->ReadCancel();
111 void CTestCase0468::CancelNotify(CTestCaseRoot *pThis)
114 CTestCase0468 * p = REINTERPRET_CAST(CTestCase0468 *,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 CTestCase0468::DescribePreconditions()
124 test.Printf(_L("Insert 'A' connector beforehand.\n"));
125 test.Printf(_L("ID_PIN detection and VBus driving tests must already pass.\n"));
128 void CTestCase0468::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 CTestCase0468::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);
163 // 1. load the LDD and init.
168 iCaseStep = EDetectAPlug;
172 // 2. detect 'A' plug now
174 if (KTestCaseWatchdogTO == iStatus.Int())
176 return TestFailed(KErrAbort, _L("User response too slow - FAILED!"));
179 // if doing this test in /AUTO mode, we would fail this now
180 // however if we can control ID_PIN through an API in future, we turn in on now.
181 if (!otgIdPinPresent())
183 test.Printf(KInsertAConnectorPrompt);
184 test.Printf(KPressAnyKeyToContinue);
187 iCaseStep = EDetectAPlug;
191 iCaseStep = ELoopDriveVBus;
196 // 3. Control/branch step in the loop
200 iCaseStep = ELoopDriveVBus;
204 iCaseStep = EUnloadLdd;
212 test.Printf(_L("Drive VBus, iteration %d/%d\n"), OPEN_REPEATS-iRepeats+1, OPEN_REPEATS);
213 // test for VBus rise next
214 test.Printf(_L("Waiting for VBus Event\n"));
215 iStatus = KRequestPending;
216 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 = ELoopVerifyVBus;
225 iWDTimer->IssueRequest(KDelayDurationForLocalTrigger, this, &CancelNotify);
229 case ELoopVerifyVBus:
230 // 5. get VBus rise event
231 LOG_VERBOSE2(_L("Post notification val=%d\n\n"), iOTGVBus);
232 if (KTestCaseWatchdogTO == iStatus.Int())
234 return TestFailed(KErrAbort, _L("Vbus rise not signalled in time - FAILED!"));
238 // fetch the current value
239 otgQueueOtgVbusNotification( iOTGVBus, iStatus );
240 otgCancelOtgVbusNotification();
241 User::WaitForRequest(iStatus);
243 if (iOTGVBus != RUsbOtgDriver::EVbusHigh)
246 return TestFailed(KErrAbort, _L("Vbus rise NOT 'seen' - FAILED!"));
249 // Double-check using the API in a syncronous way too
250 // NOTE: once again this is to explore timing issues
251 if (!otgVbusPresent())
253 return TestFailed(KErrAbort, _L("Vbus syncronous call error - FAILED!"));
255 iCaseStep = ELoopWait;
259 case ELoopWait: // 6. wait 50ms after applying Vbus before we are allowed to
260 ContinueAfter(KDelayBeforeBusDropUs, ELoopDropVBus);
265 otgQueueOtgVbusNotification(iOTGVBus, iStatus );
266 // drop Vbus now, since the call is not a Queing a-sync call we do this after the async call
269 iCaseStep = ELoopVerifyDrop;
270 iWDTimer->IssueRequest(KDelayDurationForLocalTrigger, this, &CancelNotify);
273 case ELoopVerifyDrop:
274 // 8. get Vbus low event
275 if (KTestCaseWatchdogTO == iStatus.Int())
277 return TestFailed(KErrAbort, _L("Vbus drop not signalled in time - FAILED!"));
282 otgQueueOtgVbusNotification( iOTGVBus, iStatus );
283 otgCancelOtgVbusNotification();
284 User::WaitForRequest(iStatus);
286 if (iOTGVBus != RUsbOtgDriver::EVbusLow)
288 return TestFailed(KErrAbort, _L("Vbus drop NOT 'seen' - FAILED!"));
291 // test again using the 'syncronous' variation
292 if (otgVbusPresent())
294 return TestFailed(KErrAbort, _L("Vbus syncronous call error - FAILED!"));
297 // wait 50ms and then go back to beginning
298 ContinueAfter(KDelayBeforeBusDropUs, ELoopControl);
303 if (EFalse == StepUnloadLDD())
304 return TestFailed(KErrAbort,_L("unload Ldd failure"));
306 iCaseStep = ELastStep;
315 test.Printf(_L("<Error> unknown test step"));
317 return (TestFailed(KErrCorrupt, _L("<Error> unknown test step")));