kerneltest/e32test/usbho/t_otgdi/src/testcase0675.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 "testcasewd.h"
    25 #include "testcasewd.h"
    26 #include "testcase0675.h"
    26 #include "testcase0675.h"
       
    27 #include "OstTraceDefinitions.h"
       
    28 #ifdef OST_TRACE_COMPILER_IN_USE
       
    29 #include "testcase0675Traces.h"
       
    30 #endif
    27 
    31 
    28 #define _REPEATS (oOpenIterations*3)
    32 #define _REPEATS (oOpenIterations*3)
    29 
    33 
    30 
    34 
    31 
    35 
    34 _LIT(KTestCaseId,"PBASE-USB_OTGDI-0675");
    38 _LIT(KTestCaseId,"PBASE-USB_OTGDI-0675");
    35 const TTestCaseFactoryReceipt<CTestCase0675> CTestCase0675::iFactoryReceipt(KTestCaseId);	
    39 const TTestCaseFactoryReceipt<CTestCase0675> CTestCase0675::iFactoryReceipt(KTestCaseId);	
    36 
    40 
    37 CTestCase0675* CTestCase0675::NewL(TBool aHost)
    41 CTestCase0675* CTestCase0675::NewL(TBool aHost)
    38 	{
    42 	{
    39 	LOG_FUNC
    43 	if(gVerboseOutput)
       
    44 	    {
       
    45 	    OstTraceFunctionEntry0(CTESTCASE0675_NEWL);
       
    46 	    }
    40 	CTestCase0675* self = new (ELeave) CTestCase0675(aHost);
    47 	CTestCase0675* self = new (ELeave) CTestCase0675(aHost);
    41 	CleanupStack::PushL(self);
    48 	CleanupStack::PushL(self);
    42 	self->ConstructL();
    49 	self->ConstructL();
    43 	CleanupStack::Pop(self);
    50 	CleanupStack::Pop(self);
    44 	return self;
    51 	return self;
    46 	
    53 	
    47 
    54 
    48 CTestCase0675::CTestCase0675(TBool aHost)
    55 CTestCase0675::CTestCase0675(TBool aHost)
    49 :	CTestCaseRoot(KTestCaseId, aHost)
    56 :	CTestCaseRoot(KTestCaseId, aHost)
    50 	{
    57 	{
    51 	LOG_FUNC
    58 	if(gVerboseOutput)
       
    59 	    {
       
    60 	    OstTraceFunctionEntry0(CTESTCASE0675_CTESTCASE0675);
       
    61 	    }
    52 		
    62 		
    53 	} 
    63 	} 
    54 
    64 
    55 
    65 
    56 /**
    66 /**
    57  ConstructL
    67  ConstructL
    58 */
    68 */
    59 void CTestCase0675::ConstructL()
    69 void CTestCase0675::ConstructL()
    60 	{
    70 	{
    61 	LOG_FUNC
    71 	if(gVerboseOutput)
       
    72 	    {
       
    73 	    OstTraceFunctionEntry0(CTESTCASE0675_CONSTRUCTL);
       
    74 	    }
    62 	iWDTimer = CTestCaseWatchdog::NewL();
    75 	iWDTimer = CTestCaseWatchdog::NewL();
    63 	iRepeats = OPEN_REPEATS;
    76 	iRepeats = OPEN_REPEATS;
    64 		
    77 		
    65 	BaseConstructL();
    78 	BaseConstructL();
    66 	}
    79 	}
    67 
    80 
    68 
    81 
    69 CTestCase0675::~CTestCase0675()
    82 CTestCase0675::~CTestCase0675()
    70 	{
    83 	{
    71 	LOG_FUNC
    84 	if(gVerboseOutput)
       
    85 	    {
       
    86 	    OstTraceFunctionEntry0(CTESTCASE0675_DCTESTCASE0675);
       
    87 	    }
    72 
    88 
    73 	Cancel();
    89 	Cancel();
    74 	delete iWDTimer;
    90 	delete iWDTimer;
    75 	
    91 	
    76 	}
    92 	}
    77 
    93 
    78 
    94 
    79 void CTestCase0675::ExecuteTestCaseL()
    95 void CTestCase0675::ExecuteTestCaseL()
    80 	{
    96 	{
    81 	LOG_FUNC
    97 	if(gVerboseOutput)
       
    98 	    {
       
    99 	    OstTraceFunctionEntry0(CTESTCASE0675_EXECUTETESTCASEL);
       
   100 	    }
    82 	iCaseStep = EPreconditions;
   101 	iCaseStep = EPreconditions;
    83 	
   102 	
    84 	iRepeats = KOperationRetriesMax;	// VBus event rise retries
   103 	iRepeats = KOperationRetriesMax;	// VBus event rise retries
    85 	
   104 	
    86 	CActiveScheduler::Add(this);
   105 	CActiveScheduler::Add(this);
    89 	}
   108 	}
    90 
   109 
    91 	
   110 	
    92 void CTestCase0675::DoCancel()
   111 void CTestCase0675::DoCancel()
    93 	{
   112 	{
    94 	LOG_FUNC
   113 	if(gVerboseOutput)
       
   114 	    {
       
   115 	    OstTraceFunctionEntry0(CTESTCASE0675_DOCANCEL);
       
   116 	    }
    95 
   117 
    96 	// cancel our timer
   118 	// cancel our timer
    97 	iTimer.Cancel();
   119 	iTimer.Cancel();
    98 	}
   120 	}
    99 
   121 
   100 
   122 
   101 void CTestCase0675::CancelKB(CTestCaseRoot *pThis)
   123 void CTestCase0675::CancelKB(CTestCaseRoot *pThis)
   102 	{
   124 	{
   103 	LOG_FUNC
   125 	if(gVerboseOutput)
       
   126 	    {
       
   127 	    OstTraceFunctionEntry0(CTESTCASE0675_CANCELKB);
       
   128 	    }
   104 	CTestCase0675 * p = REINTERPRET_CAST(CTestCase0675 *,pThis);
   129 	CTestCase0675 * p = REINTERPRET_CAST(CTestCase0675 *,pThis);
   105 	// cancel any pending call, and then complete our active obj with a cancel value
   130 	// cancel any pending call, and then complete our active obj with a cancel value
   106 	p->iConsole->ReadCancel();
   131 	p->iConsole->ReadCancel();
   107 
   132 
   108 	}
   133 	}
   109 
   134 
   110 
   135 
   111 void CTestCase0675::CancelNotify(CTestCaseRoot *pThis)
   136 void CTestCase0675::CancelNotify(CTestCaseRoot *pThis)
   112 	{
   137 	{
   113 	LOG_FUNC
   138 	if(gVerboseOutput)
       
   139 	    {
       
   140 	    OstTraceFunctionEntry0(CTESTCASE0675_CANCELNOTIFY);
       
   141 	    }
   114 	CTestCase0675 * p = REINTERPRET_CAST(CTestCase0675 *,pThis);
   142 	CTestCase0675 * p = REINTERPRET_CAST(CTestCase0675 *,pThis);
   115 	// cancel any pending call, and then complete our active obj with a timeout value
   143 	// cancel any pending call, and then complete our active obj with a timeout value
   116 	p->otgCancelOtgVbusNotification();
   144 	p->otgCancelOtgVbusNotification();
   117 	p->SelfComplete(KTestCaseWatchdogTO);
   145 	p->SelfComplete(KTestCaseWatchdogTO);
   118 	}
   146 	}
   120 
   148 
   121 // This test result depends on all the ID detection tests and the VBus driving and dropping tests have not yet passed
   149 // This test result depends on all the ID detection tests and the VBus driving and dropping tests have not yet passed
   122 void CTestCase0675::DescribePreconditions()
   150 void CTestCase0675::DescribePreconditions()
   123 	{
   151 	{
   124 	test.Printf(_L("Insert 'A' connector beforehand.\n"));
   152 	test.Printf(_L("Insert 'A' connector beforehand.\n"));
       
   153 	OstTrace0(TRACE_NORMAL, CTESTCASE0675_DESCRIBEPRECONDITIONS, "Insert 'A' connector beforehand.\n");
   125 	
   154 	
   126 	}
   155 	}
   127 
   156 
   128 void CTestCase0675::ContinueAfter(TTimeIntervalMicroSeconds32 aMicroSecs, TCaseSteps aStep)
   157 void CTestCase0675::ContinueAfter(TTimeIntervalMicroSeconds32 aMicroSecs, TCaseSteps aStep)
   129 	{
   158 	{
   130 	LOG_VERBOSE2(_L("Wait %dms before drop VBus"), (TInt)(aMicroSecs.Int()/1000));
   159 	LOG_VERBOSE2(_L("Wait %dms before drop VBus"), (TInt)(aMicroSecs.Int()/1000));
       
   160 	if(gVerboseOutput)
       
   161 	    {
       
   162 	    OstTrace1(TRACE_VERBOSE, CTESTCASE0675_CONTINUEAFTER, "Wait %dms before drop VBus", (TInt)(aMicroSecs.Int()/1000));;
       
   163 	    }
   131 	iTimer.After(iStatus, aMicroSecs);
   164 	iTimer.After(iStatus, aMicroSecs);
   132 	iCaseStep = aStep;
   165 	iCaseStep = aStep;
   133 	SetActive();
   166 	SetActive();
   134 	}
   167 	}
   135 
   168 
   136 // handle event completion	
   169 // handle event completion	
   137 void CTestCase0675::RunStepL()
   170 void CTestCase0675::RunStepL()
   138 	{
   171 	{
   139 	LOG_FUNC
   172 	if(gVerboseOutput)
       
   173 	    {
       
   174 	    OstTraceFunctionEntry0(CTESTCASE0675_RUNSTEPL);
       
   175 	    }
   140 	// Obtain the completion code for this CActive obj.
   176 	// Obtain the completion code for this CActive obj.
   141 	TInt completionCode(iStatus.Int()); 
   177 	TInt completionCode(iStatus.Int()); 
   142 	TBuf<MAX_DSTRLEN> aDescription;
   178 	TBuf<MAX_DSTRLEN> aDescription;
   143 	TInt err(0);
   179 	TInt err(0);
   144 
   180 
   153 				SelfComplete();
   189 				SelfComplete();
   154 				break;
   190 				break;
   155 				}
   191 				}
   156 			// prompt to insert connector
   192 			// prompt to insert connector
   157 			test.Printf(KInsertAConnectorPrompt);
   193 			test.Printf(KInsertAConnectorPrompt);
       
   194 			OstTrace0(TRACE_NORMAL, CTESTCASE0675_RUNSTEPL_DUP01, KInsertAConnectorPrompt);
   158 			test.Printf(KPressAnyKeyToContinue);
   195 			test.Printf(KPressAnyKeyToContinue);
       
   196 			OstTrace0(TRACE_NORMAL, CTESTCASE0675_RUNSTEPL_DUP02, KPressAnyKeyToContinue);
   159 			RequestCharacter();			
   197 			RequestCharacter();			
   160 			break;
   198 			break;
   161 			
   199 			
   162 			// 1. load the LDD and init.
   200 			// 1. load the LDD and init.
   163 		case ELoadLdd:
   201 		case ELoadLdd:
   179 				return TestFailed(KErrAbort, _L("User response too slow - FAILED!"));
   217 				return TestFailed(KErrAbort, _L("User response too slow - FAILED!"));
   180 				}
   218 				}
   181 			if (!otgIdPinPresent())
   219 			if (!otgIdPinPresent())
   182 				{
   220 				{
   183 				test.Printf(KInsertAConnectorPrompt);
   221 				test.Printf(KInsertAConnectorPrompt);
       
   222 				OstTrace0(TRACE_NORMAL, CTESTCASE0675_RUNSTEPL_DUP03, KInsertAConnectorPrompt);
   184 				test.Printf(KPressAnyKeyToContinue);
   223 				test.Printf(KPressAnyKeyToContinue);
       
   224 				OstTrace0(TRACE_NORMAL, CTESTCASE0675_RUNSTEPL_DUP04, KPressAnyKeyToContinue);
   185 				RequestCharacter();
   225 				RequestCharacter();
   186 				iCaseStep = EDetectAPlug;
   226 				iCaseStep = EDetectAPlug;
   187 				}
   227 				}
   188 			else
   228 			else
   189 				{
   229 				{
   207 			
   247 			
   208 			// 4. DRIVE VBUS
   248 			// 4. DRIVE VBUS
   209 		case ELoopDriveVBus1:
   249 		case ELoopDriveVBus1:
   210 			iWDTimer->Cancel();
   250 			iWDTimer->Cancel();
   211 			test.Printf(_L("Drive VBus, iteration %d/%d\n"), OPEN_REPEATS-iRepeats+1, OPEN_REPEATS);
   251 			test.Printf(_L("Drive VBus, iteration %d/%d\n"), OPEN_REPEATS-iRepeats+1, OPEN_REPEATS);
       
   252 			OstTraceExt2(TRACE_NORMAL, CTESTCASE0675_RUNSTEPL_DUP05, "Drive VBus, iteration %d/%d\n", OPEN_REPEATS-iRepeats+1, OPEN_REPEATS);
   212 			// test for VBus rise next
   253 			// test for VBus rise next
   213 			test.Printf(_L("Waiting for VBus Event\n"));
   254 			test.Printf(_L("Waiting for VBus Event\n"));
       
   255 			OstTrace0(TRACE_NORMAL, CTESTCASE0675_RUNSTEPL_DUP06, "Waiting for VBus Event\n");
   214 			iStatus = KRequestPending;
   256 			iStatus = KRequestPending;
   215 			otgQueueOtgVbusNotification( iOTGVBus, iStatus );
   257 			otgQueueOtgVbusNotification( iOTGVBus, iStatus );
   216 			SetActive();
   258 			SetActive();
   217 			
   259 			
   218 			// turn on VBus, since the call is not a Queing a-sync call we do this after the async call
   260 			// turn on VBus, since the call is not a Queing a-sync call we do this after the async call
   245 
   287 
   246 			// 6. DRIVE/claim VBUS 2nd time
   288 			// 6. DRIVE/claim VBUS 2nd time
   247 		case ELoopDriveVBus2:
   289 		case ELoopDriveVBus2:
   248 			iWDTimer->Cancel();
   290 			iWDTimer->Cancel();
   249 			test.Printf(_L("Drive VBus double, iteration %d/%d\n"), OPEN_REPEATS-iRepeats+1, OPEN_REPEATS);
   291 			test.Printf(_L("Drive VBus double, iteration %d/%d\n"), OPEN_REPEATS-iRepeats+1, OPEN_REPEATS);
       
   292 			OstTraceExt2(TRACE_NORMAL, CTESTCASE0675_RUNSTEPL_DUP07, "Drive VBus double, iteration %d/%d\n", OPEN_REPEATS-iRepeats+1, OPEN_REPEATS);
   250 
   293 
   251 			err = otgBusRequest();	// duplicate turn on VBus, we expect an error 
   294 			err = otgBusRequest();	// duplicate turn on VBus, we expect an error 
   252 			if (KErrUsbOtgVbusAlreadyRaised != err)
   295 			if (KErrUsbOtgVbusAlreadyRaised != err)
   253 				{
   296 				{
   254 				return TestFailed(KErrAbort, _L("Raise Vbus - RUsbOtgDriver::BusRequest() unexpected result!"));
   297 				return TestFailed(KErrAbort, _L("Raise Vbus - RUsbOtgDriver::BusRequest() unexpected result!"));
   325 			TestPassed();
   368 			TestPassed();
   326 			break;
   369 			break;
   327 			
   370 			
   328 		default:
   371 		default:
   329 			test.Printf(_L("<Error> unknown test step"));
   372 			test.Printf(_L("<Error> unknown test step"));
       
   373 			OstTrace0(TRACE_NORMAL, CTESTCASE0675_RUNSTEPL_DUP08, "<Error> unknown test step");
   330 			Cancel();
   374 			Cancel();
   331 			return (TestFailed(KErrCorrupt, _L("<Error> unknown test step")));
   375 			return (TestFailed(KErrCorrupt, _L("<Error> unknown test step")));
   332 		}
   376 		}
   333 	}
   377 	}
   334 
   378