os/graphics/graphicsresourceservices/graphicsresourceimplementation/test/src/tsggenericmanual.cpp
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/graphics/graphicsresourceservices/graphicsresourceimplementation/test/src/tsggenericmanual.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,210 @@
1.4 +// Copyright (c) 2007-2010 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 +// Tests for manual execution.
1.18 +
1.19 +/**
1.20 + @file
1.21 + @test
1.22 + @internalComponent - Graphics Resource API Conformance Test Suite
1.23 +*/
1.24 +
1.25 +#include "tsggenericmanual.h"
1.26 +
1.27 +CTSgGenericManual::CTSgGenericManual(TBool aConformanceTests) :
1.28 + CTSgTestStepBase(aConformanceTests)
1.29 + {
1.30 + INFO_PRINTF1(_L("Graphics resource component test - Generic Manual Tests.\r\n"));
1.31 + }
1.32 +
1.33 +CTSgGenericManual::~CTSgGenericManual()
1.34 + {
1.35 + iSecondProcess.Close();
1.36 + iMsgQ.Close();
1.37 + }
1.38 +
1.39 +/**
1.40 +This is intented to be used for TestStressResourceLeakL (GRAPHICS-RESOURCE-0050) test.
1.41 +It creates images until the memory full situation. The images are kept in the passed RArray of RSgImage.
1.42 +The returned error code is expected to be either KErrNoMemory or KErrNoGraphicsMemory.
1.43 +Optionally, it opens and closes a duplicate handle to each image in the same process and in another process.
1.44 +*/
1.45 +TInt CTSgGenericManual::CreateImages(const TSgImageInfo& aInfo, RArray<RSgImage>& aTestImages, TBool aDuplicate)
1.46 + {
1.47 + TInt err = KErrNone;
1.48 + while(err == KErrNone)
1.49 + {
1.50 + RSgImage image;
1.51 + err = image.Create(aInfo);
1.52 + if(err == KErrNone)
1.53 + {
1.54 + err = aTestImages.Append(image);
1.55 + if (err != KErrNone)
1.56 + {
1.57 + image.Close();
1.58 + return err;
1.59 + }
1.60 + if (aDuplicate)
1.61 + {
1.62 + RSgImage image2;
1.63 + err = image2.Open(image.Id());
1.64 + if (err != KErrNone)
1.65 + {
1.66 + return err;
1.67 + }
1.68 + // send the image ID to the second process and wait until the
1.69 + // second process has opened and closed a handle to the image
1.70 + TRequestStatus status;
1.71 + iSecondProcess.Rendezvous(status);
1.72 + iMsgQ.SendBlocking(image.Id());
1.73 + User::WaitForRequest(status);
1.74 + image2.Close();
1.75 + err = status.Int();
1.76 + }
1.77 + }
1.78 + }
1.79 + return err;
1.80 + }
1.81 +
1.82 +void CTSgGenericManual::DestroyImages(RArray<RSgImage>& aTestImages)
1.83 + {
1.84 + TInt count = aTestImages.Count();
1.85 + for(TInt i=0; i<count; ++i)
1.86 + {
1.87 + aTestImages[i].Close();
1.88 + }
1.89 + aTestImages.Reset();
1.90 + }
1.91 +
1.92 +/**
1.93 +@leave Gets system wide error code
1.94 +@return TVerdict code
1.95 +*/
1.96 +TVerdict CTSgGenericManual::doTestStepL()
1.97 + {
1.98 + SetTestStepID(_L("GRAPHICS-RESOURCE-0050"));
1.99 + INFO_PRINTF1(_L("RSgImage generic resource leak stress test.\r\n"));
1.100 + TestStressResourceLeakL();
1.101 + RecordTestResultL();
1.102 +
1.103 + return TestStepResult();
1.104 + }
1.105 +
1.106 +/**
1.107 +@SYMTestCaseID GRAPHICS-RESOURCE-0050
1.108 +@SYMTestCaseDesc RSgImage exhaustive and resource leak test
1.109 +@SYMPREQ PREQ2637
1.110 +@SYMFssID RSgImage::Create(const TSgImageInfo&, const TAny*, TInt)
1.111 + RSgImage::Open(TSgDrawableId)
1.112 + RSgImage::Close()
1.113 +@SYMTestPriority Medium
1.114 +@SYMTestType CT
1.115 +@SYMTestPurpose To ensure no resource leaks while creating and destroying RSgImage multiple times
1.116 +@SYMTestActions Create images until it returns no memory error. Close the created images and
1.117 + create as many images as possible until memory is full. Test the number of images
1.118 + created and also for each iteration the number of images created to be the same.
1.119 +@SYMTestExpectedResults There should be no panics or leaves.
1.120 + */
1.121 +void CTSgGenericManual::TestStressResourceLeakL()
1.122 + {
1.123 + TestOpenDriverL();
1.124 + _LIT(KSection, "TestStressResourceLeak");
1.125 + TInt numIterations;
1.126 + if (!GetIntFromConfig(KSection, _L("NumIterations"), numIterations))
1.127 + {
1.128 + numIterations = 2;
1.129 + }
1.130 + TInt tolerance;
1.131 + if (!GetIntFromConfig(KSection, _L("Tolerance"), tolerance))
1.132 + {
1.133 + tolerance = -1;
1.134 + }
1.135 + TInt width;
1.136 + if (!GetIntFromConfig(KSection, _L("ImageWidth"), width))
1.137 + {
1.138 + width = 1;
1.139 + }
1.140 + TInt height;
1.141 + if (!GetIntFromConfig(KSection, _L("ImageHeight"), height))
1.142 + {
1.143 + height = 1;
1.144 + }
1.145 + TSgImageInfo info;
1.146 + info.iPixelFormat = EUidPixelFormatRGB_565;
1.147 + info.iSizeInPixels = TSize(width, height);
1.148 + info.iUsage = ESgUsageBitOpenVgImage;
1.149 + TBool duplicate;
1.150 + if (!GetBoolFromConfig(KSection, _L("DuplicateHandle"), duplicate))
1.151 + {
1.152 + duplicate = EFalse;
1.153 + }
1.154 + if (duplicate)
1.155 + {
1.156 + User::LeaveIfError(iMsgQ.CreateGlobal(KSgTestMultiprocessMsgQ, 1));
1.157 + _LIT(KProcessName, "tgraphicsresourcemanualsecondprocess.exe");
1.158 + User::LeaveIfError(iSecondProcess.Create(KProcessName, KNullDesC));
1.159 + iSecondProcess.Resume();
1.160 + }
1.161 +
1.162 + RArray<RSgImage> testImages;
1.163 +
1.164 + TInt count(0);
1.165 + TInt err = KErrNone;
1.166 + for (TInt i = 0; i < numIterations && err == KErrNone; ++i)
1.167 + {
1.168 + err = CreateImages(info, testImages, duplicate);
1.169 + TInt thisCount = testImages.Count();
1.170 + DestroyImages(testImages);
1.171 +
1.172 + if (err == KErrNoMemory || err == KErrNoGraphicsMemory)
1.173 + {
1.174 + err = KErrNone;
1.175 + }
1.176 + else if (err != KErrNone)
1.177 + {
1.178 + WARN_PRINTF2(_L("Create images error [%d]"), err);
1.179 + SetTestStepResult(ETestSuiteError);
1.180 + }
1.181 +
1.182 + if (i == 0)
1.183 + {
1.184 + count = thisCount;
1.185 + }
1.186 + else
1.187 + {
1.188 + if (count != thisCount)
1.189 + {
1.190 + INFO_PRINTF4(_L("Mismatch @ iteration %d: initial %d, now %d"), i, count, thisCount);
1.191 + }
1.192 + if (tolerance >= 0)
1.193 + {
1.194 + TEST(Abs(count - thisCount) <= tolerance);
1.195 + }
1.196 + }
1.197 + }
1.198 +
1.199 + INFO_PRINTF2(_L("Last iteration: %d images created\r\n"), count);
1.200 + if (duplicate)
1.201 + {
1.202 + // send a null ID to tell the second process to kill itself
1.203 + // and wait until the second process terminates
1.204 + TRequestStatus status;
1.205 + iSecondProcess.Logon(status);
1.206 + iMsgQ.SendBlocking(KSgNullDrawableId);
1.207 + User::WaitForRequest(status);
1.208 + iMsgQ.Close();
1.209 + iSecondProcess.Close();
1.210 + }
1.211 + TestCloseDriver();
1.212 + }
1.213 +