kerneltest/e32test/usbho/t_otgdi/src/testcase0680.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".
    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 "testcase0680.h"
    26 #include "testcase0680.h"
       
    27 #include "OstTraceDefinitions.h"
       
    28 #ifdef OST_TRACE_COMPILER_IN_USE
       
    29 #include "testcase0680Traces.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-0680");
    39 _LIT(KTestCaseId,"PBASE-USB_OTGDI-0680");
    36 const TTestCaseFactoryReceipt<CTestCase0680> CTestCase0680::iFactoryReceipt(KTestCaseId);	
    40 const TTestCaseFactoryReceipt<CTestCase0680> CTestCase0680::iFactoryReceipt(KTestCaseId);	
    37 
    41 
    38 CTestCase0680* CTestCase0680::NewL(TBool aHost)
    42 CTestCase0680* CTestCase0680::NewL(TBool aHost)
    39 	{
    43 	{
    40 	LOG_FUNC
    44 	if(gVerboseOutput)
       
    45 	    {
       
    46 	    OstTraceFunctionEntry0(CTESTCASE0680_NEWL);
       
    47 	    }
    41 	CTestCase0680* self = new (ELeave) CTestCase0680(aHost);
    48 	CTestCase0680* self = new (ELeave) CTestCase0680(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 CTestCase0680::CTestCase0680(TBool aHost)
    56 CTestCase0680::CTestCase0680(TBool aHost)
    50 	: CTestCaseB2BRoot(KTestCaseId, aHost, iStatus) 
    57 	: CTestCaseB2BRoot(KTestCaseId, aHost, iStatus) 
    51 	{
    58 	{
    52 	LOG_FUNC
    59 	if(gVerboseOutput)
       
    60 	    {
       
    61 	    OstTraceFunctionEntry0(CTESTCASE0680_CTESTCASE0680);
       
    62 	    }
    53 		
    63 		
    54 	} 
    64 	} 
    55 
    65 
    56 
    66 
    57 /**
    67 /**
    58  ConstructL
    68  ConstructL
    59 */
    69 */
    60 void CTestCase0680::ConstructL()
    70 void CTestCase0680::ConstructL()
    61 	{
    71 	{
    62 	LOG_FUNC
    72 	if(gVerboseOutput)
       
    73 	    {
       
    74 	    OstTraceFunctionEntry0(CTESTCASE0680_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 CTestCase0680::~CTestCase0680()
    83 CTestCase0680::~CTestCase0680()
    71 	{
    84 	{
    72 	LOG_FUNC
    85 	if(gVerboseOutput)
       
    86 	    {
       
    87 	    OstTraceFunctionEntry0(CTESTCASE0680_DCTESTCASE0680);
       
    88 	    }
    73 	iCollector.DestroyObservers();
    89 	iCollector.DestroyObservers();
    74 	Cancel();
    90 	Cancel();
    75 	}
    91 	}
    76 
    92 
    77 
    93 
    78 void CTestCase0680::ExecuteTestCaseL()
    94 void CTestCase0680::ExecuteTestCaseL()
    79 	{
    95 	{
    80 	LOG_FUNC
    96 	if(gVerboseOutput)
       
    97 	    {
       
    98 	    OstTraceFunctionEntry0(CTESTCASE0680_EXECUTETESTCASEL);
       
    99 	    }
    81 	iCaseStep = EPreconditions;
   100 	iCaseStep = EPreconditions;
    82 	CActiveScheduler::Add(this);
   101 	CActiveScheduler::Add(this);
    83 	SelfComplete();
   102 	SelfComplete();
    84 	}
   103 	}
    85 
   104 
    86 	
   105 	
    87 void CTestCase0680::DoCancel()
   106 void CTestCase0680::DoCancel()
    88 	{
   107 	{
    89 	LOG_FUNC
   108 	if(gVerboseOutput)
       
   109 	    {
       
   110 	    OstTraceFunctionEntry0(CTESTCASE0680_DOCANCEL);
       
   111 	    }
    90 	// cancel our timer
   112 	// cancel our timer
    91 	iTimer.Cancel();
   113 	iTimer.Cancel();
    92 	}
   114 	}
    93 
   115 
    94 
   116 
    95 // handle event completion	
   117 // handle event completion	
    96 void CTestCase0680::RunStepL()
   118 void CTestCase0680::RunStepL()
    97 	{
   119 	{
    98 	LOG_FUNC
   120 	if(gVerboseOutput)
       
   121 	    {
       
   122 	    OstTraceFunctionEntry0(CTESTCASE0680_RUNSTEPL);
       
   123 	    }
    99 	// Obtain the completion code for this CActive obj.
   124 	// Obtain the completion code for this CActive obj.
   100 	TInt completionCode(iStatus.Int()); 
   125 	TInt completionCode(iStatus.Int()); 
   101 	TBuf<MAX_DSTRLEN> aDescription;
   126 	TBuf<MAX_DSTRLEN> aDescription;
   102 	TInt err(0);
   127 	TInt err(0);
   103 
   128 
   142 			}
   167 			}
   143 			
   168 			
   144 		case EReadyToRaiseVBus:
   169 		case EReadyToRaiseVBus:
   145 			{
   170 			{
   146 			test.Printf(_L("Into EReadyToRaiseVBus step...\n"));
   171 			test.Printf(_L("Into EReadyToRaiseVBus step...\n"));
       
   172 			OstTrace0(TRACE_NORMAL, CTESTCASE0680_RUNSTEPL_DUP01, "Into EReadyToRaiseVBus step...\n");
   147 			if (gTestRoleMaster)
   173 			if (gTestRoleMaster)
   148 				{
   174 				{
   149 				// wait for Vbus to be raised
   175 				// wait for Vbus to be raised
   150 				iCollector.AddRequiredNotification(EWatcherState, RUsbOtgDriver::EStateBIdle);
   176 				iCollector.AddRequiredNotification(EWatcherState, RUsbOtgDriver::EStateBIdle);
   151 				iCollector.AddRequiredNotification(EWatcherEvent, RUsbOtgDriver::EEventVbusRaised);
   177 				iCollector.AddRequiredNotification(EWatcherEvent, RUsbOtgDriver::EEventVbusRaised);
   175 			}
   201 			}
   176 			
   202 			
   177 		case EDefaultRoles:
   203 		case EDefaultRoles:
   178 			{
   204 			{
   179 			test.Printf(_L("Into EDefaultRoles step...\n"));
   205 			test.Printf(_L("Into EDefaultRoles step...\n"));
       
   206 			OstTrace0(TRACE_NORMAL, CTESTCASE0680_RUNSTEPL_DUP02, "Into EDefaultRoles step...\n");
   180 			LOG_STEPNAME(_L("EWaitEnumeration"));
   207 			LOG_STEPNAME(_L("EWaitEnumeration"));
   181 			
   208 			
   182 			if (gTestRoleMaster)
   209 			if (gTestRoleMaster)
   183 				{
   210 				{
   184 				//	B-Device should now wait until it is configured
   211 				//	B-Device should now wait until it is configured
   198 				//	to observe the B-Device test code for the pass/fail
   225 				//	to observe the B-Device test code for the pass/fail
   199 				const TInt KTestCase0680ATimeout = 4000;			//	4 seconds before A-Device drops VBus (before B test times out at 5 seconds)
   226 				const TInt KTestCase0680ATimeout = 4000;			//	4 seconds before A-Device drops VBus (before B test times out at 5 seconds)
   200 				iCollector.AddStepTimeout(KTestCase0680ATimeout);	//	NB. In this test on the A-Device, we expect to timeout
   227 				iCollector.AddStepTimeout(KTestCase0680ATimeout);	//	NB. In this test on the A-Device, we expect to timeout
   201 																	//	so a timeout isn't treated as a failure
   228 																	//	so a timeout isn't treated as a failure
   202 				test.Printf(_L("NOTE : Please observe test result on B-Device...\n"));
   229 				test.Printf(_L("NOTE : Please observe test result on B-Device...\n"));
       
   230 				OstTrace0(TRACE_NORMAL, CTESTCASE0680_RUNSTEPL_DUP03, "NOTE : Please observe test result on B-Device...\n");
   203 				iCaseStep = EDropVBus;	//	This is the step the A-Device will go to
   231 				iCaseStep = EDropVBus;	//	This is the step the A-Device will go to
   204 										//	when the timer (set up in previous test) fires
   232 										//	when the timer (set up in previous test) fires
   205 				}
   233 				}
   206 			SetActive();
   234 			SetActive();
   207 			break;
   235 			break;
   209 
   237 
   210 			
   238 			
   211 		case EBConfigured:	//	A B-Device only step!
   239 		case EBConfigured:	//	A B-Device only step!
   212 			{
   240 			{
   213 			test.Printf(_L("Into EBConfigured step...\n"));
   241 			test.Printf(_L("Into EBConfigured step...\n"));
       
   242 			OstTrace0(TRACE_NORMAL, CTESTCASE0680_RUNSTEPL_DUP04, "Into EBConfigured step...\n");
   214 			if (KTestCaseWatchdogTO == iStatus.Int())
   243 			if (KTestCaseWatchdogTO == iStatus.Int())
   215 				{
   244 				{
   216 				iCollector.DestroyObservers();
   245 				iCollector.DestroyObservers();
   217 				return TestFailed(KErrAbort, _L("Timeout"));
   246 				return TestFailed(KErrAbort, _L("Timeout"));
   218 				}
   247 				}
   219 
   248 
   220 			iCollector.AddRequiredNotification(EWatcherMessage, RUsbOtgDriver::EMessageHnpNotSuspended);
   249 			iCollector.AddRequiredNotification(EWatcherMessage, RUsbOtgDriver::EMessageHnpNotSuspended);
   221 
   250 
   222 			test.Printf(_L("Attempting a swap on an unsuspended link...\n"));
   251 			test.Printf(_L("Attempting a swap on an unsuspended link...\n"));
       
   252 			OstTrace0(TRACE_NORMAL, CTESTCASE0680_RUNSTEPL_DUP05, "Attempting a swap on an unsuspended link...\n");
   223 			err = otgBusRequest();	//	Request the host role
   253 			err = otgBusRequest();	//	Request the host role
   224 
   254 
   225 			if (KErrNone != err)
   255 			if (KErrNone != err)
   226 				{
   256 				{
   227 				test.Printf(_L("BusRequest returned %d)"),err);
   257 				test.Printf(_L("BusRequest returned %d)"),err);
       
   258 				OstTrace1(TRACE_NORMAL, CTESTCASE0680_RUNSTEPL_DUP06, "BusRequest returned %d)",err);
   228 				return TestFailed(KErrAbort, _L("BusRequest() failed!"));
   259 				return TestFailed(KErrAbort, _L("BusRequest() failed!"));
   229 				}			
   260 				}			
   230 
   261 
   231 			iCaseStep = EBErrorReceived;
   262 			iCaseStep = EBErrorReceived;
   232 			SetActive();
   263 			SetActive();
   240 				iCollector.DestroyObservers();
   271 				iCollector.DestroyObservers();
   241 				return TestFailed(KErrAbort, _L("Timeout"));
   272 				return TestFailed(KErrAbort, _L("Timeout"));
   242 				}
   273 				}
   243 
   274 
   244 			test.Printf(_L("Into EBErrorReceived step...\n"));
   275 			test.Printf(_L("Into EBErrorReceived step...\n"));
       
   276 			OstTrace0(TRACE_NORMAL, CTESTCASE0680_RUNSTEPL_DUP07, "Into EBErrorReceived step...\n");
   245 			iCaseStep = EDropVBus;	//	Test has pretty much passed now. Just wait for A-Device to drop VBus.
   277 			iCaseStep = EDropVBus;	//	Test has pretty much passed now. Just wait for A-Device to drop VBus.
   246 			SelfComplete();
   278 			SelfComplete();
   247 			break;
   279 			break;
   248 			}
   280 			}
   249 
   281 
   300 			TestPassed();
   332 			TestPassed();
   301 			break;
   333 			break;
   302 			
   334 			
   303 		default:
   335 		default:
   304 			test.Printf(_L("<Error> unknown test step"));
   336 			test.Printf(_L("<Error> unknown test step"));
       
   337 			OstTrace0(TRACE_NORMAL, CTESTCASE0680_RUNSTEPL_DUP08, "<Error> unknown test step");
   305 			Cancel();
   338 			Cancel();
   306 			return (TestFailed(KErrCorrupt, _L("<Error> unknown test step")));
   339 			return (TestFailed(KErrCorrupt, _L("<Error> unknown test step")));
   307 		}
   340 		}
   308 	}
   341 	}