os/kernelhwsrv/kerneltest/e32test/usbho/t_otgdi/src/testcase0684.cpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
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 "b2bwatchers.h"
sl@0
    27
#include "testcase0684.h"
sl@0
    28
sl@0
    29
#include <e32debug.h> 
sl@0
    30
sl@0
    31
#define _REPEATS (oOpenIterations*3)
sl@0
    32
sl@0
    33
sl@0
    34
/* **************************************************************************************
sl@0
    35
 * the name below is used to add a pointer to our construction method to a pointer MAP in 
sl@0
    36
 * the class factory
sl@0
    37
 */
sl@0
    38
_LIT(KTestCaseId,"PBASE-USB_OTGDI-0684");
sl@0
    39
const TTestCaseFactoryReceipt<CTestCase0684> CTestCase0684::iFactoryReceipt(KTestCaseId);	
sl@0
    40
sl@0
    41
CTestCase0684* CTestCase0684::NewL(TBool aHost)
sl@0
    42
	{
sl@0
    43
	LOG_FUNC
sl@0
    44
	CTestCase0684* self = new (ELeave) CTestCase0684(aHost);
sl@0
    45
	CleanupStack::PushL(self);
sl@0
    46
	self->ConstructL();
sl@0
    47
	CleanupStack::Pop(self);
sl@0
    48
	return self;
sl@0
    49
	}
sl@0
    50
	
sl@0
    51
sl@0
    52
CTestCase0684::CTestCase0684(TBool aHost)
sl@0
    53
	: CTestCaseB2BRoot(KTestCaseId, aHost, iStatus) 
sl@0
    54
	{
sl@0
    55
	LOG_FUNC
sl@0
    56
		
sl@0
    57
	} 
sl@0
    58
sl@0
    59
sl@0
    60
/**
sl@0
    61
 ConstructL
sl@0
    62
*/
sl@0
    63
void CTestCase0684::ConstructL()
sl@0
    64
	{
sl@0
    65
	LOG_FUNC
sl@0
    66
sl@0
    67
	iDualRoleCase = ETrue;
sl@0
    68
	iBusRequestCounter = 2;
sl@0
    69
	iIsTimeToDrop = EFalse;
sl@0
    70
	
sl@0
    71
	BaseConstructL();
sl@0
    72
	}
sl@0
    73
sl@0
    74
sl@0
    75
CTestCase0684::~CTestCase0684()
sl@0
    76
	{
sl@0
    77
	LOG_FUNC
sl@0
    78
	iCollector.DestroyObservers();
sl@0
    79
	Cancel();
sl@0
    80
	}
sl@0
    81
sl@0
    82
sl@0
    83
void CTestCase0684::ExecuteTestCaseL()
sl@0
    84
	{
sl@0
    85
	LOG_FUNC
sl@0
    86
	iCaseStep = EPreconditions;
sl@0
    87
	CActiveScheduler::Add(this);
sl@0
    88
	SelfComplete();
sl@0
    89
	}
sl@0
    90
sl@0
    91
	
sl@0
    92
void CTestCase0684::DoCancel()
sl@0
    93
	{
sl@0
    94
	LOG_FUNC
sl@0
    95
	// cancel our timer
sl@0
    96
	iTimer.Cancel();
sl@0
    97
	}
sl@0
    98
