kerneltest/e32test/usbho/t_otgdi/src/testcase0676.cpp
changeset 0 a41df078684a
child 253 d37db4dcc88d
equal deleted inserted replaced
-1:000000000000 0:a41df078684a
       
     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 "testcase0676.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-0676");
       
    35 const TTestCaseFactoryReceipt<CTestCase0676> CTestCase0676::iFactoryReceipt(KTestCaseId);	
       
    36 
       
    37 CTestCase0676* CTestCase0676::NewL(TBool aHost)
       
    38 	{
       
    39 	LOG_FUNC
       
    40 	CTestCase0676* self = new (ELeave) CTestCase0676(aHost);
       
    41 	CleanupStack::PushL(self);
       
    42 	self->ConstructL();
       
    43 	CleanupStack::Pop(self);
       
    44 	return self;
       
    45 	}
       
    46 	
       
    47 
       
    48 CTestCase0676::CTestCase0676(TBool aHost)
       
    49 :	CTestCaseRoot(KTestCaseId, aHost)
       
    50 	{
       
    51 	LOG_FUNC
       
    52 		
       
    53 	} 
       
    54 
       
    55 
       
    56 /**
       
    57  ConstructL
       
    58 */
       
    59 void CTestCase0676::ConstructL()
       
    60 	{
       
    61 	LOG_FUNC
       
    62 	iWDTimer = CTestCaseWatchdog::NewL();
       
    63 	iRepeats = OPEN_REPEATS;
       
    64 		
       
    65 	BaseConstructL();
       
    66 	}
       
    67 
       
    68 
       
    69 CTestCase0676::~CTestCase0676()
       
    70 	{
       
    71 	LOG_FUNC
       
    72 
       
    73 	Cancel();
       
    74 	delete iWDTimer;
       
    75 	
       
    76 	}
       
    77 
       
    78 
       
    79 void CTestCase0676::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 CTestCase0676::DoCancel()
       
    93 	{
       
    94 	LOG_FUNC
       
    95 
       
    96 	// cancel our timer
       
    97 	iTimer.Cancel();
       
    98 	}
       
    99 
       
   100 
       
   101 void CTestCase0676::CancelKB(CTestCaseRoot *pThis)
       
   102 	{
       
   103 	LOG_FUNC
       
   104 	CTestCase0676 * p = REINTERPRET_CAST(CTestCase0676 *,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 CTestCase0676::CancelNotify(CTestCaseRoot *pThis)
       
   112 	{
       
   113 	LOG_FUNC
       
   114 	CTestCase0676 * p = REINTERPRET_CAST(CTestCase0676 *,pThis);
       
   115 	// cancel any pending call, and then complete our active obj with a timeout value
       
   116 	p->otgCancelOtgVbusNotification();
       
   117 	p->SelfComplete(KTestCaseWatchdogTO);
       
   118 	}
       
   119 
       
   120 
       
   121 // This test result depends on all the ID detection tests and the VBus driving and dropping tests have not yet passed
       
   122 void CTestCase0676::DescribePreconditions()
       
   123 	{
       
   124 	test.Printf(_L("Insert 'A' connector beforehand.\n"));
       
   125 	}
       
   126 
       
   127 void CTestCase0676::ContinueAfter(TTimeIntervalMicroSeconds32 aMicroSecs, TCaseSteps aStep)
       
   128 	{
       
   129 	LOG_VERBOSE2(_L("Wait %dms before drop VBus"), (TInt)(aMicroSecs.Int()/1000));
       
   130 	iTimer.After(iStatus, aMicroSecs);
       
   131 	iCaseStep = aStep;
       
   132 	SetActive();
       
   133 	}
       
   134 
       
   135 // handle event completion	
       
   136 void CTestCase0676::RunStepL()
       
   137 	{
       
   138 	LOG_FUNC
       
   139 	// Obtain the completion code for this CActive obj.
       
   140 	TInt completionCode(iStatus.Int()); 
       
   141 	TBuf<MAX_DSTRLEN> aDescription;
       
   142 	TInt err(0);
       
   143 
       
   144 
       
   145 	switch(iCaseStep)
       
   146 		{
       
   147 		case EPreconditions:
       
   148 			iCaseStep = ELoadLdd;
       
   149 			if (iAutomated)
       
   150 				{
       
   151 				iCaseStep = ELoadLdd;
       
   152 				SelfComplete();
       
   153 				break;
       
   154 				}
       
   155 			// prompt to insert connector
       
   156 			test.Printf(KInsertAConnectorPrompt);
       
   157 			test.Printf(KPressAnyKeyToContinue);
       
   158 			RequestCharacter();			
       
   159 			break;
       
   160 			
       
   161 		case ELoadLdd:
       
   162 			// 1. load the LDD and init.
       
   163 			if (!StepLoadLDD())
       
   164 				{
       
   165 				break;
       
   166 				}
       
   167 			iCaseStep = EDetectAPlug;
       
   168 			SelfComplete();
       
   169 			break;
       
   170 			
       
   171 			// 2. detect 'A' plug now
       
   172 		case EDetectAPlug:
       
   173 			if (KTestCaseWatchdogTO == iStatus.Int())
       
   174 				{
       
   175 				return TestFailed(KErrAbort, _L("User response too slow - FAILED!"));
       
   176 				}
       
   177 
       
   178 			// if doing this test in /AUTO mode, we would fail this now
       
   179 			// however if we can control ID_PIN through an API in future, we turn in on now.
       
   180 			if (!otgIdPinPresent())
       
   181 				{
       
   182 				test.Printf(KInsertAConnectorPrompt);
       
   183 				test.Printf(KPressAnyKeyToContinue);
       
   184 				RequestCharacter();
       
   185 
       
   186 				iCaseStep = EDetectAPlug;
       
   187 				}
       
   188 			else
       
   189 				{
       
   190 				iCaseStep = ELoopDriveVBus;
       
   191 				SelfComplete();
       
   192 				}
       
   193 			break;
       
   194 			
       
   195 			// 3. Control/branch step in the loop
       
   196 		case ELoopControl:
       
   197 			if (--iRepeats)
       
   198 				{
       
   199 				iCaseStep = ELoopDriveVBus;
       
   200 				}
       
   201 			else
       
   202 				{
       
   203 				iCaseStep = EUnloadLdd;
       
   204 				}
       
   205 			SelfComplete();
       
   206 			break;
       
   207 			
       
   208 		case ELoopDriveVBus:
       
   209 			// 4. DRIVE VBUS
       
   210 			iWDTimer->Cancel();
       
   211 			test.Printf(_L("Drive VBus, iteration %d/%d\n"), OPEN_REPEATS-iRepeats+1, OPEN_REPEATS);
       
   212 			// test for VBus rise next
       
   213 			test.Printf(_L("Waiting for VBus Event\n"));
       
   214 			iStatus = KRequestPending;
       
   215 			otgQueueOtgVbusNotification( iOTGVBus, iStatus );
       
   216 
       
   217 			// turn on VBus, since the call is not a Queing a-sync call we do this after the async call
       
   218 			err = otgBusRequest();	// ok to turn on VBus now
       
   219 			if (KErrNone != err)
       
   220 				{
       
   221 				return TestFailed(KErrAbort, _L("Raise Vbus - RUsbOtgDriver::BusRequest() FAILED!"));
       
   222 				}
       
   223 			iCaseStep = ELoopVerifyVBus;
       
   224 			iWDTimer->IssueRequest(KDelayDurationForLocalTrigger, this, &CancelNotify);
       
   225 			SetActive();
       
   226 			break;
       
   227 			
       
   228 		case ELoopVerifyVBus:
       
   229 			// 5. get VBus rise event
       
   230 			if (KTestCaseWatchdogTO == iStatus.Int())
       
   231 				{
       
   232 				return TestFailed(KErrAbort, _L("Vbus rise not signalled in time - FAILED!"));
       
   233 				}
       
   234 			iWDTimer->Cancel();
       
   235 
       
   236 			otgQueueOtgVbusNotification( iOTGVBus, iStatus );
       
   237 			otgCancelOtgVbusNotification();
       
   238 			User::WaitForRequest(iStatus);
       
   239 
       
   240 
       
   241 			if (iOTGVBus != RUsbOtgDriver::EVbusHigh)
       
   242 				{
       
   243 		
       
   244 				return TestFailed(KErrAbort, _L("Vbus rise NOT 'seen' - FAILED!"));
       
   245 				}
       
   246 
       
   247 			// Double-check using the API in a syncronous way too
       
   248 			// NOTE: once again this is to explore timing issues
       
   249 			if (!otgVbusPresent())
       
   250 				{
       
   251 				return TestFailed(KErrAbort, _L("Vbus syncronous call error - FAILED!"));
       
   252 				}
       
   253 			iCaseStep = ELoopWait;
       
   254 			SelfComplete();
       
   255 			break;
       
   256 			
       
   257 		case ELoopWait:	// 6. wait 50ms after applying Vbus before we are allowed to 
       
   258 			ContinueAfter(KDelayBeforeBusDropUs, ELoopDropVBus);
       
   259 			break;
       
   260 			
       
   261 		case ELoopDropVBus:
       
   262 			// 7. drop Bus
       
   263 			otgQueueOtgVbusNotification(iOTGVBus, iStatus );
       
   264 			// drop Vbus now, since the call is not a Queing a-sync call we do this after the async call
       
   265 			otgBusDrop();
       
   266 			SetActive();
       
   267 			iCaseStep = ELoopVerifyDrop;
       
   268 			iWDTimer->IssueRequest(KDelayDurationForLocalTrigger, this, &CancelNotify);
       
   269 			break;
       
   270 			
       
   271 		case ELoopVerifyDrop:
       
   272 			// 8. get Vbus low event
       
   273 			if (KTestCaseWatchdogTO == iStatus.Int())
       
   274 				{
       
   275 				return TestFailed(KErrAbort, _L("Vbus drop not signalled in time - FAILED!"));
       
   276 				}
       
   277 			iWDTimer->Cancel();
       
   278 
       
   279 			// fetch the value			
       
   280 			otgQueueOtgVbusNotification( iOTGVBus, iStatus );
       
   281 			otgCancelOtgVbusNotification();
       
   282 			User::WaitForRequest(iStatus);
       
   283 
       
   284 			if (iOTGVBus != RUsbOtgDriver::EVbusLow)
       
   285 				{
       
   286 				return TestFailed(KErrAbort, _L("Vbus drop NOT 'seen' - FAILED!"));
       
   287 				}
       
   288 				
       
   289 			// test again using the 'syncronous' variation
       
   290 			if (otgVbusPresent())
       
   291 				{
       
   292 				return TestFailed(KErrAbort, _L("Vbus syncronous call error - FAILED!"));
       
   293 				}
       
   294 				
       
   295 			// wait 50ms and then go back to beginning
       
   296 			ContinueAfter(KDelayBeforeBusDropUs, ELoopControl);
       
   297 			break;
       
   298 			
       
   299 		case EUnloadLdd:
       
   300 			// 9. unload
       
   301 			if (EFalse == StepUnloadLDD())
       
   302 				return TestFailed(KErrAbort,_L("unload Ldd failure"));	
       
   303 			
       
   304 			iCaseStep = ELastStep;
       
   305 			SelfComplete();
       
   306 			break;
       
   307 			
       
   308 		case ELastStep:
       
   309 			TestPassed();
       
   310 			break;
       
   311 			
       
   312 		default:
       
   313 			test.Printf(_L("<Error> unknown test step"));
       
   314 			Cancel();
       
   315 			return (TestFailed(KErrCorrupt, _L("<Error> unknown test step")));
       
   316 		}
       
   317 	}
       
   318 
       
   319