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 "testcase0683.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-0683");
37 const TTestCaseFactoryReceipt<CTestCase0683> CTestCase0683::iFactoryReceipt(KTestCaseId);
39 CTestCase0683* CTestCase0683::NewL(TBool aHost)
42 CTestCase0683* self = new (ELeave) CTestCase0683(aHost);
43 CleanupStack::PushL(self);
45 CleanupStack::Pop(self);
50 CTestCase0683::CTestCase0683(TBool aHost)
51 : CTestCaseB2BRoot(KTestCaseId, aHost, iStatus)
61 void CTestCase0683::ConstructL()
65 iDualRoleCase = ETrue; // another back-back
71 CTestCase0683::~CTestCase0683()
74 iCollector.DestroyObservers();
79 void CTestCase0683::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 CTestCase0683::DoCancel()
97 // handle event completion
98 void CTestCase0683::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);
156 // All as usual - we should report a failure if the B-Device ever reports "busy"
157 iCollector.AddFailureNotification(EWatcherAConnectionIdle, RUsbOtgDriver::EConnectionBusy);
161 // Raise VBus, then wait for default role
162 err = otgBusRequest(); // ok to turn on VBus now
165 return TestFailed(KErrAbort, _L("Raise Vbus - RUsbOtgDriver::BusRequest() FAILED!"));
168 // we might also wait for and EStateAIdle
169 iCollector.AddRequiredNotification(EWatcherState, RUsbOtgDriver::EStateAIdle);
170 iCollector.AddRequiredNotification(EWatcherEvent, RUsbOtgDriver::EEventVbusRaised);
171 iCollector.AddRequiredNotification(EWatcherEvent, RUsbOtgDriver::EEventRoleChangedToHost);
172 iCollector.AddRequiredNotification(EWatcherAConnectionIdle, RUsbOtgDriver::EConnectionBusy);
174 iCaseStep = EDefaultRoles;
175 const TInt KTestCase0683Timeout = 30000; // 30 seconds, should be plenty of time for 3 role swaps
176 iCollector.AddStepTimeout(KTestCase0683Timeout);
183 test.Printf(_L("Into EDefaultRoles step...\n"));
185 if (KTestCaseWatchdogTO == iStatus.Int())
187 iCollector.DestroyObservers();
188 return TestFailed(KErrAbort, _L("Timeout"));
191 if ( --iHNPCounter > 0)
193 // We want to do further role swapping
196 // B-Device should now wait until it is configured
197 iCollector.AddRequiredNotification(EWatcherPeripheralState, EUsbcDeviceStateConfigured);
198 iCaseStep = EBConfigured;
202 iCollector.AddRequiredNotification(EWatcherAConnectionIdle, RUsbOtgDriver::EConnectionIdle);
203 iCaseStep = EAIdleHostPriorToAPeripheral;
209 // We've done 3 x HNP cycles back to default roles.
210 // This time, we want A-Host to suspend B-Peripheral,
211 // have the B-Peripheral *not* do a bus request, then
212 // have the A-Device detect idle and shut down VBus.
215 // B-Device should now wait until it is configured (for the last time this test)
216 iCollector.AddRequiredNotification(EWatcherPeripheralState, EUsbcDeviceStateConfigured);
217 iCaseStep = EBConfigured;
221 iCollector.AddRequiredNotification(EWatcherAConnectionIdle, RUsbOtgDriver::EConnectionIdle);
222 iCaseStep = EAIdleHostPriorToVBusDown;
229 case EBConfigured: // A B-Device only step!
231 test.Printf(_L("Into EBConfigured step...\n"));
232 if (KTestCaseWatchdogTO == iStatus.Int())
234 iCollector.DestroyObservers();
235 return TestFailed(KErrAbort, _L("Timeout"));
237 iCollector.AddRequiredNotification(EWatcherPeripheralState, EUsbcDeviceStateSuspended);
238 iCaseStep = EBSuspended;
245 test.Printf(_L("Into EBSuspended step...\n"));
246 if (KTestCaseWatchdogTO == iStatus.Int())
248 iCollector.DestroyObservers();
249 return TestFailed(KErrAbort, _L("Timeout"));
254 // issue bus request to trigger HNP
255 test.Printf(_L("VBus present, attempting a swap.\n"));
256 iCollector.AddRequiredNotification(EWatcherState, RUsbOtgDriver::EStateBHost);
258 err = otgBusRequest(); // Request the host role
261 test.Printf(_L("BusRequest returned %d\n"),err);
262 return TestFailed(KErrAbort, _L("BusRequest() failed!"));
265 iCaseStep = ESwappedRoles;
270 // We've done all the role-swapping we want. Now just wait for
271 // A-Host to drop VBus...
272 iCaseStep = EDropVBus;
279 case EAIdleHostPriorToAPeripheral: // an "A-Device only" step
281 test.Printf(_L("Into EAIdleHostPriorToAPeripheral step...\n"));
282 if (KTestCaseWatchdogTO == iStatus.Int())
284 iCollector.DestroyObservers();
285 return TestFailed(KErrAbort, _L("Timeout"));
288 // A-Device should expect nothing more until it becomes A-Peripheral
289 iCollector.AddRequiredNotification(EWatcherState, RUsbOtgDriver::EStateAPeripheral);
290 iCollector.AddRequiredNotification(EWatcherAConnectionIdle, RUsbOtgDriver::EConnectionBusy);
291 iCaseStep = ESwappedRoles;
298 test.Printf(_L("Into ESwappedRoles step...\n"));
299 if (KTestCaseWatchdogTO == iStatus.Int())
301 iCollector.DestroyObservers();
302 return TestFailed(KErrAbort, _L("Timeout"));
307 // B-Device should now wait until it is back to B-Peripheral
308 iCollector.AddRequiredNotification(EWatcherState, RUsbOtgDriver::EStateBPeripheral);
309 iCaseStep = EDefaultRoles;
313 // A-Device should wait to become a configured A-Peripheral
314 iCollector.AddRequiredNotification(EWatcherPeripheralState, EUsbcDeviceStateConfigured);
315 iCaseStep = EAConfigured;
321 case EAConfigured: // A-Device only step
323 test.Printf(_L("Into EAConfigured step...\n"));
324 if (KTestCaseWatchdogTO == iStatus.Int())
326 iCollector.DestroyObservers();
327 return TestFailed(KErrAbort, _L("Timeout"));
330 iCollector.AddRequiredNotification(EWatcherAConnectionIdle, RUsbOtgDriver::EConnectionIdle);
331 iCollector.AddRequiredNotification(EWatcherPeripheralState, EUsbcDeviceStateSuspended);
332 iCaseStep = EASuspended;
337 case EASuspended: // A-Device only step
339 test.Printf(_L("Into EASuspended step...\n"));
340 if (KTestCaseWatchdogTO == iStatus.Int())
342 iCollector.DestroyObservers();
343 return TestFailed(KErrAbort, _L("Timeout"));
346 iCollector.AddRequiredNotification(EWatcherAConnectionIdle, RUsbOtgDriver::EConnectionBusy);
347 iCollector.AddRequiredNotification(EWatcherState, RUsbOtgDriver::EStateAHost); // Swapping back to default role
349 iCaseStep = EDefaultRoles;
354 case EAIdleHostPriorToVBusDown:
356 test.Printf(_L("Into EAIdleHostPriorToVBusDown step...\n"));
357 if (KTestCaseWatchdogTO == iStatus.Int())
359 iCollector.DestroyObservers();
360 return TestFailed(KErrAbort, _L("Timeout"));
363 iCaseStep = EDropVBus;
369 LOG_STEPNAME(_L("EDropVBus"))
370 if (KTestCaseWatchdogTO == iStatus.Int())
372 iCollector.DestroyObservers();
373 return TestFailed(KErrAbort, _L("Timeout"));
376 iCollector.AddRequiredNotification(EWatcherEvent, RUsbOtgDriver::EEventVbusDropped);
377 if ( gTestRoleMaster)
379 iCollector.AddRequiredNotification(EWatcherState, RUsbOtgDriver::EStateBIdle);
384 iCollector.AddRequiredNotification(EWatcherState, RUsbOtgDriver::EStateAIdle);
386 iCaseStep = EVBusDropped;
391 LOG_STEPNAME(_L("ELoopVerifyDrop"))
392 if (KTestCaseWatchdogTO == iStatus.Int())
394 return TestFailed(KErrAbort, _L("Timeout"));
397 if (otgVbusPresent())
399 return TestFailed(KErrAbort, _L("Vbus did not drop - FAILED!"));
401 iCaseStep = EUnloadLdd;
406 LOG_STEPNAME(_L("EUnloadLdd"))
407 otgDeactivateFdfActor();
408 iCollector.DestroyObservers();
409 if (EFalse == StepUnloadLDD())
410 return TestFailed(KErrAbort,_L("unload Ldd failure"));
411 if (!StepUnloadClient())
412 return TestFailed(KErrAbort,_L("Client Unload Failure"));
414 iCaseStep = ELastStep;
419 LOG_STEPNAME(_L("ELastStep"))
424 test.Printf(_L("<Error> unknown test step"));
426 return (TestFailed(KErrCorrupt, _L("<Error> unknown test step")));