kerneltest/e32test/dmav2/t_dma2.cpp
changeset 247 d8d70de2bd36
parent 139 95f71bcdcdb7
--- a/kerneltest/e32test/dmav2/t_dma2.cpp	Tue Jul 06 15:50:07 2010 +0300
+++ b/kerneltest/e32test/dmav2/t_dma2.cpp	Wed Aug 18 11:08:29 2010 +0300
@@ -131,6 +131,10 @@
 	if(iDmaSession.Handle() == KNullHandle)
 		{
 		TInt r = iDmaSession.Open();
+		if(KErrNone != r)
+			{
+			RDebug::Printf("CDmaTest::OpenDmaSession = %d\n", r);
+			}
 		TEST_ASSERT(r == KErrNone);
 		r = iDmaSession.OpenSharedChunk(iChunk);
 		TEST_ASSERT(r == KErrNone);
@@ -700,6 +704,159 @@
 	}
 
 //////////////////////////////////////////////////////////////////////
+//	CPauseResumeNegTest
+//
+//	-Open DMA Channel
+//	-Pause and Resume DMA channel
+//	-Check that KErrNotSupported is returned
+//	-Close DMA Channel
+//////////////////////////////////////////////////////////////////////
+CPauseResumeNegTest::~CPauseResumeNegTest()
+	{
+	}
+
+void CPauseResumeNegTest::RunTest()
+	{
+	OpenDmaSession();
+
+	//Open a single DMA channel for a transfer
+	OpenChannel();
+
+	RDebug::Printf("Resume unpaused idle channel");
+	TInt r = iDmaSession.ChannelResume(iChannelSessionCookie);
+	TEST_ASSERT(KErrNotSupported == r);
+
+	RDebug::Printf("Pause idle channel");
+	r = iDmaSession.ChannelPause(iChannelSessionCookie);
+	TEST_ASSERT(KErrNotSupported == r);
+
+	RDebug::Printf("Pause paused idle Channel");
+	r = iDmaSession.ChannelPause(iChannelSessionCookie);
+	TEST_ASSERT(KErrNotSupported == r);
+
+	RDebug::Printf("Resume paused idle channel");
+	r = iDmaSession.ChannelResume(iChannelSessionCookie);
+	TEST_ASSERT(KErrNotSupported == r);
+
+	CloseChannel();
+	CloseDmaSession();
+	}
+
+void CPauseResumeNegTest::PrintTestType() const
+	{
+	RDebug::RawPrint(_L("Pause and Resume API Test - Negative Test"));
+	}
+
+//////////////////////////////////////////////////////////////////////
+//	CLinkChannelTest
+//
+//	-Open DMA Channel
+//	-Link and Unlink DMA channel
+//	-Check that KErrNotSupported is returned
+//	-Close DMA Channel
+//
+//////////////////////////////////////////////////////////////////////
+CLinkChannelTest::~CLinkChannelTest()
+	{
+	}
+
+void CLinkChannelTest::RunTest()
+	{
+	OpenDmaSession();
+
+	//Open a single DMA channel for a transfer
+	OpenChannel();
+
+	RDebug::Printf("Linking DMA channels");
+	TInt r = iDmaSession.ChannelLinking(iChannelSessionCookie);
+	TEST_ASSERT(KErrNotSupported == r);
+
+	RDebug::Printf("Unlinking DMA channels");
+	r = iDmaSession.ChannelUnLinking(iChannelSessionCookie);
+	TEST_ASSERT(KErrNotSupported == r);
+
+	CloseChannel();
+	CloseDmaSession();
+	}
+
+void CLinkChannelTest::PrintTestType() const
+	{
+	RDebug::RawPrint(_L("Channel Linking API Test - Negative Test"));
+	}
+
+//////////////////////////////////////////////////////////////////////
+//	CElementCountingTest
+//
+//	-Open DMA Channel
+//	-Create Request
+//	-Fragment and Make calls to Element Counting APIs
+//  -Check that TotalNumDstElementsTransferred() and TotalNumSrcElementsTransferred()
+//	 return non zero values
+//  -Check that KErrNone(from test driver) returned for other API calls
+//	-Queue Request 
+//	-Close DMA Channel
+//////////////////////////////////////////////////////////////////////
+CElementCountingTest::~CElementCountingTest()
+	{
+	}
+
+void CElementCountingTest::RunTest()
+	{
+	OpenDmaSession();
+	PreTransferSetup();
+
+	//Open a single DMA channel for a transfer
+	OpenChannel();
+	
+	//Setup a DMA request and Fragment the request.
+	RDebug::Printf("Create and Fragment DMA Request");
+	CreateDmaRequest();
+	Fragment();
+
+	//Enable src/dst counting
+	RDebug::Printf("Enable DstElementCounting");
+	TInt r = iDmaSession.RequestEnableDstElementCounting(iRequestSessionCookie);
+	TEST_ASSERT(KErrNone == r);
+
+	RDebug::Printf("Enable SrcElementCounting");
+	r = iDmaSession.RequestEnableSrcElementCounting(iRequestSessionCookie);
+	TEST_ASSERT(KErrNone == r);
+
+	//Queue request
+	RDebug::Printf("Queue DMA Request");
+	Queue();
+
+	//Disable src/dst counting
+	RDebug::Printf("Disable DstElementCounting");
+	r = iDmaSession.RequestDisableDstElementCounting(iRequestSessionCookie);
+	TEST_ASSERT(KErrNone == r);
+
+	RDebug::Printf("Disable SrcElementCounting");
+	r = iDmaSession.RequestDisableSrcElementCounting(iRequestSessionCookie);
+	TEST_ASSERT(KErrNone == r);
+
+	//check total src/dst elements transferred
+	RDebug::Printf("Get Total Number of DstElementsTransferred");
+	r = iDmaSession.RequestTotalNumDstElementsTransferred(iRequestSessionCookie);
+	TEST_ASSERT(r >= 0);
+
+	RDebug::Printf("Get Total Number of SrcElementsTransferred");
+	r = iDmaSession.RequestTotalNumSrcElementsTransferred(iRequestSessionCookie);
+	TEST_ASSERT(r >= 0);
+
+	FreeRequest();
+	CloseChannel();
+
+	PostTransferCheck();
+	CloseDmaSession();
+	}
+
+void CElementCountingTest::PrintTestType() const
+	{
+	RDebug::RawPrint(_L("Element Counting Tests"));
+	}
+
+//////////////////////////////////////////////////////////////////////
 // COpenCloseTest
 //////////////////////////////////////////////////////////////////////
 COpenCloseTest::~COpenCloseTest()
