os/kernelhwsrv/kerneltest/e32test/usbho/t_otgdi/src/testcase0467.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
// @internalComponent
sl@0
    15
// 
sl@0
    16
//
sl@0
    17
sl@0
    18
#include <e32std.h>
sl@0
    19
#include <e32std_private.h>
sl@0
    20
#include <u32std.h> 	// unicode builds
sl@0
    21
#include <e32base.h>
sl@0
    22
#include <e32base_private.h>
sl@0
    23
#include <e32Test.h>	// RTest headder
sl@0
    24
#include "testcaseroot.h"
sl@0
    25
#include "testcasewd.h"
sl@0
    26
#include "testcase0467.h"
sl@0
    27
sl@0
    28
sl@0
    29
sl@0
    30
// # times to repeat the steps (default=3)
sl@0
    31
#define INSERT_REPEATS		gOpenIterations
sl@0
    32
sl@0
    33
// the name below is used to add a pointer to our construction method to a pointer MAP in 
sl@0
    34
// the class factory
sl@0
    35
_LIT(KTestCaseId,"PBASE-USB_OTGDI-0467");
sl@0
    36
const TTestCaseFactoryReceipt<CTestCase0467> CTestCase0467::iFactoryReceipt(KTestCaseId);	
sl@0
    37
sl@0
    38
CTestCase0467* CTestCase0467::NewL(TBool aHost)
sl@0
    39
	{
sl@0
    40
	LOG_FUNC
sl@0
    41
	CTestCase0467* self = new (ELeave) CTestCase0467(aHost);
sl@0
    42
	CleanupStack::PushL(self);
sl@0
    43
	self->ConstructL();
sl@0
    44
	CleanupStack::Pop(self);
sl@0
    45
	return self;
sl@0
    46
	}
sl@0
    47
	
sl@0
    48
sl@0
    49
CTestCase0467::CTestCase0467(TBool aHost)
sl@0
    50
:	CTestCaseRoot(KTestCaseId, aHost)
sl@0
    51
	{
sl@0
    52
	LOG_FUNC
sl@0
    53
		
sl@0
    54
	} 
sl@0
    55
sl@0
    56
sl@0
    57
/**
sl@0
    58
 ConstructL
sl@0
    59
*/
sl@0
    60
void CTestCase0467::ConstructL()
sl@0
    61
	{
sl@0
    62
	LOG_FUNC
sl@0
    63
	iRepeats = INSERT_REPEATS;
sl@0
    64
	iWDTimer = CTestCaseWatchdog::NewL();
sl@0
    65
	
sl@0
    66
	BaseConstructL();
sl@0
    67
	}
sl@0
    68
sl@0
    69
sl@0
    70
CTestCase0467::~CTestCase0467()
sl@0
    71
	{
sl@0
    72
	LOG_FUNC
sl@0
    73
sl@0
    74
	Cancel();
sl@0
    75
	delete iWDTimer;
sl@0
    76
	
sl@0
    77
	}
sl@0
    78
sl@0
    79
sl@0
    80
void CTestCase0467::ExecuteTestCaseL()
sl@0
    81
	{
sl@0
    82
	LOG_FUNC
sl@0
    83
	iCaseStep = EPreconditions;
sl@0
    84
	
sl@0
    85
	iRepeats = KOperationRetriesMax;	// VBus event rise retries
sl@0
    86
	
sl@0
    87
	CActiveScheduler::Add(this);
sl@0
    88
	SelfComplete();
sl@0
    89
sl@0
    90
	}
sl@0
    91
sl@0
    92
	
sl@0
    93
void CTestCase0467::DoCancel()
sl@0
    94
	{
sl@0
    95
	LOG_FUNC
sl@0
    96
sl@0
    97
	// cancel our timer
sl@0
    98
	iTimer.Cancel();
sl@0
    99
	}
sl@0
   100
sl@0
   101
sl@0
   102
void CTestCase0467::CancelKB(CTestCaseRoot *pThis)
sl@0
   103
	{
sl@0
   104
	CTestCase0467 * p = REINTERPRET_CAST(CTestCase0467 *,pThis);
sl@0
   105
	// cancel the pending call
sl@0
   106
sl@0
   107
	p->iConsole->ReadCancel();
sl@0
   108
sl@0
   109
	}
sl@0
   110
sl@0
   111
sl@0
   112
