kerneltest/e32test/dmav2/t_dma2.cpp
changeset 139 95f71bcdcdb7
parent 36 538db54a451d
child 199 189ece41fa29
child 247 d8d70de2bd36
equal deleted inserted replaced
109:b3a1d9898418 139:95f71bcdcdb7
     1 // Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies).
     1 // Copyright (c) 2002-2010 Nokia Corporation and/or its subsidiary(-ies).
     2 // All rights reserved.
     2 // All rights reserved.
     3 // This component and the accompanying materials are made available
     3 // This component and the accompanying materials are made available
     4 // under the terms of "Eclipse Public License v1.0"
     4 // under the terms of "Eclipse Public License v1.0"
     5 // which accompanies this distribution, and is available
     5 // which accompanies this distribution, and is available
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
     9 // Nokia Corporation - initial contribution.
     9 // Nokia Corporation - initial contribution.
    10 //
    10 //
    11 // Contributors:
    11 // Contributors:
    12 //
    12 //
    13 // Description:
    13 // Description:
    14 // e32test\dma\t_dma.cpp
    14 // e32test\dmav2\t_dma2.cpp
    15 
    15 
    16 #include "d_dma2.h"
    16 #include "d_dma2.h"
    17 #include "u32std.h"
    17 #include "u32std.h"
    18 #include "t_dma2.h"
    18 #include "t_dma2.h"
    19 #include "cap_reqs.h"
    19 #include "cap_reqs.h"
    24 #include <e32svr.h>
    24 #include <e32svr.h>
    25 #include <e32def_private.h>
    25 #include <e32def_private.h>
    26 
    26 
    27 // DMA test framework command  parameter options
    27 // DMA test framework command  parameter options
    28 
    28 
    29 // SelfTest Option
    29 // SelfTest option
    30 _LIT(KArgSelfTest, "/SELFTEST");  
    30 _LIT(KArgSelfTest, "/SELFTEST");  
    31 _LIT(KArgSelfTest2, "/S");		  
    31 _LIT(KArgSelfTest2, "/S");		  
    32 
    32 
    33 //Verbose Option
    33 //Verbose option
    34 _LIT(KArgVerboseOutput, "/VERBOSE"); 
    34 _LIT(KArgVerboseOutput, "/VERBOSE"); 
    35 _LIT(KArgVerboseOutput2, "/V");	     
    35 _LIT(KArgVerboseOutput2, "/V");	     
    36   
    36   
       
    37 //Simple transfer test option
       
    38 _LIT(KArgSimpleTest, "/simple"); 
       
    39 
       
    40 //Callback test option
       
    41 _LIT(KArgCallBackTest, "/callback");
       
    42 
       
    43 //Suspend test option
       
    44 _LIT(KArgSuspendTest, "/suspend");
       
    45 
       
    46 //Multipart transfer tests
       
    47 _LIT(KArgMultiPartTest, "/multi");
       
    48 
       
    49 //Isr and dfc test option
       
    50 _LIT(KArgIsrDfcTest, "/isrdfc");
       
    51 
       
    52 //Isr reque  test option
       
    53 _LIT(KArgIsrequeTest, "/isreque");
       
    54 
       
    55 //Benchmark test option
       
    56 _LIT(KArgBenchmarkTest, "/bench");
       
    57 
       
    58 //Graphics test option
       
    59 _LIT(KArgGraphicTest, "/graphic");
       
    60 
       
    61 //DMA channel (opening and closing)  test option
       
    62 _LIT(KArgChannelTest, "/channel");
       
    63 
       
    64 //Queue test option
       
    65 _LIT(KArgQueueTest, "/queue");
       
    66 
       
    67 //Fragment test option
       
    68 _LIT(KArgFragmentTest, "/fragment");
       
    69 
       
    70 //Request test option
       
    71 _LIT(KArgRequestTest, "/request");
       
    72 
       
    73 
    37 
    74 
    38 TBool gHelpRequested;   // print usage 
    75 TBool gHelpRequested;   // print usage 
    39 TBool gVerboseOutput;   // enable verbose output 
    76 TBool gVerboseOutput;   // enable verbose output 
    40 TBool gSelfTest;        // run SelfTest 
    77 TBool gSelfTest;        // run SelfTest 
       
    78 TBool gSimpleTest;		// run only Simple transfer test
       
    79 TBool gCallBack;		// run only Callback test
       
    80 TBool gSuspend;			// run only Pause and resume tests
       
    81 TBool gIsrReque;		// run only IsrReque tests
       
    82 TBool gMultiPart;		// run only Multipart tests
       
    83 TBool gIsrAndDfc;		// run only IsrAndDfc tests
       
    84 TBool gBenchmark;		// run only Benchmark tests
       
    85 TBool gGraphic;			// run only Graphic tests
       
    86 TBool gFragment;		// run only Fragment related tests
       
    87 TBool gChannel;			// run only Channel(open/close)tests
       
    88 TBool gQueue;			// run only Queue related tests
       
    89 TBool gRequest;			// run only Request related tests
    41 
    90 
    42 /**
    91 /**
    43 This function prints out the PSL test Information
    92 This function prints out the PSL test Information
    44 */
    93 */
    45 void Print(const TDmaV2TestInfo& aInfo)
    94 void Print(const TDmaV2TestInfo& aInfo)
    75 // CDmaTest
   124 // CDmaTest
    76 //////////////////////////////////////////////////////////////////////
   125 //////////////////////////////////////////////////////////////////////
    77 
   126 
    78 void CDmaTest::OpenDmaSession()
   127 void CDmaTest::OpenDmaSession()
    79 	{
   128 	{
    80 	TInt r = iDmaSession.Open();
   129 	// Only open a new session if one
       
   130 	// was not already supplied
       
   131 	if(iDmaSession.Handle() == KNullHandle)
       
   132 		{
       
   133 		TInt r = iDmaSession.Open();
       
   134 		TEST_ASSERT(r == KErrNone);
       
   135 		r = iDmaSession.OpenSharedChunk(iChunk);
       
   136 		TEST_ASSERT(r == KErrNone);
       
   137 		}
       
   138 	}
       
   139 
       
   140 // Open another handle to the test driver
       
   141 void CDmaTest::OpenDmaSession(const RDmaSession& aSession)
       
   142 	{
       
   143 	iDmaSession = aSession;
       
   144 	TInt r = iDmaSession.Duplicate(RThread(), EOwnerThread);
    81 	TEST_ASSERT(r == KErrNone);
   145 	TEST_ASSERT(r == KErrNone);
       
   146 
       
   147 	// open another handle to the test driver chunk
    82 	r = iDmaSession.OpenSharedChunk(iChunk);
   148 	r = iDmaSession.OpenSharedChunk(iChunk);
    83 	TEST_ASSERT(r == KErrNone);
   149 	TEST_ASSERT(r == KErrNone);
    84 	}
   150 	}
    85 
   151 
    86 void CDmaTest::CloseDmaSession()
   152 void CDmaTest::CloseDmaSession()
    87 	{
   153 	{
    88 	iChunk.Close();
   154 	iChunk.Close();
    89 	iDmaSession.Close();
   155 	iDmaSession.Close();
    90 	}
   156 	}
    91 
   157 
       
   158 void CDmaTest::PreTransferSetup()
       
   159 	{
       
   160 	}
       
   161 
       
   162 TInt CDmaTest::DoPostTransferCheck()
       
   163 	{
       
   164 	return KErrNotSupported;
       
   165 	}
       
   166 
       
   167 void CDmaTest::ChannelPause(TUint aChannelSessionCookie)
       
   168 {
       
   169 	TInt r = iDmaSession.ChannelPause(aChannelSessionCookie);
       
   170 	TEST_ASSERT(r == KErrNone);
       
   171 }
       
   172 
       
   173 void CDmaTest::ChannelResume(TUint aChannelSessionCookie)
       
   174 {
       
   175 	TInt r = iDmaSession.ChannelResume(aChannelSessionCookie);
       
   176 	TEST_ASSERT(r == KErrNone);
       
   177 }
    92 //////////////////////////////////////////////////////////////////////
   178 //////////////////////////////////////////////////////////////////////
    93 // CSingleTransferTest
   179 // CSingleTransferTest
    94 //////////////////////////////////////////////////////////////////////
   180 //////////////////////////////////////////////////////////////////////
    95 void CSingleTransferTest::RunTest()
   181 void CSingleTransferTest::RunTest()
    96 	{
   182 	{
   121 		if(gVerboseOutput)
   207 		if(gVerboseOutput)
   122 			{
   208 			{
   123 			RDebug::Printf("Calling New Request API\n");
   209 			RDebug::Printf("Calling New Request API\n");
   124 			}
   210 			}
   125 		iActual.iRequestResult.iCreate =
   211 		iActual.iRequestResult.iCreate =
   126 			iDmaSession.RequestCreateNew(iChannelSessionCookie, iRequestSessionCookie, iMaxFragmentSize);
   212 			iDmaSession.RequestCreate(iChannelSessionCookie, iRequestSessionCookie, iMaxFragmentSize);
   127 		}
   213 		}
   128 	else
   214 	else
   129 		{
   215 		{
   130 		if(gVerboseOutput)
   216 		if(gVerboseOutput)
   131 			{
   217 			{
   132 			RDebug::Printf("Calling Old Request API\n");
   218 			RDebug::Printf("Calling Old Request API\n");
   133 			}
   219 			}
   134 		iActual.iRequestResult.iCreate =
   220 		iActual.iRequestResult.iCreate =
   135 			iDmaSession.RequestCreate(iChannelSessionCookie, iRequestSessionCookie, iMaxFragmentSize);
   221 			iDmaSession.RequestCreateOld(iChannelSessionCookie, iRequestSessionCookie, iMaxFragmentSize);
   136 		}
   222 		}
   137 	}
   223 	}
   138 
   224 
   139 void CSingleTransferTest::Fragment()
   225 void CSingleTransferTest::Fragment()
   140 	{
   226 	{
   156 			{
   242 			{
   157 			RDebug::Printf("Calling Old Fragment API\n");
   243 			RDebug::Printf("Calling Old Fragment API\n");
   158 			}
   244 			}
   159 		iActual.iRequestResult.iFragmentationResult =
   245 		iActual.iRequestResult.iFragmentationResult =
   160 			iDmaSession.FragmentRequestOld(iRequestSessionCookie, iTransferArgs);
   246 			iDmaSession.FragmentRequestOld(iRequestSessionCookie, iTransferArgs);
   161 
       
   162 		}
   247 		}
   163 
   248 
   164 	const TInt fragmentCount = iDmaSession.RequestFragmentCount(iRequestSessionCookie);
   249 	const TInt fragmentCount = iDmaSession.RequestFragmentCount(iRequestSessionCookie);
   165 
   250 
   166 	// Record the fragment count if a non-zero value was expected,
   251 	// Record the fragment count if a non-zero value was expected,
   209 void CSingleTransferTest::PrintTestType() const
   294 void CSingleTransferTest::PrintTestType() const
   210 	{
   295 	{
   211 	RDebug::RawPrint(_L("Single transfer"));
   296 	RDebug::RawPrint(_L("Single transfer"));
   212 	}
   297 	}
   213 
   298 
       
   299 void CSingleTransferTest::PrintTestInfo() const
       
   300 	{
       
   301 	CDmaTest::PrintTestInfo();
       
   302 
       
   303 	// State which API versions are being used
       
   304 	if(iUseNewFragment)
       
   305 		RDebug::RawPrint(_L(", Fragment v2,"));
       
   306 	else
       
   307 		RDebug::RawPrint(_L(", Fragment v1,"));
       
   308 
       
   309 	if(iUseNewRequest)
       
   310 		RDebug::RawPrint(_L(" DDmaRequest v2"));
       
   311 	else
       
   312 		RDebug::RawPrint(_L(" DDmaRequest v1"));
       
   313 	}
       
   314 
   214 void CSingleTransferTest::PreTransferSetup()
   315 void CSingleTransferTest::PreTransferSetup()
   215 	{
   316 	{
   216 	if(iPreTransfer)
   317 	if(iPreTransfer)
   217 		iPreTransfer->Setup(*this); //initialize test
   318 		iPreTransfer->Setup(*this); //initialize test
   218 	}
   319 	}
   237 		iActual.iCallbackRecord.Print();
   338 		iActual.iCallbackRecord.Print();
   238 		}
   339 		}
   239 	return result;
   340 	return result;
   240 	}
   341 	}
   241 
   342 
   242 
   343 //////////////////////////////////////////////////////////////////////
       
   344 // CDmaTestDecorator
       
   345 //////////////////////////////////////////////////////////////////////
       
   346 
       
   347 CDmaTestDecorator::CDmaTestDecorator(CDmaTest* aDecoratedTest)
       
   348 	: CDmaTest(_L("Decorated Test"), 1, NULL, NULL), iDecoratedTest(aDecoratedTest)
       
   349 	{}
       
   350 
       
   351 CDmaTestDecorator::CDmaTestDecorator(const CDmaTestDecorator& aOther)
       
   352 	: CDmaTest(aOther), iDecoratedTest( static_cast<CDmaTest*>( aOther.iDecoratedTest->Clone() ) )
       
   353 	// Need cast because Clone does not have a covariant return type,
       
   354 	// as not all compillers allow it
       
   355 	{}
       
   356 
       
   357 //////////////////////////////////////////////////////////////////////
       
   358 // CMultiVersionTest
       
   359 //////////////////////////////////////////////////////////////////////
       
   360 
       
   361 CMultiVersionTest::CMultiVersionTest(CSingleTransferTest* aDmaTest)
       
   362 	: CDmaTestDecorator(aDmaTest), iNewVersionTest(NULL)
       
   363 	{
       
   364 	}
       
   365 
       
   366 CMultiVersionTest::CMultiVersionTest(const CMultiVersionTest& aOther)
       
   367 	: CDmaTestDecorator(aOther), iNewVersionTest( aOther.iNewVersionTest ? static_cast<CSingleTransferTest*>(aOther.iNewVersionTest->Clone()) : NULL)
       
   368 	{
       
   369 	}
       
   370 
       
   371 CMultiVersionTest::~CMultiVersionTest()
       
   372 	{
       
   373 	delete iDecoratedTest;
       
   374 	delete iNewVersionTest;
       
   375 	}
       
   376 
       
   377 void CMultiVersionTest::SetupL()
       
   378 	{
       
   379 	// Open a tempory dma session to find out the
       
   380 	// capabilities of the dma channel.
       
   381 	OpenDmaSession();
       
   382 	Configure();
       
   383 	CloseDmaSession();
       
   384 	}
       
   385 
       
   386 void CMultiVersionTest::Announce() const
       
   387 	{
       
   388 	CTest::Announce();
       
   389 
       
   390 	iDecoratedTest->Announce();
       
   391 
       
   392 	if(iNewVersionTest)
       
   393 		iNewVersionTest->Announce();
       
   394 	}
       
   395 
       
   396 void CMultiVersionTest::PrintTestType() const
       
   397 	{
       
   398 	RDebug::RawPrint(_L("Multi version test wrapper"));
       
   399 	}
       
   400 
       
   401 void CMultiVersionTest::PrintTestInfo() const
       
   402 	{
       
   403 		if(iNewVersionTest)
       
   404 			{ 		
       
   405 			RDebug::RawPrint(_L("Running tests using Version 2 PIL"));
       
   406 			}
       
   407 		else
       
   408 			{
       
   409 			RDebug::RawPrint(_L("Running tests using Version 1 PIL"));		
       
   410 			}
       
   411 	}
       
   412 
       
   413 void CMultiVersionTest::RunTest()
       
   414 	{
       
   415 	OpenDmaSession();
       
   416 
       
   417 	// iDecoratedTest is the test, in the old configuration
       
   418 	// iNewVersionTest is the same test, configured
       
   419 	// to use the new APIs
       
   420 	//
       
   421 	// 2 objects are needed since they can each store
       
   422 	// their own results
       
   423 
       
   424 	iDecoratedTest->OpenDmaSession(iDmaSession);
       
   425 	(*iDecoratedTest)();
       
   426 
       
   427 	if(iNewVersionTest)
       
   428 		{
       
   429 		iNewVersionTest->OpenDmaSession(iDmaSession);
       
   430 		(*iNewVersionTest)();
       
   431 		}
       
   432 
       
   433 	CloseDmaSession();
       
   434 	}
       
   435 
       
   436 /**
       
   437 Maybe create another test object to run with new API
       
   438 
       
   439 Pass on the cookie for the channel they must test
       
   440 */
       
   441 void CMultiVersionTest::Configure()
       
   442 	{
       
   443 	static_cast<CSingleTransferTest*>(iDecoratedTest)->UseNewDmaApi(EFalse);
       
   444 	iDecoratedTest->SetChannelCookie(iChannelCookie);
       
   445 
       
   446 	if(Version2PILAvailable())
       
   447 		{
       
   448 		iNewVersionTest = static_cast<CSingleTransferTest*>(iDecoratedTest->Clone());
       
   449 		TEST_ASSERT(iNewVersionTest != NULL);
       
   450 
       
   451 		iNewVersionTest->UseNewDmaApi(ETrue);
       
   452 		iNewVersionTest->SetChannelCookie(iChannelCookie);
       
   453 		}
       
   454 	}
       
   455 
       
   456 /**
       
   457 Discover from DMA channel what PIL versions are available.
       
   458 In practice V1 APIs will always be available, V2 may be.
       
   459 */
       
   460 TBool CMultiVersionTest::Version2PILAvailable()
       
   461 	{
       
   462 	TUint channelSessionCookie;
       
   463 	TInt r = iDmaSession.ChannelOpen(iChannelCookie, channelSessionCookie);
       
   464 	TEST_ASSERT(r == KErrNone);
       
   465 
       
   466 	TDmacTestCaps channelCaps;
       
   467 	r = iDmaSession.ChannelCaps(channelSessionCookie, channelCaps);
       
   468 	TEST_ASSERT(r == KErrNone);
       
   469 
       
   470 	r = iDmaSession.ChannelClose(channelSessionCookie);
       
   471 	TEST_ASSERT(r == KErrNone);
       
   472 
       
   473 	return channelCaps.iPILVersion >= 2;
       
   474 	}
       
   475 
       
   476 TBool CMultiVersionTest::Result()
       
   477 	{
       
   478 	TBool v1Result = iDecoratedTest->Result();
       
   479 	if(gVerboseOutput || !v1Result)
       
   480 		RDebug::Printf("V1 API result: %s", v1Result ? "success" : "failure");
       
   481 
       
   482 	TBool v2Result = iNewVersionTest ? iNewVersionTest->Result() : ETrue;
       
   483 	if(gVerboseOutput || !v1Result)
       
   484 		RDebug::Printf("V2 API result: %s", v2Result ? "success" : "failure");
       
   485 	return v1Result && v2Result;
       
   486 	}
   243 
   487 
   244 //////////////////////////////////////////////////////////////////////
   488 //////////////////////////////////////////////////////////////////////
   245 // CDmaBenchmark
   489 // CDmaBenchmark
   246 //////////////////////////////////////////////////////////////////////
   490 //////////////////////////////////////////////////////////////////////
   247 
       
   248 CDmaBenchmark::CDmaBenchmark(const TDesC& aName, TInt aIterations, const TResultSet& aExpectedResults, const TDmaTransferArgs& aTransferArgs, TUint aMaxFragmentSize)
   491 CDmaBenchmark::CDmaBenchmark(const TDesC& aName, TInt aIterations, const TResultSet& aExpectedResults, const TDmaTransferArgs& aTransferArgs, TUint aMaxFragmentSize)
   249 	:CSingleTransferTest(aName, aIterations, aTransferArgs, aExpectedResults, aMaxFragmentSize, NULL, NULL)
   492 	:CSingleTransferTest(aName, aIterations, aTransferArgs, aExpectedResults, aMaxFragmentSize, NULL, NULL)
   250 	{
   493 	{
   251 	UseNewDmaApi(EFalse);
   494 	UseNewDmaApi(EFalse);
       
   495 	}
       
   496 
       
   497 CDmaBenchmark::CDmaBenchmark(const CDmaBenchmark& aOriginal)
       
   498 	:CSingleTransferTest(aOriginal)
       
   499 	{
       
   500 	CopyL(aOriginal.iResultArray, iResultArray);
   252 	}
   501 	}
   253 
   502 
   254 CDmaBenchmark::~CDmaBenchmark()
   503 CDmaBenchmark::~CDmaBenchmark()
   255 	{
   504 	{
   256 	iResultArray.Close();
   505 	iResultArray.Close();
   286 	if(result)
   535 	if(result)
   287 		{
   536 		{
   288 		RDebug::Printf("  Mean time: %lu us", MeanResult());
   537 		RDebug::Printf("  Mean time: %lu us", MeanResult());
   289 		}
   538 		}
   290 
   539 
   291 	//TODO this will be handled by the ctor later
       
   292 	iResultArray.Close();
       
   293 
       
   294 	return result;
   540 	return result;
   295 	}
   541 	}
   296 
   542 
   297 
       
   298 //////////////////////////////////////////////////////////////////////
   543 //////////////////////////////////////////////////////////////////////
   299 // CDmaBmFragmentation
   544 // CDmaBmFragmentation
   300 //////////////////////////////////////////////////////////////////////
   545 //////////////////////////////////////////////////////////////////////
   301 
       
   302 CDmaBmFragmentation::CDmaBmFragmentation(const TDesC& aName, TInt aIterations, const TDmaTransferArgs& aTransferArgs, TUint aMaxFragmentSize)
   546 CDmaBmFragmentation::CDmaBmFragmentation(const TDesC& aName, TInt aIterations, const TDmaTransferArgs& aTransferArgs, TUint aMaxFragmentSize)
   303 	:CDmaBenchmark(aName, aIterations, ExpectedResults, aTransferArgs, aMaxFragmentSize)
   547 	:CDmaBenchmark(aName, aIterations, ExpectedResults, aTransferArgs, aMaxFragmentSize)
   304 	{}
   548 	{}
   305 
   549 
   306 const TResultSet CDmaBmFragmentation::ExpectedResults(KErrNone,
   550 const TResultSet CDmaBmFragmentation::ExpectedResults(KErrNone,
   329 	OpenChannel();
   573 	OpenChannel();
   330 	CreateDmaRequest();
   574 	CreateDmaRequest();
   331 	Fragment();
   575 	Fragment();
   332 	FreeRequest();
   576 	FreeRequest();
   333 	CloseChannel();
   577 	CloseChannel();
   334 
       
   335 	CloseDmaSession();
   578 	CloseDmaSession();
   336 	}
   579 	}
   337 
   580 
   338 //////////////////////////////////////////////////////////////////////
   581 //////////////////////////////////////////////////////////////////////
       
   582 //	CPauseResumeTest
       
   583 //
       
   584 //	-Time how long a given transfer takes
       
   585 //	-Pause the channel
       
   586 //	-repeat the transfer (queued asynchronously)
       
   587 //	-wait for some time (say, 3 times the time measured)
       
   588 //	-read the value of the TRequestStatus object, to check it is still pending
       
   589 //	-resume the channel
       
   590 //	-Wait on the request
       
   591 //	-Confirm that the request completed
       
   592 //////////////////////////////////////////////////////////////////////
       
   593 CPauseResumeTest::~CPauseResumeTest()
       
   594 	{
       
   595 	}
       
   596 
       
   597 void CPauseResumeTest::RunTest()
       
   598 	{
       
   599 	OpenDmaSession();
       
   600 
       
   601 	//Open a single DMA channel for a transfer
       
   602 	OpenChannel();
       
   603 
       
   604 	RDebug::Printf("Resume unpaused idle channel");
       
   605 	TInt r = iDmaSession.ChannelResume(iChannelSessionCookie);
       
   606 	TEST_ASSERT(KErrCompletion == r);
       
   607 
       
   608 	RDebug::Printf("Pause idle channel");
       
   609 	r = iDmaSession.ChannelPause(iChannelSessionCookie);
       
   610 	TEST_ASSERT(KErrNone == r);
       
   611 
       
   612 	RDebug::Printf("Pause paused idle Channel");
       
   613 	r = iDmaSession.ChannelPause(iChannelSessionCookie);
       
   614 	TEST_ASSERT(KErrCompletion == r);
       
   615 
       
   616 	RDebug::Printf("Resume paused idle channel");
       
   617 	r = iDmaSession.ChannelResume(iChannelSessionCookie);
       
   618 	TEST_ASSERT(KErrNone == r);
       
   619 
       
   620 	//Setup a DMA request and Fragment the request.
       
   621 	CreateDmaRequest();
       
   622 	Fragment();
       
   623 
       
   624 	//Queue the DMA request and time how long a transfer takes
       
   625 	TUint64 queueTime;
       
   626 	DoCalibrationTransfer(queueTime);
       
   627 
       
   628 	RDebug::Printf("Calibration transfer completed in %Lu us",queueTime);
       
   629 	TUint32 waitQueueReqTime = I64LOW(queueTime*3); //3 times the time measured in DoCalibrationTransfer
       
   630 	TEST_ASSERT(I64HIGH(queueTime*3) == 0); // If transfer takes over an hour, something has gone wrong anyway
       
   631 
       
   632 	// Initialise buffers, after calibration transfer
       
   633 	PreTransferSetup();
       
   634 
       
   635 	RDebug::Printf("Resume unpaused channel");
       
   636 	r = iDmaSession.ChannelResume(iChannelSessionCookie);
       
   637 	TEST_ASSERT(KErrCompletion == r);
       
   638 
       
   639 	//Pause DMA Transfer
       
   640 	RDebug::Printf("Pausing DMA Channel");
       
   641 	r = iDmaSession.ChannelPause(iChannelSessionCookie);
       
   642 	TEST_ASSERT(KErrNone == r);
       
   643 
       
   644 	RDebug::Printf("Pause paused Channel");
       
   645 	r = iDmaSession.ChannelPause(iChannelSessionCookie);
       
   646 	TEST_ASSERT(KErrCompletion == r);
       
   647 
       
   648 	//Repeat the transfer (queued asynchronously)
       
   649 	TRequestStatus queueRequestStatus;
       
   650 	iActual.iRequestResult.iQueueResult = QueueAsyncRequest(queueRequestStatus,queueTime);
       
   651 	RDebug::Printf("Queue a DMA Request and wait for %u us ", waitQueueReqTime);
       
   652 
       
   653 	User::After(waitQueueReqTime);
       
   654 	RDebug::Printf("Finished waiting");
       
   655 	TEST_ASSERT(queueRequestStatus.Int() == KRequestPending);
       
   656 
       
   657 	TBool queueEmpty = ETrue;
       
   658 	r = iDmaSession.ChannelIsQueueEmpty(iChannelSessionCookie,queueEmpty);
       
   659 	TEST_ASSERT(r == KErrNone);
       
   660 	TEST_ASSERT(!queueEmpty);
       
   661 
       
   662 	//Resume DMA channel
       
   663 	RDebug::Printf("Resuming paused DMA Channel");
       
   664 	r = iDmaSession.ChannelResume(iChannelSessionCookie);
       
   665 	TEST_ASSERT(KErrNone == r);
       
   666 
       
   667 	//Wait for transfer to complete
       
   668 	User::WaitForRequest(queueRequestStatus);
       
   669 	if (queueRequestStatus.Int() == KErrNone)
       
   670 		{
       
   671 		RDebug::Printf("DMA QueueAsyncRequest completed");
       
   672 		}
       
   673 
       
   674 	FreeRequest();
       
   675 	CloseChannel();
       
   676 
       
   677 	PostTransferCheck();
       
   678 	CloseDmaSession();
       
   679 	}
       
   680 
       
   681 /**
       
   682 Time how long transfer takes, with no pausing
       
   683 */
       
   684 void CPauseResumeTest::DoCalibrationTransfer(TUint64 &atime)
       
   685 	{
       
   686 	//Queue the DMA request.
       
   687 	TCallbackRecord pCallbackRecord;
       
   688 	TInt r = iDmaSession.QueueRequest(iRequestSessionCookie,&pCallbackRecord,&atime);
       
   689 	TEST_ASSERT(r == KErrNone);
       
   690 	}
       
   691 
       
   692 TInt CPauseResumeTest::QueueAsyncRequest(TRequestStatus &aRequestState, TUint64 &atime)
       
   693 	{
       
   694 	return iDmaSession.QueueRequest(iRequestSessionCookie,aRequestState, &iActual.iCallbackRecord, &atime);
       
   695 	}
       
   696 
       
   697 void CPauseResumeTest::PrintTestType() const
       
   698 	{
       
   699 	RDebug::RawPrint(_L("Pause and Resume API Test"));
       
   700 	}
       
   701 
       
   702 //////////////////////////////////////////////////////////////////////
       
   703 // COpenCloseTest
       
   704 //////////////////////////////////////////////////////////////////////
       
   705 COpenCloseTest::~COpenCloseTest()
       
   706 	{
       
   707 	}
       
   708 
       
   709 TBool COpenCloseTest::DoRunClose()
       
   710 	{
       
   711 	// For storing cookie during neagtive test i,e open channel twice
       
   712 	TUint testChannelSessionCookie = 0; 
       
   713 
       
   714 	// Open a single DMA channel
       
   715 	TInt r = iDmaSession.ChannelOpen(iChannelCookie, iChannelSessionCookie);
       
   716 	if (r == KErrNone)//Check that DMA channel opened with no errors
       
   717 		{
       
   718 		RDebug::Printf("DMA channel opened");					
       
   719 		}
       
   720 	else
       
   721 		{
       
   722 		RDebug::Printf("Open DMA channel failed");			
       
   723 		return EFalse;
       
   724 		}
       
   725 
       
   726 	// Open DMA channel again and check that opening DMA channel again fails		
       
   727 	r = iDmaSession.ChannelOpen(iChannelCookie, testChannelSessionCookie);
       
   728 	if (r == KErrInUse)
       
   729 		{
       
   730 		RDebug::Printf("Opening DMA channel again fails as expected");	
       
   731 		}
       
   732 	else
       
   733 		{
       
   734 		RDebug::Printf("Open DMA channel again failed");
       
   735 		return EFalse;
       
   736 		}
       
   737 
       
   738 	// Close the DMA channel and check that DMA channel closes with no errors
       
   739 	r =iDmaSession.ChannelClose(iChannelSessionCookie);	 
       
   740 	if (r == KErrNone) 
       
   741 		{
       
   742 		RDebug::Printf("DMA channel closes with no errors");				
       
   743 		}
       
   744 	else
       
   745 		{
       
   746 		RDebug::Printf("Close the DMA channel failed");
       
   747 		return EFalse;
       
   748 		}
       
   749 	
       
   750 	// Verify that the DMA channel was actually closed by opening DMA channel
       
   751 	r = iDmaSession.ChannelOpen(iChannelCookie, iChannelSessionCookie);
       
   752 	if (r == KErrNone)
       
   753 		{
       
   754 		RDebug::Printf("DMA channel opened after a previous close operation");
       
   755 		return ETrue;
       
   756 		}
       
   757 	else
       
   758 		{
       
   759 		RDebug::Printf("Open DMA channel to verify that the DMA channel closed failed");
       
   760 		return EFalse;
       
   761 		}	
       
   762 	}
       
   763 
       
   764 TBool COpenCloseTest::DoRunOpen()
       
   765 	{
       
   766 	// Open a single DMA channel
       
   767 	TInt r = iDmaSession.ChannelOpen(iChannelCookie, iChannelSessionCookie);
       
   768 	if (r == KErrNone)//Check that DMA channel opened with no errors
       
   769 		{			
       
   770 		RDebug::Printf("DoRunOpen:DMA channel opened");			
       
   771 		}
       
   772 	else
       
   773 		{
       
   774 		RDebug::Printf("DoRunOpenDMA channel failed to open");				
       
   775 		return EFalse;
       
   776 		}	
       
   777 
       
   778 	// Verify that channel is really open by closing DMA channel
       
   779 	// and checking that DMA channel closes with no errors
       
   780 	r = iDmaSession.ChannelClose(iChannelSessionCookie);
       
   781 	if (r == KErrNone)
       
   782 		{
       
   783 		RDebug::Printf("DoRunOpen:DMA channel closes with no errors");			
       
   784 		return ETrue;
       
   785 		}
       
   786 	else
       
   787 		{
       
   788 		RDebug::Printf("DoRunOpen:DMA channel failed to close");		
       
   789 		return EFalse;
       
   790 		}
       
   791 	}
       
   792 
       
   793 TBool COpenCloseTest::DoRunOpenExposed()
       
   794 	{
       
   795 	SCreateInfoTest TOpenInfo;
       
   796 	TOpenInfo.iCookie =iChannelCookie;
       
   797 	TOpenInfo.iDfcPriority = 3;
       
   798 	
       
   799 	const TInt desCount[3] = {0,1,128}; 
       
   800 	const TBool dynChannel[3] =	{EFalse,EFalse,ETrue};  
       
   801 	const TInt expectedResults[3] = {KErrArgument,KErrNone,KErrInUse};  
       
   802 	TInt actualResults[3] = {1, 1, 1};
       
   803 
       
   804 	for (TInt i =0; i<3; i++)
       
   805 		{	
       
   806 		TOpenInfo.iDesCount = desCount[i];
       
   807 		TOpenInfo.iDynChannel = dynChannel[i];		
       
   808 
       
   809 		// Open a single DMA channel
       
   810 		RDebug::Printf("DoRunOpenExposed:Trying to open DMA channel using iDesCount(%d) and iDynChannel(%d)  ", TOpenInfo.iDesCount,TOpenInfo.iDynChannel);
       
   811 		actualResults[i] = iDmaSession.ChannelOpen(iChannelSessionCookie, TOpenInfo);
       
   812 		if (actualResults[i] == KErrNone)// Verify that channel is really open by closing DMA channel	
       
   813 			{
       
   814 			TInt err = iDmaSession.ChannelClose(iChannelSessionCookie);
       
   815 			TEST_ASSERT(err == KErrNone)//Check that DMA channel closed with no errors
       
   816 			}
       
   817 		}
       
   818 
       
   819 	// This case should fail if idesCount  =  0.
       
   820 	// PIL has been changed to return KErrArgument instead of using an assertion check
       
   821 	if (expectedResults[0] == actualResults[0])
       
   822 		{
       
   823 		RDebug::Printf("DoRunOpenExposed:DMA channel failed to open as expected as for iDesCount = 0 ");			
       
   824 		}
       
   825 	else
       
   826 		{
       
   827 		RDebug::Printf("DoRunOpenExposed:Error code returned (%d), expected KErrArgument as iDesCount= 0) ", actualResults[0]);	
       
   828 		return EFalse;
       
   829 		}
       
   830 
       
   831 	// For this case( idesCount  =  1), DMA channel should open with no issues	
       
   832 	if (expectedResults[1] == actualResults[1])
       
   833 		{		
       
   834 		RDebug::Printf("DoRunOpenExposed:DMA channel closes with no errors as expected for iDesCount = 1 ");
       
   835 		}
       
   836 	else
       
   837 		{
       
   838 		RDebug::Printf("DoRunOpenExposed:Failed to open DMA channel with error code (%d)", actualResults[1]);	
       
   839 		return EFalse;
       
   840 		}
       
   841 
       
   842 	// For this case(dynaChannel=ETrue), DMA channel now returns KErrInUse. dynaChannel is not supported in the PSL.
       
   843 	// PSL now returns a NULL pointer when dynaChannel is requested. The PIL interprets a NULL 
       
   844 	// pointer being returned from opening a DMA channel as a channel in use. Hence, KErrInUse is returned.
       
   845 	if (expectedResults[2] == actualResults[2])
       
   846 		{
       
   847 		RDebug::Printf("DoRunOpenExposed:DMA channel failed to open as expected as dynamic channel is not supported");		
       
   848 		}
       
   849 	else
       
   850 		{
       
   851 		RDebug::Printf("DoRunOpenExposed:Error code returned (%d), expected KErrInUse as as dynamic channel is not supported", actualResults[2]);			
       
   852 		return EFalse;
       
   853 		}
       
   854 
       
   855 	return ETrue;
       
   856 	}
       
   857 
       
   858 void COpenCloseTest::RunTest()
       
   859 	{
       
   860 	OpenDmaSession(); 
       
   861 
       
   862 	if (iRunOpen) 
       
   863 	{	// Run Open() API test
       
   864 		iOpenCloseResult = DoRunOpenExposed();
       
   865 		if(iOpenCloseResult)
       
   866 			iOpenCloseResult = DoRunOpen();
       
   867 	}
       
   868 	else
       
   869 	{
       
   870 		// Run Close() API test	
       
   871 		iOpenCloseResult = DoRunClose();
       
   872 	}
       
   873 
       
   874 	CloseDmaSession();
       
   875 	}
       
   876 
       
   877 void COpenCloseTest::PrintTestType() const
       
   878 	{
       
   879 	RDebug::RawPrint(_L("Close/Open API Test"));
       
   880 
       
   881 	}
       
   882 
       
   883 TBool COpenCloseTest::Result()
       
   884 	{
       
   885 	if(gVerboseOutput)
       
   886 		{
       
   887 		RDebug::Printf("Results for Close/Open API Test");
       
   888 		}
       
   889 
       
   890 	if(!iOpenCloseResult)
       
   891 		{
       
   892 		RDebug::Printf("Open/Close test sequence failed"); 
       
   893 		}
       
   894 			
       
   895 	return iOpenCloseResult;
       
   896 	}
       
   897 //////////////////////////////////////////////////////////////////////
   339 // CDmaBmTransfer
   898 // CDmaBmTransfer
   340 //////////////////////////////////////////////////////////////////////
   899 //////////////////////////////////////////////////////////////////////
   341 
       
   342 CDmaBmTransfer::CDmaBmTransfer(const TDesC& aName, TInt aIterations, const TDmaTransferArgs& aTransferArgs, TUint aMaxFragmentSize)
   900 CDmaBmTransfer::CDmaBmTransfer(const TDesC& aName, TInt aIterations, const TDmaTransferArgs& aTransferArgs, TUint aMaxFragmentSize)
   343 	:CDmaBenchmark(aName, aIterations,
   901 	:CDmaBenchmark(aName, aIterations,
   344 		TResultSet(KErrNone, TRequestResults(),	KErrUnknown, TCallbackRecord(TCallbackRecord::EThread,1)),
   902 		TResultSet(KErrNone, TRequestResults(),	KErrUnknown, TCallbackRecord(TCallbackRecord::EThread,1)),
   345 		aTransferArgs, aMaxFragmentSize)
   903 		aTransferArgs, aMaxFragmentSize)
   346 	{}
   904 	{}
   347 
       
   348 
   905 
   349 void CDmaBmTransfer::PrintTestType() const
   906 void CDmaBmTransfer::PrintTestType() const
   350 	{
   907 	{
   351 	RDebug::RawPrint(_L("Transfer Benchmark"));
   908 	RDebug::RawPrint(_L("Transfer Benchmark"));
   352 	}
   909 	}
   373 		iActual.iRequestResult.iQueueResult = iDmaSession.QueueRequest(iRequestSessionCookie, &iActual.iCallbackRecord, &time);
   930 		iActual.iRequestResult.iQueueResult = iDmaSession.QueueRequest(iRequestSessionCookie, &iActual.iCallbackRecord, &time);
   374 		iResultArray.Append(time);
   931 		iResultArray.Append(time);
   375 		}
   932 		}
   376 	}
   933 	}
   377 
   934 
       
   935 /*
       
   936 1.	Open a DMA channel for a transfer.
       
   937 2.	Queue multiple request on the DMA channel.
       
   938 3.	Call CancelAll () on the DMA channel.
       
   939 4.	Verify that all transfers have been cancelled.
       
   940 5.	Open a DMA channel for a transfer. This channel should support pause and resume.
       
   941 6.	Call Pause () on the channel.
       
   942 7.	Queue multiple request on the DMA channel.
       
   943 8.	Call CancelAll () on the channel.
       
   944 9.	Verify that all transfers have been cancelled.
       
   945 
       
   946    Note: This check does not add results to TResultSet like some
       
   947    other tests as its operation is different. The test checks for 
       
   948    the the cancelllation of all transfers queued on a channel by
       
   949    calling iDmaSession.ChannelIsQueueEmpty(); 
       
   950 */
       
   951 
       
   952 //////////////////////////////////////////////////////////////////////
       
   953 // CCancelAllTest
       
   954 //////////////////////////////////////////////////////////////////////
       
   955 
       
   956 
       
   957 CCancelAllTest::CCancelAllTest(const TDesC& aName, TInt aIterations,
       
   958 		const TDmaTransferArgs* aTransferArgs, const TResultSet* aResultSets,
       
   959 		TInt aCount)
       
   960 	:CMultiTransferTest(aName, aIterations, aTransferArgs, aResultSets, aCount)
       
   961 	{}
       
   962 
       
   963 void CCancelAllTest::RunTest()
       
   964 	{
       
   965 	OpenDmaSession();
       
   966 	PreTransferSetup();
       
   967 
       
   968 	// Open a DMA channel for a transfer.This channel should support pause and resume.
       
   969 	OpenChannel();
       
   970 
       
   971 	//Call Pause () on the channel
       
   972 	RDebug::Printf("Pausing DMA Channel");
       
   973 	ChannelPause(iChannelSessionCookie);
       
   974 	
       
   975 	// Queue multiple request on the DMA channel.
       
   976 	CreateDmaRequests();
       
   977 	Fragment();
       
   978 
       
   979 	QueueRequestsAsync();
       
   980 
       
   981 	// Call CancelAll () on the DMA channel and Verify that all transfers have been cancelled.
       
   982 	TInt r = CancelAllRequests();
       
   983 	TEST_ASSERT(r == KErrNone);
       
   984 
       
   985 	//Call Resume () on the channel.
       
   986 	RDebug::Printf("Cancel should clear Pause state: resuming channel should fail");
       
   987 	ChannelResume(iChannelSessionCookie);		
       
   988 	//TEST_ASSERT(r == KErrCompletion);
       
   989 
       
   990 	r = DoPostTransferCheck();
       
   991 	TEST_ASSERT(r == KErrNone);
       
   992 	//Destroy request
       
   993     for(TInt i=0; i<2; i++)
       
   994 		{
       
   995 		r = iDmaSession.RequestDestroy(iRequestCookies[i]);
       
   996 		TEST_ASSERT(r == KErrNone);
       
   997 		}
       
   998 
       
   999 	//Close DMA channel
       
  1000 	CloseChannel();
       
  1001 
       
  1002 	CloseDmaSession();
       
  1003 	}
       
  1004 
       
  1005 TInt CCancelAllTest::CancelAllRequests()
       
  1006 	{
       
  1007 	if(gVerboseOutput)
       
  1008 		{
       
  1009 		RDebug::Printf("CCancelAllTest::CancelAllRequests()");
       
  1010 		}
       
  1011 	TInt r = KErrGeneral;
       
  1012 	r  = iDmaSession.ChannelCancelAll(iChannelSessionCookie);
       
  1013 	if (r != KErrNone)
       
  1014 		return r;
       
  1015 
       
  1016 	TBool queueEmpty;
       
  1017 	r = iDmaSession.ChannelIsQueueEmpty(iChannelSessionCookie,queueEmpty);
       
  1018 	if (r != KErrNone)
       
  1019 		return r;
       
  1020 
       
  1021 	if(!queueEmpty)
       
  1022 		return KErrGeneral;
       
  1023 
       
  1024 	if(gVerboseOutput)
       
  1025 		{
       
  1026 		RDebug::Printf("Both current and pending requests cancelled");
       
  1027 		}
       
  1028 	return KErrNone;
       
  1029 	}
       
  1030 
       
  1031 void CCancelAllTest::PrintTestType() const
       
  1032 	{
       
  1033 	RDebug::RawPrint(_L("CCancelAllTest"));
       
  1034 	}
       
  1035 
       
  1036 void CCancelAllTest::QueueRequestsAsync()
       
  1037 	{
       
  1038 	if(iPauseWhileQueuing)
       
  1039 		{
       
  1040 		TInt r = iDmaSession.ChannelPause(iChannelSessionCookie);
       
  1041 		TEST_ASSERT(r == KErrNone);
       
  1042 		}
       
  1043 
       
  1044 	// Queue all the DMA requests asynchronously
       
  1045 	TEST_ASSERT(iActualResults.Count() == iTransferArgsCount);
       
  1046 	for(TInt i=0; i<iTransferArgsCount; i++)
       
  1047 		{
       
  1048 		TResultSet& resultSet = iActualResults[i];
       
  1049 		if(resultSet.iRequestResult.iFragmentationResult != KErrNone)
       
  1050 			continue;
       
  1051 
       
  1052 		TInt r = iDmaSession.QueueRequest(iRequestCookies[i], iDummyRequestStatus, &resultSet.iCallbackRecord, NULL);
       
  1053 		resultSet.iRequestResult.iQueueResult = r;
       
  1054 		}
       
  1055 
       
  1056 	if(iPauseWhileQueuing)
       
  1057 		{
       
  1058 		TInt r = iDmaSession.ChannelResume(iChannelSessionCookie);
       
  1059 		TEST_ASSERT(r == KErrNone);
       
  1060 		}
       
  1061 	}
       
  1062 
       
  1063 //////////////////////////////////////////////////////////////////////
       
  1064 // CIsQueueEmptyTest
       
  1065 //////////////////////////////////////////////////////////////////////
       
  1066 CIsQueueEmptyTest::CIsQueueEmptyTest(const TDesC& aName, TInt aIterations, const TDmaTransferArgs* aTransferArgs,
       
  1067 		const TResultSet* aResultSets, TInt aCount)
       
  1068 	:CMultiTransferTest(aName, aIterations, aTransferArgs, aResultSets, aCount)
       
  1069 	{}
       
  1070 
       
  1071 CIsQueueEmptyTest::CIsQueueEmptyTest(const CIsQueueEmptyTest& aOther)
       
  1072 	:CMultiTransferTest(aOther)
       
  1073 	{}
       
  1074 
       
  1075 CIsQueueEmptyTest::~CIsQueueEmptyTest()
       
  1076 	{
       
  1077 	}
       
  1078 
       
  1079 void CIsQueueEmptyTest::RunTest()
       
  1080 	{
       
  1081 	OpenDmaSession();
       
  1082 	PreTransferSetup();
       
  1083 	
       
  1084 	OpenChannel();
       
  1085 
       
  1086 	CreateDmaRequests();
       
  1087 	Fragment();
       
  1088 	QueueRequests();
       
  1089 
       
  1090 	TInt r = DoPostTransferCheck();
       
  1091 	TEST_ASSERT(r == KErrNone);
       
  1092 
       
  1093 	CloseDmaSession();
       
  1094 	}
       
  1095 
       
  1096 void CIsQueueEmptyTest::DoIsQueueEmpty()
       
  1097 	{
       
  1098 	TBool queueEmpty;
       
  1099 	TInt r = iDmaSession.ChannelIsQueueEmpty(iChannelSessionCookie,queueEmpty);
       
  1100 	TEST_ASSERT(r == KErrNone);
       
  1101 
       
  1102 	if(queueEmpty)
       
  1103 		{
       
  1104 		RDebug::Printf("Verified that calling IsQueueEmpty() returns ETrue before calling Queue()");
       
  1105 		}
       
  1106 	else
       
  1107 		{
       
  1108 		RDebug::Printf("IsQueueEmpty() fails to return ETrue before calling Queue()");
       
  1109 		TEST_ASSERT(queueEmpty);	
       
  1110 		}
       
  1111 	}
       
  1112 
       
  1113 void CIsQueueEmptyTest::DoQueueNotEmpty()
       
  1114 	{
       
  1115 	TBool queueEmpty;
       
  1116 	TInt r = iDmaSession.ChannelIsQueueEmpty(iChannelSessionCookie,queueEmpty);
       
  1117 	TEST_ASSERT(r == KErrNone);
       
  1118 
       
  1119 	if (!queueEmpty)
       
  1120 		{
       
  1121 		RDebug::Printf("Verified that calling IsQueueEmpty() returns EFalse after calling Queue()");
       
  1122 		}
       
  1123 	else
       
  1124 		{
       
  1125 		RDebug::Printf("IsQueueEmpty() fails to return EFalse after calling Queue()");
       
  1126 		TEST_ASSERT(!queueEmpty);
       
  1127 		}
       
  1128 	}
       
  1129 
       
  1130 void CIsQueueEmptyTest::PrintTestType() const
       
  1131 	{
       
  1132 	RDebug::RawPrint(_L("IsQueue Empty Test using Multi Transfer"));
       
  1133 	}
       
  1134 
       
  1135 void CIsQueueEmptyTest::QueueRequests()
       
  1136 	{
       
  1137 	// Queue all the DMA requests asynchronously
       
  1138 	TInt i;
       
  1139 	RArray<TRequestStatus> requestStates;
       
  1140 	
       
  1141 	ChannelPause(iChannelSessionCookie);
       
  1142 	DoIsQueueEmpty();
       
  1143 
       
  1144 	TEST_ASSERT(iActualResults.Count() == iTransferArgsCount);
       
  1145 	for(i=0; i<iTransferArgsCount; i++)
       
  1146 		{
       
  1147 		TResultSet& resultSet = iActualResults[i];
       
  1148 		if(resultSet.iRequestResult.iFragmentationResult != KErrNone)
       
  1149 			continue;
       
  1150 
       
  1151 		TInt r = requestStates.Append(TRequestStatus());
       
  1152 		TEST_ASSERT(r == KErrNone);
       
  1153 
       
  1154 		r = iDmaSession.QueueRequest(iRequestCookies[i], requestStates[i], &resultSet.iCallbackRecord, NULL);
       
  1155 		resultSet.iRequestResult.iQueueResult = r;
       
  1156 
       
  1157 		DoQueueNotEmpty();
       
  1158 		}
       
  1159 	
       
  1160 	ChannelResume(iChannelSessionCookie);
       
  1161 
       
  1162 	// wait for all transfers to complete
       
  1163 	const TInt count = requestStates.Count();
       
  1164 
       
  1165 	for(i=0; i<count; i++)
       
  1166 		{
       
  1167 		User::WaitForRequest(requestStates[i]);
       
  1168 		}
       
  1169 
       
  1170 	requestStates.Close();
       
  1171 	}
   378 
  1172 
   379 //////////////////////////////////////////////////////////////////////
  1173 //////////////////////////////////////////////////////////////////////
   380 // CMultiTransferTest
  1174 // CMultiTransferTest
   381 //////////////////////////////////////////////////////////////////////
  1175 //////////////////////////////////////////////////////////////////////
   382 
       
   383 //TODO
       
   384 // Add pre and post transfer for CMultiTransferTest
       
   385 CMultiTransferTest::CMultiTransferTest(const TDesC& aName, TInt aIterations, const TDmaTransferArgs* aTransferArgs,
  1176 CMultiTransferTest::CMultiTransferTest(const TDesC& aName, TInt aIterations, const TDmaTransferArgs* aTransferArgs,
   386 		const TResultSet* aResultSets, TInt aCount)
  1177 		const TResultSet* aResultSets, TInt aCount)
   387 	: CDmaTest(aName, aIterations, NULL, NULL), iTransferArgs(aTransferArgs), iTransferArgsCount(aCount), iNewDmaApi(ETrue),
  1178 	: CDmaTest(aName, aIterations, NULL, NULL), iTransferArgs(aTransferArgs), iTransferArgsCount(aCount), iNewDmaApi(ETrue),
   388 	iChannelSessionCookie(0), iExpectedArray(aResultSets), iPauseWhileQueuing(EFalse)
  1179 	iChannelSessionCookie(0), iExpectedArray(aResultSets), iPauseWhileQueuing(EFalse)
   389 	{}
  1180 	{}
   390 
  1181 
   391 CMultiTransferTest::CMultiTransferTest(const CMultiTransferTest& aOther)
  1182 CMultiTransferTest::CMultiTransferTest(const CMultiTransferTest& aOther)
   392 	: CDmaTest(aOther), iTransferArgs(aOther.iTransferArgs), iTransferArgsCount(aOther.iTransferArgsCount),
  1183 	: CDmaTest(aOther), iTransferArgs(aOther.iTransferArgs), iTransferArgsCount(aOther.iTransferArgsCount),
   393 	iNewDmaApi(aOther.iNewDmaApi),
  1184 	iNewDmaApi(aOther.iNewDmaApi),
   394 	iExpectedArray(aOther.iExpectedArray), iPauseWhileQueuing(aOther.iPauseWhileQueuing)
  1185 	iExpectedArray(aOther.iExpectedArray), iPauseWhileQueuing(aOther.iPauseWhileQueuing)
   395 	//const cast is required because their isn't a ctor taking const
  1186 	{
   396 	//array values
  1187 	CopyL(aOther.iRequestCookies, iRequestCookies);
   397 	//TODO iRequestCookies(const_cast<TUint*>(&aOther.iRequestCookies[0]), aOther.iRequestCookies.Count())
       
   398 	{
       
   399 	}
  1188 	}
   400 
  1189 
   401 CMultiTransferTest::~CMultiTransferTest()
  1190 CMultiTransferTest::~CMultiTransferTest()
   402 	{
  1191 	{
   403 	iRequestCookies.Close();
  1192 	iRequestCookies.Close();
   495 	TInt r = iDmaSession.ChannelOpen(iChannelCookie, iChannelSessionCookie);
  1284 	TInt r = iDmaSession.ChannelOpen(iChannelCookie, iChannelSessionCookie);
   496 
  1285 
   497 	TEST_ASSERT(iActualResults.Count() == iTransferArgsCount);
  1286 	TEST_ASSERT(iActualResults.Count() == iTransferArgsCount);
   498 	for(TInt i=0; i<iTransferArgsCount; i++)
  1287 	for(TInt i=0; i<iTransferArgsCount; i++)
   499 		{
  1288 		{
   500 		// Since all transfers will use the same channel,
  1289 		// In a multi transfer test a series of requests are created and queued.
   501 		// they all get the same result
  1290 		// They all use the same channel, is opened here at the beginning of the test
   502 		// Arguably, iChannelOpenResult doesn't
  1291 		//
   503 		// belong TResultSet
  1292 		// Each transfer has a TResultSet which holds a result for the channel opening,
       
  1293 		// which we store here. Although in this case it is redundant,
       
  1294 		// in future it might be that different transfers open
       
  1295 		// different channels.
   504 		iActualResults[i].iChannelOpenResult = r;
  1296 		iActualResults[i].iChannelOpenResult = r;
   505 		}
  1297 		}
   506 	}
  1298 	}
   507 
  1299 
   508 TInt CMultiTransferTest::CloseChannel()
  1300 TInt CMultiTransferTest::CloseChannel()
   526 		TUint cookie = 0;
  1318 		TUint cookie = 0;
   527 		TInt r = KErrGeneral;
  1319 		TInt r = KErrGeneral;
   528 
  1320 
   529 		if(iNewDmaApi)
  1321 		if(iNewDmaApi)
   530 			{
  1322 			{
   531 			r = iDmaSession.RequestCreateNew(iChannelSessionCookie, cookie);
  1323 			r = iDmaSession.RequestCreate(iChannelSessionCookie, cookie);
   532 			}
  1324 			}
   533 		else
  1325 		else
   534 			{
  1326 			{
   535 			r = iDmaSession.RequestCreate(iChannelSessionCookie, cookie);
  1327 			r = iDmaSession.RequestCreateOld(iChannelSessionCookie, cookie);
   536 			}
  1328 			}
   537 		iActualResults[i].iRequestResult.iCreate = r;
  1329 		iActualResults[i].iRequestResult.iCreate = r;
   538 
  1330 
   539 		if(r == KErrNone)
  1331 		if(r == KErrNone)
   540 			{
  1332 			{
   609 		}
  1401 		}
   610 
  1402 
   611 	requestStates.Close();
  1403 	requestStates.Close();
   612 	}
  1404 	}
   613 
  1405 
   614 //TODO support test setup for CMultiTransferTest
       
   615 void CMultiTransferTest::PreTransferSetup()
  1406 void CMultiTransferTest::PreTransferSetup()
   616 	{
  1407 	{
       
  1408 	// TODO this is the wrong place to do this!
   617 	for(TInt i=0; i<iTransferArgsCount; i++)
  1409 	for(TInt i=0; i<iTransferArgsCount; i++)
   618 		{
  1410 		{
   619 		//pre-fill actual results with error values
  1411 		//pre-fill actual results with error values
   620 		TInt r = iActualResults.Append(TResultSet(EFalse));
  1412 		TInt r = iActualResults.Append(TResultSet(EFalse));
   621 		TEST_ASSERT(r == KErrNone);
  1413 		TEST_ASSERT(r == KErrNone);
   632 		return KErrNone;
  1424 		return KErrNone;
   633 	}
  1425 	}
   634 //////////////////////////////////////////////////////////////////////
  1426 //////////////////////////////////////////////////////////////////////
   635 // CIsrRequeTest
  1427 // CIsrRequeTest
   636 //////////////////////////////////////////////////////////////////////
  1428 //////////////////////////////////////////////////////////////////////
   637 
       
   638 
       
   639 CIsrRequeTest::CIsrRequeTest(const TDesC& aName, TInt aIterations, const TDmaTransferArgs& aArgs,
  1429 CIsrRequeTest::CIsrRequeTest(const TDesC& aName, TInt aIterations, const TDmaTransferArgs& aArgs,
   640 			TIsrRequeArgs* aRequeueArgs, TInt aCount,
  1430 			TIsrRequeArgs* aRequeueArgs, TInt aCount,
   641 			const TResultSet& aExpected,const MPreTransfer* aPreTfer,const MPostTransferCheck* aPostTferChk, TUint aMaxFragmentSize)
  1431 			const TResultSet& aExpected,const MPreTransfer* aPreTfer,const MPostTransferCheck* aPostTferChk, TUint aMaxFragmentSize)
   642 	:CSingleTransferTest(aName, aIterations, aArgs, aExpected, aMaxFragmentSize, aPostTferChk, aPreTfer), iRequeArgSet(aRequeueArgs, aCount)
  1432 	:CSingleTransferTest(aName, aIterations, aArgs, aExpected, aMaxFragmentSize, aPostTferChk, aPreTfer), iRequeArgSet(aRequeueArgs, aCount)
   643 	{}
  1433 	{}
   653 void CIsrRequeTest::PrintTestType() const
  1443 void CIsrRequeTest::PrintTestType() const
   654 	{
  1444 	{
   655 	RDebug::RawPrint(_L("ISR Requeue"));
  1445 	RDebug::RawPrint(_L("ISR Requeue"));
   656 	}
  1446 	}
   657 
  1447 
   658 /*
       
   659 //TODO will need to support buffer checking of the trasnfers
       
   660 TBool CIsrRequeTest::Result()
       
   661 	{
       
   662 	return CSingleTransferTest::Result();
       
   663 	}
       
   664 */
       
   665 
       
   666 void CIsrRequeTest::PreTransferSetup()
  1448 void CIsrRequeTest::PreTransferSetup()
   667 	{
  1449 	{
   668 	if(iPreTransfer)
  1450 	if(iPreTransfer)
   669 		iPreTransfer->Setup(*this); //initialize test
  1451 		iPreTransfer->Setup(*this); //initialize test
   670 	}
  1452 	}
   675 	}
  1457 	}
   676 
  1458 
   677 //////////////////////////////////////////////////////////////////////
  1459 //////////////////////////////////////////////////////////////////////
   678 // TResultSet
  1460 // TResultSet
   679 //////////////////////////////////////////////////////////////////////
  1461 //////////////////////////////////////////////////////////////////////
   680 
       
   681 void TResultSet::Print() const
  1462 void TResultSet::Print() const
   682 	{
  1463 	{
   683 	PRINT(iChannelOpenResult);
  1464 	PRINT(iChannelOpenResult);
   684 	PRINT(iRequestResult.iCreate);
  1465 	PRINT(iRequestResult.iCreate);
   685 	PRINT(iRequestResult.iFragmentCount);
  1466 	PRINT(iRequestResult.iFragmentCount);
   694 	}
  1475 	}
   695 
  1476 
   696 //////////////////////////////////////////////////////////////////////
  1477 //////////////////////////////////////////////////////////////////////
   697 // MPostTransferCheck classes
  1478 // MPostTransferCheck classes
   698 //////////////////////////////////////////////////////////////////////
  1479 //////////////////////////////////////////////////////////////////////
   699 
       
   700 TInt TCompareSrcDst::Check(const CSingleTransferTest& aTest) const
  1480 TInt TCompareSrcDst::Check(const CSingleTransferTest& aTest) const
   701 	{
  1481 	{
   702 	if(gVerboseOutput)
  1482 	if(gVerboseOutput)
   703 		{
  1483 		{
   704 		RDebug::Printf("Comparing CSingleTransferTest buffers");
  1484 		RDebug::Printf("Comparing CSingleTransferTest buffers");
   705 		}
  1485 		}
   706 	return Check(aTest.TransferArgs(), aTest.Chunk().Base());
  1486 	return Check(aTest.TransferArgs(), aTest.Chunk().Base());
   707 	}
  1487 	}
   708 
  1488 
   709 //TODO
  1489 // Note: this check will not deal correctly with transfers were subsequent
   710 //this check will not deal correctly transfers were subsequent
  1490 // requeues overlap previous sources or destinations
   711 //requeues overlap
  1491 // or where the source of transfer depends on a previous transfer.
       
  1492 // This is because it simply compares the source and destination
       
  1493 // pairwise for each transfer
       
  1494 //
       
  1495 // If TPreTransferIncrBytes is used for the pre-test then the transfers
       
  1496 // will be checked however.
   712 TInt TCompareSrcDst::Check(const CIsrRequeTest& aTest) const
  1497 TInt TCompareSrcDst::Check(const CIsrRequeTest& aTest) const
   713 	{
  1498 	{
   714 	if(gVerboseOutput)
  1499 	if(gVerboseOutput)
   715 		{
  1500 		{
   716 		RDebug::Printf("Comparing CIsrRequeTest buffers");
  1501 		RDebug::Printf("Comparing CIsrRequeTest buffers");
   727 	const TIsrRequeArgsSet& requeueArgs = aTest.GetRequeueArgs();
  1512 	const TIsrRequeArgsSet& requeueArgs = aTest.GetRequeueArgs();
   728 	return Check(requeueArgs, chunkBase, transferArgs);
  1513 	return Check(requeueArgs, chunkBase, transferArgs);
   729 	}
  1514 	}
   730 
  1515 
   731 TInt TCompareSrcDst::Check(const TDmaTransferArgs& aTransferArgs, TUint8* aChunkBase) const
  1516 TInt TCompareSrcDst::Check(const TDmaTransferArgs& aTransferArgs, TUint8* aChunkBase) const
   732 	{
  1517 	{	
   733 	//TODO could make use of Fixup() method
       
   734 	const TUint32 srcOffset = aTransferArgs.iSrcConfig.iAddr;
  1518 	const TUint32 srcOffset = aTransferArgs.iSrcConfig.iAddr;
   735 	const TUint32 dstOffset = aTransferArgs.iDstConfig.iAddr;
  1519 	const TUint32 dstOffset = aTransferArgs.iDstConfig.iAddr;
   736 	const TInt size = aTransferArgs.iTransferCount;
  1520 	const TInt size = aTransferArgs.iTransferCount;
   737 
  1521 
   738 	const TUint8* src = srcOffset + aChunkBase;
  1522 	const TUint8* src = srcOffset + aChunkBase;
   778 		}
  1562 		}
   779 
  1563 
   780 	return memcompare(src, size, dst, size);
  1564 	return memcompare(src, size, dst, size);
   781 	}
  1565 	}
   782 
  1566 
       
  1567 // Note: this check will not deal correctly with transfers were subsequent
       
  1568 // requeues overlap previous sources or destinations
       
  1569 // or where the source of trasnfer depends on a previous trasnfer.
       
  1570 // This is because it simply compares the source and destination
       
  1571 // pairwise for each transfer
       
  1572 //
       
  1573 // If TCompareSrcDst is used for the pre-test then the transfers
       
  1574 // will be checked however.
   783 TInt TCompareSrcDst::Check(CMultiTransferTest& aTest) const
  1575 TInt TCompareSrcDst::Check(CMultiTransferTest& aTest) const
   784 	{
  1576 	{
   785 	if(gVerboseOutput)
  1577 	if(gVerboseOutput)
   786 		{
  1578 		{
   787 		RDebug::Printf("Comparing CMultiTransferTest buffers");
  1579 		RDebug::Printf("Comparing CMultiTransferTest buffers");
   831 
  1623 
   832 TInt TCompare2D::Check(CMultiTransferTest&) const
  1624 TInt TCompare2D::Check(CMultiTransferTest&) const
   833 	{
  1625 	{
   834 	return KErrNotSupported;
  1626 	return KErrNotSupported;
   835 	}
  1627 	}
       
  1628 
       
  1629 
       
  1630 TInt TCheckNoTransfer::Check(const CSingleTransferTest&) const
       
  1631 	{
       
  1632 	return KErrNotSupported;
       
  1633 	}
       
  1634 
       
  1635 TInt TCheckNoTransfer::Check(const CIsrRequeTest&) const
       
  1636 	{
       
  1637 	return KErrNotSupported;
       
  1638 	}
       
  1639 
       
  1640 TInt TCheckNoTransfer::Check(CMultiTransferTest& aTest) const
       
  1641 	{
       
  1642 	if(gVerboseOutput)
       
  1643 		{
       
  1644 		RDebug::Printf("TCheckNoTransfer Comparing CMultiTransferTest buffers");
       
  1645 		}
       
  1646 
       
  1647 	const TInt transferCount = aTest.TransferCount();
       
  1648 	TUint8* const chunkBase = aTest.Chunk().Base();
       
  1649 
       
  1650 	// check buffers for each transfer
       
  1651 	for(TInt i=0; i<transferCount; i++)
       
  1652 		{
       
  1653 		TInt r = KErrCorrupt;
       
  1654 		if(IsZeroed(aTest.TransferArgs(i), chunkBase))
       
  1655 			{
       
  1656 			r = KErrNone;
       
  1657 			}
       
  1658 
       
  1659 		aTest.SetPostTransferResult(i, r);
       
  1660 		}
       
  1661 	// CMultiTransferTest is handled differently to the others.
       
  1662 	// Whereas CSingleTransferTest logs just the return value
       
  1663 	// of the check, here, we write back a result for each transfer
       
  1664 	// so the return value from this function is not important
       
  1665 	return KErrNone;
       
  1666 	}
       
  1667 
       
  1668 TBool TCheckNoTransfer::IsZeroed(const TDmaTransferArgs& aTransferArgs, TUint8* aChunkBase) const
       
  1669 	{
       
  1670 	TAddressParms parms = GetAddrParms(aTransferArgs);
       
  1671 	parms.Fixup(reinterpret_cast<TLinAddr>(aChunkBase));
       
  1672 	const TAddrRange destination = parms.DestRange();
       
  1673 
       
  1674 	return destination.IsFilled(0);
       
  1675 	}
   836 //////////////////////////////////////////////////////////////////////
  1676 //////////////////////////////////////////////////////////////////////
   837 // MPreTransfer classes
  1677 // MPreTransfer classes
   838 //////////////////////////////////////////////////////////////////////
  1678 //////////////////////////////////////////////////////////////////////
   839 
       
   840 void TPreTransferIncrBytes::Setup(const CSingleTransferTest& aTest) const
  1679 void TPreTransferIncrBytes::Setup(const CSingleTransferTest& aTest) const
   841 	{
  1680 	{
   842 	if(gVerboseOutput)
  1681 	if(gVerboseOutput)
   843 		{
  1682 		{
   844 		RDebug::Printf("TPreTransferIncrBytes(CSingleTransferTest)");
  1683 		RDebug::Printf("TPreTransferIncrBytes(CSingleTransferTest)");
   902 	{
  1741 	{
   903 	if(gVerboseOutput)
  1742 	if(gVerboseOutput)
   904 		{
  1743 		{
   905 		RDebug::Printf("TPreTransferIncrBytes(CMultiTransferTest)");
  1744 		RDebug::Printf("TPreTransferIncrBytes(CMultiTransferTest)");
   906 		}
  1745 		}
   907 	//TODO check for overlap
  1746 
       
  1747 	if(!CheckBuffers(aTest))
       
  1748 		{
       
  1749 		RDebug::Printf("Successive transfer destinations may not overlap previous src or dst buffers");
       
  1750 		TEST_FAULT;
       
  1751 		}
   908 
  1752 
   909 	TUint8* const chunkBase = aTest.Chunk().Base();
  1753 	TUint8* const chunkBase = aTest.Chunk().Base();
   910 	const TInt transferCount = aTest.TransferCount();
  1754 	const TInt transferCount = aTest.TransferCount();
   911 
  1755 
   912 	// initialise buffers for each transfer
  1756 	// initialise buffers for each transfer
   938 
  1782 
   939 	const TBool result = CheckBuffers(array);
  1783 	const TBool result = CheckBuffers(array);
   940 
  1784 
   941 	array.Close();
  1785 	array.Close();
   942 	return result;
  1786 	return result;
       
  1787 	}
       
  1788 
       
  1789 /**
       
  1790 A CMultiTransferTest will wait for all transfers to complete
       
  1791 before comapairing source and destination buffers. For this to be successful
       
  1792 each transfer must be independent ie. no destination or source may be
       
  1793 overwritten by another transfer and source buffers may not depend on an
       
  1794 earlier transfer
       
  1795 */
       
  1796 TBool TPreTransferIncrBytes::CheckBuffers(const CMultiTransferTest& aTest) const
       
  1797 	{
       
  1798 	TUint8* const chunkBase = aTest.Chunk().Base();
       
  1799 	const TInt transferCount = aTest.TransferCount();
       
  1800 
       
  1801 	// assemble an array of TAddressParams from aTest, that
       
  1802 	// can then be passed to CheckBuffers(RArray<TAddressParms>)
       
  1803 	RArray<const TAddressParms> array;
       
  1804 
       
  1805 	for(TInt i=0; i<transferCount; i++)
       
  1806 		{
       
  1807 		TAddressParms params = GetAddrParms(aTest.TransferArgs(i));
       
  1808 		params.Fixup((TLinAddr)chunkBase);
       
  1809 
       
  1810 		array.AppendL(params);
       
  1811 		}
       
  1812 
       
  1813 	 // 2nd arg EFalse as there is no need to permit exact repeats
       
  1814 	const TBool r = CheckBuffers(array, EFalse);
       
  1815 
       
  1816 	array.Close();
       
  1817 	return r;
   943 	}
  1818 	}
   944 
  1819 
   945 /**
  1820 /**
   946 Check that the destination of each TAddressParms does not overlap with
  1821 Check that the destination of each TAddressParms does not overlap with
   947 any previous source or destination or that if it does the whole transfer
  1822 any previous source or destination or that if it does the whole transfer
   948 matches.
  1823 matches.
   949 This is so that successive transfers do not overwrite the destinations or
  1824 This is so that successive transfers do not overwrite the destinations or
   950 sources of preceeding ones.
  1825 sources of preceeding ones.
   951 Exactly matching transfers are allowed to test the case that a repeat
  1826 
   952 transfer is required - though it can't then be determined just from
  1827 If aAllowExactRepeat is true then exactly matching transfers are allowed
   953 looking at the buffers that the repeat was successful
  1828 to test the case where a repeat transfer is required - though it can't
       
  1829 then be determined just from looking at the buffers that the repeat was
       
  1830 successful
   954 */
  1831 */
   955 TBool TPreTransferIncrBytes::CheckBuffers(const RArray<const TAddressParms> aTransferParams) const
  1832 TBool TPreTransferIncrBytes::CheckBuffers(const RArray<const TAddressParms>& aTransferParams, TBool aAllowExactRepeat) const
   956 	{
  1833 	{
       
  1834 
   957 	const TInt count = aTransferParams.Count();
  1835 	const TInt count = aTransferParams.Count();
   958 
  1836 
       
  1837 	if(gVerboseOutput)
       
  1838 		{
       
  1839 		RDebug::Printf("CheckBuffers, %d transfers", count);
       
  1840 		}
       
  1841 
       
  1842 	TBuf<128> buf;
   959 	for(TInt i=1; i<count; i++)
  1843 	for(TInt i=1; i<count; i++)
   960 		{
  1844 		{
   961 		const TAddressParms& current = aTransferParams[i];
  1845 		const TAddressParms& current = aTransferParams[i];
       
  1846 
       
  1847 		if(gVerboseOutput)
       
  1848 			{
       
  1849 			buf.Zero();
       
  1850 			current.AppendString(buf);
       
  1851 			RDebug::Print(_L("Check current: %S, against:"), &buf);
       
  1852 			}
       
  1853 
   962 		for(TInt j=0; j<i; j++)
  1854 		for(TInt j=0; j<i; j++)
   963 			{
  1855 			{
   964 			const TAddressParms& previous = aTransferParams[j];
  1856 			const TAddressParms& previous = aTransferParams[j];
   965 			const TBool ok = !previous.Overlaps(current.DestRange()) || current == previous;
  1857 			if(gVerboseOutput)
       
  1858 				{
       
  1859 				buf.Zero();
       
  1860 				previous.AppendString(buf);
       
  1861 				RDebug::Print(_L("Previous: %S"), &buf);
       
  1862 				}
       
  1863 
       
  1864 			const TBool curDstOverlapsPrevTfer = previous.Overlaps(current.DestRange());
       
  1865 			const TBool curSrcDependsOnPrevDest = current.SourceRange().Overlaps(previous.DestRange());
       
  1866 			const TBool permitExactRepeat = aAllowExactRepeat && (current == previous);
       
  1867 
       
  1868 			const TBool ok = !(curDstOverlapsPrevTfer || curSrcDependsOnPrevDest) || permitExactRepeat;
   966 			if(!ok)
  1869 			if(!ok)
   967 				return EFalse;
  1870 				return EFalse;
   968 			}
  1871 			}
   969 		}
  1872 		}
   970 	return ETrue;
  1873 	return ETrue;
   971 	}
  1874 	}
   972 //////////////////////////////////////////////////////////////////////
  1875 //////////////////////////////////////////////////////////////////////
   973 // TTransferIter class
  1876 // TTransferIter class
   974 //////////////////////////////////////////////////////////////////////
  1877 //////////////////////////////////////////////////////////////////////
   975 
       
   976 void TTransferIter::operator++ ()
  1878 void TTransferIter::operator++ ()
   977 	{
  1879 	{
   978 	iPtr++; //the standard post increment
  1880 	iPtr++; //the standard post increment
   979 	if(iElem < (iCfg->iElementsPerFrame-1))
  1881 	if(iElem < (iCfg->iElementsPerFrame-1))
   980 		{
  1882 		{
  1005 
  1907 
  1006 void TTransferIter::Invariant() const
  1908 void TTransferIter::Invariant() const
  1007 	{
  1909 	{
  1008 	const TInt elemSize = iCfg->iElementSize;
  1910 	const TInt elemSize = iCfg->iElementSize;
  1009 	RTest test(_L("TTransferIter invariant"));
  1911 	RTest test(_L("TTransferIter invariant"));
  1010 	const TInt bytesTransfered = (
  1912 	const TUint bytesTransfered = (
  1011 			elemSize * (iFrame * iCfg->iElementsPerFrame + iElem)
  1913 			elemSize * (iFrame * iCfg->iElementsPerFrame + iElem)
  1012 			+ ((TUint)iPtr % (elemSize))
  1914 			+ ((TUint)iPtr % (elemSize))
  1013 			);
  1915 			);
  1014 	test_Equal(iBytes, bytesTransfered);
  1916 	test_Equal(iBytes, bytesTransfered);
  1015 	test.Close();
  1917 	test.Close();
  1235 		const TTestCase& testCase = *iTestCases[i];
  2137 		const TTestCase& testCase = *iTestCases[i];
  1236 
  2138 
  1237 		//Here, we must create a test thread for each channel
  2139 		//Here, we must create a test thread for each channel
  1238 		RPointerArray<CTest> concurrentTests;
  2140 		RPointerArray<CTest> concurrentTests;
  1239 
  2141 
  1240 		if(testCase.iConcurrentTest)
       
  1241 			RDebug::Printf("== Begin concurrent test run ==");
       
  1242 
       
  1243 		const TInt chanRecCount = iChannelRecords.Count();
  2142 		const TInt chanRecCount = iChannelRecords.Count();
  1244 		for(TInt j=0; j < chanRecCount; j++)
  2143 		for(TInt j=0; j < chanRecCount; j++)
  1245 			{
  2144 			{
  1246 			const TChannelRecord& record = iChannelRecords[j];
  2145 			const TChannelRecord& record = iChannelRecords[j];
  1247 			const TDmacTestCaps& caps = record.iChannelCaps;
  2146 			const TDmacTestCaps& caps = record.iChannelCaps;
  1254 				{
  2153 				{
  1255 				CDmaTest* dmaTest = static_cast<CDmaTest*>(testCase.iTest->Clone());
  2154 				CDmaTest* dmaTest = static_cast<CDmaTest*>(testCase.iTest->Clone());
  1256 				TEST_ASSERT(dmaTest != NULL);
  2155 				TEST_ASSERT(dmaTest != NULL);
  1257 
  2156 
  1258 				dmaTest->SetChannelCookie(record.iCookie);
  2157 				dmaTest->SetChannelCookie(record.iCookie);
  1259 				dmaTest->Announce();
  2158 				dmaTest->SetupL();
  1260 				if(testCase.iConcurrentTest)
  2159 				if(testCase.iConcurrentTest)
  1261 					{
  2160 					{
  1262 					//Add test to array to be run concurrently
  2161 					//Add test to array to be run concurrently
  1263 					TInt r = concurrentTests.Append(dmaTest);
  2162 					TInt r = concurrentTests.Append(dmaTest);
  1264 					TEST_ASSERT(r == KErrNone);
  2163 					TEST_ASSERT(r == KErrNone);
  1265 					}
  2164 					}
  1266 				else
  2165 				else
  1267 					{
  2166 					{
       
  2167 					dmaTest->Announce();
  1268 					//Run test in this thread
  2168 					//Run test in this thread
  1269 					(*dmaTest)();
  2169 					(*dmaTest)();
  1270 					//TTestThread(
       
  1271 					TBool result = dmaTest->Result();
  2170 					TBool result = dmaTest->Result();
  1272 					TEST_ASSERT(result);
  2171 					TEST_ASSERT(result);
  1273 
  2172 
  1274 					delete dmaTest;
  2173 					delete dmaTest;
  1275 					}
  2174 					}
  1295 			//alternatively run the current test case on the next channel:
  2194 			//alternatively run the current test case on the next channel:
  1296 
  2195 
  1297 			//if the test case has been run on all channels it will then  wait for all threads to complete.
  2196 			//if the test case has been run on all channels it will then  wait for all threads to complete.
  1298 			}
  2197 			}
  1299 
  2198 
       
  2199 		// Run the tests which should happen concurrently
  1300 		const TInt count = concurrentTests.Count();
  2200 		const TInt count = concurrentTests.Count();
  1301 		if(count>0)
  2201 		if(count>0)
  1302 			{
  2202 			{
       
  2203 			RDebug::Printf("== Begin concurrent test run ==");
       
  2204 
       
  2205 			TInt i;											// VC++
       
  2206 			for(i=0; i<count; i++)
       
  2207 				{
       
  2208 				concurrentTests[i]->Announce();
       
  2209 				}
       
  2210 
  1303 			MultipleTestRun(concurrentTests);
  2211 			MultipleTestRun(concurrentTests);
  1304 			for(TInt i=0; i<count; i++)
  2212 			for(i=0; i<count; i++)
  1305 				{
  2213 				{
  1306 				TBool result = static_cast<CDmaTest*>(concurrentTests[i])->Result();
  2214 				TBool result = static_cast<CDmaTest*>(concurrentTests[i])->Result();
  1307 				TEST_ASSERT(result);
  2215 				TEST_ASSERT(result);
  1308 				}
  2216 				}
  1309 			RDebug::Printf("== End concurrent test run ==");
  2217 			RDebug::Printf("== End concurrent test run ==");
  1372 */
  2280 */
  1373 void PrintUsage()
  2281 void PrintUsage()
  1374 	{
  2282 	{
  1375 	test.Printf(_L("*** DMA TEST FRAMEWORK ***\n"));
  2283 	test.Printf(_L("*** DMA TEST FRAMEWORK ***\n"));
  1376 	test.Printf(_L("Usage : t_dma2.exe [/option]\n"));
  2284 	test.Printf(_L("Usage : t_dma2.exe [/option]\n"));
  1377 	test.Printf(_L("  /V  or /VERBOSE    = Control test output\n"));
  2285 	test.Printf(_L("  /V or /VERBOSE  = Control test output\n"));
  1378 	test.Printf(_L("  /S  or /SELFTEST   = Run DMA self test\n"));
  2286 	test.Printf(_L("  /S or /SELFTEST = Run DMA self tests\n"));
       
  2287 	test.Printf(_L("  /simple = Run only simple transfer tests\n"));
       
  2288 	test.Printf(_L("  /callback = Run only callback tests\n"));
       
  2289 	test.Printf(_L("  /multi = Run only multipart transfer tests\n"));
       
  2290 	test.Printf(_L("  /isrdfc = Run only isr and dfc tests\n"));
       
  2291 	test.Printf(_L("  /isreque = Run only isr reque tests\n"));
       
  2292 	test.Printf(_L("  /bench = Run only benchmark tests\n"));
       
  2293 	test.Printf(_L("  /suspend = Run only pause and resume tests\n"));
       
  2294 	test.Printf(_L("  /graphic = Run only graphic tests\n"));
       
  2295 	test.Printf(_L("  /channel = Run only DMA channel (opening and closing) tests\n"));
       
  2296 	test.Printf(_L("  /queue = Run only queue tests\n"));
       
  2297 	test.Printf(_L("  /fragment = Run only fragmentation related tests\n"));
       
  2298 	test.Printf(_L("  /request = Run only requests tests related tests\n"));
  1379 	test.Printf(_L("\n"));
  2299 	test.Printf(_L("\n"));
  1380 	}
  2300 	}
  1381 
  2301 
  1382 void ProcessCommandLineL()
  2302 void ProcessCommandLineL()
  1383 {
  2303 {
  1422 			test.Printf(_L("Command Line Options:Verbose option specified.\n"));
  2342 			test.Printf(_L("Command Line Options:Verbose option specified.\n"));
  1423 			gVerboseOutput = ETrue;
  2343 			gVerboseOutput = ETrue;
  1424 			tokenParsed = ETrue;			
  2344 			tokenParsed = ETrue;			
  1425 			}
  2345 			}
  1426 
  2346 
       
  2347 		// '/suspend' option
       
  2348 		if ((0== tc->FindF(KArgSuspendTest)))
       
  2349 			{
       
  2350 			gSuspend = ETrue;
       
  2351 			tokenParsed = ETrue;
       
  2352 			}	
       
  2353 		
       
  2354 		// '/simple' option
       
  2355 		if ((0== tc->FindF(KArgSimpleTest)))
       
  2356 			{
       
  2357 			gSimpleTest = ETrue;
       
  2358 			tokenParsed = ETrue;
       
  2359 			}	
       
  2360 		
       
  2361 		// '/multi' option
       
  2362 		if ((0== tc->FindF(KArgMultiPartTest)))
       
  2363 			{
       
  2364 			gMultiPart = ETrue;
       
  2365 			tokenParsed = ETrue;
       
  2366 			}	
       
  2367 	
       
  2368 		// '/callback' option
       
  2369 		if ((0== tc->FindF(KArgCallBackTest)))
       
  2370 			{
       
  2371 			gCallBack = ETrue;
       
  2372 			tokenParsed = ETrue;
       
  2373 			}	
       
  2374 		
       
  2375 		// '/IsrAndDfc' option
       
  2376 		if ((0== tc->FindF(KArgIsrDfcTest)))
       
  2377 			{
       
  2378 			gIsrAndDfc  = ETrue;
       
  2379 			tokenParsed = ETrue;
       
  2380 			}	
       
  2381 		
       
  2382 		// '/IsrReque' option
       
  2383 		if ((0== tc->FindF(KArgIsrequeTest)))
       
  2384 			{
       
  2385 			gIsrReque = ETrue;
       
  2386 			tokenParsed = ETrue;
       
  2387 			}	
       
  2388 
       
  2389 		// '/Benchmark' option
       
  2390 		if ((0== tc->FindF(KArgBenchmarkTest)))
       
  2391 			{
       
  2392 			gBenchmark = ETrue;
       
  2393 			tokenParsed = ETrue;
       
  2394 			}	
       
  2395 
       
  2396 		// '/Queue' option
       
  2397 		if ((0== tc->FindF(KArgQueueTest)))
       
  2398 			{
       
  2399 			gQueue = ETrue;
       
  2400 			tokenParsed = ETrue;
       
  2401 			}	
       
  2402 
       
  2403 		// '/Fragment' option
       
  2404 		if ((0== tc->FindF(KArgFragmentTest)))
       
  2405 			{
       
  2406 			gFragment = ETrue;
       
  2407 			tokenParsed = ETrue;
       
  2408 			}	
       
  2409 		
       
  2410 		// '/Channel' option
       
  2411 		if ((0== tc->FindF(KArgChannelTest)))
       
  2412 			{
       
  2413 			gChannel = ETrue;
       
  2414 			tokenParsed = ETrue;
       
  2415 			}	
       
  2416 		
       
  2417 		// '/Graphic' option
       
  2418 		if ((0== tc->FindF(KArgGraphicTest)))
       
  2419 			{
       
  2420 			gGraphic = ETrue;
       
  2421 			tokenParsed = ETrue;
       
  2422 			}	
       
  2423 
       
  2424 		// '/Request' option
       
  2425 		if ((0== tc->FindF(KArgRequestTest)))
       
  2426 			{
       
  2427 			gRequest = ETrue;
       
  2428 			tokenParsed = ETrue;
       
  2429 			}	
       
  2430 	
  1427 		if (!tokenParsed)
  2431 		if (!tokenParsed)
  1428 			{
  2432 			{
  1429 			// warn about unparsed parameter
  2433 			// warn about unparsed parameter
  1430 			test.Printf(_L("Warning: '%lS'??? not parsed\n"), tc);
  2434 			test.Printf(_L("Warning: '%lS'??? not parsed\n"), tc);
  1431 			gHelpRequested = ETrue;
  2435 			gHelpRequested = ETrue;
  1442 	{
  2446 	{
  1443 	test.Start(_L("Creating test runner\n"));
  2447 	test.Start(_L("Creating test runner\n"));
  1444 	TTestRunner testRunner;
  2448 	TTestRunner testRunner;
  1445 
  2449 
  1446 	test.Next(_L("Add global test cases to test runner\n"));
  2450 	test.Next(_L("Add global test cases to test runner\n"));
  1447 	testRunner.AddTestCases(TestArray);
  2451 
  1448 
  2452 	if (gSimpleTest) //Add only simple tranfer test cases
       
  2453 	{
       
  2454 		testRunner.AddTestCases(TestArraySimple);
       
  2455 	}
       
  2456 	else if (gCallBack)  //Add only callback test cases
       
  2457 	{
       
  2458 		testRunner.AddTestCases(TestArrayCallback);
       
  2459 	}
       
  2460 	else if (gIsrReque)  //Add only ISR Reque test cases
       
  2461 	{
       
  2462 		testRunner.AddTestCases(TestArrayIsrReque);
       
  2463 	}
       
  2464 	else if (gMultiPart)  //Add only Multipart test cases
       
  2465 	{
       
  2466 		testRunner.AddTestCases(TestArrayMultiPart);
       
  2467 	}
       
  2468 	else if (gIsrAndDfc)  //Add only IsrAndDfc test cases
       
  2469 	{
       
  2470 		testRunner.AddTestCases(TestArrayIsrAndDfc);
       
  2471 	}
       
  2472 	else if (gBenchmark)  //Add only Benchmark test cases
       
  2473 	{
       
  2474 		testRunner.AddTestCases(TestArrayBenchmark);
       
  2475 	}
       
  2476 	else if (gGraphic)  //Add only 2D test cases
       
  2477 	{
       
  2478 		testRunner.AddTestCases(TestArray2DTest);
       
  2479 	}
       
  2480 	else if (gFragment)  //Add only Fragment test cases
       
  2481 	{
       
  2482 		testRunner.AddTestCases(TestArrayFragment);
       
  2483 	}
       
  2484 	else if (gChannel)  //Add only Channel test cases
       
  2485 	{
       
  2486 		testRunner.AddTestCases(TestArrayChannel);
       
  2487 	}
       
  2488 	else if (gSuspend)  //Add only Suspend test cases
       
  2489 	{
       
  2490 		testRunner.AddTestCases(TestArraySuspend);
       
  2491 	}
       
  2492 	else if (gQueue)  //Add only queue test cases
       
  2493 	{
       
  2494 		testRunner.AddTestCases(TestArrayQueue);
       
  2495 	}
       
  2496 	else if (gRequest)  //Add only request test cases
       
  2497 	{
       
  2498 		testRunner.AddTestCases(TestArrayRequest);
       
  2499 	}
       
  2500 	else
       
  2501 	{
       
  2502 		testRunner.AddTestCases(TestArray);//Add all test cases
       
  2503 	}
       
  2504 
       
  2505 	
  1449 	test.Next(_L("call TTestRunner::RunTests()\n"));
  2506 	test.Next(_L("call TTestRunner::RunTests()\n"));
  1450 	testRunner.RunTests();
  2507 	testRunner.RunTests();
  1451 
  2508 
  1452 	test.End();
  2509 	test.End();
  1453 	}
  2510 	}
  1454 
  2511 
  1455 TInt E32Main()
  2512 TInt E32Main()
  1456 	{
  2513 	{
  1457 	__UHEAP_MARK;
  2514 	__UHEAP_MARK;
  1458 	//__KHEAP_MARK;
       
  1459 	test.Title();
  2515 	test.Title();
  1460 
  2516 
  1461 	gHelpRequested = EFalse;
  2517 	gHelpRequested = EFalse;
  1462 	TInt r;
  2518 	TInt r;
  1463 
  2519 
  1493 	r = User::LoadLogicalDevice(KDma2Compat);
  2549 	r = User::LoadLogicalDevice(KDma2Compat);
  1494 	const TBool dma2CompatLoaded = ((r == KErrNone) || (r == KErrAlreadyExists));
  2550 	const TBool dma2CompatLoaded = ((r == KErrNone) || (r == KErrAlreadyExists));
  1495 
  2551 
  1496 	if (!(dma2Loaded || dma2CompatLoaded))
  2552 	if (!(dma2Loaded || dma2CompatLoaded))
  1497 		{
  2553 		{
  1498 		//TODO how can we distinguish this case from a platform where
  2554 		test.Printf(_L("DMA test driver not found - test skipped\n"));
  1499 		//dma is supposed to be supported but the dma test ldd is
       
  1500 		//missing?
       
  1501 		test.Printf(_L("DMA not supported - test skipped\n"));
       
  1502 		return 0;
  2555 		return 0;
  1503 		}
  2556 		}
  1504 	else if (dma2Loaded && !dma2CompatLoaded)
  2557 	else if (dma2Loaded && !dma2CompatLoaded)
  1505 		{
  2558 		{
  1506 		test.Printf(_L("Loaded %S\n"), &KDma);
  2559 		test.Printf(_L("Loaded %S\n"), &KDma);
  1525 	if (gSelfTest) //Run self tests if specified on command line
  2578 	if (gSelfTest) //Run self tests if specified on command line
  1526 	{
  2579 	{
  1527 	SelfTests(); 	
  2580 	SelfTests(); 	
  1528 	}
  2581 	}
  1529 
  2582 
  1530 	ApiTests();
       
  1531 
       
  1532 	RunDMATests();
  2583 	RunDMATests();
  1533 
  2584 
       
  2585 	// Wait for the supervisor thread to run and perform asynchronous
       
  2586 	// cleanup, so that kernel heap space will be freed
       
  2587 	r = UserSvr::HalFunction(EHalGroupKernel, EKernelHalSupervisorBarrier, (TAny*)5000, 0);
       
  2588 	test_KErrNone(r);
  1534 	__KHEAP_MARKEND;
  2589 	__KHEAP_MARKEND;
  1535 
  2590 
  1536 	r = User::FreeLogicalDevice(KTestDmaLddName);
  2591 	r = User::FreeLogicalDevice(KTestDmaLddName);
  1537 	test_KErrNone(r);
  2592 	test_KErrNone(r);
  1538 	test.End();
  2593 	test.End();
  1539 	test.Close();
  2594 	test.Close();
  1540 
  2595 
  1541 	delete cleanup;
  2596 	delete cleanup;
  1542 
  2597 
  1543 	//__KHEAP_MARKEND;
       
  1544 	__UHEAP_MARKEND;
  2598 	__UHEAP_MARKEND;
  1545 	return 0;
  2599 	return 0;
  1546 	}
  2600 	}