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