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