os/kernelhwsrv/kerneltest/e32test/usbho/t_otgdi/src/testcase0677.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 "testcase0677.h"
sl@0
    27
sl@0
    28
#define _REPEATS (oOpenIterations*3)
sl@0
    29
sl@0
    30
sl@0
    31
sl@0
    32
// the name below is used to add a pointer to our construction method to a pointer MAP in 
sl@0
    33
// the class factory
sl@0
    34
_LIT(KTestCaseId,"PBASE-USB_OTGDI-0677");
sl@0
    35
const TTestCaseFactoryReceipt<CTestCase0677> CTestCase0677::iFactoryReceipt(KTestCaseId);	
sl@0
    36
sl@0
    37
CTestCase0677* CTestCase0677::NewL(TBool aHost)
sl@0
    38
	{
sl@0
    39
	LOG_FUNC
sl@0
    40
	CTestCase0677* self = new (ELeave) CTestCase0677(aHost);
sl@0
    41
	CleanupStack::PushL(self);
sl@0
    42
	self->ConstructL();
sl@0
    43
	CleanupStack::Pop(self);
sl@0
    44
	return self;
sl@0
    45
	}
sl@0
    46
	
sl@0
    47
sl@0
    48
CTestCase0677::CTestCase0677(TBool aHost)
sl@0
    49
:	CTestCaseRoot(KTestCaseId, aHost)
sl@0
    50
	{
sl@0
    51
	LOG_FUNC
sl@0
    52
		
sl@0
    53
	} 
sl@0
    54
sl@0
    55
sl@0
    56
/**
sl@0
    57
 ConstructL
sl@0
    58
*/
sl@0
    59
void CTestCase0677::ConstructL()
sl@0
    60
	{
sl@0
    61
	LOG_FUNC
sl@0
    62
	iWDTimer = CTestCaseWatchdog::NewL();
sl@0
    63
	iRepeats = OPEN_REPEATS;
sl@0
    64
		
sl@0
    65
	BaseConstructL();
sl@0
    66
	}
sl@0
    67
sl@0
    68
sl@0
    69
CTestCase0677::~CTestCase0677()
sl@0
    70
	{
sl@0
    71
	LOG_FUNC
sl@0
    72
sl@0
    73
	Cancel();
sl@0
    74
	delete iWDTimer;
sl@0
    75
	
sl@0
    76
	}
sl@0
    77
sl@0
    78
sl@0
    79
void CTestCase0677::ExecuteTestCaseL()
sl@0
    80
	{
sl@0
    81
	LOG_FUNC
sl@0
    82
	iCaseStep = EPreconditions;
sl@0
    83
	
sl@0
    84
	iRepeats = KOperationRetriesMax;	// VBus event rise retries
sl@0
    85
	
sl@0
    86
	CActiveScheduler::Add(this);
sl@0
    87
	SelfComplete();
sl@0
    88
sl@0
    89
	}
sl@0
    90
sl@0
    91
	
sl@0
    92
void CTestCase0677::DoCancel()
sl@0
    93
	{
sl@0
    94
	LOG_FUNC
sl@0
    95
sl@0
    96
	// cancel our timer
sl@0
    97
	iTimer.Cancel();
sl@0
    98
	}
sl@0
    99
sl@0
   100
sl@0
   101
void CTestCase0677::CancelKB(CTestCaseRoot *pThis)
sl@0
   102
	{
sl@0
   103
	LOG_FUNC
sl@0
   104
	CTestCase0677 * p = REINTERPRET_CAST(CTestCase0677 *,pThis);
sl@0
   105
	// cancel any pending call, and then complete our active obj with a cancel value
sl@0
   106
	p->iConsole->ReadCancel();
sl@0
   107
sl@0
   108
	}
sl@0
   109
sl@0
   110
sl@0
   111
