os/kernelhwsrv/kerneltest/e32test/usbho/t_otgdi/src/testcase0465.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 "testcase0465.h"
sl@0
    27
sl@0
    28
sl@0
    29
sl@0
    30
sl@0
    31
// the name below is used to add a pointer to our construction method to a pointer MAP in 
sl@0
    32
// the class factory
sl@0
    33
_LIT(KTestCaseId,"PBASE-USB_OTGDI-0465");
sl@0
    34
const TTestCaseFactoryReceipt<CTestCase0465> CTestCase0465::iFactoryReceipt(KTestCaseId);	
sl@0
    35
sl@0
    36
CTestCase0465* CTestCase0465::NewL(TBool aHost)
sl@0
    37
	{
sl@0
    38
	LOG_FUNC
sl@0
    39
	CTestCase0465* self = new (ELeave) CTestCase0465(aHost);
sl@0
    40
	CleanupStack::PushL(self);
sl@0
    41
	self->ConstructL();
sl@0
    42
	CleanupStack::Pop(self);
sl@0
    43
	return self;
sl@0
    44
	}
sl@0
    45
	
sl@0
    46
sl@0
    47
CTestCase0465::CTestCase0465(TBool aHost)
sl@0
    48
:	CTestCaseRoot(KTestCaseId, aHost)
sl@0
    49
	{
sl@0
    50
	LOG_FUNC
sl@0
    51
		
sl@0
    52
	} 
sl@0
    53
sl@0
    54
sl@0
    55
/**
sl@0
    56
 ConstructL
sl@0
    57
*/
sl@0
    58
void CTestCase0465::ConstructL()
sl@0
    59
	{
sl@0
    60
	LOG_FUNC
sl@0
    61
	iWDTimer = CTestCaseWatchdog::NewL();
sl@0
    62
	
sl@0
    63
	BaseConstructL();
sl@0
    64
	}
sl@0
    65
sl@0
    66
sl@0
    67
CTestCase0465::~CTestCase0465()
sl@0
    68
	{
sl@0
    69
	LOG_FUNC
sl@0
    70
sl@0
    71
	Cancel();
sl@0
    72
	delete iWDTimer;
sl@0
    73
	
sl@0
    74
	}
sl@0
    75
sl@0
    76
sl@0
    77
void CTestCase0465::ExecuteTestCaseL()
sl@0
    78
	{
sl@0
    79
	LOG_FUNC
sl@0
    80
	iCaseStep = EPreconditions;
sl@0
    81
	
sl@0
    82
	iRepeats = KOperationRetriesMax;	// VBus event rise retries
sl@0
    83
	
sl@0
    84
	CActiveScheduler::Add(this);
sl@0
    85
	SelfComplete();
sl@0
    86
sl@0
    87
	}
sl@0
    88
sl@0
    89
	
sl@0
    90
void CTestCase0465::DoCancel()
sl@0
    91
	{
sl@0
    92
	LOG_FUNC
sl@0
    93
sl@0
    94
	// cancel our timer
sl@0
    95
	iTimer.Cancel();
sl@0
    96
	}
sl@0
    97
sl@0
    98
sl@0
    99
void CTestCase0465::CancelKB(CTestCaseRoot *pThis)
sl@0
   100
	{
sl@0
   101
	CTestCase0465 * p = REINTERPRET_CAST(CTestCase0465 *,pThis);
sl@0
   102
	// cancel the pending call
sl@0
   103
sl@0
   104
	p->iConsole->ReadCancel();
sl@0
   105
sl@0
   106
	}
sl@0
   107
sl@0
   108
sl@0
   109
void CTestCase0465::CancelDrive(CTestCaseRoot *pThis)
sl@0
   110
	{
sl@0
   111
	CTestCase0465 * p = REINTERPRET_CAST(CTestCase0465 *,pThis);
sl@0
   112
	// cancel any pending call, and then complete our active obj with a timeout value
sl@0
   113
	p->SelfComplete(KTestCaseWatchdogTO);	
sl@0
   114
	}
