os/kernelhwsrv/kerneltest/e32test/usbho/t_otgdi/src/testcase1233.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 "testcase1233.h"
sl@0
    27
sl@0
    28
#include <e32debug.h> 
sl@0
    29
sl@0
    30
#define LOG_INTO_STEP(a) test.Printf(_L("\nInto Step [%S]\n\n"), &a);
sl@0
    31
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
 */
sl@0
    36
_LIT(KTestCaseId,"PBASE-USB_OTGDI-1233");
sl@0
    37
const TTestCaseFactoryReceipt<CTestCase1233> CTestCase1233::iFactoryReceipt(KTestCaseId);	
sl@0
    38
sl@0
    39
CTestCase1233* CTestCase1233::NewL(TBool aHost)
sl@0
    40
	{
sl@0
    41
	LOG_FUNC
sl@0
    42
	CTestCase1233* self = new (ELeave) CTestCase1233(aHost);
sl@0
    43
	CleanupStack::PushL(self);
sl@0
    44
	self->ConstructL();
sl@0
    45
	CleanupStack::Pop(self);
sl@0
    46
	return self;
sl@0
    47
	}
sl@0
    48
	
sl@0
    49
sl@0
    50
CTestCase1233::CTestCase1233(TBool aHost)
sl@0
    51
	: CTestCaseB2BRoot(KTestCaseId, aHost, iStatus) 
sl@0
    52
	{
sl@0
    53
	LOG_FUNC
sl@0
    54
		
sl@0
    55
	} 
sl@0
    56
sl@0
    57
sl@0
    58
/**
sl@0
    59
 ConstructL
sl@0
    60
*/
sl@0
    61
void CTestCase1233::ConstructL()
sl@0
    62
	{
sl@0
    63
	LOG_FUNC
sl@0
    64
sl@0
    65
	iTestVID = 0x0E22;		// Symbian
sl@0
    66
	iTestPID = 0xF000 + 1233; // Test 1233
sl@0
    67
	
sl@0
    68
	BaseConstructL();
sl@0
    69
	}
sl@0
    70
sl@0
    71
sl@0
    72
CTestCase1233::~CTestCase1233()
sl@0
    73
	{
sl@0
    74
	LOG_FUNC
sl@0
    75
	iCollector.DestroyObservers();
sl@0
    76
	Cancel();
sl@0
    77
	}
sl@0
    78
sl@0
    79
sl@0
    80
void CTestCase1233::ExecuteTestCaseL()
sl@0
    81
	{
sl@0
    82
	LOG_FUNC
sl@0
    83
	iCaseStep = EPreconditions;
sl@0
    84
	CActiveScheduler::Add(this);
sl@0
    85
	SelfComplete();
sl@0
    86
	}
sl@0
    87
sl@0
    88
	
sl@0
    89
void CTestCase1233::DoCancel()
sl@0
    90
	{
sl@0
    91
	LOG_FUNC
sl@0
    92
	// cancel our timer
sl@0
    93
	iTimer.Cancel();
sl@0
    94
	}
sl@0
    95
sl@0
    96
sl@0
    97
