kerneltest/e32test/usbho/t_otgdi/src/testcase0681.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".
    22 #include <e32base_private.h>
    22 #include <e32base_private.h>
    23 #include <e32Test.h>	// RTest headder
    23 #include <e32Test.h>	// RTest headder
    24 #include "testcaseroot.h"
    24 #include "testcaseroot.h"
    25 #include "b2bwatchers.h"
    25 #include "b2bwatchers.h"
    26 #include "testcase0681.h"
    26 #include "testcase0681.h"
       
    27 #include "OstTraceDefinitions.h"
       
    28 #ifdef OST_TRACE_COMPILER_IN_USE
       
    29 #include "testcase0681Traces.h"
       
    30 #endif
    27 
    31 
    28 #define _REPEATS (oOpenIterations*3)
    32 #define _REPEATS (oOpenIterations*3)
    29 
    33 
    30 
    34 
    31 /* **************************************************************************************
    35 /* **************************************************************************************
    35 _LIT(KTestCaseId,"PBASE-USB_OTGDI-0681");
    39 _LIT(KTestCaseId,"PBASE-USB_OTGDI-0681");
    36 const TTestCaseFactoryReceipt<CTestCase0681> CTestCase0681::iFactoryReceipt(KTestCaseId);	
    40 const TTestCaseFactoryReceipt<CTestCase0681> CTestCase0681::iFactoryReceipt(KTestCaseId);	
    37 
    41 
    38 CTestCase0681* CTestCase0681::NewL(TBool aHost)
    42 CTestCase0681* CTestCase0681::NewL(TBool aHost)
    39 	{
    43 	{
    40 	LOG_FUNC
    44 	if(gVerboseOutput)
       
    45 	    {
       
    46 	    OstTraceFunctionEntry0(CTESTCASE0681_NEWL);
       
    47 	    }
    41 	CTestCase0681* self = new (ELeave) CTestCase0681(aHost);
    48 	CTestCase0681* self = new (ELeave) CTestCase0681(aHost);
    42 	CleanupStack::PushL(self);
    49 	CleanupStack::PushL(self);
    43 	self->ConstructL();
    50 	self->ConstructL();
    44 	CleanupStack::Pop(self);
    51 	CleanupStack::Pop(self);
    45 	return self;
    52 	return self;
    47 	
    54 	
    48 
    55 
    49 CTestCase0681::CTestCase0681(TBool aHost)
    56 CTestCase0681::CTestCase0681(TBool aHost)
    50 	: CTestCaseB2BRoot(KTestCaseId, aHost, iStatus) 
    57 	: CTestCaseB2BRoot(KTestCaseId, aHost, iStatus) 
    51 	{
    58 	{
    52 	LOG_FUNC
    59 	if(gVerboseOutput)
       
    60 	    {
       
    61 	    OstTraceFunctionEntry0(CTESTCASE0681_CTESTCASE0681);
       
    62 	    }
    53 		
    63 		
    54 	} 
    64 	} 
    55 
    65 
    56 
    66 
    57 /**
    67 /**
    58  ConstructL
    68  ConstructL
    59 */
    69 */
    60 void CTestCase0681::ConstructL()
    70 void CTestCase0681::ConstructL()
    61 	{
    71 	{
    62 	LOG_FUNC
    72 	if(gVerboseOutput)
       
    73 	    {
       
    74 	    OstTraceFunctionEntry0(CTESTCASE0681_CONSTRUCTL);
       
    75 	    }
    63 
    76 
    64 	iDualRoleCase = ETrue;	// another back-back
    77 	iDualRoleCase = ETrue;	// another back-back
    65 		
    78 		
    66 	BaseConstructL();
    79 	BaseConstructL();
    67 	}
    80 	}
    68 
    81 
    69 
    82 
    70 CTestCase0681::~CTestCase0681()
    83 CTestCase0681::~CTestCase0681()
    71 	{
    84 	{
    72 	LOG_FUNC
    85 	if(gVerboseOutput)
       
    86 	    {
       
    87 	    OstTraceFunctionEntry0(CTESTCASE0681_DCTESTCASE0681);
       
    88 	    }
    73 	iCollector.DestroyObservers();
    89 	iCollector.DestroyObservers();
    74 	Cancel();
    90 	Cancel();
    75 	}
    91 	}
    76 
    92 
    77 
    93 
    78 void CTestCase0681::ExecuteTestCaseL()
    94 void CTestCase0681::ExecuteTestCaseL()
    79 	{
    95 	{
    80 	LOG_FUNC
    96 	if(gVerboseOutput)
       
    97 	    {
       
    98 	    OstTraceFunctionEntry0(CTESTCASE0681_EXECUTETESTCASEL);
       
    99 	    }
    81 	iCaseStep = EPreconditions;
   100 	iCaseStep = EPreconditions;
    82 	iHNPCounter = 3;	//	To be decremented to govern the number of times we do HNP.
   101 	iHNPCounter = 3;	//	To be decremented to govern the number of times we do HNP.
    83 	CActiveScheduler::Add(this);
   102 	CActiveScheduler::Add(this);
    84 	SelfComplete();
   103 	SelfComplete();
    85 	}
   104 	}
    86 
   105 
    87 	
   106 	
    88 void CTestCase0681::DoCancel()
   107 void CTestCase0681::DoCancel()
    89 	{
   108 	{
    90 	LOG_FUNC
   109 	if(gVerboseOutput)
       
   110 	    {
       
   111 	    OstTraceFunctionEntry0(CTESTCASE0681_DOCANCEL);
       
   112 	    }
    91 	// cancel our timer
   113 	// cancel our timer
    92 	iTimer.Cancel();
   114 	iTimer.Cancel();
    93 	}
   115 	}
    94 
   116 
    95 void CTestCase0681::StepB2BPreconditions()
   117 void CTestCase0681::StepB2BPreconditions()
    96 	{
   118 	{
    97 	// prompt to insert connector and activate A-end first...
   119 	// prompt to insert connector and activate A-end first...
    98 	if (gTestRoleMaster)
   120 	if (gTestRoleMaster)
    99 		{ // "B" device
   121 		{ // "B" device
   100 		test.Printf(_L("***** Important note *****\n"));
   122 		test.Printf(_L("***** Important note *****\n"));
       
   123 		OstTrace0(TRACE_NORMAL, CTESTCASE0681_STEPB2BPRECONDITIONS, "***** Important note *****\n");
   101 		test.Printf(_L("Before commencing test, please\n"));
   124 		test.Printf(_L("Before commencing test, please\n"));
       
   125 		OstTrace0(TRACE_NORMAL, CTESTCASE0681_STEPB2BPRECONDITIONS_DUP01, "Before commencing test, please\n");
   102 		test.Printf(_L("insert 'B'-cable end and activate\n"));
   126 		test.Printf(_L("insert 'B'-cable end and activate\n"));
       
   127 		OstTrace0(TRACE_NORMAL, CTESTCASE0681_STEPB2BPRECONDITIONS_DUP02, "insert 'B'-cable end and activate\n");
   103 		test.Printf(_L("the test on the 'A' device.\n"));
   128 		test.Printf(_L("the test on the 'A' device.\n"));
       
   129 		OstTrace0(TRACE_NORMAL, CTESTCASE0681_STEPB2BPRECONDITIONS_DUP03, "the test on the 'A' device.\n");
   104 		test.Printf(_L("Then, press any key to continue.\n"));
   130 		test.Printf(_L("Then, press any key to continue.\n"));
       
   131 		OstTrace0(TRACE_NORMAL, CTESTCASE0681_STEPB2BPRECONDITIONS_DUP04, "Then, press any key to continue.\n");
   105 		test.Printf(_L("**************************\n"));
   132 		test.Printf(_L("**************************\n"));
       
   133 		OstTrace0(TRACE_NORMAL, CTESTCASE0681_STEPB2BPRECONDITIONS_DUP05, "**************************\n");
   106 		}
   134 		}
   107 	else
   135 	else
   108 		{
   136 		{
   109 		test.Printf(KInsertACablePrompt);
   137 		test.Printf(KInsertACablePrompt);
       
   138 		OstTrace0(TRACE_NORMAL, CTESTCASE0681_STEPB2BPRECONDITIONS_DUP06, KInsertACablePrompt);
   110 		test.Printf(KPressAnyKeyToContinue);
   139 		test.Printf(KPressAnyKeyToContinue);
       
   140 		OstTrace0(TRACE_NORMAL, CTESTCASE0681_STEPB2BPRECONDITIONS_DUP07, KPressAnyKeyToContinue);
   111 		}
   141 		}
   112 
   142 
   113 	RequestCharacter();	
   143 	RequestCharacter();	
   114 	}
   144 	}
   115 
   145 
   116 // handle event completion	
   146 // handle event completion	
   117 void CTestCase0681::RunStepL()
   147 void CTestCase0681::RunStepL()
   118 	{
   148 	{
   119 	LOG_FUNC
   149 	if(gVerboseOutput)
       
   150 	    {
       
   151 	    OstTraceFunctionEntry0(CTESTCASE0681_RUNSTEPL);
       
   152 	    }
   120 	// Obtain the completion code for this CActive obj.
   153 	// Obtain the completion code for this CActive obj.
   121 	TInt completionCode(iStatus.Int()); 
   154 	TInt completionCode(iStatus.Int()); 
   122 	TBuf<MAX_DSTRLEN> aDescription;
   155 	TBuf<MAX_DSTRLEN> aDescription;
   123 	TInt err(0);
   156 	TInt err(0);
   124 
   157 
   190 			}
   223 			}
   191 			
   224 			
   192 		case EPerformSrp:
   225 		case EPerformSrp:
   193 			{
   226 			{
   194 			test.Printf(_L("Into EPerformSrp step...\n"));
   227 			test.Printf(_L("Into EPerformSrp step...\n"));
       
   228 			OstTrace0(TRACE_NORMAL, CTESTCASE0681_RUNSTEPL_DUP01, "Into EPerformSrp step...\n");
   195 
   229 
   196 			if (gTestRoleMaster)
   230 			if (gTestRoleMaster)
   197 				{
   231 				{
   198 				// Trigger SRP
   232 				// Trigger SRP
   199 				iCollector.AddRequiredNotification(EWatcherState, RUsbOtgDriver::EStateBIdle);
   233 				iCollector.AddRequiredNotification(EWatcherState, RUsbOtgDriver::EStateBIdle);
   229 			}
   263 			}
   230 
   264 
   231 		case EAReceivedSrp:		//	A-Device step only!
   265 		case EAReceivedSrp:		//	A-Device step only!
   232 			{
   266 			{
   233 			test.Printf(_L("Into EAReceivedSrp step...\n"));
   267 			test.Printf(_L("Into EAReceivedSrp step...\n"));
       
   268 			OstTrace0(TRACE_NORMAL, CTESTCASE0681_RUNSTEPL_DUP02, "Into EAReceivedSrp step...\n");
   234 
   269 
   235 			if (KTestCaseWatchdogTO == iStatus.Int())
   270 			if (KTestCaseWatchdogTO == iStatus.Int())
   236 				{
   271 				{
   237 				iCollector.DestroyObservers();
   272 				iCollector.DestroyObservers();
   238 				return TestFailed(KErrAbort, _L("Timeout"));
   273 				return TestFailed(KErrAbort, _L("Timeout"));
   255 			}
   290 			}
   256 
   291 
   257 		case ESwappedRoles:
   292 		case ESwappedRoles:
   258 			{
   293 			{
   259 			test.Printf(_L("Into ESwappedRoles step...\n"));
   294 			test.Printf(_L("Into ESwappedRoles step...\n"));
       
   295 			OstTrace0(TRACE_NORMAL, CTESTCASE0681_RUNSTEPL_DUP03, "Into ESwappedRoles step...\n");
   260 			if (KTestCaseWatchdogTO == iStatus.Int())
   296 			if (KTestCaseWatchdogTO == iStatus.Int())
   261 				{
   297 				{
   262 				iCollector.DestroyObservers();
   298 				iCollector.DestroyObservers();
   263 				return TestFailed(KErrAbort, _L("Timeout"));
   299 				return TestFailed(KErrAbort, _L("Timeout"));
   264 				}			
   300 				}			
   280 			}
   316 			}
   281 			
   317 			
   282 		case EAConfigured:	//	A-Device only step
   318 		case EAConfigured:	//	A-Device only step
   283 			{
   319 			{
   284 			test.Printf(_L("Into EAConfigured step...\n"));
   320 			test.Printf(_L("Into EAConfigured step...\n"));
       
   321 			OstTrace0(TRACE_NORMAL, CTESTCASE0681_RUNSTEPL_DUP04, "Into EAConfigured step...\n");
   285 			if (KTestCaseWatchdogTO == iStatus.Int())
   322 			if (KTestCaseWatchdogTO == iStatus.Int())
   286 				{
   323 				{
   287 				iCollector.DestroyObservers();
   324 				iCollector.DestroyObservers();
   288 				return TestFailed(KErrAbort, _L("Timeout"));
   325 				return TestFailed(KErrAbort, _L("Timeout"));
   289 				}			
   326 				}			
   295 			}
   332 			}
   296 		
   333 		
   297 		case EASuspended:	//	A-Device only step
   334 		case EASuspended:	//	A-Device only step
   298 			{
   335 			{
   299 			test.Printf(_L("Into EASuspended step...\n"));
   336 			test.Printf(_L("Into EASuspended step...\n"));
       
   337 			OstTrace0(TRACE_NORMAL, CTESTCASE0681_RUNSTEPL_DUP05, "Into EASuspended step...\n");
   300 			if (KTestCaseWatchdogTO == iStatus.Int())
   338 			if (KTestCaseWatchdogTO == iStatus.Int())
   301 				{
   339 				{
   302 				iCollector.DestroyObservers();
   340 				iCollector.DestroyObservers();
   303 				return TestFailed(KErrAbort, _L("Timeout"));
   341 				return TestFailed(KErrAbort, _L("Timeout"));
   304 				}			
   342 				}			
   311 			}
   349 			}
   312 			
   350 			
   313 		case EDefaultRoles:
   351 		case EDefaultRoles:
   314 			{
   352 			{
   315 			test.Printf(_L("Into EDefaultRoles step...\n"));
   353 			test.Printf(_L("Into EDefaultRoles step...\n"));
       
   354 			OstTrace0(TRACE_NORMAL, CTESTCASE0681_RUNSTEPL_DUP06, "Into EDefaultRoles step...\n");
   316 			
   355 			
   317 			if ( --iHNPCounter >= 0)
   356 			if ( --iHNPCounter >= 0)
   318 				{
   357 				{
   319 				//	We want to do further role swapping
   358 				//	We want to do further role swapping
   320 				if (gTestRoleMaster)
   359 				if (gTestRoleMaster)
   343 
   382 
   344 			
   383 			
   345 		case EBConfigured:	//	A B-Device only step!
   384 		case EBConfigured:	//	A B-Device only step!
   346 			{
   385 			{
   347 			test.Printf(_L("Into EBConfigured step...\n"));
   386 			test.Printf(_L("Into EBConfigured step...\n"));
       
   387 			OstTrace0(TRACE_NORMAL, CTESTCASE0681_RUNSTEPL_DUP07, "Into EBConfigured step...\n");
   348 			if (KTestCaseWatchdogTO == iStatus.Int())
   388 			if (KTestCaseWatchdogTO == iStatus.Int())
   349 				{
   389 				{
   350 				iCollector.DestroyObservers();
   390 				iCollector.DestroyObservers();
   351 				return TestFailed(KErrAbort, _L("Timeout"));
   391 				return TestFailed(KErrAbort, _L("Timeout"));
   352 				}
   392 				}
   357 			}
   397 			}
   358 			
   398 			
   359 		case EBSuspended:	
   399 		case EBSuspended:	
   360 			{
   400 			{
   361 			test.Printf(_L("Into EBSuspended step...\n"));
   401 			test.Printf(_L("Into EBSuspended step...\n"));
       
   402 			OstTrace0(TRACE_NORMAL, CTESTCASE0681_RUNSTEPL_DUP08, "Into EBSuspended step...\n");
   362 			if (KTestCaseWatchdogTO == iStatus.Int())
   403 			if (KTestCaseWatchdogTO == iStatus.Int())
   363 				{
   404 				{
   364 				iCollector.DestroyObservers();
   405 				iCollector.DestroyObservers();
   365 				return TestFailed(KErrAbort, _L("Timeout"));
   406 				return TestFailed(KErrAbort, _L("Timeout"));
   366 				}			
   407 				}			
   367 			
   408 			
   368 			// issue HNP
   409 			// issue HNP
   369 			test.Printf(_L("VBus present, attempting a swap.\n"));
   410 			test.Printf(_L("VBus present, attempting a swap.\n"));
       
   411 			OstTrace0(TRACE_NORMAL, CTESTCASE0681_RUNSTEPL_DUP09, "VBus present, attempting a swap.\n");
   370 			iCollector.AddRequiredNotification(EWatcherState, RUsbOtgDriver::EStateBHost);
   412 			iCollector.AddRequiredNotification(EWatcherState, RUsbOtgDriver::EStateBHost);
   371 
   413 
   372 			err = otgBusRequest();	//	Request the host role
   414 			err = otgBusRequest();	//	Request the host role
   373 
   415 
   374 			if (KErrNone != err)
   416 			if (KErrNone != err)
   375 				{
   417 				{
   376 				test.Printf(_L("BusRequest returned %d\n"),err);
   418 				test.Printf(_L("BusRequest returned %d\n"),err);
       
   419 				OstTrace1(TRACE_NORMAL, CTESTCASE0681_RUNSTEPL_DUP10, "BusRequest returned %d\n",err);
   377 				return TestFailed(KErrAbort, _L("BusRequest() failed!"));
   420 				return TestFailed(KErrAbort, _L("BusRequest() failed!"));
   378 				}
   421 				}
   379 		
   422 		
   380 			iCaseStep = ESwappedRoles;
   423 			iCaseStep = ESwappedRoles;
   381 			SetActive();
   424 			SetActive();
   436 			TestPassed();
   479 			TestPassed();
   437 			break;
   480 			break;
   438 			
   481 			
   439 		default:
   482 		default:
   440 			test.Printf(_L("<Error> unknown test step"));
   483 			test.Printf(_L("<Error> unknown test step"));
       
   484 			OstTrace0(TRACE_NORMAL, CTESTCASE0681_RUNSTEPL_DUP11, "<Error> unknown test step");
   441 			Cancel();
   485 			Cancel();
   442 			return (TestFailed(KErrCorrupt, _L("<Error> unknown test step")));
   486 			return (TestFailed(KErrCorrupt, _L("<Error> unknown test step")));
   443 		}
   487 		}
   444 	}
   488 	}