os/kernelhwsrv/kerneltest/e32test/usbho/t_otgdi/src/testcase0461.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 // CTestCase0461.cpp
    15 // @internalComponent
    16 // 
    17 //
    18 
    19 #include <e32std.h>
    20 #include <e32std_private.h>
    21 #include <u32std.h> 	// unicode builds
    22 #include <e32base.h>
    23 #include <e32base_private.h>
    24 #include <e32Test.h>	// RTest headder
    25 #include "testcaseroot.h"
    26 #include "testcasewd.h"
    27 #include "testcase0461.h"
    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-0461");
    34 const TTestCaseFactoryReceipt<CTestCase0461> CTestCase0461::iFactoryReceipt(KTestCaseId);	
    35 
    36 CTestCase0461* CTestCase0461::NewL(TBool aHost)
    37 	{
    38 	LOG_FUNC
    39 	CTestCase0461* self = new (ELeave) CTestCase0461(aHost);
    40 	CleanupStack::PushL(self);
    41 	self->ConstructL();
    42 	CleanupStack::Pop(self);
    43 	return self;
    44 	}
    45 	
    46 
    47 CTestCase0461::CTestCase0461(TBool aHost)
    48 :	CTestCaseRoot(KTestCaseId, aHost)
    49 	{
    50 	LOG_FUNC
    51 		
    52 	} 
    53 
    54 
    55 /**
    56  ConstructL
    57 */
    58 void CTestCase0461::ConstructL()
    59 	{
    60 	LOG_FUNC
    61 	iRepeats = KOperationRetriesMax;
    62 	BaseConstructL();
    63 	
    64 	iWDTimer = CTestCaseWatchdog::NewL();
    65 	}
    66 
    67 
    68 CTestCase0461::~CTestCase0461()
    69 	{
    70 	LOG_FUNC
    71 
    72 	Cancel();
    73 	delete iWDTimer;
    74 	}
    75 
    76 
    77 void CTestCase0461::ExecuteTestCaseL()
    78 	{
    79 	LOG_FUNC
    80 	iCaseStep = ELoadLdd;
    81 	
    82 	CActiveScheduler::Add(this);
    83 	SelfComplete();
    84 
    85 	}
    86 
    87 
    88 void CTestCase0461::DescribePreconditions()
    89 	{
    90 	test.Printf(_L("Insert 'A' connector beforehand.\n"));
    91 	}
    92 
    93 	
    94 void CTestCase0461::DoCancel()
    95 	{
    96 	LOG_FUNC
    97 
    98 	// cancel our timer
    99 	iTimer.Cancel();
   100 	}
   101 	
   102 void CTestCase0461::CancelKB(CTestCaseRoot *pThis)
   103 	{
   104 	CTestCase0461 * p = REINTERPRET_CAST(CTestCase0461 *,pThis);
   105 	// cancel any pending call, and then complete our active obj with a timeout value
   106 
   107 	p->iConsole->ReadCancel();
   108 	
   109 	}	
   110 
   111 // handle event completion	
   112 void CTestCase0461::RunStepL()
   113 	{
   114 	LOG_FUNC
   115 	// Obtain the completion code for this CActive obj.
   116 	TInt completionCode(iStatus.Int()); 
   117 	TBuf<MAX_DSTRLEN> aDescription;
   118 		
   119 	switch(iCaseStep)
   120 		{
   121 		case EPreconditions:
   122 			iCaseStep = ELoadLdd;
   123 			if (iAutomated)
   124 				{
   125 				iCaseStep = ELoadLdd;
   126 				SelfComplete();
   127 				break;
   128 				}
   129 			// prompt to insert connector
   130 			test.Printf(KInsertAConnectorPrompt);
   131 			test.Printf(KPressAnyKeyToContinue);
   132 			RequestCharacter();			
   133 			break;
   134 			
   135 		case ELoadLdd:
   136 			if (!StepLoadLDD())
   137 				{
   138 				break;
   139 				}
   140 
   141 			iCaseStep = ERegisterForEvents;
   142 			SelfComplete();
   143 			iDequeAttempts = 0;	
   144 			break;
   145 			
   146 			// 2. Prepare to wait on ID_PIN
   147 		case ERegisterForEvents:
   148 			// prompt to remove connector
   149 			test.Printf(KRemoveAConnectorPrompt);		
   150 			if (iDequeAttempts > 3)
   151 				{
   152 				return (TestFailed(KErrCorrupt, _L("<Error> too many irrelevant/incorrect events")));
   153 				}
   154 
   155 			otgQueueOtgEventRequest( iOTGEvent, iStatus);
   156 			iIDcheckStart.HomeTime();
   157 			iCaseStep = EGetAndCancelEvent;
   158 			SetActive();
   159 			break;
   160 			
   161 			// 3. pick up events already buffered when we start
   162 		case EEmptyQueue:
   163 			{
   164 			
   165 			TInt aMillisec;
   166 			iIDcheckEnd.HomeTime();
   167 			TTimeIntervalMicroSeconds ivlMicro(iIDcheckEnd.MicroSecondsFrom(iIDcheckStart));
   168 			aMillisec = (TInt)(ivlMicro.Int64())/1000;	// USB times are in uSec, but in ms for the user layer
   169 			iCaseStep = EGetAndCancelEvent;
   170 			// test if too quick!
   171 			if ((aMillisec < KDelayDurationForQEmpty) &&(!gSemiAutomated)) // use 200ms - clocked at 17ms
   172 				{
   173 				iCaseStep = ERegisterForEvents;
   174 				iDequeAttempts++;
   175 				SelfComplete();
   176 				break;
   177 				}
   178 			}// drop through to next step
   179 		case EGetAndCancelEvent: //4.
   180 			OtgEventString(iOTGEvent, aDescription);
   181 			test.Printf(_L("Received event %d '%S' status(%d)"), iOTGEvent, &aDescription, completionCode);
   182 			if (RUsbOtgDriver::EEventAPlugRemoved == iOTGEvent)
   183 				{
   184 				otgQueueOtgEventRequest( iOTGEvent, iStatus);
   185 				// cancel it and then go into a loop
   186 				otgCancelOtgEventRequest();
   187 				// swallow the cancelation now
   188 				User::WaitForRequest(iStatus);
   189 
   190 				iCaseStep = ECancelNotify;
   191 				}
   192 			else
   193 				{			
   194 				// wrong event in the Q already, keep at it
   195 				iCaseStep = ERegisterForEvents;	
   196 				iDequeAttempts++;
   197 				}
   198 			SelfComplete();
   199 			break;
   200 			
   201 			// 5. prepare to go into a loop
   202 		case ECancelNotify:  // insert 'A'
   203 			iRepeats = 3;	// #times to insert+remove
   204 			iExpectedEvents = 0;
   205 			iEventsInQueue = 0;
   206 			iCaseStep = EInsertA;
   207 			SelfComplete();
   208 			break;
   209 			
   210 			// 6
   211 		case EInsertA: // insert 'A' plug
   212 			iWDTimer->Cancel();
   213 			iConsole->ReadCancel();
   214 			test.Printf(KInsertAConnectorPrompt);
   215 			iCaseStep = ERemoveA;
   216 			test.Printf(KPressAnyKeyToContinue);
   217 			
   218 			RequestCharacter();
   219 			iWDTimer->IssueRequest(KDelayDurationForUserActivityMS, this, &CancelKB);			
   220 
   221 			iExpectedEvents++;
   222 			break;
   223 			
   224 			// 7. remove 'A' plug
   225 		case ERemoveA:
   226 			iWDTimer->Cancel();
   227 			iConsole->ReadCancel();
   228 			test.Printf(KRemoveAConnectorPrompt);
   229 			if (iRepeats-- >0)
   230 				{
   231 				// Do it again please
   232 				iCaseStep = EInsertA;
   233 				}
   234 			else
   235 				{ // got enough events in Q, let's count them up
   236 				iCaseStep = ETallyEvents;
   237 				}
   238 			test.Printf(KPressAnyKeyToContinue);
   239 
   240 			RequestCharacter();			
   241 			iWDTimer->IssueRequest(KDelayDurationForUserActivityMS, this, &CancelKB);			
   242 			iExpectedEvents++;
   243 			break;
   244 			
   245 			// 8.
   246 		case ETallyEvents:
   247 			// Getting here tests if the object does not get double-signalled.
   248 			// a stray signal anywhere would Panic the scheduler when we self complete
   249 			iCaseStep = ETallyNewEvent;
   250 			iStatus = KRequestPending;
   251 			otgQueueOtgEventRequest( iOTGEvent, iStatus);
   252 			SetActive();
   253 			break;
   254 			// 9.
   255 		case ETallyNewEvent:
   256 			iEventsInQueue++;	// got one, add it
   257 			if (iExpectedEvents == iEventsInQueue)
   258 				{
   259 				iCaseStep = EUnloadLdd;	
   260 				}
   261 			else
   262 				{
   263 				iCaseStep = ETallyEvents;
   264 				}
   265 			SelfComplete();
   266 			break;
   267 			
   268 		case EUnloadLdd:
   269 		case ELastStep:
   270 			if (EFalse == StepUnloadLDD())
   271 				return TestFailed(KErrAbort,_L("unload Ldd failure"));	
   272 			
   273 			return TestPassed();
   274 
   275 		default:
   276 			test.Printf(_L("<Error> unknown test step"));
   277 			Cancel();
   278 			return (TestFailed(KErrCorrupt, _L("<Error> unknown test step")));
   279 
   280 		}
   281 	}
   282 
   283