kerneltest/e32test/usbho/t_otgdi/src/testcase0465.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 "testcase0465.h"
       
    27 
       
    28 
       
    29 
       
    30 
       
    31 // the name below is used to add a pointer to our construction method to a pointer MAP in 
       
    32 // the class factory
       
    33 _LIT(KTestCaseId,"PBASE-USB_OTGDI-0465");
       
    34 const TTestCaseFactoryReceipt<CTestCase0465> CTestCase0465::iFactoryReceipt(KTestCaseId);	
       
    35 
       
    36 CTestCase0465* CTestCase0465::NewL(TBool aHost)
       
    37 	{
       
    38 	LOG_FUNC
       
    39 	CTestCase0465* self = new (ELeave) CTestCase0465(aHost);
       
    40 	CleanupStack::PushL(self);
       
    41 	self->ConstructL();
       
    42 	CleanupStack::Pop(self);
       
    43 	return self;
       
    44 	}
       
    45 	
       
    46 
       
    47 CTestCase0465::CTestCase0465(TBool aHost)
       
    48 :	CTestCaseRoot(KTestCaseId, aHost)
       
    49 	{
       
    50 	LOG_FUNC
       
    51 		
       
    52 	} 
       
    53 
       
    54 
       
    55 /**
       
    56  ConstructL
       
    57 */
       
    58 void CTestCase0465::ConstructL()
       
    59 	{
       
    60 	LOG_FUNC
       
    61 	iWDTimer = CTestCaseWatchdog::NewL();
       
    62 	
       
    63 	BaseConstructL();
       
    64 	}
       
    65 
       
    66 
       
    67 CTestCase0465::~CTestCase0465()
       
    68 	{
       
    69 	LOG_FUNC
       
    70 
       
    71 	Cancel();
       
    72 	delete iWDTimer;
       
    73 	
       
    74 	}
       
    75 
       
    76 
       
    77 void CTestCase0465::ExecuteTestCaseL()
       
    78 	{
       
    79 	LOG_FUNC
       
    80 	iCaseStep = EPreconditions;
       
    81 	
       
    82 	iRepeats = KOperationRetriesMax;	// VBus event rise retries
       
    83 	
       
    84 	CActiveScheduler::Add(this);
       
    85 	SelfComplete();
       
    86 
       
    87 	}
       
    88 
       
    89 	
       
    90 void CTestCase0465::DoCancel()
       
    91 	{
       
    92 	LOG_FUNC
       
    93 
       
    94 	// cancel our timer
       
    95 	iTimer.Cancel();
       
    96 	}
       
    97 
       
    98 
       
    99 void CTestCase0465::CancelKB(CTestCaseRoot *pThis)
       
   100 	{
       
   101 	CTestCase0465 * p = REINTERPRET_CAST(CTestCase0465 *,pThis);
       
   102 	// cancel the pending call
       
   103 
       
   104 	p->iConsole->ReadCancel();
       
   105 
       
   106 	}
       
   107 
       
   108 
       
   109 void CTestCase0465::CancelDrive(CTestCaseRoot *pThis)
       
   110 	{
       
   111 	CTestCase0465 * p = REINTERPRET_CAST(CTestCase0465 *,pThis);
       
   112 	// cancel any pending call, and then complete our active obj with a timeout value
       
   113 	p->SelfComplete(KTestCaseWatchdogTO);	
       
   114 	}
       
   115 
       
   116 
       
   117 // This test result depends on all the ID detection tests and the VBus driving and dropping tests have not yet passed
       
   118 void CTestCase0465::DescribePreconditions()
       
   119 	{
       
   120 	test.Printf(_L("BEFORE running this test\n"));
       
   121 	test.Printf(_L("\n"));
       
   122 	test.Printf(_L("Insert 'A' connector\n"));
       
   123 	test.Printf(_L("\n"));
       
   124 	test.Printf(_L("Confirm passing tests\n"));
       
   125 	test.Printf(_L("\n"));
       
   126 	test.Printf(_L("ID_PIN detection\n"));
       
   127 	test.Printf(_L("VBus Driving\n"));
       
   128 	test.Printf(_L("\n"));
       
   129 	}
       
   130 		
       
   131 
       
   132 // handle event completion	
       
   133 void CTestCase0465::RunStepL()
       
   134 	{
       
   135 	LOG_FUNC
       
   136 	// Obtain the completion code for this CActive obj.
       
   137 	TInt completionCode(iStatus.Int()); 
       
   138 	TBuf<MAX_DSTRLEN> aDescription;
       
   139 	TInt err(0);
       
   140 		
       
   141 	switch(iCaseStep)
       
   142 		{
       
   143 		case EPreconditions:
       
   144 			iCaseStep = ELoadLdd;
       
   145 			if (iAutomated)
       
   146 				{
       
   147 				iCaseStep = ELoadLdd;
       
   148 				SelfComplete();
       
   149 				break;
       
   150 				}
       
   151 			// prompt to insert connector
       
   152 			test.Printf(_L("\n"));
       
   153 			test.Printf(KInsertAConnectorPrompt);
       
   154 			test.Printf(_L("\n"));
       
   155 			test.Printf(KPressAnyKeyToContinue);
       
   156 			test.Printf(_L("\n"));
       
   157 			RequestCharacter();			
       
   158 			break;
       
   159 			
       
   160 		case ELoadLdd:
       
   161 			// 1. load the LDD and init.
       
   162 			if (!StepLoadLDD())
       
   163 				{
       
   164 				break;
       
   165 				}
       
   166 			iCaseStep = EDriveVBus;
       
   167 			SelfComplete();
       
   168 			break;
       
   169 			
       
   170 		case EDriveVBus:
       
   171 			// 2. DRIVE VBUS
       
   172 			// wait for 100 ms to allow the stack time to settle
       
   173 			User::After(100000);
       
   174 			err = otgBusRequest();
       
   175 			if (KErrNone != err)
       
   176 				{
       
   177 				return TestFailed(KErrAbort, _L("Raise VBus - RUsbOtgDriver::BusRequest() FAILED!"));
       
   178 				}
       
   179 
       
   180 			// wait for 1000 ms as per test document
       
   181 			User::After(1000000);
       
   182 
       
   183 			// test for VBus rise next
       
   184 			otgQueueOtgEventRequest( iOTGEvent, iStatus );
       
   185 			SetActive();
       
   186 			iCaseStep = EVerifyVBus;
       
   187 			break;
       
   188 			
       
   189 		case EVerifyVBus:
       
   190 			// 3. get VBus rise event
       
   191 			iCaseStep = EUnloadLdd;
       
   192 			OtgEventString(iOTGEvent, aDescription);
       
   193 			test.Printf(_L("Received event %d '%S' status(%d)\n"), iOTGEvent, &aDescription, completionCode);
       
   194 			
       
   195 			if (iOTGEvent != RUsbOtgDriver::EEventVbusRaised)
       
   196 				{
       
   197 				iCaseStep = EVerifyVBus;
       
   198 				iRepeats--;
       
   199 				if (iRepeats <0)
       
   200 					{
       
   201 					return TestFailed(KErrAbort, _L("Raise VBus event not detected. FAILED!"));
       
   202 					}
       
   203 
       
   204 				otgQueueOtgEventRequest( iOTGEvent, iStatus );
       
   205 				SetActive();				
       
   206 				break;	
       
   207 				}
       
   208 			test.Printf(_L("VBus seen OK.\n"));
       
   209 			
       
   210 			SelfComplete();
       
   211 			break;
       
   212 			
       
   213 		case EUnloadLdd:
       
   214 			// unload
       
   215 			if (EFalse == StepUnloadLDD())
       
   216 				{
       
   217 				return TestFailed(KErrAbort,_L("unload Ldd failure"));	
       
   218 				}	
       
   219 			
       
   220 			// wait for 100 ms to allow the stack time to settle
       
   221 			User::After(100000);
       
   222 			
       
   223 			test.Printf(_L("Use meter or oscilloscope\n"));
       
   224 			test.Printf(_L("to measure VBUS, which should\n"));
       
   225 			test.Printf(_L("have dropped\n"));
       
   226 			test.Printf(_L("\n"));
       
   227 			test.Printf(_L("Is it below 0.2 volts?\n"));
       
   228 			test.Printf(_L("\n"));
       
   229 			test.Printf(_L("Select Y or N to continue\n"));
       
   230 			RequestCharacter();
       
   231 			iWDTimer->IssueRequest(KDelayDurationForUserActivityMS, this, &CancelKB);
       
   232 			iCaseStep = EVerifyBusGone;
       
   233 			break;
       
   234 			
       
   235 		case EVerifyBusGone:
       
   236 			// since the LDD is gone, there is no OTGDI API from here on
       
   237 			if (KTestCaseWatchdogTO == iStatus.Int())
       
   238 				{
       
   239 				return TestFailed(KErrAbort, _L("Operator response timeout"));
       
   240 				}
       
   241 			iWDTimer->Cancel();
       
   242 			// user intput
       
   243 			if (('y' == iKeyCodeInput) ||('Y' == iKeyCodeInput))
       
   244 				{
       
   245 				test.Printf(_L("VBUS 'drop' seen\n"));
       
   246 				SelfComplete();
       
   247 				}
       
   248 			else
       
   249 				{
       
   250 				return TestFailed(KErrAbort, _L("VBus drop NOT 'seen' - FAILED!"));
       
   251 				}
       
   252 			iCaseStep = ELastStep;
       
   253 			break;
       
   254 			
       
   255 		case ELastStep:
       
   256 			TestPassed();
       
   257 			break;
       
   258 			
       
   259 		default:
       
   260 			test.Printf(_L("<Error> unknown test step\n"));
       
   261 			Cancel();
       
   262 			return (TestFailed(KErrCorrupt, _L("<Error> unknown test step")));
       
   263 		}
       
   264 	}
       
   265 
       
   266