os/kernelhwsrv/kerneltest/e32test/usbho/t_otgdi/src/testcaseroot.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
// @file testcaseroot.cpp
sl@0
    15
// @internalComponent
sl@0
    16
// 
sl@0
    17
//
sl@0
    18
sl@0
    19
#include <e32std.h>
sl@0
    20
#include <e32std_private.h>
sl@0
    21
#include <u32std.h> 	// unicode builds
sl@0
    22
#include <e32base.h>
sl@0
    23
#include <e32base_private.h>
sl@0
    24
#include <e32cons.h>
sl@0
    25
#include <e32Test.h>	// RTest header
sl@0
    26
//#include <e32ver.h>
sl@0
    27
#include <e32def.h>
sl@0
    28
#include <e32def_private.h>
sl@0
    29
#include <d32otgdi.h>		// OTGDI header
sl@0
    30
#include <d32usbc.h>		// USBCC header
sl@0
    31
#include "testcaseroot.h"
sl@0
    32
sl@0
    33
/* Implemention of classes CTestCaseRoot, CTestCaseB2BRoot
sl@0
    34
 *
sl@0
    35
 */ 
sl@0
    36
sl@0
    37
/* ===============================================================
sl@0
    38
 *  The root test-case class, provides test-framework features  
sl@0
    39
 */
sl@0
    40
CTestCaseRoot::CTestCaseRoot(const TDesC& aTestCaseId, TBool aAutomation)
sl@0
    41
:	CActive(EPriorityUserInput),
sl@0
    42
	COtgRoot(),
sl@0
    43
	iAutomated(aAutomation)
sl@0
    44
	{
sl@0
    45
	iTestCaseId.Copy(aTestCaseId);
sl@0
    46
	}
sl@0
    47
sl@0
    48
	
sl@0
    49
void CTestCaseRoot::BaseConstructL()
sl@0
    50
	{
sl@0
    51
	LOG_FUNC
sl@0
    52
	
sl@0
    53
sl@0
    54
	TInt err(iTimer.CreateLocal());
sl@0
    55
	if (err == KErrNone)
sl@0
    56
		{
sl@0
    57
		LOG_VERBOSE1(_L("Test case timer created"));
sl@0
    58
		}
sl@0
    59
	else
sl@0
    60
		{
sl@0
    61
		RDebug::Printf("<Error %d> Test case timer could not be created",err);
sl@0
    62
		User::Leave(err);
sl@0
    63
		}
sl@0
    64
	//
sl@0
    65
	iConsole = test.Console();
sl@0
    66
	iRequestedChar = EFalse;
sl@0
    67
	}
sl@0
    68
	
sl@0
    69
	
sl@0
    70
CTestCaseRoot::~CTestCaseRoot()
sl@0
    71
	{
sl@0
    72
	LOG_FUNC
sl@0
    73
	Cancel();
sl@0
    74
	}
sl@0
    75
sl@0
    76
// utility GUI methods
sl@0
    77
void CTestCaseRoot::DisplayTestCaseOptions()
sl@0
    78
	{
sl@0
    79
	LOG_FUNC
sl@0
    80
sl@0
    81
	// commonly overridden to display any options for that test
sl@0
    82
	test.Printf(_L("Press <ESC> to end the test.\n"));	
sl@0
    83
	}
sl@0
    84
sl@0
    85
    
sl@0
    86
/***********************************************************************/
sl@0
    87
//
sl@0
    88
void CTestCaseRoot::SetTestPolicy(CBasicTestPolicy* aTestPolicy)
sl@0
    89
	{
sl@0
    90
	iTestPolicy = aTestPolicy;
sl@0
    91
	iAutomated = gSemiAutomated;	// read the global flag at this time
sl@0
    92
	}
sl@0
    93
sl@0
    94
sl@0
    95
CBasicTestPolicy& CTestCaseRoot::TestPolicy()
sl@0
    96
	{
sl@0
    97
	return *iTestPolicy;
sl@0
    98
	}
sl@0
    99
	
sl@0
   100
sl@0
   101
void CTestCaseRoot::DoCancel()
sl@0
   102
	{
sl@0
   103
	LOG_FUNC
sl@0
   104
	}
sl@0
   105
sl@0
   106
    
sl@0
   107
/** ProcessKey
sl@0
   108
override this method to perform other tasks, the base-class does nothing so that 
sl@0
   109
child classes can use it as an any-key-to-continue helper
sl@0
   110
*/
sl@0
   111
void CTestCaseRoot::ProcessKey(TKeyCode &aKey)
sl@0
   112
	{// default implementation - reads the key.
sl@0
   113
		iKeyCodeInput = aKey;
sl@0
   114
	}
sl@0
   115
    
sl@0
   116
    
