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 "b2bwatchers.h"
27 #include "testcase0678.h"
29 #define _REPEATS (oOpenIterations*3)
32 /* **************************************************************************************
33 * the name below is used to add a pointer to our construction method to a pointer MAP in
36 _LIT(KTestCaseId,"PBASE-USB_OTGDI-0678");
37 const TTestCaseFactoryReceipt<CTestCase0678> CTestCase0678::iFactoryReceipt(KTestCaseId);
39 CTestCase0678* CTestCase0678::NewL(TBool aHost)
42 CTestCase0678* self = new (ELeave) CTestCase0678(aHost);
43 CleanupStack::PushL(self);
45 CleanupStack::Pop(self);
50 CTestCase0678::CTestCase0678(TBool aHost)
51 : CTestCaseB2BRoot(KTestCaseId, aHost, iStatus)
61 void CTestCase0678::ConstructL()
65 iDualRoleCase = ETrue; // another back-back
71 CTestCase0678::~CTestCase0678()
74 iCollector.DestroyObservers();
79 void CTestCase0678::ExecuteTestCaseL()
82 iCaseStep = EPreconditions;
83 iHNPCounter = 3; // To be decremented to govern the number of times we do HNP.
84 CActiveScheduler::Add(this);
89 void CTestCase0678::DoCancel()
97 // handle event completion
98 void CTestCase0678::RunStepL()
101 // Obtain the completion code for this CActive obj.
102 TInt completionCode(iStatus.Int());
103 TBuf<MAX_DSTRLEN> aDescription;
110 LOG_STEPNAME(_L("EPreconditions"))
111 iCaseStep = ELoadLdd;
112 StepB2BPreconditions();
116 // 1. Load the Client LDD
119 LOG_STEPNAME(_L("ELoadLdd"))
120 if (!StepLoadClient(0xF678/*use default settings for SRP/HNP support*/))
122 return TestFailed(KErrAbort, _L("Client Load Failure"));
124 // load OTG ldd and init.
127 return TestFailed(KErrAbort, _L("OTG Load Failure"));
130 if(otgActivateFdfActor()!=KErrNone)
132 return TestFailed(KErrAbort, _L("Couldn't load FDF Actor"));
135 // test that the right cable is in
136 CheckRoleConnections();
138 // subscribe to OTG states,events and messages now that it has loaded OK
139 TRAPD(result, iCollector.CreateObserversL(*this));
140 if (KErrNone != result)
141 return(TestFailed(KErrNoMemory, _L("Unable to create observers")));
142 iCollector.ClearAllEvents();
143 iCaseStep = EReadyToRaiseVBus;
148 case EReadyToRaiseVBus:
152 // wait for Vbus to be raised
153 iCollector.AddRequiredNotification(EWatcherState, RUsbOtgDriver::EStateBIdle);
154 iCollector.AddRequiredNotification(EWatcherEvent, RUsbOtgDriver::EEventVbusRaised);
155 iCollector.AddRequiredNotification(EWatcherState, RUsbOtgDriver::EStateBPeripheral);
159 // Raise VBus, then wait for default role
160 err = otgBusRequest(); // ok to turn on VBus now
163 return TestFailed(KErrAbort, _L("Raise Vbus - RUsbOtgDriver::BusRequest() FAILED!"));
166 // we might also wait for and EStateAIdle
167 iCollector.AddRequiredNotification(EWatcherState, RUsbOtgDriver::EStateAIdle);
168 iCollector.AddRequiredNotification(EWatcherEvent, RUsbOtgDriver::EEventVbusRaised);
169 iCollector.AddRequiredNotification(EWatcherEvent, RUsbOtgDriver::EEventRoleChangedToHost);
171 iCaseStep = EDefaultRoles;
172 const TInt KTestCase0678Timeout = 30000; // 30 seconds, should be plenty of time for 3 role swaps
173 iCollector.AddStepTimeout(KTestCase0678Timeout);
180 test.Printf(_L("Into EDefaultRoles step...\n"));
182 if ( --iHNPCounter >= 0)
184 // We want to do further role swapping
187 // B-Device should now wait until it is configured
188 iCollector.AddRequiredNotification(EWatcherPeripheralState, EUsbcDeviceStateConfigured);
189 iCaseStep = EBConfigured;
193 // A-Device should expect nothing more until it becomes A-Peripheral
194 iCollector.AddRequiredNotification(EWatcherState, RUsbOtgDriver::EStateAPeripheral);
195 iCaseStep = ESwappedRoles;
201 // We've done 3 x HNP cycles back to default roles.
202 // Time to shut down VBus and stop the test case.
203 iCaseStep = EDropVBus;
210 case EBConfigured: // A B-Device only step!
212 test.Printf(_L("Into EBConfigured step...\n"));
213 if (KTestCaseWatchdogTO == iStatus.Int())
215 iCollector.DestroyObservers();
216 return TestFailed(KErrAbort, _L("Timeout"));
218 iCollector.AddRequiredNotification(EWatcherPeripheralState, EUsbcDeviceStateSuspended);
219 iCaseStep = EBSuspended;
226 test.Printf(_L("Into EBSuspended step...\n"));
227 if (KTestCaseWatchdogTO == iStatus.Int())
229 iCollector.DestroyObservers();
230 return TestFailed(KErrAbort, _L("Timeout"));
234 test.Printf(_L("VBus present, attempting a swap.\n"));
235 iCollector.AddRequiredNotification(EWatcherState, RUsbOtgDriver::EStateBHost);
237 err = otgBusRequest(); // Request the host role
241 test.Printf(_L("BusRequest returned %d\n"),err);
242 return TestFailed(KErrAbort, _L("BusRequest() failed!"));
245 iCaseStep = ESwappedRoles;
252 test.Printf(_L("Into ESwappedRoles step...\n"));
253 if (KTestCaseWatchdogTO == iStatus.Int())
255 iCollector.DestroyObservers();
256 return TestFailed(KErrAbort, _L("Timeout"));
261 // B-Device should now wait until it is back to B-Peripheral
262 iCollector.AddRequiredNotification(EWatcherState, RUsbOtgDriver::EStateBPeripheral);
263 iCaseStep = EDefaultRoles;
267 // A-Device should wait to become a configured A-Peripheral
268 iCollector.AddRequiredNotification(EWatcherPeripheralState, EUsbcDeviceStateConfigured);
269 iCaseStep = EAConfigured;
275 case EAConfigured: // A-Device only step
277 test.Printf(_L("Into EWaitTillAConfigured step...\n"));
278 if (KTestCaseWatchdogTO == iStatus.Int())
280 iCollector.DestroyObservers();
281 return TestFailed(KErrAbort, _L("Timeout"));
284 iCollector.AddRequiredNotification(EWatcherPeripheralState, EUsbcDeviceStateSuspended);
285 iCaseStep = EASuspended;
290 case EASuspended: // A-Device only step
292 test.Printf(_L("Into EWaitTillASuspended step...\n"));
293 if (KTestCaseWatchdogTO == iStatus.Int())
295 iCollector.DestroyObservers();
296 return TestFailed(KErrAbort, _L("Timeout"));
299 iCollector.AddRequiredNotification(EWatcherState, RUsbOtgDriver::EStateAHost); // Swapping back to default role
301 iCaseStep = EDefaultRoles;
307 LOG_STEPNAME(_L("EDropVBus"))
309 iCollector.AddRequiredNotification(EWatcherEvent, RUsbOtgDriver::EEventVbusDropped);
310 if ( gTestRoleMaster)
312 iCollector.AddRequiredNotification(EWatcherState, RUsbOtgDriver::EStateBIdle);
313 iCollector.AddRequiredNotification(EWatcherEvent, RUsbOtgDriver::EEventRoleChangedToDevice);
318 iCollector.AddRequiredNotification(EWatcherState, RUsbOtgDriver::EStateAIdle);
319 iCollector.AddRequiredNotification(EWatcherEvent, RUsbOtgDriver::EEventRoleChangedToHost);
321 iCaseStep = EVBusDropped;
326 LOG_STEPNAME(_L("ELoopVerifyDrop"))
327 if (KTestCaseWatchdogTO == iStatus.Int())
329 return TestFailed(KErrAbort, _L("Timeout"));
332 if (otgVbusPresent())
334 return TestFailed(KErrAbort, _L("Vbus did not drop - FAILED!"));
336 iCaseStep = EUnloadLdd;
341 LOG_STEPNAME(_L("EUnloadLdd"))
342 otgDeactivateFdfActor();
343 iCollector.DestroyObservers();
344 if (EFalse == StepUnloadLDD())
345 return TestFailed(KErrAbort,_L("unload Ldd failure"));
346 if (!StepUnloadClient())
347 return TestFailed(KErrAbort,_L("Client Unload Failure"));
349 iCaseStep = ELastStep;
354 LOG_STEPNAME(_L("ELastStep"))
359 test.Printf(_L("<Error> unknown test step"));
361 return (TestFailed(KErrCorrupt, _L("<Error> unknown test step")));