os/graphics/graphicsresourceservices/graphicsresourceimplementation/test/src/tsggenericmanual.cpp
First public contribution.
1 // Copyright (c) 2007-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.
14 // Tests for manual execution.
19 @internalComponent - Graphics Resource API Conformance Test Suite
22 #include "tsggenericmanual.h"
24 CTSgGenericManual::CTSgGenericManual(TBool aConformanceTests) :
25 CTSgTestStepBase(aConformanceTests)
27 INFO_PRINTF1(_L("Graphics resource component test - Generic Manual Tests.\r\n"));
30 CTSgGenericManual::~CTSgGenericManual()
32 iSecondProcess.Close();
37 This is intented to be used for TestStressResourceLeakL (GRAPHICS-RESOURCE-0050) test.
38 It creates images until the memory full situation. The images are kept in the passed RArray of RSgImage.
39 The returned error code is expected to be either KErrNoMemory or KErrNoGraphicsMemory.
40 Optionally, it opens and closes a duplicate handle to each image in the same process and in another process.
42 TInt CTSgGenericManual::CreateImages(const TSgImageInfo& aInfo, RArray<RSgImage>& aTestImages, TBool aDuplicate)
45 while(err == KErrNone)
48 err = image.Create(aInfo);
51 err = aTestImages.Append(image);
60 err = image2.Open(image.Id());
65 // send the image ID to the second process and wait until the
66 // second process has opened and closed a handle to the image
67 TRequestStatus status;
68 iSecondProcess.Rendezvous(status);
69 iMsgQ.SendBlocking(image.Id());
70 User::WaitForRequest(status);
79 void CTSgGenericManual::DestroyImages(RArray<RSgImage>& aTestImages)
81 TInt count = aTestImages.Count();
82 for(TInt i=0; i<count; ++i)
84 aTestImages[i].Close();
90 @leave Gets system wide error code
93 TVerdict CTSgGenericManual::doTestStepL()
95 SetTestStepID(_L("GRAPHICS-RESOURCE-0050"));
96 INFO_PRINTF1(_L("RSgImage generic resource leak stress test.\r\n"));
97 TestStressResourceLeakL();
100 return TestStepResult();
104 @SYMTestCaseID GRAPHICS-RESOURCE-0050
105 @SYMTestCaseDesc RSgImage exhaustive and resource leak test
107 @SYMFssID RSgImage::Create(const TSgImageInfo&, const TAny*, TInt)
108 RSgImage::Open(TSgDrawableId)
110 @SYMTestPriority Medium
112 @SYMTestPurpose To ensure no resource leaks while creating and destroying RSgImage multiple times
113 @SYMTestActions Create images until it returns no memory error. Close the created images and
114 create as many images as possible until memory is full. Test the number of images
115 created and also for each iteration the number of images created to be the same.
116 @SYMTestExpectedResults There should be no panics or leaves.
118 void CTSgGenericManual::TestStressResourceLeakL()
121 _LIT(KSection, "TestStressResourceLeak");
123 if (!GetIntFromConfig(KSection, _L("NumIterations"), numIterations))
128 if (!GetIntFromConfig(KSection, _L("Tolerance"), tolerance))
133 if (!GetIntFromConfig(KSection, _L("ImageWidth"), width))
138 if (!GetIntFromConfig(KSection, _L("ImageHeight"), height))
143 info.iPixelFormat = EUidPixelFormatRGB_565;
144 info.iSizeInPixels = TSize(width, height);
145 info.iUsage = ESgUsageBitOpenVgImage;
147 if (!GetBoolFromConfig(KSection, _L("DuplicateHandle"), duplicate))
153 User::LeaveIfError(iMsgQ.CreateGlobal(KSgTestMultiprocessMsgQ, 1));
154 _LIT(KProcessName, "tgraphicsresourcemanualsecondprocess.exe");
155 User::LeaveIfError(iSecondProcess.Create(KProcessName, KNullDesC));
156 iSecondProcess.Resume();
159 RArray<RSgImage> testImages;
163 for (TInt i = 0; i < numIterations && err == KErrNone; ++i)
165 err = CreateImages(info, testImages, duplicate);
166 TInt thisCount = testImages.Count();
167 DestroyImages(testImages);
169 if (err == KErrNoMemory || err == KErrNoGraphicsMemory)
173 else if (err != KErrNone)
175 WARN_PRINTF2(_L("Create images error [%d]"), err);
176 SetTestStepResult(ETestSuiteError);
185 if (count != thisCount)
187 INFO_PRINTF4(_L("Mismatch @ iteration %d: initial %d, now %d"), i, count, thisCount);
191 TEST(Abs(count - thisCount) <= tolerance);
196 INFO_PRINTF2(_L("Last iteration: %d images created\r\n"), count);
199 // send a null ID to tell the second process to kill itself
200 // and wait until the second process terminates
201 TRequestStatus status;
202 iSecondProcess.Logon(status);
203 iMsgQ.SendBlocking(KSgNullDrawableId);
204 User::WaitForRequest(status);
206 iSecondProcess.Close();