os/kernelhwsrv/kerneltest/e32test/dma/t_dma.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/kernelhwsrv/kerneltest/e32test/dma/t_dma.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,1004 @@
     1.4 +// Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.5 +// All rights reserved.
     1.6 +// This component and the accompanying materials are made available
     1.7 +// under the terms of the License "Eclipse Public License v1.0"
     1.8 +// which accompanies this distribution, and is available
     1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.10 +//
    1.11 +// Initial Contributors:
    1.12 +// Nokia Corporation - initial contribution.
    1.13 +//
    1.14 +// Contributors:
    1.15 +//
    1.16 +// Description:
    1.17 +// e32test\dma\t_dma.cpp
    1.18 +// Overview:
    1.19 +// Test the DMA channel functionality.
    1.20 +// API Information:
    1.21 +// RBusLogicalChannel, DLogicalChannelBase, DLogicalDevice
    1.22 +// Details:	
    1.23 +// - Load the DMA LDD, create a critical section, an active scheduler and
    1.24 +// a CPeriodic object.
    1.25 +// - Test one shot single buffer transfers: test simple transfer, request 
    1.26 +// reconfiguration and cancelling. Verify results are as expected.
    1.27 +// - Test one shot double buffer transfers: test simple transfer, request 
    1.28 +// reconfiguration and cancelling. Verify results are as expected.
    1.29 +// - Test streaming single buffer transfers: test simple transfer and
    1.30 +// cancelling. Test that framework behaves correctly if one or more DMA
    1.31 +// interrupts are missed. Verify results are as expected.
    1.32 +// - Test streaming double buffer transfers: test simple transfer and
    1.33 +// cancelling. Test that framework behaves correctly if one or more DMA
    1.34 +// interrupts are missed. Verify results are as expected.
    1.35 +// - Test streaming scatter/gather transfers: test simple transfer and
    1.36 +// cancelling. Test that framework behaves correctly if one or more DMA
    1.37 +// interrupts are missed. Verify results are as expected.
    1.38 +// Platforms/Drives/Compatibility:
    1.39 +// Hardware (Automatic).
    1.40 +// Assumptions/Requirement/Pre-requisites:
    1.41 +// Failures and causes:
    1.42 +// Base Port information:
    1.43 +// 
    1.44 +//
    1.45 +
    1.46 +#define __E32TEST_EXTENSION__
    1.47 +#include <e32test.h>
    1.48 +#include "d_dma.h"
    1.49 +#include <e32debug.h>
    1.50 +#include <e32svr.h>
    1.51 +#include <e32def.h>
    1.52 +#include <e32def_private.h>
    1.53 +#include "u32std.h"
    1.54 +
    1.55 +#ifdef __DMASIM__
    1.56 +RTest test(_L("T_DMASIM"));
    1.57 +#else
    1.58 +RTest test(_L("T_DMA"));
    1.59 +#endif
    1.60 +
    1.61 +//////////////////////////////////////////////////////////////////////////////
    1.62 +// Mini-framework for running tests either in a single thread or in
    1.63 +// several concurrent ones.
    1.64 +
    1.65 +RTestDma::TInfo Info;
    1.66 +TBool JitEnabled;
    1.67 +RCriticalSection TheCriticalSection;						// protect following variables
    1.68 +TInt ThreadCount;											// decremented when tester thread dies
    1.69 +CPeriodic* Bipper;											// display dots during tests to detect lock-ups
    1.70 +
    1.71 +// Test macro used inside tester threads
    1.72 +_LIT(KTestFailure, "XTEST");
    1.73 +static void TestPanic(TInt aLine, TUint32 a1, TUint32 a2, TUint32 a3)
    1.74 +	{
    1.75 +	RDebug::Printf("Line %d test failed a1=%08x a2=%08x a3=%08x", aLine, a1, a2, a3);
    1.76 +	RThread().Panic(KTestFailure, aLine);
    1.77 +	}
    1.78 +#define XTEST(e)				if (!(e)) TestPanic(__LINE__, 0, 0, 0)
    1.79 +#define XTEST1(e,a1)			if (!(e)) TestPanic(__LINE__, (a1), 0, 0)
    1.80 +#define XTEST2(e,a1,a2)			if (!(e)) TestPanic(__LINE__, (a1), (a2), 0)
    1.81 +#define XTEST3(e,a1,a2,a3)		if (!(e)) TestPanic(__LINE__, (a1), (a2), (a3))
    1.82 +
    1.83 +
    1.84 +/**
    1.85 +Specifies a DMA test
    1.86 +@note Have not inherited from CBase so that implicit copy ctors are used
    1.87 +*/
    1.88 +class CTest
    1.89 +	{
    1.90 +public:
    1.91 +	typedef void (*TTestFunction)(RTestDma aChannel, TInt aMaxFragment, TInt aFragmentSize);
    1.92 +
    1.93 +	CTest(TTestFunction aFn, TInt aMaxIter)
    1.94 +		:iTestFn(aFn), iChannelId(0), iMaxIter(aMaxIter)
    1.95 +		{}
    1.96 +
    1.97 +	virtual ~CTest()
    1.98 +		{}
    1.99 +
   1.100 +	TInt RunTest();
   1.101 +
   1.102 +	virtual TBool OpenChannel(TInt aDesCount, TInt aMaxFragmentSize=0);
   1.103 +
   1.104 +	virtual void AnnounceTest(TDes& aDes)
   1.105 +		{aDes.AppendFormat(_L("Channel Id %d, iMaxIter %d"), iChannelId, iMaxIter);}
   1.106 +	virtual void ReportState(TDes& aDes)
   1.107 +		{aDes.AppendFormat(_L("Channel Id %d, iCurIter %d"), iChannelId, iCurIter);}
   1.108 +
   1.109 +
   1.110 +	void SetChannelId(TUint32 aChannelId)
   1.111 +		{iChannelId = aChannelId;}
   1.112 +
   1.113 +	TInt MaxIter() const {return iMaxIter;}
   1.114 +	TInt CurIter() const {return iCurIter;}
   1.115 +
   1.116 +	/**
   1.117 +	@return A copy of this test
   1.118 +	*/	
   1.119 +	virtual	CTest* Clone() const =0;
   1.120 +
   1.121 +protected:
   1.122 +	TInt virtual DoRunTest() =0;
   1.123 +
   1.124 +	const TTestFunction iTestFn;
   1.125 +	TUint32 iChannelId;
   1.126 +	const TInt iMaxIter;
   1.127 +	TInt iCurIter;
   1.128 +	RTestDma iChannel;
   1.129 +	};	
   1.130 +
   1.131 +/**
   1.132 +Specifies a DMA test where the maximum fragmentation is
   1.133 +explicitly limited. This tests that requests are split
   1.134 +in to the number of fragments expected.
   1.135 +
   1.136 +This test also requires that physically contiguous buffers
   1.137 +are used. For this reason the product of iMaxFragment and
   1.138 +iMaxFragmentSize should be kept small
   1.139 +*/
   1.140 +class CFragmentationTest : public CTest
   1.141 +	{
   1.142 +public:
   1.143 +	CFragmentationTest(TTestFunction aFn, TInt aMaxIter, TInt aMaxFragment, TInt aMaxFragmentSize)
   1.144 +		: CTest(aFn, aMaxIter), iMaxFragment(aMaxFragment), iMaxFragmentSize(aMaxFragmentSize), iCurFragment(0)
   1.145 +	{}
   1.146 +
   1.147 +	TInt virtual DoRunTest();
   1.148 +
   1.149 +	virtual void AnnounceTest(TDes& aDes)
   1.150 +		{
   1.151 +		aDes.AppendFormat(_L("CFragmentationTest: Frag count = [1..%d], Max Frag Size = 0x%08x bytes: "), iMaxFragment, iMaxFragmentSize);
   1.152 +		CTest::AnnounceTest(aDes);
   1.153 +		}
   1.154 +
   1.155 +	virtual void ReportState(TDes& aDes)
   1.156 +		{
   1.157 +		aDes.AppendFormat(_L("CFragmentationTest: Current Fragment %d: "), iCurFragment);
   1.158 +		CTest::ReportState(aDes);
   1.159 +		}
   1.160 +
   1.161 +	CTest* Clone() const
   1.162 +		{return new CFragmentationTest(*this);}
   1.163 +
   1.164 +private:
   1.165 +	const TInt iMaxFragment;
   1.166 +	TInt iMaxFragmentSize;
   1.167 +	TInt iCurFragment;
   1.168 +	};
   1.169 +
   1.170 +/**
   1.171 +Specifies a DMA test where the maximum fragment size is
   1.172 +not limited - and we do not care how many fragments are
   1.173 +used
   1.174 +
   1.175 +- This checks that transfers work correctly with the DMAC's
   1.176 +default fragment size
   1.177 +*/
   1.178 +class CDefaultFragTest : public CTest
   1.179 +	{
   1.180 +public:
   1.181 +	CDefaultFragTest(TTestFunction aFn, TInt aMaxIter, TUint aTotalTransferSize)
   1.182 +		: CTest(aFn, aMaxIter), iTotalTransferSize(aTotalTransferSize)
   1.183 +		{}
   1.184 +
   1.185 +	TInt virtual DoRunTest();
   1.186 +
   1.187 +	virtual void AnnounceTest(TDes& aDes)
   1.188 +		{
   1.189 +		aDes.AppendFormat(_L("CDefaultFragTest: Transfer = 0x%08x bytes: "), iTotalTransferSize);
   1.190 +		CTest::AnnounceTest(aDes);
   1.191 +		}
   1.192 +
   1.193 +	CTest* Clone() const
   1.194 +		{return new CDefaultFragTest(*this);}
   1.195 +
   1.196 +	const TInt iTotalTransferSize;
   1.197 +	};
   1.198 +
   1.199 +
   1.200 +//
   1.201 +// Active object used to create a tester thread, log on to it and
   1.202 +// interpret its exit status.
   1.203 +//
   1.204 +class CTesterThread : public CActive
   1.205 +	{
   1.206 +public:
   1.207 +	CTesterThread(TInt aIdx, CTest* aTest);
   1.208 +	~CTesterThread()
   1.209 +		{
   1.210 +		delete iTest;
   1.211 +		}
   1.212 +private:
   1.213 +	static TInt ThreadFunction(TAny* aSelf);
   1.214 +	TInt StartThread();
   1.215 +	// from CActive
   1.216 +	virtual void DoCancel();
   1.217 +	virtual void RunL();
   1.218 +private:
   1.219 +	RThread iThread;
   1.220 +	CTest* iTest;
   1.221 +	};
   1.222 +
   1.223 +
   1.224 +/**
   1.225 +Run the test for iMaxIter iterations
   1.226 +*/
   1.227 +TInt CTest::RunTest()
   1.228 +	{
   1.229 +	TInt r = KErrNone;
   1.230 +	for (iCurIter=0; iCurIter<iMaxIter; ++iCurIter)
   1.231 +		{
   1.232 +		r =  DoRunTest();
   1.233 +		if(KErrNone != r)
   1.234 +			break;
   1.235 +		}
   1.236 +	return r;
   1.237 +	}
   1.238 +
   1.239 +/**
   1.240 +Open iChannel
   1.241 +
   1.242 +@pre iChannel is not open
   1.243 +@return
   1.244 +   - KErrNotSupported Channel does not exist on DMAC
   1.245 +   - KErrNone Success
   1.246 +   - KErrInUse
   1.247 +*/
   1.248 +TInt CTest::OpenChannel(TInt aDesCount, TInt aMaxFragmentSize)
   1.249 +		{
   1.250 +		ASSERT(!iChannel.Handle());
   1.251 +		const TInt r = iChannel.Open(iChannelId, aDesCount, aMaxFragmentSize);
   1.252 +		if (r == KErrNotSupported)
   1.253 +			return r;
   1.254 +		XTEST1(KErrNone == r || KErrInUse == r, r);
   1.255 +		
   1.256 +		if(KErrInUse == r)
   1.257 +			{
   1.258 +			// Channel is in use.
   1.259 +			RDebug::Printf("\nDMA Channel %d is in use",iChannelId);
   1.260 +			if(0 == iCurIter)
   1.261 +				{
   1.262 +				// Terminate thread by returning this error code KErrInUse.
   1.263 +				return r;
   1.264 +				}
   1.265 +			else
   1.266 +				{
   1.267 +#ifdef __WINS__
   1.268 +#pragma warning( disable : 4127 ) // warning C4127: conditional expression is constant
   1.269 +#endif // __WINS__
   1.270 +				XTEST1(EFalse, iCurIter);
   1.271 +#ifdef __WINS__
   1.272 +#pragma warning( default : 4127 ) // warning C4127: conditional expression is constant
   1.273 +#endif // __WINS__
   1.274 +				}
   1.275 +			}
   1.276 +		return r;
   1.277 +		}
   1.278 +
   1.279 +
   1.280 +
   1.281 +// Spawn thread. Will auto-delete when thread exits.
   1.282 +CTesterThread::CTesterThread(TInt aIdx, CTest* aTest)
   1.283 +	: CActive(EPriorityStandard), iTest(aTest)
   1.284 +	{
   1.285 +	CActiveScheduler::Add(this);
   1.286 +	TBuf<16> name;
   1.287 +	name = _L("TESTER-");
   1.288 +	name.AppendNum(aIdx);
   1.289 +	test(iThread.Create(name, ThreadFunction, 0x1000, NULL, this) == KErrNone);
   1.290 +	iThread.SetPriority(EPriorityLess);
   1.291 +	iThread.Logon(iStatus);
   1.292 +	SetActive();
   1.293 +	iThread.Resume();
   1.294 +	}
   1.295 +
   1.296 +
   1.297 +TInt CTesterThread::ThreadFunction(TAny* aSelf)
   1.298 +	{
   1.299 +	CTesterThread* self = (CTesterThread*)aSelf;
   1.300 +	return self->StartThread();
   1.301 +	}
   1.302 +
   1.303 +TInt CTesterThread::StartThread()
   1.304 +	{
   1.305 +	return iTest->RunTest();
   1.306 +	}
   1.307 +
   1.308 +
   1.309 +
   1.310 +TInt CFragmentationTest::DoRunTest()
   1.311 +	{
   1.312 +	// In case iMaxFragmentSize was larger than suppported (we need to know what fragment
   1.313 +	// size will actually be used)
   1.314 +	iMaxFragmentSize = Min(iMaxFragmentSize, Info.iMaxTransferSize);
   1.315 +
   1.316 +	// Open channel with enough descriptors for 3 open DMA
   1.317 +	// requests (see TestStreaming).
   1.318 +	TInt r = OpenChannel(3* iMaxFragment, iMaxFragmentSize);
   1.319 +	if(r != KErrNone)
   1.320 +		return r;
   1.321 +
   1.322 +	//we are controlling fragment size, so we know how
   1.323 +	//many to expect
   1.324 +	for (iCurFragment=1; iCurFragment<=iMaxFragment; iCurFragment*=2)
   1.325 +		{
   1.326 +		const TInt size = iCurFragment * ( iMaxFragmentSize & ~Info.iMemAlignMask);
   1.327 +		iTestFn(iChannel, iCurFragment, size);
   1.328 +		}
   1.329 +	iChannel.Close();
   1.330 +	return KErrNone;
   1.331 +	}
   1.332 +
   1.333 +TInt CDefaultFragTest::DoRunTest()
   1.334 +	{
   1.335 +	// +1 so we don't underestimate maxFragount for inexact division
   1.336 +	const TUint maxFragCount = (iTotalTransferSize / Info.iMaxTransferSize) +1;
   1.337 +
   1.338 +	// Open channel with enough descriptors for 3 open DMA
   1.339 +	// requests (see TestStreaming).
   1.340 +	const TUint descriptorCount = 3 * maxFragCount;
   1.341 +
   1.342 +	TInt r = OpenChannel(descriptorCount);
   1.343 +	if(r != KErrNone)
   1.344 +		return r;
   1.345 +
   1.346 +	iTestFn(iChannel, 0, iTotalTransferSize);
   1.347 +	
   1.348 +	iChannel.Close();
   1.349 +	return KErrNone;
   1.350 +	}
   1.351 +
   1.352 +
   1.353 +// Called when thread completed.
   1.354 +void CTesterThread::RunL()
   1.355 +	{
   1.356 +	TExitType et = iThread.ExitType();
   1.357 +	TInt er = iThread.ExitReason();
   1.358 +	TExitCategoryName ec = iThread.ExitCategory();
   1.359 +	TName name = iThread.Name();
   1.360 +	CLOSE_AND_WAIT(iThread);
   1.361 +
   1.362 +	switch (et)
   1.363 +		{
   1.364 +	case EExitKill:
   1.365 +		// nothing to do
   1.366 +		break;
   1.367 +	case EExitPanic:
   1.368 +			{
   1.369 +			User::SetJustInTime(JitEnabled);
   1.370 +			TBuf<128> buffer;
   1.371 +			iTest->ReportState(buffer);
   1.372 +			test.Printf(_L("Tester Thread Panic: %S: Test: %S\n"),
   1.373 +						&name, &buffer);
   1.374 +			if (ec.Match(KTestFailure) == 0)
   1.375 +				test.Panic(_L("Test failure line %d"), er);
   1.376 +			else
   1.377 +				test.Panic(_L("Unexpected panic: %S-%d"), &ec, er);
   1.378 +			break;
   1.379 +			}
   1.380 +	default:
   1.381 +		test.Panic(_L("Invalid thread exit type"));
   1.382 +		}
   1.383 +
   1.384 +	TheCriticalSection.Wait();
   1.385 +	if (--ThreadCount == 0)
   1.386 +		{
   1.387 +		Bipper->Cancel();
   1.388 +		test.Console()->Printf(_L("\n"));
   1.389 +		CActiveScheduler::Stop();
   1.390 +		}
   1.391 +	TheCriticalSection.Signal();
   1.392 +
   1.393 +	// We commit suicide as the alternative (being deleted by
   1.394 +	// RunTest()) implies keeping a list of all instances in
   1.395 +	// RunTest().
   1.396 +	delete this;
   1.397 +	}
   1.398 +
   1.399 +
   1.400 +void CTesterThread::DoCancel()
   1.401 +	{
   1.402 +	test.Panic(_L("CTesterThread::DoCancel called"));
   1.403 +	}
   1.404 +
   1.405 +
   1.406 +static TInt Bip(TAny*)
   1.407 +	{
   1.408 +	test.Console()->Printf(_L("."));
   1.409 +	return 0;
   1.410 +	}
   1.411 +
   1.412 +
   1.413 +// Execute provided test object in one or more tester threads.
   1.414 +void RunTest(TUint32 aChannelIds[], TInt aMaxThread, CTest* aTest)			 
   1.415 +	{
   1.416 +	test_NotNull(aTest);
   1.417 +
   1.418 +	if (aMaxThread == 0)
   1.419 +		{
   1.420 +		delete aTest;
   1.421 +		test.Printf(_L("transfer mode not supported - skipped\n"));
   1.422 +		return;
   1.423 +		}
   1.424 +
   1.425 +	test.Printf(_L("Using %d thread(s)\n"), aMaxThread);
   1.426 +
   1.427 +	// We don't want JIT debugging here because the tester threads may panic
   1.428 +	JitEnabled = User::JustInTime();
   1.429 +	User::SetJustInTime(EFalse);
   1.430 +
   1.431 +	// must be set before spawning threads to avoid premature active scheduler stop
   1.432 +	ThreadCount = aMaxThread;
   1.433 +
   1.434 +	TBuf<128> buffer;
   1.435 +	for (TInt i=0; i<aMaxThread; ++i)
   1.436 +		{
   1.437 +		//each CTesterThread needs its own CTest object
   1.438 +		CTest* dmaTest = aTest->Clone();
   1.439 +		test_NotNull(dmaTest);
   1.440 +
   1.441 +		dmaTest->SetChannelId(aChannelIds[i]);
   1.442 +
   1.443 +		buffer.Zero();
   1.444 +		dmaTest->AnnounceTest(buffer);
   1.445 +		test.Printf(_L("Thread %d: %S\n"), i, &buffer);
   1.446 +		
   1.447 +		test(new CTesterThread(i, dmaTest) != NULL);
   1.448 +		dmaTest = NULL; //ownership transferred to CTesterThread
   1.449 +		}
   1.450 +	//the orginal isn't needed
   1.451 +	delete aTest;
   1.452 +	aTest = NULL;
   1.453 +
   1.454 +	const TTimeIntervalMicroSeconds32 KPeriod = 1000000;	// 1s
   1.455 +	Bipper->Start(KPeriod, KPeriod, Bip);
   1.456 +
   1.457 +	CActiveScheduler::Start();
   1.458 +
   1.459 +	User::SetJustInTime(JitEnabled);
   1.460 +	}
   1.461 +
   1.462 +
   1.463 +inline void RunSbTest(TInt aMaxThread, CTest* aTest)
   1.464 +	{
   1.465 +	RunTest(Info.iSbChannels, Min(aMaxThread,Info.iMaxSbChannels), aTest);
   1.466 +	}
   1.467 +
   1.468 +inline void RunDbTest(TInt aMaxThread, CTest* aTest)
   1.469 +	{
   1.470 +	RunTest(Info.iDbChannels, Min(aMaxThread,Info.iMaxDbChannels), aTest);
   1.471 +	}
   1.472 +
   1.473 +inline void RunSgTest(TInt aMaxThread, CTest* aTest)
   1.474 +	{
   1.475 +	RunTest(Info.iSgChannels, Min(aMaxThread,Info.iMaxSgChannels), aTest);
   1.476 +	}
   1.477 +//////////////////////////////////////////////////////////////////////////////
   1.478 +
   1.479 +static void GetChannelInfo()
   1.480 +	{
   1.481 +	RTestDma channel;
   1.482 +	test(channel.GetInfo(Info) == KErrNone);
   1.483 +	test(Info.iMaxSbChannels>0 || Info.iMaxDbChannels>0 || Info.iMaxSgChannels>0);
   1.484 +	}
   1.485 +
   1.486 +
   1.487 +static void TestOneShot(RTestDma aChannel, TInt aFragmentCount, TInt aSize)
   1.488 +	{
   1.489 +	const TInt KRequest = 0;
   1.490 +	const TInt KSrcBuf = 0;
   1.491 +	const TInt KDestBuf1 = 1;
   1.492 +	const TInt KDestBuf2 = 2;
   1.493 +
   1.494 +	TInt r = aChannel.AllocBuffer(KSrcBuf, aSize);
   1.495 +	XTEST2(r == KErrNone, r, aSize);
   1.496 +	aChannel.FillBuffer(KSrcBuf, 'A');
   1.497 +	r = aChannel.AllocBuffer(KDestBuf1, aSize);
   1.498 +	XTEST2(r == KErrNone, r, aSize);
   1.499 +	aChannel.FillBuffer(KDestBuf1, '\0');
   1.500 +	r = aChannel.AllocBuffer(KDestBuf2, aSize);
   1.501 +	XTEST2(r == KErrNone, r, aSize);
   1.502 +	aChannel.FillBuffer(KDestBuf2, '\0');
   1.503 +
   1.504 +	// Test simple transfer
   1.505 +	TRequestStatus rs;
   1.506 +	r = aChannel.Fragment(KRequest, KSrcBuf, KDestBuf1, aSize, &rs);
   1.507 +	XTEST2(r == KErrNone, r, aSize);
   1.508 +	test(aChannel.FragmentCheck(KRequest, aFragmentCount));
   1.509 +	r = aChannel.Execute(_L8("Q0"));
   1.510 +	XTEST1(r == KErrNone, r);
   1.511 +	User::WaitForRequest(rs);
   1.512 +	XTEST1(rs == KErrNone, rs.Int());
   1.513 +	XTEST(aChannel.CheckBuffer(KDestBuf1, 'A'));
   1.514 +
   1.515 +	// Test request reconfiguration.
   1.516 +	aChannel.FillBuffer(KDestBuf1, '\0');
   1.517 +	r = aChannel.Fragment(KRequest, KSrcBuf, KDestBuf2, aSize, &rs);
   1.518 +	XTEST2(r == KErrNone, r, aSize);
   1.519 +	test(aChannel.FragmentCheck(KRequest, aFragmentCount));
   1.520 +	r = aChannel.Execute(_L8("Q0"));
   1.521 +	XTEST1(r == KErrNone, r);
   1.522 +	User::WaitForRequest(rs);
   1.523 +	XTEST1(rs == KErrNone, rs.Int());
   1.524 +	XTEST(aChannel.CheckBuffer(KDestBuf1, '\0'));			// previous dest unchanged?
   1.525 +	XTEST(aChannel.CheckBuffer(KDestBuf2, 'A'));
   1.526 +
   1.527 +	// Test cancelling
   1.528 +	aChannel.FillBuffer(KDestBuf1, '\0');
   1.529 +	r = aChannel.Fragment(KRequest, KSrcBuf, KDestBuf1, aSize);
   1.530 +	XTEST2(r == KErrNone, r, aSize);
   1.531 +	test(aChannel.FragmentCheck(KRequest, aFragmentCount));
   1.532 +	r = aChannel.Execute(_L8("Q0C"));
   1.533 +	XTEST1(r == KErrNone, r);
   1.534 +	// Part of the destination buffer should be unchanged if the
   1.535 +	// cancel occured before the transfer completed.
   1.536 +#ifdef __DMASIM__
   1.537 +	// At least part of the last destination buffer should be
   1.538 +	// unchanged if cancel occured before the transfer completed.
   1.539 +	// Assert only on WINS as real DMACs are too fast.
   1.540 +	XTEST(! aChannel.CheckBuffer(KDestBuf2, 'C'));
   1.541 +#endif
   1.542 +
   1.543 +	// Perform another transfer to ensure cancel operation let the
   1.544 +	// framework in a consistent state.
   1.545 +	aChannel.FillBuffer(KDestBuf1, '\0');
   1.546 +	r = aChannel.Fragment(KRequest, KSrcBuf, KDestBuf1, aSize, &rs);
   1.547 +	XTEST2(r == KErrNone, r, aSize);
   1.548 +	test(aChannel.FragmentCheck(KRequest, aFragmentCount));
   1.549 +	r = aChannel.Execute(_L8("Q0"));
   1.550 +	XTEST1(r == KErrNone, r);
   1.551 +	User::WaitForRequest(rs);
   1.552 +	XTEST1(rs == KErrNone, rs.Int());
   1.553 +	XTEST(aChannel.CheckBuffer(KDestBuf1, 'A'));
   1.554 +
   1.555 +	//
   1.556 +	// Test failure if the underlying DMA kernel extension allows it.
   1.557 +	//
   1.558 +	// As long as only "CancelAllFragments" is supported, it's okay to
   1.559 +	// always fail on the first fragment.
   1.560 +	//
   1.561 +
   1.562 +	if (aChannel.FailNext(1) == KErrNone)
   1.563 +		{
   1.564 +		aChannel.FillBuffer(KDestBuf1, '\0');
   1.565 +		r = aChannel.Fragment(KRequest, KSrcBuf, KDestBuf1, aSize, &rs);
   1.566 +		XTEST2(r == KErrNone, r, aSize);
   1.567 +		test(aChannel.FragmentCheck(KRequest, aFragmentCount));
   1.568 +		r = aChannel.Execute(_L8("Q0"));
   1.569 +		XTEST1(r == KErrNone, r);
   1.570 +		User::WaitForRequest(rs);
   1.571 +		XTEST1(rs != KErrNone, rs.Int());
   1.572 +		XTEST(! aChannel.CheckBuffer(KDestBuf1, 'A'));
   1.573 +		r = aChannel.Execute(_L8("C"));
   1.574 +		XTEST1(r == KErrNone, r);
   1.575 +
   1.576 +		// Perform another transfer to ensure we are still in a
   1.577 +		// consistent state.
   1.578 +		aChannel.FillBuffer(KDestBuf1, '\0');
   1.579 +		r = aChannel.Fragment(KRequest, KSrcBuf, KDestBuf1, aSize, &rs);
   1.580 +		XTEST2(r == KErrNone, r, aSize);
   1.581 +		test(aChannel.FragmentCheck(KRequest, aFragmentCount));
   1.582 +		r = aChannel.Execute(_L8("Q0"));
   1.583 +		XTEST1(r == KErrNone, r);
   1.584 +		User::WaitForRequest(rs);
   1.585 +		XTEST1(rs == KErrNone, rs.Int());
   1.586 +		XTEST(aChannel.CheckBuffer(KDestBuf1, 'A'));
   1.587 +		}
   1.588 +
   1.589 +	aChannel.FreeAllBuffers();
   1.590 +	}
   1.591 +
   1.592 +
   1.593 +static void TestStreaming(RTestDma aChannel, TInt aFragmentCount, TInt aSize)
   1.594 +	{
   1.595 +	const TInt KRequest0 = 0;
   1.596 +	const TInt KRequest1 = 1;
   1.597 +	const TInt KRequest2 = 2;
   1.598 +	const TInt KSrcBuf0 = 0;
   1.599 +	const TInt KSrcBuf1 = 1;
   1.600 +	const TInt KSrcBuf2 = 2;
   1.601 +	const TInt KDestBuf0 = 3;
   1.602 +	const TInt KDestBuf1 = 4;
   1.603 +	const TInt KDestBuf2 = 5;
   1.604 +
   1.605 +	//
   1.606 +	// Allocate and initialise source buffers
   1.607 +	//
   1.608 +
   1.609 +	TInt r = aChannel.AllocBuffer(KSrcBuf0, aSize);
   1.610 +	XTEST2(r == KErrNone, r, aSize);
   1.611 +	aChannel.FillBuffer(KSrcBuf0, 'A');
   1.612 +
   1.613 +	r = aChannel.AllocBuffer(KSrcBuf1, aSize);
   1.614 +	XTEST2(r == KErrNone, r, aSize);
   1.615 +	aChannel.FillBuffer(KSrcBuf1, 'B');
   1.616 +
   1.617 +	r = aChannel.AllocBuffer(KSrcBuf2, aSize);
   1.618 +	XTEST2(r == KErrNone, r, aSize);
   1.619 +	aChannel.FillBuffer(KSrcBuf2, 'C');
   1.620 +
   1.621 +	//
   1.622 +	// Allocate destination buffers
   1.623 +	//
   1.624 +
   1.625 +	r = aChannel.AllocBuffer(KDestBuf0, aSize);
   1.626 +	XTEST2(r == KErrNone, r, aSize);
   1.627 +	r = aChannel.AllocBuffer(KDestBuf1, aSize);
   1.628 +	XTEST2(r == KErrNone, r, aSize);
   1.629 +	r = aChannel.AllocBuffer(KDestBuf2, aSize);
   1.630 +	XTEST2(r == KErrNone, r, aSize);
   1.631 +
   1.632 +	//
   1.633 +	// Test simple transfer.
   1.634 +	// (no need to test for request reconfiguration afterwards because
   1.635 +	// this was exercised in the one-shot test case)
   1.636 +	//
   1.637 +
   1.638 +	TRequestStatus rs0;
   1.639 +	r = aChannel.Fragment(KRequest0, KSrcBuf0, KDestBuf0, aSize, &rs0);
   1.640 +	XTEST2(r == KErrNone, r, aSize);
   1.641 +	test(aChannel.FragmentCheck(KRequest0, aFragmentCount));
   1.642 +	TRequestStatus rs1;
   1.643 + 	r = aChannel.Fragment(KRequest1, KSrcBuf1, KDestBuf1, aSize, &rs1);
   1.644 +	XTEST2(r == KErrNone, r, aSize);
   1.645 +	test(aChannel.FragmentCheck(KRequest1, aFragmentCount));
   1.646 +	TRequestStatus rs2;
   1.647 +	r = aChannel.Fragment(KRequest2, KSrcBuf2, KDestBuf2, aSize, &rs2);
   1.648 +	XTEST2(r == KErrNone, r, aSize);
   1.649 +	test(aChannel.FragmentCheck(KRequest2, aFragmentCount));
   1.650 +
   1.651 +	r = aChannel.Execute(_L8("Q0Q1Q2"));
   1.652 +	XTEST1(r == KErrNone, r);
   1.653 +	User::WaitForRequest(rs0);
   1.654 +	XTEST1(rs0 == KErrNone, rs0.Int());
   1.655 +	XTEST(aChannel.CheckBuffer(KDestBuf0, 'A'));
   1.656 +	User::WaitForRequest(rs1);
   1.657 +	XTEST1(rs1 == KErrNone, rs1.Int());
   1.658 +	XTEST(aChannel.CheckBuffer(KDestBuf1, 'B'));
   1.659 +	User::WaitForRequest(rs2);
   1.660 +	XTEST1(rs2 == KErrNone, rs2.Int());
   1.661 +	XTEST(aChannel.CheckBuffer(KDestBuf2, 'C'));
   1.662 +
   1.663 +	//
   1.664 +	// Test cancel
   1.665 +	//
   1.666 +
   1.667 +	aChannel.FillBuffer(KDestBuf0, '\0');
   1.668 +	aChannel.FillBuffer(KDestBuf1, '\0');
   1.669 +	aChannel.FillBuffer(KDestBuf2, '\0');
   1.670 +
   1.671 +	r = aChannel.Fragment(KRequest0, KSrcBuf0, KDestBuf0, aSize);
   1.672 +	XTEST2(r == KErrNone, r, aSize);
   1.673 +	test(aChannel.FragmentCheck(KRequest0, aFragmentCount));
   1.674 + 	r = aChannel.Fragment(KRequest1, KSrcBuf1, KDestBuf1, aSize);
   1.675 +	XTEST2(r == KErrNone, r, aSize);
   1.676 +	test(aChannel.FragmentCheck(KRequest1, aFragmentCount));
   1.677 +	r = aChannel.Fragment(KRequest2, KSrcBuf2, KDestBuf2, aSize);
   1.678 +	XTEST2(r == KErrNone, r, aSize);
   1.679 +	test(aChannel.FragmentCheck(KRequest2, aFragmentCount));
   1.680 +
   1.681 +	r = aChannel.Execute(_L8("Q0Q1Q2C"));
   1.682 +	XTEST1(r == KErrNone, r);
   1.683 +#ifdef __DMASIM__
   1.684 +	// At least part of the last destination buffer should be
   1.685 +	// unchanged if cancel occured before the transfer completed.
   1.686 +	// Assert only on WINS as real DMACs are too fast.
   1.687 +	XTEST(! aChannel.CheckBuffer(KDestBuf2, 'C'));
   1.688 +#endif
   1.689 +
   1.690 +	//
   1.691 +	// Perform another transfer to ensure cancel operation let the
   1.692 +	// framework in a consistent state.
   1.693 +	//
   1.694 +
   1.695 +	aChannel.FillBuffer(KDestBuf0, '\0');
   1.696 +	aChannel.FillBuffer(KDestBuf1, '\0');
   1.697 +	aChannel.FillBuffer(KDestBuf2, '\0');
   1.698 +	// Reconfigure last request to enable transfer completion notification
   1.699 +	r = aChannel.Fragment(KRequest2, KSrcBuf2, KDestBuf2, aSize, &rs2);
   1.700 +	XTEST2(r == KErrNone, r, aSize);
   1.701 +	test(aChannel.FragmentCheck(KRequest2, aFragmentCount));
   1.702 +	r = aChannel.Execute(_L8("Q0Q1Q2"));
   1.703 +	XTEST1(r == KErrNone, r);
   1.704 +	User::WaitForRequest(rs2);
   1.705 +	XTEST1(rs2 == KErrNone, rs2.Int());
   1.706 +	XTEST(aChannel.CheckBuffer(KDestBuf0, 'A'));
   1.707 +	XTEST(aChannel.CheckBuffer(KDestBuf1, 'B'));
   1.708 +	XTEST(aChannel.CheckBuffer(KDestBuf2, 'C'));
   1.709 +
   1.710 +	//
   1.711 +	// Test for proper implementation of UnlinkHwDes() in the PSL.
   1.712 +	//
   1.713 +
   1.714 +	aChannel.FillBuffer(KDestBuf0, '\0');
   1.715 +	aChannel.FillBuffer(KDestBuf1, '\0');
   1.716 +	aChannel.FillBuffer(KDestBuf2, '\0');
   1.717 +	// Reconfigure last request to enable transfer completion notification
   1.718 +	r = aChannel.Fragment(KRequest2, KSrcBuf2, KDestBuf2, aSize, &rs2);
   1.719 +	XTEST2(r == KErrNone, r, aSize);
   1.720 +	test(aChannel.FragmentCheck(KRequest2, aFragmentCount));
   1.721 +	// Queue first request (Q0)
   1.722 +	r = aChannel.Execute(_L8("Q0"));
   1.723 +	// Wait a second, so next request will be queued on its own
   1.724 +	// (instead of being appended to the previous one)
   1.725 +	User::After(1000000);
   1.726 +	// Queue third request (Q2)
   1.727 +	r = aChannel.Execute(_L8("Q2"));
   1.728 +	XTEST1(r == KErrNone, r);
   1.729 +	User::WaitForRequest(rs2);
   1.730 +	XTEST1(rs2 == KErrNone, rs2.Int());
   1.731 +	XTEST(aChannel.CheckBuffer(KDestBuf0, 'A'));
   1.732 +	// KDestBuf1 should have been left untouched!
   1.733 +	// If we find all B's in KDestBuf1, that means the last descriptor of the
   1.734 +	// first request (Q0) wasn't properly unlinked and still points to the Q1
   1.735 +	// descriptor chain from the previous run.
   1.736 +	XTEST(aChannel.CheckBuffer(KDestBuf1, '\0'));
   1.737 +	XTEST(aChannel.CheckBuffer(KDestBuf2, 'C'));
   1.738 +
   1.739 +	//
   1.740 +	// Test failure if the underlying DMA kernel extension allows it.
   1.741 +	//
   1.742 +	// As long as only "CancelAllFragments" is supported, it's okay to
   1.743 +	// always fail on the first fragment.
   1.744 +	//
   1.745 +
   1.746 +	if (aChannel.FailNext(1) == KErrNone)
   1.747 +		{
   1.748 +		aChannel.FillBuffer(KDestBuf0, '\0');
   1.749 +		aChannel.FillBuffer(KDestBuf1, '\0');
   1.750 +		aChannel.FillBuffer(KDestBuf2, '\0');
   1.751 +		XTEST(aChannel.Fragment(KRequest0, KSrcBuf0, KDestBuf0, aSize, &rs0) == KErrNone);
   1.752 +		test(aChannel.FragmentCheck(KRequest0, aFragmentCount));
   1.753 +		XTEST(aChannel.Fragment(KRequest1, KSrcBuf1, KDestBuf1, aSize) == KErrNone);
   1.754 +		test(aChannel.FragmentCheck(KRequest1, aFragmentCount));
   1.755 +		XTEST(aChannel.Fragment(KRequest2, KSrcBuf2, KDestBuf2, aSize) == KErrNone);
   1.756 +		test(aChannel.FragmentCheck(KRequest2, aFragmentCount));
   1.757 +		XTEST(aChannel.Execute(_L8("Q0Q1Q2")) == KErrNone);
   1.758 +		User::WaitForRequest(rs0);
   1.759 +		XTEST(rs0 != KErrNone);
   1.760 +		XTEST(! aChannel.CheckBuffer(KDestBuf0, 'A'));
   1.761 +		XTEST(! aChannel.CheckBuffer(KDestBuf1, 'B'));
   1.762 +		XTEST(! aChannel.CheckBuffer(KDestBuf2, 'C'));
   1.763 +		XTEST(aChannel.Execute(_L8("C")) == KErrNone);
   1.764 +
   1.765 +		// Transfer again to ensure cancel cleaned-up correctly
   1.766 +		aChannel.FillBuffer(KDestBuf0, '\0');
   1.767 +		aChannel.FillBuffer(KDestBuf1, '\0');
   1.768 +		aChannel.FillBuffer(KDestBuf2, '\0');
   1.769 +		XTEST(aChannel.Fragment(KRequest0, KSrcBuf0, KDestBuf0, aSize, &rs0) == KErrNone);
   1.770 +		test(aChannel.FragmentCheck(KRequest0, aFragmentCount));
   1.771 +		XTEST(aChannel.Fragment(KRequest1, KSrcBuf1, KDestBuf1, aSize, &rs1) == KErrNone);
   1.772 +		test(aChannel.FragmentCheck(KRequest1, aFragmentCount));
   1.773 +		XTEST(aChannel.Fragment(KRequest2, KSrcBuf2, KDestBuf2, aSize, &rs2) == KErrNone);
   1.774 +		test(aChannel.FragmentCheck(KRequest2, aFragmentCount));
   1.775 +		XTEST(aChannel.Execute(_L8("Q0Q1Q2")) == KErrNone);
   1.776 +		User::WaitForRequest(rs0);
   1.777 +		XTEST(rs0 == KErrNone);
   1.778 +		User::WaitForRequest(rs1);
   1.779 +		XTEST(rs1 == KErrNone);
   1.780 +		User::WaitForRequest(rs2);
   1.781 +		XTEST(rs2 == KErrNone);
   1.782 +		XTEST(aChannel.CheckBuffer(KDestBuf0, 'A'));
   1.783 +		XTEST(aChannel.CheckBuffer(KDestBuf1, 'B'));
   1.784 +		XTEST(aChannel.CheckBuffer(KDestBuf2, 'C'));
   1.785 +		}
   1.786 +
   1.787 +	//
   1.788 +	// Test that framework behaves correctly if one or more DMA interrupts are
   1.789 +	// missed.
   1.790 +	//
   1.791 +
   1.792 +	if (aChannel.MissNextInterrupts(1) == KErrNone)
   1.793 +		{
   1.794 +		aChannel.FillBuffer(KDestBuf0, '\0');
   1.795 +		aChannel.FillBuffer(KDestBuf1, '\0');
   1.796 +		aChannel.FillBuffer(KDestBuf2, '\0');
   1.797 +		XTEST(aChannel.Fragment(KRequest0, KSrcBuf0, KDestBuf0, aSize, &rs0) == KErrNone);
   1.798 +		test(aChannel.FragmentCheck(KRequest0, aFragmentCount));
   1.799 +		XTEST(aChannel.Fragment(KRequest1, KSrcBuf1, KDestBuf1, aSize, &rs1) == KErrNone);
   1.800 +		test(aChannel.FragmentCheck(KRequest1, aFragmentCount));
   1.801 +		XTEST(aChannel.Fragment(KRequest2, KSrcBuf2, KDestBuf2, aSize, &rs2) == KErrNone);
   1.802 +		test(aChannel.FragmentCheck(KRequest2, aFragmentCount));
   1.803 +		XTEST(aChannel.Execute(_L8("Q0Q1Q2")) == KErrNone);
   1.804 +		User::WaitForRequest(rs0);
   1.805 +		XTEST(rs0 == KErrNone);
   1.806 +		User::WaitForRequest(rs1);
   1.807 +		XTEST(rs1 == KErrNone);
   1.808 +		User::WaitForRequest(rs2);
   1.809 +		XTEST(rs2 == KErrNone);
   1.810 +		XTEST(aChannel.CheckBuffer(KDestBuf0, 'A'));
   1.811 +		XTEST(aChannel.CheckBuffer(KDestBuf1, 'B'));
   1.812 +		XTEST(aChannel.CheckBuffer(KDestBuf2, 'C'));
   1.813 +		}
   1.814 +
   1.815 +	if (aChannel.MissNextInterrupts(2) == KErrNone)
   1.816 +		{
   1.817 +		aChannel.FillBuffer(KDestBuf0, '\0');
   1.818 +		aChannel.FillBuffer(KDestBuf1, '\0');
   1.819 +		aChannel.FillBuffer(KDestBuf2, '\0');
   1.820 +		XTEST(aChannel.Fragment(KRequest0, KSrcBuf0, KDestBuf0, aSize, &rs0) == KErrNone);
   1.821 +		test(aChannel.FragmentCheck(KRequest0, aFragmentCount));
   1.822 +		XTEST(aChannel.Fragment(KRequest1, KSrcBuf1, KDestBuf1, aSize, &rs1) == KErrNone);
   1.823 +		test(aChannel.FragmentCheck(KRequest1, aFragmentCount));
   1.824 +		XTEST(aChannel.Fragment(KRequest2, KSrcBuf2, KDestBuf2, aSize, &rs2) == KErrNone);
   1.825 +		test(aChannel.FragmentCheck(KRequest2, aFragmentCount));
   1.826 +		XTEST(aChannel.Execute(_L8("Q0Q1Q2")) == KErrNone);
   1.827 +		User::WaitForRequest(rs0);
   1.828 +		XTEST(rs0 == KErrNone);
   1.829 +		User::WaitForRequest(rs1);
   1.830 +		XTEST(rs1 == KErrNone);
   1.831 +		User::WaitForRequest(rs2);
   1.832 +		XTEST(rs2 == KErrNone);
   1.833 +		XTEST(aChannel.CheckBuffer(KDestBuf0, 'A'));
   1.834 +		XTEST(aChannel.CheckBuffer(KDestBuf1, 'B'));
   1.835 +		XTEST(aChannel.CheckBuffer(KDestBuf2, 'C'));
   1.836 +		}
   1.837 +
   1.838 +	aChannel.FreeAllBuffers();
   1.839 +	}
   1.840 +
   1.841 +
   1.842 +static TBool ParseCmdLine(TBool& aCrashDbg, TInt& aMaxfrag, TInt& aMaxIter, TInt& aMaxchannel, TInt& aMaxFragSize)
   1.843 +//
   1.844 +// The command line. Syntax is:
   1.845 +//
   1.846 +//     t_dma [enableCrashDebugger [aMaxFrag [aMaxIter [aMaxchannel [aMaxFragSize]]]]]
   1.847 +//
   1.848 +	{
   1.849 +	TBuf<256> cmdline;
   1.850 +	User::CommandLine(cmdline);
   1.851 +	TLex lex(cmdline);
   1.852 +
   1.853 +	lex.SkipSpace();
   1.854 +
   1.855 +	if (lex.Eos())
   1.856 +		return ETrue;
   1.857 +	if (lex.Val(aCrashDbg) != KErrNone)
   1.858 +		return EFalse;
   1.859 +	lex.SkipSpace();
   1.860 +	if (lex.Eos())
   1.861 +		return ETrue;
   1.862 +	if (lex.Val(aMaxfrag) != KErrNone)
   1.863 +		return EFalse;
   1.864 +	lex.SkipSpace();
   1.865 +	if (lex.Eos())
   1.866 +		return ETrue;
   1.867 +	if (lex.Val(aMaxIter) != KErrNone)
   1.868 +		return EFalse;
   1.869 +	lex.SkipSpace();
   1.870 +	if (lex.Eos())
   1.871 +		return ETrue;
   1.872 +	if (lex.Val(aMaxchannel) != KErrNone)
   1.873 +		return EFalse;
   1.874 +	lex.SkipSpace();
   1.875 +	if (lex.Eos())
   1.876 +		return ETrue;
   1.877 +
   1.878 +	return lex.Val(aMaxFragSize) == KErrNone;
   1.879 +	}
   1.880 +
   1.881 +
   1.882 +TInt E32Main()
   1.883 +	{
   1.884 +	test.Title();
   1.885 +
   1.886 +	test.Start(_L("Parsing command-line"));
   1.887 +	// Default values when run with empty command-line
   1.888 +	TInt maxfrag = 16; // 5 fragments needed to exercise fully double-buffering state machine
   1.889 +	TInt maxIter = 3;
   1.890 +	TInt maxchannel = KMaxTInt;
   1.891 +	TBool crashDbg = EFalse;
   1.892 +	TInt maxFragSize = 0x4000; //16k
   1.893 +
   1.894 +	(void) ParseCmdLine(crashDbg, maxfrag, maxIter, maxchannel, maxFragSize);
   1.895 +
   1.896 +	if (crashDbg)
   1.897 +		{
   1.898 +		User::SetCritical(User::ESystemCritical);
   1.899 +		User::SetProcessCritical(User::ESystemCritical);
   1.900 +		}
   1.901 +
   1.902 +
   1.903 +	TInt r;
   1.904 +#if defined(__DMASIM__) && defined(__WINS__)
   1.905 +	test.Next(_L("Loading DMA simulator"));
   1.906 +	r = User::LoadLogicalDevice(_L("DMASIM.DLL"));
   1.907 +	test(r == KErrNone || r == KErrAlreadyExists);
   1.908 +#endif
   1.909 +
   1.910 +	test.Next(_L("Loading test LDD"));
   1.911 +#ifdef __DMASIM__
   1.912 +	r = User::LoadLogicalDevice(_L("D_DMASIM"));
   1.913 +	test(r == KErrNone || r == KErrAlreadyExists);
   1.914 +#else
   1.915 +	//load either the original test ldd, d_dma.ldd,
   1.916 +	//or d_dma_compat.ldd - an ldd providing the same interface
   1.917 +	//but linked against the new MHA dma framework
   1.918 +	_LIT(KDma, "D_DMA.LDD");
   1.919 +	r = User::LoadLogicalDevice(KDma);
   1.920 +	const TBool dmaPresent = (r == KErrNone || r == KErrAlreadyExists);
   1.921 +
   1.922 +	_LIT(KDmaCompat, "D_DMA_COMPAT.LDD");
   1.923 +	r = User::LoadLogicalDevice(KDmaCompat);
   1.924 +	const TBool dmaCompatPresent = (r == KErrNone || r == KErrAlreadyExists);
   1.925 +
   1.926 +	if (!(dmaPresent || dmaCompatPresent))
   1.927 +		{
   1.928 +		test.Printf(_L("DMA test driver not found - test skipped\n"));
   1.929 +		return 0;
   1.930 +		}
   1.931 +	else if (dmaPresent && !dmaCompatPresent)
   1.932 +		{
   1.933 +		test.Printf(_L("Loaded %S\n"), &KDma);
   1.934 +		}
   1.935 +	else if (!dmaPresent && dmaCompatPresent)
   1.936 +		{
   1.937 +		test.Printf(_L("Loaded %S\n"), &KDmaCompat);
   1.938 +		}
   1.939 +	else
   1.940 +		{
   1.941 +		test.Printf(_L("The ROM contains %S and %S - only one should be present\n"), &KDma, &KDmaCompat);
   1.942 +		test(EFalse);
   1.943 +		}
   1.944 +#endif
   1.945 +
   1.946 +	// Turn off evil lazy dll unloading
   1.947 +	RLoader l;
   1.948 +	test(l.Connect()==KErrNone);
   1.949 +	test(l.CancelLazyDllUnload()==KErrNone);
   1.950 +	l.Close();
   1.951 +
   1.952 +	__UHEAP_MARK;
   1.953 +	__KHEAP_MARK;
   1.954 +
   1.955 +	test.Next(_L("Creating critical section"));
   1.956 +	test(TheCriticalSection.CreateLocal() == KErrNone);
   1.957 +
   1.958 +	test.Next(_L("Creating active scheduler"));
   1.959 +	CActiveScheduler* pS = new CActiveScheduler;
   1.960 +	test(pS != NULL);
   1.961 +	CActiveScheduler::Install(pS);
   1.962 +
   1.963 +	test.Next(_L("Creating bipper"));
   1.964 +	Bipper = CPeriodic::New(CActive::EPriorityStandard);
   1.965 +	test(Bipper != NULL);
   1.966 +
   1.967 +	test.Next(_L("Getting channel info"));
   1.968 +	GetChannelInfo();
   1.969 +
   1.970 +	// Size for the single transfer test
   1.971 +	TInt totalTransferSize = 64 * KKilo;
   1.972 +
   1.973 +	test.Next(_L("Testing one shot single buffer transfer"));
   1.974 +	RunSbTest(maxchannel, new CFragmentationTest(TestOneShot, maxIter, maxfrag, maxFragSize));
   1.975 +	RunSbTest(maxchannel, new CDefaultFragTest(TestOneShot, maxIter, totalTransferSize));
   1.976 +
   1.977 +	test.Next(_L("Testing one shot double buffer transfer"));
   1.978 +	RunDbTest(maxchannel, new CFragmentationTest(TestOneShot, maxIter, maxfrag, maxFragSize));
   1.979 +	RunDbTest(maxchannel, new CDefaultFragTest(TestOneShot, maxIter, totalTransferSize));
   1.980 +
   1.981 +	test.Next(_L("Testing one shot scatter/gather transfer"));
   1.982 +	RunSgTest(maxchannel, new CFragmentationTest(TestOneShot, maxIter, maxfrag, maxFragSize));
   1.983 +	RunSgTest(maxchannel, new CDefaultFragTest(TestOneShot, maxIter, totalTransferSize));
   1.984 +
   1.985 +	test.Next(_L("Testing streaming single buffer transfer"));
   1.986 +	RunSbTest(maxchannel, new CFragmentationTest(TestStreaming, maxIter, maxfrag, maxFragSize));
   1.987 +	RunSbTest(maxchannel, new CDefaultFragTest(TestStreaming, maxIter, totalTransferSize));
   1.988 +
   1.989 +	test.Next(_L("Testing streaming double buffer transfer"));
   1.990 +	RunDbTest(maxchannel, new CFragmentationTest(TestStreaming, maxIter, maxfrag, maxFragSize));
   1.991 +	RunDbTest(maxchannel, new CDefaultFragTest(TestStreaming, maxIter, totalTransferSize));
   1.992 +
   1.993 +	test.Next(_L("Testing streaming scatter/gather transfer"));
   1.994 +	RunSgTest(maxchannel, new CFragmentationTest(TestStreaming, maxIter, maxfrag, maxFragSize));
   1.995 +	RunSgTest(maxchannel, new CDefaultFragTest(TestStreaming, maxIter, totalTransferSize));
   1.996 +
   1.997 +	delete pS;
   1.998 +	delete Bipper;
   1.999 +	TheCriticalSection.Close();
  1.1000 +
  1.1001 +	UserSvr::HalFunction(EHalGroupKernel, EKernelHalSupervisorBarrier, (TAny*)5000, 0);
  1.1002 +	__KHEAP_MARKEND;
  1.1003 +	__UHEAP_MARKEND;
  1.1004 +
  1.1005 +	test.End();
  1.1006 +	return 0;
  1.1007 +	}