kerneltest/e32test/usbho/t_otgdi/src/testcase0683.cpp
changeset 259 57b9594f5772
parent 0 a41df078684a
child 257 3e88ff8f41d5
equal deleted inserted replaced
247:d8d70de2bd36 259:57b9594f5772
     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 "testcase0683.h"
    27 #include "testcase0683.h"
       
    28 #include "OstTraceDefinitions.h"
       
    29 #ifdef OST_TRACE_COMPILER_IN_USE
       
    30 #include "testcase0683Traces.h"
       
    31 #endif
    28 
    32 
    29 #define _REPEATS (oOpenIterations*3)
    33 #define _REPEATS (oOpenIterations*3)
    30 
    34 
    31 
    35 
    32 /* **************************************************************************************
    36 /* **************************************************************************************
    36 _LIT(KTestCaseId,"PBASE-USB_OTGDI-0683");
    40 _LIT(KTestCaseId,"PBASE-USB_OTGDI-0683");
    37 const TTestCaseFactoryReceipt<CTestCase0683> CTestCase0683::iFactoryReceipt(KTestCaseId);	
    41 const TTestCaseFactoryReceipt<CTestCase0683> CTestCase0683::iFactoryReceipt(KTestCaseId);	
    38 
    42 
    39 CTestCase0683* CTestCase0683::NewL(TBool aHost)
    43 CTestCase0683* CTestCase0683::NewL(TBool aHost)
    40 	{
    44 	{
    41 	LOG_FUNC
    45 	if(gVerboseOutput)
       
    46 	    {
       
    47 	    OstTraceFunctionEntry0(CTESTCASE0683_NEWL);
       
    48 	    }
    42 	CTestCase0683* self = new (ELeave) CTestCase0683(aHost);
    49 	CTestCase0683* self = new (ELeave) CTestCase0683(aHost);
    43 	CleanupStack::PushL(self);
    50 	CleanupStack::PushL(self);
    44 	self->ConstructL();
    51 	self->ConstructL();
    45 	CleanupStack::Pop(self);
    52 	CleanupStack::Pop(self);
    46 	return self;
    53 	return self;
    48 	
    55 	
    49 
    56 
    50 CTestCase0683::CTestCase0683(TBool aHost)
    57 CTestCase0683::CTestCase0683(TBool aHost)
    51 	: CTestCaseB2BRoot(KTestCaseId, aHost, iStatus) 
    58 	: CTestCaseB2BRoot(KTestCaseId, aHost, iStatus) 
    52 	{
    59 	{
    53 	LOG_FUNC
    60 	if(gVerboseOutput)
       
    61 	    {
       
    62 	    OstTraceFunctionEntry0(CTESTCASE0683_CTESTCASE0683);
       
    63 	    }
    54 		
    64 		
    55 	} 
    65 	} 
    56 
    66 
    57 
    67 
    58 /**
    68 /**
    59  ConstructL
    69  ConstructL
    60 */
    70 */
    61 void CTestCase0683::ConstructL()
    71 void CTestCase0683::ConstructL()
    62 	{
    72 	{
    63 	LOG_FUNC
    73 	if(gVerboseOutput)
       
    74 	    {
       
    75 	    OstTraceFunctionEntry0(CTESTCASE0683_CONSTRUCTL);
       
    76 	    }
    64 
    77 
    65 	iDualRoleCase = ETrue;	// another back-back
    78 	iDualRoleCase = ETrue;	// another back-back
    66 		
    79 		
    67 	BaseConstructL();
    80 	BaseConstructL();
    68 	}
    81 	}
    69 
    82 
    70 
    83 
    71 CTestCase0683::~CTestCase0683()
    84 CTestCase0683::~CTestCase0683()
    72 	{
    85 	{
    73 	LOG_FUNC
    86 	if(gVerboseOutput)
       
    87 	    {
       
    88 	    OstTraceFunctionEntry0(CTESTCASE0683_DCTESTCASE0683);
       
    89 	    }
    74 	iCollector.DestroyObservers();
    90 	iCollector.DestroyObservers();
    75 	Cancel();
    91 	Cancel();
    76 	}
    92 	}
    77 
    93 
    78 
    94 
    79 void CTestCase0683::ExecuteTestCaseL()
    95 void CTestCase0683::ExecuteTestCaseL()
    80 	{
    96 	{
    81 	LOG_FUNC
    97 	if(gVerboseOutput)
       
    98 	    {
       
    99 	    OstTraceFunctionEntry0(CTESTCASE0683_EXECUTETESTCASEL);
       
   100 	    }
    82 	iCaseStep = EPreconditions;
   101 	iCaseStep = EPreconditions;
    83 	iHNPCounter = 3;	//	To be decremented to govern the number of times we do HNP.
   102 	iHNPCounter = 3;	//	To be decremented to govern the number of times we do HNP.
    84 	CActiveScheduler::Add(this);
   103 	CActiveScheduler::Add(this);
    85 	SelfComplete();
   104 	SelfComplete();
    86 	}
   105 	}
    87 
   106 
    88 	
   107 	
    89 void CTestCase0683::DoCancel()
   108 void CTestCase0683::DoCancel()
    90 	{
   109 	{
    91 	LOG_FUNC
   110 	if(gVerboseOutput)
       
   111 	    {
       
   112 	    OstTraceFunctionEntry0(CTESTCASE0683_DOCANCEL);
       
   113 	    }
    92 	// cancel our timer
   114 	// cancel our timer
    93 	iTimer.Cancel();
   115 	iTimer.Cancel();
    94 	}
   116 	}
    95 
   117 
    96 
   118 
    97 // handle event completion	
   119 // handle event completion	
    98 void CTestCase0683::RunStepL()
   120 void CTestCase0683::RunStepL()
    99 	{
   121 	{
   100 	LOG_FUNC
   122 	if(gVerboseOutput)
       
   123 	    {
       
   124 	    OstTraceFunctionEntry0(CTESTCASE0683_RUNSTEPL);
       
   125 	    }
   101 	// Obtain the completion code for this CActive obj.
   126 	// Obtain the completion code for this CActive obj.
   102 	TInt completionCode(iStatus.Int()); 
   127 	TInt completionCode(iStatus.Int()); 
   103 	TBuf<MAX_DSTRLEN> aDescription;
   128 	TBuf<MAX_DSTRLEN> aDescription;
   104 	TInt err(0);
   129 	TInt err(0);
   105 
   130 
   179 			}
   204 			}
   180 			
   205 			
   181 		case EDefaultRoles:
   206 		case EDefaultRoles:
   182 			{
   207 			{
   183 			test.Printf(_L("Into EDefaultRoles step...\n"));
   208 			test.Printf(_L("Into EDefaultRoles step...\n"));
       
   209 			OstTrace0(TRACE_NORMAL, CTESTCASE0683_RUNSTEPL_DUP01, "Into EDefaultRoles step...\n");
   184 
   210 
   185 			if (KTestCaseWatchdogTO == iStatus.Int())
   211 			if (KTestCaseWatchdogTO == iStatus.Int())
   186 				{
   212 				{
   187 				iCollector.DestroyObservers();
   213 				iCollector.DestroyObservers();
   188 				return TestFailed(KErrAbort, _L("Timeout"));
   214 				return TestFailed(KErrAbort, _L("Timeout"));
   227 			}
   253 			}
   228 
   254 
   229 		case EBConfigured:	//	A B-Device only step!
   255 		case EBConfigured:	//	A B-Device only step!
   230 			{
   256 			{
   231 			test.Printf(_L("Into EBConfigured step...\n"));
   257 			test.Printf(_L("Into EBConfigured step...\n"));
       
   258 			OstTrace0(TRACE_NORMAL, CTESTCASE0683_RUNSTEPL_DUP02, "Into EBConfigured step...\n");
   232 			if (KTestCaseWatchdogTO == iStatus.Int())
   259 			if (KTestCaseWatchdogTO == iStatus.Int())
   233 				{
   260 				{
   234 				iCollector.DestroyObservers();
   261 				iCollector.DestroyObservers();
   235 				return TestFailed(KErrAbort, _L("Timeout"));
   262 				return TestFailed(KErrAbort, _L("Timeout"));
   236 				}
   263 				}
   241 			}
   268 			}
   242 			
   269 			
   243 		case EBSuspended:	
   270 		case EBSuspended:	
   244 			{
   271 			{
   245 			test.Printf(_L("Into EBSuspended step...\n"));
   272 			test.Printf(_L("Into EBSuspended step...\n"));
       
   273 			OstTrace0(TRACE_NORMAL, CTESTCASE0683_RUNSTEPL_DUP03, "Into EBSuspended step...\n");
   246 			if (KTestCaseWatchdogTO == iStatus.Int())
   274 			if (KTestCaseWatchdogTO == iStatus.Int())
   247 				{
   275 				{
   248 				iCollector.DestroyObservers();
   276 				iCollector.DestroyObservers();
   249 				return TestFailed(KErrAbort, _L("Timeout"));
   277 				return TestFailed(KErrAbort, _L("Timeout"));
   250 				}			
   278 				}			
   251 			
   279 			
   252 			if (iHNPCounter > 0)
   280 			if (iHNPCounter > 0)
   253 				{			
   281 				{			
   254 				// issue bus request to trigger HNP
   282 				// issue bus request to trigger HNP
   255 				test.Printf(_L("VBus present, attempting a swap.\n"));
   283 				test.Printf(_L("VBus present, attempting a swap.\n"));
       
   284 				OstTrace0(TRACE_NORMAL, CTESTCASE0683_RUNSTEPL_DUP04, "VBus present, attempting a swap.\n");
   256 				iCollector.AddRequiredNotification(EWatcherState, RUsbOtgDriver::EStateBHost);
   285 				iCollector.AddRequiredNotification(EWatcherState, RUsbOtgDriver::EStateBHost);
   257 
   286 
   258 				err = otgBusRequest();	//	Request the host role
   287 				err = otgBusRequest();	//	Request the host role
   259 				if (KErrNone != err)
   288 				if (KErrNone != err)
   260 					{
   289 					{
   261 					test.Printf(_L("BusRequest returned %d\n"),err);
   290 					test.Printf(_L("BusRequest returned %d\n"),err);
       
   291 					OstTrace1(TRACE_NORMAL, CTESTCASE0683_RUNSTEPL_DUP05, "BusRequest returned %d\n",err);
   262 					return TestFailed(KErrAbort, _L("BusRequest() failed!"));
   292 					return TestFailed(KErrAbort, _L("BusRequest() failed!"));
   263 					}
   293 					}
   264 			
   294 			
   265 				iCaseStep = ESwappedRoles;
   295 				iCaseStep = ESwappedRoles;
   266 				SetActive();
   296 				SetActive();
   277 			}
   307 			}
   278 
   308 
   279 		case EAIdleHostPriorToAPeripheral:	//	an "A-Device only" step
   309 		case EAIdleHostPriorToAPeripheral:	//	an "A-Device only" step
   280 			{
   310 			{
   281 			test.Printf(_L("Into EAIdleHostPriorToAPeripheral step...\n"));
   311 			test.Printf(_L("Into EAIdleHostPriorToAPeripheral step...\n"));
       
   312 			OstTrace0(TRACE_NORMAL, CTESTCASE0683_RUNSTEPL_DUP06, "Into EAIdleHostPriorToAPeripheral step...\n");
   282 			if (KTestCaseWatchdogTO == iStatus.Int())
   313 			if (KTestCaseWatchdogTO == iStatus.Int())
   283 				{
   314 				{
   284 				iCollector.DestroyObservers();
   315 				iCollector.DestroyObservers();
   285 				return TestFailed(KErrAbort, _L("Timeout"));
   316 				return TestFailed(KErrAbort, _L("Timeout"));
   286 				}			
   317 				}			
   294 			}
   325 			}
   295 			
   326 			
   296 		case ESwappedRoles:
   327 		case ESwappedRoles:
   297 			{
   328 			{
   298 			test.Printf(_L("Into ESwappedRoles step...\n"));
   329 			test.Printf(_L("Into ESwappedRoles step...\n"));
       
   330 			OstTrace0(TRACE_NORMAL, CTESTCASE0683_RUNSTEPL_DUP07, "Into ESwappedRoles step...\n");
   299 			if (KTestCaseWatchdogTO == iStatus.Int())
   331 			if (KTestCaseWatchdogTO == iStatus.Int())
   300 				{
   332 				{
   301 				iCollector.DestroyObservers();
   333 				iCollector.DestroyObservers();
   302 				return TestFailed(KErrAbort, _L("Timeout"));
   334 				return TestFailed(KErrAbort, _L("Timeout"));
   303 				}			
   335 				}			
   319 			}
   351 			}
   320 			
   352 			
   321 		case EAConfigured:	//	A-Device only step
   353 		case EAConfigured:	//	A-Device only step
   322 			{
   354 			{
   323 			test.Printf(_L("Into EAConfigured step...\n"));
   355 			test.Printf(_L("Into EAConfigured step...\n"));
       
   356 			OstTrace0(TRACE_NORMAL, CTESTCASE0683_RUNSTEPL_DUP08, "Into EAConfigured step...\n");
   324 			if (KTestCaseWatchdogTO == iStatus.Int())
   357 			if (KTestCaseWatchdogTO == iStatus.Int())
   325 				{
   358 				{
   326 				iCollector.DestroyObservers();
   359 				iCollector.DestroyObservers();
   327 				return TestFailed(KErrAbort, _L("Timeout"));
   360 				return TestFailed(KErrAbort, _L("Timeout"));
   328 				}			
   361 				}			
   335 			}
   368 			}
   336 		
   369 		
   337 		case EASuspended:	//	A-Device only step
   370 		case EASuspended:	//	A-Device only step
   338 			{
   371 			{
   339 			test.Printf(_L("Into EASuspended step...\n"));
   372 			test.Printf(_L("Into EASuspended step...\n"));
       
   373 			OstTrace0(TRACE_NORMAL, CTESTCASE0683_RUNSTEPL_DUP09, "Into EASuspended step...\n");
   340 			if (KTestCaseWatchdogTO == iStatus.Int())
   374 			if (KTestCaseWatchdogTO == iStatus.Int())
   341 				{
   375 				{
   342 				iCollector.DestroyObservers();
   376 				iCollector.DestroyObservers();
   343 				return TestFailed(KErrAbort, _L("Timeout"));
   377 				return TestFailed(KErrAbort, _L("Timeout"));
   344 				}			
   378 				}			
   352 			}
   386 			}
   353 
   387 
   354 		case EAIdleHostPriorToVBusDown:
   388 		case EAIdleHostPriorToVBusDown:
   355 			{
   389 			{
   356 			test.Printf(_L("Into EAIdleHostPriorToVBusDown step...\n"));
   390 			test.Printf(_L("Into EAIdleHostPriorToVBusDown step...\n"));
       
   391 			OstTrace0(TRACE_NORMAL, CTESTCASE0683_RUNSTEPL_DUP10, "Into EAIdleHostPriorToVBusDown step...\n");
   357 			if (KTestCaseWatchdogTO == iStatus.Int())
   392 			if (KTestCaseWatchdogTO == iStatus.Int())
   358 				{
   393 				{
   359 				iCollector.DestroyObservers();
   394 				iCollector.DestroyObservers();
   360 				return TestFailed(KErrAbort, _L("Timeout"));
   395 				return TestFailed(KErrAbort, _L("Timeout"));
   361 				}			
   396 				}			
   420 			TestPassed();
   455 			TestPassed();
   421 			break;
   456 			break;
   422 			
   457 			
   423 		default:
   458 		default:
   424 			test.Printf(_L("<Error> unknown test step"));
   459 			test.Printf(_L("<Error> unknown test step"));
       
   460 			OstTrace0(TRACE_NORMAL, CTESTCASE0683_RUNSTEPL_DUP11, "<Error> unknown test step");
   425 			Cancel();
   461 			Cancel();
   426 			return (TestFailed(KErrCorrupt, _L("<Error> unknown test step")));
   462 			return (TestFailed(KErrCorrupt, _L("<Error> unknown test step")));
   427 		}
   463 		}
   428 	}
   464 	}
   429 
   465