sl@0
   117
void CTestCaseRoot::ProcessEngineKey(TKeyCode &aKey)
sl@0
   118
	{
sl@0
   119
	LOG_FUNC
sl@0
   120
	
sl@0
   121
	if (EKeyEscape == aKey)
sl@0
   122
		{
sl@0
   123
		AssertionFailed( 1, _L("Test aborted by the user <ESC>\n"));
sl@0
   124
		CActiveScheduler::Stop();
sl@0
   125
		}
sl@0
   126
	else
sl@0
   127
		{
sl@0
   128
			
sl@0
   129
		// call virtual method here to invoke the test's overridden method
sl@0
   130
		ProcessKey(aKey);
sl@0
   131
		// note, we do not go ask for another, that is done by the console handler
sl@0
   132
		}
sl@0
   133
	}
sl@0
   134
    
sl@0
   135
sl@0
   136
void CTestCaseRoot::RequestCharacter()
sl@0
   137
	{
sl@0
   138
	LOG_FUNC
sl@0
   139
	  // A request is issued to the CConsoleBase to accept a
sl@0
   140
	  // character from the keyboard.
sl@0
   141
sl@0
   142
	__ASSERT_ALWAYS(!IsActive(), User::Panic(KMsgAlreadyActive, EPanicAlreadyActive));
sl@0
   143
	  
sl@0
   144
	iConsole->Read(iStatus); 
sl@0
   145
	SetActive();
sl@0
   146
	iRequestedChar = ETrue;
sl@0
   147
	}
sl@0
   148
sl@0
   149
sl@0
   150
void CTestCaseRoot::RunL()
sl@0
   151
	{
sl@0
   152
	LOG_FUNC
sl@0
   153
	TInt complCode(iStatus.Int());
sl@0
   154
	if (iRequestedChar)
sl@0
   155
		{
sl@0
   156
		
sl@0
   157
		TKeyCode k(iConsole->KeyCode());
sl@0
   158
		
sl@0
   159
		// WARNING!
sl@0
   160
		// EMULATOR QUIRK!
sl@0
   161
		// When debugging if you have a breakpoint just before you read/process a key, 
sl@0
   162
		// the EMULATOR will read the key sent to the IDE and you get a (F5) key that 
sl@0
   163
		// you did not want from the IDE not the emulator.
sl@0
   164
		
sl@0
   165
		ProcessEngineKey(k);
sl@0
   166
		iRequestedChar = EFalse;
sl@0
   167
sl@0
   168
		// complete so that other tasks (there are none) can run
sl@0
   169
		// we will then be scheduled by the ActiveScheduler again to run the next test step.
sl@0
   170
		SelfComplete();
sl@0
   171
		}
sl@0
   172
	else
sl@0
   173
		{
sl@0
   174
		// run the next test step
sl@0
   175
		TInt currentStep(GetStepIndex());
sl@0
   176
		PreRunStep();
sl@0
   177
		LOG_VERBOSE2(_L("\n<< RunStepL() step=%d\n"), currentStep);
sl@0
   178
		RunStepL();
sl@0
   179
		LOG_VERBOSE3(_L(">> RunStepL() step=%d->%d\n"), currentStep, GetStepIndex());
sl@0
   180
		PostRunStep();
sl@0
   181
		}
sl@0
   182
	}
sl@0
   183
sl@0
   184
sl@0
   185
void CTestCaseRoot::PostRunStep()
sl@0
   186
	{
sl@0
   187
		// default impl.
sl@0
   188
	}
sl@0
   189
sl@0
   190
void CTestCaseRoot::PreRunStep()
sl@0
   191
	{
sl@0
   192
		// default impl.
sl@0
   193
	}
sl@0
   194
sl@0
   195
TInt CTestCaseRoot::RunError(TInt aError)
sl@0
   196
	{
sl@0
   197
	LOG_FUNC
sl@0
   198
	test.Printf(_L("Test case C%lS::RunL left with %d"), &iTestCaseId, aError);
sl@0
   199
	AssertionFailed(aError, _L("RunError"));
sl@0
   200
	return KErrNone;
sl@0
   201
	}
sl@0
   202
	
sl@0
   203
	
sl@0
   204
TDesC& CTestCaseRoot::TestCaseId()
sl@0
   205
	{
sl@0
   206
	return iTestCaseId;
sl@0
   207
	}
sl@0
   208
	
sl@0
   209
	
sl@0
   210
TInt CTestCaseRoot::TestResult() const
sl@0
   211
	{
sl@0
   212
	return iTestResult;
sl@0
   213
	}
sl@0
   214
	
sl@0
   215
	
sl@0
   216
