Update contrib.
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 "testcase0677.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-0677");
35 const TTestCaseFactoryReceipt<CTestCase0677> CTestCase0677::iFactoryReceipt(KTestCaseId);
37 CTestCase0677* CTestCase0677::NewL(TBool aHost)
40 CTestCase0677* self = new (ELeave) CTestCase0677(aHost);
41 CleanupStack::PushL(self);
43 CleanupStack::Pop(self);
48 CTestCase0677::CTestCase0677(TBool aHost)
49 : CTestCaseRoot(KTestCaseId, aHost)
59 void CTestCase0677::ConstructL()
62 iWDTimer = CTestCaseWatchdog::NewL();
63 iRepeats = OPEN_REPEATS;
69 CTestCase0677::~CTestCase0677()
79 void CTestCase0677::ExecuteTestCaseL()
82 iCaseStep = EPreconditions;
84 iRepeats = KOperationRetriesMax; // VBus event rise retries
86 CActiveScheduler::Add(this);
92 void CTestCase0677::DoCancel()
101 void CTestCase0677::CancelKB(CTestCaseRoot *pThis)
104 CTestCase0677 * p = REINTERPRET_CAST(CTestCase0677 *,pThis);
105 // cancel any pending call, and then complete our active obj with a cancel value
106 p->iConsole->ReadCancel();
111 void CTestCase0677::CancelNotify(CTestCaseRoot *pThis)
114 CTestCase0677 * p = REINTERPRET_CAST(CTestCase0677 *,pThis);
115 // cancel any pending call, and then complete our active obj with a timeout value
116 switch (p->iCancelWhat)
118 case ECancelEventNotify:
119 p->otgCancelOtgEventRequest();
121 case ECancelMessageNotify:
122 p->otgCancelOtgMessageRequest();
124 case ECancelVBusNotify:
125 p->otgCancelOtgVbusNotification();
131 p->SelfComplete(KTestCaseWatchdogTO);
135 // This test result depends on all the ID detection tests and the VBus driving and dropping tests have not yet passed
136 void CTestCase0677::DescribePreconditions()
138 test.Printf(_L("Using OET, connect oscilloscope chan.A to VBus\n"));
139 test.Printf(_L("Connect oscilloscope chan.B to D+\n"));
140 test.Printf(_L("Trigger once, 200mV, 100ms \n"));
141 test.Printf(_L("Prepare to observe VBus, D+ pulse.\n\n"));
145 void CTestCase0677::ContinueAfter(TTimeIntervalMicroSeconds32 aMicroSecs, TCaseSteps aStep)
147 LOG_VERBOSE2(_L("Wait %dms before drop VBus"), (TInt)(aMicroSecs.Int()/1000));
148 iTimer.After(iStatus, aMicroSecs);
154 // handle event completion
155 void CTestCase0677::RunStepL()
158 // Obtain the completion code for this CActive obj.
159 TInt completionCode(iStatus.Int());
160 TBuf<MAX_DSTRLEN> aDescription;
167 iCaseStep = ELoadLdd;
170 iCaseStep = ELoadLdd;
174 // prompt to insert connector
175 test.Printf(KAttachOETAsBDevice);
176 test.Printf(KPressAnyKeyToContinue);
180 // 1. load the LDD and init.
186 iCaseStep = EDetectBPlug;
190 // 2. detect 'B' plug now
192 if (KTestCaseWatchdogTO == iStatus.Int())
194 return TestFailed(KErrAbort, _L("User response too slow - FAILED!"));
197 // if doing this test in /AUTO mode, we would fail this now
198 // however if we can control ID_PIN through an API in future, we turn in on now.
199 if (otgIdPinPresent())
201 test.Printf(KRemoveAConnectorPrompt);
202 test.Printf(KPressAnyKeyToContinue);
205 iCaseStep = EDetectBPlug;
209 iCaseStep = ERequestBus;
214 // 5. Issue SRP (request VBUS)
218 test.Printf(KMsgWaitingForSRPInitiated);
219 otgQueueOtgEventRequest( iOTGEvent, iStatus );
221 // turn on VBus (B-SRP)
222 err = otgBusRequest();
223 iTimeSRPStart.HomeTime();
227 return TestFailed(KErrAbort, _L("Issue SRP - RUsbOtgDriver::BusRequest() FAILED!"));
229 iCaseStep = EWaitForSRPInitiated;
230 iCancelWhat = ECancelEventNotify;
231 iWDTimer->IssueRequest(32000*2 /*KSpec_TA_SRP_RSPNS +1000*/, this, &CancelNotify);
235 // 6. get SRP initiated event, this is a local indication
236 case EWaitForSRPInitiated:
237 if (KTestCaseWatchdogTO == iStatus.Int())
239 return TestFailed(KErrAbort, _L("SRP Active indication NOT fired in time - FAILED!"));
241 OtgEventString(iOTGEvent, aDescription);
242 test.Printf(_L("Received event %d '%S' status(%d)\n"), iOTGEvent, &aDescription, completionCode);
243 if (RUsbOtgDriver::EEventSrpInitiated == iOTGEvent)
246 TTimeIntervalMicroSeconds aIntvlMicro;
249 aIntvlMicro = aNowTime.MicroSecondsFrom(iTimeSRPStart);
250 LOG_VERBOSE2(_L("SRP active after %d ms\n"), (TInt)(aIntvlMicro.Int64()/1000));
251 iCancelWhat = ECancelMessageNotify;
252 otgQueueOtgMessageRequest( iOTGMessage, iStatus );
253 iCaseStep = EWaitForSRPTimeout;
254 test.Printf(KMsgWaitingForSRPTimeout);
259 iCaseStep = EWaitForSRPInitiated;
260 test.Printf(KMsgWaitingForSRPInitiated);
261 iStatus = KRequestPending;
262 otgQueueOtgEventRequest( iOTGEvent, iStatus );
267 // 6. get SRP timeout event, this is a local indication
268 case EWaitForSRPTimeout:
269 if (KTestCaseWatchdogTO == iStatus.Int())
271 return TestFailed(KErrAbort, _L("SRP T/O NOT fired in time - FAILED!"));
273 OtgMessageString(iOTGMessage, aDescription);
274 test.Printf(_L("Received message %d '%S' status(%d)\n"), iOTGMessage, &aDescription, completionCode);
275 if (RUsbOtgDriver::EMessageSrpTimeout == iOTGMessage)
277 iWDTimer->Cancel(); // Only cancel WD Timer here, when timed portion of test is over
279 TTimeIntervalMicroSeconds aIntvlMicro;
282 aIntvlMicro = aNowTime.MicroSecondsFrom(iTimeSRPStart);
283 LOG_VERBOSE2(_L("SRP times out after %d ms\n"), (TInt)(aIntvlMicro.Int64()/1000));
284 // the correct value is 32 seconds, not 4.9 seconds as per the spec.
286 iCaseStep = EIssueSRPObservedPrompt;
291 iCaseStep = EWaitForSRPTimeout;
292 test.Printf(KMsgWaitingForSRPTimeout);
293 iStatus = KRequestPending;
294 otgQueueOtgMessageRequest( iOTGMessage, iStatus );
299 case EIssueSRPObservedPrompt:
301 test.Printf(_L("\nPress Y to verify that SRP was observed\n"));
302 test.Printf(_L("or any other key to fail test.\n"));
304 iCaseStep = ECheckSRPObservedUserInput;
309 case ECheckSRPObservedUserInput:
311 if (('y' != iKeyCodeInput) && ('Y' != iKeyCodeInput))
313 return TestFailed(KErrAbort, _L("SRP NOT observed - FAILED!"));
315 iCaseStep = EUnloadLdd;
322 if (EFalse == StepUnloadLDD())
323 return TestFailed(KErrAbort,_L("Unload Ldd failure"));
325 iCaseStep = ELastStep;
334 test.Printf(_L("<Error> unknown test step\n"));
336 return (TestFailed(KErrCorrupt, _L("<Error> unknown test step")));