os/kernelhwsrv/kerneltest/e32test/usbho/t_otgdi/src/testcase0676.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 "testcase0676.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-0676");
sl@0
    35
const TTestCaseFactoryReceipt<CTestCase0676> CTestCase0676::iFactoryReceipt(KTestCaseId);	
sl@0
    36
sl@0
    37
CTestCase0676* CTestCase0676::NewL(TBool aHost)
sl@0
    38
	{
sl@0
    39
	LOG_FUNC
sl@0
    40
	CTestCase0676* self = new (ELeave) CTestCase0676(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
CTestCase0676::CTestCase0676(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 CTestCase0676::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
CTestCase0676::~CTestCase0676()
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 CTestCase0676::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 CTestCase0676::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 CTestCase0676::CancelKB(CTestCaseRoot *pThis)
sl@0
   102
	{
sl@0
   103
	LOG_FUNC
sl@0
   104
	CTestCase0676 * p = REINTERPRET_CAST(CTestCase0676 *,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 CTestCase0676::CancelNotify(CTestCaseRoot *pThis)
sl@0
   112
	{
sl@0
   113
	LOG_FUNC
sl@0
   114
	CTestCase0676 * p = REINTERPRET_CAST(CTestCase0676 *,pThis);
sl@0
   115
	// cancel any pending call, and then complete our active obj with a timeout value
sl@0
   116
	p->otgCancelOtgVbusNotification();
sl@0
   117
	p->SelfComplete(KTestCaseWatchdogTO);
sl@0
   118
	}
sl@0
   119
sl@0
   120
sl@0
   121
// This test result depends on all the ID detection tests and the VBus driving and dropping tests have not yet passed
sl@0
   122
void CTestCase0676::DescribePreconditions()
sl@0
   123
	{
sl@0
   124
	test.Printf(_L("Insert 'A' connector beforehand.\n"));
sl@0
   125
	}
sl@0
   126
sl@0
   127
void CTestCase0676::ContinueAfter(TTimeIntervalMicroSeconds32 aMicroSecs, TCaseSteps aStep)
sl@0
   128
	{
sl@0
   129
	LOG_VERBOSE2(_L("Wait %dms before drop VBus"), (TInt)(aMicroSecs.Int()/1000));
sl@0
   130
	iTimer.After(iStatus, aMicroSecs);
sl@0
   131
	iCaseStep = aStep;
sl@0
   132
	SetActive();
sl@0
   133
	}
sl@0
   134
sl@0
   135
// handle event completion	
sl@0
   136
void CTestCase0676::RunStepL()
sl@0
   137
	{
sl@0
   138
	LOG_FUNC
sl@0
   139
	// Obtain the completion code for this CActive obj.
sl@0
   140
	TInt completionCode(iStatus.Int()); 
sl@0
   141
	TBuf<MAX_DSTRLEN> aDescription;
sl@0
   142
	TInt err(0);
sl@0
   143
sl@0
   144
sl@0
   145
	switch(iCaseStep)
sl@0
   146
		{
sl@0
   147
		case EPreconditions:
sl@0
   148
			iCaseStep = ELoadLdd;
sl@0
   149
			if (iAutomated)
sl@0
   150
				{
sl@0
   151
				iCaseStep = ELoadLdd;
sl@0
   152
				SelfComplete();
sl@0
   153
				break;
sl@0
   154
				}
sl@0
   155
			// prompt to insert connector
sl@0
   156
			test.Printf(KInsertAConnectorPrompt);
sl@0
   157
			test.Printf(KPressAnyKeyToContinue);
sl@0
   158
			RequestCharacter();			
sl@0
   159
			break;
sl@0
   160
			
sl@0
   161
		case ELoadLdd:
sl@0
   162
			// 1. load the LDD and init.
sl@0
   163
			if (!StepLoadLDD())
sl@0
   164
				{
sl@0
   165
				break;
sl@0
   166
				}
sl@0
   167
			iCaseStep = EDetectAPlug;
sl@0
   168
			SelfComplete();
sl@0
   169
			break;
sl@0
   170
			
sl@0
   171
			// 2. detect 'A' plug now
sl@0
   172
		case EDetectAPlug:
sl@0
   173
			if (KTestCaseWatchdogTO == iStatus.Int())
sl@0
   174
				{
sl@0
   175
				return TestFailed(KErrAbort, _L("User response too slow - FAILED!"));
sl@0
   176
				}
sl@0
   177
sl@0
   178
			// if doing this test in /AUTO mode, we would fail this now
sl@0
   179
			// however if we can control ID_PIN through an API in future, we turn in on now.
sl@0
   180
			if (!otgIdPinPresent())
sl@0
   181
				{
sl@0
   182
				test.Printf(KInsertAConnectorPrompt);
sl@0
   183
				test.Printf(KPressAnyKeyToContinue);
sl@0
   184
				RequestCharacter();
sl@0
   185
sl@0
   186
				iCaseStep = EDetectAPlug;
sl@0
   187
				}
sl@0
   188
			else
sl@0
   189
				{
sl@0
   190
				iCaseStep = ELoopDriveVBus;
sl@0
   191
				SelfComplete();
sl@0
   192
				}
sl@0
   193
			break;
sl@0
   194
			
sl@0
   195
			// 3. Control/branch step in the loop
sl@0
   196
		case ELoopControl:
sl@0
   197
			if (--iRepeats)
sl@0
   198
				{
sl@0
   199
				iCaseStep = ELoopDriveVBus;
sl@0
   200
				}
sl@0
   201
			else
sl@0
   202
				{
sl@0
   203
				iCaseStep = EUnloadLdd;
sl@0
   204
				}
sl@0
   205
			SelfComplete();
sl@0
   206
			break;
sl@0
   207
			
sl@0
   208
		case ELoopDriveVBus:
sl@0
   209
			// 4. DRIVE VBUS
sl@0
   210
			iWDTimer->Cancel();
sl@0
   211
			test.Printf(_L("Drive VBus, iteration %d/%d\n"), OPEN_REPEATS-iRepeats+1, OPEN_REPEATS);
sl@0
   212
			// test for VBus rise next
sl@0
   213
			test.Printf(_L("Waiting for VBus Event\n"));
sl@0
   214
			iStatus = KRequestPending;
sl@0
   215
			otgQueueOtgVbusNotification( iOTGVBus, iStatus );
sl@0
   216
sl@0
   217
			// turn on VBus, since the call is not a Queing a-sync call we do this after the async call
sl@0
   218
			err = otgBusRequest();	// ok to turn on VBus now
sl@0
   219
			if (KErrNone != err)
sl@0
   220
				{
sl@0
   221
				return TestFailed(KErrAbort, _L("Raise Vbus - RUsbOtgDriver::BusRequest() FAILED!"));
sl@0
   222
				}
sl@0
   223
			iCaseStep = ELoopVerifyVBus;
sl@0
   224
			iWDTimer->IssueRequest(KDelayDurationForLocalTrigger, this, &CancelNotify);
sl@0
   225
			SetActive();
sl@0
   226
			break;
sl@0
   227
			
sl@0
   228
		case ELoopVerifyVBus:
sl@0
   229
			// 5. get VBus rise event
sl@0
   230
			if (KTestCaseWatchdogTO == iStatus.Int())
sl@0
   231
				{
sl@0
   232
				return TestFailed(KErrAbort, _L("Vbus rise not signalled in time - FAILED!"));
sl@0
   233
				}
sl@0
   234
			iWDTimer->Cancel();
sl@0
   235
sl@0
   236
			otgQueueOtgVbusNotification( iOTGVBus, iStatus );
sl@0
   237
			otgCancelOtgVbusNotification();
sl@0
   238
			User::WaitForRequest(iStatus);
sl@0
   239
sl@0
   240
sl@0
   241
			if (iOTGVBus != RUsbOtgDriver::EVbusHigh)
sl@0
   242
				{
sl@0
   243
		
sl@0
   244
				return TestFailed(KErrAbort, _L("Vbus rise NOT 'seen' - FAILED!"));
sl@0
   245
				}
sl@0
   246
sl@0
   247
			// Double-check using the API in a syncronous way too
sl@0
   248
			// NOTE: once again this is to explore timing issues
sl@0
   249
			if (!otgVbusPresent())
sl@0
   250
				{
sl@0
   251
				return TestFailed(KErrAbort, _L("Vbus syncronous call error - FAILED!"));
sl@0
   252
				}
sl@0
   253
			iCaseStep = ELoopWait;
sl@0
   254
			SelfComplete();
sl@0
   255
			break;
sl@0
   256
			
sl@0
   257
		case ELoopWait:	// 6. wait 50ms after applying Vbus before we are allowed to 
sl@0
   258
			ContinueAfter(KDelayBeforeBusDropUs, ELoopDropVBus);
sl@0
   259
			break;
sl@0
   260
			
sl@0
   261
		case ELoopDropVBus:
sl@0
   262
			// 7. drop Bus
sl@0
   263
			otgQueueOtgVbusNotification(iOTGVBus, iStatus );
sl@0
   264
			// drop Vbus now, since the call is not a Queing a-sync call we do this after the async call
sl@0
   265
			otgBusDrop();
sl@0
   266
			SetActive();
sl@0
   267
			iCaseStep = ELoopVerifyDrop;
sl@0
   268
			iWDTimer->IssueRequest(KDelayDurationForLocalTrigger, this, &CancelNotify);
sl@0
   269
			break;
sl@0
   270
			
sl@0
   271
		case ELoopVerifyDrop:
sl@0
   272
			// 8. get Vbus low event
sl@0
   273
			if (KTestCaseWatchdogTO == iStatus.Int())
sl@0
   274
				{
sl@0
   275
				return TestFailed(KErrAbort, _L("Vbus drop not signalled in time - FAILED!"));
sl@0
   276
				}
sl@0
   277
			iWDTimer->Cancel();
sl@0
   278
sl@0
   279
			// fetch the value			
sl@0
   280
			otgQueueOtgVbusNotification( iOTGVBus, iStatus );
sl@0
   281
			otgCancelOtgVbusNotification();
sl@0
   282
			User::WaitForRequest(iStatus);
sl@0
   283
sl@0
   284
			if (iOTGVBus != RUsbOtgDriver::EVbusLow)
sl@0
   285
				{
sl@0
   286
				return TestFailed(KErrAbort, _L("Vbus drop NOT 'seen' - FAILED!"));
sl@0
   287
				}
sl@0
   288
				
sl@0
   289
			// test again using the 'syncronous' variation
sl@0
   290
			if (otgVbusPresent())
sl@0
   291
				{
sl@0
   292
				return TestFailed(KErrAbort, _L("Vbus syncronous call error - FAILED!"));
sl@0
   293
				}
sl@0
   294
				
sl@0
   295
			// wait 50ms and then go back to beginning
sl@0
   296
			ContinueAfter(KDelayBeforeBusDropUs, ELoopControl);
sl@0
   297
			break;
sl@0
   298
			
sl@0
   299
		case EUnloadLdd:
sl@0
   300
			// 9. unload
sl@0
   301
			if (EFalse == StepUnloadLDD())
sl@0
   302
				return TestFailed(KErrAbort,_L("unload Ldd failure"));	
sl@0
   303
			
sl@0
   304
			iCaseStep = ELastStep;
sl@0
   305
			SelfComplete();
sl@0
   306
			break;
sl@0
   307
			
sl@0
   308
		case ELastStep:
sl@0
   309
			TestPassed();
sl@0
   310
			break;
sl@0
   311
			
sl@0
   312
		default:
sl@0
   313
			test.Printf(_L("<Error> unknown test step"));
sl@0
   314
			Cancel();
sl@0
   315
			return (TestFailed(KErrCorrupt, _L("<Error> unknown test step")));
sl@0
   316
		}
sl@0
   317
	}
sl@0
   318
sl@0
   319