os/graphics/graphicsresourceservices/graphicsresourceimplementation/test/src/tsggenericmanual.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
sl@0
     1
// Copyright (c) 2007-2010 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     2
// All rights reserved.
sl@0
     3
// This component and the accompanying materials are made available
sl@0
     4
// under the terms of "Eclipse Public License v1.0"
sl@0
     5
// which accompanies this distribution, and is available
sl@0
     6
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     7
//
sl@0
     8
// Initial Contributors:
sl@0
     9
// Nokia Corporation - initial contribution.
sl@0
    10
//
sl@0
    11
// Contributors:
sl@0
    12
//
sl@0
    13
// Description:
sl@0
    14
// Tests for manual execution.
sl@0
    15
sl@0
    16
/**
sl@0
    17
 @file
sl@0
    18
 @test
sl@0
    19
 @internalComponent - Graphics Resource API Conformance Test Suite
sl@0
    20
*/
sl@0
    21
sl@0
    22
#include "tsggenericmanual.h"
sl@0
    23
sl@0
    24
CTSgGenericManual::CTSgGenericManual(TBool aConformanceTests) :
sl@0
    25
	CTSgTestStepBase(aConformanceTests)
sl@0
    26
	{
sl@0
    27
	INFO_PRINTF1(_L("Graphics resource component test - Generic Manual Tests.\r\n"));
sl@0
    28
	}
sl@0
    29
sl@0
    30
CTSgGenericManual::~CTSgGenericManual()
sl@0
    31
	{
sl@0
    32
	iSecondProcess.Close();
sl@0
    33
	iMsgQ.Close();
sl@0
    34
	}
sl@0
    35
sl@0
    36
/**
sl@0
    37
This is intented to be used for TestStressResourceLeakL (GRAPHICS-RESOURCE-0050) test. 
sl@0
    38
It creates images until the memory full situation. The images are kept in the passed RArray of RSgImage. 
sl@0
    39
The returned error code is expected to be either KErrNoMemory or KErrNoGraphicsMemory.
sl@0
    40
Optionally, it opens and closes a duplicate handle to each image in the same process and in another process.
sl@0
    41
*/
sl@0
    42
TInt CTSgGenericManual::CreateImages(const TSgImageInfo& aInfo, RArray<RSgImage>& aTestImages, TBool aDuplicate)
sl@0
    43
    {
sl@0
    44
    TInt err = KErrNone;
sl@0
    45
    while(err == KErrNone)
sl@0
    46
        {
sl@0
    47
        RSgImage image;
sl@0
    48
        err = image.Create(aInfo);
sl@0
    49
        if(err == KErrNone)
sl@0
    50
            {
sl@0
    51
            err = aTestImages.Append(image);
sl@0
    52
            if (err != KErrNone)
sl@0
    53
            	{
sl@0
    54
				image.Close();
sl@0
    55
				return err;
sl@0
    56
            	}
sl@0
    57
            if (aDuplicate)
sl@0
    58
            	{
sl@0
    59
				RSgImage image2;
sl@0
    60
				err = image2.Open(image.Id());
sl@0
    61
				if (err != KErrNone)
sl@0
    62
					{
sl@0
    63
					return err;
sl@0
    64
					}
sl@0
    65
				// send the image ID to the second process and wait until the
sl@0
    66
				// second process has opened and closed a handle to the image
sl@0
    67
				TRequestStatus status;
sl@0
    68
				iSecondProcess.Rendezvous(status);
sl@0
    69
				iMsgQ.SendBlocking(image.Id());
sl@0
    70
				User::WaitForRequest(status);
sl@0
    71
				image2.Close();
sl@0
    72
				err = status.Int();
sl@0
    73
            	}
sl@0
    74
            }
sl@0
    75
        }
sl@0
    76
    return err;
sl@0
    77
    }
sl@0
    78
sl@0
    79
void CTSgGenericManual::DestroyImages(RArray<RSgImage>& aTestImages)
sl@0
    80
    {
sl@0
    81
    TInt count = aTestImages.Count();
sl@0
    82
    for(TInt i=0; i<count; ++i)
sl@0
    83
        {
sl@0
    84
        aTestImages[i].Close();
sl@0
    85
        }   
sl@0
    86
    aTestImages.Reset();    
sl@0
    87
    }
sl@0
    88
sl@0
    89
/** 
sl@0
    90
@leave Gets system wide error code
sl@0
    91
@return TVerdict code
sl@0
    92
*/
sl@0
    93
TVerdict CTSgGenericManual::doTestStepL()
sl@0
    94
	{	
sl@0
    95
    SetTestStepID(_L("GRAPHICS-RESOURCE-0050"));
sl@0
    96
    INFO_PRINTF1(_L("RSgImage generic resource leak stress test.\r\n"));
sl@0
    97
    TestStressResourceLeakL();
sl@0
    98
	RecordTestResultL();
sl@0
    99
	
sl@0
   100
	return TestStepResult();
sl@0
   101
	}
sl@0
   102
sl@0
   103
