kerneltest/e32test/usbho/t_otgdi/src/testcase0684.cpp
changeset 9 96e5fb8b040d
child 43 c1f20ce4abcf
equal deleted inserted replaced
-1:000000000000 9:96e5fb8b040d
       
     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 "testcase0684.h"
       
    28 
       
    29 #include <e32debug.h> 
       
    30 
       
    31 #define _REPEATS (oOpenIterations*3)
       
    32 
       
    33 
       
    34 /* **************************************************************************************
       
    35  * the name below is used to add a pointer to our construction method to a pointer MAP in 
       
    36  * the class factory
       
    37  */
       
    38 _LIT(KTestCaseId,"PBASE-USB_OTGDI-0684");
       
    39 const TTestCaseFactoryReceipt<CTestCase0684> CTestCase0684::iFactoryReceipt(KTestCaseId);	
       
    40 
       
    41 CTestCase0684* CTestCase0684::NewL(TBool aHost)
       
    42 	{
       
    43 	LOG_FUNC
       
    44 	CTestCase0684* self = new (ELeave) CTestCase0684(aHost);
       
    45 	CleanupStack::PushL(self);
       
    46 	self->ConstructL();
       
    47 	CleanupStack::Pop(self);
       
    48 	return self;
       
    49 	}
       
    50 	
       
    51 
       
    52 CTestCase0684::CTestCase0684(TBool aHost)
       
    53 	: CTestCaseB2BRoot(KTestCaseId, aHost, iStatus) 
       
    54 	{
       
    55 	LOG_FUNC
       
    56 		
       
    57 	} 
       
    58 
       
    59 
       
    60 /**
       
    61  ConstructL
       
    62 */
       
    63 void CTestCase0684::ConstructL()
       
    64 	{
       
    65 	LOG_FUNC
       
    66 
       
    67 	iDualRoleCase = ETrue;
       
    68 	iBusRequestCounter = 2;
       
    69 	iIsTimeToDrop = EFalse;
       
    70 	
       
    71 	BaseConstructL();
       
    72 	}
       
    73 
       
    74 
       
    75 CTestCase0684::~CTestCase0684()
       
    76 	{
       
    77 	LOG_FUNC
       
    78 	iCollector.DestroyObservers();
       
    79 	Cancel();
       
    80 	}
       
    81 
       
    82 
       
    83 void CTestCase0684::ExecuteTestCaseL()
       
    84 	{
       
    85 	LOG_FUNC
       
    86 	iCaseStep = EPreconditions;
       
    87 	CActiveScheduler::Add(this);
       
    88 	SelfComplete();
       
    89 	}
       
    90 
       
    91 	
       
    92 void CTestCase0684::DoCancel()
       
    93 	{
       
    94 	LOG_FUNC
       
    95 	// cancel our timer
       
    96 	iTimer.Cancel();
       
    97 	}
       
    98 void CTestCase0684::RunStepL()
       
    99 	{
       
   100 	LOG_FUNC
       
   101 	
       
   102 	// Obtain the completion code for this CActive obj.
       
   103 	TInt completionCode(iStatus.Int()); 
       
   104 	TBuf<MAX_DSTRLEN> aDescription;
       
   105 	TInt err(0);
       
   106 	
       
   107 	switch(iCaseStep)
       
   108 		{
       
   109 		case EPreconditions:
       
   110 			{
       
   111 			LOG_STEPNAME(_L("EPreconditions"))
       
   112 		
       
   113 			iCaseStep = ELoadLdd;
       
   114 			StepB2BPreconditions();	
       
   115 			break;
       
   116 			}
       
   117 			
       
   118 			// 1. Load the Client LDD 
       
   119 		case ELoadLdd:
       
   120 			{
       
   121 			LOG_STEPNAME(_L("ELoadLdd"))
       
   122 			
       
   123 			if (!StepLoadClient(0xF684/*use default settings for SRP/HNP support*/))
       
   124 				{
       
   125 				return TestFailed(KErrAbort, _L("Client Load Failure"));
       
   126 				}
       
   127 			
       
   128 			//  load OTG ldd and init.		
       
   129 			if (!StepLoadLDD())
       
   130 				{
       
   131 				return TestFailed(KErrAbort, _L("OTG Load Failure"));
       
   132 				}
       
   133 				
       
   134 			if(otgActivateFdfActor()!=KErrNone)
       
   135 				{
       
   136 				return TestFailed(KErrAbort, _L("Couldn't load FDF Actor"));
       
   137 				}
       
   138 			
       
   139 			// test that the right cable is in
       
   140 			CheckRoleConnections();
       
   141 					
       
   142 			// subscribe to OTG states,events and messages now that it has loaded OK
       
   143 			TRAPD(result, iCollector.CreateObserversL(*this));
       
   144 			if (KErrNone != result)
       
   145 				{
       
   146 				return(TestFailed(KErrNoMemory, _L("Unable to create observers")));
       
   147 				}
       
   148 			iCollector.ClearAllEvents();
       
   149 			iCaseStep = ESetMaxPower2Zero;
       
   150 			SelfComplete();
       
   151 			break;
       
   152 			}
       
   153 			
       
   154 		case ESetMaxPower2Zero:
       
   155 			LOG_STEPNAME(_L("ESetMaxPower2Zero"))
       
   156 			iCaseStep = EReadyToRaiseVBus;
       
   157 			SetMaxPowerToL(0);
       
   158 			SelfComplete();
       
   159 			break;
       
   160 			
       
   161 		case EReadyToRaiseVBus:
       
   162 			{
       
   163 			test.Printf(_L("Into EReadyToRaiseVBus step...\n"));
       
   164 			
       
   165 			if (gTestRoleMaster)
       
   166 				{
       
   167 				// B device, so , just wait for Vbus to be raised
       
   168 				iCollector.AddRequiredNotification(EWatcherState, RUsbOtgDriver::EStateBIdle);
       
   169 				iCollector.AddRequiredNotification(EWatcherEvent, RUsbOtgDriver::EEventVbusRaised);
       
   170 				iCollector.AddRequiredNotification(EWatcherEvent, RUsbOtgDriver::EEventHnpEnabled);
       
   171 				iCollector.AddRequiredNotification(EWatcherState, RUsbOtgDriver::EStateBPeripheral);
       
   172 				//	All as usual - we should report a failure if the B-Device ever reports "busy"
       
   173 				iCollector.AddFailureNotification(EWatcherAConnectionIdle, RUsbOtgDriver::EConnectionBusy);
       
   174 				}
       
   175 			else
       
   176 				{ 
       
   177 				// A device, Raise VBus, then wait for default role
       
   178 				err = otgBusRequest();	// ok to turn on VBus now
       
   179 				
       
   180 				if (KErrNone != err)
       
   181 					{
       
   182 					return TestFailed(KErrAbort, _L("Raise Vbus - RUsbOtgDriver::BusRequest() FAILED!"));
       
   183 					}
       
   184 				
       
   185 				// we might also wait for and EStateAIdle
       
   186 				iCollector.AddRequiredNotification(EWatcherState, RUsbOtgDriver::EStateAIdle);
       
   187 				iCollector.AddRequiredNotification(EWatcherEvent, RUsbOtgDriver::EEventVbusRaised);
       
   188 				iCollector.AddRequiredNotification(EWatcherEvent, RUsbOtgDriver::EEventRoleChangedToHost);
       
   189 				iCollector.AddRequiredNotification(EWatcherAConnectionIdle, RUsbOtgDriver::EConnectionBusy);
       
   190 				}
       
   191 			
       
   192 			iCaseStep = EDefaultRoles;
       
   193 			const TInt KTestCase0684Timeout = 30000;			//	30 seconds, should be plenty of time for 3 role swaps
       
   194 			iCollector.AddStepTimeout(KTestCase0684Timeout);
       
   195 			SetActive();
       
   196 			break;
       
   197 			}
       
   198 			
       
   199 		case EDefaultRoles:
       
   200 			{
       
   201 			test.Printf(_L("Into EDefaultRoles step...\n"));
       
   202 			if (KTestCaseWatchdogTO == iStatus.Int())
       
   203 				{
       
   204 				iCollector.DestroyObservers();
       
   205 				return TestFailed(KErrAbort, _L("Timeout"));
       
   206 				}			
       
   207 						
       
   208 			if(gTestRoleMaster){
       
   209 				// B
       
   210 				iCollector.AddRequiredNotification(EWatcherPeripheralState, EUsbcDeviceStateConfigured);
       
   211 				iCaseStep = EBConfigured;
       
   212 			}
       
   213 			else{
       
   214 				iCollector.AddRequiredNotification(EWatcherState, RUsbOtgDriver::EStateAPeripheral);
       
   215 				iCaseStep = EAToPeripheral;
       
   216 			}
       
   217 			SetActive();
       
   218 			break;
       
   219 			}
       
   220 			
       
   221 		case EAIdleHostPriorToAPeripheral:	//	an "A-Device only" step
       
   222 			{
       
   223 			test.Printf(_L("Into EAIdleHostPriorToAPeripheral step...\n"));
       
   224 			if (KTestCaseWatchdogTO == iStatus.Int())
       
   225 				{
       
   226 				iCollector.DestroyObservers();
       
   227 				return TestFailed(KErrAbort, _L("Timeout"));
       
   228 				}			
       
   229 				
       
   230 			//	A-Device should expect nothing more until it becomes A-Peripheral
       
   231 			iCollector.AddRequiredNotification(EWatcherState, RUsbOtgDriver::EStateAPeripheral);
       
   232 			iCollector.AddRequiredNotification(EWatcherAConnectionIdle, RUsbOtgDriver::EConnectionBusy);
       
   233 			iCollector.AddRequiredNotification(EWatcherPeripheralState, EUsbcDeviceStateConfigured);
       
   234 			iCollector.AddRequiredNotification(EWatcherState, RUsbOtgDriver::EStateAHost);
       
   235 			iCaseStep = EAToHost;
       
   236 			SetActive();
       
   237 			break;
       
   238 			}	
       
   239 			
       
   240 		case EBConfigured:
       
   241 			{
       
   242 			test.Printf(_L("Into EBConfigured step...\n"));
       
   243 			if (KTestCaseWatchdogTO == iStatus.Int())
       
   244 				{
       
   245 				iCollector.DestroyObservers();
       
   246 				RDebug::Print(_L("Timeout"));
       
   247 				return TestFailed(KErrAbort, _L("Timeout"));
       
   248 				}
       
   249 			iCollector.AddRequiredNotification(EWatcherPeripheralState, EUsbcDeviceStateSuspended);
       
   250 			iCaseStep = EBSuspended;
       
   251 			SetActive();
       
   252 			break;
       
   253 			}
       
   254 			
       
   255 		case EBSuspended:
       
   256 			{
       
   257 			test.Printf(_L("Into EBSuspended step...\n"));					
       
   258 			if (KTestCaseWatchdogTO == iStatus.Int())
       
   259 				{
       
   260 				iCollector.DestroyObservers();
       
   261 				RDebug::Print(_L("Timeout"));
       
   262 				return TestFailed(KErrAbort, _L("Timeout"));
       
   263 				}
       
   264 			
       
   265 			if(iBusRequestCounter > 0){
       
   266 				test.Printf(_L("VBus present, attempting a swap.\n"));
       
   267 				iCollector.AddRequiredNotification(EWatcherState, RUsbOtgDriver::EStateBHost);
       
   268 				
       
   269 				iBusRequestCounter --;
       
   270 				err = otgBusRequest();	//	Request the host role
       
   271 				if (KErrNone != err)
       
   272 					{
       
   273 					test.Printf(_L("BusRequest returned %d\n"),err);
       
   274 					return TestFailed(KErrAbort, _L("BusRequest() failed!"));
       
   275 					}
       
   276 				iCaseStep = EBToHost;
       
   277 			}
       
   278 			else{
       
   279 				iCollector.AddRequiredNotification(EWatcherAConnectionIdle, RUsbOtgDriver::EConnectionIdle);
       
   280 				iCaseStep = EIdleHostPriorToVBusDown;
       
   281 			}	
       
   282 			SetActive();
       
   283 			break;
       
   284 			}
       
   285 			
       
   286 		case EAToHost:
       
   287 			{
       
   288 			test.Printf(_L("Into EAToHost step...\n"));
       
   289 			if (KTestCaseWatchdogTO == iStatus.Int())
       
   290 				{
       
   291 				iCollector.DestroyObservers();
       
   292 				return TestFailed(KErrAbort, _L("Timeout"));
       
   293 				}
       
   294 			
       
   295 			if( ! iIsTimeToDrop){
       
   296 				iIsTimeToDrop = ETrue;
       
   297 				SetMaxPowerToL(50);
       
   298 				TUint16 val = 0;
       
   299 				GetMaxPower(val);
       
   300 				test.Printf(_L("bMaxPower= %d\n"), val);
       
   301 				iCollector.AddRequiredNotification(EWatcherState, RUsbOtgDriver::EStateAPeripheral);
       
   302 				iCaseStep = EAToPeripheral;
       
   303 			}
       
   304 			else{
       
   305 				iCollector.AddRequiredNotification(EWatcherAConnectionIdle, RUsbOtgDriver::EConnectionIdle);
       
   306 				iCaseStep = EIdleHostPriorToVBusDown;
       
   307 			}
       
   308 			
       
   309 			SetActive();
       
   310 			break;			
       
   311 			}
       
   312 			
       
   313 		case EAToPeripheral:
       
   314 			{
       
   315 			test.Printf(_L("Into EAToPeripheral step...\n"));
       
   316 			if (KTestCaseWatchdogTO == iStatus.Int())
       
   317 				{
       
   318 				iCollector.DestroyObservers();
       
   319 				return TestFailed(KErrAbort, _L("Timeout"));
       
   320 				}
       
   321 			iCollector.AddRequiredNotification(EWatcherState, RUsbOtgDriver::EStateAHost);
       
   322 			iCaseStep = EAToHost;
       
   323 			SetActive();
       
   324 			break;
       
   325 			}
       
   326 		
       
   327 		case EBToHost:
       
   328 			{
       
   329 			test.Printf(_L("Into EBToHost step...\n"));
       
   330 			if (KTestCaseWatchdogTO == iStatus.Int())
       
   331 				{
       
   332 				iCollector.DestroyObservers();
       
   333 				return TestFailed(KErrAbort, _L("Timeout"));
       
   334 				}
       
   335 			iCollector.AddRequiredNotification(EWatcherState, RUsbOtgDriver::EStateBPeripheral);
       
   336 			iCaseStep = EBToPeripheral;
       
   337 			SetActive();
       
   338 			break;
       
   339 			}
       
   340 			
       
   341 		case EBToPeripheral:
       
   342 			{
       
   343 			test.Printf(_L("Into EBToPeripheral step...\n"));
       
   344 			if (KTestCaseWatchdogTO == iStatus.Int())
       
   345 				{
       
   346 				iCollector.DestroyObservers();
       
   347 				return TestFailed(KErrAbort, _L("Timeout"));
       
   348 				}
       
   349 			if(iBusRequestCounter > 0)
       
   350 				{
       
   351 				iCollector.AddRequiredNotification(EWatcherPeripheralState, EUsbcDeviceStateConfigured);
       
   352 				iCaseStep = EBConfigured;
       
   353 				}
       
   354 			else
       
   355 				{
       
   356 				iCollector.AddRequiredNotification(EWatcherEvent, RUsbOtgDriver::EEventVbusDropped);
       
   357 				iCaseStep = EVBusDropped;
       
   358 				}
       
   359 			SetActive();
       
   360 			break;
       
   361 			}
       
   362 			
       
   363 		case EIdleHostPriorToVBusDown:
       
   364 			{
       
   365 			test.Printf(_L("Into EAIdleHostPriorToVBusDown step...\n"));
       
   366 			
       
   367 			if (KTestCaseWatchdogTO == iStatus.Int())
       
   368 				{
       
   369 				iCollector.DestroyObservers();
       
   370 				return TestFailed(KErrAbort, _L("Timeout"));
       
   371 				}			
       
   372 	
       
   373 			iCaseStep = EDropVBus;
       
   374 			SelfComplete();
       
   375 			break;
       
   376 			}
       
   377 			
       
   378 		case EDropVBus:
       
   379 			LOG_STEPNAME(_L("EDropVBus"))
       
   380 			if (KTestCaseWatchdogTO == iStatus.Int())
       
   381 				{
       
   382 				iCollector.DestroyObservers();
       
   383 				return TestFailed(KErrAbort, _L("Timeout"));
       
   384 				}			
       
   385 
       
   386 			iCollector.AddRequiredNotification(EWatcherEvent, RUsbOtgDriver::EEventVbusDropped);
       
   387 			if ( gTestRoleMaster)
       
   388 				{
       
   389 				iCollector.AddRequiredNotification(EWatcherState, RUsbOtgDriver::EStateBIdle);
       
   390 				}
       
   391 			else
       
   392 				{ // SLAVE "A"
       
   393 				otgBusDrop();
       
   394 				iCollector.AddRequiredNotification(EWatcherState, RUsbOtgDriver::EStateAIdle);
       
   395 				}
       
   396 			iCaseStep = EVBusDropped;
       
   397 			SetActive();
       
   398 			break;
       
   399 			
       
   400 		case EVBusDropped:
       
   401 			LOG_STEPNAME(_L("ELoopVerifyDrop"))
       
   402 			if (KTestCaseWatchdogTO == iStatus.Int())
       
   403 				{
       
   404 				return TestFailed(KErrAbort, _L("Timeout"));
       
   405 				}
       
   406 				
       
   407 			if (otgVbusPresent())
       
   408 				{
       
   409 				return TestFailed(KErrAbort, _L("Vbus did not drop - FAILED!"));
       
   410 				}
       
   411 			iCaseStep = EUnloadLdd;
       
   412 			SelfComplete();
       
   413 			break;
       
   414 			
       
   415 		case EUnloadLdd:
       
   416 			LOG_STEPNAME(_L("EUnloadLdd"))
       
   417 			otgDeactivateFdfActor();
       
   418 			iCollector.DestroyObservers();
       
   419 			if (EFalse == StepUnloadLDD()){
       
   420 				return TestFailed(KErrAbort,_L("unload Ldd failure"));
       
   421 			}
       
   422 			if (!StepUnloadClient()){
       
   423 				return TestFailed(KErrAbort,_L("Client Unload Failure"));
       
   424 			}
       
   425 
       
   426 			iCaseStep = ELastStep;
       
   427 			SelfComplete();
       
   428 			break;
       
   429 			
       
   430 		case ELastStep:
       
   431 			LOG_STEPNAME(_L("ELastStep"))
       
   432 			TestPassed();
       
   433 			RequestCharacter();	
       
   434 			break;
       
   435 			
       
   436 		default:
       
   437 			test.Printf(_L("<Error> unknown test step"));
       
   438 			Cancel();
       
   439 			RequestCharacter();	
       
   440 			return (TestFailed(KErrCorrupt, _L("<Error> unknown test step")));
       
   441 		}
       
   442 	
       
   443 	}