os/kernelhwsrv/kerneltest/e32test/usbho/t_otgdi/src/testcase0677.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 // Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
     2 // All rights reserved.
     3 // This component and the accompanying materials are made available
     4 // under the terms of the License "Eclipse Public License v1.0"
     5 // which accompanies this distribution, and is available
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7 //
     8 // Initial Contributors:
     9 // Nokia Corporation - initial contribution.
    10 //
    11 // Contributors:
    12 //
    13 // Description:
    14 // @internalComponent
    15 // 
    16 //
    17 
    18 #include <e32std.h>
    19 #include <e32std_private.h>
    20 #include <u32std.h> 	// unicode builds
    21 #include <e32base.h>
    22 #include <e32base_private.h>
    23 #include <e32Test.h>	// RTest headder
    24 #include "testcaseroot.h"
    25 #include "testcasewd.h"
    26 #include "testcase0677.h"
    27 
    28 #define _REPEATS (oOpenIterations*3)
    29 
    30 
    31 
    32 // the name below is used to add a pointer to our construction method to a pointer MAP in 
    33 // the class factory
    34 _LIT(KTestCaseId,"PBASE-USB_OTGDI-0677");
    35 const TTestCaseFactoryReceipt<CTestCase0677> CTestCase0677::iFactoryReceipt(KTestCaseId);	
    36 
    37 CTestCase0677* CTestCase0677::NewL(TBool aHost)
    38 	{
    39 	LOG_FUNC
    40 	CTestCase0677* self = new (ELeave) CTestCase0677(aHost);
    41 	CleanupStack::PushL(self);
    42 	self->ConstructL();
    43 	CleanupStack::Pop(self);
    44 	return self;
    45 	}
    46 	
    47 
    48 CTestCase0677::CTestCase0677(TBool aHost)
    49 :	CTestCaseRoot(KTestCaseId, aHost)
    50 	{
    51 	LOG_FUNC
    52 		
    53 	} 
    54 
    55 
    56 /**
    57  ConstructL
    58 */
    59 void CTestCase0677::ConstructL()
    60 	{
    61 	LOG_FUNC
    62 	iWDTimer = CTestCaseWatchdog::NewL();
    63 	iRepeats = OPEN_REPEATS;
    64 		
    65 	BaseConstructL();
    66 	}
    67 
    68 
    69 CTestCase0677::~CTestCase0677()
    70 	{
    71 	LOG_FUNC
    72 
    73 	Cancel();
    74 	delete iWDTimer;
    75 	
    76 	}
    77 
    78 
    79 void CTestCase0677::ExecuteTestCaseL()
    80 	{
    81 	LOG_FUNC
    82 	iCaseStep = EPreconditions;
    83 	
    84 	iRepeats = KOperationRetriesMax;	// VBus event rise retries
    85 	
    86 	CActiveScheduler::Add(this);
    87 	SelfComplete();
    88 
    89 	}
    90 
    91 	
    92 void CTestCase0677::DoCancel()
    93 	{
    94 	LOG_FUNC
    95 
    96 	// cancel our timer
    97 	iTimer.Cancel();
    98 	}
    99 
   100 
   101 void CTestCase0677::CancelKB(CTestCaseRoot *pThis)
   102 	{
   103 	LOG_FUNC
   104 	CTestCase0677 * p = REINTERPRET_CAST(CTestCase0677 *,pThis);
   105 	// cancel any pending call, and then complete our active obj with a cancel value
   106 	p->iConsole->ReadCancel();
   107 
   108 	}
   109 
   110 
   111 void CTestCase0677::CancelNotify(CTestCaseRoot *pThis)
   112 	{
   113 	LOG_FUNC
   114 	CTestCase0677 * p = REINTERPRET_CAST(CTestCase0677 *,pThis);
   115 	// cancel any pending call, and then complete our active obj with a timeout value
   116 	switch (p->iCancelWhat)
   117 		{
   118 			case ECancelEventNotify:
   119 				p->otgCancelOtgEventRequest();
   120 				break;			
   121 			case ECancelMessageNotify: 
   122 				p->otgCancelOtgMessageRequest();
   123 				break;
   124 			case ECancelVBusNotify:
   125 				p->otgCancelOtgVbusNotification();
   126 				break;	
   127 			default:
   128 				ASSERT(0);
   129 				break;
   130 		}
   131 	p->SelfComplete(KTestCaseWatchdogTO);
   132 	}
   133 
   134 
   135 // This test result depends on all the ID detection tests and the VBus driving and dropping tests have not yet passed
   136 void CTestCase0677::DescribePreconditions()
   137 	{
   138 	test.Printf(_L("Using OET, connect oscilloscope chan.A to VBus\n"));
   139 	test.Printf(_L("Connect oscilloscope chan.B to D+\n"));
   140 	test.Printf(_L("Trigger once, 200mV, 100ms \n"));
   141 	test.Printf(_L("Prepare to observe VBus, D+ pulse.\n\n"));
   142 	}
   143 
   144 
   145 void CTestCase0677::ContinueAfter(TTimeIntervalMicroSeconds32 aMicroSecs, TCaseSteps aStep)
   146 	{
   147 	LOG_VERBOSE2(_L("Wait %dms before drop VBus"), (TInt)(aMicroSecs.Int()/1000));
   148 	iTimer.After(iStatus, aMicroSecs);
   149 	iCaseStep = aStep;
   150 	SetActive();
   151 	}
   152 
   153 
   154 // handle event completion	
   155 void CTestCase0677::RunStepL()
   156 	{
   157 	LOG_FUNC
   158 	// Obtain the completion code for this CActive obj.
   159 	TInt completionCode(iStatus.Int()); 
   160 	TBuf<MAX_DSTRLEN> aDescription;
   161 	TInt err(0);
   162 
   163 
   164 	switch(iCaseStep)
   165 		{
   166 		case EPreconditions:
   167 			iCaseStep = ELoadLdd;
   168 			if (iAutomated)
   169 				{
   170 				iCaseStep = ELoadLdd;
   171 				SelfComplete();
   172 				break;
   173 				}
   174 			// prompt to insert connector
   175 			test.Printf(KAttachOETAsBDevice);
   176 			test.Printf(KPressAnyKeyToContinue);
   177 			RequestCharacter();			
   178 			break;
   179 			
   180 			// 1. load the LDD and init.		
   181 		case ELoadLdd:
   182 			if (!StepLoadLDD())
   183 				{
   184 				break;
   185 				}
   186 			iCaseStep = EDetectBPlug;
   187 			SelfComplete();
   188 			break;
   189 
   190 			// 2. detect 'B' plug now
   191 		case EDetectBPlug:
   192 			if (KTestCaseWatchdogTO == iStatus.Int())
   193 				{
   194 				return TestFailed(KErrAbort, _L("User response too slow - FAILED!"));
   195 				}
   196 
   197 			// if doing this test in /AUTO mode, we would fail this now
   198 			// however if we can control ID_PIN through an API in future, we turn in on now.
   199 			if (otgIdPinPresent())
   200 				{
   201 				test.Printf(KRemoveAConnectorPrompt);
   202 				test.Printf(KPressAnyKeyToContinue);
   203 				RequestCharacter();
   204 
   205 				iCaseStep = EDetectBPlug;
   206 				}
   207 			else
   208 				{
   209 				iCaseStep = ERequestBus;
   210 				SelfComplete();
   211 				}
   212 			break;
   213 						
   214 			// 5. Issue SRP (request VBUS)
   215 		case ERequestBus:
   216 			iWDTimer->Cancel();
   217 
   218 			test.Printf(KMsgWaitingForSRPInitiated);
   219 			otgQueueOtgEventRequest( iOTGEvent, iStatus );
   220 
   221 			// turn on VBus (B-SRP)
   222 			err = otgBusRequest();
   223 			iTimeSRPStart.HomeTime();
   224 			
   225 			if (KErrNone != err)
   226 				{
   227 				return TestFailed(KErrAbort, _L("Issue SRP - RUsbOtgDriver::BusRequest() FAILED!"));
   228 				}
   229 			iCaseStep = EWaitForSRPInitiated;
   230 			iCancelWhat = ECancelEventNotify;
   231 			iWDTimer->IssueRequest(32000*2 /*KSpec_TA_SRP_RSPNS +1000*/, this, &CancelNotify);
   232 			SetActive();
   233 			break;
   234 			
   235 			// 6. get SRP initiated event, this is a local indication
   236 		case EWaitForSRPInitiated:			
   237 			if (KTestCaseWatchdogTO == iStatus.Int())
   238 				{
   239 				return TestFailed(KErrAbort, _L("SRP Active indication NOT fired in time - FAILED!"));
   240 				}
   241 			OtgEventString(iOTGEvent, aDescription);
   242 			test.Printf(_L("Received event %d '%S' status(%d)\n"), iOTGEvent, &aDescription, completionCode);
   243 			if (RUsbOtgDriver::EEventSrpInitiated == iOTGEvent)
   244 				{
   245 				// calc interval
   246 				TTimeIntervalMicroSeconds aIntvlMicro;
   247 				TTime aNowTime;
   248 				aNowTime.HomeTime();
   249 				aIntvlMicro = aNowTime.MicroSecondsFrom(iTimeSRPStart);
   250 				LOG_VERBOSE2(_L("SRP active after %d ms\n"), (TInt)(aIntvlMicro.Int64()/1000));
   251 				iCancelWhat = ECancelMessageNotify;
   252 				otgQueueOtgMessageRequest( iOTGMessage, iStatus );
   253 				iCaseStep = EWaitForSRPTimeout;
   254 				test.Printf(KMsgWaitingForSRPTimeout);
   255 				SetActive();
   256 				}
   257 			else
   258 				{
   259 				iCaseStep = EWaitForSRPInitiated;
   260 				test.Printf(KMsgWaitingForSRPInitiated);
   261 				iStatus = KRequestPending;
   262 				otgQueueOtgEventRequest( iOTGEvent, iStatus );
   263 				SetActive();
   264 				}
   265 			break;
   266 				
   267 			// 6. get SRP timeout event, this is a local indication
   268 		case EWaitForSRPTimeout:			
   269 			if (KTestCaseWatchdogTO == iStatus.Int())
   270 				{
   271 				return TestFailed(KErrAbort, _L("SRP T/O NOT fired in time - FAILED!"));
   272 				}
   273 			OtgMessageString(iOTGMessage, aDescription);
   274 			test.Printf(_L("Received message %d '%S' status(%d)\n"), iOTGMessage, &aDescription, completionCode);
   275 			if (RUsbOtgDriver::EMessageSrpTimeout == iOTGMessage)
   276 				{
   277 				iWDTimer->Cancel();		//	Only cancel WD Timer here, when timed portion of test is over
   278 				// calc interval
   279 				TTimeIntervalMicroSeconds aIntvlMicro;
   280 				TTime aNowTime;
   281 				aNowTime.HomeTime();
   282 				aIntvlMicro = aNowTime.MicroSecondsFrom(iTimeSRPStart);
   283 				LOG_VERBOSE2(_L("SRP times out after %d ms\n"), (TInt)(aIntvlMicro.Int64()/1000));
   284 				// the correct value is 32 seconds, not 4.9 seconds as per the spec.
   285 
   286 				iCaseStep = EIssueSRPObservedPrompt;
   287 				SelfComplete();
   288 				}
   289 			else
   290 				{
   291 				iCaseStep = EWaitForSRPTimeout;
   292 				test.Printf(KMsgWaitingForSRPTimeout);
   293 				iStatus = KRequestPending;
   294 				otgQueueOtgMessageRequest( iOTGMessage, iStatus );
   295 				SetActive();
   296 				}
   297 			break;
   298 				
   299 		case EIssueSRPObservedPrompt:
   300 			{
   301 			test.Printf(_L("\nPress Y to verify that SRP was observed\n"));
   302 			test.Printf(_L("or any other key to fail test.\n"));
   303 			RequestCharacter();
   304 			iCaseStep = ECheckSRPObservedUserInput;
   305 			break;
   306 			}
   307 			
   308 							
   309 		case ECheckSRPObservedUserInput:
   310 			{
   311 			if (('y' != iKeyCodeInput) && ('Y' != iKeyCodeInput))
   312 				{
   313 				return TestFailed(KErrAbort, _L("SRP NOT observed - FAILED!"));
   314 				}
   315 			iCaseStep = EUnloadLdd;
   316 			SelfComplete();
   317 			break;
   318 			}
   319 							
   320 			// 12. unload OTG
   321 		case EUnloadLdd:
   322 			if (EFalse == StepUnloadLDD())
   323 				return TestFailed(KErrAbort,_L("Unload Ldd failure"));	
   324 			
   325 			iCaseStep = ELastStep;
   326 			SelfComplete();
   327 			break;
   328 			
   329 		case ELastStep:
   330 			TestPassed();
   331 			break;
   332 			
   333 		default:
   334 			test.Printf(_L("<Error> unknown test step\n"));
   335 			Cancel();
   336 			return (TestFailed(KErrCorrupt, _L("<Error> unknown test step")));
   337 		}
   338 	}
   339 
   340