void CTestCaseRoot::PerformTestL()
sl@0
   217
	{
sl@0
   218
		// tell user what they should have done before starting!
sl@0
   219
		DescribePreconditions();
sl@0
   220
		// run it
sl@0
   221
		ExecuteTestCaseL();
sl@0
   222
	}
sl@0
   223
sl@0
   224
sl@0
   225
void CTestCaseRoot::TestFailed(TInt aFailResult, const TDesC &aErrorDescription)
sl@0
   226
	{
sl@0
   227
	LOG_FUNC
sl@0
   228
	iTestResult = aFailResult;
sl@0
   229
	test.Printf(_L("Test %S\n"), &TestCaseId());
sl@0
   230
	test.Printf(_L("Failed (%d)\n"), aFailResult);
sl@0
   231
	test.Printf(_L("%S!\n"), &aErrorDescription);
sl@0
   232
	if (!iAutomated)
sl@0
   233
		{
sl@0
   234
		test.Printf(_L("\n"));
sl@0
   235
		test.Printf(KPressAnyKeyToContinue);
sl@0
   236
		iConsole->Getch();
sl@0
   237
		}
sl@0
   238
	// the next call panics the framework!
sl@0
   239
	TestPolicy().SignalTestComplete(iTestResult);
sl@0
   240
	}
sl@0
   241
	
sl@0
   242
	
sl@0
   243
void CTestCaseRoot::TestFailed2(TInt aFailResult, const TDesC &aErrorDescription, TInt errorCode)
sl@0
   244
	{
sl@0
   245
	LOG_FUNC
sl@0
   246
	iTestResult = aFailResult;
sl@0
   247
	test.Printf(_L("Test %S FAILED %d '%S %d'!\n"), 
sl@0
   248
	            &TestCaseId(), 
sl@0
   249
	            aFailResult, 
sl@0
   250
	            &aErrorDescription, 
sl@0
   251
	            errorCode);
sl@0
   252
	// the next call panics the framework!
sl@0
   253
	TestPolicy().SignalTestComplete(iTestResult);
sl@0
   254
	}
sl@0
   255
	
sl@0
   256
	
sl@0
   257
	
sl@0
   258
void CTestCaseRoot::TestPassed()
sl@0
   259
	{
sl@0
   260
	LOG_FUNC
sl@0
   261
	iTestResult = KErrNone;
sl@0
   262
	TestPolicy().SignalTestComplete(iTestResult);
sl@0
   263
	}
sl@0
   264
	
sl@0
   265
	
sl@0
   266
	
sl@0
   267
			
sl@0
   268
/** Complete the servicing of the Active object and signal it ready to run again 
sl@0
   269
 in next scheduler slot. This method works as drop-through when a test step has 
sl@0
   270
 nothing more to do .
sl@0
   271
*/
sl@0
   272
void CTestCaseRoot::SelfComplete(TInt aCode)
sl@0
   273
	{	
sl@0
   274
	TRequestStatus* s = &iStatus;
sl@0
   275
	iStatus = KRequestPending;
sl@0
   276
	User::RequestComplete(s, aCode);
sl@0
   277
	SetActive();
sl@0
   278
	}
sl@0
   279
sl@0
   280
/* Prints a little banner at the top of a test-step : 
sl@0
   281
 * B2B tests also display the duration of the last step, and the current OTG state
sl@0
   282
 */
sl@0
   283
void CTestCaseRoot::PrintStepName(const TDesC &aStepName)
sl@0
   284
	{
sl@0
   285
	if (gVerboseOutput) 
sl@0
   286
		{
sl@0
   287
		test.Printf(_L("--------------\n %S "), &aStepName);
sl@0
   288
		// B2B class method dumps the engine state
sl@0
   289
		//
sl@0
   290
		test.Printf(_L("\n--------------\n"));
sl@0
   291
		}
sl@0
   292
	}
sl@0
   293
sl@0
   294
sl@0
   295
/* **************************************************************************************
sl@0
   296
 * 
sl@0
   297
 */
sl@0
   298
CTestCaseB2BRoot::CTestCaseB2BRoot(const TDesC& aTestCaseId, TBool aHost, TRequestStatus &aStatus) 
sl@0
   299
	: CTestCaseRoot(aTestCaseId, aHost) , iCollector(aStatus)
sl@0
   300
	{
sl@0
   301
	LOG_FUNC
sl@0
   302
	
sl@0
   303
	}
sl@0
   304
sl@0
   305
sl@0
   306
CTestCaseB2BRoot::~CTestCaseB2BRoot()
sl@0
   307
	{
sl@0
   308
	LOG_FUNC
sl@0
   309
	
sl@0
   310
	}
sl@0
   311
sl@0
   312
/* Print step name : B2B override displays the OTG Engine state as well
sl@0
   313
 */
