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 "testcase0680.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-0680");
36 const TTestCaseFactoryReceipt<CTestCase0680> CTestCase0680::iFactoryReceipt(KTestCaseId);
38 CTestCase0680* CTestCase0680::NewL(TBool aHost)
41 CTestCase0680* self = new (ELeave) CTestCase0680(aHost);
42 CleanupStack::PushL(self);
44 CleanupStack::Pop(self);
49 CTestCase0680::CTestCase0680(TBool aHost)
50 : CTestCaseB2BRoot(KTestCaseId, aHost, iStatus)
60 void CTestCase0680::ConstructL()
64 iDualRoleCase = ETrue; // another back-back
70 CTestCase0680::~CTestCase0680()
73 iCollector.DestroyObservers();
78 void CTestCase0680::ExecuteTestCaseL()
81 iCaseStep = EPreconditions;
82 CActiveScheduler::Add(this);
87 void CTestCase0680::DoCancel()
95 // handle event completion
96 void CTestCase0680::RunStepL()
99 // Obtain the completion code for this CActive obj.
100 TInt completionCode(iStatus.Int());
101 TBuf<MAX_DSTRLEN> aDescription;
108 LOG_STEPNAME(_L("EPreconditions"))
109 iCaseStep = ELoadLdd;
110 StepB2BPreconditions();
114 // 1. Load the Client LDD
117 LOG_STEPNAME(_L("ELoadLdd"))
118 if (!StepLoadClient(0xF680)) // Use default params, so HNP/SRP both supported
120 return TestFailed(KErrAbort, _L("Client Load Failure"));
122 // load OTG ldd and init.
125 return TestFailed(KErrAbort, _L("OTG Load Failure"));
128 // NB. We don't load the FDF Actor, because we don't want
129 // the A-Host to suspend the attached B-Peripheral.
131 // test that the right cable is in
132 CheckRoleConnections();
134 // subscribe to OTG states,events and messages now that it has loaded OK
135 TRAPD(result, iCollector.CreateObserversL(*this));
136 if (KErrNone != result)
137 return(TestFailed(KErrNoMemory, _L("Unable to create observers")));
138 iCollector.ClearAllEvents();
139 iCaseStep = EReadyToRaiseVBus;
144 case EReadyToRaiseVBus:
146 test.Printf(_L("Into EReadyToRaiseVBus step...\n"));
149 // wait for Vbus to be raised
150 iCollector.AddRequiredNotification(EWatcherState, RUsbOtgDriver::EStateBIdle);
151 iCollector.AddRequiredNotification(EWatcherEvent, RUsbOtgDriver::EEventVbusRaised);
152 iCollector.AddRequiredNotification(EWatcherState, RUsbOtgDriver::EStateBPeripheral);
156 // Raise VBus, then wait for default role
157 err = otgBusRequest(); // ok to turn on VBus now
160 return TestFailed(KErrAbort, _L("Raise Vbus - RUsbOtgDriver::BusRequest() FAILED!"));
163 // we might also wait for and EStateAIdle
164 iCollector.AddRequiredNotification(EWatcherState, RUsbOtgDriver::EStateAIdle);
165 iCollector.AddRequiredNotification(EWatcherEvent, RUsbOtgDriver::EEventVbusRaised);
166 iCollector.AddRequiredNotification(EWatcherEvent, RUsbOtgDriver::EEventRoleChangedToHost);
169 const TInt KTestCase0680VBusRaiseTimeout = 2000; // 2 seconds, should be plenty of time for this test
170 iCollector.AddStepTimeout(KTestCase0680VBusRaiseTimeout);
172 iCaseStep = EDefaultRoles;
179 test.Printf(_L("Into EDefaultRoles step...\n"));
180 LOG_STEPNAME(_L("EWaitEnumeration"));
184 // B-Device should now wait until it is configured
185 iCollector.AddRequiredNotification(EWatcherPeripheralState, EUsbcDeviceStateConfigured);
187 const TInt KTestCase0680BTimeout = 5000; // 5 seconds, should be plenty of time for overall test
188 iCollector.AddStepTimeout(KTestCase0680BTimeout);
190 iCaseStep = EBConfigured;
194 // A-Device should expect nothing more (role swap won't happen
195 // because the B-Device doesn't indicate support for OTG in its
196 // OTG descriptor, so the host won't have sent SetFeature(b_hnp_enable))
197 // Instead, just rely on the test timeout and display a request for the user
198 // to observe the B-Device test code for the pass/fail
199 const TInt KTestCase0680ATimeout = 4000; // 4 seconds before A-Device drops VBus (before B test times out at 5 seconds)
200 iCollector.AddStepTimeout(KTestCase0680ATimeout); // NB. In this test on the A-Device, we expect to timeout
201 // so a timeout isn't treated as a failure
202 test.Printf(_L("NOTE : Please observe test result on B-Device...\n"));
203 iCaseStep = EDropVBus; // This is the step the A-Device will go to
204 // when the timer (set up in previous test) fires
211 case EBConfigured: // A B-Device only step!
213 test.Printf(_L("Into EBConfigured step...\n"));
214 if (KTestCaseWatchdogTO == iStatus.Int())
216 iCollector.DestroyObservers();
217 return TestFailed(KErrAbort, _L("Timeout"));
220 iCollector.AddRequiredNotification(EWatcherMessage, RUsbOtgDriver::EMessageHnpNotSuspended);
222 test.Printf(_L("Attempting a swap on an unsuspended link...\n"));
223 err = otgBusRequest(); // Request the host role
227 test.Printf(_L("BusRequest returned %d)"),err);
228 return TestFailed(KErrAbort, _L("BusRequest() failed!"));
231 iCaseStep = EBErrorReceived;
236 case EBErrorReceived:
238 if (KTestCaseWatchdogTO == iStatus.Int())
240 iCollector.DestroyObservers();
241 return TestFailed(KErrAbort, _L("Timeout"));
244 test.Printf(_L("Into EBErrorReceived step...\n"));
245 iCaseStep = EDropVBus; // Test has pretty much passed now. Just wait for A-Device to drop VBus.
251 LOG_STEPNAME(_L("EDropVBus"))
253 iCollector.AddRequiredNotification(EWatcherEvent, RUsbOtgDriver::EEventVbusDropped);
254 if ( gTestRoleMaster)
256 iCollector.AddRequiredNotification(EWatcherState, RUsbOtgDriver::EStateBIdle);
260 iCollector.AddRequiredNotification(EWatcherState, RUsbOtgDriver::EStateAIdle);
263 iCaseStep = EVBusDropped;
268 LOG_STEPNAME(_L("ELoopVerifyDrop"))
269 if (KTestCaseWatchdogTO == iStatus.Int() && gTestRoleMaster)
271 // Remember, a timeout is only a failure for the B-Device in this test,
272 // we're expecting and relying on a timeout on the A-Device to conclude
273 // the test and bring VBus down.
274 return TestFailed(KErrAbort, _L("Timeout"));
277 if (otgVbusPresent())
279 return TestFailed(KErrAbort, _L("Vbus did not drop - FAILED!"));
281 iCaseStep = EUnloadLdd;
286 LOG_STEPNAME(_L("EUnloadLdd"))
287 iCollector.DestroyObservers();
289 if (EFalse == StepUnloadLDD())
290 return TestFailed(KErrAbort,_L("unload Ldd failure"));
291 if (!StepUnloadClient())
292 return TestFailed(KErrAbort,_L("Client Unload Failure"));
294 iCaseStep = ELastStep;
299 LOG_STEPNAME(_L("ELastStep"))
304 test.Printf(_L("<Error> unknown test step"));
306 return (TestFailed(KErrCorrupt, _L("<Error> unknown test step")));