@@ -1999,8 +2156,8 @@
 	case EEndiannessConversion:
 	case EGraphicsOps:
 	case ERepeatingTransfers:
-	case EChannelLinking:
-		TEST_FAULT;
+	case EChannelLinking:	
+		return aChannelCaps.iChannelLinking == (TBool)iValue;
 	case EHwDescriptors:
 		return aChannelCaps.iHwDescriptors == (TBool)iValue;
 	case ESrcDstAsymmetry:
@@ -2502,13 +2659,81 @@
 		testRunner.AddTestCases(TestArray);//Add all test cases
 	}
 
-	
 	test.Next(_L("call TTestRunner::RunTests()\n"));
 	testRunner.RunTests();
 
 	test.End();
 	}
 
+
+struct TSimTest
+	{
+	TUint iPslId;
+	TBool iFragment;
+	};
+
+const TSimTest KSimTests[] =
+	{
+		{0, EFalse},
+		{1, EFalse},
+		{2, ETrue},
+		{3, ETrue},
+	};
+
+const TInt KSimTestsCount = ARRAY_LENGTH(KSimTests);
+
+void RunSimDMATests()
+	{
+	test.Start(_L("Run simulated DMAC tests\n"));
+
+	test.Next(_L("Open session"));
+	RDmaSession session;
+	TInt r = session.OpenSim();
+	test_KErrNone(r);
+
+	for(TInt i=0; i<KSimTestsCount; i++)
+		{
+		TUint pslId = KSimTests[i].iPslId;
+		TBool doFrag = KSimTests[i].iFragment;
+
+		test.Start(_L("Open channel"));
+		TUint channelCookie=0;
+		r = session.ChannelOpen(pslId, channelCookie);
+		test.Printf(_L("Open channel %d, cookie recived = 0x%08x\n"), pslId, channelCookie);
+		test_KErrNone(r);
+
+		test.Next(_L("Create Dma request"));
+
+		TUint reqCookie=0;
+		r = session.RequestCreate(channelCookie, reqCookie);
+		test.Printf(_L("cookie recived = 0x%08x\n"), reqCookie );
+		test_KErrNone(r);
+
+		if(doFrag)
+			{
+			test.Next(_L("Fragment request"));
+			const TInt size = 128 * KKilo;
+			TDmaTransferArgs transferArgs(0, size, size, KDmaMemAddr);
+			r = session.FragmentRequest(reqCookie, transferArgs);
+			test_KErrNone(r);
+			}
+
+		test.Next(_L("Destroy Dma request"));
+		r = session.RequestDestroy(reqCookie);
+		test_KErrNone(r);
+
+		test.Next(_L("Channel close"));
+		r = session.ChannelClose(channelCookie);
+		test_KErrNone(r);
+		test.End();
+		}
+
+	test.Next(_L("Close session"));
+	RTest::CloseHandleAndWaitForDestruction(session);
+
+	test.End();
+	}
+
 TInt E32Main()
 	{
 	__UHEAP_MARK;
@@ -2531,7 +2756,7 @@
 		{
 		User::Panic(_L("DMA test run memory failure"), KErrNoMemory);
 		}
-	
+
 	if (gHelpRequested)
 		{
 		PrintUsage();
@@ -2551,8 +2776,7 @@
 
 	if (!(dma2Loaded || dma2CompatLoaded))
 		{
-		test.Printf(_L("DMA test driver not found - test skipped\n"));
-		return 0;
+		test.Printf(_L("Hardware DMA test driver not found - will run tests on simulated DMAC only\n"));
 		}
 	else if (dma2Loaded && !dma2CompatLoaded)
 		{
@@ -2567,6 +2791,23 @@
 		test.Printf(_L("The ROM contains %S and %S - only one should be present\n"), &KDma, &KDma2Compat);
 		TEST_FAULT;
 		}
+
+	const TBool dmaHwPresent = (dma2Loaded || dma2CompatLoaded);
+
+	_LIT(KDma2Sim, "D_DMA2_SIM.LDD");
+
+	r = User::LoadLogicalDevice(KDma2Sim);
+	const TBool dma2SimLoaded = ((r == KErrNone) || (r == KErrAlreadyExists));
+	if (dma2SimLoaded)
+		{
+		test.Printf(_L("Loaded %S\n"), &KDma2Sim);
+		}
+	else
+		{
+		test.Printf(_L("Failed to load %S, r=%d\n"), &KDma2Sim, r);
+		test(EFalse);
+		}
+
 	// Turn off evil lazy dll unloading
 	RLoader l;
 	test(l.Connect()==KErrNone);
@@ -2576,11 +2817,15 @@
 	__KHEAP_MARK;
 
 	if (gSelfTest) //Run self tests if specified on command line
-	{
-	SelfTests(); 	
-	}
-
-	RunDMATests();
+		{
+		SelfTests();
+		}
+
+	RunSimDMATests();
+	if (dmaHwPresent)
+		{
+		RunDMATests();
+		}
 
 	// Wait for the supervisor thread to run and perform asynchronous
 	// cleanup, so that kernel heap space will be freed
@@ -2588,8 +2833,14 @@
 	test_KErrNone(r);
 	__KHEAP_MARKEND;
 
-	r = User::FreeLogicalDevice(KTestDmaLddName);
+	if(dmaHwPresent)
+		{
+		r = User::FreeLogicalDevice(KTestDmaLddNameHw);
+		test_KErrNone(r);
+		}
+	r = User::FreeLogicalDevice(KTestDmaLddNameSim);
 	test_KErrNone(r);
+
 	test.End();
 	test.Close();