void CTestCase0467::CancelIdPin(CTestCaseRoot *pThis)
sl@0
   113
	{
sl@0
   114
	LOG_FUNC
sl@0
   115
	
sl@0
   116
	CTestCase0467 * p = REINTERPRET_CAST(CTestCase0467 *,pThis);
sl@0
   117
	// cancel any pending call, and then complete our active obj with a timeout value
sl@0
   118
	p->otgCancelOtgIdPinNotification();
sl@0
   119
	p->SelfComplete(KTestCaseWatchdogTO);	
sl@0
   120
	}
sl@0
   121
sl@0
   122
sl@0
   123
// This test result depends on all the ID detection tests and the VBus driving and dropping tests have not yet passed
sl@0
   124
void CTestCase0467::DescribePreconditions()
sl@0
   125
	{
sl@0
   126
	test.Printf(_L("Remove 'A' connector beforehand.\n"));
sl@0
   127
	test.Printf(_L("ID_PIN detection and VBus driving tests must already pass.\n"));
sl@0
   128
	}
sl@0
   129
		
sl@0
   130
sl@0
   131
// handle event completion	
sl@0
   132
void CTestCase0467::RunStepL()
sl@0
   133
	{
sl@0
   134
	LOG_FUNC
sl@0
   135
	// Obtain the completion code for this CActive obj.
sl@0
   136
	TInt completionCode(iStatus.Int()); 
sl@0
   137
	TBuf<MAX_DSTRLEN> aDescription;
sl@0
   138
sl@0
   139
	switch(iCaseStep)
sl@0
   140
		{
sl@0
   141
		case EPreconditions:
sl@0
   142
			iCaseStep = ELoadLdd;
sl@0
   143
			if (iAutomated)
sl@0
   144
				{
sl@0
   145
				iCaseStep = ELoadLdd;
sl@0
   146
				SelfComplete();
sl@0
   147
				break;
sl@0
   148
				}
sl@0
   149
			// prompt to remove connector
sl@0
   150
			test.Printf(KRemoveAConnectorPrompt);
sl@0
   151
			test.Printf(KPressAnyKeyToContinue);
sl@0
   152
			RequestCharacter();			
sl@0
   153
			break;
sl@0
   154
			
sl@0
   155
		case ELoadLdd:
sl@0
   156
			// 1. load the LDD and init.
sl@0
   157
			if (!StepLoadLDD())
sl@0
   158
				{
sl@0
   159
				break;
sl@0
   160
				}
sl@0
   161
			// initialize variables for loop control
sl@0
   162
			
sl@0
   163
			iCaseStep = EWaitForIDPresent;
sl@0
   164
			SelfComplete();
sl@0
   165
			break;
sl@0
   166
			
sl@0
   167
		case ERepeatLoop: // 2
sl@0
   168
			test.Printf(_L("Repeat test %d/%d\n"), INSERT_REPEATS-iRepeats+1, INSERT_REPEATS);
sl@0
   169
sl@0
   170
			if (--iRepeats)
sl@0
   171
				iCaseStep = EWaitForIDPresent;
sl@0
   172
			else
sl@0
   173
				iCaseStep = EUnloadLdd;
sl@0
   174
			SelfComplete();	
sl@0
   175
			break;
sl@0
   176
			
sl@0
   177
		case EWaitForIDPresent:
sl@0
   178
			// 3. prompt for insertion
sl@0
   179
			test.Printf(KInsertAConnectorPrompt);
sl@0
   180
			otgQueueOtgIdPinNotification( iOTGIdPin, iStatus );
sl@0
   181
sl@0
   182
			SetActive();
sl@0
   183
			iCaseStep = EVerifyIDPresent;
sl@0
   184
			iDetectionRetry = 0;
sl@0
   185
			break;
sl@0
   186
			
sl@0
   187
		case EVerifyIDPresent:
sl@0
   188
			// 4. detect id_pin event
sl@0
   189
			LOG_VERBOSE1(_L("STEP4 - detect id_pin event 'A'\n"));
sl@0
   190
sl@0
   191
			// retrieve the current ID_PIN value
sl@0
   192
			otgQueueOtgIdPinNotification( iOTGIdPin, iStatus );
sl@0
   193
			otgCancelOtgIdPinNotification();
sl@0
   194
			User::WaitForRequest(iStatus); // swallow the cancellation event (serves to test that it does cancel)
sl@0
   195
sl@0
   196
sl@0
   197
			if (iOTGIdPin != RUsbOtgDriver::EIdPinAPlug)
sl@0
   198
				{
sl@0
   199
				if (iDetectionRetry++ < 3)
sl@0
   200
					{
sl@0
   201
					iCaseStep = EVerifyIDPresent;
sl@0
   202
					otgQueueOtgIdPinNotification( iOTGIdPin, iStatus );
sl@0
   203
sl@0
   204
					SetActive();
sl@0
   205
					break;
sl@0
   206
					}
sl@0
   207
				else
sl@0
   208
					{
sl@0
   209
					return TestFailed(KErrAbort, _L("ID_PIN NOT 'seen' - FAILED!"));
sl@0
   210
					}
sl@0
   211
				}
sl@0
   212
				
sl@0
   213
			// check using the API in a syncronous way too
sl@0
   214
			// NOTE: we test this twice to explore and expose timing problems
sl@0
   215
			if (!otgIdPinPresent())
sl@0
   216
				{
sl@0
   217
				return TestFailed(KErrAbort, _L("ID_PIN syncronous call error - FAILED!"));
sl@0
   218
				}
sl@0
   219
			iCaseStep = EWaitForIDGone;
sl@0
   220
			SelfComplete();
sl@0
   221
			iDetectionRetry = 0;
sl@0
   222
			break;
sl@0
   223
			
sl@0
   224
		case EWaitForIDGone: 
sl@0
   225
			// 5. prompt for insertion
sl@0
   226
			test.Printf(KRemoveAConnectorPrompt);
sl@0
   227
			otgQueueOtgIdPinNotification( iOTGIdPin, iStatus );
sl@0
   228
			SetActive();
sl@0
   229
			iCaseStep = EVerifyIDGone;
sl@0
   230
			break;
sl@0
   231
			
sl@0
   232
		case EVerifyIDGone:
sl@0
   233
			// 6. detect id_pin gone event
sl@0
   234
			LOG_VERBOSE1(_L("STEP4 - detect id_pin remove event 'B'\n"));
sl@0
   235
			test.Printf(_L("ID_PIN=%d\n"), iOTGIdPin);
sl@0
   236
sl@0
   237
			User::After(5000); // 5ms
sl@0
   238
			otgQueueOtgIdPinNotification( iOTGIdPin, iStatus );
sl@0
   239
			otgCancelOtgIdPinNotification();
sl@0
   240
			User::WaitForRequest(iStatus); // swallow it
sl@0
   241
			test.Printf(_L("ID_PIN=%d\n"), iOTGIdPin);
sl@0
   242
sl@0
   243
			if (iOTGIdPin != RUsbOtgDriver::EIdPinBPlug)
sl@0
   244
				{
sl@0
   245
				if (iDetectionRetry++ < 3)
sl@0
   246
					{
sl@0
   247
					iCaseStep = EVerifyIDGone;
sl@0
   248
					otgQueueOtgIdPinNotification( iOTGIdPin, iStatus );
sl@0
   249
					SetActive();
sl@0
   250
					break;
sl@0
   251
					}
sl@0
   252
				else
sl@0
   253
					{
sl@0
   254
					return TestFailed(KErrAbort, _L("ID_PIN NOT 'removed' - FAILED!"));
sl@0
   255
					}
sl@0
   256
				}
sl@0
   257
			// check using the API in a syncronous way too
sl@0
   258
			if (otgIdPinPresent())
sl@0
   259
				{
sl@0
   260
				return TestFailed(KErrAbort, _L("ID_PIN syncronous call error - FAILED!"));
sl@0
   261
				}
sl@0
   262
			iCaseStep = ERepeatLoop;
sl@0
   263
			SelfComplete();
sl@0
   264
			break;
sl@0
   265
			
sl@0
   266
		case EUnloadLdd:
sl@0
   267
			// 7. unload
sl@0
   268
			if (EFalse == StepUnloadLDD())
sl@0
   269
				return TestFailed(KErrAbort,_L("Unload Ldd failure"));
sl@0
   270
			
sl@0
   271
			iCaseStep = ELastStep;
sl@0
   272
			SelfComplete();
sl@0
   273
			break;
sl@0
   274
			
sl@0
   275
		case ELastStep:
sl@0
   276
			TestPassed();
sl@0
   277
			break;
sl@0
   278
			
sl@0
   279
		default:
sl@0
   280
			test.Printf(_L("<Error> unknown test step"));
sl@0
   281
			Cancel();
sl@0
   282
			return (TestFailed(KErrCorrupt, _L("<Error> unknown test step")));
sl@0
   283
		}
sl@0
   284
	}
sl@0
   285