os/kernelhwsrv/kerneltest/e32test/dmav2/dma_api_tests.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/kernelhwsrv/kerneltest/e32test/dmav2/dma_api_tests.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,188 @@
     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 "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\dma_api_tests.cpp
    1.18 +// 
    1.19 +// Overview:
    1.20 +//  This file contains API tests for the new DMA framework
    1.21 +//
    1.22 +
    1.23 +#define __E32TEST_EXTENSION__
    1.24 +#include "d_dma2.h"
    1.25 +#include "u32std.h"
    1.26 +#include "t_dma2.h"
    1.27 +#include "cap_reqs.h"
    1.28 +
    1.29 +#include <e32test.h>
    1.30 +#include <e32debug.h>
    1.31 +#include <e32svr.h>
    1.32 +
    1.33 +static RTest test(_L("DMA Test Framework API"));
    1.34 +//----------------------------------------------------------------------------------------------
    1.35 +//! @SYMTestCaseID      KBASE-DMA-2564
    1.36 +//! @SYMTestType        CIT
    1.37 +//! @SYMPREQ            REQ
    1.38 +//! @SYMTestCaseDesc    This test checks the correct behaviour of Open API in the new DMA framework
    1.39 +//!
    1.40 +//! @SYMTestActions     
    1.41 +//!						1.  Open a DMA channel
    1.42 +//!						2.	Verify that channel is really open.
    1.43 +//!
    1.44 +//! @SYMTestExpectedResults 
    1.45 +//!						1.  DMA channel opens and KErrNone returned
    1.46 +//!						2.  Call to ChannelIsOpened() return as ETrue.
    1.47 +//!
    1.48 +//! @SYMTestPriority        High
    1.49 +//! @SYMTestStatus          Implemented
    1.50 +//----------------------------------------------------------------------------------------------
    1.51 +void test_open_api()
    1.52 +{
    1.53 +	//TO DO : Expose TInt Open(const SCreateInfo& aInfo, TDmaChannel*& aChannel)
    1.54 +	//TO DO : Implement more test cases
    1.55 +	test.Start(_L("*** Testing Open() API  ***"));
    1.56 +
    1.57 +	test.Next(_L("Open session"));
    1.58 +	RDmaSession session;
    1.59 +	TInt r = session.Open();
    1.60 +	test_KErrNone(r);
    1.61 +
    1.62 +	TUint channelCookie_open_api=0;
    1.63 +	
    1.64 +	test.Next(_L("Open DMA Channel"));
    1.65 +	channelCookie_open_api=0;
    1.66 +	r = session.ChannelOpen(16, channelCookie_open_api);
    1.67 +	test.Printf(_L("cookie recieved = 0x%08x\n"), channelCookie_open_api);
    1.68 +	test_KErrNone(r);
    1.69 +
    1.70 +	//Check if channel is open
    1.71 +	// test.Printf(_L("Verify that the specified DMA channel is opened\n"));	
    1.72 +	// TBool channelOpened;
    1.73 +	// TBool channelNotOpened = EFalse;
    1.74 +	// r = session.ChannelIsOpened(channelCookie_open_api,  channelOpened);
    1.75 +	// test_KErrNone(r);	
    1.76 + 	// TEST_ASSERT(channelOpened != channelNotOpened)
    1.77 +	
    1.78 +	//close channel
    1.79 +	test.Next(_L("Channel close"));
    1.80 +	r = session.ChannelClose(channelCookie_open_api);
    1.81 +	test_KErrNone(r);
    1.82 +	
    1.83 +	RTest::CloseHandleAndWaitForDestruction(session);
    1.84 +	test.End();
    1.85 +}
    1.86 +
    1.87 +//----------------------------------------------------------------------------------------------
    1.88 +//! @SYMTestCaseID      KBASE-DMA-2568
    1.89 +//! @SYMTestType        CIT
    1.90 +//! @SYMPREQ            REQ
    1.91 +//! @SYMTestCaseDesc    This test checks the correct behaviour of Close API in the new DMA framework
    1.92 +//!
    1.93 +//! @SYMTestActions     
    1.94 +//!						1.  Open a DMA channel
    1.95 +//!						2.	Open DMA Channel again
    1.96 +//!						3	Close the DMA channel.
    1.97 +//!						4	Open DMA channel to verify that the DMA channel closed.
    1.98 +//!						5.	Open DMA channel again.
    1.99 +//!						6.	Queue a request on the channel.
   1.100 +//!						7.	Close DMA channel while request is still queued on it.
   1.101 +//!
   1.102 +//! @SYMTestExpectedResults 
   1.103 +//!						1.  DMA channel opens and KErrNone returned.
   1.104 +//!						2.	DMA Framework returns KErrInUse as channel is already open.					
   1.105 +//!						3.	DMA channel closes and KErrNone returned.
   1.106 +//!						4.	DMA channel opens and KErrNone returned.
   1.107 +//!						5.	DMA Framework returns KErrInUse as channel is already open.
   1.108 +//!						6.	DMA request queued and KErrNone returned.
   1.109 +//!						7.	DMA channel closes and DMA framework flags an error.
   1.110 +//!							
   1.111 +//!
   1.112 +//! @SYMTestPriority        High
   1.113 +//! @SYMTestStatus          Implemented
   1.114 +//----------------------------------------------------------------------------------------------
   1.115 +void test_close_api()
   1.116 +{
   1.117 +	test.Start(_L("*** Testing Close() API  ***"));
   1.118 +	
   1.119 +	test.Next(_L("Open session"));
   1.120 +	RDmaSession session;
   1.121 +	TInt r = session.Open();
   1.122 +	test_KErrNone(r);
   1.123 +
   1.124 +	const TInt size = 64 * KKilo;
   1.125 +	TUint reqCookieNewStyle_close_api=0;	
   1.126 +	TUint channelCookie_close_api=0;
   1.127 +	
   1.128 +	test.Next(_L("Open a single DMA channel"));
   1.129 +	r = session.ChannelOpen(16, channelCookie_close_api);
   1.130 +	test.Printf(_L("cookie recieved = 0x%08x\n"), channelCookie_close_api);
   1.131 +	test_KErrNone(r);
   1.132 +
   1.133 +	// test.Next(_L("Open DMA channel again"));
   1.134 +	// TUint channelCookie_close_api_1=0;
   1.135 +	// r = session.ChannelOpen(16, channelCookie_close_api_1);
   1.136 +	// test.Printf(_L("Verify that DMA channel is already opened\n"));
   1.137 +	// test_Equal(KErrInUse,r); 
   1.138 +
   1.139 +	test.Next(_L("Close the DMA channel"));
   1.140 +	r = session.ChannelClose(channelCookie_close_api);
   1.141 +	test_KErrNone(r);
   1.142 +
   1.143 +	test.Next(_L("Open DMA channel again"));
   1.144 +	r = session.ChannelOpen(16, channelCookie_close_api);
   1.145 +	test.Printf(_L("Verify that DMA channel was closed\n"));
   1.146 +	test_KErrNone(r); 
   1.147 +
   1.148 +	//Fails if a request is created and cancel
   1.149 +	test.Next(_L("Queue a request on the channel"));
   1.150 +  	r = session.RequestCreateNew(channelCookie_close_api, reqCookieNewStyle_close_api); //Create Dma request (with new-style callback)
   1.151 +  	test.Printf(_L("cookie recieved for open channel = 0x%08x\n"), reqCookieNewStyle_close_api);
   1.152 +  	test_KErrNone(r);
   1.153 +  
   1.154 +  	TDmaTransferArgs transferArgs_close_api;
   1.155 +  	transferArgs_close_api.iSrcConfig.iAddr = 0;
   1.156 +  	transferArgs_close_api.iDstConfig.iAddr = size;
   1.157 +  	transferArgs_close_api.iSrcConfig.iFlags = KDmaMemAddr;
   1.158 +  	transferArgs_close_api.iDstConfig.iFlags = KDmaMemAddr;
   1.159 +  	transferArgs_close_api.iTransferCount = size;
   1.160 +  	r = session.FragmentRequest(reqCookieNewStyle_close_api, transferArgs_close_api);
   1.161 +  	test_KErrNone(r);
   1.162 +  	
   1.163 +  	test.Next(_L("Queue DMA Request"));
   1.164 +  	TCallbackRecord record_close_api;
   1.165 +  	r = session.QueueRequest(reqCookieNewStyle_close_api, &record_close_api);
   1.166 +  	test_KErrNone(r);
   1.167 +	
   1.168 +	test.Next(_L("Destroy Dma request"));
   1.169 +	r = session.RequestDestroy(reqCookieNewStyle_close_api);
   1.170 +	test_KErrNone(r);
   1.171 +
   1.172 +	test.Next(_L("Close the DMA channel"));
   1.173 +	r = session.ChannelClose(channelCookie_close_api);
   1.174 +	test_KErrNone(r);
   1.175 +
   1.176 +	test.End();
   1.177 +	RTest::CloseHandleAndWaitForDestruction(session);
   1.178 +}
   1.179 +
   1.180 +void RDmaSession::ApiTest()
   1.181 +	{
   1.182 +    test_open_api();     // Verify that Open() opens a DMA channel
   1.183 +    test_close_api();    // Verify that Close() closes a DMA channel
   1.184 +	}
   1.185 +
   1.186 +void ApiTests()
   1.187 +	{
   1.188 +	test.Next(_L("Running framework API tests"));
   1.189 +	RDmaSession::ApiTest();	
   1.190 +	test.Close();
   1.191 +	}