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