void CTestCase1233::RunStepL()
sl@0
    98
	{
sl@0
    99
	LOG_FUNC
sl@0
   100
	
sl@0
   101
	// Obtain the completion code for this CActive obj.
sl@0
   102
	TInt completionCode(iStatus.Int()); 
sl@0
   103
	TBuf<MAX_DSTRLEN> aDescription;
sl@0
   104
sl@0
   105
	switch(iCaseStep)
sl@0
   106
		{
sl@0
   107
		/*==================================================*/
sl@0
   108
		/* Fixed 'pre' steps								*/
sl@0
   109
		/*==================================================*/
sl@0
   110
		case EPreconditions:
sl@0
   111
			{
sl@0
   112
			LOG_INTO_STEP(_L("EPreconditions"))
sl@0
   113
		
sl@0
   114
			iCaseStep = ELoadLdd;
sl@0
   115
			StepB2BPreconditions();	
sl@0
   116
			break;
sl@0
   117
			}
sl@0
   118
			
sl@0
   119
		case ELoadLdd:
sl@0
   120
			{
sl@0
   121
			LOG_INTO_STEP(_L("ELoadLdd"))
sl@0
   122
			
sl@0
   123
			// Note we use here the hex equivalent of #1233 for the PID
sl@0
   124
sl@0
   125
			if (!StepLoadClient(0xF4D1/*use default settings for SRP/HNP support*/))
sl@0
   126
				{
sl@0
   127
				return TestFailed(KErrAbort, _L("Client Load Failure"));
sl@0
   128
				}
sl@0
   129
			
sl@0
   130
			//  load OTG ldd and init.		
sl@0
   131
			if (!StepLoadLDD())
sl@0
   132
				{
sl@0
   133
				return TestFailed(KErrAbort, _L("OTG Load Failure"));
sl@0
   134
				}
sl@0
   135
				
sl@0
   136
			if(otgActivateFdfActor()!=KErrNone)
sl@0
   137
				{
sl@0
   138
				return TestFailed(KErrAbort, _L("Couldn't load FDF Actor"));
sl@0
   139
				}
sl@0
   140
			
sl@0
   141
			// test that the right cable is in
sl@0
   142
			CheckRoleConnections();
sl@0
   143
					
sl@0
   144
			// subscribe to OTG states,events and messages now that it has loaded OK
sl@0
   145
			TRAPD(result, iCollector.CreateObserversL(*this));
sl@0
   146
			if (KErrNone != result)
sl@0
   147
				{
sl@0
   148
				return(TestFailed(KErrNoMemory, _L("Unable to create observers")));
sl@0
   149
				}
sl@0
   150
sl@0
   151
			// Allow enough time for 8 enumerations, say a second each, plus two of the
sl@0
   152
			// tests require 15 seconds of SOF traffic
sl@0
   153
			
sl@0
   154
			const TInt KTestCase1233Timeout = 45000;
sl@0
   155
			iCollector.AddStepTimeout(KTestCase1233Timeout);
sl@0
   156
sl@0
   157
			iCollector.ClearAllEvents();
sl@0
   158
			iCaseStep = ERaiseVBus;
sl@0
   159
sl@0
   160
			SelfComplete();
sl@0
   161
			break;
sl@0
   162
			}
sl@0
   163
			
sl@0
   164
		/*==================================================*/
sl@0
   165
		/* Steps for this test case only					*/
sl@0
   166
		/*==================================================*/
sl@0
   167
		
sl@0
   168
		case ELoopToNextPID:
sl@0
   169
			{
sl@0
   170
			LOG_INTO_STEP(_L("ELoopToNextPID"));
sl@0
   171
			
sl@0
   172
			if (KTestCaseWatchdogTO == iStatus.Int())
sl@0
   173
				{
sl@0
   174
				iCollector.DestroyObservers();
sl@0
   175
				return TestFailed(KErrAbort, _L("Timeout"));
sl@0
   176
				}
sl@0
   177
			
sl@0
   178
			if ( iTestVID == 0x0E22 )
sl@0
   179
				{
sl@0
   180
				iTestVID = 0x1A0A;	// OPT and test devices
sl@0
   181
				iTestPID = 0x0100; 	// One *before* the first HS test ID
sl@0
   182
				}
sl@0
   183
sl@0
   184
			iTestPID++;
sl@0
   185
			
sl@0
   186
			if ( iTestPID > 0x0108 )
sl@0
   187
				{
sl@0
   188
				test.Printf(_L("All VID/PID pairs done\n"));
sl@0
   189
				
sl@0
   190
				iCaseStep = EUnloadLdd;
sl@0
   191
				}
sl@0
   192
			else
sl@0
   193
				{
sl@0
   194
				if(gTestRoleMaster)
sl@0
   195
					{
sl@0
   196
					// B
sl@0
   197
					test.Printf(_L("Setting VID/PID of 0x%04x/0x%04x\n"),iTestVID,iTestPID);
sl@0
   198
					
sl@0
   199
					if (!StepChangeVidPid(iTestVID,iTestPID))
sl@0
   200
						{
sl@0
   201
						return TestFailed(KErrAbort, _L("VID/PID Change Failure"));
sl@0
   202
						}
sl@0
   203
					}
sl@0
   204
				else
sl@0
   205
					{
sl@0
   206
					// A
sl@0
   207
					test.Printf(_L("Expecting VID/PID of 0x%04x/0x%04x\n"),iTestVID,iTestPID);
sl@0
   208
					}
sl@0
   209
				
sl@0
   210
				iCollector.ClearAllEvents();
sl@0
   211
				iCaseStep = ERaiseVBus;
sl@0
   212
				}
sl@0
   213
			
sl@0
   214
			SelfComplete();
sl@0
   215
			break;			
sl@0
   216
			}
sl@0
   217
sl@0
   218
		case ERaiseVBus:
sl@0
   219
			{
sl@0
   220
			LOG_INTO_STEP(_L("ERaiseVBus"));
sl@0
   221
			
sl@0
   222
			if (KTestCaseWatchdogTO == iStatus.Int())
sl@0
   223
				{
sl@0
   224
				iCollector.DestroyObservers();
sl@0
   225
				return TestFailed(KErrAbort, _L("Timeout"));
sl@0
   226
				}			
sl@0
   227
sl@0
   228
			if (gTestRoleMaster)
sl@0
   229
				{
sl@0
   230
				// B device
sl@0
   231
				iCollector.AddRequiredNotification(EWatcherEvent, RUsbOtgDriver::EEventVbusRaised);
sl@0
   232
				iCollector.AddRequiredNotification(EWatcherState, RUsbOtgDriver::EStateBPeripheral);
sl@0
   233
				iCollector.AddRequiredNotification(EWatcherPeripheralState, EUsbcDeviceStateDefault);
sl@0
   234
				iCollector.AddRequiredNotification(EWatcherPeripheralState, EUsbcDeviceStateAddress);
sl@0
   235
				iCollector.AddRequiredNotification(EWatcherEvent, RUsbOtgDriver::EEventHnpEnabled);
sl@0
   236
				iCollector.AddRequiredNotification(EWatcherPeripheralState, EUsbcDeviceStateConfigured);
sl@0
   237
				}
sl@0
   238
			else
sl@0
   239
				{ 
sl@0
   240
				// A device
sl@0
   241
				test.Printf(_L("Raising VBUS for VID/PID = 0x%04x/0x%04x\n"),iTestVID,iTestPID);
sl@0
   242
				
sl@0
   243
				if ( otgBusRequest() != KErrNone )
sl@0
   244
					{
sl@0
   245
					return TestFailed(KErrAbort, _L("Raise Vbus - RUsbOtgDriver::BusRequest() FAILED!"));
sl@0
   246
					}
sl@0
   247
				
sl@0
   248
				iCollector.AddRequiredNotification(EWatcherEvent, RUsbOtgDriver::EEventVbusRaised);
sl@0
   249
				iCollector.AddRequiredNotification(EWatcherAConnectionIdle, RUsbOtgDriver::EConnectionBusy);
sl@0
   250
				iCollector.AddRequiredNotification(EWatcherState, RUsbOtgDriver::EStateAHost);
sl@0
   251
				}
sl@0
   252
			
sl@0
   253
			iCaseStep = EVBusRaised;
sl@0
   254
			SetActive();
sl@0
   255
			break;
sl@0
   256
			}
sl@0
   257
			
sl@0
   258
		case EVBusRaised:
sl@0
   259
			{
sl@0
   260
			LOG_INTO_STEP(_L("EVBusRaised"));
sl@0
   261
sl@0
   262
			if (KTestCaseWatchdogTO == iStatus.Int())
sl@0
   263
				{
sl@0
   264
				return TestFailed(KErrAbort, _L("Timeout"));
sl@0
   265
				}
sl@0
   266
sl@0
   267
			if ( otgVbusPresent() )
sl@0
   268
				{
sl@0
   269
				test.Printf(_L("...VBUS is UP\n"));
sl@0
   270
				iCaseStep = EDropVBus;
sl@0
   271
				}
sl@0
   272
			else
sl@0
   273
				{
sl@0
   274
				test.Printf(_L("...VBUS is DOWN\n"));
sl@0
   275
				return TestFailed(KErrAbort, _L("Vbus did not rise - FAILED!"));
sl@0
   276
				}
sl@0
   277
sl@0
   278
			if (gTestRoleMaster)
sl@0
   279
				{
sl@0
   280
				// B device
sl@0
   281
				SelfComplete();
sl@0
   282
				}
sl@0
   283
			else
sl@0
   284
				{ 
sl@0
   285
				// A device
sl@0
   286
				
sl@0
   287
				// The default device (0x0E22/0xB4D1) is passed to the FDF, which will (eventually)
sl@0
   288
				// suspend and enter connection idle state.
sl@0
   289
				
sl@0
   290
				// The HS test devices (0x1A0A) will not be presented to FDF, so there will be no
sl@0
   291
				// trailing connection idle to find.
sl@0
   292
				
sl@0
   293
				if ( iTestVID == 0x0E22 )
sl@0
   294
					{
sl@0
   295
					iCollector.AddRequiredNotification(EWatcherAConnectionIdle, RUsbOtgDriver::EConnectionIdle);
sl@0
   296
					SetActive();
sl@0
   297
					}
sl@0
   298
				else
sl@0
   299
					{
sl@0
   300
					SelfComplete();
sl@0
   301
					}
sl@0
   302
				}
sl@0
   303
sl@0
   304
			break;
sl@0
   305
			}
sl@0
   306
			
sl@0
   307
		case EDropVBus:
sl@0
   308
			{
sl@0
   309
			LOG_INTO_STEP(_L("EDropVBus"));
sl@0
   310
			
sl@0
   311
			if (KTestCaseWatchdogTO == iStatus.Int())
sl@0
   312
				{
sl@0
   313
				iCollector.DestroyObservers();
sl@0
   314
				return TestFailed(KErrAbort, _L("Timeout"));
sl@0
   315
				}			
sl@0
   316
sl@0
   317
			if ( gTestRoleMaster)
sl@0
   318
				{
sl@0
   319
				// B device
sl@0
   320
				iCollector.AddRequiredNotification(EWatcherEvent, RUsbOtgDriver::EEventVbusDropped);
sl@0
   321
				}
sl@0
   322
			else
sl@0
   323
				{
sl@0
   324
				// A device
sl@0
   325
				otgBusDrop();
sl@0
   326
				
sl@0
   327
				iCollector.AddRequiredNotification(EWatcherEvent, RUsbOtgDriver::EEventVbusDropped);
sl@0
   328
				}
sl@0
   329
			
sl@0
   330
			iCaseStep = EVBusDropped;
sl@0
   331
			SetActive();
sl@0
   332
			break;
sl@0
   333
			}
sl@0
   334
			
sl@0
   335
		case EVBusDropped:
sl@0
   336
			{
sl@0
   337
			LOG_INTO_STEP(_L("EVBusDropped"));
sl@0
   338
sl@0
   339
			if (KTestCaseWatchdogTO == iStatus.Int())
sl@0
   340
				{
sl@0
   341
				return TestFailed(KErrAbort, _L("Timeout"));
sl@0
   342
				}
sl@0
   343
sl@0
   344
			if ( otgVbusPresent() )
sl@0
   345
				{
sl@0
   346
				test.Printf(_L("...VBUS is UP\n"));
sl@0
   347
				return TestFailed(KErrAbort, _L("Vbus did not rise - FAILED!"));
sl@0
   348
				}
sl@0
   349
			else
sl@0
   350
				{
sl@0
   351
				test.Printf(_L("...VBUS is DOWN\n"));
sl@0
   352
				iCaseStep = ELoopToNextPID;
sl@0
   353
				}
sl@0
   354
sl@0
   355
			SelfComplete();
sl@0
   356
			break;
sl@0
   357
			}
sl@0
   358
			
sl@0
   359
		/*==================================================*/
sl@0
   360
		/* Fixed 'post' steps								*/
sl@0
   361
		/*==================================================*/
sl@0
   362
			
sl@0
   363
		case EUnloadLdd:
sl@0
   364
			{
sl@0
   365
			LOG_INTO_STEP(_L("EUnloadLdd"))
sl@0
   366
sl@0
   367
			otgDeactivateFdfActor();
sl@0
   368
			iCollector.DestroyObservers();
sl@0
   369
			if (EFalse == StepUnloadLDD()){
sl@0
   370
				return TestFailed(KErrAbort,_L("unload Ldd failure"));
sl@0
   371
			}
sl@0
   372
			if (!StepUnloadClient()){
sl@0
   373
				return TestFailed(KErrAbort,_L("Client Unload Failure"));
sl@0
   374
			}
sl@0
   375
sl@0
   376
			iCaseStep = ELastStep;
sl@0
   377
			SelfComplete();
sl@0
   378
			break;
sl@0
   379
			}
sl@0
   380
			
sl@0
   381
		case ELastStep:
sl@0
   382
			{
sl@0
   383
			LOG_INTO_STEP(_L("ELastStep"))
sl@0
   384
			
sl@0
   385
			TestPassed();
sl@0
   386
			RequestCharacter();	
sl@0
   387
			break;
sl@0
   388
			}
sl@0
   389
			
sl@0
   390
		default:
sl@0
   391
			{
sl@0
   392
			LOG_INTO_STEP(_L("DEFAULT! (unknown test step)"));
sl@0
   393
			Cancel();
sl@0
   394
			RequestCharacter();	
sl@0
   395
			return (TestFailed(KErrCorrupt, _L("<Error> unknown test step")));
sl@0
   396
			}
sl@0
   397
		}
sl@0
   398
	
sl@0
   399
	}