os/graphics/graphicsresourceservices/graphicsresourceimplementation/test/src/tgraphicsresourceinternalsecondprocesstesthandler.cpp
Update contrib.
1 // Copyright (c) 2009-2010 Nokia Corporation and/or its subsidiary(-ies).
2 // All rights reserved.
3 // This component and the accompanying materials are made available
4 // under the terms of "Eclipse Public License v1.0"
5 // which accompanies this distribution, and is available
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
21 #include "tgraphicsresourceinternalsecondprocesstesthandler.h"
22 #include "tgraphicsresourcemultiprocessthread.h"
23 #include "tgraphicsresourceinternalsecondprocessenums.h"
24 #include "tsgdrawablegeneric.h"
25 #include "tsgimagegeneric.h"
27 CTSgResInternalSecondProcessTestHandler* CTSgResInternalSecondProcessTestHandler::NewLC()
29 CTSgResInternalSecondProcessTestHandler* self = new(ELeave) CTSgResInternalSecondProcessTestHandler();
30 CleanupStack::PushL(self);
35 Runs the specified test
37 @param TInt The test case to be run
39 TInt CTSgResInternalSecondProcessTestHandler::RunTestCaseL(const TSgResIntTestInfo& aInfo)
41 RDebug::Printf("CTSgResSecondProcessTestHandler::RunTestCaseL(%i)", aInfo.iTestCase);
43 switch (aInfo.iTestCase)
45 case ESgResIntDriverMemoryLeak:
46 TestDriverMemoryLeakL();
48 case ESgResIntDrawableOOM:
49 result = TestDrawableOOM();
51 case ESgResIntImageOOM:
52 result = TestImageOOM(aInfo);
54 case ESgResIntInitializeAndShutdown:
55 result = TestDriverInitializeAndShutdownL();
57 case ESgResIntInitializeAndShutdownManyTimes:
58 result = TestDriverInitializeAndShutdownManyTimes();
60 case ESgResIntResourceProfiling:
61 result = TestResourceProfiling(aInfo);
64 result = KErrNotFound;
67 RDebug::Printf("CTSgResSecondProcessTestHandler::RunTestCaseL result=%i", result);
71 CTSgResInternalSecondProcessTestHandler::CTSgResInternalSecondProcessTestHandler()
75 CTSgResInternalSecondProcessTestHandler::~CTSgResInternalSecondProcessTestHandler()
81 Opens the SgDriver and gets the test extension interfaces required for the
84 void CTSgResInternalSecondProcessTestHandler::OpenDriverL()
86 User::LeaveIfError(iSgDriver.Open());
87 User::LeaveIfError(iSgDriver.GetInterface(iTestExt));
88 User::LeaveIfError(iSgDriver.GetInterface(iProfExt));
92 Second process implementaion of the test ESgResIntDriverMemoryLeak.
94 Memory leak detection is beun and an image opened.
95 The image is not closed before the memory leak checking is ended.
96 This should cause an SGALLOC panic.
98 void CTSgResInternalSecondProcessTestHandler::TestDriverMemoryLeakL()
100 iTestExt->AllocMarkStart();
102 info.iSizeInPixels = TSize(8, 8);
103 info.iUsage = ESgUsageBitOpenVgImage;
104 info.iPixelFormat = EUidPixelFormatRGB_565;
107 image.Create(info, NULL, 0);
108 iTestExt->AllocMarkEnd(0); //Expecting this to panic
114 Second process impementation of the test ESgResIntDrawableOOM.
116 Tests RSgDrawable in a number of different situations with simulated
117 low memory conditions.
119 TInt CTSgResInternalSecondProcessTestHandler::TestDrawableOOM()
126 iTestExt->SetAllocFail(RAllocator::EFailNext, ++tryCount);
127 TRAP(err, DoDrawableMemoryTestsL());
129 while(err == KErrNoMemory);
131 iTestExt->SetAllocFail(RAllocator::ENone, 0);
133 result |= EFirstTestPassed;
138 Second process implementation of the test ESgResTestImageOOM.
140 Tests RSgImage in a number of different situations with simulated
141 low memory conditions.
143 TInt CTSgResInternalSecondProcessTestHandler::TestImageOOM(const TSgResIntTestInfo& aInfo)
150 iTestExt->SetAllocFail(RAllocator::EFailNext, ++tryCount);
151 TRAP(err, DoImageMemoryTestsL(aInfo));
153 while(err == KErrNoMemory);
155 iTestExt->SetAllocFail(RAllocator::ENone, 0);
159 result |= EFirstTestPassed;
166 Performs the RSgDrawable low memory tests; checks for Heap and RSgDriver memory
167 leaks after each individual test.
169 void CTSgResInternalSecondProcessTestHandler::DoDrawableMemoryTestsL()
171 //Construct the SgDrawable tests using EFalse to enable KErrNoMemory testing
172 CTSgDrawableGeneric* drawableTests = new(ELeave)CTSgDrawableGeneric(EFalse);
173 CleanupStack::PushL(drawableTests);
175 __UHEAP_MARK; iTestExt->AllocMarkStart();
176 drawableTests->TestOpenImageAsDrawableL();
177 __UHEAP_MARKEND; iTestExt->AllocMarkEnd(0);
179 __UHEAP_MARK; iTestExt->AllocMarkStart();
180 drawableTests->TestGetDrawableDrawableIdL();
181 __UHEAP_MARKEND; iTestExt->AllocMarkEnd(0);
183 __UHEAP_MARK; iTestExt->AllocMarkStart();
184 drawableTests->TestOpenDrawableInvalidL();
185 __UHEAP_MARKEND; iTestExt->AllocMarkEnd(0);
187 __UHEAP_MARK; iTestExt->AllocMarkStart();
188 drawableTests->TestCloseDrawableWithoutOpenL();
189 __UHEAP_MARKEND; iTestExt->AllocMarkEnd(0);
191 CleanupStack::PopAndDestroy(drawableTests);
195 Performs the RSgImage low memory tests; checks for Heap and RSgDriver memory
196 leaks after each individual test.
198 void CTSgResInternalSecondProcessTestHandler::DoImageMemoryTestsL(const TSgResIntTestInfo& aInfo)
200 // open image that is created in another process
201 __UHEAP_MARK; iTestExt->AllocMarkStart();
202 TestOpenImageL(aInfo.iDrawableId);
203 __UHEAP_MARKEND; iTestExt->AllocMarkEnd(0);
206 //Construct the SgImage generic tests using EFalse to enable KErrNoMemory testing
207 CTSgImageGeneric* imageTests = new(ELeave)CTSgImageGeneric(EFalse);
208 CleanupStack::PushL(imageTests);
210 __UHEAP_MARK; iTestExt->AllocMarkStart();
211 imageTests->TestGetPixelFormatsL();
212 __UHEAP_MARKEND; iTestExt->AllocMarkEnd(0);
214 __UHEAP_MARK; iTestExt->AllocMarkStart();
215 imageTests->TestCreateImageUninitializedL();
216 __UHEAP_MARKEND; iTestExt->AllocMarkEnd(0);
218 __UHEAP_MARK; iTestExt->AllocMarkStart();
219 imageTests->TestCreateImageL();
220 __UHEAP_MARKEND; iTestExt->AllocMarkEnd(0);
222 __UHEAP_MARK; iTestExt->AllocMarkStart();
223 imageTests->TestCreateImageFromExistingImageL();
224 __UHEAP_MARKEND; iTestExt->AllocMarkEnd(0);
226 __UHEAP_MARK; iTestExt->AllocMarkStart();
227 imageTests->TestGetImageInfoL();
228 __UHEAP_MARKEND; iTestExt->AllocMarkEnd(0);
230 __UHEAP_MARK; iTestExt->AllocMarkStart();
231 imageTests->TestGetImageDrawableIdL();
232 __UHEAP_MARKEND; iTestExt->AllocMarkEnd(0);
234 __UHEAP_MARK; iTestExt->AllocMarkStart();
235 imageTests->TestOpenImageL();
236 __UHEAP_MARKEND; iTestExt->AllocMarkEnd(0);
238 __UHEAP_MARK; iTestExt->AllocMarkStart();
239 imageTests->TestGetInterfaceL();
240 __UHEAP_MARKEND; iTestExt->AllocMarkEnd(0);
242 __UHEAP_MARK; iTestExt->AllocMarkStart();
243 imageTests->TestGetPixelFormatsInvalidL();
244 __UHEAP_MARKEND; iTestExt->AllocMarkEnd(0);
246 __UHEAP_MARK; iTestExt->AllocMarkStart();
247 imageTests->TestOpenImageInvalidL();
248 __UHEAP_MARKEND; iTestExt->AllocMarkEnd(0);
250 __UHEAP_MARK; iTestExt->AllocMarkStart();
251 imageTests->TestCloseImageManyTimesL();
252 __UHEAP_MARKEND; iTestExt->AllocMarkEnd(0);
254 __UHEAP_MARK; iTestExt->AllocMarkStart();
255 imageTests->TestCloseImageWithoutOpenL();
256 __UHEAP_MARKEND; iTestExt->AllocMarkEnd(0);
258 __UHEAP_MARK; iTestExt->AllocMarkStart();
259 imageTests->TestCreateImageInvalidL();
260 __UHEAP_MARKEND; iTestExt->AllocMarkEnd(0);
262 __UHEAP_MARK; iTestExt->AllocMarkStart();
263 imageTests->TestGetInfoImageInvalidL();
264 __UHEAP_MARKEND; iTestExt->AllocMarkEnd(0);
266 __UHEAP_MARK; iTestExt->AllocMarkStart();
267 imageTests->TestGetAttributesImageInvalidL();
268 __UHEAP_MARKEND; iTestExt->AllocMarkEnd(0);
270 __UHEAP_MARK; iTestExt->AllocMarkStart();
271 imageTests->TestCreateImageDataStrideL();
272 __UHEAP_MARKEND; iTestExt->AllocMarkEnd(0);
274 __UHEAP_MARK; iTestExt->AllocMarkStart();
275 imageTests->TestStress1L();
276 __UHEAP_MARKEND; iTestExt->AllocMarkEnd(0);
279 CleanupStack::PopAndDestroy(imageTests);
283 Used for OOM testing for opening an image in another process. For this purpose,
284 the image that is opened here must be created in another process.
286 void CTSgResInternalSecondProcessTestHandler::TestOpenImageL(TSgDrawableId aId)
288 TSgDrawableId id = aId;
292 User::LeaveIfError(image.Open(id));
298 Test the Local Reference count of RSgDriver when creating and destroying images
300 TInt CTSgResInternalSecondProcessTestHandler::TestDriverInitializeAndShutdownL()
304 info.iSizeInPixels = TSize(8, 8);
305 info.iUsage = ESgUsageBitOpenVgImage;
306 info.iPixelFormat = EUidPixelFormatRGB_565;
309 User::LeaveIfError(image.Create(info, KCrossImageData, KCrossImageDataStride));
311 if (1 == iProfExt->LocalResourceCount())
312 result |= EFirstTestPassed;
316 User::LeaveIfError(image.Create(info, KCrossImageData, KCrossImageDataStride));
319 if (KErrNone == image.Create(info, KCrossImageData, KCrossImageDataStride))
320 result |= ESecondTestPassed;
323 if (0 == iProfExt->LocalResourceCount())
324 result |= EThirdTestPassed;
330 Test the Local Reference count of RSgDriver when creating and destroying images
331 with multiple driver sessions.
333 TInt CTSgResInternalSecondProcessTestHandler::TestDriverInitializeAndShutdownManyTimes()
339 info.iSizeInPixels = TSize(8, 8);
340 info.iUsage = ESgUsageBitOpenVgImage;
341 info.iPixelFormat = EUidPixelFormatRGB_565;
345 if(KErrNone == image.Create(info, KCrossImageData, KCrossImageDataStride))
346 result |= EFirstTestPassed;
353 if(KErrNone == iSgDriver.Open())
354 result |= ESecondTestPassed;
356 if(KErrNone == image.Create(info, KCrossImageData, KCrossImageDataStride))
357 result |= EThirdTestPassed;
361 if(0 == iProfExt->LocalResourceCount())
362 result |= EFourthTestPassed;
372 Test the SgDriver extension MSgDriver_Profiling is reporting the correct local and
373 global memory usage and resource counts, when another process has created images
374 and then called into this process.
376 TInt CTSgResInternalSecondProcessTestHandler::TestResourceProfiling(const TSgResIntTestInfo& aInfo)
380 const TSize KImageSize(8, 8);
382 // Check that this process is reporting the same memory usage as the calling
383 // process, and is using zero local memory.
384 if (iProfExt->GlobalGraphicsMemoryUsed() == aInfo.iGlobalGraphicsMemory)
385 result |= EFirstTestPassed;
386 if (iProfExt->LocalGraphicsMemoryUsed() == 0)
387 result |= ESecondTestPassed;
388 if (iProfExt->GlobalResourceCount() == aInfo.iGlobalResourceCount)
389 result |= EThirdTestPassed;
392 if (KErrNone == image.Create(TSgImageInfo(KImageSize, ESgPixelFormatARGB_8888, ESgUsageBitOpenVgImage)))
394 // Check that the local resource count is one, and the global resource count has
395 // incremented by one.
396 if (iProfExt->LocalResourceCount() == 1)
397 result |= EFourthTestPassed;
398 if (iProfExt->GlobalResourceCount() == aInfo.iGlobalResourceCount+1)
399 result |= EFifthTestPassed;
401 // Check that creating an image in this process increases the global and
402 // local memory usage reported by the extension, and destroying it will
403 // set it back to how it was.
404 TInt localGraphicsMemory = iProfExt->LocalGraphicsMemoryUsed();
405 TInt globalGraphicsMemory = iProfExt->GlobalGraphicsMemoryUsed();
406 if (localGraphicsMemory >= (KImageSize.iWidth * KImageSize.iHeight * 4))
407 result |= ESixthTestPassed;
408 if (globalGraphicsMemory == (localGraphicsMemory + aInfo.iGlobalGraphicsMemory))
409 result |= ESeventhTestPassed;
413 // Check the local memory usage is the same as before the test started
414 if (iProfExt->LocalGraphicsMemoryUsed() == 0)
415 result |= EEighthTestPassed;
416 if (iProfExt->GlobalGraphicsMemoryUsed() == aInfo.iGlobalGraphicsMemory)
417 result |= ENinthTestPassed;
418 // Check the local resource count is zero and the global count is the same
419 // as before the test started.
420 if (iProfExt->LocalResourceCount() == 0)
421 result |= ETenthTestPassed;
422 if (iProfExt->GlobalResourceCount() == aInfo.iGlobalResourceCount)
423 result |= EEleventhTestPassed;