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 "b2bwatchers.h"
26 #include "testcase0681.h"
28 #define _REPEATS (oOpenIterations*3)
31 /* **************************************************************************************
32 * the name below is used to add a pointer to our construction method to a pointer MAP in
35 _LIT(KTestCaseId,"PBASE-USB_OTGDI-0681");
36 const TTestCaseFactoryReceipt<CTestCase0681> CTestCase0681::iFactoryReceipt(KTestCaseId);
38 CTestCase0681* CTestCase0681::NewL(TBool aHost)
41 CTestCase0681* self = new (ELeave) CTestCase0681(aHost);
42 CleanupStack::PushL(self);
44 CleanupStack::Pop(self);
49 CTestCase0681::CTestCase0681(TBool aHost)
50 : CTestCaseB2BRoot(KTestCaseId, aHost, iStatus)
60 void CTestCase0681::ConstructL()
64 iDualRoleCase = ETrue; // another back-back
70 CTestCase0681::~CTestCase0681()
73 iCollector.DestroyObservers();
78 void CTestCase0681::ExecuteTestCaseL()
81 iCaseStep = EPreconditions;
82 iHNPCounter = 3; // To be decremented to govern the number of times we do HNP.
83 CActiveScheduler::Add(this);
88 void CTestCase0681::DoCancel()
95 void CTestCase0681::StepB2BPreconditions()
97 // prompt to insert connector and activate A-end first...
100 test.Printf(_L("***** Important note *****\n"));
101 test.Printf(_L("Before commencing test, please\n"));
102 test.Printf(_L("insert 'B'-cable end and activate\n"));
103 test.Printf(_L("the test on the 'A' device.\n"));
104 test.Printf(_L("Then, press any key to continue.\n"));
105 test.Printf(_L("**************************\n"));
109 test.Printf(KInsertACablePrompt);
110 test.Printf(KPressAnyKeyToContinue);
116 // handle event completion
117 void CTestCase0681::RunStepL()
120 // Obtain the completion code for this CActive obj.
121 TInt completionCode(iStatus.Int());
122 TBuf<MAX_DSTRLEN> aDescription;
125 if(completionCode != KErrNone)
128 switch(completionCode)
130 case KTestCaseFailureEventReceived:
132 TestFailed(KErrAbort, _L("Failure Event Received"));
135 case KTestCaseWatchdogTO:
137 TestFailed(KErrAbort, _L("Watchdog timer expired"));
142 TestFailed(KErrAbort, _L("Test step completed with Error"));
146 iCollector.DestroyObservers();
154 LOG_STEPNAME(_L("EPreconditions"))
155 iCaseStep = ELoadLdd;
156 StepB2BPreconditions();
160 // 1. Load the Client LDD
163 LOG_STEPNAME(_L("ELoadLdd"))
164 if (!StepLoadClient(0xF681/*use default settings for SRP/HNP support*/))
166 return TestFailed(KErrAbort, _L("Client Load Failure"));
168 // load OTG ldd and init.
171 return TestFailed(KErrAbort, _L("OTG Load Failure"));
174 if(otgActivateFdfActor()!=KErrNone)
176 return TestFailed(KErrAbort, _L("Couldn't load FDF Actor"));
179 // test that the right cable is in
180 CheckRoleConnections();
182 // subscribe to OTG states,events and messages now that it has loaded OK
183 TRAPD(result, iCollector.CreateObserversL(*this));
184 if (KErrNone != result)
185 return(TestFailed(KErrNoMemory, _L("Unable to create observers")));
186 iCollector.ClearAllEvents();
187 iCaseStep = EPerformSrp;
194 test.Printf(_L("Into EPerformSrp step...\n"));
199 iCollector.AddRequiredNotification(EWatcherState, RUsbOtgDriver::EStateBIdle);
200 iCollector.AddRequiredNotification(EWatcherEvent, RUsbOtgDriver::EEventSrpInitiated);
201 iCollector.AddRequiredNotification(EWatcherEvent, RUsbOtgDriver::EEventVbusRaised);
202 iCollector.AddRequiredNotification(EWatcherState, RUsbOtgDriver::EStateBHost);
204 // We shouldn't get configured at any point however since ADevice will call
205 // BusRespondSrp which should bypass that stage on the way to enabling us to
207 iCollector.AddFailureNotification(EWatcherPeripheralState, EUsbcDeviceStateConfigured);
209 err = otgBusRequest();
212 return TestFailed(KErrAbort, _L("Raise Vbus - RUsbOtgDriver::BusRequest() FAILED!"));
215 iCaseStep = ESwappedRoles;
221 iCollector.AddRequiredNotification(EWatcherEvent, RUsbOtgDriver::EEventSrpReceived);
223 iCaseStep = EAReceivedSrp;
225 const TInt KTestCase0681Timeout = 30000; // 30 seconds, should be plenty of time for 3 role swaps
226 iCollector.AddStepTimeout(KTestCase0681Timeout);
231 case EAReceivedSrp: // A-Device step only!
233 test.Printf(_L("Into EAReceivedSrp step...\n"));
235 if (KTestCaseWatchdogTO == iStatus.Int())
237 iCollector.DestroyObservers();
238 return TestFailed(KErrAbort, _L("Timeout"));
241 iCollector.AddRequiredNotification(EWatcherEvent, RUsbOtgDriver::EEventVbusRaised);
242 iCollector.AddRequiredNotification(EWatcherEvent, RUsbOtgDriver::EEventRoleChangedToDevice);
243 iCollector.AddRequiredNotification(EWatcherState, RUsbOtgDriver::EStateAPeripheral);
245 // We've received SRP. We use BusRespondSRP to raise VBus and cede the host role
246 err = otgBusRespondSRP();
249 return TestFailed(KErrAbort, _L("Raise Vbus - RUsbOtgDriver::BusRequest() FAILED!"));
252 iCaseStep = ESwappedRoles;
259 test.Printf(_L("Into ESwappedRoles step...\n"));
260 if (KTestCaseWatchdogTO == iStatus.Int())
262 iCollector.DestroyObservers();
263 return TestFailed(KErrAbort, _L("Timeout"));
268 // B-Device should now wait until it is B-Peripheral
269 iCollector.AddRequiredNotification(EWatcherState, RUsbOtgDriver::EStateBPeripheral);
270 iCaseStep = EDefaultRoles;
274 // A-Device should wait to become a configured A-Peripheral
275 iCollector.AddRequiredNotification(EWatcherPeripheralState, EUsbcDeviceStateConfigured);
276 iCaseStep = EAConfigured;
282 case EAConfigured: // A-Device only step
284 test.Printf(_L("Into EAConfigured step...\n"));
285 if (KTestCaseWatchdogTO == iStatus.Int())
287 iCollector.DestroyObservers();
288 return TestFailed(KErrAbort, _L("Timeout"));
291 iCollector.AddRequiredNotification(EWatcherPeripheralState, EUsbcDeviceStateSuspended);
292 iCaseStep = EASuspended;
297 case EASuspended: // A-Device only step
299 test.Printf(_L("Into EASuspended step...\n"));
300 if (KTestCaseWatchdogTO == iStatus.Int())
302 iCollector.DestroyObservers();
303 return TestFailed(KErrAbort, _L("Timeout"));
306 iCollector.AddRequiredNotification(EWatcherState, RUsbOtgDriver::EStateAHost); // Swapping back to default role
308 iCaseStep = EDefaultRoles;
315 test.Printf(_L("Into EDefaultRoles step...\n"));
317 if ( --iHNPCounter >= 0)
319 // We want to do further role swapping
322 // B-Device should now wait until it is configured
323 iCollector.AddRequiredNotification(EWatcherPeripheralState, EUsbcDeviceStateConfigured);
324 iCaseStep = EBConfigured;
328 // A-Device should expect nothing more until it becomes A-Peripheral
329 iCollector.AddRequiredNotification(EWatcherState, RUsbOtgDriver::EStateAPeripheral);
330 iCaseStep = ESwappedRoles;
336 // We've done 3 x HNP cycles back to default roles.
337 // Time to shut down VBus and stop the test case.
338 iCaseStep = EDropVBus;
345 case EBConfigured: // A B-Device only step!
347 test.Printf(_L("Into EBConfigured step...\n"));
348 if (KTestCaseWatchdogTO == iStatus.Int())
350 iCollector.DestroyObservers();
351 return TestFailed(KErrAbort, _L("Timeout"));
353 iCollector.AddRequiredNotification(EWatcherPeripheralState, EUsbcDeviceStateSuspended);
354 iCaseStep = EBSuspended;
361 test.Printf(_L("Into EBSuspended step...\n"));
362 if (KTestCaseWatchdogTO == iStatus.Int())
364 iCollector.DestroyObservers();
365 return TestFailed(KErrAbort, _L("Timeout"));
369 test.Printf(_L("VBus present, attempting a swap.\n"));
370 iCollector.AddRequiredNotification(EWatcherState, RUsbOtgDriver::EStateBHost);
372 err = otgBusRequest(); // Request the host role
376 test.Printf(_L("BusRequest returned %d\n"),err);
377 return TestFailed(KErrAbort, _L("BusRequest() failed!"));
380 iCaseStep = ESwappedRoles;
388 LOG_STEPNAME(_L("EDropVBus"))
390 iCollector.AddRequiredNotification(EWatcherEvent, RUsbOtgDriver::EEventVbusDropped);
391 if ( gTestRoleMaster)
393 iCollector.AddRequiredNotification(EWatcherState, RUsbOtgDriver::EStateBIdle);
394 iCollector.AddRequiredNotification(EWatcherEvent, RUsbOtgDriver::EEventRoleChangedToDevice);
399 iCollector.AddRequiredNotification(EWatcherState, RUsbOtgDriver::EStateAIdle);
400 iCollector.AddRequiredNotification(EWatcherEvent, RUsbOtgDriver::EEventRoleChangedToHost);
402 iCaseStep = EVBusDropped;
407 LOG_STEPNAME(_L("ELoopVerifyDrop"))
408 if (KTestCaseWatchdogTO == iStatus.Int())
410 return TestFailed(KErrAbort, _L("Timeout"));
413 if (otgVbusPresent())
415 return TestFailed(KErrAbort, _L("Vbus did not drop - FAILED!"));
417 iCaseStep = EUnloadLdd;
422 LOG_STEPNAME(_L("EUnloadLdd"))
423 otgDeactivateFdfActor();
424 iCollector.DestroyObservers();
425 if (EFalse == StepUnloadLDD())
426 return TestFailed(KErrAbort,_L("unload Ldd failure"));
427 if (!StepUnloadClient())
428 return TestFailed(KErrAbort,_L("Client Unload Failure"));
430 iCaseStep = ELastStep;
435 LOG_STEPNAME(_L("ELastStep"))
440 test.Printf(_L("<Error> unknown test step"));
442 return (TestFailed(KErrCorrupt, _L("<Error> unknown test step")));