graphicsresourceservices/graphicsresourceimplementation/test/src/tsggenericmanual.cpp
changeset 103 2717213c588a
parent 36 01a6848ebfd7
equal deleted inserted replaced
98:bf7481649c98 103:2717213c588a
     1 // Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
     1 // Copyright (c) 2007-2010 Nokia Corporation and/or its subsidiary(-ies).
     2 // All rights reserved.
     2 // All rights reserved.
     3 // This component and the accompanying materials are made available
     3 // This component and the accompanying materials are made available
     4 // under the terms of "Eclipse Public License v1.0"
     4 // under the terms of "Eclipse Public License v1.0"
     5 // which accompanies this distribution, and is available
     5 // which accompanies this distribution, and is available
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
    27 	INFO_PRINTF1(_L("Graphics resource component test - Generic Manual Tests.\r\n"));
    27 	INFO_PRINTF1(_L("Graphics resource component test - Generic Manual Tests.\r\n"));
    28 	}
    28 	}
    29 
    29 
    30 CTSgGenericManual::~CTSgGenericManual()
    30 CTSgGenericManual::~CTSgGenericManual()
    31 	{
    31 	{
       
    32 	iSecondProcess.Close();
       
    33 	iMsgQ.Close();
    32 	}
    34 	}
    33 
    35 
    34 /**
    36 /**
    35 This is intented to be used for TestStressResourceLeakL (GRAPHICS-RESOURCE-0050) test. 
    37 This is intented to be used for TestStressResourceLeakL (GRAPHICS-RESOURCE-0050) test. 
    36 It creates images until the memory full situation. The images are kept in the passed RArray of RSgImage. 
    38 It creates images until the memory full situation. The images are kept in the passed RArray of RSgImage. 
    37 The returned error code is expected to be either KErrNoMemory or KErrNoGraphicsMemory.
    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.
    38 */
    41 */
    39 TInt CTSgGenericManual::CreateImages(const TSgImageInfo& aInfo, RArray<RSgImage>& aTestImages)
    42 TInt CTSgGenericManual::CreateImages(const TSgImageInfo& aInfo, RArray<RSgImage>& aTestImages, TBool aDuplicate)
    40     {
    43     {
    41     TInt err = KErrNone;
    44     TInt err = KErrNone;
    42     while(err == KErrNone)
    45     while(err == KErrNone)
    43         {
    46         {
    44         RSgImage image;
    47         RSgImage image;
    45         err = image.Create(aInfo);
    48         err = image.Create(aInfo);
    46         if(err == KErrNone)
    49         if(err == KErrNone)
    47             {
    50             {
    48             err = aTestImages.Append(image);
    51             err = aTestImages.Append(image);
       
    52             if (err != KErrNone)
       
    53             	{
       
    54 				image.Close();
       
    55 				return err;
       
    56             	}
       
    57             if (aDuplicate)
       
    58             	{
       
    59 				RSgImage image2;
       
    60 				err = image2.Open(image.Id());
       
    61 				if (err != KErrNone)
       
    62 					{
       
    63 					return err;
       
    64 					}
       
    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);
       
    71 				image2.Close();
       
    72 				err = status.Int();
       
    73             	}
    49             }
    74             }
    50         }    
    75         }
    51     return err;
    76     return err;
    52     }
    77     }
    53 
    78 
    54 void CTSgGenericManual::DestroyImages(RArray<RSgImage>& aTestImages)
    79 void CTSgGenericManual::DestroyImages(RArray<RSgImage>& aTestImages)
    55     {
    80     {
    78 /**
   103 /**
    79 @SYMTestCaseID          GRAPHICS-RESOURCE-0050
   104 @SYMTestCaseID          GRAPHICS-RESOURCE-0050
    80 @SYMTestCaseDesc        RSgImage exhaustive and resource leak test
   105 @SYMTestCaseDesc        RSgImage exhaustive and resource leak test
    81 @SYMPREQ                PREQ2637
   106 @SYMPREQ                PREQ2637
    82 @SYMFssID               RSgImage::Create(const TSgImageInfo&, const TAny*, TInt)
   107 @SYMFssID               RSgImage::Create(const TSgImageInfo&, const TAny*, TInt)
    83                         RSgImage::Close() 
   108                         RSgImage::Open(TSgDrawableId)
       
   109                         RSgImage::Close()
    84 @SYMTestPriority        Medium
   110 @SYMTestPriority        Medium
    85 @SYMTestType            CT
   111 @SYMTestType            CT
    86 @SYMTestPurpose         To ensure no resource leaks while creating and destroying RSgImage multiple times
   112 @SYMTestPurpose         To ensure no resource leaks while creating and destroying RSgImage multiple times
    87 @SYMTestActions         Create images until it returns no memomy error. Close the created images and          
   113 @SYMTestActions         Create images until it returns no memory error. Close the created images and          
    88                         create as many images as possible until memory is full. Test the number of images
   114                         create as many images as possible until memory is full. Test the number of images
    89                         created and also for each iteration the number of images created to be the same.
   115                         created and also for each iteration the number of images created to be the same.
    90 @SYMTestExpectedResults There should be no panics or leaves.
   116 @SYMTestExpectedResults There should be no panics or leaves.
    91  */
   117  */
    92 void CTSgGenericManual::TestStressResourceLeakL()
   118 void CTSgGenericManual::TestStressResourceLeakL()
    93     {
   119     {
    94     TestOpenDriverL();
   120     TestOpenDriverL();
    95     
   121     _LIT(KSection, "TestStressResourceLeak");
    96     const TInt KNumIterations = 100000;
   122     TInt numIterations;
       
   123     if (!GetIntFromConfig(KSection, _L("NumIterations"), numIterations))
       
   124     	{
       
   125 		numIterations = 2;
       
   126     	}
       
   127     TInt tolerance;
       
   128     if (!GetIntFromConfig(KSection, _L("Tolerance"), tolerance))
       
   129     	{
       
   130 		tolerance = -1;
       
   131     	}
       
   132     TInt width;
       
   133     if (!GetIntFromConfig(KSection, _L("ImageWidth"), width))
       
   134     	{
       
   135 		width = 1;
       
   136     	}
       
   137     TInt height;
       
   138     if (!GetIntFromConfig(KSection, _L("ImageHeight"), height))
       
   139     	{
       
   140 		height = 1;
       
   141     	}
    97     TSgImageInfo info;
   142     TSgImageInfo info;
    98     info.iPixelFormat = EUidPixelFormatRGB_565;
   143     info.iPixelFormat = EUidPixelFormatRGB_565;
    99     info.iSizeInPixels = TSize(1, 1);
   144     info.iSizeInPixels = TSize(width, height);
   100     info.iUsage = ESgUsageBitOpenVgImage;
   145     info.iUsage = ESgUsageBitOpenVgImage;
   101     
   146     TBool duplicate;
       
   147     if (!GetBoolFromConfig(KSection, _L("DuplicateHandle"), duplicate))
       
   148     	{
       
   149 		duplicate = EFalse;
       
   150     	}
       
   151     if (duplicate)
       
   152     	{
       
   153 		User::LeaveIfError(iMsgQ.CreateGlobal(KSgTestMultiprocessMsgQ, 1));
       
   154 		_LIT(KProcessName, "tgraphicsresourcemanualsecondprocess.exe");
       
   155 		User::LeaveIfError(iSecondProcess.Create(KProcessName, KNullDesC));
       
   156 		iSecondProcess.Resume();
       
   157     	}
       
   158 
   102     RArray<RSgImage> testImages;    
   159     RArray<RSgImage> testImages;    
   103     
   160     
   104     TInt count(0);
   161     TInt count(0);
   105     TInt err = KErrNone;
   162     TInt err = KErrNone;
   106     for(TInt i=0; i<KNumIterations && (err == KErrNone); ++i) 
   163     for (TInt i = 0; i < numIterations && err == KErrNone; ++i)
   107         {
   164         {
   108         err = CreateImages(info, testImages);
   165         err = CreateImages(info, testImages, duplicate);
   109         TInt thisCount = testImages.Count();
   166         TInt thisCount = testImages.Count();
   110         DestroyImages(testImages);
   167         DestroyImages(testImages);
   111 
   168 
   112         if (err == KErrNoMemory || err == KErrNoGraphicsMemory)
   169         if (err == KErrNoMemory || err == KErrNoGraphicsMemory)
   113         	{
   170         	{
   114         	err = KErrNone;
   171         	err = KErrNone;
   115         	}
   172         	}
   116         else if (err != KErrNone)
   173         else if (err != KErrNone)
   117         	{
   174         	{
   118         	ERR_PRINTF2(_L("Create images error [%d]"), err);
   175         	WARN_PRINTF2(_L("Create images error [%d]"), err);
   119         	SetTestStepResult(EFail);
   176         	SetTestStepResult(ETestSuiteError);
   120         	}
   177         	}
   121       
   178       
   122         if(i > 0 && count != thisCount)
   179         if (i == 0)
       
   180         	{
       
   181 			count = thisCount;
       
   182         	}
       
   183         else
   123             {
   184             {
   124             ERR_PRINTF4(_L("Mismatch @ iteration %d : Was %d, now %d"), i,  count, thisCount);
   185 			if (count != thisCount)
   125             }        
   186 				{
   126         count = thisCount;
   187 				INFO_PRINTF4(_L("Mismatch @ iteration %d: initial %d, now %d"), i,  count, thisCount);
       
   188 				}
       
   189 			if (tolerance >= 0)
       
   190 				{
       
   191 				TEST(Abs(count - thisCount) <= tolerance);
       
   192 				}
       
   193             }
   127         }
   194         }
   128     
   195     
   129     INFO_PRINTF2(_L("%d images created \r\n"), count);
   196     INFO_PRINTF2(_L("Last iteration: %d images created\r\n"), count);
       
   197     if (duplicate)
       
   198     	{
       
   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);
       
   205 		iMsgQ.Close();
       
   206 		iSecondProcess.Close();
       
   207     	}
   130     TestCloseDriver();
   208     TestCloseDriver();
   131     }
   209     }
   132 
   210