void CTestCase0677::CancelNotify(CTestCaseRoot *pThis)
sl@0
   112
	{
sl@0
   113
	LOG_FUNC
sl@0
   114
	CTestCase0677 * p = REINTERPRET_CAST(CTestCase0677 *,pThis);
sl@0
   115
	// cancel any pending call, and then complete our active obj with a timeout value
sl@0
   116
	switch (p->iCancelWhat)
sl@0
   117
		{
sl@0
   118
			case ECancelEventNotify:
sl@0
   119
				p->otgCancelOtgEventRequest();
sl@0
   120
				break;			
sl@0
   121
			case ECancelMessageNotify: 
sl@0
   122
				p->otgCancelOtgMessageRequest();
sl@0
   123
				break;
sl@0
   124
			case ECancelVBusNotify:
sl@0
   125
				p->otgCancelOtgVbusNotification();
sl@0
   126
				break;	
sl@0
   127
			default:
sl@0
   128
				ASSERT(0);
sl@0
   129
				break;
sl@0
   130
		}
sl@0
   131
	p->SelfComplete(KTestCaseWatchdogTO);
sl@0
   132
	}
sl@0
   133
sl@0
   134
sl@0
   135
// This test result depends on all the ID detection tests and the VBus driving and dropping tests have not yet passed
sl@0
   136
void CTestCase0677::DescribePreconditions()
sl@0
   137
	{
sl@0
   138
	test.Printf(_L("Using OET, connect oscilloscope chan.A to VBus\n"));
sl@0
   139
	test.Printf(_L("Connect oscilloscope chan.B to D+\n"));
sl@0
   140
	test.Printf(_L("Trigger once, 200mV, 100ms \n"));
sl@0
   141
	test.Printf(_L("Prepare to observe VBus, D+ pulse.\n\n"));
sl@0
   142
	}
sl@0
   143
sl@0
   144
sl@0
   145
void CTestCase0677::ContinueAfter(TTimeIntervalMicroSeconds32 aMicroSecs, TCaseSteps aStep)
sl@0
   146
	{
sl@0
   147
	LOG_VERBOSE2(_L("Wait %dms before drop VBus"), (TInt)(aMicroSecs.Int()/1000));
sl@0
   148
	iTimer.After(iStatus, aMicroSecs);
sl@0
   149
	iCaseStep = aStep;
sl@0
   150
	SetActive();
sl@0
   151
	}
sl@0
   152
sl@0
   153
sl@0
   154
// handle event completion	
sl@0
   155
