1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/mm/mmlibs/mmfw/tsrc/mmfunittest/MidiClnt/TestMidiClientMultiSharedHeap.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,268 @@
1.4 +// Copyright (c) 2006-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 +//
1.18 +
1.19 +
1.20 +#include "TestMidiClientSharedHeap.h"
1.21 +
1.22 +
1.23 +const TInt KMaxPlayers = 24; // easily enough to overflow the chunk if there were one
1.24 +
1.25 +const TInt KNoSharedPlayer = 2;
1.26 +// which of the created players should be given its own heap on mixed style tests
1.27 +// This must always be true: KNoSharedPlayer < KMaxPlayers
1.28 +
1.29 +
1.30 +const TInt KRepeatAmount = 16;
1.31 +// how often CTestStepPlayerSharedHeapRepeatMultiFilePlayer should create and delete players
1.32 +
1.33 +
1.34 +CTestMidiClntMultiSharedHeap::CTestMidiClntMultiSharedHeap(const TDesC& aTestName,const TDesC& aSectName,const TDesC& aKeyName, TBool aMixHeapStyle )
1.35 + : CTestMmfMidiClntStep(aTestName, ETestValid)
1.36 + , iMixHeapStyle( aMixHeapStyle )
1.37 + {
1.38 + iSectName = aSectName;
1.39 + iKeyName = aKeyName;
1.40 + }
1.41 +
1.42 +CTestMidiClntMultiSharedHeap* CTestMidiClntMultiSharedHeap::NewL(const TDesC& aTestName,const TDesC& aSectName,const TDesC& aKeyName, TBool aMixHeapStyle )
1.43 + {
1.44 + CTestMidiClntMultiSharedHeap* self = new(ELeave) CTestMidiClntMultiSharedHeap(aTestName, aSectName, aKeyName, aMixHeapStyle );
1.45 + return self;
1.46 + }
1.47 +
1.48 +TVerdict CTestMidiClntMultiSharedHeap::DoTestStepL()
1.49 + {
1.50 + TPtrC filename;
1.51 + if(!GetStringFromConfig(iSectName,iKeyName,filename))
1.52 + return EInconclusive;
1.53 +
1.54 + INFO_PRINTF2(_L("Check we can create lots of clients - creating %d clients"), KMaxPlayers );
1.55 +
1.56 + // create lots of players
1.57 + RPointerArray<CMidiClientUtility> players;
1.58 +
1.59 + TVerdict ret = EPass;
1.60 +
1.61 + __MM_HEAP_MARK;
1.62 +
1.63 + for( TInt i = 0; i < KMaxPlayers; ++i )
1.64 + {
1.65 + CMidiClientUtility* player = NULL;
1.66 + // create player with shared heap
1.67 +
1.68 + TBool useSharedHeap = ETrue;
1.69 + if( i == KNoSharedPlayer && iMixHeapStyle )
1.70 + {
1.71 + INFO_PRINTF2(_L("MIDI client on iteration %d has own heap."), i );
1.72 + useSharedHeap = EFalse;
1.73 + }
1.74 +
1.75 + TRAPD( err, player = CMidiClientUtility::NewL(*this, EMdaPriorityNormal, EMdaPriorityPreferenceTimeAndQuality, useSharedHeap ) );
1.76 + if( err )
1.77 + {
1.78 + if( err == KErrNoMemory )
1.79 + {
1.80 + INFO_PRINTF2(_L("Could not create player #%d due to lack of memory."), i );
1.81 + ret = EFail;
1.82 + }
1.83 + else
1.84 + {
1.85 + INFO_PRINTF3(_L("Error %d. Could not create player #%d."), err, i );
1.86 + ret = EFail;
1.87 + }
1.88 +
1.89 + delete player;
1.90 + player = NULL;
1.91 + break;
1.92 + }
1.93 + else
1.94 + {
1.95 + if( players.Append( player ) )
1.96 + {
1.97 + // could not add to array
1.98 + delete player;
1.99 + player = NULL;
1.100 + ret = EInconclusive;
1.101 + break;
1.102 + }
1.103 + }
1.104 + }
1.105 +
1.106 + if( (ret == EPass) && (players.Count() > 0) ) // no errors so far
1.107 + {
1.108 + // do fake play
1.109 + TMMFMessageDestinationPckg dummyPckg;
1.110 + TInt dummyFunc = 0; //EDevMidiOff;
1.111 + TBuf8<8> dummyBuff;
1.112 + (players[0])->CustomCommandSyncL(dummyPckg, dummyFunc, dummyBuff, dummyBuff, dummyBuff);
1.113 + (players[0])->OpenFile(filename);
1.114 +
1.115 + // Wait for initialisation callback
1.116 + INFO_PRINTF1(_L("CMidiClientUtility: Opening file"));
1.117 + CActiveScheduler::Start();
1.118 +
1.119 + (players[0])->Play();
1.120 + // wait for playback callback
1.121 + CActiveScheduler::Start();
1.122 +
1.123 + if( iError )
1.124 + {
1.125 + // something went wrong
1.126 + INFO_PRINTF2(_L("Error %d during playback."), iError );
1.127 + ret = EFail;
1.128 + }
1.129 + }
1.130 +
1.131 +
1.132 + // cleanup
1.133 + for( TInt i = 0; i < players.Count(); ++i )
1.134 + {
1.135 + delete players[i];
1.136 + players[i] = NULL;
1.137 + }
1.138 + players.Close();
1.139 +
1.140 + __MM_HEAP_MARKEND;
1.141 +
1.142 +
1.143 + return ret;
1.144 + }
1.145 +
1.146 +
1.147 +// =======================================================================
1.148 +
1.149 +
1.150 +CTestMidiClntRepeatMultiSharedHeap::CTestMidiClntRepeatMultiSharedHeap(const TDesC& aTestName,const TDesC& aSectName,const TDesC& aKeyName, TBool aMixHeapStyle )
1.151 + : CTestMmfMidiClntStep(aTestName, ETestValid)
1.152 + , iMixHeapStyle( aMixHeapStyle )
1.153 + {
1.154 + iSectName = aSectName;
1.155 + iKeyName = aKeyName;
1.156 + iHeapSize = 512 * 1024; // 512k rather than the usual 64k to avoid KErrNoMemory
1.157 + }
1.158 +
1.159 +CTestMidiClntRepeatMultiSharedHeap* CTestMidiClntRepeatMultiSharedHeap::NewL(const TDesC& aTestName,const TDesC& aSectName,const TDesC& aKeyName, TBool aMixHeapStyle )
1.160 + {
1.161 + CTestMidiClntRepeatMultiSharedHeap* self = new(ELeave) CTestMidiClntRepeatMultiSharedHeap(aTestName, aSectName, aKeyName, aMixHeapStyle );
1.162 + return self;
1.163 + }
1.164 +
1.165 +TVerdict CTestMidiClntRepeatMultiSharedHeap::DoTestStepL()
1.166 + {
1.167 + TPtrC filename;
1.168 + if(!GetStringFromConfig(iSectName,iKeyName,filename))
1.169 + return EInconclusive;
1.170 +
1.171 + INFO_PRINTF3(_L("Create and delete %d players %d times"), KMaxPlayers, KRepeatAmount );
1.172 +
1.173 + TVerdict ret = EPass;
1.174 +
1.175 + __MM_HEAP_MARK;
1.176 +
1.177 + for( TInt j = 0; j < KRepeatAmount; ++j )
1.178 + {
1.179 + INFO_PRINTF2(_L("** Starting outter iteration %d."), j );
1.180 +
1.181 + // create lots of players
1.182 + RPointerArray<CMidiClientUtility> players;
1.183 +
1.184 + for( TInt i = 0; i < KMaxPlayers; ++i )
1.185 + {
1.186 + CMidiClientUtility* player = NULL;
1.187 + // create player with shared heap
1.188 +
1.189 + TBool useSharedHeap = ETrue;
1.190 + if( (i == KNoSharedPlayer) && iMixHeapStyle )
1.191 + {
1.192 + INFO_PRINTF2(_L("MIDI client on iteration %d has own heap."), i );
1.193 + useSharedHeap = EFalse;
1.194 + }
1.195 +
1.196 + TRAPD( err, player = CMidiClientUtility::NewL(*this, EMdaPriorityNormal, EMdaPriorityPreferenceTimeAndQuality, useSharedHeap ) );
1.197 + if( err )
1.198 + {
1.199 + if( err == KErrNoMemory )
1.200 + {
1.201 + INFO_PRINTF2(_L("Could not create player #%d due to lack of memory."), i );
1.202 + ret = EFail;
1.203 + }
1.204 + else
1.205 + {
1.206 + INFO_PRINTF3(_L("Error %d. Could not create player #%d."), err, i );
1.207 + ret = EFail;
1.208 + }
1.209 +
1.210 + delete player;
1.211 + player = NULL;
1.212 + break;
1.213 + }
1.214 + else
1.215 + {
1.216 + if( players.Append( player ) )
1.217 + {
1.218 + // could not add to array
1.219 + delete player;
1.220 + player = NULL;
1.221 + ret = EInconclusive;
1.222 + break;
1.223 + }
1.224 + }
1.225 + }
1.226 +
1.227 + if( (ret == EPass) && (players.Count() > 0) ) // no errors so far
1.228 + {
1.229 + // do fake play
1.230 + TMMFMessageDestinationPckg dummyPckg;
1.231 + TInt dummyFunc = 0; //EDevMidiOff;
1.232 + TBuf8<8> dummyBuff;
1.233 + (players[0])->CustomCommandSyncL(dummyPckg, dummyFunc, dummyBuff, dummyBuff, dummyBuff);
1.234 + (players[0])->OpenFile(filename);
1.235 +
1.236 + // Wait for initialisation callback
1.237 + INFO_PRINTF1(_L("CMidiClientUtility: Opening file"));
1.238 + CActiveScheduler::Start();
1.239 +
1.240 + (players[0])->Play();
1.241 + // wait for playback callback
1.242 + CActiveScheduler::Start();
1.243 +
1.244 + if( iError )
1.245 + {
1.246 + // something went wrong
1.247 + INFO_PRINTF2(_L("Error %d during playback."), iError );
1.248 + ret = EFail;
1.249 + }
1.250 + }
1.251 +
1.252 + // cleanup
1.253 + for( TInt i = 0; i < players.Count(); ++i )
1.254 + {
1.255 + delete players[i];
1.256 + players[i] = NULL;
1.257 + }
1.258 + players.Close();
1.259 +
1.260 + if( ret != EPass )
1.261 + {
1.262 + INFO_PRINTF2(_L("Outter iteration %d failed. Stopping."), j);
1.263 + break;
1.264 + }
1.265 +
1.266 + }// end outter loop
1.267 +
1.268 + __MM_HEAP_MARKEND;
1.269 +
1.270 + return ret;
1.271 + }