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 "b2bwatchers.h"
27 #include "testcase0684.h"
31 #define _REPEATS (oOpenIterations*3)
34 /* **************************************************************************************
35 * the name below is used to add a pointer to our construction method to a pointer MAP in
38 _LIT(KTestCaseId,"PBASE-USB_OTGDI-0684");
39 const TTestCaseFactoryReceipt<CTestCase0684> CTestCase0684::iFactoryReceipt(KTestCaseId);
41 CTestCase0684* CTestCase0684::NewL(TBool aHost)
44 CTestCase0684* self = new (ELeave) CTestCase0684(aHost);
45 CleanupStack::PushL(self);
47 CleanupStack::Pop(self);
52 CTestCase0684::CTestCase0684(TBool aHost)
53 : CTestCaseB2BRoot(KTestCaseId, aHost, iStatus)
63 void CTestCase0684::ConstructL()
67 iDualRoleCase = ETrue;
68 iBusRequestCounter = 2;
69 iIsTimeToDrop = EFalse;
75 CTestCase0684::~CTestCase0684()
78 iCollector.DestroyObservers();
83 void CTestCase0684::ExecuteTestCaseL()
86 iCaseStep = EPreconditions;
87 CActiveScheduler::Add(this);
92 void CTestCase0684::DoCancel()
98 void CTestCase0684::RunStepL()
102 // Obtain the completion code for this CActive obj.
103 TInt completionCode(iStatus.Int());
104 TBuf<MAX_DSTRLEN> aDescription;
111 LOG_STEPNAME(_L("EPreconditions"))
113 iCaseStep = ELoadLdd;
114 StepB2BPreconditions();
118 // 1. Load the Client LDD
121 LOG_STEPNAME(_L("ELoadLdd"))
123 if (!StepLoadClient(0xF684/*use default settings for SRP/HNP support*/))
125 return TestFailed(KErrAbort, _L("Client Load Failure"));
128 // load OTG ldd and init.
131 return TestFailed(KErrAbort, _L("OTG Load Failure"));
134 if(otgActivateFdfActor()!=KErrNone)
136 return TestFailed(KErrAbort, _L("Couldn't load FDF Actor"));
139 // test that the right cable is in
140 CheckRoleConnections();
142 // subscribe to OTG states,events and messages now that it has loaded OK
143 TRAPD(result, iCollector.CreateObserversL(*this));
144 if (KErrNone != result)
146 return(TestFailed(KErrNoMemory, _L("Unable to create observers")));
148 iCollector.ClearAllEvents();
149 iCaseStep = ESetMaxPower2Zero;
154 case ESetMaxPower2Zero:
155 LOG_STEPNAME(_L("ESetMaxPower2Zero"))
156 iCaseStep = EReadyToRaiseVBus;
161 case EReadyToRaiseVBus:
163 test.Printf(_L("Into EReadyToRaiseVBus step...\n"));
167 // B device, so , just wait for Vbus to be raised
168 iCollector.AddRequiredNotification(EWatcherState, RUsbOtgDriver::EStateBIdle);
169 iCollector.AddRequiredNotification(EWatcherEvent, RUsbOtgDriver::EEventVbusRaised);
170 iCollector.AddRequiredNotification(EWatcherEvent, RUsbOtgDriver::EEventHnpEnabled);
171 iCollector.AddRequiredNotification(EWatcherState, RUsbOtgDriver::EStateBPeripheral);
172 // All as usual - we should report a failure if the B-Device ever reports "busy"
173 iCollector.AddFailureNotification(EWatcherAConnectionIdle, RUsbOtgDriver::EConnectionBusy);
177 // A device, Raise VBus, then wait for default role
178 err = otgBusRequest(); // ok to turn on VBus now
182 return TestFailed(KErrAbort, _L("Raise Vbus - RUsbOtgDriver::BusRequest() FAILED!"));
185 // we might also wait for and EStateAIdle
186 iCollector.AddRequiredNotification(EWatcherState, RUsbOtgDriver::EStateAIdle);
187 iCollector.AddRequiredNotification(EWatcherEvent, RUsbOtgDriver::EEventVbusRaised);
188 iCollector.AddRequiredNotification(EWatcherEvent, RUsbOtgDriver::EEventRoleChangedToHost);
189 iCollector.AddRequiredNotification(EWatcherAConnectionIdle, RUsbOtgDriver::EConnectionBusy);
192 iCaseStep = EDefaultRoles;
193 const TInt KTestCase0684Timeout = 30000; // 30 seconds, should be plenty of time for 3 role swaps
194 iCollector.AddStepTimeout(KTestCase0684Timeout);
201 test.Printf(_L("Into EDefaultRoles step...\n"));
202 if (KTestCaseWatchdogTO == iStatus.Int())
204 iCollector.DestroyObservers();
205 return TestFailed(KErrAbort, _L("Timeout"));
210 iCollector.AddRequiredNotification(EWatcherPeripheralState, EUsbcDeviceStateConfigured);
211 iCaseStep = EBConfigured;
214 iCollector.AddRequiredNotification(EWatcherState, RUsbOtgDriver::EStateAPeripheral);
215 iCaseStep = EAToPeripheral;
221 case EAIdleHostPriorToAPeripheral: // an "A-Device only" step
223 test.Printf(_L("Into EAIdleHostPriorToAPeripheral step...\n"));
224 if (KTestCaseWatchdogTO == iStatus.Int())
226 iCollector.DestroyObservers();
227 return TestFailed(KErrAbort, _L("Timeout"));
230 // A-Device should expect nothing more until it becomes A-Peripheral
231 iCollector.AddRequiredNotification(EWatcherState, RUsbOtgDriver::EStateAPeripheral);
232 iCollector.AddRequiredNotification(EWatcherAConnectionIdle, RUsbOtgDriver::EConnectionBusy);
233 iCollector.AddRequiredNotification(EWatcherPeripheralState, EUsbcDeviceStateConfigured);
234 iCollector.AddRequiredNotification(EWatcherState, RUsbOtgDriver::EStateAHost);
235 iCaseStep = EAToHost;
242 test.Printf(_L("Into EBConfigured step...\n"));
243 if (KTestCaseWatchdogTO == iStatus.Int())
245 iCollector.DestroyObservers();
246 RDebug::Print(_L("Timeout"));
247 return TestFailed(KErrAbort, _L("Timeout"));
249 iCollector.AddRequiredNotification(EWatcherPeripheralState, EUsbcDeviceStateSuspended);
250 iCaseStep = EBSuspended;
257 test.Printf(_L("Into EBSuspended step...\n"));
258 if (KTestCaseWatchdogTO == iStatus.Int())
260 iCollector.DestroyObservers();
261 RDebug::Print(_L("Timeout"));
262 return TestFailed(KErrAbort, _L("Timeout"));
265 if(iBusRequestCounter > 0){
266 test.Printf(_L("VBus present, attempting a swap.\n"));
267 iCollector.AddRequiredNotification(EWatcherState, RUsbOtgDriver::EStateBHost);
269 iBusRequestCounter --;
270 err = otgBusRequest(); // Request the host role
273 test.Printf(_L("BusRequest returned %d\n"),err);
274 return TestFailed(KErrAbort, _L("BusRequest() failed!"));
276 iCaseStep = EBToHost;
279 iCollector.AddRequiredNotification(EWatcherAConnectionIdle, RUsbOtgDriver::EConnectionIdle);
280 iCaseStep = EIdleHostPriorToVBusDown;
288 test.Printf(_L("Into EAToHost step...\n"));
289 if (KTestCaseWatchdogTO == iStatus.Int())
291 iCollector.DestroyObservers();
292 return TestFailed(KErrAbort, _L("Timeout"));
295 if( ! iIsTimeToDrop){
296 iIsTimeToDrop = ETrue;
300 test.Printf(_L("bMaxPower= %d\n"), val);
301 iCollector.AddRequiredNotification(EWatcherState, RUsbOtgDriver::EStateAPeripheral);
302 iCaseStep = EAToPeripheral;
305 iCollector.AddRequiredNotification(EWatcherAConnectionIdle, RUsbOtgDriver::EConnectionIdle);
306 iCaseStep = EIdleHostPriorToVBusDown;
315 test.Printf(_L("Into EAToPeripheral step...\n"));
316 if (KTestCaseWatchdogTO == iStatus.Int())
318 iCollector.DestroyObservers();
319 return TestFailed(KErrAbort, _L("Timeout"));
321 iCollector.AddRequiredNotification(EWatcherState, RUsbOtgDriver::EStateAHost);
322 iCaseStep = EAToHost;
329 test.Printf(_L("Into EBToHost step...\n"));
330 if (KTestCaseWatchdogTO == iStatus.Int())
332 iCollector.DestroyObservers();
333 return TestFailed(KErrAbort, _L("Timeout"));
335 iCollector.AddRequiredNotification(EWatcherState, RUsbOtgDriver::EStateBPeripheral);
336 iCaseStep = EBToPeripheral;
343 test.Printf(_L("Into EBToPeripheral step...\n"));
344 if (KTestCaseWatchdogTO == iStatus.Int())
346 iCollector.DestroyObservers();
347 return TestFailed(KErrAbort, _L("Timeout"));
349 if(iBusRequestCounter > 0)
351 iCollector.AddRequiredNotification(EWatcherPeripheralState, EUsbcDeviceStateConfigured);
352 iCaseStep = EBConfigured;
356 iCollector.AddRequiredNotification(EWatcherEvent, RUsbOtgDriver::EEventVbusDropped);
357 iCaseStep = EVBusDropped;
363 case EIdleHostPriorToVBusDown:
365 test.Printf(_L("Into EAIdleHostPriorToVBusDown step...\n"));
367 if (KTestCaseWatchdogTO == iStatus.Int())
369 iCollector.DestroyObservers();
370 return TestFailed(KErrAbort, _L("Timeout"));
373 iCaseStep = EDropVBus;
379 LOG_STEPNAME(_L("EDropVBus"))
380 if (KTestCaseWatchdogTO == iStatus.Int())
382 iCollector.DestroyObservers();
383 return TestFailed(KErrAbort, _L("Timeout"));
386 iCollector.AddRequiredNotification(EWatcherEvent, RUsbOtgDriver::EEventVbusDropped);
387 if ( gTestRoleMaster)
389 iCollector.AddRequiredNotification(EWatcherState, RUsbOtgDriver::EStateBIdle);
394 iCollector.AddRequiredNotification(EWatcherState, RUsbOtgDriver::EStateAIdle);
396 iCaseStep = EVBusDropped;
401 LOG_STEPNAME(_L("ELoopVerifyDrop"))
402 if (KTestCaseWatchdogTO == iStatus.Int())
404 return TestFailed(KErrAbort, _L("Timeout"));
407 if (otgVbusPresent())
409 return TestFailed(KErrAbort, _L("Vbus did not drop - FAILED!"));
411 iCaseStep = EUnloadLdd;
416 LOG_STEPNAME(_L("EUnloadLdd"))
417 otgDeactivateFdfActor();
418 iCollector.DestroyObservers();
419 if (EFalse == StepUnloadLDD()){
420 return TestFailed(KErrAbort,_L("unload Ldd failure"));
422 if (!StepUnloadClient()){
423 return TestFailed(KErrAbort,_L("Client Unload Failure"));
426 iCaseStep = ELastStep;
431 LOG_STEPNAME(_L("ELastStep"))
437 test.Printf(_L("<Error> unknown test step"));
440 return (TestFailed(KErrCorrupt, _L("<Error> unknown test step")));