kerneltest/e32test/usbho/t_otgdi/src/testcase0678.cpp
changeset 0 a41df078684a
child 253 d37db4dcc88d
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 "testcasewd.h"
       
    26 #include "b2bwatchers.h"
       
    27 #include "testcase0678.h"
       
    28 
       
    29 #define _REPEATS (oOpenIterations*3)
       
    30 
       
    31 
       
    32 /* **************************************************************************************
       
    33  * the name below is used to add a pointer to our construction method to a pointer MAP in 
       
    34  * the class factory
       
    35  */
       
    36 _LIT(KTestCaseId,"PBASE-USB_OTGDI-0678");
       
    37 const TTestCaseFactoryReceipt<CTestCase0678> CTestCase0678::iFactoryReceipt(KTestCaseId);	
       
    38 
       
    39 CTestCase0678* CTestCase0678::NewL(TBool aHost)
       
    40 	{
       
    41 	LOG_FUNC
       
    42 	CTestCase0678* self = new (ELeave) CTestCase0678(aHost);
       
    43 	CleanupStack::PushL(self);
       
    44 	self->ConstructL();
       
    45 	CleanupStack::Pop(self);
       
    46 	return self;
       
    47 	}
       
    48 	
       
    49 
       
    50 CTestCase0678::CTestCase0678(TBool aHost)
       
    51 	: CTestCaseB2BRoot(KTestCaseId, aHost, iStatus) 
       
    52 	{
       
    53 	LOG_FUNC
       
    54 		
       
    55 	} 
       
    56 
       
    57 
       
    58 /**
       
    59  ConstructL
       
    60 */
       
    61 void CTestCase0678::ConstructL()
       
    62 	{
       
    63 	LOG_FUNC
       
    64 
       
    65 	iDualRoleCase = ETrue;	// another back-back
       
    66 		
       
    67 	BaseConstructL();
       
    68 	}
       
    69 
       
    70 
       
    71 CTestCase0678::~CTestCase0678()
       
    72 	{
       
    73 	LOG_FUNC
       
    74 	iCollector.DestroyObservers();
       
    75 	Cancel();
       
    76 	}
       
    77 
       
    78 
       
    79 void CTestCase0678::ExecuteTestCaseL()
       
    80 	{
       
    81 	LOG_FUNC
       
    82 	iCaseStep = EPreconditions;
       
    83 	iHNPCounter = 3;	//	To be decremented to govern the number of times we do HNP.
       
    84 	CActiveScheduler::Add(this);
       
    85 	SelfComplete();
       
    86 	}
       
    87 
       
    88 	
       
    89 void CTestCase0678::DoCancel()
       
    90 	{
       
    91 	LOG_FUNC
       
    92 	// cancel our timer
       
    93 	iTimer.Cancel();
       
    94 	}
       
    95 
       
    96 
       
    97 // handle event completion	
       
    98 void CTestCase0678::RunStepL()
       
    99 	{
       
   100 	LOG_FUNC
       
   101 	// Obtain the completion code for this CActive obj.
       
   102 	TInt completionCode(iStatus.Int()); 
       
   103 	TBuf<MAX_DSTRLEN> aDescription;
       
   104 	TInt err(0);
       
   105 
       
   106 	switch(iCaseStep)
       
   107 		{
       
   108 		case EPreconditions:
       
   109 			{
       
   110 			LOG_STEPNAME(_L("EPreconditions"))
       
   111 			iCaseStep = ELoadLdd;
       
   112 			StepB2BPreconditions();				
       
   113 			break;
       
   114 			}
       
   115 			
       
   116 			// 1. Load the Client LDD 
       
   117 		case ELoadLdd:
       
   118 			{
       
   119 			LOG_STEPNAME(_L("ELoadLdd"))
       
   120 			if (!StepLoadClient(0xF678/*use default settings for SRP/HNP support*/))
       
   121 				{
       
   122 				return TestFailed(KErrAbort, _L("Client Load Failure"));
       
   123 				}
       
   124 			//  load OTG ldd and init.		
       
   125 			if (!StepLoadLDD())
       
   126 				{
       
   127 				return TestFailed(KErrAbort, _L("OTG Load Failure"));
       
   128 				}
       
   129 				
       
   130 			if(otgActivateFdfActor()!=KErrNone)
       
   131 				{
       
   132 				return TestFailed(KErrAbort, _L("Couldn't load FDF Actor"));
       
   133 				}
       
   134 			
       
   135 			// test that the right cable is in
       
   136 			CheckRoleConnections();
       
   137 					
       
   138 			// subscribe to OTG states,events and messages now that it has loaded OK
       
   139 			TRAPD(result, iCollector.CreateObserversL(*this));
       
   140 			if (KErrNone != result)
       
   141 				return(TestFailed(KErrNoMemory, _L("Unable to create observers")));
       
   142 			iCollector.ClearAllEvents();
       
   143 			iCaseStep = EReadyToRaiseVBus;
       
   144 			SelfComplete();
       
   145 			break;
       
   146 			}
       
   147 			
       
   148 		case EReadyToRaiseVBus:
       
   149 			{
       
   150 			if (gTestRoleMaster)
       
   151 				{
       
   152 				// wait for Vbus to be raised
       
   153 				iCollector.AddRequiredNotification(EWatcherState, RUsbOtgDriver::EStateBIdle);
       
   154 				iCollector.AddRequiredNotification(EWatcherEvent, RUsbOtgDriver::EEventVbusRaised);
       
   155 				iCollector.AddRequiredNotification(EWatcherState, RUsbOtgDriver::EStateBPeripheral);
       
   156 				}
       
   157 			else
       
   158 				{ // slave "A"
       
   159 				// Raise VBus, then wait for default role
       
   160 				err = otgBusRequest();	// ok to turn on VBus now
       
   161 				if (KErrNone != err)
       
   162 					{
       
   163 					return TestFailed(KErrAbort, _L("Raise Vbus - RUsbOtgDriver::BusRequest() FAILED!"));
       
   164 					}
       
   165 				
       
   166 				// we might also wait for and EStateAIdle
       
   167 				iCollector.AddRequiredNotification(EWatcherState, RUsbOtgDriver::EStateAIdle);
       
   168 				iCollector.AddRequiredNotification(EWatcherEvent, RUsbOtgDriver::EEventVbusRaised);
       
   169 				iCollector.AddRequiredNotification(EWatcherEvent, RUsbOtgDriver::EEventRoleChangedToHost);
       
   170 				}
       
   171 			iCaseStep = EDefaultRoles;
       
   172 			const TInt KTestCase0678Timeout = 30000;			//	30 seconds, should be plenty of time for 3 role swaps
       
   173 			iCollector.AddStepTimeout(KTestCase0678Timeout);
       
   174 			SetActive();
       
   175 			break;
       
   176 			}
       
   177 			
       
   178 		case EDefaultRoles:
       
   179 			{
       
   180 			test.Printf(_L("Into EDefaultRoles step...\n"));
       
   181 			
       
   182 			if ( --iHNPCounter >= 0)
       
   183 				{
       
   184 				//	We want to do further role swapping
       
   185 				if (gTestRoleMaster)
       
   186 					{
       
   187 					//	B-Device should now wait until it is configured
       
   188 					iCollector.AddRequiredNotification(EWatcherPeripheralState, EUsbcDeviceStateConfigured);
       
   189 					iCaseStep = EBConfigured;
       
   190 					}
       
   191 				else
       
   192 					{
       
   193 					//	A-Device should expect nothing more until it becomes A-Peripheral
       
   194 					iCollector.AddRequiredNotification(EWatcherState, RUsbOtgDriver::EStateAPeripheral);
       
   195 					iCaseStep = ESwappedRoles;
       
   196 					}
       
   197 				SetActive();
       
   198 				}
       
   199 			else
       
   200 				{
       
   201 				//	We've done 3 x HNP cycles back to default roles. 
       
   202 				//	Time to shut down VBus and stop the test case.
       
   203 				iCaseStep = EDropVBus;
       
   204 				SelfComplete();
       
   205 				}
       
   206 			break;
       
   207 			}
       
   208 
       
   209 			
       
   210 		case EBConfigured:	//	A B-Device only step!
       
   211 			{
       
   212 			test.Printf(_L("Into EBConfigured step...\n"));
       
   213 			if (KTestCaseWatchdogTO == iStatus.Int())
       
   214 				{
       
   215 				iCollector.DestroyObservers();
       
   216 				return TestFailed(KErrAbort, _L("Timeout"));
       
   217 				}
       
   218 			iCollector.AddRequiredNotification(EWatcherPeripheralState, EUsbcDeviceStateSuspended);
       
   219 			iCaseStep = EBSuspended;
       
   220 			SetActive();
       
   221 			break;
       
   222 			}
       
   223 			
       
   224 		case EBSuspended:	
       
   225 			{
       
   226 			test.Printf(_L("Into EBSuspended step...\n"));
       
   227 			if (KTestCaseWatchdogTO == iStatus.Int())
       
   228 				{
       
   229 				iCollector.DestroyObservers();
       
   230 				return TestFailed(KErrAbort, _L("Timeout"));
       
   231 				}			
       
   232 			
       
   233 			// issue HNP
       
   234 			test.Printf(_L("VBus present, attempting a swap.\n"));
       
   235 			iCollector.AddRequiredNotification(EWatcherState, RUsbOtgDriver::EStateBHost);
       
   236 
       
   237 			err = otgBusRequest();	//	Request the host role
       
   238 
       
   239 			if (KErrNone != err)
       
   240 				{
       
   241 				test.Printf(_L("BusRequest returned %d\n"),err);
       
   242 				return TestFailed(KErrAbort, _L("BusRequest() failed!"));
       
   243 				}
       
   244 		
       
   245 			iCaseStep = ESwappedRoles;
       
   246 			SetActive();
       
   247 			break;
       
   248 			}
       
   249 			
       
   250 		case ESwappedRoles:
       
   251 			{
       
   252 			test.Printf(_L("Into ESwappedRoles step...\n"));
       
   253 			if (KTestCaseWatchdogTO == iStatus.Int())
       
   254 				{
       
   255 				iCollector.DestroyObservers();
       
   256 				return TestFailed(KErrAbort, _L("Timeout"));
       
   257 				}			
       
   258 
       
   259 			if (gTestRoleMaster)
       
   260 				{
       
   261 				//	B-Device should now wait until it is back to B-Peripheral
       
   262 				iCollector.AddRequiredNotification(EWatcherState, RUsbOtgDriver::EStateBPeripheral);
       
   263 				iCaseStep = EDefaultRoles;
       
   264 				}
       
   265 			else
       
   266 				{
       
   267 				//	A-Device should wait to become a configured A-Peripheral
       
   268 				iCollector.AddRequiredNotification(EWatcherPeripheralState, EUsbcDeviceStateConfigured);
       
   269 				iCaseStep = EAConfigured;
       
   270 				}
       
   271 			SetActive();
       
   272 			break;
       
   273 			}
       
   274 			
       
   275 		case EAConfigured:	//	A-Device only step
       
   276 			{
       
   277 			test.Printf(_L("Into EWaitTillAConfigured step...\n"));
       
   278 			if (KTestCaseWatchdogTO == iStatus.Int())
       
   279 				{
       
   280 				iCollector.DestroyObservers();
       
   281 				return TestFailed(KErrAbort, _L("Timeout"));
       
   282 				}			
       
   283 
       
   284 			iCollector.AddRequiredNotification(EWatcherPeripheralState, EUsbcDeviceStateSuspended);
       
   285 			iCaseStep = EASuspended;
       
   286 			SetActive();
       
   287 			break;
       
   288 			}
       
   289 		
       
   290 		case EASuspended:	//	A-Device only step
       
   291 			{
       
   292 			test.Printf(_L("Into EWaitTillASuspended step...\n"));
       
   293 			if (KTestCaseWatchdogTO == iStatus.Int())
       
   294 				{
       
   295 				iCollector.DestroyObservers();
       
   296 				return TestFailed(KErrAbort, _L("Timeout"));
       
   297 				}			
       
   298 			
       
   299 			iCollector.AddRequiredNotification(EWatcherState, RUsbOtgDriver::EStateAHost);	//	Swapping back to default role
       
   300 
       
   301 			iCaseStep = EDefaultRoles;
       
   302 			SetActive();
       
   303 			break;
       
   304 			}
       
   305 
       
   306 		case EDropVBus:
       
   307 			LOG_STEPNAME(_L("EDropVBus"))
       
   308 
       
   309 			iCollector.AddRequiredNotification(EWatcherEvent, RUsbOtgDriver::EEventVbusDropped);
       
   310 			if ( gTestRoleMaster)
       
   311 				{
       
   312 				iCollector.AddRequiredNotification(EWatcherState, RUsbOtgDriver::EStateBIdle);
       
   313 				iCollector.AddRequiredNotification(EWatcherEvent, RUsbOtgDriver::EEventRoleChangedToDevice);
       
   314 				}
       
   315 			else
       
   316 				{ // SLAVE "A"
       
   317 				otgBusDrop();
       
   318 				iCollector.AddRequiredNotification(EWatcherState, RUsbOtgDriver::EStateAIdle);
       
   319 				iCollector.AddRequiredNotification(EWatcherEvent, RUsbOtgDriver::EEventRoleChangedToHost);
       
   320 				}
       
   321 			iCaseStep = EVBusDropped;
       
   322 			SetActive();
       
   323 			break;
       
   324 			
       
   325 		case EVBusDropped:
       
   326 			LOG_STEPNAME(_L("ELoopVerifyDrop"))
       
   327 			if (KTestCaseWatchdogTO == iStatus.Int())
       
   328 				{
       
   329 				return TestFailed(KErrAbort, _L("Timeout"));
       
   330 				}
       
   331 				
       
   332 			if (otgVbusPresent())
       
   333 				{
       
   334 				return TestFailed(KErrAbort, _L("Vbus did not drop - FAILED!"));
       
   335 				}
       
   336 			iCaseStep = EUnloadLdd;
       
   337 			SelfComplete();
       
   338 			break;
       
   339 			
       
   340 		case EUnloadLdd:
       
   341 			LOG_STEPNAME(_L("EUnloadLdd"))
       
   342 			otgDeactivateFdfActor();
       
   343 			iCollector.DestroyObservers();
       
   344 			if (EFalse == StepUnloadLDD())
       
   345 				return TestFailed(KErrAbort,_L("unload Ldd failure"));	
       
   346 			if (!StepUnloadClient())
       
   347 				return TestFailed(KErrAbort,_L("Client Unload Failure"));	
       
   348 
       
   349 			iCaseStep = ELastStep;
       
   350 			SelfComplete();
       
   351 			break;
       
   352 			
       
   353 		case ELastStep:
       
   354 			LOG_STEPNAME(_L("ELastStep"))
       
   355 			TestPassed();
       
   356 			break;
       
   357 			
       
   358 		default:
       
   359 			test.Printf(_L("<Error> unknown test step"));
       
   360 			Cancel();
       
   361 			return (TestFailed(KErrCorrupt, _L("<Error> unknown test step")));
       
   362 		}
       
   363 	}
       
   364