os/kernelhwsrv/kerneltest/e32test/usbho/t_otgdi/src/testcase0466.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 "testcase0466.h"
sl@0
    27
sl@0
    28
sl@0
    29
sl@0
    30
// the name below is used to add a pointer to our construction method to a pointer MAP in 
sl@0
    31
// the class factory
sl@0
    32
_LIT(KTestCaseId,"PBASE-USB_OTGDI-0466");
sl@0
    33
const TTestCaseFactoryReceipt<CTestCase0466> CTestCase0466::iFactoryReceipt(KTestCaseId);	
sl@0
    34
sl@0
    35
CTestCase0466* CTestCase0466::NewL(TBool aHost)
sl@0
    36
	{
sl@0
    37
	LOG_FUNC
sl@0
    38
	CTestCase0466* self = new (ELeave) CTestCase0466(aHost);
sl@0
    39
	CleanupStack::PushL(self);
sl@0
    40
	self->ConstructL();
sl@0
    41
	CleanupStack::Pop(self);
sl@0
    42
	return self;
sl@0
    43
	}
sl@0
    44
	
sl@0
    45
sl@0
    46
CTestCase0466::CTestCase0466(TBool aHost)
sl@0
    47
:	CTestCaseRoot(KTestCaseId, aHost)
sl@0
    48
	{
sl@0
    49
	LOG_FUNC
sl@0
    50
		
sl@0
    51
	} 
sl@0
    52
sl@0
    53
sl@0
    54
/**
sl@0
    55
 ConstructL
sl@0
    56
*/
sl@0
    57
void CTestCase0466::ConstructL()
sl@0
    58
	{
sl@0
    59
	LOG_FUNC
sl@0
    60
	iWDTimer = CTestCaseWatchdog::NewL();
sl@0
    61
	
sl@0
    62
	BaseConstructL();
sl@0
    63
	}
sl@0
    64
sl@0
    65
sl@0
    66
CTestCase0466::~CTestCase0466()
sl@0
    67
	{
sl@0
    68
	LOG_FUNC
sl@0
    69
sl@0
    70
	Cancel();
sl@0
    71
	delete iWDTimer;
sl@0
    72
	}
sl@0
    73
sl@0
    74
sl@0
    75
void CTestCase0466::ExecuteTestCaseL()
sl@0
    76
	{
sl@0
    77
	LOG_FUNC
sl@0
    78
	iCaseStep = EPreconditions;
sl@0
    79
	
sl@0
    80
	iRepeats = KOperationRetriesMax;
sl@0
    81
	
sl@0
    82
	CActiveScheduler::Add(this);
sl@0
    83
	SelfComplete();
sl@0
    84
sl@0
    85
	}
sl@0
    86
sl@0
    87
sl@0
    88
void CTestCase0466::DescribePreconditions()
sl@0
    89
	{
sl@0
    90
	test.Printf(_L("BEFORE running this test\n"));
sl@0
    91
	test.Printf(_L("\n"));
sl@0
    92
	test.Printf(_L("Insert the connector\n"));
sl@0
    93
	test.Printf(_L("from the OET with SW9\n"));
sl@0
    94
	test.Printf(_L("set to 'A-DEVICE' and\n"));
sl@0
    95
	test.Printf(_L("all other switches OFF\n"));
sl@0
    96
	test.Printf(_L("\n"));
sl@0
    97
	test.Printf(_L("Confirm passing tests\n"));
sl@0
    98
	test.Printf(_L("\n"));
sl@0
    99
	test.Printf(_L("ID_PIN detection\n"));
sl@0
   100
	test.Printf(_L("VBus Driving\n"));
sl@0
   101
	test.Printf(_L("\n"));
sl@0
   102
	}
sl@0
   103
sl@0
   104
	
sl@0
   105
void CTestCase0466::DoCancel()
sl@0
   106
	{
sl@0
   107
	LOG_FUNC
sl@0
   108
sl@0
   109
	// cancel our timer
sl@0
   110
	iTimer.Cancel();
sl@0
   111
	}
sl@0
   112
	
sl@0
   113
	// static cb helper
sl@0
   114
void CTestCase0466::CancelDrive(CTestCaseRoot *pThis)
sl@0
   115
	{
sl@0
   116
	CTestCase0466 * p = REINTERPRET_CAST(CTestCase0466 *,pThis);
sl@0
   117
	// cancel any pending call, and then complete our active obj with a timeout value
sl@0
   118
	p->SelfComplete(KTestCaseWatchdogTO);
sl@0
   119
	
sl@0
   120
	}
sl@0
   121
sl@0
   122
sl@0
   123
// handle event completion	
sl@0
   124
