os/kernelhwsrv/kerneltest/e32test/usbho/t_otgdi/src/testcase0680.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
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".
     7 //
     8 // Initial Contributors:
     9 // Nokia Corporation - initial contribution.
    10 //
    11 // Contributors:
    12 //
    13 // Description:
    14 // @internalComponent
    15 // 
    16 //
    17 
    18 #include <e32std.h>
    19 #include <e32std_private.h>
    20 #include <u32std.h> 	// unicode builds
    21 #include <e32base.h>
    22 #include <e32base_private.h>
    23 #include <e32Test.h>	// RTest headder
    24 #include "testcaseroot.h"
    25 #include "b2bwatchers.h"
    26 #include "testcase0680.h"
    27 
    28 #define _REPEATS (oOpenIterations*3)
    29 
    30 
    31 /* **************************************************************************************
    32  * the name below is used to add a pointer to our construction method to a pointer MAP in 
    33  * the class factory
    34  */
    35 _LIT(KTestCaseId,"PBASE-USB_OTGDI-0680");
    36 const TTestCaseFactoryReceipt<CTestCase0680> CTestCase0680::iFactoryReceipt(KTestCaseId);	
    37 
    38 CTestCase0680* CTestCase0680::NewL(TBool aHost)
    39 	{
    40 	LOG_FUNC
    41 	CTestCase0680* self = new (ELeave) CTestCase0680(aHost);
    42 	CleanupStack::PushL(self);
    43 	self->ConstructL();
    44 	CleanupStack::Pop(self);
    45 	return self;
    46 	}
    47 	
    48 
    49 CTestCase0680::CTestCase0680(TBool aHost)
    50 	: CTestCaseB2BRoot(KTestCaseId, aHost, iStatus) 
    51 	{
    52 	LOG_FUNC
    53 		
    54 	} 
    55 
    56 
    57 /**
    58  ConstructL
    59 */
    60 void CTestCase0680::ConstructL()
    61 	{
    62 	LOG_FUNC
    63 
    64 	iDualRoleCase = ETrue;	// another back-back
    65 		
    66 	BaseConstructL();
    67 	}
    68 
    69 
    70 CTestCase0680::~CTestCase0680()
    71 	{
    72 	LOG_FUNC
    73 	iCollector.DestroyObservers();
    74 	Cancel();
    75 	}
    76 
    77 
    78 void CTestCase0680::ExecuteTestCaseL()
    79 	{
    80 	LOG_FUNC
    81 	iCaseStep = EPreconditions;
    82 	CActiveScheduler::Add(this);
    83 	SelfComplete();
    84 	}
    85 
    86 	
    87 void CTestCase0680::DoCancel()
    88 	{
    89 	LOG_FUNC
    90 	// cancel our timer
    91 	iTimer.Cancel();
    92 	}
    93 
    94 
    95 // handle event completion	
    96 void CTestCase0680::RunStepL()
    97 	{
    98 	LOG_FUNC
    99 	// Obtain the completion code for this CActive obj.
   100 	TInt completionCode(iStatus.Int()); 
   101 	TBuf<MAX_DSTRLEN> aDescription;
   102 	TInt err(0);
   103 
   104 	switch(iCaseStep)
   105 		{
   106 		case EPreconditions:
   107 			{
   108 			LOG_STEPNAME(_L("EPreconditions"))
   109 			iCaseStep = ELoadLdd;
   110 			StepB2BPreconditions();				
   111 			break;
   112 			}
   113 			
   114 			// 1. Load the Client LDD 
   115 		case ELoadLdd:
   116 			{
   117 			LOG_STEPNAME(_L("ELoadLdd"))
   118 			if (!StepLoadClient(0xF680))	//	Use default params, so HNP/SRP both supported
   119 				{
   120 				return TestFailed(KErrAbort, _L("Client Load Failure"));
   121 				}
   122 			//  load OTG ldd and init.		
   123 			if (!StepLoadLDD())
   124 				{
   125 				return TestFailed(KErrAbort, _L("OTG Load Failure"));
   126 				}
   127 				
   128 			//	NB. We don't load the FDF Actor, because we don't want
   129 			//	the A-Host to suspend the attached B-Peripheral.
   130 			
   131 			// test that the right cable is in
   132 			CheckRoleConnections();
   133 					
   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;
   140 			SelfComplete();
   141 			break;
   142 			}
   143 			
   144 		case EReadyToRaiseVBus:
   145 			{
   146 			test.Printf(_L("Into EReadyToRaiseVBus step...\n"));
   147 			if (gTestRoleMaster)
   148 				{
   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);
   153 				}
   154 			else
   155 				{ // slave "A"
   156 				// Raise VBus, then wait for default role
   157 				err = otgBusRequest();	// ok to turn on VBus now
   158 				if (KErrNone != err)
   159 					{
   160 					return TestFailed(KErrAbort, _L("Raise Vbus - RUsbOtgDriver::BusRequest() FAILED!"));
   161 					}
   162 				
   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);
   167 				}
   168 
   169 			const TInt KTestCase0680VBusRaiseTimeout = 2000;	//	2 seconds, should be plenty of time for this test 
   170 			iCollector.AddStepTimeout(KTestCase0680VBusRaiseTimeout);
   171 
   172 			iCaseStep = EDefaultRoles;
   173 			SetActive();									
   174 			break;
   175 			}
   176 			
   177 		case EDefaultRoles:
   178 			{
   179 			test.Printf(_L("Into EDefaultRoles step...\n"));
   180 			LOG_STEPNAME(_L("EWaitEnumeration"));
   181 			
   182 			if (gTestRoleMaster)
   183 				{
   184 				//	B-Device should now wait until it is configured
   185 				iCollector.AddRequiredNotification(EWatcherPeripheralState, EUsbcDeviceStateConfigured);
   186 
   187 				const TInt KTestCase0680BTimeout = 5000;			//	5 seconds, should be plenty of time for overall test 
   188 				iCollector.AddStepTimeout(KTestCase0680BTimeout);
   189 
   190 				iCaseStep = EBConfigured;
   191 				}
   192 			else
   193 				{
   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
   205 				}
   206 			SetActive();
   207 			break;
   208 			}
   209 
   210 			
   211 		case EBConfigured:	//	A B-Device only step!
   212 			{
   213 			test.Printf(_L("Into EBConfigured step...\n"));
   214 			if (KTestCaseWatchdogTO == iStatus.Int())
   215 				{
   216 				iCollector.DestroyObservers();
   217 				return TestFailed(KErrAbort, _L("Timeout"));
   218 				}
   219 
   220 			iCollector.AddRequiredNotification(EWatcherMessage, RUsbOtgDriver::EMessageHnpNotSuspended);
   221 
   222 			test.Printf(_L("Attempting a swap on an unsuspended link...\n"));
   223 			err = otgBusRequest();	//	Request the host role
   224 
   225 			if (KErrNone != err)
   226 				{
   227 				test.Printf(_L("BusRequest returned %d)"),err);
   228 				return TestFailed(KErrAbort, _L("BusRequest() failed!"));
   229 				}			
   230 
   231 			iCaseStep = EBErrorReceived;
   232 			SetActive();
   233 			break;
   234 			}
   235 						
   236 		case EBErrorReceived:
   237 			{
   238 			if (KTestCaseWatchdogTO == iStatus.Int())
   239 				{
   240 				iCollector.DestroyObservers();
   241 				return TestFailed(KErrAbort, _L("Timeout"));
   242 				}
   243 
   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.
   246 			SelfComplete();
   247 			break;
   248 			}
   249 
   250 		case EDropVBus:
   251 			LOG_STEPNAME(_L("EDropVBus"))
   252 
   253 			iCollector.AddRequiredNotification(EWatcherEvent, RUsbOtgDriver::EEventVbusDropped);
   254 			if ( gTestRoleMaster)
   255 				{
   256 				iCollector.AddRequiredNotification(EWatcherState, RUsbOtgDriver::EStateBIdle);
   257 				}
   258 			else
   259 				{ // SLAVE "A"
   260 				iCollector.AddRequiredNotification(EWatcherState, RUsbOtgDriver::EStateAIdle);
   261 				otgBusDrop();
   262 				}
   263 			iCaseStep = EVBusDropped;
   264 			SetActive();
   265 			break;
   266 			
   267 		case EVBusDropped:
   268 			LOG_STEPNAME(_L("ELoopVerifyDrop"))
   269 			if (KTestCaseWatchdogTO == iStatus.Int() && gTestRoleMaster)
   270 				{
   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"));
   275 				}
   276 				
   277 			if (otgVbusPresent())
   278 				{
   279 				return TestFailed(KErrAbort, _L("Vbus did not drop - FAILED!"));
   280 				}
   281 			iCaseStep = EUnloadLdd;
   282 			SelfComplete();
   283 			break;
   284 			
   285 		case EUnloadLdd:
   286 			LOG_STEPNAME(_L("EUnloadLdd"))
   287 			iCollector.DestroyObservers();
   288 
   289 			if (EFalse == StepUnloadLDD())
   290 				return TestFailed(KErrAbort,_L("unload Ldd failure"));	
   291 			if (!StepUnloadClient())
   292 				return TestFailed(KErrAbort,_L("Client Unload Failure"));	
   293 
   294 			iCaseStep = ELastStep;
   295 			SelfComplete();
   296 			break;
   297 			
   298 		case ELastStep:
   299 			LOG_STEPNAME(_L("ELastStep"))
   300 			TestPassed();
   301 			break;
   302 			
   303 		default:
   304 			test.Printf(_L("<Error> unknown test step"));
   305 			Cancel();
   306 			return (TestFailed(KErrCorrupt, _L("<Error> unknown test step")));
   307 		}
   308 	}