void CTestCase0677::RunStepL()
sl@0
   156
	{
sl@0
   157
	LOG_FUNC
sl@0
   158
	// Obtain the completion code for this CActive obj.
sl@0
   159
	TInt completionCode(iStatus.Int()); 
sl@0
   160
	TBuf<MAX_DSTRLEN> aDescription;
sl@0
   161
	TInt err(0);
sl@0
   162
sl@0
   163
sl@0
   164
	switch(iCaseStep)
sl@0
   165
		{
sl@0
   166
		case EPreconditions:
sl@0
   167
			iCaseStep = ELoadLdd;
sl@0
   168
			if (iAutomated)
sl@0
   169
				{
sl@0
   170
				iCaseStep = ELoadLdd;
sl@0
   171
				SelfComplete();
sl@0
   172
				break;
sl@0
   173
				}
sl@0
   174
			// prompt to insert connector
sl@0
   175
			test.Printf(KAttachOETAsBDevice);
sl@0
   176
			test.Printf(KPressAnyKeyToContinue);
sl@0
   177
			RequestCharacter();			
sl@0
   178
			break;
sl@0
   179
			
sl@0
   180
			// 1. load the LDD and init.		
sl@0
   181
		case ELoadLdd:
sl@0
   182
			if (!StepLoadLDD())
sl@0
   183
				{
sl@0
   184
				break;
sl@0
   185
				}
sl@0
   186
			iCaseStep = EDetectBPlug;
sl@0
   187
			SelfComplete();
sl@0
   188
			break;
sl@0
   189
sl@0
   190
			// 2. detect 'B' plug now
sl@0
   191
		case EDetectBPlug:
sl@0
   192
			if (KTestCaseWatchdogTO == iStatus.Int())
sl@0
   193
				{
sl@0
   194
				return TestFailed(KErrAbort, _L("User response too slow - FAILED!"));
sl@0
   195
				}
sl@0
   196
sl@0
   197
			// if doing this test in /AUTO mode, we would fail this now
sl@0
   198
			// however if we can control ID_PIN through an API in future, we turn in on now.
sl@0
   199
			if (otgIdPinPresent())
sl@0
   200
				{
sl@0
   201
				test.Printf(KRemoveAConnectorPrompt);
sl@0
   202
				test.Printf(KPressAnyKeyToContinue);
sl@0
   203
				RequestCharacter();
sl@0
   204
sl@0
   205
				iCaseStep = EDetectBPlug;
sl@0
   206
				}
sl@0
   207
			else
sl@0
   208
				{
sl@0
   209
				iCaseStep = ERequestBus;
sl@0
   210
				SelfComplete();
sl@0
   211
				}
sl@0
   212
			break;
sl@0
   213
						
sl@0
   214
			// 5. Issue SRP (request VBUS)
sl@0
   215
		case ERequestBus:
sl@0
   216
			iWDTimer->Cancel();
sl@0
   217
sl@0
   218
			test.Printf(KMsgWaitingForSRPInitiated);
sl@0
   219
			otgQueueOtgEventRequest( iOTGEvent, iStatus );
sl@0
   220
sl@0
   221
			// turn on VBus (B-SRP)
sl@0
   222
			err = otgBusRequest();
sl@0
   223
			iTimeSRPStart.HomeTime();
sl@0
   224
			
sl@0
   225
			if (KErrNone != err)
sl@0
   226
				{
sl@0
   227
				return TestFailed(KErrAbort, _L("Issue SRP - RUsbOtgDriver::BusRequest() FAILED!"));
sl@0
   228
				}
sl@0
   229
			iCaseStep = EWaitForSRPInitiated;
sl@0
   230
			iCancelWhat = ECancelEventNotify;
sl@0
   231
			iWDTimer->IssueRequest(32000*2 /*KSpec_TA_SRP_RSPNS +1000*/, this, &CancelNotify);
sl@0
   232
			SetActive();
sl@0
   233
			break;
sl@0
   234
			
sl@0
   235
			// 6. get SRP initiated event, this is a local indication
sl@0
   236
		case EWaitForSRPInitiated:			
sl@0
   237
			if (KTestCaseWatchdogTO == iStatus.Int())
sl@0
   238
				{
sl@0
   239
				return TestFailed(KErrAbort, _L("SRP Active indication NOT fired in time - FAILED!"));
sl@0
   240
				}
sl@0
   241
			OtgEventString(iOTGEvent, aDescription);
sl@0
   242
			test.Printf(_L("Received event %d '%S' status(%d)\n"), iOTGEvent, &aDescription, completionCode);
sl@0
   243
			if (RUsbOtgDriver::EEventSrpInitiated == iOTGEvent)
sl@0
   244
				{
sl@0
   245
				// calc interval
sl@0
   246
				TTimeIntervalMicroSeconds aIntvlMicro;
sl@0
   247
				TTime aNowTime;
sl@0
   248
				aNowTime.HomeTime();
sl@0
   249
				aIntvlMicro = aNowTime.MicroSecondsFrom(iTimeSRPStart);
sl@0
   250
				LOG_VERBOSE2(_L("SRP active after %d ms\n"), (TInt)(aIntvlMicro.Int64()/1000));
sl@0
   251
				iCancelWhat = ECancelMessageNotify;
sl@0
   252
				otgQueueOtgMessageRequest( iOTGMessage, iStatus );
sl@0
   253
				iCaseStep = EWaitForSRPTimeout;
sl@0
   254
				test.Printf(KMsgWaitingForSRPTimeout);
sl@0
   255
				SetActive();
sl@0
   256
				}
sl@0
   257
			else
sl@0
   258
				{
sl@0
   259
				iCaseStep = EWaitForSRPInitiated;
sl@0
   260
				test.Printf(KMsgWaitingForSRPInitiated);
sl@0
   261
				iStatus = KRequestPending;
sl@0
   262
				otgQueueOtgEventRequest( iOTGEvent, iStatus );
sl@0
   263
				SetActive();
sl@0
   264
				}
sl@0
   265
			break;
sl@0
   266
				
sl@0
   267
			// 6. get SRP timeout event, this is a local indication
sl@0
   268
		case EWaitForSRPTimeout:			
sl@0
   269
			if (KTestCaseWatchdogTO == iStatus.Int())
sl@0
   270
				{
sl@0
   271
				return TestFailed(KErrAbort, _L("SRP T/O NOT fired in time - FAILED!"));
sl@0
   272
				}
sl@0
   273
			OtgMessageString(iOTGMessage, aDescription);
sl@0
   274
			test.Printf(_L("Received message %d '%S' status(%d)\n"), iOTGMessage, &aDescription, completionCode);
sl@0
   275
			if (RUsbOtgDriver::EMessageSrpTimeout == iOTGMessage)
sl@0
   276
				{
sl@0
   277
				iWDTimer->Cancel();		//	Only cancel WD Timer here, when timed portion of test is over
sl@0
   278
				// calc interval
sl@0
   279
				TTimeIntervalMicroSeconds aIntvlMicro;
sl@0
   280
				TTime aNowTime;
sl@0
   281
				aNowTime.HomeTime();
sl@0
   282
				aIntvlMicro = aNowTime.MicroSecondsFrom(iTimeSRPStart);
sl@0
   283
				LOG_VERBOSE2(_L("SRP times out after %d ms\n"), (TInt)(aIntvlMicro.Int64()/1000));
sl@0
   284
				// the correct value is 32 seconds, not 4.9 seconds as per the spec.
sl@0
   285
sl@0
   286
				iCaseStep = EIssueSRPObservedPrompt;
sl@0
   287
				SelfComplete();
sl@0
   288
				}
sl@0
   289
			else
sl@0
   290
				{
sl@0
   291
				iCaseStep = EWaitForSRPTimeout;
sl@0
   292
				test.Printf(KMsgWaitingForSRPTimeout);
sl@0
   293
				iStatus = KRequestPending;
sl@0
   294
				otgQueueOtgMessageRequest( iOTGMessage, iStatus );
sl@0
   295
				SetActive();
sl@0
   296
				}
sl@0
   297
			break;
sl@0
   298
				
sl@0
   299
		case EIssueSRPObservedPrompt:
sl@0
   300
			{
sl@0
   301
			test.Printf(_L("\nPress Y to verify that SRP was observed\n"));
sl@0
   302
			test.Printf(_L("or any other key to fail test.\n"));
sl@0
   303
			RequestCharacter();
sl@0
   304
			iCaseStep = ECheckSRPObservedUserInput;
sl@0
   305
			break;
sl@0
   306
			}
sl@0
   307
			
sl@0
   308
							
sl@0
   309
		case ECheckSRPObservedUserInput:
sl@0
   310
			{
sl@0
   311
			if (('y' != iKeyCodeInput) && ('Y' != iKeyCodeInput))
sl@0
   312
				{
sl@0
   313
				return TestFailed(KErrAbort, _L("SRP NOT observed - FAILED!"));
sl@0
   314
				}
sl@0
   315
			iCaseStep = EUnloadLdd;
sl@0
   316
			SelfComplete();
sl@0
   317
			break;
sl@0
   318
			}
sl@0
   319
							
sl@0
   320
			// 12. unload OTG
sl@0
   321
		case EUnloadLdd:
sl@0
   322
			if (EFalse == StepUnloadLDD())
sl@0
   323
				return TestFailed(KErrAbort,_L("Unload Ldd failure"));	
sl@0
   324
			
sl@0
   325
			iCaseStep = ELastStep;
sl@0
   326
			SelfComplete();
sl@0
   327
			break;
sl@0
   328
			
sl@0
   329
		case ELastStep:
sl@0
   330
			TestPassed();
sl@0
   331
			break;
sl@0
   332
			
sl@0
   333
		default:
sl@0
   334
			test.Printf(_L("<Error> unknown test step\n"));
sl@0
   335
			Cancel();
sl@0
   336
			return (TestFailed(KErrCorrupt, _L("<Error> unknown test step")));
sl@0
   337
		}
sl@0
   338
	}
sl@0
   339
sl@0
   340