sl@0
   314
void CTestCaseB2BRoot::PrintStepName(const TDesC &aStepName)
sl@0
   315
	{
sl@0
   316
	if (gVerboseOutput) 
sl@0
   317
		{
sl@0
   318
		test.Printf(_L("--------------\n %S "), &aStepName);
sl@0
   319
		// engine state
sl@0
   320
		CNotifyWatcherBase *pWatcher = iCollector.GetWatcher(EWatcherState);
sl@0
   321
		if (pWatcher)
sl@0
   322
			{
sl@0
   323
			TBuf<MAX_DSTRLEN> aDescription;
sl@0
   324
			RUsbOtgDriver::TOtgState aState = static_cast<RUsbOtgDriver::TOtgState>(pWatcher->GetEventValue());
sl@0
   325
			
sl@0
   326
			OtgStateString(aState, aDescription);
sl@0
   327
			LOG_VERBOSE3(_L("OTGState %d '%S' \n"), aState, &aDescription);
sl@0
   328
			}
sl@0
   329
		test.Printf(_L(" : time = %dms\n--------------\n"), iCollector.DurationElapsed());
sl@0
   330
		}
sl@0
   331
	}
sl@0
   332
sl@0
   333
/* Default implementation which describes this as a B2B test-case 
sl@0
   334
 */
sl@0
   335
void CTestCaseB2BRoot::DescribePreconditions()
sl@0
   336
	{
sl@0
   337
	test.Printf(KTestTypeB2BMsg); // B2B
sl@0
   338
	if (gTestRoleMaster)
sl@0
   339
		test.Printf(KRoleMasterMsg);
sl@0
   340
	else
sl@0
   341
		test.Printf(KRoleSlaveMsg);
sl@0
   342
	}
sl@0
   343
sl@0
   344
sl@0
   345
void CTestCaseB2BRoot::StepB2BPreconditions()
sl@0
   346
	{
sl@0
   347
	// prompt to insert connector
sl@0
   348
	if (gTestRoleMaster)
sl@0
   349
		{ // "B" device
sl@0
   350
		test.Printf(KInsertBCablePrompt);
sl@0
   351
		}
sl@0
   352
	else
sl@0
   353
		{
sl@0
   354
		test.Printf(KInsertACablePrompt);
sl@0
   355
		}
sl@0
   356
	if (iAutomated)
sl@0
   357
		{
sl@0
   358
sl@0
   359
		SelfComplete();
sl@0
   360
		return;
sl@0
   361
		}
sl@0
   362
	test.Printf(KPressAnyKeyToContinue);
sl@0
   363
	RequestCharacter();	
sl@0
   364
	}
sl@0
   365
sl@0
   366
sl@0
   367
/* Test for A or B plug as relevant for MASTER/SLAVE role, fail the test if wrong
sl@0
   368
 */
sl@0
   369
void CTestCaseB2BRoot::CheckRoleConnections()
sl@0
   370
	{
sl@0
   371
	if (gTestRoleMaster)
sl@0
   372
		{
sl@0
   373
		if (otgIdPinPresent())
sl@0
   374
			{ // oops
sl@0
   375
			test.Printf(KMsgErrorPreconditionFailed);
sl@0
   376
			return TestFailed(KErrAbort, KMsgBPlugNotFound);
sl@0
   377
			}
sl@0
   378
		}
sl@0
   379
	else
sl@0
   380
		{
sl@0
   381
		if (!otgIdPinPresent())
sl@0
   382
			{ // oops
sl@0
   383
			test.Printf(KMsgErrorPreconditionFailed);
sl@0
   384
			return TestFailed(KErrAbort, KMsgAPlugNotFound);
sl@0
   385
			}
sl@0
   386
		}
sl@0
   387
	}
sl@0
   388
sl@0
   389
sl@0
   390
/* Clears the expected event Q just before calling the step, but not the 
sl@0
   391
 * recieved Q since the step may still inspect it using the EventReceivedAlready() method.
sl@0
   392
 */
sl@0
   393
void CTestCaseB2BRoot::PreRunStep()
sl@0
   394
	{
sl@0
   395
	LOG_FUNC
sl@0
   396
		
sl@0
   397
		iCollector.ClearAllEvents(EFalse, ETrue);
sl@0
   398
	}
sl@0
   399
sl@0
   400
sl@0
   401
void CTestCaseB2BRoot::PostRunStep()
sl@0
   402
	{
sl@0
   403
	LOG_FUNC
sl@0
   404
		// clear the recieved event Q, but not the expected Q
sl@0
   405
		iCollector.ClearAllEvents(ETrue, EFalse);
sl@0
   406
	
sl@0
   407
	}
sl@0
   408
sl@0
   409
sl@0
   410