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