sl@0
   115
sl@0
   116
sl@0
   117
// This test result depends on all the ID detection tests and the VBus driving and dropping tests have not yet passed
sl@0
   118
void CTestCase0465::DescribePreconditions()
sl@0
   119
	{
sl@0
   120
	test.Printf(_L("BEFORE running this test\n"));
sl@0
   121
	test.Printf(_L("\n"));
sl@0
   122
	test.Printf(_L("Insert 'A' connector\n"));
sl@0
   123
	test.Printf(_L("\n"));
sl@0
   124
	test.Printf(_L("Confirm passing tests\n"));
sl@0
   125
	test.Printf(_L("\n"));
sl@0
   126
	test.Printf(_L("ID_PIN detection\n"));
sl@0
   127
	test.Printf(_L("VBus Driving\n"));
sl@0
   128
	test.Printf(_L("\n"));
sl@0
   129
	}
sl@0
   130
		
sl@0
   131
sl@0
   132
// handle event completion	
sl@0
   133
void CTestCase0465::RunStepL()
sl@0
   134
	{
sl@0
   135
	LOG_FUNC
sl@0
   136
	// Obtain the completion code for this CActive obj.
sl@0
   137
	TInt completionCode(iStatus.Int()); 
sl@0
   138
	TBuf<MAX_DSTRLEN> aDescription;
sl@0
   139
	TInt err(0);
sl@0
   140
		
sl@0
   141
	switch(iCaseStep)
sl@0
   142
		{
sl@0
   143
		case EPreconditions:
sl@0
   144
			iCaseStep = ELoadLdd;
sl@0
   145
			if (iAutomated)
sl@0
   146
				{
sl@0
   147
				iCaseStep = ELoadLdd;
sl@0
   148
				SelfComplete();
sl@0
   149
				break;
sl@0
   150
				}
sl@0
   151
			// prompt to insert connector
sl@0
   152
			test.Printf(_L("\n"));
sl@0
   153
			test.Printf(KInsertAConnectorPrompt);
sl@0
   154
			test.Printf(_L("\n"));
sl@0
   155
			test.Printf(KPressAnyKeyToContinue);
sl@0
   156
			test.Printf(_L("\n"));
sl@0
   157
			RequestCharacter();			
sl@0
   158
			break;
sl@0
   159
			
sl@0
   160
		case ELoadLdd:
sl@0
   161
			// 1. load the LDD and init.
sl@0
   162
			if (!StepLoadLDD())
sl@0
   163
				{
sl@0
   164
				break;
sl@0
   165
				}
sl@0
   166
			iCaseStep = EDriveVBus;
sl@0
   167
			SelfComplete();
sl@0
   168
			break;
sl@0
   169
			
sl@0
   170
		case EDriveVBus:
sl@0
   171
			// 2. DRIVE VBUS
sl@0
   172
			// wait for 100 ms to allow the stack time to settle
sl@0
   173
			User::After(100000);
sl@0
   174
			err = otgBusRequest();
sl@0
   175
			if (KErrNone != err)
sl@0
   176
				{
sl@0
   177
				return TestFailed(KErrAbort, _L("Raise VBus - RUsbOtgDriver::BusRequest() FAILED!"));
sl@0
   178
				}
sl@0
   179
sl@0
   180
			// wait for 1000 ms as per test document
sl@0
   181
			User::After(1000000);
sl@0
   182
sl@0
   183
			// test for VBus rise next
sl@0
   184
			otgQueueOtgEventRequest( iOTGEvent, iStatus );
sl@0
   185
			SetActive();
sl@0
   186
			iCaseStep = EVerifyVBus;
sl@0
   187
			break;
sl@0
   188
			
sl@0
   189
		case EVerifyVBus:
sl@0
   190
			// 3. get VBus rise event
sl@0
   191
			iCaseStep = EUnloadLdd;
sl@0
   192
			OtgEventString(iOTGEvent, aDescription);
sl@0
   193
			test.Printf(_L("Received event %d '%S' status(%d)\n"), iOTGEvent, &aDescription, completionCode);
sl@0
   194
			
sl@0
   195
			if (iOTGEvent != RUsbOtgDriver::EEventVbusRaised)
sl@0
   196
				{
sl@0
   197
				iCaseStep = EVerifyVBus;
sl@0
   198
				iRepeats--;
sl@0
   199
				if (iRepeats <0)
sl@0
   200
					{
sl@0
   201
					return TestFailed(KErrAbort, _L("Raise VBus event not detected. FAILED!"));
sl@0
   202
					}
sl@0
   203
sl@0
   204
				otgQueueOtgEventRequest( iOTGEvent, iStatus );
sl@0
   205
				SetActive();				
sl@0
   206
				break;	
sl@0
   207
				}
sl@0
   208
			test.Printf(_L("VBus seen OK.\n"));
sl@0
   209
			
sl@0
   210
			SelfComplete();
sl@0
   211
			break;
sl@0
   212
			
sl@0
   213
		case EUnloadLdd:
sl@0
   214
			// unload
sl@0
   215
			if (EFalse == StepUnloadLDD())
sl@0
   216
				{
sl@0
   217
				return TestFailed(KErrAbort,_L("unload Ldd failure"));	
sl@0
   218
				}	
sl@0
   219
			
sl@0
   220
			// wait for 100 ms to allow the stack time to settle
sl@0
   221
			User::After(100000);
sl@0
   222
			
sl@0
   223
			test.Printf(_L("Use meter or oscilloscope\n"));
sl@0
   224
			test.Printf(_L("to measure VBUS, which should\n"));
sl@0
   225
			test.Printf(_L("have dropped\n"));
sl@0
   226
			test.Printf(_L("\n"));
sl@0
   227
			test.Printf(_L("Is it below 0.2 volts?\n"));
sl@0
   228
			test.Printf(_L("\n"));
sl@0
   229
			test.Printf(_L("Select Y or N to continue\n"));
sl@0
   230
			RequestCharacter();
sl@0
   231
			iWDTimer->IssueRequest(KDelayDurationForUserActivityMS, this, &CancelKB);
sl@0
   232
			iCaseStep = EVerifyBusGone;
sl@0
   233
			break;
sl@0
   234
			
sl@0
   235
		case EVerifyBusGone:
sl@0
   236
			// since the LDD is gone, there is no OTGDI API from here on
sl@0
   237
			if (KTestCaseWatchdogTO == iStatus.Int())
sl@0
   238
				{
sl@0
   239
				return TestFailed(KErrAbort, _L("Operator response timeout"));
sl@0
   240
				}
sl@0
   241
			iWDTimer->Cancel();
sl@0
   242
			// user intput
sl@0
   243
			if (('y' == iKeyCodeInput) ||('Y' == iKeyCodeInput))
sl@0
   244
				{
sl@0
   245
				test.Printf(_L("VBUS 'drop' seen\n"));
sl@0
   246
				SelfComplete();
sl@0
   247
				}
sl@0
   248
			else
sl@0
   249
				{
sl@0
   250
				return TestFailed(KErrAbort, _L("VBus drop NOT 'seen' - FAILED!"));
sl@0
   251
				}
sl@0
   252
			iCaseStep = ELastStep;
sl@0
   253
			break;
sl@0
   254
			
sl@0
   255
		case ELastStep:
sl@0
   256
			TestPassed();
sl@0
   257
			break;
sl@0
   258
			
sl@0
   259
		default:
sl@0
   260
			test.Printf(_L("<Error> unknown test step\n"));
sl@0
   261
			Cancel();
sl@0
   262
			return (TestFailed(KErrCorrupt, _L("<Error> unknown test step")));
sl@0
   263
		}
sl@0
   264
	}
sl@0
   265
sl@0
   266