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