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 "testcase0682.h"
28 #define _REPEATS (oOpenIterations*3)
30 /* **************************************************************************************
31 * the name below is used to add a pointer to our construction method to a pointer MAP in
34 _LIT(KTestCaseId,"PBASE-USB_OTGDI-0682");
35 const TTestCaseFactoryReceipt<CTestCase0682> CTestCase0682::iFactoryReceipt(KTestCaseId);
37 CTestCase0682* CTestCase0682::NewL(TBool aHost)
40 CTestCase0682* self = new (ELeave) CTestCase0682(aHost);
41 CleanupStack::PushL(self);
43 CleanupStack::Pop(self);
48 CTestCase0682::CTestCase0682(TBool aHost)
49 : CTestCaseB2BRoot(KTestCaseId, aHost, iStatus),
60 void CTestCase0682::ConstructL()
64 iDualRoleCase = ETrue; // another back-back
70 CTestCase0682::~CTestCase0682()
73 iCollector.DestroyObservers();
78 void CTestCase0682::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 CTestCase0682::DoCancel()
95 void CTestCase0682::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 CTestCase0682::RunStepL()
120 // Obtain the completion code for this CActive obj.
121 TInt completionCode(iStatus.Int());
122 TBuf<MAX_DSTRLEN> aDescription;
129 LOG_STEPNAME(_L("EPreconditions"))
130 iCaseStep = ELoadLdd;
131 StepB2BPreconditions();
135 // 1. Load the Client LDD
138 LOG_STEPNAME(_L("ELoadLdd"))
139 if (!StepLoadClient(0xF682/*use default settings for SRP/HNP support*/))
141 return TestFailed(KErrAbort, _L("Client Load Failure"));
143 // load OTG ldd and init.
146 return TestFailed(KErrAbort, _L("OTG Load Failure"));
149 if(otgActivateFdfActor()!=KErrNone)
151 return TestFailed(KErrAbort, _L("Couldn't load FDF Actor"));
154 // test that the right cable is in
155 CheckRoleConnections();
157 // subscribe to OTG states,events and messages now that it has loaded OK
158 TRAPD(result, iCollector.CreateObserversL(*this));
159 if (KErrNone != result)
160 return(TestFailed(KErrNoMemory, _L("Unable to create observers")));
161 iCollector.ClearAllEvents();
162 iCaseStep = EPerformSrp;
169 test.Printf(_L("Into EPerformSrp step...\n"));
174 iCollector.AddRequiredNotification(EWatcherState, RUsbOtgDriver::EStateBIdle);
175 iCollector.AddRequiredNotification(EWatcherEvent, RUsbOtgDriver::EEventSrpInitiated);
176 iCollector.AddRequiredNotification(EWatcherEvent, RUsbOtgDriver::EEventVbusRaised);
177 iCollector.AddRequiredNotification(EWatcherState, RUsbOtgDriver::EStateBPeripheral);
179 err = otgBusRequest(); // Should generate SRP
182 return TestFailed(KErrAbort, _L("Raise Vbus - RUsbOtgDriver::BusRequest() FAILED!"));
185 iCaseStep = EDefaultRoles;
190 iCollector.AddRequiredNotification(EWatcherEvent, RUsbOtgDriver::EEventSrpReceived);
192 iCaseStep = EAReceivedSrp;
194 const TInt KTestCase0681Timeout = 30000; // 30 seconds, should be plenty of time for 3 role swaps
195 iCollector.AddStepTimeout(KTestCase0681Timeout);
200 case EAReceivedSrp: // A-Device step only!
202 test.Printf(_L("Into EAReceivedSrp step...\n"));
204 if (KTestCaseWatchdogTO == iStatus.Int())
206 iCollector.DestroyObservers();
207 return TestFailed(KErrAbort, _L("Timeout"));
210 // We've received SRP. In this test, we use BusRequest to raise VBus but not cede the host role
211 // before we've enumerated and configured the device.
213 iCollector.AddRequiredNotification(EWatcherEvent, RUsbOtgDriver::EEventVbusRaised);
214 iCollector.AddRequiredNotification(EWatcherEvent, RUsbOtgDriver::EEventRoleChangedToHost);
215 iCollector.AddRequiredNotification(EWatcherState, RUsbOtgDriver::EStateAHost);
217 err = otgBusRequest();
220 return TestFailed(KErrAbort, _L("Raise Vbus - RUsbOtgDriver::BusRequest() FAILED!"));
223 iCaseStep = EDefaultRoles;
230 test.Printf(_L("Into EDefaultRoles step...\n"));
232 if ( --iHNPCounter >= 0)
234 // We want to do further role swapping
237 // B-Device should now wait until it is configured
238 iCollector.AddRequiredNotification(EWatcherPeripheralState, EUsbcDeviceStateConfigured);
239 iCaseStep = EBConfigured;
243 // A-Device should expect nothing more until it becomes A-Peripheral
244 iCollector.AddRequiredNotification(EWatcherState, RUsbOtgDriver::EStateAPeripheral);
245 iCaseStep = ESwappedRoles;
251 // We've done 3 x HNP cycles back to default roles.
252 // Time to shut down VBus and stop the test case.
253 iCaseStep = EDropVBus;
260 case EBConfigured: // A B-Device only step!
262 test.Printf(_L("Into EBConfigured step...\n"));
263 if (KTestCaseWatchdogTO == iStatus.Int())
265 iCollector.DestroyObservers();
266 return TestFailed(KErrAbort, _L("Timeout"));
268 iCollector.AddRequiredNotification(EWatcherPeripheralState, EUsbcDeviceStateSuspended);
269 iCaseStep = EBSuspended;
276 test.Printf(_L("Into EBSuspended step...\n"));
277 if (KTestCaseWatchdogTO == iStatus.Int())
279 iCollector.DestroyObservers();
280 return TestFailed(KErrAbort, _L("Timeout"));
284 iCollector.AddRequiredNotification(EWatcherState, RUsbOtgDriver::EStateBHost);
286 // The first time we arrive here, it should be unnecessary for the test code
287 // to issue a further bus request - it should "remember" that it earlier
288 // requested the host role, triggering SRP to be followed (hopefully now) by HNP
291 err = otgBusRequest(); // Request the host role
294 test.Printf(_L("BusRequest returned %d\n"),err);
295 return TestFailed(KErrAbort, _L("BusRequest() failed!"));
300 // So that we know next time around that we need to perform a bus request
301 iFirstRoleSwap = EFalse;
304 iCaseStep = ESwappedRoles;
311 test.Printf(_L("Into ESwappedRoles step...\n"));
312 if (KTestCaseWatchdogTO == iStatus.Int())
314 iCollector.DestroyObservers();
315 return TestFailed(KErrAbort, _L("Timeout"));
320 // B-Device should now wait until it is back to B-Peripheral
321 iCollector.AddRequiredNotification(EWatcherState, RUsbOtgDriver::EStateBPeripheral);
322 iCaseStep = EDefaultRoles;
326 // A-Device should wait to become a configured A-Peripheral
327 iCollector.AddRequiredNotification(EWatcherPeripheralState, EUsbcDeviceStateConfigured);
328 iCaseStep = EAConfigured;
334 case EAConfigured: // A-Device only step
336 test.Printf(_L("Into EWaitTillAConfigured step...\n"));
337 if (KTestCaseWatchdogTO == iStatus.Int())
339 iCollector.DestroyObservers();
340 return TestFailed(KErrAbort, _L("Timeout"));
343 iCollector.AddRequiredNotification(EWatcherPeripheralState, EUsbcDeviceStateSuspended);
344 iCaseStep = EASuspended;
349 case EASuspended: // A-Device only step
351 test.Printf(_L("Into EWaitTillASuspended step...\n"));
352 if (KTestCaseWatchdogTO == iStatus.Int())
354 iCollector.DestroyObservers();
355 return TestFailed(KErrAbort, _L("Timeout"));
358 iCollector.AddRequiredNotification(EWatcherState, RUsbOtgDriver::EStateAHost); // Swapping back to default role
360 iCaseStep = EDefaultRoles;
366 LOG_STEPNAME(_L("EDropVBus"))
368 iCollector.AddRequiredNotification(EWatcherEvent, RUsbOtgDriver::EEventVbusDropped);
369 if ( gTestRoleMaster)
371 iCollector.AddRequiredNotification(EWatcherState, RUsbOtgDriver::EStateBIdle);
372 iCollector.AddRequiredNotification(EWatcherEvent, RUsbOtgDriver::EEventRoleChangedToDevice);
377 iCollector.AddRequiredNotification(EWatcherState, RUsbOtgDriver::EStateAIdle);
378 iCollector.AddRequiredNotification(EWatcherEvent, RUsbOtgDriver::EEventRoleChangedToHost);
380 iCaseStep = EVBusDropped;
385 LOG_STEPNAME(_L("ELoopVerifyDrop"))
386 if (KTestCaseWatchdogTO == iStatus.Int())
388 return TestFailed(KErrAbort, _L("Timeout"));
391 if (otgVbusPresent())
393 return TestFailed(KErrAbort, _L("Vbus did not drop - FAILED!"));
395 iCaseStep = EUnloadLdd;
400 LOG_STEPNAME(_L("EUnloadLdd"))
401 otgDeactivateFdfActor();
402 iCollector.DestroyObservers();
403 if (EFalse == StepUnloadLDD())
404 return TestFailed(KErrAbort,_L("unload Ldd failure"));
405 if (!StepUnloadClient())
406 return TestFailed(KErrAbort,_L("Client Unload Failure"));
408 iCaseStep = ELastStep;
413 LOG_STEPNAME(_L("ELastStep"))
418 test.Printf(_L("<Error> unknown test step"));
420 return (TestFailed(KErrCorrupt, _L("<Error> unknown test step")));