kerneltest/e32test/usbho/t_otgdi/inc/testcaseroot.h
changeset 0 a41df078684a
equal deleted inserted replaced
-1:000000000000 0:a41df078684a
       
     1 // Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of the License "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 // @internalComponent
       
    15 // 
       
    16 //
       
    17 
       
    18 #ifndef TESTCASEROOT_H
       
    19 #define TESTCASEROOT_H
       
    20 
       
    21 #include <d32otgdi.h>	// OTGDI thunk headder (under test)
       
    22 #include "debugmacros.h"
       
    23 #include "testcasefactory.h"
       
    24 #include "testpolicy.h"
       
    25 #include "otgroot.h"		// otg driver facade
       
    26 #include "b2bwatchers.h"	// otg watchers server
       
    27 
       
    28 
       
    29 #define MINMAX_CLAMPVALUE(a,min,max) (a < min?a=min:(a>max?a=max:(int)0))
       
    30 
       
    31 // keyboard input, different from KErrNone and KErrCancel
       
    32 const TInt KTestCaseWatchdogTO		= 1025;
       
    33 const TInt KTestCaseFailureEventReceived = 1026;	//	Meaning that some specific undesired event occurred during a test step
       
    34 
       
    35 const TInt KB2BStepTimeoutDefaultMS 	= 5000;	// 5 seconds
       
    36 const TInt KB2BStepTimeoutShortMS		= 1000; // timeout for things that should happen virtually immediately
       
    37 const TInt KB2BStepRoleSustainB_MS		= 30000;	// B-device must stay in role for at least 30 seconds
       
    38 const TInt KB2BStepRoleSustainA_MS		= 35000;	// A-device must stay in role longer before it drops the bus
       
    39 
       
    40 
       
    41 // Prompts to the tester
       
    42 					// H4 width    ****************************
       
    43 _LIT(KAttachOETAsBDevice,		  "Attach OET, SW9 set as B-Device.\n");
       
    44 _LIT(KInsertAConnectorPrompt,	  "Please insert 'A'-connector now.\n");
       
    45 _LIT(KRemoveAConnectorPrompt,  	  "Please remove 'A'-connector now.\n");
       
    46 _LIT(KInsertBCablePrompt,	   	  "Please insert 'B'-cable end now.\n ");
       
    47 _LIT(KInsertACablePrompt,	  	  "Please insert 'A'-cable end now.\n ");
       
    48 _LIT(KInsertAIntoPC,              "Please insert 'A'-connector into PC\n ");
       
    49 _LIT(KRemoveAFromPC,              "Please remove 'A'-connector from PC\n ");
       
    50 _LIT(KPressAnyKeyToStart,		  "Press any key to start...");
       
    51 _LIT(KPressAnyKeyToContinue,	  "Press any key to proceed...");
       
    52 _LIT(KPressAnyKeyToEnd,			  "Press any key to end.");
       
    53 _LIT(KMsgErrorPreconditionFailed, "<Error>Test precondition not met!\n");
       
    54 _LIT(KMsgBPlugNotFound,			  "B plug not detected ERROR!\n");
       
    55 _LIT(KMsgAPlugNotFound,			  "A plug not detected ERROR!\n");
       
    56 _LIT(KMsgWaitingForSRPTimeout,    "Waiting for SRP timeout (32 s)\n");
       
    57 _LIT(KMsgWaitingForSRPInitiated,  "Waiting for SRP initiation\n");
       
    58 
       
    59 
       
    60 _LIT(KTestTypeB2BMsg, "== B2B connected test ==\n");
       
    61 _LIT(KRoleMasterMsg,  "== MASTER ==\n");
       
    62 _LIT(KRoleSlaveMsg,   "== SLAVE  ==\n");
       
    63 
       
    64 // CActive helper string
       
    65 _LIT(KMsgAlreadyActive, "Is already Active");		
       
    66 
       
    67 // name of the OTGDI ldd
       
    68 _LIT(KOTGDeviceInterfaceDriverName,"otgdi");
       
    69 
       
    70 // names for the USBC ldd
       
    71 _LIT(KUsbcLddFileName, "eusbc");
       
    72 _LIT(KUsbDeviceName, "Usbc");
       
    73 
       
    74 
       
    75 const TInt KDelayDurationForUserActivityMS	= 15000;
       
    76 const TInt KDelayDurationForQEmpty			= 200;	// > 17 ms
       
    77 const TInt KDelayDurationForLocalTrigger	= 50;	// 50 ms (API call with a local side-effect)
       
    78 
       
    79 const TInt KDelayBeforeBusDropUs	= 50000;	// 50ms time after VBus rise before we may drop it - prevents
       
    80 											// ambiguous Vbus pulse signalling.
       
    81 
       
    82 const TInt KTestProductID 		= 0x2670;	// Symbian USB PID product-id 
       
    83 
       
    84 // Specification values
       
    85 const TInt KSpec_TA_SRP_RSPNS = 4900; 		// ms [OTG section 5.3.2] - NOTE: A device timeout=32 seconds
       
    86 
       
    87 
       
    88 const TInt KOperationRetriesMax = 3;	// # retries on various operations.
       
    89 const TInt KParameterTextLenMax = 80;	// command-line param length
       
    90 
       
    91 // map the number of times to re-run the OPEN/CLOSE tests to the command-line parameter
       
    92 // this parameter is also used for many other tests that allow itteration count control
       
    93 #define OPEN_REPEATS		gOpenIterations	
       
    94 #define OPEN_MINREPEATS		1
       
    95 #define OPEN_MAXREPEATS		1000
       
    96 
       
    97 // # times to repeat the steps
       
    98 #define OOMOPEN_REPEATS		gOOMIterations
       
    99 #define OOM_MINREPEATS		1
       
   100 #define OOM_MAXREPEATS		99
       
   101 
       
   102 // panics
       
   103 enum
       
   104 	{
       
   105 	EPanicAlreadyActive=1000,
       
   106 	EPanicPropertyDeleted = 1001,
       
   107 	EPanicWatchdogError = 1002
       
   108 	};
       
   109 
       
   110 
       
   111 
       
   112 /** Abstract base class to derive all tests from
       
   113 */
       
   114 class CTestCaseRoot : public CActive, public COtgRoot
       
   115     {
       
   116 public:
       
   117 	virtual ~CTestCaseRoot();
       
   118 		
       
   119 	/** Provides us with a pointer to the test policy which instantiated this object
       
   120 	 in OTGDI, the policy does not do any policy making, it merely instantiates the test
       
   121 	 and provides parameters */
       
   122 	void SetTestPolicy(CBasicTestPolicy* aTestPolicy);
       
   123 	
       
   124 	void DisplayTestCaseOptions();
       
   125 	
       
   126 	virtual void DescribePreconditions() = 0;
       
   127 	virtual TInt GetStepIndex() = 0;
       
   128 
       
   129 	// Performs the test case
       
   130 	void PerformTestL();
       
   131 
       
   132 	virtual void ExecuteTestCaseL()=0; // override to implement	
       
   133 	
       
   134 	// Provides to the caller the identity of this test case
       
   135 	// @return descriptor referrence to the test case identity
       
   136 	TDesC& TestCaseId();
       
   137 	
       
   138 	// Retrieve the test result for the executed test case
       
   139 	// @return the test case result
       
   140 	TInt TestResult() const;	
       
   141 
       
   142 	TBool IsActiveOutstanding() {return(IsActive());}; 
       
   143                           
       
   144 
       
   145 protected:
       
   146 	/**
       
   147 	Constructor
       
   148 	@param aTestCaseId the identity that this test case is to represent
       
   149 	@param aHostFlag the flag for host role
       
   150 	*/
       
   151 	CTestCaseRoot(const TDesC& aTestCaseId, TBool aHost);
       
   152 	
       
   153 	/**
       
   154 	Base class 2nd phase constructor
       
   155 	*/
       
   156 	void BaseConstructL();	 
       
   157 
       
   158 	/**
       
   159 	Called when Cancel is called (if active)
       
   160 	*/
       
   161 	virtual void DoCancel();
       
   162 	
       
   163 	/**
       
   164 	Called when the this AO has been scheduled
       
   165 	*/
       
   166 	virtual void RunL();
       
   167 	
       
   168 	/**
       
   169 	This default implementation just informs the test controller that this specific test case RunL
       
   170 	left with the error code so that the active scheduler will not Panic.  This indicates that the test case failed.
       
   171 	Derived test cases are expected to override for exact knowledge of error
       
   172 	@param aError the error from a derived test case execution
       
   173 	@return KErrNone
       
   174 	*/
       
   175 	virtual TInt RunError(TInt aError);
       
   176 	
       
   177 	/**
       
   178 	State that the test case has failed with the given error code
       
   179 	@param aFailResult the failure result for the test case
       
   180 	*/
       
   181 	void TestFailed(TInt aFailResult, const TDesC &aErrorDescription);
       
   182 	void TestFailed2(TInt aFailResult, const TDesC &aErrorDescription, TInt errorCode);
       
   183 	
       
   184 	void AssertionFailed(TInt aFailResult, const TDesC &aErrorDescription) {TestFailed(aFailResult, aErrorDescription);};
       
   185 	void AssertionFailed2(TInt aFailResult, const TDesC &aErrorDescription, TInt errorCode) {TestFailed2(aFailResult, aErrorDescription, errorCode);}; 
       
   186 	
       
   187 	virtual void PrintStepName(const TDesC &aStepName);
       
   188 
       
   189 	/**
       
   190 	Instruct the test case that it has passed
       
   191 	*/
       
   192 	void TestPassed();                  
       
   193 
       
   194 	void SelfComplete(TInt aError=KErrNone);
       
   195 	
       
   196 	CBasicTestPolicy& TestPolicy();
       
   197 
       
   198 	// override this method in each test that needs KB input
       
   199 	virtual void ProcessKey(TKeyCode &aKey);
       
   200 
       
   201 	void ProcessEngineKey(TKeyCode &aKey);
       
   202 
       
   203 	// Issue request
       
   204 	void RequestCharacter();
       
   205 
       
   206 	virtual void RunStepL() =0;
       
   207 	virtual void PreRunStep();
       
   208 	virtual void PostRunStep();
       
   209 
       
   210 
       
   211 	                  
       
   212 	// DATA MEMBERS
       
   213 protected:
       
   214 	/** bypass some manual steps, will skip preconditioning steps 
       
   215 		when you want to run the tests in the correct sequence (IE previous test leaves 
       
   216 		the external inputs in a state ready for this test).
       
   217 	*/
       
   218 	TBool iAutomated;	
       
   219    
       
   220 	
       
   221 	/**
       
   222 	The timer resource for timeout of test actions
       
   223 	and possibly other uses
       
   224 	*/
       
   225 	RTimer iTimer;	
       
   226 	
       
   227 	/**
       
   228 	The execution result for the test case
       
   229 	*/
       
   230 	TInt iTestResult;
       
   231 
       
   232 	
       
   233 	// key input status to wait upon (wrap it in a method-call)
       
   234 	TKeyCode iKeyCodeInput;		
       
   235 	
       
   236 	CConsoleBase* iConsole; // A console for reading from
       
   237 	TBool iDualRoleCase;	// True for tests with 2 roles (Master/Slave)
       
   238 	
       
   239 private:	
       
   240 	TBool iRequestedChar;
       
   241 
       
   242     TTime iStartTime;  // time that the test started at
       
   243 
       
   244     TBuf<KMaxName> iRootID; // test case name or step name
       
   245 
       
   246 	/**
       
   247 	*/
       
   248 	CBasicTestPolicy* iTestPolicy;
       
   249 	
       
   250 	/**
       
   251 	The identity of the test case
       
   252 	*/
       
   253 	TBuf<KMaxName> iTestCaseId;
       
   254     
       
   255     }; // CTestCaseRoot
       
   256         
       
   257 
       
   258 /* ***************************************************************************
       
   259  * Abstract class for B2b test-cases adds B2B helpers and datas to the 
       
   260  * CTestCaseRoot class. 
       
   261  */
       
   262 class CTestCaseB2BRoot : public CTestCaseRoot
       
   263 	{
       
   264 public:
       
   265 	static CTestCaseB2BRoot* NewL(const TDesC& aTestCaseId, TBool aHost, TRequestStatus &aStatus);
       
   266 	virtual ~CTestCaseB2BRoot(); 	
       
   267 	
       
   268 	virtual void DescribePreconditions();
       
   269 	void 	CheckRoleConnections();
       
   270 
       
   271 	virtual void StepB2BPreconditions();
       
   272 	
       
   273 	
       
   274 protected:
       
   275 	CTestCaseB2BRoot(const TDesC& aTestCaseId, TBool aHost, TRequestStatus &aStatus);
       
   276 	void ConstructL();
       
   277 	
       
   278 	void PrintStepName(const TDesC &aStepName);
       
   279 	// the default B2B action is to clear the expected notification Q at the start of step, 
       
   280 	// and the received q as the step ends
       
   281 	void PreRunStep(); // from CTestCaseRoot
       
   282 	void PostRunStep(); // from CTestCaseRoot
       
   283 	
       
   284 protected:
       
   285 	CNotifyCollector	iCollector;
       
   286 	
       
   287 	};
       
   288 
       
   289 
       
   290 #endif // TESTCASEROOT_H