os/kernelhwsrv/kerneltest/e32test/usbho/t_otgdi/src/testcase0679.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 "b2bwatchers.h"
sl@0
    26
#include "testcase0679.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
 */
sl@0
    35
_LIT(KTestCaseId,"PBASE-USB_OTGDI-0679");
sl@0
    36
const TTestCaseFactoryReceipt<CTestCase0679> CTestCase0679::iFactoryReceipt(KTestCaseId);	
sl@0
    37
sl@0
    38
CTestCase0679* CTestCase0679::NewL(TBool aHost)
sl@0
    39
	{
sl@0
    40
	LOG_FUNC
sl@0
    41
	CTestCase0679* self = new (ELeave) CTestCase0679(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
CTestCase0679::CTestCase0679(TBool aHost)
sl@0
    50
	: CTestCaseB2BRoot(KTestCaseId, aHost, iStatus) 
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 CTestCase0679::ConstructL()
sl@0
    61
	{
sl@0
    62
	LOG_FUNC
sl@0
    63
sl@0
    64
	iDualRoleCase = ETrue;	// another back-back
sl@0
    65
		
sl@0
    66
	BaseConstructL();
sl@0
    67
	}
sl@0
    68
sl@0
    69
sl@0
    70
CTestCase0679::~CTestCase0679()
sl@0
    71
	{
sl@0
    72
	LOG_FUNC
sl@0
    73
	iCollector.DestroyObservers();
sl@0
    74
	Cancel();
sl@0
    75
	}
sl@0
    76
sl@0
    77
sl@0
    78
void CTestCase0679::ExecuteTestCaseL()
sl@0
    79
	{
sl@0
    80
	LOG_FUNC
sl@0
    81
	iCaseStep = EPreconditions;
sl@0
    82
	CActiveScheduler::Add(this);
sl@0
    83
	SelfComplete();
sl@0
    84
	}
sl@0
    85
sl@0
    86
	
sl@0
    87
void CTestCase0679::DoCancel()
sl@0
    88
	{
sl@0
    89
	LOG_FUNC
sl@0
    90
	// cancel our timer
sl@0
    91
	iTimer.Cancel();
sl@0
    92
	}
sl@0
    93
sl@0
    94
sl@0
    95
// handle event completion	
sl@0
    96
void CTestCase0679::RunStepL()
sl@0
    97
	{
sl@0
    98
	LOG_FUNC
sl@0
    99
	// Obtain the completion code for this CActive obj.
sl@0
   100
	TInt completionCode(iStatus.Int()); 
sl@0
   101
	TBuf<MAX_DSTRLEN> aDescription;
sl@0
   102
	TInt err(0);
sl@0
   103
sl@0
   104
	switch(iCaseStep)
sl@0
   105
		{
sl@0
   106
		case EPreconditions:
sl@0
   107
			{
sl@0
   108
			LOG_STEPNAME(_L("EPreconditions"))
sl@0
   109
			iCaseStep = ELoadLdd;
sl@0
   110
			StepB2BPreconditions();				
sl@0
   111
			break;
sl@0
   112
			}
sl@0
   113
			
sl@0
   114
			// 1. Load the Client LDD 
sl@0
   115
		case ELoadLdd:
sl@0
   116
			{
sl@0
   117
			LOG_STEPNAME(_L("ELoadLdd"))
sl@0
   118
			if (!StepLoadClient(0xF679, EFalse /*no HNP support!*/))
sl@0
   119
				{
sl@0
   120
				return TestFailed(KErrAbort, _L("Client Load Failure"));
sl@0
   121
				}
sl@0
   122
			//  load OTG ldd and init.		
sl@0
   123
			if (!StepLoadLDD())
sl@0
   124
				{
sl@0
   125
				return TestFailed(KErrAbort, _L("OTG Load Failure"));
sl@0
   126
				}
sl@0
   127
				
sl@0
   128
			if(otgActivateFdfActor()!=KErrNone)
sl@0
   129
				{
sl@0
   130
				return TestFailed(KErrAbort, _L("Couldn't load FDF Actor"));
sl@0
   131
				}
sl@0
   132
			
sl@0
   133
			// test that the right cable is in
sl@0
   134
			CheckRoleConnections();
sl@0
   135
					
sl@0
   136
			// subscribe to OTG states,events and messages now that it has loaded OK
sl@0
   137
			TRAPD(result, iCollector.CreateObserversL(*this));
sl@0
   138
			if (KErrNone != result)
sl@0
   139
				return(TestFailed(KErrNoMemory, _L("Unable to create observers")));
sl@0
   140
			iCollector.ClearAllEvents();
sl@0
   141
			iCaseStep = EReadyToRaiseVBus;
sl@0
   142
			SelfComplete();
sl@0
   143
			break;
sl@0
   144
			}
sl@0
   145
			
sl@0
   146
		case EReadyToRaiseVBus:
sl@0
   147
			{
sl@0
   148
			if (gTestRoleMaster)
sl@0
   149
				{
sl@0
   150
				// wait for Vbus to be raised
sl@0
   151
				iCollector.AddRequiredNotification(EWatcherState, RUsbOtgDriver::EStateBIdle);
sl@0
   152
				iCollector.AddRequiredNotification(EWatcherEvent, RUsbOtgDriver::EEventVbusRaised);
sl@0
   153
				iCollector.AddRequiredNotification(EWatcherState, RUsbOtgDriver::EStateBPeripheral);
sl@0
   154
				}
sl@0
   155
			else
sl@0
   156
				{ // slave "A"
sl@0
   157
				// Raise VBus, then wait for default role
sl@0
   158
				err = otgBusRequest();	// ok to turn on VBus now
sl@0
   159
				if (KErrNone != err)
sl@0
   160
					{
sl@0
   161
					return TestFailed(KErrAbort, _L("Raise Vbus - RUsbOtgDriver::BusRequest() FAILED!"));
sl@0
   162
					}
sl@0
   163
				
sl@0
   164
				// we might also wait for and EStateAIdle
sl@0
   165
				iCollector.AddRequiredNotification(EWatcherState, RUsbOtgDriver::EStateAIdle);
sl@0
   166
				iCollector.AddRequiredNotification(EWatcherEvent, RUsbOtgDriver::EEventVbusRaised);
sl@0
   167
				iCollector.AddRequiredNotification(EWatcherEvent, RUsbOtgDriver::EEventRoleChangedToHost);
sl@0
   168
				}
sl@0
   169
sl@0
   170
			const TInt KTestCase0679VBusRaiseTimeout = 2000;	//	2 seconds, should be plenty of time for this test 
sl@0
   171
			iCollector.AddStepTimeout(KTestCase0679VBusRaiseTimeout);
sl@0
   172
sl@0
   173
			iCaseStep = EDefaultRoles;
sl@0
   174
			SetActive();									
sl@0
   175
			break;
sl@0
   176
			}
sl@0
   177
			
sl@0
   178
		case EDefaultRoles:
sl@0
   179
			{
sl@0
   180
			test.Printf(_L("Into EDefaultRoles step...\n"));
sl@0
   181
			LOG_STEPNAME(_L("EWaitEnumeration"));
sl@0
   182
			
sl@0
   183
			if (gTestRoleMaster)
sl@0
   184
				{
sl@0
   185
				//	B-Device should now wait until it is configured
sl@0
   186
				iCollector.AddRequiredNotification(EWatcherPeripheralState, EUsbcDeviceStateConfigured);
sl@0
   187
sl@0
   188
				const TInt KTestCase0679BTimeout = 5000;			//	5 seconds, should be plenty of time for overall test 
sl@0
   189
				iCollector.AddStepTimeout(KTestCase0679BTimeout);
sl@0
   190
sl@0
   191
				iCaseStep = EBConfigured;
sl@0
   192
				}
sl@0
   193
			else
sl@0
   194
				{
sl@0
   195
				//	A-Device should expect nothing more (role swap won't happen
sl@0
   196
				//	because the B-Device doesn't indicate support for OTG in its
sl@0
   197
				//	OTG descriptor, so the host won't have sent SetFeature(b_hnp_enable))
sl@0
   198
				//	Instead, just rely on the test timeout and display a request for the user 
sl@0
   199
				//	to observe the B-Device test code for the pass/fail
sl@0
   200
				const TInt KTestCase0679ATimeout = 4000;			//	4 seconds before A-Device drops VBus (before B test times out at 5 seconds)
sl@0
   201
				iCollector.AddStepTimeout(KTestCase0679ATimeout);	//	NB. In this test on the A-Device, we expect to timeout
sl@0
   202
																	//	so a timeout isn't treated as a failure
sl@0
   203
				test.Printf(_L("NOTE : Please observe test result on B-Device...\n"));
sl@0
   204
				iCaseStep = EDropVBus;	//	This is the step the A-Device will go to
sl@0
   205
										//	when the timer (set up in previous test) fires
sl@0
   206
				}
sl@0
   207
			SetActive();
sl@0
   208
			break;
sl@0
   209
			}
sl@0
   210
sl@0
   211
			
sl@0
   212
		case EBConfigured:	//	A B-Device only step!
sl@0
   213
			{
sl@0
   214
			test.Printf(_L("Into EBConfigured step...\n"));
sl@0
   215
			if (KTestCaseWatchdogTO == iStatus.Int())
sl@0
   216
				{
sl@0
   217
				iCollector.DestroyObservers();
sl@0
   218
				return TestFailed(KErrAbort, _L("Timeout"));
sl@0
   219
				}
sl@0
   220
			iCollector.AddRequiredNotification(EWatcherPeripheralState, EUsbcDeviceStateSuspended);
sl@0
   221
			iCaseStep = EBSuspended;
sl@0
   222
			SetActive();
sl@0
   223
			break;
sl@0
   224
			}
sl@0
   225
			
sl@0
   226
		case EBSuspended:	
sl@0
   227
			{
sl@0
   228
			test.Printf(_L("Into EBSuspended step...\n"));
sl@0
   229
			if (KTestCaseWatchdogTO == iStatus.Int())
sl@0
   230
				{
sl@0
   231
				iCollector.DestroyObservers();
sl@0
   232
				return TestFailed(KErrAbort, _L("Timeout"));
sl@0
   233
				}			
sl@0
   234
			
sl@0
   235
			// issue HNP
sl@0
   236
			test.Printf(_L("Attempting a swap on a non-HNP enabled link...\n"));
sl@0
   237
			iCollector.AddRequiredNotification(EWatcherMessage, RUsbOtgDriver::EMessageHnpNotEnabled);
sl@0
   238
sl@0
   239
			err = otgBusRequest();	//	Request the host role
sl@0
   240
sl@0
   241
			if (KErrNone != err)
sl@0
   242
				{
sl@0
   243
				test.Printf(_L("BusRequest returned %d)"),err);
sl@0
   244
				//DS Temp! return TestFailed(KErrAbort, _L("BusRequest() failed!"));
sl@0
   245
				}
sl@0
   246
		
sl@0
   247
			iCaseStep = EBErrorReceived;
sl@0
   248
			SetActive();
sl@0
   249
			break;
sl@0
   250
			}
sl@0
   251
			
sl@0
   252
		case EBErrorReceived:
sl@0
   253
			{
sl@0
   254
			test.Printf(_L("Into EBErrorReceived step...\n"));
sl@0
   255
			if (KTestCaseWatchdogTO == iStatus.Int())
sl@0
   256
				{
sl@0
   257
				iCollector.DestroyObservers();
sl@0
   258
				return TestFailed(KErrAbort, _L("Timeout"));
sl@0
   259
				}			
sl@0
   260
			iCaseStep = EDropVBus;	//	Test has pretty much passed now. Just wait for A-Device to drop VBus.
sl@0
   261
			SelfComplete();
sl@0
   262
			break;
sl@0
   263
			}
sl@0
   264
sl@0
   265
		case EDropVBus:
sl@0
   266
			LOG_STEPNAME(_L("EDropVBus"))
sl@0
   267
sl@0
   268
			iCollector.AddRequiredNotification(EWatcherEvent, RUsbOtgDriver::EEventVbusDropped);
sl@0
   269
			if ( gTestRoleMaster)
sl@0
   270
				{
sl@0
   271
				iCollector.AddRequiredNotification(EWatcherState, RUsbOtgDriver::EStateBIdle);
sl@0
   272
				}
sl@0
   273
			else
sl@0
   274
				{ // SLAVE "A"
sl@0
   275
				iCollector.AddRequiredNotification(EWatcherState, RUsbOtgDriver::EStateAIdle);
sl@0
   276
				otgBusDrop();
sl@0
   277
				}
sl@0
   278
			iCaseStep = EVBusDropped;
sl@0
   279
			SetActive();
sl@0
   280
			break;
sl@0
   281
			
sl@0
   282
		case EVBusDropped:
sl@0
   283
			LOG_STEPNAME(_L("EVBusDropped"))
sl@0
   284
			if (KTestCaseWatchdogTO == iStatus.Int() && gTestRoleMaster)
sl@0
   285
				{
sl@0
   286
				//	Remember, a timeout is only a failure for the B-Device in this test,
sl@0
   287
				//	we're expecting and relying on a timeout on the A-Device to conclude
sl@0
   288
				//	the test and bring VBus down.
sl@0
   289
				return TestFailed(KErrAbort, _L("Timeout"));
sl@0
   290
				}
sl@0
   291
				
sl@0
   292
			if (otgVbusPresent())
sl@0
   293
				{
sl@0
   294
				return TestFailed(KErrAbort, _L("Vbus did not drop - FAILED!"));
sl@0
   295
				}
sl@0
   296
			iCaseStep = EUnloadLdd;
sl@0
   297
			SelfComplete();
sl@0
   298
			break;
sl@0
   299
			
sl@0
   300
		case EUnloadLdd:
sl@0
   301
			LOG_STEPNAME(_L("EUnloadLdd"))
sl@0
   302
			iCollector.DestroyObservers();
sl@0
   303
			otgDeactivateFdfActor();
sl@0
   304
			if (EFalse == StepUnloadLDD())
sl@0
   305
				return TestFailed(KErrAbort,_L("unload Ldd failure"));	
sl@0
   306
			if (!StepUnloadClient())
sl@0
   307
				return TestFailed(KErrAbort,_L("Client Unload Failure"));	
sl@0
   308
sl@0
   309
			iCaseStep = ELastStep;
sl@0
   310
			SelfComplete();
sl@0
   311
			break;
sl@0
   312
			
sl@0
   313
		case ELastStep:
sl@0
   314
			LOG_STEPNAME(_L("ELastStep"))
sl@0
   315
			TestPassed();
sl@0
   316
			break;
sl@0
   317
			
sl@0
   318
		default:
sl@0
   319
			test.Printf(_L("<Error> unknown test step"));
sl@0
   320
			Cancel();
sl@0
   321
			return (TestFailed(KErrCorrupt, _L("<Error> unknown test step")));
sl@0
   322
		}
sl@0
   323
	}