/**
sl@0
   104
@SYMTestCaseID          GRAPHICS-RESOURCE-0050
sl@0
   105
@SYMTestCaseDesc        RSgImage exhaustive and resource leak test
sl@0
   106
@SYMPREQ                PREQ2637
sl@0
   107
@SYMFssID               RSgImage::Create(const TSgImageInfo&, const TAny*, TInt)
sl@0
   108
                        RSgImage::Open(TSgDrawableId)
sl@0
   109
                        RSgImage::Close()
sl@0
   110
@SYMTestPriority        Medium
sl@0
   111
@SYMTestType            CT
sl@0
   112
@SYMTestPurpose         To ensure no resource leaks while creating and destroying RSgImage multiple times
sl@0
   113
@SYMTestActions         Create images until it returns no memory error. Close the created images and          
sl@0
   114
                        create as many images as possible until memory is full. Test the number of images
sl@0
   115
                        created and also for each iteration the number of images created to be the same.
sl@0
   116
@SYMTestExpectedResults There should be no panics or leaves.
sl@0
   117
 */
sl@0
   118
void CTSgGenericManual::TestStressResourceLeakL()
sl@0
   119
    {
sl@0
   120
    TestOpenDriverL();
sl@0
   121
    _LIT(KSection, "TestStressResourceLeak");
sl@0
   122
    TInt numIterations;
sl@0
   123
    if (!GetIntFromConfig(KSection, _L("NumIterations"), numIterations))
sl@0
   124
    	{
sl@0
   125
		numIterations = 2;
sl@0
   126
    	}
sl@0
   127
    TInt tolerance;
sl@0
   128
    if (!GetIntFromConfig(KSection, _L("Tolerance"), tolerance))
sl@0
   129
    	{
sl@0
   130
		tolerance = -1;
sl@0
   131
    	}
sl@0
   132
    TInt width;
sl@0
   133
    if (!GetIntFromConfig(KSection, _L("ImageWidth"), width))
sl@0
   134
    	{
sl@0
   135
		width = 1;
sl@0
   136
    	}
sl@0
   137
    TInt height;
sl@0
   138
    if (!GetIntFromConfig(KSection, _L("ImageHeight"), height))
sl@0
   139
    	{
sl@0
   140
		height = 1;
sl@0
   141
    	}
sl@0
   142
    TSgImageInfo info;
sl@0
   143
    info.iPixelFormat = EUidPixelFormatRGB_565;
sl@0
   144
    info.iSizeInPixels = TSize(width, height);
sl@0
   145
    info.iUsage = ESgUsageBitOpenVgImage;
sl@0
   146
    TBool duplicate;
sl@0
   147
    if (!GetBoolFromConfig(KSection, _L("DuplicateHandle"), duplicate))
sl@0
   148
    	{
sl@0
   149
		duplicate = EFalse;
sl@0
   150
    	}
sl@0
   151
    if (duplicate)
sl@0
   152
    	{
sl@0
   153
		User::LeaveIfError(iMsgQ.CreateGlobal(KSgTestMultiprocessMsgQ, 1));
sl@0
   154
		_LIT(KProcessName, "tgraphicsresourcemanualsecondprocess.exe");
sl@0
   155
		User::LeaveIfError(iSecondProcess.Create(KProcessName, KNullDesC));
sl@0
   156
		iSecondProcess.Resume();
sl@0
   157
    	}
sl@0
   158
sl@0
   159
    RArray<RSgImage> testImages;    
sl@0
   160
    
sl@0
   161
    TInt count(0);
sl@0
   162
    TInt err = KErrNone;
sl@0
   163
    for (TInt i = 0; i < numIterations && err == KErrNone; ++i)
sl@0
   164
        {
sl@0
   165
        err = CreateImages(info, testImages, duplicate);
sl@0
   166
        TInt thisCount = testImages.Count();
sl@0
   167
        DestroyImages(testImages);
sl@0
   168
sl@0
   169
        if (err == KErrNoMemory || err == KErrNoGraphicsMemory)
sl@0
   170
        	{
sl@0
   171
        	err = KErrNone;
sl@0
   172
        	}
sl@0
   173
        else if (err != KErrNone)
sl@0
   174
        	{
sl@0
   175
        	WARN_PRINTF2(_L("Create images error [%d]"), err);
sl@0
   176
        	SetTestStepResult(ETestSuiteError);
sl@0
   177
        	}
sl@0
   178
      
sl@0
   179
        if (i == 0)
sl@0
   180
        	{
sl@0
   181
			count = thisCount;
sl@0
   182
        	}
sl@0
   183
        else
sl@0
   184
            {
sl@0
   185
			if (count != thisCount)
sl@0
   186
				{
sl@0
   187
				INFO_PRINTF4(_L("Mismatch @ iteration %d: initial %d, now %d"), i,  count, thisCount);
sl@0
   188
				}
sl@0
   189
			if (tolerance >= 0)
sl@0
   190
				{
sl@0
   191
				TEST(Abs(count - thisCount) <= tolerance);
sl@0
   192
				}
sl@0
   193
            }
sl@0
   194
        }
sl@0
   195
    
sl@0
   196
    INFO_PRINTF2(_L("Last iteration: %d images created\r\n"), count);
sl@0
   197
    if (duplicate)
sl@0
   198
    	{
sl@0
   199
		// send a null ID to tell the second process to kill itself
sl@0
   200
		// and wait until the second process terminates
sl@0
   201
		TRequestStatus status;
sl@0
   202
		iSecondProcess.Logon(status);
sl@0
   203
		iMsgQ.SendBlocking(KSgNullDrawableId);
sl@0
   204
		User::WaitForRequest(status);
sl@0
   205
		iMsgQ.Close();
sl@0
   206
		iSecondProcess.Close();
sl@0
   207
    	}
sl@0
   208
    TestCloseDriver();
sl@0
   209
    }
sl@0
   210