kerneltest/e32test/usbho/t_otgdi/src/testcase0684.cpp
branchRCL_3
changeset 44 3e88ff8f41d5
parent 43 c1f20ce4abcf
equal deleted inserted replaced
43:c1f20ce4abcf 44:3e88ff8f41d5
     1 // Copyright (c) 2007-2010 Nokia Corporation and/or its subsidiary(-ies).
     1 // Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
     2 // All rights reserved.
     2 // All rights reserved.
     3 // This component and the accompanying materials are made available
     3 // This component and the accompanying materials are made available
     4 // under the terms of the License "Eclipse Public License v1.0"
     4 // under the terms of the License "Eclipse Public License v1.0"
     5 // which accompanies this distribution, and is available
     5 // which accompanies this distribution, and is available
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
    23 #include <e32Test.h>	// RTest headder
    23 #include <e32Test.h>	// RTest headder
    24 #include "testcaseroot.h"
    24 #include "testcaseroot.h"
    25 //#include "testcasewd.h"
    25 //#include "testcasewd.h"
    26 #include "b2bwatchers.h"
    26 #include "b2bwatchers.h"
    27 #include "testcase0684.h"
    27 #include "testcase0684.h"
    28 #include "OstTraceDefinitions.h"
       
    29 #ifdef OST_TRACE_COMPILER_IN_USE
       
    30 #include "testcase0684Traces.h"
       
    31 #endif
       
    32 
    28 
    33 #include <e32debug.h> 
    29 #include <e32debug.h> 
    34 
    30 
    35 #define _REPEATS (oOpenIterations*3)
    31 #define _REPEATS (oOpenIterations*3)
    36 
    32 
    42 _LIT(KTestCaseId,"PBASE-USB_OTGDI-0684");
    38 _LIT(KTestCaseId,"PBASE-USB_OTGDI-0684");
    43 const TTestCaseFactoryReceipt<CTestCase0684> CTestCase0684::iFactoryReceipt(KTestCaseId);	
    39 const TTestCaseFactoryReceipt<CTestCase0684> CTestCase0684::iFactoryReceipt(KTestCaseId);	
    44 
    40 
    45 CTestCase0684* CTestCase0684::NewL(TBool aHost)
    41 CTestCase0684* CTestCase0684::NewL(TBool aHost)
    46 	{
    42 	{
    47 	if(gVerboseOutput)
    43 	LOG_FUNC
    48 	    {
       
    49 	    OstTraceFunctionEntry0(CTESTCASE0684_NEWL);
       
    50 	    }
       
    51 	CTestCase0684* self = new (ELeave) CTestCase0684(aHost);
    44 	CTestCase0684* self = new (ELeave) CTestCase0684(aHost);
    52 	CleanupStack::PushL(self);
    45 	CleanupStack::PushL(self);
    53 	self->ConstructL();
    46 	self->ConstructL();
    54 	CleanupStack::Pop(self);
    47 	CleanupStack::Pop(self);
    55 	return self;
    48 	return self;
    57 	
    50 	
    58 
    51 
    59 CTestCase0684::CTestCase0684(TBool aHost)
    52 CTestCase0684::CTestCase0684(TBool aHost)
    60 	: CTestCaseB2BRoot(KTestCaseId, aHost, iStatus) 
    53 	: CTestCaseB2BRoot(KTestCaseId, aHost, iStatus) 
    61 	{
    54 	{
    62 	if(gVerboseOutput)
    55 	LOG_FUNC
    63 	    {
       
    64 	    OstTraceFunctionEntry0(CTESTCASE0684_CTESTCASE0684);
       
    65 	    }
       
    66 		
    56 		
    67 	} 
    57 	} 
    68 
    58 
    69 
    59 
    70 /**
    60 /**
    71  ConstructL
    61  ConstructL
    72 */
    62 */
    73 void CTestCase0684::ConstructL()
    63 void CTestCase0684::ConstructL()
    74 	{
    64 	{
    75 	if(gVerboseOutput)
    65 	LOG_FUNC
    76 	    {
       
    77 	    OstTraceFunctionEntry0(CTESTCASE0684_CONSTRUCTL);
       
    78 	    }
       
    79 
    66 
    80 	iDualRoleCase = ETrue;
    67 	iDualRoleCase = ETrue;
    81 	iBusRequestCounter = 2;
    68 	iBusRequestCounter = 2;
    82 	iIsTimeToDrop = EFalse;
    69 	iIsTimeToDrop = EFalse;
    83 	
    70 	
    85 	}
    72 	}
    86 
    73 
    87 
    74 
    88 CTestCase0684::~CTestCase0684()
    75 CTestCase0684::~CTestCase0684()
    89 	{
    76 	{
    90 	if(gVerboseOutput)
    77 	LOG_FUNC
    91 	    {
       
    92 	    OstTraceFunctionEntry0(CTESTCASE0684_DCTESTCASE0684);
       
    93 	    }
       
    94 	iCollector.DestroyObservers();
    78 	iCollector.DestroyObservers();
    95 	Cancel();
    79 	Cancel();
    96 	}
    80 	}
    97 
    81 
    98 
    82 
    99 void CTestCase0684::ExecuteTestCaseL()
    83 void CTestCase0684::ExecuteTestCaseL()
   100 	{
    84 	{
   101 	if(gVerboseOutput)
    85 	LOG_FUNC
   102 	    {
       
   103 	    OstTraceFunctionEntry0(CTESTCASE0684_EXECUTETESTCASEL);
       
   104 	    }
       
   105 	iCaseStep = EPreconditions;
    86 	iCaseStep = EPreconditions;
   106 	CActiveScheduler::Add(this);
    87 	CActiveScheduler::Add(this);
   107 	SelfComplete();
    88 	SelfComplete();
   108 	}
    89 	}
   109 
    90 
   110 	
    91 	
   111 void CTestCase0684::DoCancel()
    92 void CTestCase0684::DoCancel()
   112 	{
    93 	{
   113 	if(gVerboseOutput)
    94 	LOG_FUNC
   114 	    {
       
   115 	    OstTraceFunctionEntry0(CTESTCASE0684_DOCANCEL);
       
   116 	    }
       
   117 	// cancel our timer
    95 	// cancel our timer
   118 	iTimer.Cancel();
    96 	iTimer.Cancel();
   119 	}
    97 	}
   120 void CTestCase0684::RunStepL()
    98 void CTestCase0684::RunStepL()
   121 	{
    99 	{
   122 	if(gVerboseOutput)
   100 	LOG_FUNC
   123 	    {
       
   124 	    OstTraceFunctionEntry0(CTESTCASE0684_RUNSTEPL);
       
   125 	    }
       
   126 	
   101 	
   127 	// Obtain the completion code for this CActive obj.
   102 	// Obtain the completion code for this CActive obj.
   128 	TInt completionCode(iStatus.Int()); 
   103 	TInt completionCode(iStatus.Int()); 
   129 	TBuf<MAX_DSTRLEN> aDescription;
   104 	TBuf<MAX_DSTRLEN> aDescription;
   130 	TInt err(0);
   105 	TInt err(0);
   184 			break;
   159 			break;
   185 			
   160 			
   186 		case EReadyToRaiseVBus:
   161 		case EReadyToRaiseVBus:
   187 			{
   162 			{
   188 			test.Printf(_L("Into EReadyToRaiseVBus step...\n"));
   163 			test.Printf(_L("Into EReadyToRaiseVBus step...\n"));
   189 			OstTrace0(TRACE_NORMAL, CTESTCASE0684_RUNSTEPL_DUP01, "Into EReadyToRaiseVBus step...\n");
       
   190 			
   164 			
   191 			if (gTestRoleMaster)
   165 			if (gTestRoleMaster)
   192 				{
   166 				{
   193 				// B device, so , just wait for Vbus to be raised
   167 				// B device, so , just wait for Vbus to be raised
   194 				iCollector.AddRequiredNotification(EWatcherState, RUsbOtgDriver::EStateBIdle);
   168 				iCollector.AddRequiredNotification(EWatcherState, RUsbOtgDriver::EStateBIdle);
   223 			}
   197 			}
   224 			
   198 			
   225 		case EDefaultRoles:
   199 		case EDefaultRoles:
   226 			{
   200 			{
   227 			test.Printf(_L("Into EDefaultRoles step...\n"));
   201 			test.Printf(_L("Into EDefaultRoles step...\n"));
   228 			OstTrace0(TRACE_NORMAL, CTESTCASE0684_RUNSTEPL_DUP02, "Into EDefaultRoles step...\n");
       
   229 			if (KTestCaseWatchdogTO == iStatus.Int())
   202 			if (KTestCaseWatchdogTO == iStatus.Int())
   230 				{
   203 				{
   231 				iCollector.DestroyObservers();
   204 				iCollector.DestroyObservers();
   232 				return TestFailed(KErrAbort, _L("Timeout"));
   205 				return TestFailed(KErrAbort, _L("Timeout"));
   233 				}			
   206 				}			
   246 			}
   219 			}
   247 			
   220 			
   248 		case EAIdleHostPriorToAPeripheral:	//	an "A-Device only" step
   221 		case EAIdleHostPriorToAPeripheral:	//	an "A-Device only" step
   249 			{
   222 			{
   250 			test.Printf(_L("Into EAIdleHostPriorToAPeripheral step...\n"));
   223 			test.Printf(_L("Into EAIdleHostPriorToAPeripheral step...\n"));
   251 			OstTrace0(TRACE_NORMAL, CTESTCASE0684_RUNSTEPL_DUP03, "Into EAIdleHostPriorToAPeripheral step...\n");
       
   252 			if (KTestCaseWatchdogTO == iStatus.Int())
   224 			if (KTestCaseWatchdogTO == iStatus.Int())
   253 				{
   225 				{
   254 				iCollector.DestroyObservers();
   226 				iCollector.DestroyObservers();
   255 				return TestFailed(KErrAbort, _L("Timeout"));
   227 				return TestFailed(KErrAbort, _L("Timeout"));
   256 				}			
   228 				}			
   266 			}	
   238 			}	
   267 			
   239 			
   268 		case EBConfigured:
   240 		case EBConfigured:
   269 			{
   241 			{
   270 			test.Printf(_L("Into EBConfigured step...\n"));
   242 			test.Printf(_L("Into EBConfigured step...\n"));
   271 			OstTrace0(TRACE_NORMAL, CTESTCASE0684_RUNSTEPL_DUP04, "Into EBConfigured step...\n");
   243 			if (KTestCaseWatchdogTO == iStatus.Int())
   272 			if (KTestCaseWatchdogTO == iStatus.Int())
   244 				{
   273 				{
   245 				iCollector.DestroyObservers();
   274 				iCollector.DestroyObservers();
   246 				RDebug::Print(_L("Timeout"));
   275 				OstTrace0(TRACE_NORMAL, CTESTCASE0684_RUNSTEPL_DUP05, "Timeout");
       
   276 				return TestFailed(KErrAbort, _L("Timeout"));
   247 				return TestFailed(KErrAbort, _L("Timeout"));
   277 				}
   248 				}
   278 			iCollector.AddRequiredNotification(EWatcherPeripheralState, EUsbcDeviceStateSuspended);
   249 			iCollector.AddRequiredNotification(EWatcherPeripheralState, EUsbcDeviceStateSuspended);
   279 			iCaseStep = EBSuspended;
   250 			iCaseStep = EBSuspended;
   280 			SetActive();
   251 			SetActive();
   282 			}
   253 			}
   283 			
   254 			
   284 		case EBSuspended:
   255 		case EBSuspended:
   285 			{
   256 			{
   286 			test.Printf(_L("Into EBSuspended step...\n"));					
   257 			test.Printf(_L("Into EBSuspended step...\n"));					
   287 			OstTrace0(TRACE_NORMAL, CTESTCASE0684_RUNSTEPL_DUP06, "Into EBSuspended step...\n");					
   258 			if (KTestCaseWatchdogTO == iStatus.Int())
   288 			if (KTestCaseWatchdogTO == iStatus.Int())
   259 				{
   289 				{
   260 				iCollector.DestroyObservers();
   290 				iCollector.DestroyObservers();
   261 				RDebug::Print(_L("Timeout"));
   291 				OstTrace0(TRACE_NORMAL, CTESTCASE0684_RUNSTEPL_DUP07, "Timeout");
       
   292 				return TestFailed(KErrAbort, _L("Timeout"));
   262 				return TestFailed(KErrAbort, _L("Timeout"));
   293 				}
   263 				}
   294 			
   264 			
   295 			if(iBusRequestCounter > 0){
   265 			if(iBusRequestCounter > 0){
   296 				test.Printf(_L("VBus present, attempting a swap.\n"));
   266 				test.Printf(_L("VBus present, attempting a swap.\n"));
   297 				OstTrace0(TRACE_NORMAL, CTESTCASE0684_RUNSTEPL_DUP08, "VBus present, attempting a swap.\n");
       
   298 				iCollector.AddRequiredNotification(EWatcherState, RUsbOtgDriver::EStateBHost);
   267 				iCollector.AddRequiredNotification(EWatcherState, RUsbOtgDriver::EStateBHost);
   299 				
   268 				
   300 				iBusRequestCounter --;
   269 				iBusRequestCounter --;
   301 				err = otgBusRequest();	//	Request the host role
   270 				err = otgBusRequest();	//	Request the host role
   302 				if (KErrNone != err)
   271 				if (KErrNone != err)
   303 					{
   272 					{
   304 					test.Printf(_L("BusRequest returned %d\n"),err);
   273 					test.Printf(_L("BusRequest returned %d\n"),err);
   305 					OstTrace1(TRACE_NORMAL, CTESTCASE0684_RUNSTEPL_DUP09, "BusRequest returned %d\n",err);
       
   306 					return TestFailed(KErrAbort, _L("BusRequest() failed!"));
   274 					return TestFailed(KErrAbort, _L("BusRequest() failed!"));
   307 					}
   275 					}
   308 				iCaseStep = EBToHost;
   276 				iCaseStep = EBToHost;
   309 			}
   277 			}
   310 			else{
   278 			else{
   316 			}
   284 			}
   317 			
   285 			
   318 		case EAToHost:
   286 		case EAToHost:
   319 			{
   287 			{
   320 			test.Printf(_L("Into EAToHost step...\n"));
   288 			test.Printf(_L("Into EAToHost step...\n"));
   321 			OstTrace0(TRACE_NORMAL, CTESTCASE0684_RUNSTEPL_DUP10, "Into EAToHost step...\n");
       
   322 			if (KTestCaseWatchdogTO == iStatus.Int())
   289 			if (KTestCaseWatchdogTO == iStatus.Int())
   323 				{
   290 				{
   324 				iCollector.DestroyObservers();
   291 				iCollector.DestroyObservers();
   325 				return TestFailed(KErrAbort, _L("Timeout"));
   292 				return TestFailed(KErrAbort, _L("Timeout"));
   326 				}
   293 				}
   329 				iIsTimeToDrop = ETrue;
   296 				iIsTimeToDrop = ETrue;
   330 				SetMaxPowerToL(50);
   297 				SetMaxPowerToL(50);
   331 				TUint16 val = 0;
   298 				TUint16 val = 0;
   332 				GetMaxPower(val);
   299 				GetMaxPower(val);
   333 				test.Printf(_L("bMaxPower= %d\n"), val);
   300 				test.Printf(_L("bMaxPower= %d\n"), val);
   334 				OstTrace1(TRACE_NORMAL, CTESTCASE0684_RUNSTEPL_DUP11, "bMaxPower= %d\n", val);
       
   335 				iCollector.AddRequiredNotification(EWatcherState, RUsbOtgDriver::EStateAPeripheral);
   301 				iCollector.AddRequiredNotification(EWatcherState, RUsbOtgDriver::EStateAPeripheral);
   336 				iCaseStep = EAToPeripheral;
   302 				iCaseStep = EAToPeripheral;
   337 			}
   303 			}
   338 			else{
   304 			else{
   339 				iCollector.AddRequiredNotification(EWatcherAConnectionIdle, RUsbOtgDriver::EConnectionIdle);
   305 				iCollector.AddRequiredNotification(EWatcherAConnectionIdle, RUsbOtgDriver::EConnectionIdle);
   345 			}
   311 			}
   346 			
   312 			
   347 		case EAToPeripheral:
   313 		case EAToPeripheral:
   348 			{
   314 			{
   349 			test.Printf(_L("Into EAToPeripheral step...\n"));
   315 			test.Printf(_L("Into EAToPeripheral step...\n"));
   350 			OstTrace0(TRACE_NORMAL, CTESTCASE0684_RUNSTEPL_DUP12, "Into EAToPeripheral step...\n");
       
   351 			if (KTestCaseWatchdogTO == iStatus.Int())
   316 			if (KTestCaseWatchdogTO == iStatus.Int())
   352 				{
   317 				{
   353 				iCollector.DestroyObservers();
   318 				iCollector.DestroyObservers();
   354 				return TestFailed(KErrAbort, _L("Timeout"));
   319 				return TestFailed(KErrAbort, _L("Timeout"));
   355 				}
   320 				}
   360 			}
   325 			}
   361 		
   326 		
   362 		case EBToHost:
   327 		case EBToHost:
   363 			{
   328 			{
   364 			test.Printf(_L("Into EBToHost step...\n"));
   329 			test.Printf(_L("Into EBToHost step...\n"));
   365 			OstTrace0(TRACE_NORMAL, CTESTCASE0684_RUNSTEPL_DUP13, "Into EBToHost step...\n");
       
   366 			if (KTestCaseWatchdogTO == iStatus.Int())
   330 			if (KTestCaseWatchdogTO == iStatus.Int())
   367 				{
   331 				{
   368 				iCollector.DestroyObservers();
   332 				iCollector.DestroyObservers();
   369 				return TestFailed(KErrAbort, _L("Timeout"));
   333 				return TestFailed(KErrAbort, _L("Timeout"));
   370 				}
   334 				}
   375 			}
   339 			}
   376 			
   340 			
   377 		case EBToPeripheral:
   341 		case EBToPeripheral:
   378 			{
   342 			{
   379 			test.Printf(_L("Into EBToPeripheral step...\n"));
   343 			test.Printf(_L("Into EBToPeripheral step...\n"));
   380 			OstTrace0(TRACE_NORMAL, CTESTCASE0684_RUNSTEPL_DUP14, "Into EBToPeripheral step...\n");
       
   381 			if (KTestCaseWatchdogTO == iStatus.Int())
   344 			if (KTestCaseWatchdogTO == iStatus.Int())
   382 				{
   345 				{
   383 				iCollector.DestroyObservers();
   346 				iCollector.DestroyObservers();
   384 				return TestFailed(KErrAbort, _L("Timeout"));
   347 				return TestFailed(KErrAbort, _L("Timeout"));
   385 				}
   348 				}
   398 			}
   361 			}
   399 			
   362 			
   400 		case EIdleHostPriorToVBusDown:
   363 		case EIdleHostPriorToVBusDown:
   401 			{
   364 			{
   402 			test.Printf(_L("Into EAIdleHostPriorToVBusDown step...\n"));
   365 			test.Printf(_L("Into EAIdleHostPriorToVBusDown step...\n"));
   403 			OstTrace0(TRACE_NORMAL, CTESTCASE0684_RUNSTEPL_DUP15, "Into EAIdleHostPriorToVBusDown step...\n");
       
   404 			
   366 			
   405 			if (KTestCaseWatchdogTO == iStatus.Int())
   367 			if (KTestCaseWatchdogTO == iStatus.Int())
   406 				{
   368 				{
   407 				iCollector.DestroyObservers();
   369 				iCollector.DestroyObservers();
   408 				return TestFailed(KErrAbort, _L("Timeout"));
   370 				return TestFailed(KErrAbort, _L("Timeout"));
   471 			RequestCharacter();	
   433 			RequestCharacter();	
   472 			break;
   434 			break;
   473 			
   435 			
   474 		default:
   436 		default:
   475 			test.Printf(_L("<Error> unknown test step"));
   437 			test.Printf(_L("<Error> unknown test step"));
   476 			OstTrace0(TRACE_NORMAL, CTESTCASE0684_RUNSTEPL_DUP16, "<Error> unknown test step");
       
   477 			Cancel();
   438 			Cancel();
   478 			RequestCharacter();	
   439 			RequestCharacter();	
   479 			return (TestFailed(KErrCorrupt, _L("<Error> unknown test step")));
   440 			return (TestFailed(KErrCorrupt, _L("<Error> unknown test step")));
   480 		}
   441 		}
   481 	
   442