kerneltest/e32test/dmav2/t_dma2.h
branchRCL_3
changeset 257 3e88ff8f41d5
parent 256 c1f20ce4abcf
child 258 880ff05ad710
child 263 9e2d4f7f5028
equal deleted inserted replaced
256:c1f20ce4abcf 257:3e88ff8f41d5
     1 /*
       
     2 * Copyright (c) 2009-2010 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:
       
    15 *
       
    16 */
       
    17 #ifndef __T_DMA2_H__
       
    18 #define __T_DMA2_H__
       
    19 
       
    20 #include "cap_reqs.h"
       
    21 #include "test_thread.h"
       
    22 #include "d_dma2.h"
       
    23 #include <e32std.h>
       
    24 
       
    25 class TTestCase;
       
    26 // Global array of test cases
       
    27 extern RPointerArray<TTestCase> TestArray;
       
    28 extern RPointerArray<TTestCase> TestArrayCallback;
       
    29 extern RPointerArray<TTestCase> TestArrayIsrReque;
       
    30 extern RPointerArray<TTestCase> TestArrayMultiPart;
       
    31 extern RPointerArray<TTestCase> TestArrayIsrAndDfc;
       
    32 extern RPointerArray<TTestCase> TestArrayBenchmark;
       
    33 extern RPointerArray<TTestCase> TestArray2DTest;
       
    34 extern RPointerArray<TTestCase> TestArrayIsrAndDfc;
       
    35 extern RPointerArray<TTestCase> TestArrayChannel;
       
    36 extern RPointerArray<TTestCase> TestArraySuspend;
       
    37 extern RPointerArray<TTestCase> TestArrayQueue;
       
    38 extern RPointerArray<TTestCase>	TestArraySimple;
       
    39 extern RPointerArray<TTestCase>	TestArrayRequest;
       
    40 extern RPointerArray<TTestCase>	TestArrayFragment;
       
    41 
       
    42 extern TBool gVerboseOutput;   // Verbose output control
       
    43 
       
    44 const TInt KParameterTextLenMax = 80;	// command-line param length
       
    45 
       
    46 /**
       
    47 This function prints out the PSL test Information
       
    48 */
       
    49 void Print(const TDmaV2TestInfo& aInfo);
       
    50 
       
    51 /**
       
    52 Runs all framework self tests
       
    53 */
       
    54 void SelfTests();
       
    55 
       
    56 class CSingleTransferTest;
       
    57 class CIsrRequeTest;
       
    58 class CMultiTransferTest;
       
    59 
       
    60 /**
       
    61 An interface to a classs that sets up the buffers before a test
       
    62 */
       
    63 class MPreTransfer
       
    64 	{
       
    65 public:
       
    66 	virtual ~MPreTransfer()
       
    67 		{}
       
    68 	virtual void Setup(const CSingleTransferTest& aTest) const = 0;
       
    69 	virtual void Setup(const CIsrRequeTest& aTest) const = 0;
       
    70 	virtual void Setup(const CMultiTransferTest& aTest) const = 0;
       
    71 	};
       
    72 
       
    73 /**
       
    74 An interface for a check which takes place at the end of a DMA
       
    75 transfer test to verify the transfer was as expected.
       
    76 */
       
    77 class MPostTransferCheck
       
    78 	{
       
    79 public:
       
    80 	virtual ~MPostTransferCheck()
       
    81 		{}
       
    82 	virtual TInt Check(const CSingleTransferTest& aTest) const = 0;
       
    83 	virtual TInt Check(const CIsrRequeTest& aTest) const = 0;
       
    84 	virtual TInt Check(CMultiTransferTest& aTest) const = 0;
       
    85 	};
       
    86 
       
    87 class TCompare2D : public MPostTransferCheck
       
    88 	{
       
    89 public:
       
    90 	TCompare2D()
       
    91 		{}
       
    92 
       
    93 	virtual TInt Check(const CSingleTransferTest& aTest) const;
       
    94 	virtual TInt Check(const CIsrRequeTest& aTest) const;
       
    95 	virtual TInt Check(CMultiTransferTest& aTest) const;
       
    96 
       
    97 	};
       
    98 
       
    99 class TAlwaysFail : public MPostTransferCheck
       
   100 	{
       
   101 public:
       
   102 	virtual TInt Check(const CSingleTransferTest& /*aTest*/) const
       
   103 		{return KErrUnknown;}
       
   104 	virtual TInt Check(const CIsrRequeTest&) const
       
   105 		{return KErrUnknown;}
       
   106 	virtual TInt Check(CMultiTransferTest&) const
       
   107 		{return KErrUnknown;}
       
   108 	};
       
   109 
       
   110 class TAlwaysPass : public MPostTransferCheck
       
   111 	{
       
   112 public:
       
   113 	virtual TInt Check(const CSingleTransferTest& /*aTest*/) const
       
   114 		{return KErrNone;}
       
   115 	virtual TInt Check(const CIsrRequeTest&) const
       
   116 		{return KErrNone;}
       
   117 	virtual TInt Check(CMultiTransferTest&) const
       
   118 		{return KErrNone;}
       
   119 	};
       
   120 
       
   121 /**
       
   122 Compare that all the various source buffers of a test match
       
   123 its destination buffers
       
   124 */
       
   125 class TCompareSrcDst : public MPostTransferCheck
       
   126 	{
       
   127 public:
       
   128 	TCompareSrcDst()
       
   129 		{}
       
   130 
       
   131 	virtual TInt Check(const CSingleTransferTest& aTest) const;
       
   132 	virtual TInt Check(const CIsrRequeTest& aTest) const;
       
   133 	virtual TInt Check(CMultiTransferTest& aTest) const;
       
   134 
       
   135 protected:
       
   136 	TInt Check(const TIsrRequeArgsSet& aRequeueArgSet, TUint8* aChunkBase, const TDmaTransferArgs& aTferArgs) const;
       
   137 	TInt Check(const TIsrRequeArgs& aRequeueArgs) const;
       
   138 	TInt Check(const TDmaTransferArgs& aTransferArgs, TUint8* aChunkBase) const;
       
   139 	};
       
   140 
       
   141 /**
       
   142 Check whether destination buffers are zero filled
       
   143 
       
   144 Used to check that a transfer hasn't taken place.
       
   145 */
       
   146 class TCheckNoTransfer : public MPostTransferCheck
       
   147 	{
       
   148 public:
       
   149 	TCheckNoTransfer()
       
   150 		{}
       
   151 
       
   152 	virtual TInt Check(const CSingleTransferTest& aTest) const;
       
   153 	virtual TInt Check(const CIsrRequeTest& aTest) const;
       
   154 	virtual TInt Check(CMultiTransferTest& aTest) const;
       
   155 
       
   156 protected:
       
   157 	TBool IsZeroed(const TDmaTransferArgs& aTransferArgs, TUint8* aChunkBase) const;
       
   158 	};
       
   159 
       
   160 /**
       
   161 Base class for all DMA tests
       
   162 */
       
   163 class CDmaTest : public CTest
       
   164 	{
       
   165 public:
       
   166 	CDmaTest(const TDesC& aName, TInt aIterations, const MPreTransfer* aPreTransfer, const MPostTransferCheck* aPostTransfer)
       
   167 		: CTest(aName, aIterations), iPreTransfer(aPreTransfer), iPostTransferCheck(aPostTransfer)
       
   168 		{}
       
   169 
       
   170 	void OpenDmaSession();
       
   171 	/* Duplicate aSession */
       
   172 	void OpenDmaSession(const RDmaSession& aSession);
       
   173 	void CloseDmaSession();
       
   174 	void ChannelPause(const TUint aChannelSessionCookie);
       
   175 	void ChannelResume(const TUint aChannelSessionCookie);
       
   176 	virtual void PrintTestInfo() const;
       
   177 	virtual TBool Result() = 0;
       
   178 
       
   179 	const RChunk& Chunk() const
       
   180 		{return iChunk;}
       
   181 
       
   182 	/**
       
   183 	Tells the test which DMA channel it should run on
       
   184 	*/
       
   185 	void SetChannelCookie(TUint32 aCookie)
       
   186 		{iChannelCookie = aCookie;}
       
   187 
       
   188 	virtual void PreTransferSetup();
       
   189 	virtual TInt DoPostTransferCheck();
       
   190 protected:
       
   191 	RDmaSession iDmaSession;
       
   192 	RChunk iChunk;
       
   193 
       
   194 	/**
       
   195 	Identifies the channel to open (as understood by a DMA PSL)
       
   196 	*/
       
   197 	TUint iChannelCookie;
       
   198 	const MPreTransfer* iPreTransfer;
       
   199 
       
   200 	const MPostTransferCheck* iPostTransferCheck; //!< Some check to be run after the transfer
       
   201 	};
       
   202 
       
   203 /**
       
   204 The Decorator Pattern is used allowing test classes to be optionally extended
       
   205 using wrapper/decorator classes.
       
   206 This is the base class for test decorators
       
   207 */
       
   208 class CDmaTestDecorator : public CDmaTest
       
   209 	{
       
   210 public:
       
   211 
       
   212 protected:
       
   213 	CDmaTestDecorator(CDmaTest* aDecoratedTest);
       
   214 	CDmaTestDecorator(const CDmaTestDecorator& aOther);
       
   215 
       
   216 	CDmaTest* iDecoratedTest;
       
   217 	};
       
   218 
       
   219 /**
       
   220 Will run the wrapped test against both versions of the DMA
       
   221 API if available, otherwise just the old version.
       
   222 */
       
   223 class CMultiVersionTest : public CDmaTestDecorator
       
   224 	{
       
   225 public:
       
   226 	CMultiVersionTest(CSingleTransferTest* aDmaTest); 
       
   227 	CMultiVersionTest(const CMultiVersionTest& aOther);
       
   228 	~CMultiVersionTest();
       
   229 
       
   230 	virtual void Announce() const;
       
   231 	virtual void PrintTestType() const;
       
   232 	virtual void PrintTestInfo() const; 
       
   233 
       
   234 	virtual CTest* Clone() const {return new CMultiVersionTest(*this);}
       
   235 	virtual void SetupL();
       
   236 
       
   237 	virtual void RunTest();
       
   238 	virtual TBool Result();
       
   239 
       
   240 protected:
       
   241 	void Configure();
       
   242 	TBool Version2PILAvailable();
       
   243 	CSingleTransferTest* iNewVersionTest;
       
   244 	};
       
   245 
       
   246 /**
       
   247 Holds return codes for the various functions which must be called
       
   248 to create, fragment, and queue a DMA request
       
   249 */
       
   250 struct TRequestResults
       
   251 	{
       
   252 	TRequestResults
       
   253 		(
       
   254 		TInt aCreate = KErrNone,
       
   255 		TInt aFragmentCount = 0,
       
   256 		TInt aFragmentationResult = KErrNone,
       
   257 		TInt aQueueResult = KErrNone
       
   258 		)
       
   259 		:iCreate(aCreate), 
       
   260 		 iFragmentCount(aFragmentCount), 
       
   261 		 iFragmentationResult(aFragmentationResult), 
       
   262 		 iQueueResult(aQueueResult)
       
   263 		{}
       
   264 
       
   265 	/**
       
   266 	Constructs with error results
       
   267 	*/
       
   268 	TRequestResults(TFalse)
       
   269 		:iCreate(KErrUnknown), 
       
   270 		 iFragmentCount(0), 
       
   271 		 iFragmentationResult(KErrUnknown), 
       
   272 		 iQueueResult(KErrUnknown)
       
   273 		{}
       
   274 
       
   275 	inline TRequestResults& CreationResult(TInt aErrorCode) {iCreate = aErrorCode; return *this;}
       
   276 	inline TRequestResults& FragmentCount(TInt aCount) {iFragmentCount = aCount; return *this;}
       
   277 	inline TRequestResults& FragmentationResult(TInt aErrorCode) {iFragmentationResult = aErrorCode; return *this;}
       
   278 	inline TRequestResults& QueueResult(TInt aErrorCode) {iQueueResult = aErrorCode; return *this;}
       
   279 
       
   280 	TInt iCreate;
       
   281 	TInt iFragmentCount; //!< 0 means any result permitted
       
   282 	TInt iFragmentationResult;
       
   283 	TInt iQueueResult;
       
   284 	};
       
   285 
       
   286 /**
       
   287 Holds all the results for a DMA CSingleTransferTest
       
   288 */
       
   289 struct TResultSet
       
   290 	{
       
   291 	/**
       
   292 	No errors expected
       
   293 	*/
       
   294 	TResultSet(TInt aChannelOpenResult = KErrNone,
       
   295 			const TRequestResults aRequestResults = TRequestResults(),
       
   296 			TInt aPostTransferCheck = KErrNone,
       
   297 			const TCallbackRecord aCallbackRecord = TCallbackRecord(TCallbackRecord::EThread,1)
       
   298 			)
       
   299 		:
       
   300 		iChannelOpenResult(aChannelOpenResult),
       
   301 		iRequestResult(aRequestResults),
       
   302 		iPostTransferCheck(aPostTransferCheck),
       
   303 		iCallbackRecord(aCallbackRecord)
       
   304 		{}
       
   305 	
       
   306 	explicit TResultSet(const TCallbackRecord& aRecord)
       
   307 		:iChannelOpenResult(KErrNone),
       
   308 		 iRequestResult(),
       
   309 		 iPostTransferCheck(KErrNone),
       
   310 		 iCallbackRecord(aRecord)
       
   311 		{}
       
   312 
       
   313 	/**
       
   314 	Errors expected
       
   315 	*/
       
   316 	TResultSet(TFalse)
       
   317 		:iChannelOpenResult(KErrUnknown), 
       
   318 		iRequestResult(EFalse),
       
   319 		iPostTransferCheck(KErrUnknown),
       
   320 		iCallbackRecord(TCallbackRecord::Empty())
       
   321 		{}		
       
   322 	
       
   323 	void Print() const;
       
   324 	TBool operator == (const TResultSet& aOther) const;
       
   325 
       
   326 	/** Set channel opening result */
       
   327 	TResultSet& ChannelOpenResult(TInt aResult) {iChannelOpenResult = aResult; return *this;}
       
   328 	TResultSet& PostTransferResult(TInt aResult) {iPostTransferCheck = aResult; return *this;}
       
   329 	/** Set request results */
       
   330 	TResultSet& RequestResult(const TRequestResults& aResults) {iRequestResult = aResults; return *this;}
       
   331 	/** Set Callback record */
       
   332 	TResultSet& CallbackRecord(const TCallbackRecord& aCallbackRecord) {iCallbackRecord = aCallbackRecord; return *this;}
       
   333 
       
   334 	TInt iChannelOpenResult;
       
   335 	TRequestResults iRequestResult;
       
   336 	TInt iPostTransferCheck;
       
   337 	TCallbackRecord iCallbackRecord;
       
   338 	};
       
   339 
       
   340 /**
       
   341 Fills each source buffer with an increasing value and clears each destination
       
   342 */
       
   343 class TPreTransferIncrBytes : public MPreTransfer
       
   344 	{
       
   345 public:
       
   346 	TPreTransferIncrBytes()
       
   347 		{}
       
   348 
       
   349 	virtual void Setup(const CSingleTransferTest& aTest) const;
       
   350 	virtual void Setup(const CIsrRequeTest& aTest) const;
       
   351 	virtual void Setup(const CMultiTransferTest& aTest) const;
       
   352 
       
   353 	static void SelfTest();
       
   354 protected:
       
   355 	virtual void Setup(const TAddressParms& aParams) const;
       
   356 
       
   357 	TBool CheckBuffers(const CIsrRequeTest& aTest) const;
       
   358 	TBool CheckBuffers(const CMultiTransferTest& aTest) const;
       
   359 
       
   360 	TBool CheckBuffers(const RArray<const TAddressParms>& aTransferParams, TBool aAllowExactRepeat=ETrue) const;
       
   361 
       
   362 	// This function is part of the unit test
       
   363 	friend TBool DoTferParmTestL(const TAddressParms* aParms, TInt aCount, TBool aAllowRepeat, TBool aPositive);
       
   364 	};
       
   365 
       
   366 const TPreTransferIncrBytes KPreTransferIncrBytes;
       
   367 const TCompareSrcDst KCompareSrcDst;
       
   368 const TCompare2D KCompare2D;
       
   369 const TCheckNoTransfer KCheckNoTransfer;
       
   370 
       
   371 
       
   372 /**
       
   373 Iterates over the bytes in buffer, in the order
       
   374 the supllied DMA config would access them
       
   375 */
       
   376 class TTransferIter
       
   377 	{
       
   378 public:
       
   379 	TTransferIter()
       
   380 		:iCfg(NULL), iPtr(NULL)
       
   381 		{}
       
   382 
       
   383 	TTransferIter(const TDmaTransferConfig& aCfg, TUint8* aChunkBase=NULL)
       
   384 		:iElem(0), iFrame(0), iCfg(&aCfg), iChunkBase(aChunkBase), iPtr(Start()), iBytes(0)
       
   385 		{}
       
   386 
       
   387 	void operator++ ();
       
   388 	TUint8& operator* ()
       
   389 		{
       
   390 		Invariant();
       
   391 		return *iPtr;
       
   392 		}
       
   393 
       
   394 	TBool operator!= (const TTransferIter& aOther)
       
   395 		{
       
   396 		return (iPtr != aOther.iPtr);
       
   397 		}
       
   398 
       
   399 	static void SelfTest();
       
   400 private:
       
   401 	TUint8* Start() const
       
   402 		{
       
   403 		return iChunkBase + iCfg->iAddr;
       
   404 		}
       
   405 
       
   406 	void Invariant() const;
       
   407 
       
   408 	TUint iElem; //!< The current element
       
   409 	TUint iFrame; //!< The current frame
       
   410 
       
   411 	const TDmaTransferConfig* const iCfg;
       
   412 	TUint8* iChunkBase;
       
   413 
       
   414 	TUint8* iPtr; //<! Pointer to the current byte
       
   415 
       
   416 	TUint iBytes; //!< The number of bytes traversed
       
   417 	};
       
   418 
       
   419 /**
       
   420 Performs a single DMA transfer using the member TDmaTransferArgs on
       
   421 one channel. At each stage of the transfer results are recorded in a
       
   422 TResultSet struct: at the end these are compared with a set of expected
       
   423 results.
       
   424 */
       
   425 class CSingleTransferTest : public CDmaTest
       
   426 	{
       
   427 public:
       
   428 	CSingleTransferTest(
       
   429 			const TDesC& aName, TInt aIterations,
       
   430 			const TDmaTransferArgs& aArgs,
       
   431 			const TResultSet& aExpected,
       
   432 			TUint aMaxFragmentSize = 0,
       
   433 			const MPostTransferCheck* aPostTferChk = &KCompareSrcDst,
       
   434 			const MPreTransfer* aPreTfer = &KPreTransferIncrBytes
       
   435 			)
       
   436 		: CDmaTest(aName, aIterations, aPreTfer, aPostTferChk),
       
   437 		iTransferArgs(aArgs),iExpected(aExpected),iActual(EFalse),
       
   438 		iUseNewRequest(ETrue),
       
   439 		iUseNewFragment(ETrue),
       
   440 		iMaxFragmentSize(aMaxFragmentSize)
       
   441 		{}
       
   442 
       
   443 	/**
       
   444 	Perform each stage of trasnfer
       
   445 	*/
       
   446 	virtual void RunTest();
       
   447 	virtual void PrintTestType() const;
       
   448 	virtual void PrintTestInfo() const;
       
   449 
       
   450 	virtual CTest* Clone() const {return new CSingleTransferTest(*this);}
       
   451 
       
   452 	/**
       
   453 	Compares the actual vs the exepected results and reports
       
   454 	of the test passed
       
   455 	@return ETrue for a pass, EFalse for a fail
       
   456 	 */
       
   457 	virtual TBool Result();
       
   458 
       
   459 	/**
       
   460 	An accessor function for the object's TDmaTransferArgs
       
   461 	*/
       
   462 	const TDmaTransferArgs& TransferArgs() const
       
   463 		{return iTransferArgs;}
       
   464 
       
   465 	// The below methods are setters, which may be chained together
       
   466 	// ie. The Named Parameter Idiom
       
   467 	// @see http://www.parashift.com/c++-faq-lite/ctors.html#faq-10.18
       
   468 	inline CSingleTransferTest& UseNewRequest(TBool aFlag) {iUseNewRequest=aFlag; return *this;}
       
   469 	inline CSingleTransferTest& UseNewFragment(TBool aFlag) {iUseNewFragment=aFlag; return *this;}
       
   470 	inline CSingleTransferTest& UseNewDmaApi(TBool aFlag) {UseNewRequest(aFlag); UseNewFragment(aFlag); return *this;}
       
   471 
       
   472 protected:
       
   473 	virtual void OpenChannel();
       
   474 	virtual void PreTransferSetup();
       
   475 	virtual void CreateDmaRequest();
       
   476 	virtual void Fragment();
       
   477 	virtual void Queue();
       
   478 	virtual void PostTransferCheck();
       
   479 	virtual TInt DoPostTransferCheck();
       
   480 	virtual void FreeRequest();
       
   481 	virtual void CloseChannel();
       
   482 
       
   483 protected:
       
   484 	/**
       
   485 	A handle to kernel side TDmaChannel object received after a channel is opened.
       
   486 	*/
       
   487 	TUint iChannelSessionCookie;
       
   488 	/**
       
   489 	A handle to kernel side DDmaRequest object.
       
   490 	*/
       
   491 	TUint iRequestSessionCookie;
       
   492 
       
   493 	const TDmaTransferArgs& iTransferArgs;
       
   494 
       
   495 	/**
       
   496 	Expected transfer results
       
   497 	*/
       
   498 	TResultSet iExpected;
       
   499 
       
   500 	/**
       
   501 	Filled with actual transfer results
       
   502 	*/
       
   503 	TResultSet iActual;
       
   504 
       
   505 	TBool iUseNewRequest; //!< If true then CSingleTransferTest will create a DDmaRequest with the v2 ctor
       
   506 	TBool iUseNewFragment; //!< If true then CSingleTransferTest will use v2 Fragment API
       
   507 	const TUint iMaxFragmentSize;
       
   508 	};
       
   509 
       
   510 /**
       
   511 This class will be used for testing DMA Close() and Open() API
       
   512 
       
   513 Extends CDmaTest by implemeting a RunTest() with a sequence of operations 
       
   514 to test Close() and Open() API 
       
   515 */
       
   516 class COpenCloseTest : public CDmaTest 
       
   517 	{
       
   518 public:
       
   519 	COpenCloseTest(
       
   520 			const TDesC& aName, TInt aIterations,	
       
   521 			const MPostTransferCheck* aPostTferChk = NULL,
       
   522 			const MPreTransfer* aPreTfer = NULL
       
   523 			)
       
   524 		: CDmaTest(aName, aIterations, aPreTfer, aPostTferChk), iOpenCloseResult(EFalse) , iRunOpen(EFalse)
       
   525 		{}
       
   526 
       
   527 	~COpenCloseTest();
       
   528 
       
   529 	virtual void RunTest();
       
   530 	virtual void PrintTestType() const;
       
   531 
       
   532 	virtual CTest* Clone() const {return new COpenCloseTest(*this);}
       
   533 	
       
   534 	/**
       
   535 	Checks the results of the sequeunce of  sequence of operations 
       
   536 	to test Close() and Open() API, return ETrue for a pass, EFalse for a fail
       
   537 	 */
       
   538 	virtual TBool Result();
       
   539 
       
   540 	// The methods below is a setters ie. The Named Parameter Idiom
       
   541 	// @see http://www.parashift.com/c++-faq-lite/ctors.html#faq-10.18
       
   542 	inline COpenCloseTest& RunOpenApiTest(TBool aFlag) {iRunOpen=aFlag; return *this;}
       
   543 
       
   544 protected:	
       
   545 	TBool DoRunClose();
       
   546 	TBool DoRunOpen();
       
   547 	TBool DoRunOpenExposed();
       
   548 
       
   549 protected:
       
   550 	/**
       
   551 	A handle to kernel side TDmaChannel object received after a channel is opened.
       
   552 	*/
       
   553 	TUint iChannelSessionCookie;
       
   554 	/**
       
   555 	A handle to kernel side DDmaRequest object.
       
   556 	*/
       
   557 	TUint iRequestSessionCookie;
       
   558 
       
   559 	/**
       
   560 	If true then Close/Open  API test passed
       
   561 	*/
       
   562 	TBool iOpenCloseResult;
       
   563 	
       
   564 	/**
       
   565 	 If true then run Open API test otherwise run Close API test
       
   566 	*/
       
   567 	TBool iRunOpen;
       
   568 	};
       
   569 
       
   570 /**
       
   571 Used for testing Pause and Resume
       
   572 
       
   573 Extends CSingle transfer by adding the capability to test
       
   574 Pause  & Resume() API.
       
   575 */
       
   576 class CPauseResumeTest : public CSingleTransferTest
       
   577 	{
       
   578 public:
       
   579 	 CPauseResumeTest(const TDesC& aName, TInt aIterations, const TDmaTransferArgs& aArgs, const TResultSet& aExpected)
       
   580 		:CSingleTransferTest(aName, aIterations, aArgs, aExpected)
       
   581 	 {}
       
   582 
       
   583 	~CPauseResumeTest();
       
   584 
       
   585 	virtual void RunTest();
       
   586 	virtual void PrintTestType() const;
       
   587 
       
   588 	virtual CTest* Clone() const {return new  CPauseResumeTest(*this);}
       
   589 
       
   590 	// The methods below is a setters ie. The Named Parameter Idiom
       
   591 	// @see http://www.parashift.com/c++-faq-lite/ctors.html#faq-10.18
       
   592 	inline CPauseResumeTest& UseNewDmaApi(TBool aFlag) {CSingleTransferTest::UseNewDmaApi(aFlag); return *this;}
       
   593 
       
   594 protected:
       
   595 	void DoCalibrationTransfer(TUint64 &atime);
       
   596 	TInt QueueAsyncRequest(TRequestStatus &aRequestState,TUint64 &atime);
       
   597 	};
       
   598 
       
   599 /**
       
   600 Used for testing Pause and Resume ( Negative Testing)
       
   601 
       
   602 Extends CSingle transfer by adding the capability to test
       
   603 Pause  & Resume() API. Expects that Pause and Resume is not supported
       
   604 */
       
   605 class CPauseResumeNegTest : public CSingleTransferTest
       
   606 	{
       
   607 public:
       
   608 	 CPauseResumeNegTest(const TDesC& aName, TInt aIterations, const TDmaTransferArgs& aArgs, const TResultSet& aExpected)
       
   609 		:CSingleTransferTest(aName, aIterations, aArgs, aExpected)
       
   610 	 {}
       
   611 
       
   612 	~CPauseResumeNegTest();
       
   613 
       
   614 	virtual void RunTest();
       
   615 	virtual void PrintTestType() const;
       
   616 
       
   617 	virtual CTest* Clone() const {return new  CPauseResumeNegTest(*this);}
       
   618 
       
   619 	// The methods below is a setters ie. The Named Parameter Idiom
       
   620 	// @see http://www.parashift.com/c++-faq-lite/ctors.html#faq-10.18
       
   621 	inline CPauseResumeNegTest& UseNewDmaApi(TBool aFlag) {CSingleTransferTest::UseNewDmaApi(aFlag); return *this;}
       
   622 	};
       
   623 
       
   624 
       
   625 /**
       
   626 Used for testing element counting 
       
   627 
       
   628 Extends CSingle transfer by adding the capability to test
       
   629 Element Counting APIs
       
   630 */
       
   631 class CElementCountingTest : public CSingleTransferTest
       
   632 	{
       
   633 public:
       
   634 	 CElementCountingTest(const TDesC& aName, TInt aIterations, const TDmaTransferArgs& aArgs, const TResultSet& aExpected)
       
   635 		:CSingleTransferTest(aName, aIterations, aArgs, aExpected)
       
   636 	 {}
       
   637 
       
   638 	~CElementCountingTest();
       
   639 
       
   640 	virtual void RunTest();
       
   641 	virtual void PrintTestType() const;
       
   642 
       
   643 	virtual CTest* Clone() const {return new CElementCountingTest(*this);}
       
   644 
       
   645 	// The methods below is a setters ie. The Named Parameter Idiom
       
   646 	// @see http://www.parashift.com/c++-faq-lite/ctors.html#faq-10.18
       
   647 	inline CElementCountingTest& UseNewDmaApi(TBool aFlag) {CSingleTransferTest::UseNewDmaApi(aFlag); return *this;}
       
   648 	};
       
   649 
       
   650 
       
   651 /**
       
   652 Used for testing Linking of DMA Channels ( Negative Testing)
       
   653 
       
   654 Extends CSingle transfer by adding the capability to test DMA channel linking
       
   655 Expects that channel linking is not supported
       
   656 */
       
   657 class CLinkChannelTest : public CSingleTransferTest
       
   658 	{
       
   659 public:
       
   660 	 CLinkChannelTest(const TDesC& aName, TInt aIterations, const TDmaTransferArgs& aArgs, const TResultSet& aExpected)
       
   661 		:CSingleTransferTest(aName, aIterations, aArgs, aExpected)
       
   662 	 {}
       
   663 
       
   664 	~CLinkChannelTest();
       
   665 
       
   666 	virtual void RunTest();
       
   667 	virtual void PrintTestType() const;
       
   668 
       
   669 	virtual CTest* Clone() const {return new  CLinkChannelTest(*this);}
       
   670 
       
   671 	// The methods below is a setters ie. The Named Parameter Idiom
       
   672 	// @see http://www.parashift.com/c++-faq-lite/ctors.html#faq-10.18
       
   673 	inline CLinkChannelTest& UseNewDmaApi(TBool aFlag) {CSingleTransferTest::UseNewDmaApi(aFlag); return *this;}
       
   674 	};
       
   675 
       
   676 
       
   677 /**
       
   678 This class will be used for tests which benchmark certain DMA operations
       
   679 */
       
   680 class CDmaBenchmark : public CSingleTransferTest
       
   681 	{
       
   682 public:
       
   683 	CDmaBenchmark(const TDesC& aName, TInt aIterations, const TResultSet& aExpectedResults, const TDmaTransferArgs& aTransferArgs, TUint aMaxFragmentSize);
       
   684 	CDmaBenchmark(const CDmaBenchmark& aOriginal);
       
   685 	~CDmaBenchmark();
       
   686 
       
   687 	virtual TBool Result();
       
   688 
       
   689 	static void SelfTest();
       
   690 
       
   691 protected:
       
   692 	/**
       
   693 	@return The mean average of the result array
       
   694 	*/
       
   695 	TUint64 MeanResult();
       
   696 
       
   697 	RArray<TUint64> iResultArray;
       
   698 	};
       
   699 
       
   700 /**
       
   701 Fragments requests (only) and records duration
       
   702 */
       
   703 class CDmaBmFragmentation : public CDmaBenchmark
       
   704 	{
       
   705 public:
       
   706 	CDmaBmFragmentation(const TDesC& aName, TInt aIterations, const TDmaTransferArgs& aTransferArgs, TUint aMaxFragmentSize);
       
   707 	virtual CTest* Clone() const {return new CDmaBmFragmentation(*this);}
       
   708 	virtual TInt DoPostTransferCheck()
       
   709 		{TEST_FAULT; return KErrNotSupported;}
       
   710 
       
   711 	virtual void RunTest();
       
   712 	virtual void PrintTestType() const;
       
   713 
       
   714 protected:
       
   715 	void Fragment();
       
   716 	static const TResultSet ExpectedResults;
       
   717 	};
       
   718 
       
   719 /**
       
   720 Performs a transfer using an old style DDmaRequest and
       
   721 records the duration
       
   722 */
       
   723 class CDmaBmTransfer : public CDmaBenchmark
       
   724 	{
       
   725 public:
       
   726 	CDmaBmTransfer(const TDesC& aName, TInt aIterations, const TDmaTransferArgs& aTransferArgs, TUint aMaxFragmentSize);
       
   727 	virtual CTest* Clone() const {return new CDmaBmTransfer(*this);}
       
   728 	virtual TInt DoPostTransferCheck()
       
   729 		{TEST_FAULT; return KErrNotSupported;}
       
   730 
       
   731 	virtual void RunTest();
       
   732 	virtual void PrintTestType() const;
       
   733 
       
   734 	inline CDmaBmTransfer& UseNewDmaApi(TBool aFlag) {CSingleTransferTest::UseNewDmaApi(aFlag); return *this;}
       
   735 	inline CDmaBmTransfer& ExpectedResults(const TResultSet& aArgs) {iExpected=aArgs; return *this;}
       
   736 protected:
       
   737 	void Queue();
       
   738 	};
       
   739 
       
   740 
       
   741 
       
   742 /**
       
   743 Will create and queue multiple requests
       
   744 
       
   745 Unlike CSingleTransferTest the class does not permit the use of TResultSet to
       
   746 define expected results (for neagative testing)
       
   747 */
       
   748 class CMultiTransferTest : public CDmaTest
       
   749 	{
       
   750 public:
       
   751 	CMultiTransferTest(const TDesC& aName, TInt aIterations, const TDmaTransferArgs* aTransferArgs, const TResultSet* aResultSets, TInt aCount);
       
   752 	CMultiTransferTest(const CMultiTransferTest& aOther);
       
   753 	virtual ~CMultiTransferTest();
       
   754 	virtual CTest* Clone() const {return new CMultiTransferTest(*this);}
       
   755 
       
   756 	virtual TBool Result();
       
   757 	virtual void RunTest();
       
   758 	virtual void PrintTestType() const;
       
   759 
       
   760 	inline CMultiTransferTest& PauseWhileQueuing() {iPauseWhileQueuing = ETrue; return *this;}
       
   761 	inline CMultiTransferTest& SetPreTransferTest(const MPreTransfer* aPreTfer) {iPreTransfer = aPreTfer; return *this;}
       
   762 	inline CMultiTransferTest& SetPostTransferTest(const MPostTransferCheck* aPostTfer) {iPostTransferCheck = aPostTfer; return *this;}
       
   763 
       
   764 	const TDmaTransferArgs& TransferArgs(TInt aIndex) const;
       
   765 	inline TInt TransferCount() const {return iTransferArgsCount;}
       
   766 
       
   767 	void SetPostTransferResult(TInt aIndex, TInt aErrorCode);
       
   768 protected:
       
   769 	void OpenChannel();
       
   770 	TInt CloseChannel();
       
   771 	void CreateDmaRequests();
       
   772 	void Fragment();
       
   773 	void QueueRequests();
       
   774 
       
   775 	virtual void PreTransferSetup();
       
   776 	virtual TInt DoPostTransferCheck();
       
   777 
       
   778 	TBool Result(TInt aTransfer);
       
   779 
       
   780 	const TDmaTransferArgs* const iTransferArgs; //pointer to an array of transfer args
       
   781 	const TInt iTransferArgsCount;
       
   782 
       
   783 
       
   784 	TBool iNewDmaApi; //!< If true then CMultiTransferTest will use new style API
       
   785 
       
   786 	/**
       
   787 	A handle to kernel side TDmaChannel object received after a channel is opened.
       
   788 	*/
       
   789 	TUint iChannelSessionCookie;
       
   790 	RArray<TUint> iRequestCookies;
       
   791 
       
   792 	const TResultSet* const iExpectedArray; // array will be of length iTransferArgsCount
       
   793 	RArray<TResultSet> iActualResults;
       
   794 
       
   795 	/**
       
   796 	If set, the test will pause the channel before queuing requests, and
       
   797 	resume once they are all queued
       
   798 	*/
       
   799 	TBool iPauseWhileQueuing;
       
   800 	};
       
   801 
       
   802 /**
       
   803 Used for testing TDmaChannel::IsQueueEmpty
       
   804 Extends CMultiTransferTest by adding the capability to test IsQueueEmpty() API. 
       
   805 */
       
   806 class CIsQueueEmptyTest : public  CMultiTransferTest 
       
   807 	{
       
   808 public:
       
   809 	CIsQueueEmptyTest(const TDesC& aName, TInt aIterations, const TDmaTransferArgs* aTransferArgs, const TResultSet* aResultSets, TInt aCount);
       
   810 	CIsQueueEmptyTest(const CIsQueueEmptyTest& aOther);
       
   811 	~CIsQueueEmptyTest();
       
   812 
       
   813 	inline CIsQueueEmptyTest& SetPreTransferTest(const MPreTransfer* aPreTfer) {iPreTransfer = aPreTfer; return *this;}
       
   814 	inline CIsQueueEmptyTest& SetPostTransferTest(const MPostTransferCheck* aPostTfer) {iPostTransferCheck = aPostTfer; return *this;}
       
   815 
       
   816 	virtual CTest* Clone() const {return new CIsQueueEmptyTest(*this);}
       
   817 	virtual void RunTest();
       
   818 	virtual void PrintTestType() const;
       
   819 
       
   820 protected:
       
   821 	void DoQueueNotEmpty();	
       
   822 	void DoIsQueueEmpty();
       
   823 	void QueueRequests();
       
   824 	};
       
   825 
       
   826 /**
       
   827 Used for testing CancelAll, Will create and queue multiple requests
       
   828 Extends CSingle transfer by adding the capability to test CancelAll API
       
   829 */
       
   830 class CCancelAllTest : public CMultiTransferTest
       
   831 	{
       
   832 public:
       
   833 	CCancelAllTest(const TDesC& aName, TInt aIterations,
       
   834 		const TDmaTransferArgs* aTransferArgs, const TResultSet* aResultSets,
       
   835 		TInt aCount
       
   836 		);
       
   837 	//CCancelAllTest(const CCacheNotifyDirCh
       
   838 
       
   839 	virtual void RunTest();
       
   840 	virtual void PrintTestType() const;
       
   841 	virtual CTest* Clone() const {return new CCancelAllTest(*this);}
       
   842 
       
   843 	inline CCancelAllTest& PauseWhileQueuing()
       
   844 		{iPauseWhileQueuing = ETrue; return *this;}
       
   845 	inline CCancelAllTest& SetPreTransferTest(const MPreTransfer* aPreTfer)
       
   846 		{iPreTransfer = aPreTfer; return *this;}
       
   847 	inline CCancelAllTest& SetPostTransferTest(const MPostTransferCheck* aPostTfer)
       
   848 		{iPostTransferCheck = aPostTfer; return *this;}
       
   849 
       
   850 protected:
       
   851 	void QueueRequestsAsync();
       
   852 	TInt CancelAllRequests();
       
   853 	void PauseChannel();
       
   854 	void ResumeChannel();
       
   855 
       
   856 	/**
       
   857 	A single request status that we use for all
       
   858 	asynchronously queued requests (we do not intend
       
   859 	to wait for them)
       
   860 	*/
       
   861 	TRequestStatus iDummyRequestStatus;
       
   862 	};
       
   863 
       
   864 /**
       
   865 Used for testing TDmaChannel::IsrRedoRequest
       
   866 
       
   867 Extends CSingle transfer by adding the capability to queue with
       
   868 additonal transfer parameters (TIsrRequeArgs) which are passed
       
   869 to IsrRedoRequest in ISR callback
       
   870 */
       
   871 class CIsrRequeTest : public CSingleTransferTest
       
   872 	{
       
   873 public:
       
   874 	CIsrRequeTest(const TDesC& aName, TInt aIterations, const TDmaTransferArgs& aArgs,
       
   875 			TIsrRequeArgs* aRequeueArgs, TInt aCount,
       
   876 			const TResultSet& aExpected, const MPreTransfer* aPreTfer,
       
   877 			const MPostTransferCheck* aPostTferChk, TUint aMaxFragmentSize=0);
       
   878 
       
   879 	virtual void PrintTestType() const;
       
   880 
       
   881 	virtual void Queue();
       
   882 	virtual CTest* Clone() const {return new CIsrRequeTest(*this);}
       
   883 
       
   884 	const TIsrRequeArgsSet& GetRequeueArgs() const
       
   885 		{return iRequeArgSet;}
       
   886 
       
   887 
       
   888 protected:
       
   889 	virtual TInt DoPostTransferCheck();
       
   890 	virtual void PreTransferSetup();
       
   891 
       
   892 	TIsrRequeArgsSet iRequeArgSet;
       
   893 	};
       
   894 
       
   895 /**
       
   896 A channel record collects DMA channel capabilities and other PSL information
       
   897 before running tests.
       
   898 */
       
   899 class TChannelRecord
       
   900 	{
       
   901 public:
       
   902 	TChannelRecord(){}
       
   903 	~TChannelRecord(){}
       
   904 
       
   905 	/**
       
   906 	DMA Channel Cookie
       
   907 	*/
       
   908 	TUint   iCookie;
       
   909 
       
   910 	/**
       
   911 	DMA Channel Capabilities
       
   912 	*/
       
   913 	TDmacTestCaps iChannelCaps;
       
   914 	};
       
   915 
       
   916 /**
       
   917 A test case collects together a DMA test (CDmaTest), its hardware prerequisites,
       
   918 and other information about how the test should be run.
       
   919 */
       
   920 class TTestCase
       
   921 	{
       
   922 public:
       
   923 	TTestCase(CDmaTest* aTest,
       
   924            TBool aConcurrent = EFalse,
       
   925 		   const TDmaCapability = TDmaCapability(),
       
   926 		   const TDmaCapability = TDmaCapability(),
       
   927 		   const TDmaCapability = TDmaCapability(),
       
   928 		   const TDmaCapability = TDmaCapability(),
       
   929 		   const TDmaCapability = TDmaCapability()
       
   930 		   );
       
   931 
       
   932 	static void SelfTest();
       
   933 
       
   934 	/**
       
   935 	Compares the requirements held in the class
       
   936 	against those described in aChannelCaps and makes a decision
       
   937 	as to whether this test case should be run, skipped, or failed.
       
   938 	*/
       
   939 	TResult TestCaseValid(const SDmacCaps& aChannelCaps) const;
       
   940 	TResult TestCaseValid(const TDmacTestCaps& aChannelCaps) const;
       
   941 
       
   942 	enum {KMaxChannelCaps=5};
       
   943 	TDmaCapability	iChannelCaps[KMaxChannelCaps];
       
   944 	TUint iChannelType;
       
   945 	TInt iTimeout;
       
   946 	CDmaTest* iTest;
       
   947 	TBool iConcurrentTest;
       
   948 	TBool iDmaV2Only; //!< If true then this test cannot be run on DMA v1 framework
       
   949 	};
       
   950 
       
   951 /**
       
   952 A TestRunner manages the whole testing process.Before running any test cases it will open its own RDmaSession 
       
   953 handle, not associated with a DMA channel, so that it can recover the TDmaTestInfo object (as used by the 
       
   954 existing DMA framework) which says what channels are available to be tested.It will use TTestThread objects 
       
   955 to run tests in new threads.TTestThread contains a number of useful features such as waiting for thread exit 
       
   956 and accepting a TFunctor object to be run in a new thread. 
       
   957 */
       
   958 class TTestRunner
       
   959 {
       
   960 public:
       
   961 	TTestRunner();
       
   962 	~TTestRunner();
       
   963 
       
   964 	/**
       
   965 	This function will populate TTestRunner with an array of test cases
       
   966 	to be run
       
   967 
       
   968 	@param aTTestCases Array of test cases
       
   969 	*/
       
   970 	void AddTestCases(RPointerArray<TTestCase>& aTTestCases);
       
   971 
       
   972 	/**
       
   973 	This will iterate over all test cases held by the test runner and
       
   974 	for each one will judge which DMA channels it can be run on, running
       
   975 	the test if possible.
       
   976 	*/
       
   977 	void RunTests();
       
   978 
       
   979 private:
       
   980 	/**
       
   981 	This functions retrieves the PSL cookies from all the DMA channels
       
   982 	and stores them in a single array.	It will use information from 
       
   983 	the PslTestInfo.
       
   984 	*/
       
   985 	void GetPslCookie();
       
   986 
       
   987 	/**
       
   988 	This function will generate the DMA channel records.i.e channel cookies,Caps.
       
   989 	*/
       
   990 	void GenerateChannelRecord();
       
   991 
       
   992 	/**
       
   993 	Holds the PslTestInfo
       
   994 	*/	
       
   995 	TDmaV2TestInfo iPslTestInfo;
       
   996 
       
   997 	/**
       
   998 	A handle to RDmaSession
       
   999 	*/
       
  1000 	RDmaSession iDmaSession;
       
  1001 	
       
  1002 	/**
       
  1003 	Array of DMA test cases 
       
  1004 	*/
       
  1005 	RPointerArray<TTestCase> iTestCases; 
       
  1006 	
       
  1007 	/**
       
  1008 	Array of DMA channel records,channel capabilities and other PSL information
       
  1009 	*/
       
  1010 	RArray<TChannelRecord> iChannelRecords; 	
       
  1011 
       
  1012 	/**
       
  1013 	Array of DMA channel cookies
       
  1014 	*/
       
  1015 	RArray<TUint> iPslCookies;
       
  1016 };
       
  1017 
       
  1018 /**
       
  1019 Copy an RArray
       
  1020 */
       
  1021 template <typename T>
       
  1022 void CopyL(const RArray<T>& aOriginal, RArray<T>& aNew)
       
  1023 	{
       
  1024 	const TInt count = aOriginal.Count();
       
  1025 	for(TInt i=0; i<count; ++i)
       
  1026 		{
       
  1027 		aNew.AppendL(aOriginal[i]);
       
  1028 		}
       
  1029 	}
       
  1030 
       
  1031 template <typename T, typename Iterator>
       
  1032 void ArrayAppendL(RArray<T>& aArray, Iterator aBegin, Iterator aEnd)
       
  1033 	{
       
  1034 	for(Iterator begin = aBegin; begin != aEnd; ++begin)
       
  1035 		aArray.AppendL(*begin);
       
  1036 	}
       
  1037 
       
  1038 
       
  1039 #endif // #ifndef __T_DMA2_H__