kerneltest/e32test/dmav2/self_test.cpp
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 * This file contains unit tests for the test framework itself.
       
    16 * They should be run if changes have been made to
       
    17 * to the user side test framework code ie. anything in the dmav2
       
    18 * directory other than the d_* driver code, or test_cases.cpp
       
    19 *
       
    20 */
       
    21 
       
    22 #include "d_dma2.h"
       
    23 #include "u32std.h"
       
    24 #include "t_dma2.h"
       
    25 #include "cap_reqs.h"
       
    26 
       
    27 #define __E32TEST_EXTENSION__
       
    28 #include <e32test.h>
       
    29 #include <e32debug.h>
       
    30 #include <e32svr.h>
       
    31 
       
    32 static RTest test(_L("t_dma2 test framework tests"));
       
    33 
       
    34 void RDmaSession::SelfTest(TBool aSimulatedDmac)
       
    35 	{
       
    36 	test.Start(_L("Simple transfer test"));
       
    37 
       
    38 	RDmaSession session;
       
    39 	TInt r = KErrUnknown;
       
    40 	if (aSimulatedDmac)
       
    41 		{
       
    42 		test.Next(_L("Open session (simulated DMA)"));
       
    43 		r = session.OpenSim();
       
    44 		}
       
    45 	else
       
    46 		{
       
    47 		test.Next(_L("Open session"));
       
    48 		r = session.Open();
       
    49 		}
       
    50 
       
    51 	test_KErrNone(r);
       
    52 
       
    53 	test.Next(_L("Get test info"));
       
    54 	TDmaV2TestInfo testInfo;
       
    55 	r = session.GetTestInfo(testInfo);
       
    56 	test_KErrNone(r);
       
    57 
       
    58 	if(gVerboseOutput)
       
    59 	{
       
    60 	Print(testInfo);
       
    61 	}
       
    62 
       
    63 	// Self test just needs 1 channel
       
    64 	// The real test will test all available ones
       
    65 	test.Next(_L("Select test channel"));
       
    66 	TUint testChannel = 0;
       
    67 	if(testInfo.iMaxSbChannels > 0)
       
    68 		{
       
    69 		testChannel = testInfo.iSbChannels[0];
       
    70 		}
       
    71 	else if(testInfo.iMaxDbChannels > 0)
       
    72 		{
       
    73 		testChannel = testInfo.iDbChannels[0];
       
    74 		}
       
    75 	else if(testInfo.iMaxSgChannels > 0)
       
    76 		{
       
    77 		testChannel = testInfo.iSgChannels[0];
       
    78 		}
       
    79 	else
       
    80 		{
       
    81 		test.Printf(_L("Driver exposes no channels to test"));
       
    82 		test(EFalse);
       
    83 		}
       
    84 
       
    85 	test.Printf(_L("using PSL cookie %d (0x%08x)\n"), testChannel, testChannel);
       
    86 	test.Next(_L("Open channel"));
       
    87 	TUint channelCookie=0;
       
    88 	r = session.ChannelOpen(testChannel, channelCookie);
       
    89 	test.Printf(_L("cookie recived = 0x%08x\n"), channelCookie);
       
    90 	test_KErrNone(r);
       
    91 
       
    92 	test.Next(_L("Get Channel caps"));
       
    93 	SDmacCaps channelCaps;
       
    94 	r = session.ChannelCaps(channelCookie, channelCaps);
       
    95 	test_KErrNone(r);
       
    96 	if(gVerboseOutput)
       
    97 	{
       
    98 	PRINT(channelCaps.iChannelPriorities);
       
    99 	PRINT(channelCaps.iChannelPauseAndResume);
       
   100 	PRINT(channelCaps.iAddrAlignedToElementSize);
       
   101 	PRINT(channelCaps.i1DIndexAddressing);
       
   102 	PRINT(channelCaps.i2DIndexAddressing);
       
   103 	PRINT(channelCaps.iSynchronizationTypes);
       
   104 	PRINT(channelCaps.iBurstTransactions);
       
   105 	PRINT(channelCaps.iDescriptorInterrupt);
       
   106 	PRINT(channelCaps.iFrameInterrupt);
       
   107 	PRINT(channelCaps.iLinkedListPausedInterrupt);
       
   108 	PRINT(channelCaps.iEndiannessConversion);
       
   109 	PRINT(channelCaps.iGraphicsOps);
       
   110 	PRINT(channelCaps.iRepeatingTransfers);
       
   111 	PRINT(channelCaps.iChannelLinking);
       
   112 	PRINT(channelCaps.iHwDescriptors);
       
   113 	PRINT(channelCaps.iSrcDstAsymmetry);
       
   114 	PRINT(channelCaps.iAsymHwDescriptors);
       
   115 	PRINT(channelCaps.iBalancedAsymSegments);
       
   116 	PRINT(channelCaps.iAsymCompletionInterrupt);
       
   117 	PRINT(channelCaps.iAsymDescriptorInterrupt);
       
   118 	PRINT(channelCaps.iAsymFrameInterrupt);
       
   119 	PRINT(channelCaps.iReserved[0]);
       
   120 	PRINT(channelCaps.iReserved[1]);
       
   121 	PRINT(channelCaps.iReserved[2]);
       
   122 	PRINT(channelCaps.iReserved[3]);
       
   123 	PRINT(channelCaps.iReserved[4]);	
       
   124 	}
       
   125 
       
   126 	test.Next(_L("Get extended Channel caps (TDmacTestCaps)"));
       
   127 	TDmacTestCaps extChannelCaps;
       
   128 	r = session.ChannelCaps(channelCookie, extChannelCaps);
       
   129 	test_KErrNone(r);
       
   130 	test.Printf(_L("PIL version = %d\n"), extChannelCaps.iPILVersion);
       
   131 
       
   132 	const TBool newPil = (extChannelCaps.iPILVersion > 1);
       
   133 
       
   134 	test.Next(_L("Create Dma request - max fragment size 32K"));
       
   135 	TUint reqCookie=0;
       
   136 	r = session.RequestCreateOld(channelCookie, reqCookie, 32 * KKilo);
       
   137 	test.Printf(_L("cookie recived = 0x%08x\n"), reqCookie);
       
   138 	test_KErrNone(r);
       
   139 
       
   140 	if(newPil)
       
   141 		{
       
   142 		test.Next(_L("Create Dma request (with new-style callback)"));
       
   143 		TUint reqCookieNewStyle=0;
       
   144 		r = session.RequestCreate(channelCookie, reqCookieNewStyle);
       
   145 		test.Printf(_L("cookie recived = 0x%08x\n"), reqCookieNewStyle );
       
   146 		test_KErrNone(r);
       
   147 
       
   148 		if(!aSimulatedDmac)
       
   149 			{
       
   150 			test.Next(_L("Fragment for ISR callback"));
       
   151 			const TInt size = 128 * KKilo;
       
   152 			TDmaTransferArgs transferArgs(0, size, size, KDmaMemAddr, KDmaSyncAuto, KDmaRequestCallbackFromIsr);
       
   153 			r = session.FragmentRequest(reqCookieNewStyle, transferArgs);
       
   154 			test_KErrNone(r);
       
   155 
       
   156 			TIsrRequeArgs reque;
       
   157 			test.Next(_L("Queue ISR callback - with default re-queue"));
       
   158 			r = session.QueueRequestWithRequeue(reqCookieNewStyle, &reque, 1);
       
   159 			test_KErrNone(r);
       
   160 			}
       
   161 
       
   162 		test.Next(_L("Destroy new-style Dma request"));
       
   163 		r = session.RequestDestroy(reqCookieNewStyle);
       
   164 		test_KErrNone(r);
       
   165 
       
   166 		test.Next(_L("Attempt to destroy request again "));
       
   167 		r = session.RequestDestroy(reqCookieNewStyle);
       
   168 		test_Equal(KErrNotFound, r);
       
   169 		}
       
   170 
       
   171 	test.Next(_L("Open chunk handle"));
       
   172 	RChunk chunk;
       
   173 	r = session.OpenSharedChunk(chunk);
       
   174 	test_KErrNone(r);
       
   175 	if(gVerboseOutput)
       
   176 	{
       
   177 	test.Printf(_L("chunk base = 0x%08x\n"), chunk.Base());
       
   178 	test.Printf(_L("chunk size = %d\n"), chunk.Size());
       
   179 	}
       
   180 	test(chunk.IsWritable());
       
   181 	test(chunk.IsReadable());
       
   182 
       
   183 	if(!aSimulatedDmac)
       
   184 		{
       
   185 		test.Next(_L("Fragment(old style)"));
       
   186 		const TInt size = 128 * KKilo;
       
   187 		TInt i;
       
   188 		for(i = 0; i<10; i++)
       
   189 			{
       
   190 			TUint64 time = 0;
       
   191 			TDmaTransferArgs transferArgs(0, size, size, KDmaMemAddr);
       
   192 			r = session.FragmentRequestOld(reqCookie, transferArgs, &time);
       
   193 			test_KErrNone(r);
       
   194 			if(gVerboseOutput)
       
   195 				{
       
   196 				test.Printf(_L("%lu us\n"), time);
       
   197 				}
       
   198 			}
       
   199 
       
   200 		test.Next(_L("Queue"));
       
   201 		TRequestStatus status;
       
   202 
       
   203 		for(i = 0; i<10; i++)
       
   204 			{
       
   205 			TUint64 time = 0;
       
   206 			r = session.QueueRequest(reqCookie, status, 0, &time);
       
   207 			User::WaitForRequest(status);
       
   208 			test_KErrNone(r);
       
   209 			if(gVerboseOutput)
       
   210 				{
       
   211 				test.Printf(_L("%lu us\n"), time);
       
   212 				}
       
   213 			}
       
   214 
       
   215 		if(newPil)
       
   216 			{
       
   217 			test.Next(_L("Fragment(new style)"));
       
   218 			TDmaTransferArgs transferArgs;
       
   219 			transferArgs.iSrcConfig.iAddr = 0;
       
   220 			transferArgs.iDstConfig.iAddr = size;
       
   221 			transferArgs.iSrcConfig.iFlags = KDmaMemAddr;
       
   222 			transferArgs.iDstConfig.iFlags = KDmaMemAddr;
       
   223 			transferArgs.iTransferCount = size;
       
   224 
       
   225 			for(i = 0; i<10; i++)
       
   226 				{
       
   227 				TUint64 time = 0;
       
   228 				r = session.FragmentRequest(reqCookie, transferArgs, &time);
       
   229 				test_KErrNone(r);
       
   230 				if(gVerboseOutput)
       
   231 					{
       
   232 					test.Printf(_L("%lu us\n"), time);
       
   233 					}
       
   234 				}
       
   235 			}
       
   236 
       
   237 		test.Next(_L("Queue"));
       
   238 		TCallbackRecord record;
       
   239 		r = session.QueueRequest(reqCookie, &record);
       
   240 		test_KErrNone(r);
       
   241 
       
   242 		test.Next(_L("check TCallbackRecord record"));
       
   243 		if(gVerboseOutput)
       
   244 		{
       
   245 		record.Print();
       
   246 		}
       
   247 		const TCallbackRecord expected(TCallbackRecord::EThread, 1);
       
   248 		if(!(record == expected))
       
   249 			{
       
   250 			test.Printf(_L("TCallbackRecords did not match"));
       
   251 			if(gVerboseOutput)
       
   252 				{
       
   253 				test.Printf(_L("expected:"));
       
   254 				expected.Print();
       
   255 				}
       
   256 			TEST_FAULT;
       
   257 			}
       
   258 		}
       
   259 
       
   260 	test.Next(_L("Destroy Dma request"));
       
   261 	r = session.RequestDestroy(reqCookie);
       
   262 	test_KErrNone(r);
       
   263 
       
   264 	test.Next(_L("Close chunk handle"));
       
   265 	chunk.Close();
       
   266 
       
   267 	test.Next(_L("Channel close"));
       
   268 	r = session.ChannelClose(channelCookie);
       
   269 	test_KErrNone(r);
       
   270 
       
   271 	test.Next(_L("Channel close (same again)"));
       
   272 	r = session.ChannelClose(channelCookie);
       
   273 	test_Equal(KErrNotFound, r);
       
   274 
       
   275 	test.Next(_L("Close session"));
       
   276 	RTest::CloseHandleAndWaitForDestruction(session);
       
   277 
       
   278 	test.End();
       
   279 	}
       
   280 
       
   281 const SDmacCaps KTestCapSet =
       
   282 	{6,										// TInt iChannelPriorities;
       
   283 	 EFalse,								// TBool iChannelPauseAndResume;
       
   284 	 ETrue,									// TBool iAddrAlignedToElementSize;
       
   285 	 EFalse,								// TBool i1DIndexAddressing;
       
   286 	 EFalse,								// TBool i2DIndexAddressing;
       
   287 	 KDmaSyncSizeElement | KDmaSyncSizeFrame |
       
   288 	 KDmaSyncSizeBlock,					   // TUint iSynchronizationTypes;
       
   289 	 KDmaBurstSize4 | KDmaBurstSize8,	   // TUint iBurstTransactions;
       
   290 	 EFalse,							   // TBool iDescriptorInterrupt;
       
   291 	 EFalse,							   // TBool iFrameInterrupt;
       
   292 	 EFalse,							   // TBool iLinkedListPausedInterrupt;
       
   293 	 EFalse,							   // TBool iEndiannessConversion;
       
   294 	 0,									   // TUint iGraphicsOps;
       
   295 	 ETrue,								   // TBool iRepeatingTransfers;
       
   296 	 EFalse,							   // TBool iChannelLinking;
       
   297 	 ETrue,								   // TBool iHwDescriptors;
       
   298 	 EFalse,							   // TBool iSrcDstAsymmetry;
       
   299 	 EFalse,							   // TBool iAsymHwDescriptors;
       
   300 	 EFalse,							   // TBool iBalancedAsymSegments;
       
   301 	 EFalse,							   // TBool iAsymCompletionInterrupt;
       
   302 	 EFalse,							   // TBool iAsymDescriptorInterrupt;
       
   303 	 EFalse,							   // TBool iAsymFrameInterrupt;
       
   304 	 {0, 0, 0, 0, 0}					   // TUint32 iReserved[5];
       
   305 	};
       
   306 
       
   307 const TDmacTestCaps KDmacTestCapsV1(KTestCapSet, 1);
       
   308 const TDmacTestCaps KDmacTestCapsV2(KTestCapSet, 2);
       
   309 
       
   310 void TDmaCapability::SelfTest()
       
   311 	{
       
   312 	test.Start(_L("Unit test_Value of TDmaCapability::CompareToDmaCaps\n"));
       
   313 // Note: The construction of the test description message
       
   314 // is horribly confusing. The _L macro will make the
       
   315 // *first* string token wide, but not the next two.
       
   316 // Therefore these must be made wide or compilier
       
   317 // will complain about concatination of narrow and wide string
       
   318 // literals
       
   319 #define CAP_TEST(CAP, CAPSET, EXPCT)\
       
   320 	{\
       
   321 	test.Next(_L(#CAP L" against " L ## #CAPSET));\
       
   322 	TResult t = (CAP).CompareToDmaCaps(CAPSET);\
       
   323 	test_Equal(EXPCT, t);\
       
   324 	}
       
   325 
       
   326 	CAP_TEST(none, KTestCapSet, ERun);
       
   327 	CAP_TEST(pauseRequired, KTestCapSet, EFail);
       
   328 	CAP_TEST(pauseRequired_skip, KTestCapSet, ESkip);
       
   329 	CAP_TEST(pauseNotWanted, KTestCapSet, ERun);
       
   330 	CAP_TEST(hwDesNotWanted, KTestCapSet, EFail);	
       
   331 	CAP_TEST(hwDesNotWanted_skip, KTestCapSet, ESkip);
       
   332 	CAP_TEST(hwDesWanted, KTestCapSet, ERun);
       
   333 
       
   334 	CAP_TEST(capEqualV1, KDmacTestCapsV1, ERun);
       
   335 	CAP_TEST(capEqualV2, KDmacTestCapsV2, ERun);
       
   336 	CAP_TEST(capEqualV1, KDmacTestCapsV2, ESkip);
       
   337 	CAP_TEST(capEqualV2, KDmacTestCapsV1, ESkip);
       
   338 	CAP_TEST(capEqualV2Fatal, KDmacTestCapsV1, EFail);
       
   339 
       
   340 	CAP_TEST(capAboveV1, KDmacTestCapsV2, ERun);
       
   341 	CAP_TEST(capBelowV2, KDmacTestCapsV1, ERun);
       
   342 	CAP_TEST(capAboveV1, KDmacTestCapsV1, ESkip);
       
   343 	CAP_TEST(capBelowV2, KDmacTestCapsV2, ESkip);
       
   344 
       
   345 	test.End();
       
   346 	}
       
   347 
       
   348 void TTestCase::SelfTest()
       
   349 	{
       
   350 	test.Start(_L("Unit test of TTestCase::TestCaseValid\n"));
       
   351 
       
   352 // Create a TTestCase with paramaters CAP1 and CAP2
       
   353 // call TTestCase::TestCaseValid against CAPSET
       
   354 // Expected result is EXPCT
       
   355 #define TEST_TEST_CASE(CAP1, CAP2, CAPSET, EXPCT)\
       
   356 	{\
       
   357 	test.Next(_L(#CAP1 L", " L ## #CAP2 L" -- Against: " L ## #CAPSET L", Expect: " L ## #EXPCT));\
       
   358 	TTestCase testCase(NULL, EFalse, CAP1, CAP2);\
       
   359 	testCase.iChannelCaps[0] = (CAP1);\
       
   360 	TResult t = testCase.TestCaseValid(CAPSET);\
       
   361 	test_Equal(EXPCT, t);\
       
   362 	}
       
   363 
       
   364 	TEST_TEST_CASE(pauseRequired, hwDesNotWanted, KTestCapSet, EFail);
       
   365 	TEST_TEST_CASE(pauseRequired_skip, hwDesNotWanted, KTestCapSet, EFail);
       
   366 	TEST_TEST_CASE(pauseRequired_skip, hwDesNotWanted_skip, KTestCapSet, ESkip);
       
   367 	TEST_TEST_CASE(pauseNotWanted, hwDesNotWanted_skip, KTestCapSet, ESkip);
       
   368 	TEST_TEST_CASE(pauseNotWanted, hwDesWanted, KTestCapSet, ERun);
       
   369     TEST_TEST_CASE(pauseNotWanted, none, KTestCapSet, ERun);
       
   370 
       
   371 	TEST_TEST_CASE(pauseNotWanted, capAboveV1, KDmacTestCapsV1, ESkip);
       
   372 	TEST_TEST_CASE(pauseNotWanted, capAboveV1, KDmacTestCapsV2, ERun);
       
   373 
       
   374 	TEST_TEST_CASE(pauseNotWanted, capBelowV2, KDmacTestCapsV1, ERun);
       
   375 	TEST_TEST_CASE(pauseNotWanted, capBelowV2, KDmacTestCapsV2, ESkip);
       
   376 
       
   377 	// contradictory requirements
       
   378 	TEST_TEST_CASE(capAboveV1, capBelowV2, KDmacTestCapsV2, ESkip);
       
   379 	TEST_TEST_CASE(capBelowV2, capAboveV1, KDmacTestCapsV2, ESkip);
       
   380 
       
   381 	TEST_TEST_CASE(capAboveV1, capBelowV2, KDmacTestCapsV1, ESkip);
       
   382 	TEST_TEST_CASE(capBelowV2, capAboveV1, KDmacTestCapsV1, ESkip);
       
   383 
       
   384 	test.End();
       
   385 	test.Close();
       
   386 	}
       
   387 
       
   388 
       
   389 void TTransferIter::SelfTest()
       
   390 	{
       
   391 	test.Start(_L("No skip"));
       
   392 
       
   393 	const TUint8 src[9] = {
       
   394 			1 ,2, 3,
       
   395 			4, 5, 6,
       
   396 			7, 8, 9
       
   397 	};
       
   398 
       
   399 	const TUint32 addr = (TUint32)src;
       
   400 	const TUint elementSize = 1;
       
   401 	const TUint elementSkip = 0;
       
   402 	const TUint elementsPerFrame = 3;
       
   403 	const TUint frameSkip = 0;
       
   404 	const TUint framesPerTransfer = 3;
       
   405 	TDmaTransferConfig cfg(addr, elementSize, elementsPerFrame, framesPerTransfer,
       
   406 			elementSkip, frameSkip, KDmaMemAddr
       
   407 			);
       
   408 
       
   409 	TTransferIter iter(cfg, 0);
       
   410 	TTransferIter end;
       
   411 	TInt i;
       
   412 	for(i = 0; i<9; i++, ++iter)
       
   413 		{
       
   414 		test_Equal(src[i],*iter);
       
   415 		};
       
   416 
       
   417 
       
   418 	test.Next(_L("90 degree rotation"));
       
   419 	// Now imagine that we wanted to perform a rotation
       
   420 	// as we write, so that we wrote out the following
       
   421 
       
   422 	const TUint8 expected[9] = {
       
   423 		7, 4, 1,
       
   424 		8, 5, 2,
       
   425 		9, 6, 3
       
   426 	};
       
   427 
       
   428 	TUint8 dst[9] = {0};
       
   429 	TDmaTransferConfig dst_cfg(cfg);
       
   430 	dst_cfg.iAddr = (TUint32)&dst[2];
       
   431 	dst_cfg.iElementSkip = 2;
       
   432 	dst_cfg.iFrameSkip = -8;
       
   433 
       
   434 	TTransferIter dst_iter(dst_cfg, 0);
       
   435 	for(i=0; dst_iter != end; i++, ++dst_iter)
       
   436 		{
       
   437 		TEST_ASSERT(i<9);
       
   438 		*dst_iter=src[i];
       
   439 		};
       
   440 
       
   441 	for(i=0; i<9; i++)
       
   442 		{
       
   443 		test_Equal(expected[i],dst[i]);
       
   444 		}
       
   445 	}
       
   446 
       
   447 void TCallbackRecord::SelfTest()
       
   448 	{
       
   449 	test.Start(_L("SelfTest of TCallbackRecord"));
       
   450 
       
   451 	test.Next(_L("create default TCallbackRecord record, record2"));
       
   452 	TCallbackRecord record;
       
   453 	const TCallbackRecord record2;
       
   454 	if(gVerboseOutput)
       
   455 	{
       
   456 	test.Next(_L("Print record"));
       
   457 	record.Print();
       
   458 	}
       
   459 
       
   460 	test.Next(_L("test (record == record2)"));
       
   461 	if(!(record == record2))
       
   462 		{
       
   463 		if(gVerboseOutput)
       
   464 			{
       
   465 			record2.Print();
       
   466 			}
       
   467 		TEST_FAULT;
       
   468 		}
       
   469 
       
   470 	//A series of callback masks
       
   471 	//Note these combinations do not necessarily represent
       
   472 	//possible callback combinations
       
   473 	TUint callbacks[]  =
       
   474 		{
       
   475 		EDmaCallbackDescriptorCompletion,
       
   476 		EDmaCallbackDescriptorCompletion,
       
   477 		EDmaCallbackDescriptorCompletion,
       
   478 		EDmaCallbackDescriptorCompletion,
       
   479 		EDmaCallbackFrameCompletion_Src,
       
   480 		EDmaCallbackFrameCompletion_Dst,
       
   481 		EDmaCallbackDescriptorCompletion_Src | EDmaCallbackDescriptorCompletion_Dst,
       
   482 		EDmaCallbackDescriptorCompletion_Src | EDmaCallbackFrameCompletion_Src | EDmaCallbackLinkedListPaused_Dst,
       
   483 		EDmaCallbackRequestCompletion | EDmaCallbackRequestCompletion_Src,
       
   484 		EDmaCallbackDescriptorCompletion_Dst
       
   485 		};
       
   486 	test.Next(_L("Feed a series of callback masks in to record"));
       
   487 	const TInt length = ARRAY_LENGTH(callbacks);
       
   488 	for(TInt i = 0; i < length; i++)
       
   489 		{
       
   490 		record.ProcessCallback(callbacks[i], EDmaResultOK);
       
   491 		}
       
   492 	
       
   493 	if(gVerboseOutput)
       
   494 	{
       
   495 	test.Next(_L("Print record"));
       
   496 	record.Print();
       
   497 	}
       
   498 
       
   499 	test.Next(_L("test GetCount"));
       
   500 	test_Equal(1, record.GetCount(EDmaCallbackRequestCompletion));
       
   501 	test_Equal(1, record.GetCount(EDmaCallbackRequestCompletion_Src));
       
   502 	test_Equal(0, record.GetCount(EDmaCallbackRequestCompletion_Dst));
       
   503 	test_Equal(4, record.GetCount(EDmaCallbackDescriptorCompletion));
       
   504 	test_Equal(2, record.GetCount(EDmaCallbackDescriptorCompletion_Src));
       
   505 	test_Equal(2, record.GetCount(EDmaCallbackDescriptorCompletion_Dst));
       
   506 	test_Equal(0, record.GetCount(EDmaCallbackFrameCompletion));
       
   507 	test_Equal(2, record.GetCount(EDmaCallbackFrameCompletion_Src));
       
   508 	test_Equal(1, record.GetCount(EDmaCallbackFrameCompletion_Dst));
       
   509 	test_Equal(0, record.GetCount(EDmaCallbackLinkedListPaused));
       
   510 	test_Equal(0, record.GetCount(EDmaCallbackLinkedListPaused_Src));
       
   511 	test_Equal(1, record.GetCount(EDmaCallbackLinkedListPaused_Dst));
       
   512 
       
   513 	test.Next(_L("test expected == record"));
       
   514 	const TCallbackRecord expected(TCallbackRecord::EThread, 1, 1, 0, 4, 2, 2, 0, 2, 1, 0, 0, 1);
       
   515 	if(!(expected == record))
       
   516 		{
       
   517 		if(gVerboseOutput)
       
   518 			{
       
   519 			expected.Print();
       
   520 			}
       
   521 		TEST_FAULT;
       
   522 		}
       
   523 
       
   524 	test.Next(_L("modify record: test expected != record"));
       
   525 	record.SetCount(EDmaCallbackFrameCompletion, 10);
       
   526 	if(expected == record)
       
   527 		{
       
   528 		if(gVerboseOutput)
       
   529 			{
       
   530 			expected.Print();
       
   531 			}
       
   532 		TEST_FAULT;
       
   533 		}
       
   534 
       
   535 	test.Next(_L("test Reset()"));
       
   536 	record.Reset();
       
   537 	test(record == record2);
       
   538 
       
   539 	test.End();
       
   540 	}
       
   541 
       
   542 void CDmaBenchmark::SelfTest()
       
   543 	{
       
   544 	test.Start(_L("SelfTest of CDmaBenchmark"));
       
   545 	test.Next(_L("MeanResult()"));
       
   546 
       
   547 	// The mean of these numbers is 10
       
   548 	TUint64 results[] = {8, 12, 1, 19, 3, 17, 10};
       
   549 	const TInt count = ARRAY_LENGTH(results);
       
   550 
       
   551 	CDmaBmFragmentation fragTest(_L("SelfTest"), count, TDmaTransferArgs(), 0);
       
   552 
       
   553 	for(TInt i = 0; i < count; i++)
       
   554 		{
       
   555 		fragTest.iResultArray.Append(results[i]);
       
   556 		}
       
   557 	test_Equal(10, fragTest.MeanResult());
       
   558 
       
   559 	test.End();
       
   560 	}
       
   561 
       
   562 void TAddrRange::SelfTest()
       
   563 	{
       
   564 	test.Start(_L("SelfTest of TAddrRange"));
       
   565 	TAddrRange a(0, 8);
       
   566 	TAddrRange b(8, 8);
       
   567 
       
   568 	test_Equal(7, a.End());
       
   569 	test_Equal(15, b.End());
       
   570 
       
   571 	test(!a.Overlaps(b));
       
   572 	test(!b.Overlaps(a));
       
   573 	test(a.Overlaps(a));
       
   574 	test(b.Overlaps(b));
       
   575 
       
   576 	TAddrRange c(7, 2);
       
   577 	test_Equal(8, c.End());
       
   578 
       
   579 	test(a.Overlaps(c));
       
   580 	test(c.Overlaps(a));
       
   581 	test(b.Overlaps(c));
       
   582 	test(c.Overlaps(b));
       
   583 
       
   584 	TAddrRange d(0, 24);
       
   585 	test(a.Overlaps(d));
       
   586 	test(d.Overlaps(a));
       
   587 
       
   588 	test(b.Overlaps(d));
       
   589 	test(d.Overlaps(b));
       
   590 
       
   591 	test(d.Contains(d));
       
   592 
       
   593 	test(d.Contains(a));
       
   594 	test(!a.Contains(d));
       
   595 
       
   596 	test(d.Contains(b));
       
   597 	test(!b.Contains(d));
       
   598 
       
   599 	test(!a.Contains(b));
       
   600 	test(!b.Contains(a));
       
   601 
       
   602 	test.Next(_L("Test IsFilled()"));
       
   603 	TUint8 buffer[] = {0,0,0,0};
       
   604 	TAddrRange range((TUint)buffer, 4);
       
   605 	test(range.IsFilled(0));
       
   606 	buffer[3] = 1;
       
   607 	test(!range.IsFilled(0));
       
   608 	buffer[2] = 1;
       
   609 	buffer[1] = 1;
       
   610 	buffer[0] = 1;
       
   611 	test(range.IsFilled(1));
       
   612 
       
   613 	test.End();
       
   614 	}
       
   615 
       
   616 void TAddressParms::SelfTest()
       
   617 	{
       
   618 	test.Start(_L("SelfTest of TAddressParms"));
       
   619 	const TAddressParms pA(0, 32, 8);
       
   620 	test(pA == pA);
       
   621 	test(pA.Overlaps(pA));
       
   622 
       
   623 	const TAddrRange rA(4, 8);
       
   624 	const TAddrRange rB(16, 8);
       
   625 	const TAddrRange rC(28, 8);
       
   626 	const TAddrRange rD(4, 32);
       
   627 
       
   628 	test(pA.Overlaps(rA));
       
   629 	test(!pA.Overlaps(rB));
       
   630 	test(pA.Overlaps(rC));
       
   631 	test(pA.Overlaps(rD));
       
   632 
       
   633 	const TAddressParms pB(8, 16, 8);
       
   634 	test(!(pA == pB));
       
   635 	test(!(pB == pA));
       
   636 	test(!pA.Overlaps(pB));
       
   637 	test(!pB.Overlaps(pA));
       
   638 
       
   639 	const TAddressParms pC(8, 28, 8);
       
   640 	test(pC.Overlaps(pA));
       
   641 	test(pC.Overlaps(pB));
       
   642 
       
   643 	const TAddressParms pD(0, 128, 64);
       
   644 	test(pD.Overlaps(pA));
       
   645 	test(pD.Overlaps(pB));
       
   646 	test(pD.Overlaps(pC));
       
   647 	test.End();
       
   648 	}
       
   649 
       
   650 void TIsrRequeArgsSet::SelfTest()
       
   651 	{
       
   652 	test.Start(_L("Selftest of TIsrRequeArgsSet"));
       
   653 
       
   654 	TUint size = 0x1000;
       
   655 	TDmaTransferArgs tferArgs(0, 1*size, size, KDmaMemAddr, KDmaSyncAuto, KDmaRequestCallbackFromIsr);
       
   656 
       
   657 	TIsrRequeArgs requeArgArray[] = {
       
   658 		TIsrRequeArgs(),									// Repeat
       
   659 		TIsrRequeArgs(KPhysAddrInvalidUser, 2*size, 0),		// Change destination
       
   660 		TIsrRequeArgs(),									// Repeat
       
   661 		TIsrRequeArgs(3*size, KPhysAddrInvalidUser, 0),		// Change source
       
   662 		TIsrRequeArgs(),									// Repeat
       
   663 	};
       
   664 	TIsrRequeArgsSet argSet(requeArgArray, ARRAY_LENGTH(requeArgArray));
       
   665 
       
   666 	test.Next(_L("Test that Substitute updates transfer args in order"));
       
   667 	argSet.Substitute(tferArgs);
       
   668 
       
   669 	TAddressParms expectedFinal(3*size, 2*size, size);
       
   670 	if(!(expectedFinal == argSet.iRequeArgs[4]))
       
   671 		{
       
   672 		TBuf<0x100> out;
       
   673 
       
   674 		out += _L("substitue: ");
       
   675 		GetAddrParms(tferArgs).AppendString(out);
       
   676 		test.Printf(out);
       
   677 
       
   678 		out.Zero();
       
   679 		out += _L("\nexpected final: ");
       
   680 		expectedFinal.AppendString(out);
       
   681 		test.Printf(out);
       
   682 
       
   683 		out.Zero();
       
   684 		out += _L("\nactual: ");
       
   685 		argSet.iRequeArgs[4].AppendString(out);
       
   686 		test.Printf(out);
       
   687 
       
   688 		test(EFalse);
       
   689 		}
       
   690 
       
   691 	TIsrRequeArgs requeArgArray2[] = {
       
   692 		TIsrRequeArgs(),									// Repeat
       
   693 		TIsrRequeArgs(KPhysAddrInvalidUser, 2*size, 0),		// Change destination
       
   694 		TIsrRequeArgs(KPhysAddrInvalidUser, 1*size, 0),		// Change destination back
       
   695 	};
       
   696 	argSet = TIsrRequeArgsSet(requeArgArray2, ARRAY_LENGTH(requeArgArray2));
       
   697 
       
   698 	test.Next(_L("CheckRange(), negative"));
       
   699 
       
   700 	test(!argSet.CheckRange(0, (2 * size) - 1, tferArgs));
       
   701 	test(!argSet.CheckRange(0, (2 * size) + 1, tferArgs));
       
   702 	test(!argSet.CheckRange(0, (2 * size), tferArgs));
       
   703 
       
   704 	test(!argSet.CheckRange(1 ,(3 * size), tferArgs));
       
   705 	test(!argSet.CheckRange(1 ,(3 * size) + 1, tferArgs));
       
   706 
       
   707 	test(!argSet.CheckRange(1 * size , 2 * size, tferArgs));
       
   708 
       
   709 	test.Next(_L("CheckRange(), positive"));
       
   710 	test(argSet.CheckRange(0, 3 * size, tferArgs));
       
   711 	test(argSet.CheckRange(0, 3 * size+1, tferArgs));
       
   712 	test(argSet.CheckRange(0, 4 * size, tferArgs));
       
   713 
       
   714 
       
   715 	test.End();
       
   716 	}
       
   717 
       
   718 void RArrayCopyTestL()
       
   719 	{
       
   720 	test.Start(_L("Selftest of RArray CopyL"));
       
   721 
       
   722 	RArray<TInt> orig;
       
   723 	TInt i;													// VC++
       
   724 	for(i=0; i<10; i++)
       
   725 		{
       
   726 		orig.AppendL(i);
       
   727 		}
       
   728 
       
   729 	RArray<TInt> newArray;
       
   730 	CopyL(orig, newArray);
       
   731 
       
   732 	test_Equal(10, newArray.Count());
       
   733 
       
   734 	for(i=0; i<10; i++)
       
   735 		{
       
   736 		test_Equal(orig[i], newArray[i])
       
   737 		}
       
   738 
       
   739 	orig.Close();
       
   740 	newArray.Close();
       
   741 	test.End();
       
   742 	}
       
   743 
       
   744 void RArrayInsertLTest()
       
   745 	{
       
   746 	test.Start(_L("Selftest of RArray InsertL"));
       
   747 
       
   748 	RArray<TInt> array;
       
   749 	TInt numbers[10] = {0,1,2,3,4,5,6,7,8,9};
       
   750 	ArrayAppendL(array, &numbers[0], numbers + ARRAY_LENGTH(numbers));
       
   751 
       
   752 	test_Equal(10, array.Count());
       
   753 	for(TInt i=0; i<10; i++)
       
   754 		{
       
   755 		test_Equal(numbers[i], array[i])
       
   756 		}
       
   757 
       
   758 	array.Close();
       
   759 	test.End();
       
   760 	}
       
   761 
       
   762 /**
       
   763 Run check buffers on the supplied TAddressParms array
       
   764 */
       
   765 TBool DoTferParmTestL(const TAddressParms* aParms, TInt aCount, TBool aAllowRepeat, TBool aPositive)
       
   766 	{
       
   767 	_LIT(KPositive, "positive");
       
   768 	_LIT(KNegative, "negative");
       
   769 	test.Printf(_L("CheckBuffers %S test: %d args, repeats allowed %d\n"),
       
   770 			(aPositive ? &KPositive : &KNegative), aCount, aAllowRepeat);
       
   771 	RArray<const TAddressParms> array;
       
   772 	ArrayAppendL(array, aParms, aParms + aCount);
       
   773 	TPreTransferIncrBytes preTran;
       
   774 	TBool r = preTran.CheckBuffers(array, aAllowRepeat);
       
   775 	array.Close();
       
   776 	return r;
       
   777 	}
       
   778 
       
   779 void TPreTransferIncrBytes::SelfTest()
       
   780 	{
       
   781 	// Test that TPreTransferIncrBytes::CheckBuffers can identify
       
   782 	// overlapping buffers
       
   783 	test.Start(_L("Selftest of TPreTransferIncrBytes"));
       
   784 
       
   785 // Macro generates test for 2 element array
       
   786 #define TPARM_TEST2(EXPECT, ALLOW_REPEAT, EL0, EL1)\
       
   787 		{\
       
   788 		TAddressParms set[2] = {EL0, EL1}; \
       
   789 		const TBool r = DoTferParmTestL(set, 2, ALLOW_REPEAT, EXPECT);\
       
   790 		test_Equal(EXPECT, r);\
       
   791 		}
       
   792 
       
   793 // Generate positive 2 element test
       
   794 #define TPARM_TEST2_POSITIVE(ALLOW_REPEAT, EL0, EL1) TPARM_TEST2(ETrue, ALLOW_REPEAT, EL0, EL1)
       
   795 // Generate negative 2 element test
       
   796 #define TPARM_TEST2_NEG(ALLOW_REPEAT, EL0, EL1) TPARM_TEST2(EFalse, ALLOW_REPEAT, EL0, EL1)
       
   797 
       
   798 // Macro generates test for 3 element array
       
   799 #define TPARM_TEST3(EXPECT, ALLOW_REPEAT, EL0, EL1, EL2)\
       
   800 		{\
       
   801 		TAddressParms set[3] = {EL0, EL1, EL2}; \
       
   802 		const TBool r = DoTferParmTestL(set, 3, ALLOW_REPEAT, EXPECT);\
       
   803 		test_Equal(EXPECT, r);\
       
   804 		}
       
   805 
       
   806 // Generate positive 3 element test
       
   807 #define TPARM_TEST3_POSITIVE(ALLOW_REPEAT, EL0, EL1, EL2) TPARM_TEST3(ETrue, ALLOW_REPEAT, EL0, EL1, EL2)
       
   808 // Generate negative 3 element test
       
   809 #define TPARM_TEST3_NEG(ALLOW_REPEAT, EL0, EL1, EL2) TPARM_TEST3(EFalse, ALLOW_REPEAT, EL0, EL1, EL2)
       
   810 
       
   811 	TPARM_TEST2_POSITIVE(EFalse, TAddressParms(0,16,16), TAddressParms(32, 48, 16));
       
   812 	TPARM_TEST2_POSITIVE(ETrue, TAddressParms(0, 16, 16), TAddressParms(0, 16, 16)); // both overlap (repeat allowed)
       
   813 
       
   814 	TPARM_TEST2_NEG(EFalse, TAddressParms(0,16,16), TAddressParms(24, 40, 16)); // second source depends on first destination
       
   815 	TPARM_TEST2_NEG(EFalse, TAddressParms(0,16,16), TAddressParms(16, 0, 16)); // second dest overwrites first source
       
   816 	TPARM_TEST2_NEG(EFalse, TAddressParms(0, 16, 16), TAddressParms(0, 16, 16)); // both overlap (repeat not allowed)
       
   817 	TPARM_TEST2_NEG(ETrue, TAddressParms(0, 16, 16), TAddressParms(0, 20, 16)); // exact repeat allowed, but overlap is only partial
       
   818 	TPARM_TEST2_NEG(ETrue, TAddressParms(0, 16, 16), TAddressParms(32, 16, 16)); // exact repeat allowed, but 2nd overwrites first dest
       
   819 
       
   820 
       
   821 	TPARM_TEST3_POSITIVE(EFalse, TAddressParms(0,16,16), TAddressParms(32, 48, 16), TAddressParms(64, 128, 64)); // no overlaps
       
   822 	TPARM_TEST3_POSITIVE(ETrue, TAddressParms(0, 16, 16), TAddressParms(0, 16, 16), TAddressParms(0, 16, 16)); // all overlap (repeat allowed)
       
   823 	TPARM_TEST3_POSITIVE(EFalse, TAddressParms(0,16,16), TAddressParms(0, 32, 16), TAddressParms(0, 48, 16)); // no overlaps (1 src to 3 dsts)
       
   824 
       
   825 	TPARM_TEST3_NEG(EFalse, TAddressParms(0,16,16), TAddressParms(128, 256, 128), TAddressParms(24, 40, 16)); // 3rd source depends on first destination
       
   826 	TPARM_TEST3_NEG(EFalse, TAddressParms(0,16,16), TAddressParms(128, 256, 128), TAddressParms(16, 0, 16)); // 3rd dest overwrites first source
       
   827 	TPARM_TEST3_NEG(EFalse, TAddressParms(0, 16, 16), TAddressParms(0, 16, 16), TAddressParms(0, 16, 16)); // all overlap (repeat not allowed)
       
   828 	test.Next(_L("CheckBuffers(RArray<TAddressParms>)"));
       
   829 	}
       
   830 
       
   831 void SelfTests()
       
   832 	{
       
   833 	test.Next(_L("Running framework unit tests"));
       
   834 #ifndef __WINS__
       
   835 	// Cannot connect real driver on Emulator - only
       
   836 	// simulator
       
   837 	RDmaSession::SelfTest(EFalse);
       
   838 #endif
       
   839 	RDmaSession::SelfTest(ETrue);
       
   840 	TDmaCapability::SelfTest();
       
   841 	TTestCase::SelfTest();
       
   842 	TTransferIter::SelfTest();
       
   843 	TCallbackRecord::SelfTest();
       
   844 	CDmaBmFragmentation::SelfTest();
       
   845 	TAddrRange::SelfTest();
       
   846 	TAddressParms::SelfTest();
       
   847 	TIsrRequeArgsSet::SelfTest();
       
   848 	RArrayCopyTestL();
       
   849 	RArrayInsertLTest();
       
   850 	TPreTransferIncrBytes::SelfTest();
       
   851 	test.End();
       
   852 	test.Close();
       
   853 	}