void CTestCase0684::RunStepL()
sl@0
    99
	{
sl@0
   100
	LOG_FUNC
sl@0
   101
	
sl@0
   102
	// Obtain the completion code for this CActive obj.
sl@0
   103
	TInt completionCode(iStatus.Int()); 
sl@0
   104
	TBuf<MAX_DSTRLEN> aDescription;
sl@0
   105
	TInt err(0);
sl@0
   106
	
sl@0
   107
	switch(iCaseStep)
sl@0
   108
		{
sl@0
   109
		case EPreconditions:
sl@0
   110
			{
sl@0
   111
			LOG_STEPNAME(_L("EPreconditions"))
sl@0
   112
		
sl@0
   113
			iCaseStep = ELoadLdd;
sl@0
   114
			StepB2BPreconditions();	
sl@0
   115
			break;
sl@0
   116
			}
sl@0
   117
			
sl@0
   118
			// 1. Load the Client LDD 
sl@0
   119
		case ELoadLdd:
sl@0
   120
			{
sl@0
   121
			LOG_STEPNAME(_L("ELoadLdd"))
sl@0
   122
			
sl@0
   123
			if (!StepLoadClient(0xF684/*use default settings for SRP/HNP support*/))
sl@0
   124
				{
sl@0
   125
				return TestFailed(KErrAbort, _L("Client Load Failure"));
sl@0
   126
				}
sl@0
   127
			
sl@0
   128
			//  load OTG ldd and init.		
sl@0
   129
			if (!StepLoadLDD())
sl@0
   130
				{
sl@0
   131
				return TestFailed(KErrAbort, _L("OTG Load Failure"));
sl@0
   132
				}
sl@0
   133
				
sl@0
   134
			if(otgActivateFdfActor()!=KErrNone)
sl@0
   135
				{
sl@0
   136
				return TestFailed(KErrAbort, _L("Couldn't load FDF Actor"));
sl@0
   137
				}
sl@0
   138
			
sl@0
   139
			// test that the right cable is in
sl@0
   140
			CheckRoleConnections();
sl@0
   141
					
sl@0
   142
			// subscribe to OTG states,events and messages now that it has loaded OK
sl@0
   143
			TRAPD(result, iCollector.CreateObserversL(*this));
sl@0
   144
			if (KErrNone != result)
sl@0
   145
				{
sl@0
   146
				return(TestFailed(KErrNoMemory, _L("Unable to create observers")));
sl@0
   147
				}
sl@0
   148
			iCollector.ClearAllEvents();
sl@0
   149
			iCaseStep = ESetMaxPower2Zero;
sl@0
   150
			SelfComplete();
sl@0
   151
			break;
sl@0
   152
			}
sl@0
   153
			
sl@0
   154
		case ESetMaxPower2Zero:
sl@0
   155
			LOG_STEPNAME(_L("ESetMaxPower2Zero"))
sl@0
   156
			iCaseStep = EReadyToRaiseVBus;
sl@0
   157
			SetMaxPowerToL(0);
sl@0
   158
			SelfComplete();
sl@0
   159
			break;
sl@0
   160
			
sl@0
   161
		case EReadyToRaiseVBus:
sl@0
   162
			{
sl@0
   163
			test.Printf(_L("Into EReadyToRaiseVBus step...\n"));
sl@0
   164
			
sl@0
   165
			if (gTestRoleMaster)
sl@0
   166
				{
sl@0
   167
				// B device, so , just wait for Vbus to be raised
sl@0
   168
				iCollector.AddRequiredNotification(EWatcherState, RUsbOtgDriver::EStateBIdle);
sl@0
   169
				iCollector.AddRequiredNotification(EWatcherEvent, RUsbOtgDriver::EEventVbusRaised);
sl@0
   170
				iCollector.AddRequiredNotification(EWatcherEvent, RUsbOtgDriver::EEventHnpEnabled);
sl@0
   171
				iCollector.AddRequiredNotification(EWatcherState, RUsbOtgDriver::EStateBPeripheral);
sl@0
   172
				//	All as usual - we should report a failure if the B-Device ever reports "busy"
sl@0
   173
				iCollector.AddFailureNotification(EWatcherAConnectionIdle, RUsbOtgDriver::EConnectionBusy);
sl@0
   174
				}
sl@0
   175
			else
sl@0
   176
				{ 
sl@0
   177
				// A device, Raise VBus, then wait for default role
sl@0
   178
				err = otgBusRequest();	// ok to turn on VBus now
sl@0
   179
				
sl@0
   180
				if (KErrNone != err)
sl@0
   181
					{
sl@0
   182
					return TestFailed(KErrAbort, _L("Raise Vbus - RUsbOtgDriver::BusRequest() FAILED!"));
sl@0
   183
					}
sl@0
   184
				
sl@0
   185
				// we might also wait for and EStateAIdle
sl@0
   186
				iCollector.AddRequiredNotification(EWatcherState, RUsbOtgDriver::EStateAIdle);
sl@0
   187
				iCollector.AddRequiredNotification(EWatcherEvent, RUsbOtgDriver::EEventVbusRaised);
sl@0
   188
				iCollector.AddRequiredNotification(EWatcherEvent, RUsbOtgDriver::EEventRoleChangedToHost);
sl@0
   189
				iCollector.AddRequiredNotification(EWatcherAConnectionIdle, RUsbOtgDriver::EConnectionBusy);
sl@0
   190
				}
sl@0
   191
			
sl@0
   192
			iCaseStep = EDefaultRoles;
sl@0
   193
			const TInt KTestCase0684Timeout = 30000;			//	30 seconds, should be plenty of time for 3 role swaps
sl@0
   194
			iCollector.AddStepTimeout(KTestCase0684Timeout);
sl@0
   195
			SetActive();
sl@0
   196
			break;
sl@0
   197
			}
sl@0
   198
			
sl@0
   199
		case EDefaultRoles:
sl@0
   200
			{
sl@0
   201
			test.Printf(_L("Into EDefaultRoles step...\n"));
sl@0
   202
			if (KTestCaseWatchdogTO == iStatus.Int())
sl@0
   203
				{
sl@0
   204
				iCollector.DestroyObservers();
sl@0
   205
				return TestFailed(KErrAbort, _L("Timeout"));
sl@0
   206
				}			
sl@0
   207
						
sl@0
   208
			if(gTestRoleMaster){
sl@0
   209
				// B
sl@0
   210
				iCollector.AddRequiredNotification(EWatcherPeripheralState, EUsbcDeviceStateConfigured);
sl@0
   211
				iCaseStep = EBConfigured;
sl@0
   212
			}
sl@0
   213
			else{
sl@0
   214
				iCollector.AddRequiredNotification(EWatcherState, RUsbOtgDriver::EStateAPeripheral);
sl@0
   215
				iCaseStep = EAToPeripheral;
sl@0
   216
			}
sl@0
   217
			SetActive();
sl@0
   218
			break;
sl@0
   219
			}
sl@0
   220
			
sl@0
   221
		case EAIdleHostPriorToAPeripheral:	//	an "A-Device only" step
sl@0
   222
			{
sl@0
   223
			test.Printf(_L("Into EAIdleHostPriorToAPeripheral step...\n"));
sl@0
   224
			if (KTestCaseWatchdogTO == iStatus.Int())
sl@0
   225
				{
sl@0
   226
				iCollector.DestroyObservers();
sl@0
   227
				return TestFailed(KErrAbort, _L("Timeout"));
sl@0
   228
				}			
sl@0
   229
				
sl@0
   230
			//	A-Device should expect nothing more until it becomes A-Peripheral
sl@0
   231
			iCollector.AddRequiredNotification(EWatcherState, RUsbOtgDriver::EStateAPeripheral);
sl@0
   232
			iCollector.AddRequiredNotification(EWatcherAConnectionIdle, RUsbOtgDriver::EConnectionBusy);
sl@0
   233
			iCollector.AddRequiredNotification(EWatcherPeripheralState, EUsbcDeviceStateConfigured);
sl@0
   234
			iCollector.AddRequiredNotification(EWatcherState, RUsbOtgDriver::EStateAHost);
sl@0
   235
			iCaseStep = EAToHost;
sl@0
   236
			SetActive();
sl@0
   237
			break;
sl@0
   238
			}	
sl@0
   239
			
sl@0
   240
		case EBConfigured:
sl@0
   241
			{
sl@0
   242
			test.Printf(_L("Into EBConfigured step...\n"));
sl@0
   243
			if (KTestCaseWatchdogTO == iStatus.Int())
sl@0
   244
				{
sl@0
   245
				iCollector.DestroyObservers();
sl@0
   246
				RDebug::Print(_L("Timeout"));
sl@0
   247
				return TestFailed(KErrAbort, _L("Timeout"));
sl@0
   248
				}
sl@0
   249
			iCollector.AddRequiredNotification(EWatcherPeripheralState, EUsbcDeviceStateSuspended);
sl@0
   250
			iCaseStep = EBSuspended;
sl@0
   251
			SetActive();
sl@0
   252
			break;
sl@0
   253
			}
sl@0
   254
			
sl@0
   255
		case EBSuspended:
sl@0
   256
			{
sl@0
   257
			test.Printf(_L("Into EBSuspended step...\n"));					
sl@0
   258
			if (KTestCaseWatchdogTO == iStatus.Int())
sl@0
   259
				{
sl@0
   260
				iCollector.DestroyObservers();
sl@0
   261
				RDebug::Print(_L("Timeout"));
sl@0
   262
				return TestFailed(KErrAbort, _L("Timeout"));
sl@0
   263
				}
sl@0
   264
			
sl@0
   265
			if(iBusRequestCounter > 0){
sl@0
   266
				test.Printf(_L("VBus present, attempting a swap.\n"));
sl@0
   267
				iCollector.AddRequiredNotification(EWatcherState, RUsbOtgDriver::EStateBHost);
sl@0
   268
				
sl@0
   269
				iBusRequestCounter --;
sl@0
   270
				err = otgBusRequest();	//	Request the host role
sl@0
   271
				if (KErrNone != err)
sl@0
   272
					{
sl@0
   273
					test.Printf(_L("BusRequest returned %d\n"),err);
sl@0
   274
					return TestFailed(KErrAbort, _L("BusRequest() failed!"));
sl@0
   275
					}
sl@0
   276
				iCaseStep = EBToHost;
sl@0
   277
			}
sl@0
   278
			else{
sl@0
   279
				iCollector.AddRequiredNotification(EWatcherAConnectionIdle, RUsbOtgDriver::EConnectionIdle);
sl@0
   280
				iCaseStep = EIdleHostPriorToVBusDown;
sl@0
   281
			}	
sl@0
   282
			SetActive();
sl@0
   283
			break;
sl@0
   284
			}
sl@0
   285
			
sl@0
   286
		case EAToHost:
sl@0
   287
			{
sl@0
   288
			test.Printf(_L("Into EAToHost step...\n"));
sl@0
   289
			if (KTestCaseWatchdogTO == iStatus.Int())
sl@0
   290
				{
sl@0
   291
				iCollector.DestroyObservers();
sl@0
   292
				return TestFailed(KErrAbort, _L("Timeout"));
sl@0
   293
				}
sl@0
   294
			
sl@0
   295
			if( ! iIsTimeToDrop){
sl@0
   296
				iIsTimeToDrop = ETrue;
sl@0
   297
				SetMaxPowerToL(50);
sl@0
   298
				TUint16 val = 0;
sl@0
   299
				GetMaxPower(val);
sl@0
   300
				test.Printf(_L("bMaxPower= %d\n"), val);
sl@0
   301
				iCollector.AddRequiredNotification(EWatcherState, RUsbOtgDriver::EStateAPeripheral);
sl@0
   302
				iCaseStep = EAToPeripheral;
sl@0
   303
			}
sl@0
   304
			else{
sl@0
   305
				iCollector.AddRequiredNotification(EWatcherAConnectionIdle, RUsbOtgDriver::EConnectionIdle);
sl@0
   306
				iCaseStep = EIdleHostPriorToVBusDown;
sl@0
   307
			}
sl@0
   308
			
sl@0
   309
			SetActive();
sl@0
   310
			break;			
sl@0
   311
			}
sl@0
   312
			
sl@0
   313
		case EAToPeripheral:
sl@0
   314
			{
sl@0
   315
			test.Printf(_L("Into EAToPeripheral step...\n"));
sl@0
   316
			if (KTestCaseWatchdogTO == iStatus.Int())
sl@0
   317
				{
sl@0
   318
				iCollector.DestroyObservers();
sl@0
   319
				return TestFailed(KErrAbort, _L("Timeout"));
sl@0
   320
				}
sl@0
   321
			iCollector.AddRequiredNotification(EWatcherState, RUsbOtgDriver::EStateAHost);
sl@0
   322
			iCaseStep = EAToHost;
sl@0
   323
			SetActive();
sl@0
   324
			break;
sl@0
   325
			}
sl@0
   326
		
sl@0
   327
		case EBToHost:
sl@0
   328
			{
sl@0
   329
			test.Printf(_L("Into EBToHost step...\n"));
sl@0
   330
			if (KTestCaseWatchdogTO == iStatus.Int())
sl@0
   331
				{
sl@0
   332
				iCollector.DestroyObservers();
sl@0
   333
				return TestFailed(KErrAbort, _L("Timeout"));
sl@0
   334
				}
sl@0
   335
			iCollector.AddRequiredNotification(EWatcherState, RUsbOtgDriver::EStateBPeripheral);
sl@0
   336
			iCaseStep = EBToPeripheral;
sl@0
   337
			SetActive();
sl@0
   338
			break;
sl@0
   339
			}
sl@0
   340
			
sl@0
   341
		case EBToPeripheral:
sl@0
   342
			{
sl@0
   343
			test.Printf(_L("Into EBToPeripheral step...\n"));
sl@0
   344
			if (KTestCaseWatchdogTO == iStatus.Int())
sl@0
   345
				{
sl@0
   346
				iCollector.DestroyObservers();
sl@0
   347
				return TestFailed(KErrAbort, _L("Timeout"));
sl@0
   348
				}
sl@0
   349
			if(iBusRequestCounter > 0)
sl@0
   350
				{
sl@0
   351
				iCollector.AddRequiredNotification(EWatcherPeripheralState, EUsbcDeviceStateConfigured);
sl@0
   352
				iCaseStep = EBConfigured;
sl@0
   353
				}
sl@0
   354
			else
sl@0
   355
				{
sl@0
   356
				iCollector.AddRequiredNotification(EWatcherEvent, RUsbOtgDriver::EEventVbusDropped);
sl@0
   357
				iCaseStep = EVBusDropped;
sl@0
   358
				}
sl@0
   359
			SetActive();
sl@0
   360
			break;
sl@0
   361
			}
sl@0
   362
			
sl@0
   363
		case EIdleHostPriorToVBusDown:
sl@0
   364
			{
sl@0
   365
			test.Printf(_L("Into EAIdleHostPriorToVBusDown step...\n"));
sl@0
   366
			
sl@0
   367
			if (KTestCaseWatchdogTO == iStatus.Int())
sl@0
   368
				{
sl@0
   369
				iCollector.DestroyObservers();
sl@0
   370
				return TestFailed(KErrAbort, _L("Timeout"));
sl@0
   371
				}			
sl@0
   372
	
sl@0
   373
			iCaseStep = EDropVBus;
sl@0
   374
			SelfComplete();
sl@0
   375
			break;
sl@0
   376
			}
sl@0
   377
			
sl@0
   378
		case EDropVBus:
sl@0
   379
			LOG_STEPNAME(_L("EDropVBus"))
sl@0
   380
			if (KTestCaseWatchdogTO == iStatus.Int())
sl@0
   381
				{
sl@0
   382
				iCollector.DestroyObservers();
sl@0
   383
				return TestFailed(KErrAbort, _L("Timeout"));
sl@0
   384
				}			
sl@0
   385
sl@0
   386
			iCollector.AddRequiredNotification(EWatcherEvent, RUsbOtgDriver::EEventVbusDropped);
sl@0
   387
			if ( gTestRoleMaster)
sl@0
   388
				{
sl@0
   389
				iCollector.AddRequiredNotification(EWatcherState, RUsbOtgDriver::EStateBIdle);
sl@0
   390
				}
sl@0
   391
			else
sl@0
   392
				{ // SLAVE "A"
sl@0
   393
				otgBusDrop();
sl@0
   394
				iCollector.AddRequiredNotification(EWatcherState, RUsbOtgDriver::EStateAIdle);
sl@0
   395
				}
sl@0
   396
			iCaseStep = EVBusDropped;
sl@0
   397
			SetActive();
sl@0
   398
			break;
sl@0
   399
			
sl@0
   400
		case EVBusDropped:
sl@0
   401
			LOG_STEPNAME(_L("ELoopVerifyDrop"))
sl@0
   402
			if (KTestCaseWatchdogTO == iStatus.Int())
sl@0
   403
				{
sl@0
   404
				return TestFailed(KErrAbort, _L("Timeout"));
sl@0
   405
				}
sl@0
   406
				
sl@0
   407
			if (otgVbusPresent())
sl@0
   408
				{
sl@0
   409
				return TestFailed(KErrAbort, _L("Vbus did not drop - FAILED!"));
sl@0
   410
				}
sl@0
   411
			iCaseStep = EUnloadLdd;
sl@0
   412
			SelfComplete();
sl@0
   413
			break;
sl@0
   414
			
sl@0
   415
		case EUnloadLdd:
sl@0
   416
			LOG_STEPNAME(_L("EUnloadLdd"))
sl@0
   417
			otgDeactivateFdfActor();
sl@0
   418
			iCollector.DestroyObservers();
sl@0
   419
			if (EFalse == StepUnloadLDD()){
sl@0
   420
				return TestFailed(KErrAbort,_L("unload Ldd failure"));
sl@0
   421
			}
sl@0
   422
			if (!StepUnloadClient()){
sl@0
   423
				return TestFailed(KErrAbort,_L("Client Unload Failure"));
sl@0
   424
			}
sl@0
   425
sl@0
   426
			iCaseStep = ELastStep;
sl@0
   427
			SelfComplete();
sl@0
   428
			break;
sl@0
   429
			
sl@0
   430
		case ELastStep:
sl@0
   431
			LOG_STEPNAME(_L("ELastStep"))
sl@0
   432
			TestPassed();
sl@0
   433
			RequestCharacter();	
sl@0
   434
			break;
sl@0
   435
			
sl@0
   436
		default:
sl@0
   437
			test.Printf(_L("<Error> unknown test step"));
sl@0
   438
			Cancel();
sl@0
   439
			RequestCharacter();	
sl@0
   440
			return (TestFailed(KErrCorrupt, _L("<Error> unknown test step")));
sl@0
   441
		}
sl@0
   442
	
sl@0
   443
	}