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