void CTestCase0466::RunStepL()
sl@0
   125
	{
sl@0
   126
	LOG_FUNC
sl@0
   127
	// Obtain the completion code for this CActive obj.
sl@0
   128
	TInt completionCode(iStatus.Int()); 
sl@0
   129
	TBuf<MAX_DSTRLEN> aDescription;
sl@0
   130
	TInt err(0);
sl@0
   131
			
sl@0
   132
	switch(iCaseStep)
sl@0
   133
		{
sl@0
   134
		case EPreconditions:
sl@0
   135
			iCaseStep = ELoadLdd;
sl@0
   136
			if (iAutomated)
sl@0
   137
				{
sl@0
   138
				iCaseStep = ELoadLdd;
sl@0
   139
				SelfComplete();
sl@0
   140
				break;
sl@0
   141
				}
sl@0
   142
			// prompt to insert connector
sl@0
   143
			test.Printf(_L("\n"));
sl@0
   144
			test.Printf(KInsertAConnectorPrompt);
sl@0
   145
			test.Printf(_L("\n"));
sl@0
   146
			test.Printf(KPressAnyKeyToContinue);
sl@0
   147
			test.Printf(_L("\n"));
sl@0
   148
			RequestCharacter();			
sl@0
   149
			break;
sl@0
   150
			
sl@0
   151
		case ELoadLdd:
sl@0
   152
			if (!StepLoadLDD())
sl@0
   153
				{
sl@0
   154
				break;
sl@0
   155
				}
sl@0
   156
sl@0
   157
			iCaseStep = EDriveBus;
sl@0
   158
			SelfComplete();
sl@0
   159
			break;
sl@0
   160
			
sl@0
   161
			// wait on 
sl@0
   162
		case EDriveBus:
sl@0
   163
			// wait for 100 ms to allow the stack time to settle
sl@0
   164
			User::After(100000);
sl@0
   165
			
sl@0
   166
			// drive VBus
sl@0
   167
			// NOTE: A-Plug must be inserted because it is illegal to power VBus unless 
sl@0
   168
			// A-Plug is detected (ID pin is low). The Thunk checks this.
sl@0
   169
			err = otgBusRequest();
sl@0
   170
			
sl@0
   171
			if (KErrNone != err)
sl@0
   172
				{
sl@0
   173
				return TestFailed(KErrAbort, _L("Raise VBus - RUsbOtgDriver::BusRequest() FAILED!"));
sl@0
   174
				}
sl@0
   175
sl@0
   176
			// wait for 1 second as described in the test document
sl@0
   177
			User::After(1000000);
sl@0
   178
sl@0
   179
			// subscribe to error events...
sl@0
   180
			otgQueueOtgMessageRequest(iOTGMessage, iStatus);
sl@0
   181
			SetActive();
sl@0
   182
sl@0
   183
			// ...and tell user to apply load	
sl@0
   184
			test.Printf(_L("\n"));
sl@0
   185
			test.Printf(_L("************************\n"));
sl@0
   186
			test.Printf(_L("* Using SW4 on the OET *\n"));
sl@0
   187
			test.Printf(_L("* Apply 100mA LOAD now *\n"));
sl@0
   188
			test.Printf(_L("************************\n"));
sl@0
   189
			test.Printf(_L("\n"));
sl@0
   190
			
sl@0
   191
			iCaseStep = EVerifyBusFail;
sl@0
   192
			
sl@0
   193
			break;
sl@0
   194
			
sl@0
   195
		case EVerifyBusFail:
sl@0
   196
		
sl@0
   197
			OtgMessageString(iOTGMessage, aDescription);
sl@0
   198
			test.Printf(_L("Received message %d '%S' status(%d)\n"), iOTGMessage, &aDescription, completionCode);
sl@0
   199
sl@0
   200
			if (RUsbOtgDriver::EMessageVbusError == iOTGMessage)
sl@0
   201
				{
sl@0
   202
				err = otgBusClearError();
sl@0
   203
				
sl@0
   204
				if ( err )
sl@0
   205
					{
sl@0
   206
					return TestFailed(KErrAbort, _L("VBUS Error Clear - FAILED!"));
sl@0
   207
					}
sl@0
   208
sl@0
   209
				iCaseStep = EUnloadLdd;
sl@0
   210
				SelfComplete();
sl@0
   211
				}
sl@0
   212
			else
sl@0
   213
				{
sl@0
   214
				iRepeats--;
sl@0
   215
				if (iRepeats <0)
sl@0
   216
					{
sl@0
   217
					return TestFailed(KErrAbort, _L("VBUS Fall FAILED!"));
sl@0
   218
					}
sl@0
   219
sl@0
   220
				otgQueueOtgMessageRequest(iOTGMessage, iStatus);
sl@0
   221
				SetActive();
sl@0
   222
sl@0
   223
				iCaseStep = EVerifyBusFail;
sl@0
   224
				}
sl@0
   225
sl@0
   226
			break;
sl@0
   227
			
sl@0
   228
		case EUnloadLdd:
sl@0
   229
			
sl@0
   230
			if (EFalse == StepUnloadLDD())
sl@0
   231
				{
sl@0
   232
				return TestFailed(KErrAbort,_L("unload Ldd failure"));
sl@0
   233
				}
sl@0
   234
sl@0
   235
			// remove 100ma Load - this reminds the user
sl@0
   236
			test.Printf(_L("\n"));
sl@0
   237
			test.Printf(_L("************************\n"));
sl@0
   238
			test.Printf(_L("* Using SW4 on the OET *\n"));
sl@0
   239
			test.Printf(_L("* Remove 100mA LOAD!   *\n"));
sl@0
   240
			test.Printf(_L("************************\n"));
sl@0
   241
			test.Printf(_L("\n"));
sl@0
   242
			
sl@0
   243
			iCaseStep = ELastStep;
sl@0
   244
			// press any key
sl@0
   245
			test.Printf(KPressAnyKeyToContinue);
sl@0
   246
			RequestCharacter();			
sl@0
   247
			break;
sl@0
   248
			
sl@0
   249
		case ELastStep:
sl@0
   250
			return TestPassed();
sl@0
   251
			
sl@0
   252
		default:
sl@0
   253
			test.Printf(_L("<Error> unknown test step"));
sl@0
   254
			Cancel();
sl@0
   255
			return (TestFailed(KErrCorrupt, _L("<Error> unknown test step")));
sl@0
   256
sl@0
   257
		}
sl@0
   258
sl@0
   259
	}
sl@0
   260
sl@0
   261