kerneltest/e32test/usbho/t_otgdi/src/testcase0679.cpp
changeset 0 a41df078684a
child 43 c1f20ce4abcf
equal deleted inserted replaced
-1:000000000000 0:a41df078684a
       
     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 "testcase0679.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-0679");
       
    36 const TTestCaseFactoryReceipt<CTestCase0679> CTestCase0679::iFactoryReceipt(KTestCaseId);	
       
    37 
       
    38 CTestCase0679* CTestCase0679::NewL(TBool aHost)
       
    39 	{
       
    40 	LOG_FUNC
       
    41 	CTestCase0679* self = new (ELeave) CTestCase0679(aHost);
       
    42 	CleanupStack::PushL(self);
       
    43 	self->ConstructL();
       
    44 	CleanupStack::Pop(self);
       
    45 	return self;
       
    46 	}
       
    47 	
       
    48 
       
    49 CTestCase0679::CTestCase0679(TBool aHost)
       
    50 	: CTestCaseB2BRoot(KTestCaseId, aHost, iStatus) 
       
    51 	{
       
    52 	LOG_FUNC
       
    53 		
       
    54 	} 
       
    55 
       
    56 
       
    57 /**
       
    58  ConstructL
       
    59 */
       
    60 void CTestCase0679::ConstructL()
       
    61 	{
       
    62 	LOG_FUNC
       
    63 
       
    64 	iDualRoleCase = ETrue;	// another back-back
       
    65 		
       
    66 	BaseConstructL();
       
    67 	}
       
    68 
       
    69 
       
    70 CTestCase0679::~CTestCase0679()
       
    71 	{
       
    72 	LOG_FUNC
       
    73 	iCollector.DestroyObservers();
       
    74 	Cancel();
       
    75 	}
       
    76 
       
    77 
       
    78 void CTestCase0679::ExecuteTestCaseL()
       
    79 	{
       
    80 	LOG_FUNC
       
    81 	iCaseStep = EPreconditions;
       
    82 	CActiveScheduler::Add(this);
       
    83 	SelfComplete();
       
    84 	}
       
    85 
       
    86 	
       
    87 void CTestCase0679::DoCancel()
       
    88 	{
       
    89 	LOG_FUNC
       
    90 	// cancel our timer
       
    91 	iTimer.Cancel();
       
    92 	}
       
    93 
       
    94 
       
    95 // handle event completion	
       
    96 void CTestCase0679::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(0xF679, EFalse /*no HNP support!*/))
       
   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 			if(otgActivateFdfActor()!=KErrNone)
       
   129 				{
       
   130 				return TestFailed(KErrAbort, _L("Couldn't load FDF Actor"));
       
   131 				}
       
   132 			
       
   133 			// test that the right cable is in
       
   134 			CheckRoleConnections();
       
   135 					
       
   136 			// subscribe to OTG states,events and messages now that it has loaded OK
       
   137 			TRAPD(result, iCollector.CreateObserversL(*this));
       
   138 			if (KErrNone != result)
       
   139 				return(TestFailed(KErrNoMemory, _L("Unable to create observers")));
       
   140 			iCollector.ClearAllEvents();
       
   141 			iCaseStep = EReadyToRaiseVBus;
       
   142 			SelfComplete();
       
   143 			break;
       
   144 			}
       
   145 			
       
   146 		case EReadyToRaiseVBus:
       
   147 			{
       
   148 			if (gTestRoleMaster)
       
   149 				{
       
   150 				// wait for Vbus to be raised
       
   151 				iCollector.AddRequiredNotification(EWatcherState, RUsbOtgDriver::EStateBIdle);
       
   152 				iCollector.AddRequiredNotification(EWatcherEvent, RUsbOtgDriver::EEventVbusRaised);
       
   153 				iCollector.AddRequiredNotification(EWatcherState, RUsbOtgDriver::EStateBPeripheral);
       
   154 				}
       
   155 			else
       
   156 				{ // slave "A"
       
   157 				// Raise VBus, then wait for default role
       
   158 				err = otgBusRequest();	// ok to turn on VBus now
       
   159 				if (KErrNone != err)
       
   160 					{
       
   161 					return TestFailed(KErrAbort, _L("Raise Vbus - RUsbOtgDriver::BusRequest() FAILED!"));
       
   162 					}
       
   163 				
       
   164 				// we might also wait for and EStateAIdle
       
   165 				iCollector.AddRequiredNotification(EWatcherState, RUsbOtgDriver::EStateAIdle);
       
   166 				iCollector.AddRequiredNotification(EWatcherEvent, RUsbOtgDriver::EEventVbusRaised);
       
   167 				iCollector.AddRequiredNotification(EWatcherEvent, RUsbOtgDriver::EEventRoleChangedToHost);
       
   168 				}
       
   169 
       
   170 			const TInt KTestCase0679VBusRaiseTimeout = 2000;	//	2 seconds, should be plenty of time for this test 
       
   171 			iCollector.AddStepTimeout(KTestCase0679VBusRaiseTimeout);
       
   172 
       
   173 			iCaseStep = EDefaultRoles;
       
   174 			SetActive();									
       
   175 			break;
       
   176 			}
       
   177 			
       
   178 		case EDefaultRoles:
       
   179 			{
       
   180 			test.Printf(_L("Into EDefaultRoles step...\n"));
       
   181 			LOG_STEPNAME(_L("EWaitEnumeration"));
       
   182 			
       
   183 			if (gTestRoleMaster)
       
   184 				{
       
   185 				//	B-Device should now wait until it is configured
       
   186 				iCollector.AddRequiredNotification(EWatcherPeripheralState, EUsbcDeviceStateConfigured);
       
   187 
       
   188 				const TInt KTestCase0679BTimeout = 5000;			//	5 seconds, should be plenty of time for overall test 
       
   189 				iCollector.AddStepTimeout(KTestCase0679BTimeout);
       
   190 
       
   191 				iCaseStep = EBConfigured;
       
   192 				}
       
   193 			else
       
   194 				{
       
   195 				//	A-Device should expect nothing more (role swap won't happen
       
   196 				//	because the B-Device doesn't indicate support for OTG in its
       
   197 				//	OTG descriptor, so the host won't have sent SetFeature(b_hnp_enable))
       
   198 				//	Instead, just rely on the test timeout and display a request for the user 
       
   199 				//	to observe the B-Device test code for the pass/fail
       
   200 				const TInt KTestCase0679ATimeout = 4000;			//	4 seconds before A-Device drops VBus (before B test times out at 5 seconds)
       
   201 				iCollector.AddStepTimeout(KTestCase0679ATimeout);	//	NB. In this test on the A-Device, we expect to timeout
       
   202 																	//	so a timeout isn't treated as a failure
       
   203 				test.Printf(_L("NOTE : Please observe test result on B-Device...\n"));
       
   204 				iCaseStep = EDropVBus;	//	This is the step the A-Device will go to
       
   205 										//	when the timer (set up in previous test) fires
       
   206 				}
       
   207 			SetActive();
       
   208 			break;
       
   209 			}
       
   210 
       
   211 			
       
   212 		case EBConfigured:	//	A B-Device only step!
       
   213 			{
       
   214 			test.Printf(_L("Into EBConfigured step...\n"));
       
   215 			if (KTestCaseWatchdogTO == iStatus.Int())
       
   216 				{
       
   217 				iCollector.DestroyObservers();
       
   218 				return TestFailed(KErrAbort, _L("Timeout"));
       
   219 				}
       
   220 			iCollector.AddRequiredNotification(EWatcherPeripheralState, EUsbcDeviceStateSuspended);
       
   221 			iCaseStep = EBSuspended;
       
   222 			SetActive();
       
   223 			break;
       
   224 			}
       
   225 			
       
   226 		case EBSuspended:	
       
   227 			{
       
   228 			test.Printf(_L("Into EBSuspended step...\n"));
       
   229 			if (KTestCaseWatchdogTO == iStatus.Int())
       
   230 				{
       
   231 				iCollector.DestroyObservers();
       
   232 				return TestFailed(KErrAbort, _L("Timeout"));
       
   233 				}			
       
   234 			
       
   235 			// issue HNP
       
   236 			test.Printf(_L("Attempting a swap on a non-HNP enabled link...\n"));
       
   237 			iCollector.AddRequiredNotification(EWatcherMessage, RUsbOtgDriver::EMessageHnpNotEnabled);
       
   238 
       
   239 			err = otgBusRequest();	//	Request the host role
       
   240 
       
   241 			if (KErrNone != err)
       
   242 				{
       
   243 				test.Printf(_L("BusRequest returned %d)"),err);
       
   244 				//DS Temp! return TestFailed(KErrAbort, _L("BusRequest() failed!"));
       
   245 				}
       
   246 		
       
   247 			iCaseStep = EBErrorReceived;
       
   248 			SetActive();
       
   249 			break;
       
   250 			}
       
   251 			
       
   252 		case EBErrorReceived:
       
   253 			{
       
   254 			test.Printf(_L("Into EBErrorReceived step...\n"));
       
   255 			if (KTestCaseWatchdogTO == iStatus.Int())
       
   256 				{
       
   257 				iCollector.DestroyObservers();
       
   258 				return TestFailed(KErrAbort, _L("Timeout"));
       
   259 				}			
       
   260 			iCaseStep = EDropVBus;	//	Test has pretty much passed now. Just wait for A-Device to drop VBus.
       
   261 			SelfComplete();
       
   262 			break;
       
   263 			}
       
   264 
       
   265 		case EDropVBus:
       
   266 			LOG_STEPNAME(_L("EDropVBus"))
       
   267 
       
   268 			iCollector.AddRequiredNotification(EWatcherEvent, RUsbOtgDriver::EEventVbusDropped);
       
   269 			if ( gTestRoleMaster)
       
   270 				{
       
   271 				iCollector.AddRequiredNotification(EWatcherState, RUsbOtgDriver::EStateBIdle);
       
   272 				}
       
   273 			else
       
   274 				{ // SLAVE "A"
       
   275 				iCollector.AddRequiredNotification(EWatcherState, RUsbOtgDriver::EStateAIdle);
       
   276 				otgBusDrop();
       
   277 				}
       
   278 			iCaseStep = EVBusDropped;
       
   279 			SetActive();
       
   280 			break;
       
   281 			
       
   282 		case EVBusDropped:
       
   283 			LOG_STEPNAME(_L("EVBusDropped"))
       
   284 			if (KTestCaseWatchdogTO == iStatus.Int() && gTestRoleMaster)
       
   285 				{
       
   286 				//	Remember, a timeout is only a failure for the B-Device in this test,
       
   287 				//	we're expecting and relying on a timeout on the A-Device to conclude
       
   288 				//	the test and bring VBus down.
       
   289 				return TestFailed(KErrAbort, _L("Timeout"));
       
   290 				}
       
   291 				
       
   292 			if (otgVbusPresent())
       
   293 				{
       
   294 				return TestFailed(KErrAbort, _L("Vbus did not drop - FAILED!"));
       
   295 				}
       
   296 			iCaseStep = EUnloadLdd;
       
   297 			SelfComplete();
       
   298 			break;
       
   299 			
       
   300 		case EUnloadLdd:
       
   301 			LOG_STEPNAME(_L("EUnloadLdd"))
       
   302 			iCollector.DestroyObservers();
       
   303 			otgDeactivateFdfActor();
       
   304 			if (EFalse == StepUnloadLDD())
       
   305 				return TestFailed(KErrAbort,_L("unload Ldd failure"));	
       
   306 			if (!StepUnloadClient())
       
   307 				return TestFailed(KErrAbort,_L("Client Unload Failure"));	
       
   308 
       
   309 			iCaseStep = ELastStep;
       
   310 			SelfComplete();
       
   311 			break;
       
   312 			
       
   313 		case ELastStep:
       
   314 			LOG_STEPNAME(_L("ELastStep"))
       
   315 			TestPassed();
       
   316 			break;
       
   317 			
       
   318 		default:
       
   319 			test.Printf(_L("<Error> unknown test step"));
       
   320 			Cancel();
       
   321 			return (TestFailed(KErrCorrupt, _L("<Error> unknown test step")));
       
   322 		}
       
   323 	}