os/kernelhwsrv/kerneltest/e32test/usbho/t_otgdi/src/testcase0468.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/kernelhwsrv/kerneltest/e32test/usbho/t_otgdi/src/testcase0468.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,321 @@
     1.4 +// Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.5 +// All rights reserved.
     1.6 +// This component and the accompanying materials are made available
     1.7 +// under the terms of the License "Eclipse Public License v1.0"
     1.8 +// which accompanies this distribution, and is available
     1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.10 +//
    1.11 +// Initial Contributors:
    1.12 +// Nokia Corporation - initial contribution.
    1.13 +//
    1.14 +// Contributors:
    1.15 +//
    1.16 +// Description:
    1.17 +// @internalComponent
    1.18 +// 
    1.19 +//
    1.20 +
    1.21 +#include <e32std.h>
    1.22 +#include <e32std_private.h>
    1.23 +#include <u32std.h> 	// unicode builds
    1.24 +#include <e32base.h>
    1.25 +#include <e32base_private.h>
    1.26 +#include <e32Test.h>	// RTest headder
    1.27 +#include "testcaseroot.h"
    1.28 +#include "testcasewd.h"
    1.29 +#include "testcase0468.h"
    1.30 +
    1.31 +#define _REPEATS (oOpenIterations*3)
    1.32 +
    1.33 +
    1.34 +
    1.35 +// the name below is used to add a pointer to our construction method to a pointer MAP in 
    1.36 +// the class factory
    1.37 +_LIT(KTestCaseId,"PBASE-USB_OTGDI-0468");
    1.38 +const TTestCaseFactoryReceipt<CTestCase0468> CTestCase0468::iFactoryReceipt(KTestCaseId);	
    1.39 +
    1.40 +CTestCase0468* CTestCase0468::NewL(TBool aHost)
    1.41 +	{
    1.42 +	LOG_FUNC
    1.43 +	CTestCase0468* self = new (ELeave) CTestCase0468(aHost);
    1.44 +	CleanupStack::PushL(self);
    1.45 +	self->ConstructL();
    1.46 +	CleanupStack::Pop(self);
    1.47 +	return self;
    1.48 +	}
    1.49 +	
    1.50 +
    1.51 +CTestCase0468::CTestCase0468(TBool aHost)
    1.52 +:	CTestCaseRoot(KTestCaseId, aHost)
    1.53 +	{
    1.54 +	LOG_FUNC
    1.55 +		
    1.56 +	} 
    1.57 +
    1.58 +
    1.59 +/**
    1.60 + ConstructL
    1.61 +*/
    1.62 +void CTestCase0468::ConstructL()
    1.63 +	{
    1.64 +	LOG_FUNC
    1.65 +	iWDTimer = CTestCaseWatchdog::NewL();
    1.66 +	iRepeats = OPEN_REPEATS;
    1.67 +		
    1.68 +	BaseConstructL();
    1.69 +	}
    1.70 +
    1.71 +
    1.72 +CTestCase0468::~CTestCase0468()
    1.73 +	{
    1.74 +	LOG_FUNC
    1.75 +
    1.76 +	Cancel();
    1.77 +	delete iWDTimer;
    1.78 +	
    1.79 +	}
    1.80 +
    1.81 +
    1.82 +void CTestCase0468::ExecuteTestCaseL()
    1.83 +	{
    1.84 +	LOG_FUNC
    1.85 +	iCaseStep = EPreconditions;
    1.86 +	
    1.87 +	iRepeats = KOperationRetriesMax;	// VBus event rise retries
    1.88 +	
    1.89 +	CActiveScheduler::Add(this);
    1.90 +	SelfComplete();
    1.91 +
    1.92 +	}
    1.93 +
    1.94 +	
    1.95 +void CTestCase0468::DoCancel()
    1.96 +	{
    1.97 +	LOG_FUNC
    1.98 +
    1.99 +	// cancel our timer
   1.100 +	iTimer.Cancel();
   1.101 +	}
   1.102 +
   1.103 +
   1.104 +void CTestCase0468::CancelKB(CTestCaseRoot *pThis)
   1.105 +	{
   1.106 +	LOG_FUNC
   1.107 +	CTestCase0468 * p = REINTERPRET_CAST(CTestCase0468 *,pThis);
   1.108 +	// cancel any pending call, and then complete our active obj with a cancel value
   1.109 +	p->iConsole->ReadCancel();
   1.110 +
   1.111 +	}
   1.112 +
   1.113 +
   1.114 +void CTestCase0468::CancelNotify(CTestCaseRoot *pThis)
   1.115 +	{
   1.116 +	LOG_FUNC
   1.117 +	CTestCase0468 * p = REINTERPRET_CAST(CTestCase0468 *,pThis);
   1.118 +	// cancel any pending call, and then complete our active obj with a timeout value
   1.119 +	p->otgCancelOtgVbusNotification();
   1.120 +	p->SelfComplete(KTestCaseWatchdogTO);
   1.121 +	}
   1.122 +
   1.123 +
   1.124 +// This test result depends on all the ID detection tests and the VBus driving and dropping tests have not yet passed
   1.125 +void CTestCase0468::DescribePreconditions()
   1.126 +	{
   1.127 +	test.Printf(_L("Insert 'A' connector beforehand.\n"));
   1.128 +	test.Printf(_L("ID_PIN detection and VBus driving tests must already pass.\n"));
   1.129 +	}
   1.130 +
   1.131 +void CTestCase0468::ContinueAfter(TTimeIntervalMicroSeconds32 aMicroSecs, TCaseSteps aStep)
   1.132 +	{
   1.133 +	LOG_VERBOSE2(_L("Wait %dms before drop VBus"), (TInt)(aMicroSecs.Int()/1000));
   1.134 +	iTimer.After(iStatus, aMicroSecs);
   1.135 +	iCaseStep = aStep;
   1.136 +	SetActive();
   1.137 +	}
   1.138 +
   1.139 +// handle event completion	
   1.140 +void CTestCase0468::RunStepL()
   1.141 +	{
   1.142 +	LOG_FUNC
   1.143 +	// Obtain the completion code for this CActive obj.
   1.144 +	TInt completionCode(iStatus.Int()); 
   1.145 +	TBuf<MAX_DSTRLEN> aDescription;
   1.146 +	TInt err(0);
   1.147 +
   1.148 +
   1.149 +	switch(iCaseStep)
   1.150 +		{
   1.151 +		case EPreconditions:
   1.152 +			iCaseStep = ELoadLdd;
   1.153 +			if (iAutomated)
   1.154 +				{
   1.155 +				iCaseStep = ELoadLdd;
   1.156 +				SelfComplete();
   1.157 +				break;
   1.158 +				}
   1.159 +			// prompt to insert connector
   1.160 +			test.Printf(KInsertAConnectorPrompt);
   1.161 +			test.Printf(KPressAnyKeyToContinue);
   1.162 +			RequestCharacter();			
   1.163 +			break;
   1.164 +			
   1.165 +		case ELoadLdd:
   1.166 +			// 1. load the LDD and init.
   1.167 +			if (!StepLoadLDD())
   1.168 +				{
   1.169 +				break;
   1.170 +				}
   1.171 +			iCaseStep = EDetectAPlug;
   1.172 +			SelfComplete();
   1.173 +			break;
   1.174 +			
   1.175 +			// 2. detect 'A' plug now
   1.176 +		case EDetectAPlug:
   1.177 +			if (KTestCaseWatchdogTO == iStatus.Int())
   1.178 +				{
   1.179 +				return TestFailed(KErrAbort, _L("User response too slow - FAILED!"));
   1.180 +				}
   1.181 +
   1.182 +			// if doing this test in /AUTO mode, we would fail this now
   1.183 +			// however if we can control ID_PIN through an API in future, we turn in on now.
   1.184 +			if (!otgIdPinPresent())
   1.185 +				{
   1.186 +				test.Printf(KInsertAConnectorPrompt);
   1.187 +				test.Printf(KPressAnyKeyToContinue);
   1.188 +				RequestCharacter();
   1.189 +
   1.190 +				iCaseStep = EDetectAPlug;
   1.191 +				}
   1.192 +			else
   1.193 +				{
   1.194 +				iCaseStep = ELoopDriveVBus;
   1.195 +				SelfComplete();
   1.196 +				}
   1.197 +			break;
   1.198 +			
   1.199 +			// 3. Control/branch step in the loop
   1.200 +		case ELoopControl:
   1.201 +			if (--iRepeats)
   1.202 +				{
   1.203 +				iCaseStep = ELoopDriveVBus;
   1.204 +				}
   1.205 +			else
   1.206 +				{
   1.207 +				iCaseStep = EUnloadLdd;
   1.208 +				}
   1.209 +			SelfComplete();
   1.210 +			break;
   1.211 +			
   1.212 +		case ELoopDriveVBus:
   1.213 +			// 4. DRIVE VBUS
   1.214 +			iWDTimer->Cancel();
   1.215 +			test.Printf(_L("Drive VBus, iteration %d/%d\n"), OPEN_REPEATS-iRepeats+1, OPEN_REPEATS);
   1.216 +			// test for VBus rise next
   1.217 +			test.Printf(_L("Waiting for VBus Event\n"));
   1.218 +			iStatus = KRequestPending;
   1.219 +			otgQueueOtgVbusNotification( iOTGVBus, iStatus );
   1.220 +
   1.221 +			// turn on VBus, since the call is not a Queing a-sync call we do this after the async call
   1.222 +			err = otgBusRequest();	// ok to turn on VBus now
   1.223 +			if (KErrNone != err)
   1.224 +				{
   1.225 +				return TestFailed(KErrAbort, _L("Raise Vbus - RUsbOtgDriver::BusRequest() FAILED!"));
   1.226 +				}
   1.227 +			iCaseStep = ELoopVerifyVBus;
   1.228 +			iWDTimer->IssueRequest(KDelayDurationForLocalTrigger, this, &CancelNotify);
   1.229 +			SetActive();
   1.230 +			break;
   1.231 +			
   1.232 +		case ELoopVerifyVBus:
   1.233 +			// 5. get VBus rise event
   1.234 +			LOG_VERBOSE2(_L("Post notification val=%d\n\n"), iOTGVBus);
   1.235 +			if (KTestCaseWatchdogTO == iStatus.Int())
   1.236 +				{
   1.237 +				return TestFailed(KErrAbort, _L("Vbus rise not signalled in time - FAILED!"));
   1.238 +				}
   1.239 +			iWDTimer->Cancel();
   1.240 +
   1.241 +			// fetch the current value
   1.242 +			otgQueueOtgVbusNotification( iOTGVBus, iStatus );
   1.243 +			otgCancelOtgVbusNotification();
   1.244 +			User::WaitForRequest(iStatus);
   1.245 +
   1.246 +			if (iOTGVBus != RUsbOtgDriver::EVbusHigh)
   1.247 +				{
   1.248 +		
   1.249 +				return TestFailed(KErrAbort, _L("Vbus rise NOT 'seen' - FAILED!"));
   1.250 +				}
   1.251 +
   1.252 +			// Double-check using the API in a syncronous way too
   1.253 +			// NOTE: once again this is to explore timing issues
   1.254 +			if (!otgVbusPresent())
   1.255 +				{
   1.256 +				return TestFailed(KErrAbort, _L("Vbus syncronous call error - FAILED!"));
   1.257 +				}
   1.258 +			iCaseStep = ELoopWait;
   1.259 +			SelfComplete();
   1.260 +			break;
   1.261 +			
   1.262 +		case ELoopWait:	// 6. wait 50ms after applying Vbus before we are allowed to 
   1.263 +			ContinueAfter(KDelayBeforeBusDropUs, ELoopDropVBus);
   1.264 +			break;
   1.265 +			
   1.266 +		case ELoopDropVBus:
   1.267 +			// 7. drop Bus
   1.268 +			otgQueueOtgVbusNotification(iOTGVBus, iStatus );
   1.269 +			// drop Vbus now, since the call is not a Queing a-sync call we do this after the async call
   1.270 +			otgBusDrop();
   1.271 +			SetActive();
   1.272 +			iCaseStep = ELoopVerifyDrop;
   1.273 +			iWDTimer->IssueRequest(KDelayDurationForLocalTrigger, this, &CancelNotify);
   1.274 +			break;
   1.275 +			
   1.276 +		case ELoopVerifyDrop:
   1.277 +			// 8. get Vbus low event
   1.278 +			if (KTestCaseWatchdogTO == iStatus.Int())
   1.279 +				{
   1.280 +				return TestFailed(KErrAbort, _L("Vbus drop not signalled in time - FAILED!"));
   1.281 +				}
   1.282 +			iWDTimer->Cancel();
   1.283 +
   1.284 +			// fetch the value			
   1.285 +			otgQueueOtgVbusNotification( iOTGVBus, iStatus );
   1.286 +			otgCancelOtgVbusNotification();
   1.287 +			User::WaitForRequest(iStatus);
   1.288 +
   1.289 +			if (iOTGVBus != RUsbOtgDriver::EVbusLow)
   1.290 +				{
   1.291 +				return TestFailed(KErrAbort, _L("Vbus drop NOT 'seen' - FAILED!"));
   1.292 +				}
   1.293 +				
   1.294 +			// test again using the 'syncronous' variation
   1.295 +			if (otgVbusPresent())
   1.296 +				{
   1.297 +				return TestFailed(KErrAbort, _L("Vbus syncronous call error - FAILED!"));
   1.298 +				}
   1.299 +				
   1.300 +			// wait 50ms and then go back to beginning
   1.301 +			ContinueAfter(KDelayBeforeBusDropUs, ELoopControl);
   1.302 +			break;
   1.303 +			
   1.304 +		case EUnloadLdd:
   1.305 +			// 9. unload
   1.306 +			if (EFalse == StepUnloadLDD())
   1.307 +				return TestFailed(KErrAbort,_L("unload Ldd failure"));	
   1.308 +			
   1.309 +			iCaseStep = ELastStep;
   1.310 +			SelfComplete();
   1.311 +			break;
   1.312 +			
   1.313 +		case ELastStep:
   1.314 +			TestPassed();
   1.315 +			break;
   1.316 +			
   1.317 +		default:
   1.318 +			test.Printf(_L("<Error> unknown test step"));
   1.319 +			Cancel();
   1.320 +			return (TestFailed(KErrCorrupt, _L("<Error> unknown test step")));
   1.321 +		}
   1.322 +	}
   1.323 +
   1.324 +