kerneltest/e32test/usbho/t_otgdi/src/testcase0467.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 "testcasewd.h"
    25 #include "testcasewd.h"
    26 #include "testcase0467.h"
    26 #include "testcase0467.h"
    27 #include "OstTraceDefinitions.h"
       
    28 #ifdef OST_TRACE_COMPILER_IN_USE
       
    29 #include "testcase0467Traces.h"
       
    30 #endif
       
    31 
    27 
    32 
    28 
    33 
    29 
    34 // # times to repeat the steps (default=3)
    30 // # times to repeat the steps (default=3)
    35 #define INSERT_REPEATS		gOpenIterations
    31 #define INSERT_REPEATS		gOpenIterations
    39 _LIT(KTestCaseId,"PBASE-USB_OTGDI-0467");
    35 _LIT(KTestCaseId,"PBASE-USB_OTGDI-0467");
    40 const TTestCaseFactoryReceipt<CTestCase0467> CTestCase0467::iFactoryReceipt(KTestCaseId);	
    36 const TTestCaseFactoryReceipt<CTestCase0467> CTestCase0467::iFactoryReceipt(KTestCaseId);	
    41 
    37 
    42 CTestCase0467* CTestCase0467::NewL(TBool aHost)
    38 CTestCase0467* CTestCase0467::NewL(TBool aHost)
    43 	{
    39 	{
    44 	if(gVerboseOutput)
    40 	LOG_FUNC
    45 	    {
       
    46 	    OstTraceFunctionEntry0(CTESTCASE0467_NEWL);
       
    47 	    }
       
    48 	CTestCase0467* self = new (ELeave) CTestCase0467(aHost);
    41 	CTestCase0467* self = new (ELeave) CTestCase0467(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 CTestCase0467::CTestCase0467(TBool aHost)
    49 CTestCase0467::CTestCase0467(TBool aHost)
    57 :	CTestCaseRoot(KTestCaseId, aHost)
    50 :	CTestCaseRoot(KTestCaseId, aHost)
    58 	{
    51 	{
    59 	if(gVerboseOutput)
    52 	LOG_FUNC
    60 	    {
       
    61 	    OstTraceFunctionEntry0(CTESTCASE0467_CTESTCASE0467);
       
    62 	    }
       
    63 		
    53 		
    64 	} 
    54 	} 
    65 
    55 
    66 
    56 
    67 /**
    57 /**
    68  ConstructL
    58  ConstructL
    69 */
    59 */
    70 void CTestCase0467::ConstructL()
    60 void CTestCase0467::ConstructL()
    71 	{
    61 	{
    72 	if(gVerboseOutput)
    62 	LOG_FUNC
    73 	    {
       
    74 	    OstTraceFunctionEntry0(CTESTCASE0467_CONSTRUCTL);
       
    75 	    }
       
    76 	iRepeats = INSERT_REPEATS;
    63 	iRepeats = INSERT_REPEATS;
    77 	iWDTimer = CTestCaseWatchdog::NewL();
    64 	iWDTimer = CTestCaseWatchdog::NewL();
    78 	
    65 	
    79 	BaseConstructL();
    66 	BaseConstructL();
    80 	}
    67 	}
    81 
    68 
    82 
    69 
    83 CTestCase0467::~CTestCase0467()
    70 CTestCase0467::~CTestCase0467()
    84 	{
    71 	{
    85 	if(gVerboseOutput)
    72 	LOG_FUNC
    86 	    {
       
    87 	    OstTraceFunctionEntry0(CTESTCASE0467_DCTESTCASE0467);
       
    88 	    }
       
    89 
    73 
    90 	Cancel();
    74 	Cancel();
    91 	delete iWDTimer;
    75 	delete iWDTimer;
    92 	
    76 	
    93 	}
    77 	}
    94 
    78 
    95 
    79 
    96 void CTestCase0467::ExecuteTestCaseL()
    80 void CTestCase0467::ExecuteTestCaseL()
    97 	{
    81 	{
    98 	if(gVerboseOutput)
    82 	LOG_FUNC
    99 	    {
       
   100 	    OstTraceFunctionEntry0(CTESTCASE0467_EXECUTETESTCASEL);
       
   101 	    }
       
   102 	iCaseStep = EPreconditions;
    83 	iCaseStep = EPreconditions;
   103 	
    84 	
   104 	iRepeats = KOperationRetriesMax;	// VBus event rise retries
    85 	iRepeats = KOperationRetriesMax;	// VBus event rise retries
   105 	
    86 	
   106 	CActiveScheduler::Add(this);
    87 	CActiveScheduler::Add(this);
   109 	}
    90 	}
   110 
    91 
   111 	
    92 	
   112 void CTestCase0467::DoCancel()
    93 void CTestCase0467::DoCancel()
   113 	{
    94 	{
   114 	if(gVerboseOutput)
    95 	LOG_FUNC
   115 	    {
       
   116 	    OstTraceFunctionEntry0(CTESTCASE0467_DOCANCEL);
       
   117 	    }
       
   118 
    96 
   119 	// cancel our timer
    97 	// cancel our timer
   120 	iTimer.Cancel();
    98 	iTimer.Cancel();
   121 	}
    99 	}
   122 
   100 
   131 	}
   109 	}
   132 
   110 
   133 
   111 
   134 void CTestCase0467::CancelIdPin(CTestCaseRoot *pThis)
   112 void CTestCase0467::CancelIdPin(CTestCaseRoot *pThis)
   135 	{
   113 	{
   136 	if(gVerboseOutput)
   114 	LOG_FUNC
   137 	    {
       
   138 	    OstTraceFunctionEntry0(CTESTCASE0467_CANCELIDPIN);
       
   139 	    }
       
   140 	
   115 	
   141 	CTestCase0467 * p = REINTERPRET_CAST(CTestCase0467 *,pThis);
   116 	CTestCase0467 * p = REINTERPRET_CAST(CTestCase0467 *,pThis);
   142 	// cancel any pending call, and then complete our active obj with a timeout value
   117 	// cancel any pending call, and then complete our active obj with a timeout value
   143 	p->otgCancelOtgIdPinNotification();
   118 	p->otgCancelOtgIdPinNotification();
   144 	p->SelfComplete(KTestCaseWatchdogTO);	
   119 	p->SelfComplete(KTestCaseWatchdogTO);	
   147 
   122 
   148 // This test result depends on all the ID detection tests and the VBus driving and dropping tests have not yet passed
   123 // This test result depends on all the ID detection tests and the VBus driving and dropping tests have not yet passed
   149 void CTestCase0467::DescribePreconditions()
   124 void CTestCase0467::DescribePreconditions()
   150 	{
   125 	{
   151 	test.Printf(_L("Remove 'A' connector beforehand.\n"));
   126 	test.Printf(_L("Remove 'A' connector beforehand.\n"));
   152 	OstTrace0(TRACE_NORMAL, CTESTCASE0467_DESCRIBEPRECONDITIONS, "Remove 'A' connector beforehand.\n");
       
   153 	test.Printf(_L("ID_PIN detection and VBus driving tests must already pass.\n"));
   127 	test.Printf(_L("ID_PIN detection and VBus driving tests must already pass.\n"));
   154 	OstTrace0(TRACE_NORMAL, CTESTCASE0467_DESCRIBEPRECONDITIONS_DUP01, "ID_PIN detection and VBus driving tests must already pass.\n");
       
   155 	}
   128 	}
   156 		
   129 		
   157 
   130 
   158 // handle event completion	
   131 // handle event completion	
   159 void CTestCase0467::RunStepL()
   132 void CTestCase0467::RunStepL()
   160 	{
   133 	{
   161 	if(gVerboseOutput)
   134 	LOG_FUNC
   162 	    {
       
   163 	    OstTraceFunctionEntry0(CTESTCASE0467_RUNSTEPL);
       
   164 	    }
       
   165 	// Obtain the completion code for this CActive obj.
   135 	// Obtain the completion code for this CActive obj.
   166 	TInt completionCode(iStatus.Int()); 
   136 	TInt completionCode(iStatus.Int()); 
   167 	TBuf<MAX_DSTRLEN> aDescription;
   137 	TBuf<MAX_DSTRLEN> aDescription;
   168 
   138 
   169 	switch(iCaseStep)
   139 	switch(iCaseStep)
   176 				SelfComplete();
   146 				SelfComplete();
   177 				break;
   147 				break;
   178 				}
   148 				}
   179 			// prompt to remove connector
   149 			// prompt to remove connector
   180 			test.Printf(KRemoveAConnectorPrompt);
   150 			test.Printf(KRemoveAConnectorPrompt);
   181 			OstTrace0(TRACE_NORMAL, CTESTCASE0467_RUNSTEPL_DUP01, KRemoveAConnectorPrompt);
       
   182 			test.Printf(KPressAnyKeyToContinue);
   151 			test.Printf(KPressAnyKeyToContinue);
   183 			OstTrace0(TRACE_NORMAL, CTESTCASE0467_RUNSTEPL_DUP02, KPressAnyKeyToContinue);
       
   184 			RequestCharacter();			
   152 			RequestCharacter();			
   185 			break;
   153 			break;
   186 			
   154 			
   187 		case ELoadLdd:
   155 		case ELoadLdd:
   188 			// 1. load the LDD and init.
   156 			// 1. load the LDD and init.
   196 			SelfComplete();
   164 			SelfComplete();
   197 			break;
   165 			break;
   198 			
   166 			
   199 		case ERepeatLoop: // 2
   167 		case ERepeatLoop: // 2
   200 			test.Printf(_L("Repeat test %d/%d\n"), INSERT_REPEATS-iRepeats+1, INSERT_REPEATS);
   168 			test.Printf(_L("Repeat test %d/%d\n"), INSERT_REPEATS-iRepeats+1, INSERT_REPEATS);
   201 			OstTraceExt2(TRACE_NORMAL, CTESTCASE0467_RUNSTEPL_DUP03, "Repeat test %d/%d\n", INSERT_REPEATS-iRepeats+1, INSERT_REPEATS);
       
   202 
   169 
   203 			if (--iRepeats)
   170 			if (--iRepeats)
   204 				iCaseStep = EWaitForIDPresent;
   171 				iCaseStep = EWaitForIDPresent;
   205 			else
   172 			else
   206 				iCaseStep = EUnloadLdd;
   173 				iCaseStep = EUnloadLdd;
   208 			break;
   175 			break;
   209 			
   176 			
   210 		case EWaitForIDPresent:
   177 		case EWaitForIDPresent:
   211 			// 3. prompt for insertion
   178 			// 3. prompt for insertion
   212 			test.Printf(KInsertAConnectorPrompt);
   179 			test.Printf(KInsertAConnectorPrompt);
   213 			OstTrace0(TRACE_NORMAL, CTESTCASE0467_RUNSTEPL_DUP04, KInsertAConnectorPrompt);
       
   214 			otgQueueOtgIdPinNotification( iOTGIdPin, iStatus );
   180 			otgQueueOtgIdPinNotification( iOTGIdPin, iStatus );
   215 
   181 
   216 			SetActive();
   182 			SetActive();
   217 			iCaseStep = EVerifyIDPresent;
   183 			iCaseStep = EVerifyIDPresent;
   218 			iDetectionRetry = 0;
   184 			iDetectionRetry = 0;
   219 			break;
   185 			break;
   220 			
   186 			
   221 		case EVerifyIDPresent:
   187 		case EVerifyIDPresent:
   222 			// 4. detect id_pin event
   188 			// 4. detect id_pin event
   223 			LOG_VERBOSE1(_L("STEP4 - detect id_pin event 'A'\n"));
   189 			LOG_VERBOSE1(_L("STEP4 - detect id_pin event 'A'\n"));
   224 			if(gVerboseOutput)
       
   225 			    {
       
   226 			    OstTrace0(TRACE_VERBOSE, CTESTCASE0467_RUNSTEPL_DUP05, "STEP4 - detect id_pin event 'A'\n");;
       
   227 			    }
       
   228 
   190 
   229 			// retrieve the current ID_PIN value
   191 			// retrieve the current ID_PIN value
   230 			otgQueueOtgIdPinNotification( iOTGIdPin, iStatus );
   192 			otgQueueOtgIdPinNotification( iOTGIdPin, iStatus );
   231 			otgCancelOtgIdPinNotification();
   193 			otgCancelOtgIdPinNotification();
   232 			User::WaitForRequest(iStatus); // swallow the cancellation event (serves to test that it does cancel)
   194 			User::WaitForRequest(iStatus); // swallow the cancellation event (serves to test that it does cancel)
   260 			break;
   222 			break;
   261 			
   223 			
   262 		case EWaitForIDGone: 
   224 		case EWaitForIDGone: 
   263 			// 5. prompt for insertion
   225 			// 5. prompt for insertion
   264 			test.Printf(KRemoveAConnectorPrompt);
   226 			test.Printf(KRemoveAConnectorPrompt);
   265 			OstTrace0(TRACE_NORMAL, CTESTCASE0467_RUNSTEPL_DUP06, KRemoveAConnectorPrompt);
       
   266 			otgQueueOtgIdPinNotification( iOTGIdPin, iStatus );
   227 			otgQueueOtgIdPinNotification( iOTGIdPin, iStatus );
   267 			SetActive();
   228 			SetActive();
   268 			iCaseStep = EVerifyIDGone;
   229 			iCaseStep = EVerifyIDGone;
   269 			break;
   230 			break;
   270 			
   231 			
   271 		case EVerifyIDGone:
   232 		case EVerifyIDGone:
   272 			// 6. detect id_pin gone event
   233 			// 6. detect id_pin gone event
   273 			LOG_VERBOSE1(_L("STEP4 - detect id_pin remove event 'B'\n"));
   234 			LOG_VERBOSE1(_L("STEP4 - detect id_pin remove event 'B'\n"));
   274 			if(gVerboseOutput)
       
   275 			    {
       
   276 			    OstTrace0(TRACE_VERBOSE, CTESTCASE0467_RUNSTEPL_DUP07, "STEP4 - detect id_pin remove event 'B'\n");;
       
   277 			    }
       
   278 			test.Printf(_L("ID_PIN=%d\n"), iOTGIdPin);
   235 			test.Printf(_L("ID_PIN=%d\n"), iOTGIdPin);
   279 			OstTrace1(TRACE_NORMAL, CTESTCASE0467_RUNSTEPL_DUP08, "ID_PIN=%d\n", iOTGIdPin);
       
   280 
   236 
   281 			User::After(5000); // 5ms
   237 			User::After(5000); // 5ms
   282 			otgQueueOtgIdPinNotification( iOTGIdPin, iStatus );
   238 			otgQueueOtgIdPinNotification( iOTGIdPin, iStatus );
   283 			otgCancelOtgIdPinNotification();
   239 			otgCancelOtgIdPinNotification();
   284 			User::WaitForRequest(iStatus); // swallow it
   240 			User::WaitForRequest(iStatus); // swallow it
   285 			test.Printf(_L("ID_PIN=%d\n"), iOTGIdPin);
   241 			test.Printf(_L("ID_PIN=%d\n"), iOTGIdPin);
   286 			OstTrace1(TRACE_NORMAL, CTESTCASE0467_RUNSTEPL_DUP09, "ID_PIN=%d\n", iOTGIdPin);
       
   287 
   242 
   288 			if (iOTGIdPin != RUsbOtgDriver::EIdPinBPlug)
   243 			if (iOTGIdPin != RUsbOtgDriver::EIdPinBPlug)
   289 				{
   244 				{
   290 				if (iDetectionRetry++ < 3)
   245 				if (iDetectionRetry++ < 3)
   291 					{
   246 					{
   321 			TestPassed();
   276 			TestPassed();
   322 			break;
   277 			break;
   323 			
   278 			
   324 		default:
   279 		default:
   325 			test.Printf(_L("<Error> unknown test step"));
   280 			test.Printf(_L("<Error> unknown test step"));
   326 			OstTrace0(TRACE_NORMAL, CTESTCASE0467_RUNSTEPL_DUP10, "<Error> unknown test step");
       
   327 			Cancel();
   281 			Cancel();
   328 			return (TestFailed(KErrCorrupt, _L("<Error> unknown test step")));
   282 			return (TestFailed(KErrCorrupt, _L("<Error> unknown test step")));
   329 		}
   283 		}
   330 	}
   284 	}
   331 
   285