os/graphics/egl/egltest/src/egltest_oom_sgimage.cpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
sl@0
     1
// Copyright (c) 2009-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
//
sl@0
    15
sl@0
    16
/**
sl@0
    17
 @file
sl@0
    18
 @test
sl@0
    19
*/
sl@0
    20
sl@0
    21
#include <test/tefunit.h> // for ASSERT macros
sl@0
    22
#include <e32msgqueue.h>
sl@0
    23
sl@0
    24
#include <test/egltestcommonprocess.h>
sl@0
    25
#include <test/egltestcommonconversion.h>
sl@0
    26
#include <test/egltestcommoninisettings.h>
sl@0
    27
#include "egltest_oom_sgimage.h"
sl@0
    28
sl@0
    29
sl@0
    30
_LIT(KOOMSection, "OOM");
sl@0
    31
sl@0
    32
sl@0
    33
//Since we want to exhaust the memory it probably makes sense to use any 32bpp mode  
sl@0
    34
//There is no need to put it into INI file
sl@0
    35
const TUidPixelFormat KOOMPixelFormat = EUidPixelFormatARGB_8888; 
sl@0
    36
sl@0
    37
// Deviation in per cent for test 0442 and 0443
sl@0
    38
const TInt KOOMSgImageDeviation = 5; 
sl@0
    39
sl@0
    40
sl@0
    41
CEglTest_OOM_Base::~CEglTest_OOM_Base()
sl@0
    42
    {
sl@0
    43
    CleanGraphicsResources();
sl@0
    44
    CleanAll();
sl@0
    45
    }
sl@0
    46
sl@0
    47
TVerdict CEglTest_OOM_Base::doTestStepPreambleL()
sl@0
    48
    {
sl@0
    49
    TVerdict verdict = CEglTestStep::doTestStepPreambleL();
sl@0
    50
    //read all parameters from config
sl@0
    51
    CEglTestCommonIniSettings* iniParser = CEglTestCommonIniSettings::NewL();
sl@0
    52
    CleanupStack::PushL(iniParser);
sl@0
    53
    iNumIterations = iniParser->GetNumberOfIterations(KOOMSection);
sl@0
    54
    if(!iNumIterations)
sl@0
    55
        {
sl@0
    56
        ERR_PRINTF1(_L("The number iterations is not specified in INI file, the test will not be executed!"));
sl@0
    57
        User::Leave(KErrArgument);      
sl@0
    58
        }
sl@0
    59
    
sl@0
    60
    iImageSize = iniParser->GetImageSize(KOOMSection);
sl@0
    61
    if(iImageSize == TSize(0,0))
sl@0
    62
        {
sl@0
    63
        ERR_PRINTF1(_L("The image size whether is not specified in INI file or is TSize(0,0), the test will not be executed!"));
sl@0
    64
        User::Leave(KErrArgument);      
sl@0
    65
        }
sl@0
    66
    iPixelFormat = KOOMPixelFormat;
sl@0
    67
    
sl@0
    68
    iThresholdGPUUsedMemory = iniParser->GetThresholdGPUUsedMemory(KOOMSection);
sl@0
    69
    if(iThresholdGPUUsedMemory == 0)
sl@0
    70
        {
sl@0
    71
        ERR_PRINTF1(_L("Threshold GPU used memory whether is not specified in INI file or is 0, the test will not be executed!"));
sl@0
    72
        User::Leave(KErrArgument);      
sl@0
    73
        }
sl@0
    74
sl@0
    75
    iThresholdLastIteration = iniParser->GetThresholdLastIteration(KOOMSection);
sl@0
    76
    if(iThresholdLastIteration == 0)
sl@0
    77
        {
sl@0
    78
        ERR_PRINTF1(_L("Threshold last iteration whether is not specified in INI file or is 0, the test will not be executed!"));
sl@0
    79
        User::Leave(KErrArgument);      
sl@0
    80
        }
sl@0
    81
    
sl@0
    82
    CleanupStack::PopAndDestroy(iniParser);
sl@0
    83
sl@0
    84
    INFO_PRINTF4(_L("**** The test will be run in following configuration: number of iterations %d, image size (%d, %d)"), iNumIterations, iImageSize.iWidth, iImageSize.iHeight);
sl@0
    85
    INFO_PRINTF3(_L("**** Threshold GPU used memory %d, threshold last iteration %d"), iThresholdGPUUsedMemory, iThresholdLastIteration);
sl@0
    86
    
sl@0
    87
    PrintUsedPixelConfiguration();    
sl@0
    88
    return verdict;
sl@0
    89
    }
sl@0
    90
sl@0
    91
TVerdict CEglTest_OOM_Base::doTestStepPostambleL()
sl@0
    92
    {
sl@0
    93
    //to keep heap checking happy we have to clean up before destructor 
sl@0
    94
    CleanGraphicsResources();
sl@0
    95
    return CEglTestStep::doTestStepPostambleL();
sl@0
    96
    }
sl@0
    97
sl@0
    98
//receive last successful index from the client process
sl@0
    99
void CEglTest_OOM_Base::ReceiveMessageFromClient(RMsgQueue<TEglStepMessageBuffer>& aMessageQueueClientProcParam) 
sl@0
   100
    {
sl@0
   101
    TEglStepMessageBuffer param;
sl@0
   102
    aMessageQueueClientProcParam.ReceiveBlocking(param);
sl@0
   103
    iLastIterationNumber = *(TInt*) (param.iBuf);
sl@0
   104
    }
sl@0
   105
sl@0
   106
//send last successful index to the main process for analysis
sl@0
   107
void CEglTest_OOM_Base::SendIndexToMainProcessL(TInt aIndex)
sl@0
   108
    {
sl@0
   109
    TEglStepMessageBuffer param;
sl@0
   110
    RMsgQueue<TEglStepMessageBuffer> messageQueueClientProcParam;
sl@0
   111
    CleanupClosePushL(messageQueueClientProcParam);
sl@0
   112
    User::LeaveIfError(messageQueueClientProcParam.Open(EProcSlotCustomClientParam, EOwnerProcess));
sl@0
   113
    *((TInt*)param.iBuf) = aIndex;
sl@0
   114
    messageQueueClientProcParam.SendBlocking(param);
sl@0
   115
    CleanupStack::PopAndDestroy(&messageQueueClientProcParam);
sl@0
   116
    }
sl@0
   117
sl@0
   118
//clean Sg/Egl/Vg images allocated. Reset arrays for various deviation variables.
sl@0
   119
void CEglTest_OOM_Base::CleanGraphicsResources()
sl@0
   120
    {
sl@0
   121
#ifdef SYMBIAN_GRAPHICS_EGL_SGIMAGELITE
sl@0
   122
    while(iSurfaces.Count() > 0)
sl@0
   123
        {
sl@0
   124
        eglDestroySurface(iDisplay, iSurfaces[0]);
sl@0
   125
        iSurfaces.Remove(0);
sl@0
   126
        }
sl@0
   127
    iSurfaces.Reset();
sl@0
   128
sl@0
   129
    while(iVgImages.Count() > 0)
sl@0
   130
        {
sl@0
   131
        vgDestroyImage(iVgImages[0]);
sl@0
   132
        iVgImages.Remove(0);
sl@0
   133
        }
sl@0
   134
    iVgImages.Reset();
sl@0
   135
sl@0
   136
    while(iEglImages.Count() > 0)
sl@0
   137
        {
sl@0
   138
        iEglSess->DestroyEGLImage(iDisplay, iEglImages[0]);
sl@0
   139
        iEglImages.Remove(0);
sl@0
   140
        }
sl@0
   141
    iEglImages.Reset();
sl@0
   142
    
sl@0
   143
    while(iSgImages.Count() > 0)
sl@0
   144
        {
sl@0
   145
        iSgImages[0].Close();
sl@0
   146
        iSgImages.Remove(0);
sl@0
   147
        }
sl@0
   148
    iSgImages.Reset();
sl@0
   149
sl@0
   150
    iGPUUsedMemory.Reset();
sl@0
   151
    iLastIterations.Reset();
sl@0
   152
#endif
sl@0
   153
    }
sl@0
   154
sl@0
   155
//if an array is empty, it returns zero for both aMin and aMax
sl@0
   156
void CEglTest_OOM_Base::GetMinMax(const RArray<TInt>& aArray, TInt& aMin, TInt& aMax) const
sl@0
   157
    {
sl@0
   158
    aMin = 0;
sl@0
   159
    aMax = 0;
sl@0
   160
    if(aArray.Count() == 0)
sl@0
   161
        return;
sl@0
   162
    aMax = aArray[0];
sl@0
   163
    aMin = aArray[0];
sl@0
   164
    for(TInt ii = 1; ii < aArray.Count(); ii++)
sl@0
   165
        {
sl@0
   166
        if(aMin > aArray[ii])
sl@0
   167
            {
sl@0
   168
            aMin = aArray[ii];
sl@0
   169
            }
sl@0
   170
        if(aMax < aArray[ii])
sl@0
   171
            {
sl@0
   172
            aMax = aArray[ii];
sl@0
   173
            }
sl@0
   174
        }
sl@0
   175
    }
sl@0
   176
sl@0
   177
TInt CEglTest_OOM_Base::Deviation(const RArray<TInt>& aArray) const
sl@0
   178
    {
sl@0
   179
    TInt min = 0;
sl@0
   180
    TInt max = 0;
sl@0
   181
    
sl@0
   182
    GetMinMax(aArray, min, max);
sl@0
   183
    if(max == 0) 
sl@0
   184
        return 0; // to avoid division by zero
sl@0
   185
    return (max - min) / (((TReal)(min + max)) / 2) * 100;  
sl@0
   186
    }
sl@0
   187
sl@0
   188
//Calculate and output deviation of various parameters. 
sl@0
   189
//If the measurement for particular parameter doesn’t take place, for instance, 
sl@0
   190
//due to absence of the extension, the output will be skipped. 
sl@0
   191
void CEglTest_OOM_Base::CheckDeviation()
sl@0
   192
    {
sl@0
   193
    TInt res = KErrNone;
sl@0
   194
    
sl@0
   195
    if(iGPUUsedMemory.Count() > 0)
sl@0
   196
        {
sl@0
   197
        res = Deviation(iGPUUsedMemory);
sl@0
   198
        ASSERT_TRUE(iThresholdGPUUsedMemory >= res);
sl@0
   199
        INFO_PRINTF3(_L("GPU used memory deviation %d %%, threshold %d %%"), res, iThresholdGPUUsedMemory);
sl@0
   200
        }
sl@0
   201
    
sl@0
   202
    if(iLastIterations.Count() > 0)
sl@0
   203
        {
sl@0
   204
        res = Deviation(iLastIterations);
sl@0
   205
        ASSERT_TRUE(iThresholdLastIteration >= res);
sl@0
   206
        INFO_PRINTF3(_L("Last iteration deviation %d %%, threshold %d %%"), res, iThresholdLastIteration);
sl@0
   207
        }
sl@0
   208
    }
sl@0
   209
sl@0
   210
void CEglTest_OOM_Base::RetrieveExtensionDataL()
sl@0
   211
    {
sl@0
   212
    PrintEglResourceProfilingInfoL();
sl@0
   213
    INFO_PRINTF2(_L("Nember iterations before the failure occurs, %d"), iLastIterationNumber);
sl@0
   214
    iLastIterations.Append(iLastIterationNumber);
sl@0
   215
    iLastIterationNumber = -1;
sl@0
   216
    }
sl@0
   217
sl@0
   218
//Print GPU information provided be NOK_resource_profiling2 egl extension
sl@0
   219
//Some data, like GPU usage, will be memorized for further comparison
sl@0
   220
//This extension is optional and may not be present in the system
sl@0
   221
void CEglTest_OOM_Base::PrintEglResourceProfilingInfoL()
sl@0
   222
    {
sl@0
   223
#ifdef SYMBIAN_GRAPHICS_EGL_SGIMAGELITE
sl@0
   224
#ifdef EGL_PROF_MEMORY_USAGE_THRESHOLD_NOK    
sl@0
   225
sl@0
   226
    GetDisplayL();
sl@0
   227
    CreateEglSessionL();
sl@0
   228
    iEglSess->InitializeL();    
sl@0
   229
    
sl@0
   230
    if(!iPFnEglQueryProfilingDataNOK)
sl@0
   231
        {
sl@0
   232
        iPFnEglQueryProfilingDataNOK = (PFNEGLQUERYPROFILINGDATANOKPROC) eglGetProcAddress("eglQueryProfilingDataNOK");
sl@0
   233
    
sl@0
   234
        if(!iPFnEglQueryProfilingDataNOK)
sl@0
   235
            {
sl@0
   236
            CleanAll();
sl@0
   237
            WARN_PRINTF1(_L("NOK_resource_profiling2 extension is not available"));
sl@0
   238
            return;
sl@0
   239
            }
sl@0
   240
        }
sl@0
   241
        
sl@0
   242
    EGLint data_count;
sl@0
   243
    // Find out how much profiling data is available 
sl@0
   244
    iPFnEglQueryProfilingDataNOK(iDisplay, 
sl@0
   245
                             EGL_PROF_QUERY_GLOBAL_BIT_NOK | 
sl@0
   246
                             EGL_PROF_QUERY_MEMORY_USAGE_BIT_NOK,
sl@0
   247
                             NULL,
sl@0
   248
                             0,
sl@0
   249
                             &data_count);
sl@0
   250
sl@0
   251
    // Allocate room for the profiling data
sl@0
   252
    EGLint* prof_data = (EGLint*)User::AllocL(data_count * sizeof(EGLint));
sl@0
   253
sl@0
   254
    CleanupStack::PushL(prof_data);
sl@0
   255
    
sl@0
   256
    // Retrieve the profiling data 
sl@0
   257
    iPFnEglQueryProfilingDataNOK(iDisplay, 
sl@0
   258
                             EGL_PROF_QUERY_GLOBAL_BIT_NOK | 
sl@0
   259
                             EGL_PROF_QUERY_MEMORY_USAGE_BIT_NOK,
sl@0
   260
                             prof_data,
sl@0
   261
                             data_count,
sl@0
   262
                             &data_count);
sl@0
   263
sl@0
   264
    // Iterate over the returned data 
sl@0
   265
    EGLint i = 0;
sl@0
   266
    while (i < data_count)
sl@0
   267
    {
sl@0
   268
        switch (prof_data[i++])
sl@0
   269
        {
sl@0
   270
        case EGL_PROF_TOTAL_MEMORY_NOK:
sl@0
   271
            INFO_PRINTF2(_L("Total memory: %d"), prof_data[i++]);
sl@0
   272
            break;
sl@0
   273
        case EGL_PROF_USED_MEMORY_NOK:
sl@0
   274
            iGPUUsedMemory.AppendL(prof_data[i]);
sl@0
   275
            INFO_PRINTF2(_L("Used memory: %d"), prof_data[i++]);
sl@0
   276
            break;
sl@0
   277
        case EGL_PROF_PROCESS_ID_NOK:    
sl@0
   278
            if(sizeof(EGLNativeProcessIdTypeNOK) == 4)
sl@0
   279
                {
sl@0
   280
                INFO_PRINTF2(_L("Process ID(4 bytes), 0x%08X"), prof_data[i++]);
sl@0
   281
                }
sl@0
   282
            else if(sizeof(EGLNativeProcessIdTypeNOK) == 8)
sl@0
   283
                {
sl@0
   284
                EGLNativeProcessIdTypeNOK processId = ((EGLNativeProcessIdTypeNOK)(prof_data[i])) + (((EGLNativeProcessIdTypeNOK)(prof_data[i + 1]))<<32);
sl@0
   285
                RProcess process;
sl@0
   286
                TProcessId pid(processId);
sl@0
   287
                TInt err = process.Open(pid);
sl@0
   288
                if (err == KErrNone)
sl@0
   289
                    {
sl@0
   290
                    TPtrC ptr(process.FullName());
sl@0
   291
                    INFO_PRINTF4(_L("Process ID, %lu - 0x%lu - %S"), processId, processId, &ptr);
sl@0
   292
                    process.Close();
sl@0
   293
                    }
sl@0
   294
                else
sl@0
   295
                    {//this parameter is not in use in the test, thus is no point to set an error.
sl@0
   296
                    WARN_PRINTF4(_L("Process ID, %lu - 0x%lx, fail to open process with error %d"), processId, processId, err);
sl@0
   297
                    }                    
sl@0
   298
                i += 2;
sl@0
   299
                }
sl@0
   300
            else
sl@0
   301
                {//this parameter is for information only. It doesn't impact our measurement. So there is no need to set an error.
sl@0
   302
                WARN_PRINTF1(_L("Unknown EGLNativeProcessIdTypeNOK"));
sl@0
   303
                }
sl@0
   304
            break;
sl@0
   305
        case EGL_PROF_PROCESS_USED_PRIVATE_MEMORY_NOK:
sl@0
   306
            INFO_PRINTF2(_L("Process used private memory: %d"), prof_data[i++]);
sl@0
   307
            break;
sl@0
   308
        case EGL_PROF_PROCESS_USED_SHARED_MEMORY_NOK:
sl@0
   309
            INFO_PRINTF2(_L("Process used shared memory: %d"), prof_data[i++]);
sl@0
   310
            break;
sl@0
   311
        }
sl@0
   312
    }
sl@0
   313
sl@0
   314
    // Free allocated memory 
sl@0
   315
    CleanupStack::PopAndDestroy(prof_data);
sl@0
   316
    CleanAll();
sl@0
   317
    
sl@0
   318
#endif //EGL_PROF_MEMORY_USAGE_THRESHOLD_NOK    
sl@0
   319
#endif //SYMBIAN_GRAPHICS_EGL_SGIMAGELITE   
sl@0
   320
    }
sl@0
   321
sl@0
   322
/**
sl@0
   323
@SYMTestCaseID GRAPHICS-EGL-0438
sl@0
   324
sl@0
   325
@SYMTestPriority 1
sl@0
   326
sl@0
   327
@SYMPREQ 2637
sl@0
   328
sl@0
   329
@SYMTestCaseDesc
sl@0
   330
    OOM test – Free VG/Egl/Sg Images while the process which owns them is terminated
sl@0
   331
sl@0
   332
@SYMTestActions
sl@0
   333
Environmental settings:
sl@0
   334
•   Image Size: w50 h50
sl@0
   335
•   List of simulated load: 0%
sl@0
   336
•   List of pixel formats
sl@0
   337
ESgPixelFormatARGB_8888
sl@0
   338
•   Client process priorities - all the same
sl@0
   339
•   Client process random parameters:
sl@0
   340
-   None
sl@0
   341
sl@0
   342
The creation of RSgImages and launching of processes is along the lines of the method outlined in GRAPHICS-EGL-RSGIMAGE_LITE-0406
sl@0
   343
sl@0
   344
    From the main process:
sl@0
   345
    For i = 0 to N
sl@0
   346
    Spawn 2 client processes A and B.
sl@0
   347
        Signal all client processes to start by use of a semaphore
sl@0
   348
        Wait until client processes exit
sl@0
   349
    If the test fails not due to the memory allocation record an error code to the log file then set a test result as a failure and skip further actions.
sl@0
   350
    End loop
sl@0
   351
    Exit
sl@0
   352
sl@0
   353
    From client process A:
sl@0
   354
    Get EGL display
sl@0
   355
    Initialize EGL
sl@0
   356
    Open RSgDriver
sl@0
   357
    Create context, pbuffer surface.
sl@0
   358
    Make pbuffer surface current for the given context  
sl@0
   359
    Loop until exit condition met
sl@0
   360
    Start loop:
sl@0
   361
Create SgImage
sl@0
   362
Create EglImage with underlying SgImage
sl@0
   363
    Create VgImage with underlying EglImage
sl@0
   364
    Exit condition – Sg/Egl/Vg image creation has failed.
sl@0
   365
End loop:
sl@0
   366
    Destroy the pbuffer surface
sl@0
   367
Log the last iteration number and exact operation which precedes a failure. 
sl@0
   368
In the environment supporting NOK_resource_profiling2 extension retrieve for further analyzes the following GPU profiling data (if available):
sl@0
   369
•   Total memory
sl@0
   370
•   Used memory
sl@0
   371
•   Process ID
sl@0
   372
•   Process used private memory
sl@0
   373
•   Process used shared memory
sl@0
   374
sl@0
   375
Make the process busy by putting it into the indefinite loop.
sl@0
   376
    
sl@0
   377
    From client process B:
sl@0
   378
    Wait until process A fails with the image creation.
sl@0
   379
    Terminate the process A.
sl@0
   380
sl@0
   381
@SYMTestExpectedResults
sl@0
   382
For each step from 0 to N in the main process, 
sl@0
   383
-   Image allocation failure must happen at approximately the same iteration in process A. 
sl@0
   384
    MaxIterationNumber – MinIterationNumber < Threashold, where Treashold will not 
sl@0
   385
    exceeds 5 and exact value to be defined during implementation. 
sl@0
   386
-   GPU memory usage retrieved through NOK_resource_profiling2 extension, if available, 
sl@0
   387
    is consistent and doesn’t decrease over the time. 
sl@0
   388
    MaxGPUMemoryUsage – MinGPUMemoryUsage < Threshold, where Threshold will not exceed 
sl@0
   389
    5 and exact value to be defined during implementation. 
sl@0
   390
*/
sl@0
   391
TVerdict CEglTest_OOM_CloseVGImageWithTermination::doTestStepL()
sl@0
   392
    {
sl@0
   393
    SetTestStepID(_L("GRAPHICS-EGL-0438"));
sl@0
   394
    SetTestStepName(KOOM_CloseVGImageWithTermination);
sl@0
   395
    INFO_PRINTF1(_L("CEglTest_Benchmark_Multi_Process_CreateCloseImage::doTestStepL"));
sl@0
   396
sl@0
   397
#ifndef SYMBIAN_GRAPHICS_EGL_SGIMAGELITE
sl@0
   398
	INFO_PRINTF1(_L("CEglTest_OOM_CloseVGImageWithTermination can only be run with SgImage-Lite"));
sl@0
   399
#else
sl@0
   400
    TBool ret = CheckForExtensionL(KEGL_RSgimage | KEGL_KHR_image_base | KVG_KHR_EGL_image | KEGL_KHR_image_pixmap);
sl@0
   401
    if(ret)
sl@0
   402
        {
sl@0
   403
        // The extension is supported
sl@0
   404
        // if the test fails not due to the memory allocation, then skip further actions
sl@0
   405
        for(TInt index = 0; (index < iNumIterations) && (TestStepResult()== EPass); index++)
sl@0
   406
            {
sl@0
   407
            // launch 2 processes
sl@0
   408
            Test_MultiProcessL(KEglTestStepDllName, 2, TestStepName());
sl@0
   409
            RetrieveExtensionDataL();
sl@0
   410
            }
sl@0
   411
        CheckDeviation();
sl@0
   412
        }
sl@0
   413
#endif //SYMBIAN_GRAPHICS_EGL_SGIMAGELITE
sl@0
   414
sl@0
   415
    RecordTestResultL();
sl@0
   416
    CloseTMSGraphicsStep();
sl@0
   417
    return TestStepResult();
sl@0
   418
    }
sl@0
   419
sl@0
   420
void CEglTest_OOM_CloseVGImageWithTermination::doProcessFunctionL(TInt aIdx)
sl@0
   421
    {
sl@0
   422
    INFO_PRINTF2(_L("CEglTest_OOM_CloseVGImageWithTermination::doProcessFunctionL, Process %d"),aIdx);
sl@0
   423
#ifdef SYMBIAN_GRAPHICS_EGL_SGIMAGELITE
sl@0
   424
sl@0
   425
    if(aIdx == 0)
sl@0
   426
        {
sl@0
   427
        GetDisplayL();
sl@0
   428
        CreateEglSessionL(aIdx);
sl@0
   429
        iEglSess->InitializeL();    
sl@0
   430
        iEglSess->OpenSgDriverL();
sl@0
   431
sl@0
   432
        //create a dummy surface and context for the purpose of enabling use of VG
sl@0
   433
        TEglTestConfig pbufferFormat = EglTestConversion::VgFormatToPBufferSurfaceFormat(EglTestConversion::PixelFormatToVgFormat(iPixelFormat));
sl@0
   434
        EGLConfig currentConfig = 0;
sl@0
   435
        TRAPD(res, currentConfig = iEglSess->GetConfigExactMatchL( pbufferFormat ));
sl@0
   436
        User::LeaveIfError(res);
sl@0
   437
        
sl@0
   438
        iEglSess->CreatePbufferSurfaceAndMakeCurrentL(currentConfig, iImageSize, EGL_OPENVG_API);
sl@0
   439
        TInt index = 0;
sl@0
   440
        TSgImageInfo imageInfo;
sl@0
   441
        imageInfo.iUsage = ESgUsageBitOpenVgImage | ESgUsageBitOpenVgSurface;
sl@0
   442
        imageInfo.iPixelFormat = iPixelFormat;
sl@0
   443
        imageInfo.iSizeInPixels = iImageSize;
sl@0
   444
        for(;;++index)
sl@0
   445
            {
sl@0
   446
            RSgImage sgImage;
sl@0
   447
            TInt res = sgImage.Create(imageInfo, NULL);
sl@0
   448
            if(res != KErrNone || sgImage.IsNull())
sl@0
   449
                {
sl@0
   450
                INFO_PRINTF5(_L("***Fail to create RSgImage after %d attempts, error: %d, expected %d or %d"), index, res, KErrNoMemory, KErrNoGraphicsMemory);
sl@0
   451
                ASSERT_TRUE((res == KErrNoMemory) || (res == KErrNoGraphicsMemory));
sl@0
   452
                break;
sl@0
   453
                }
sl@0
   454
            EGLImageKHR eglImages = iEglSess->eglCreateImageKhrL(iDisplay,EGL_NO_CONTEXT,EGL_NATIVE_PIXMAP_KHR,&sgImage,const_cast<EGLint *> (KEglImageAttribsPreservedTrue));
sl@0
   455
            EGLint eglError = eglGetError();
sl@0
   456
            if((eglImages == EGL_NO_IMAGE_KHR) || (eglError != EGL_SUCCESS))
sl@0
   457
                {
sl@0
   458
                INFO_PRINTF4(_L("***Fail to create EGLImage after %d attempts, error: %d, expected: %d"), index, eglError, EGL_BAD_ALLOC);
sl@0
   459
                ASSERT_TRUE(eglError == EGL_BAD_ALLOC);
sl@0
   460
                break;
sl@0
   461
                }
sl@0
   462
sl@0
   463
            VGImage vgImage = iEglSess->vgCreateImageTargetKHR((VGeglImageKHR)eglImages);
sl@0
   464
            VGErrorCode vgError = vgGetError();
sl@0
   465
            if(vgImage == VG_INVALID_HANDLE || (vgError != VG_NO_ERROR))
sl@0
   466
                {
sl@0
   467
                INFO_PRINTF4(_L("***Fail to create VGImage after %d attempts, error: %d, expected: %d"), index, vgError, VG_OUT_OF_MEMORY_ERROR);
sl@0
   468
                ASSERT_TRUE(vgError == VG_OUT_OF_MEMORY_ERROR);
sl@0
   469
                break;
sl@0
   470
                }
sl@0
   471
            } //for
sl@0
   472
        SendIndexToMainProcessL(index);
sl@0
   473
        }
sl@0
   474
    Rendezvous(aIdx);
sl@0
   475
    
sl@0
   476
    //create the queue to send/receive Process ID between processes
sl@0
   477
    RMsgQueue<TProcessId> messageQueueProcId;
sl@0
   478
    User::LeaveIfError(messageQueueProcId.Open(EProcSlotMsgQueueProcId, EOwnerProcess));
sl@0
   479
    CleanupClosePushL(messageQueueProcId);
sl@0
   480
    
sl@0
   481
    if(aIdx == 0)
sl@0
   482
        {
sl@0
   483
        // Sending Process ID to other process... so that the other process can kill it.
sl@0
   484
        TProcessId procId = RProcess().Id();
sl@0
   485
        messageQueueProcId.SendBlocking(procId);
sl@0
   486
        CleanupStack::PopAndDestroy(&messageQueueProcId);
sl@0
   487
        //go into indefinite loop which will be terminated by the second process
sl@0
   488
        for(;;) { }
sl@0
   489
        }
sl@0
   490
    else
sl@0
   491
        {
sl@0
   492
        TProcessId procId;
sl@0
   493
        messageQueueProcId.ReceiveBlocking(procId);
sl@0
   494
        CleanupStack::PopAndDestroy(&messageQueueProcId);
sl@0
   495
sl@0
   496
        RProcess process;
sl@0
   497
        ASSERT_TRUE(process.Open(procId) == KErrNone);
sl@0
   498
        process.Kill(KErrNone);
sl@0
   499
        process.Close();
sl@0
   500
        
sl@0
   501
        // small delay to ensure the kernel finishes the clean-up
sl@0
   502
        User::After(1*1000*1000); // 1 second
sl@0
   503
        }
sl@0
   504
#endif //SYMBIAN_GRAPHICS_EGL_SGIMAGELITE
sl@0
   505
    }
sl@0
   506
sl@0
   507
/**
sl@0
   508
@SYMTestCaseID GRAPHICS-EGL-0439
sl@0
   509
sl@0
   510
@SYMTestPriority 1
sl@0
   511
sl@0
   512
@SYMPREQ 2637
sl@0
   513
sl@0
   514
@SYMTestCaseDesc
sl@0
   515
    OOM test – Free VG/Egl/Sg Images while the process which owns them exits gracefully
sl@0
   516
sl@0
   517
@SYMTestActions
sl@0
   518
Environmental settings:
sl@0
   519
•   Image Size: w50 h50
sl@0
   520
•   List of simulated load: 0%
sl@0
   521
•   List of pixel formats
sl@0
   522
ESgPixelFormatARGB_8888
sl@0
   523
•   Client process priorities - all the same
sl@0
   524
•   Client process random parameters:
sl@0
   525
-   None
sl@0
   526
sl@0
   527
The creation of RSgImages and launching of processes is along the lines of the method outlined in GRAPHICS-EGL-RSGIMAGE_LITE-0406
sl@0
   528
sl@0
   529
    From the main process:
sl@0
   530
    For i = 0 to N
sl@0
   531
    Spawn 1 client process.
sl@0
   532
        Signal client process to start by use of a semaphore
sl@0
   533
        Wait until client process exits
sl@0
   534
    If the test fails not due to the memory allocation record an error code to the log file then set a test result as a failure and skip further actions.
sl@0
   535
    End loop
sl@0
   536
    Exit
sl@0
   537
sl@0
   538
    From client process A:
sl@0
   539
    Get EGL display
sl@0
   540
    Initialize EGL
sl@0
   541
    Open RSgDriver
sl@0
   542
    Create context, pbuffer surface.
sl@0
   543
    Make pbuffer surface current for the given context  
sl@0
   544
    Loop until exit condition met
sl@0
   545
    Start loop:
sl@0
   546
Create SgImage
sl@0
   547
Create EglImage with underlying SgImage
sl@0
   548
    Create VgImage with underlying EglImage
sl@0
   549
    Exit condition – Sg/Egl/Vg image creation has failed.
sl@0
   550
End loop:
sl@0
   551
    Destroy the pbuffer surface
sl@0
   552
Log the last iteration number and exact operation which precedes a failure. 
sl@0
   553
Close all allocated graphics resources (Sg/Egl/Vg images)
sl@0
   554
In the environment supporting NOK_resource_profiling2 extension, retrieve for further analyzes the following GPU profiling data (if available):
sl@0
   555
•   Total memory
sl@0
   556
•   Used memory
sl@0
   557
•   Process ID
sl@0
   558
•   Process used private memory
sl@0
   559
•   Process used shared memory
sl@0
   560
sl@0
   561
Terminate EGL
sl@0
   562
Close RSgDriver
sl@0
   563
sl@0
   564
@SYMTestExpectedResults
sl@0
   565
For each step from 0 to N in the main process, 
sl@0
   566
-   Image allocation failure must happen at approximately the same iteration in process A. 
sl@0
   567
    MaxIterationNumber – MinIterationNumber < Threashold, where Treashold will not 
sl@0
   568
    exceeds 5 and exact value to be defined during implementation. 
sl@0
   569
-   GPU memory usage retrieved through NOK_resource_profiling2 extension, if available, 
sl@0
   570
    is consistent and doesn’t decrease over the time.
sl@0
   571
    MaxGPUMemoryUsage – MinGPUMemoryUsage < Threshold, where Threshold will not exceed 
sl@0
   572
    5 and exact value to be defined during implementation. 
sl@0
   573
*/
sl@0
   574
TVerdict CEglTest_OOM_CloseVGImage::doTestStepL()
sl@0
   575
    {
sl@0
   576
    SetTestStepID(_L("GRAPHICS-EGL-0439"));
sl@0
   577
    SetTestStepName(KOOM_CloseVGImage);
sl@0
   578
    INFO_PRINTF1(_L("CEglTest_OOM_CloseVGImage::doTestStepL"));
sl@0
   579
sl@0
   580
#ifndef SYMBIAN_GRAPHICS_EGL_SGIMAGELITE
sl@0
   581
    INFO_PRINTF1(_L("CEglTest_OOM_CloseVGImage can only be run with SgImage-Lite"));
sl@0
   582
#else
sl@0
   583
    TBool ret = CheckForExtensionL(KEGL_RSgimage | KEGL_KHR_image_base | KVG_KHR_EGL_image | KEGL_KHR_image_pixmap);
sl@0
   584
    if(ret)
sl@0
   585
        {
sl@0
   586
        // if the test fails not due to the memory allocation, then skip further actions
sl@0
   587
        for(TInt index = 0; (index < iNumIterations) && (TestStepResult()== EPass); index++)
sl@0
   588
            {
sl@0
   589
            // launch 1 process
sl@0
   590
            Test_MultiProcessL(KEglTestStepDllName, 1, TestStepName());
sl@0
   591
            RetrieveExtensionDataL();
sl@0
   592
            }
sl@0
   593
        CheckDeviation();
sl@0
   594
        }
sl@0
   595
#endif //SYMBIAN_GRAPHICS_EGL_SGIMAGELITE
sl@0
   596
sl@0
   597
    RecordTestResultL();
sl@0
   598
    CloseTMSGraphicsStep();
sl@0
   599
    return TestStepResult();
sl@0
   600
    }
sl@0
   601
sl@0
   602
void CEglTest_OOM_CloseVGImage::doProcessFunctionL(TInt aIdx)
sl@0
   603
    {
sl@0
   604
    INFO_PRINTF2(_L("CEglTest_OOM_CloseVGImage::doProcessFunctionL, Process %d"),aIdx);
sl@0
   605
#ifdef SYMBIAN_GRAPHICS_EGL_SGIMAGELITE
sl@0
   606
    GetDisplayL();
sl@0
   607
    CreateEglSessionL(aIdx);
sl@0
   608
    iEglSess->InitializeL();    
sl@0
   609
    iEglSess->OpenSgDriverL();
sl@0
   610
sl@0
   611
    //create a dummy surface and context for the purpose of enabling use of VG
sl@0
   612
    TEglTestConfig pbufferFormat = EglTestConversion::VgFormatToPBufferSurfaceFormat(EglTestConversion::PixelFormatToVgFormat(iPixelFormat));
sl@0
   613
    EGLConfig currentConfig = 0;
sl@0
   614
    TRAPD(res, currentConfig = iEglSess->GetConfigExactMatchL( pbufferFormat ));
sl@0
   615
    User::LeaveIfError(res);
sl@0
   616
sl@0
   617
    iEglSess->CreatePbufferSurfaceAndMakeCurrentL(currentConfig, iImageSize, EGL_OPENVG_API);
sl@0
   618
    TInt index = 0;
sl@0
   619
    TSgImageInfo imageInfo;
sl@0
   620
    imageInfo.iUsage = ESgUsageBitOpenVgImage | ESgUsageBitOpenVgSurface;
sl@0
   621
    imageInfo.iPixelFormat = iPixelFormat;
sl@0
   622
    imageInfo.iSizeInPixels = iImageSize;
sl@0
   623
sl@0
   624
    for(;;++index)
sl@0
   625
        {
sl@0
   626
        RSgImage sgImage;
sl@0
   627
        TInt res = sgImage.Create(imageInfo, NULL);
sl@0
   628
        if(res != KErrNone || sgImage.IsNull())
sl@0
   629
            {
sl@0
   630
            INFO_PRINTF5(_L("***Fail to create RSgImage after %d attempts, error: %d, expected: %d or %d"), index, res, KErrNoMemory, KErrNoGraphicsMemory);
sl@0
   631
            ASSERT_TRUE((res == KErrNoMemory) || (res == KErrNoGraphicsMemory));
sl@0
   632
            break;
sl@0
   633
            }
sl@0
   634
        iSgImages.AppendL(sgImage);
sl@0
   635
        
sl@0
   636
        EGLImageKHR eglImage = iEglSess->eglCreateImageKhrL(iDisplay,EGL_NO_CONTEXT,EGL_NATIVE_PIXMAP_KHR,&sgImage,const_cast<EGLint *> (KEglImageAttribsPreservedTrue));
sl@0
   637
        EGLint eglError = eglGetError();
sl@0
   638
        if((eglImage == EGL_NO_IMAGE_KHR) || (eglError != EGL_SUCCESS))
sl@0
   639
            {
sl@0
   640
            INFO_PRINTF4(_L("***Fail to create EGLImage after %d attempts, error: %d, expected: %d"), index, eglError, EGL_BAD_ALLOC);
sl@0
   641
            ASSERT_TRUE(eglError == EGL_BAD_ALLOC);
sl@0
   642
            break;
sl@0
   643
            }
sl@0
   644
        iEglImages.AppendL(eglImage);
sl@0
   645
        
sl@0
   646
        VGImage vgImage = iEglSess->vgCreateImageTargetKHR((VGeglImageKHR)eglImage);
sl@0
   647
        VGErrorCode vgError = vgGetError();
sl@0
   648
        if(vgImage == VG_INVALID_HANDLE || (vgError != VG_NO_ERROR))
sl@0
   649
            {
sl@0
   650
            INFO_PRINTF4(_L("***Fail to create VGImage after %d attempts, error: %d, expected: %d"), index, vgError, VG_OUT_OF_MEMORY_ERROR);
sl@0
   651
            ASSERT_TRUE(vgError == VG_OUT_OF_MEMORY_ERROR);
sl@0
   652
            break;
sl@0
   653
            }
sl@0
   654
        iVgImages.AppendL(vgImage);
sl@0
   655
        }
sl@0
   656
sl@0
   657
    SendIndexToMainProcessL(index);
sl@0
   658
    
sl@0
   659
    //now clean everything
sl@0
   660
    CleanGraphicsResources();
sl@0
   661
    iEglSess->CloseSgDriver();
sl@0
   662
    CleanAll();
sl@0
   663
#endif    
sl@0
   664
    }    
sl@0
   665
sl@0
   666
/**
sl@0
   667
@SYMTestCaseID GRAPHICS-EGL-0440
sl@0
   668
sl@0
   669
@SYMTestPriority 1
sl@0
   670
sl@0
   671
@SYMPREQ 2637
sl@0
   672
sl@0
   673
@SYMTestCaseDesc
sl@0
   674
    OOM test – Free SgImages/Pixmap surfaces while the process which owns them is terminated
sl@0
   675
sl@0
   676
@SYMTestActions
sl@0
   677
Environmental settings:
sl@0
   678
•   Image Size: w50 h50
sl@0
   679
•   List of simulated load: 0%
sl@0
   680
•   List of pixel formats
sl@0
   681
ESgPixelFormatARGB_8888
sl@0
   682
•   Client process priorities - all the same
sl@0
   683
•   Client process random parameters:
sl@0
   684
-   None
sl@0
   685
sl@0
   686
The creation of RSgImages and launching of processes is along the lines of the method outlined in GRAPHICS-EGL-RSGIMAGE_LITE-0406
sl@0
   687
sl@0
   688
    From the main process:
sl@0
   689
    For i = 0 to N
sl@0
   690
        Spawn 2 client processes A and B.
sl@0
   691
        Signal all client processes to start by use of a semaphore
sl@0
   692
        Wait until client processes exit
sl@0
   693
    If the test fails not due to the memory allocation record an error code to the log file then set a test result as a failure and skip further actions.
sl@0
   694
    End loop
sl@0
   695
    Exit
sl@0
   696
sl@0
   697
    From client process A:
sl@0
   698
    Get EGL display
sl@0
   699
    Initialize EGL
sl@0
   700
    Open RSgDriver
sl@0
   701
    Loop until exit condition met
sl@0
   702
    Start loop:
sl@0
   703
        Create SgImage
sl@0
   704
        Create Pixmap surface with underlying SgImage
sl@0
   705
        Exit condition – SgImage/Pixmap surface creation has failed.
sl@0
   706
    End loop:
sl@0
   707
    Log the last iteration number and exact operation which precedes a failure. 
sl@0
   708
    In the environment supporting NOK_resource_profiling2 extension retrieve for further analyzes the following GPU profiling data (if available):
sl@0
   709
        •   Total memory
sl@0
   710
        •   Used memory
sl@0
   711
        •   Process ID
sl@0
   712
        •   Process used private memory
sl@0
   713
        •   Process used shared memory
sl@0
   714
    Make the process busy by putting it into the indefinite loop.
sl@0
   715
    
sl@0
   716
    From client process B:
sl@0
   717
    Wait until process A fails with the image/surface creation.
sl@0
   718
    Terminate the process A.
sl@0
   719
sl@0
   720
@SYMTestExpectedResults
sl@0
   721
For each step from 0 to N in the main process, 
sl@0
   722
-   Image or surface allocation failure must happen at approximately the same iteration 
sl@0
   723
    in process A. MaxIterationNumber – MinIterationNumber < Threashold, 
sl@0
   724
    where Treashold will not exceeds 5 and exact value to be defined during implementation. 
sl@0
   725
-   GPU memory usage retrieved through NOK_resource_profiling2 extension, if available, 
sl@0
   726
    is consistent and doesn’t decrease over the time.
sl@0
   727
    MaxGPUMemoryUsage – MinGPUMemoryUsage < Threshold, where Threshold will not exceed 
sl@0
   728
    5 and exact value to be defined during implementation. 
sl@0
   729
*/
sl@0
   730
TVerdict CEglTest_OOM_ClosePixmapSurfaceWithTermination::doTestStepL()
sl@0
   731
    {
sl@0
   732
    SetTestStepID(_L("GRAPHICS-EGL-0438"));
sl@0
   733
    SetTestStepName(KOOM_ClosePixmapSurfaceWithTermination);
sl@0
   734
    INFO_PRINTF1(_L("CEglTest_OOM_ClosePixmapSurfaceWithTermination::doTestStepL"));
sl@0
   735
sl@0
   736
#ifndef SYMBIAN_GRAPHICS_EGL_SGIMAGELITE
sl@0
   737
    INFO_PRINTF1(_L("CEglTest_OOM_ClosePixmapSurfaceWithTermination can only be run with SgImage-Lite"));
sl@0
   738
#else
sl@0
   739
    TBool ret = CheckForExtensionL(KEGL_RSgimage | KEGL_KHR_image_base | KVG_KHR_EGL_image | KEGL_KHR_image_pixmap);
sl@0
   740
    if(ret)
sl@0
   741
        {
sl@0
   742
        // if the test fails not due to the memory allocation, then skip further actions
sl@0
   743
        for(TInt index = 0; (index < iNumIterations) && (TestStepResult()== EPass); index++)
sl@0
   744
            {
sl@0
   745
            // launch 2 processes
sl@0
   746
            Test_MultiProcessL(KEglTestStepDllName, 2, TestStepName());
sl@0
   747
            RetrieveExtensionDataL();
sl@0
   748
            }
sl@0
   749
        CheckDeviation();
sl@0
   750
        }
sl@0
   751
#endif //SYMBIAN_GRAPHICS_EGL_SGIMAGELITE
sl@0
   752
sl@0
   753
    RecordTestResultL();
sl@0
   754
    CloseTMSGraphicsStep();
sl@0
   755
    return TestStepResult();
sl@0
   756
    }
sl@0
   757
sl@0
   758
void CEglTest_OOM_ClosePixmapSurfaceWithTermination::doProcessFunctionL(TInt aIdx)
sl@0
   759
    {
sl@0
   760
    INFO_PRINTF2(_L("CEglTest_OOM_ClosePixmapSurfaceWithTermination::doProcessFunctionL, Process %d"),aIdx);
sl@0
   761
#ifdef SYMBIAN_GRAPHICS_EGL_SGIMAGELITE
sl@0
   762
sl@0
   763
    if(aIdx == 0)
sl@0
   764
        {
sl@0
   765
        GetDisplayL();
sl@0
   766
        CreateEglSessionL(aIdx);
sl@0
   767
        iEglSess->InitializeL();    
sl@0
   768
        iEglSess->OpenSgDriverL();
sl@0
   769
sl@0
   770
        TInt index = 0;
sl@0
   771
        TSgImageInfo imageInfo;
sl@0
   772
        imageInfo.iUsage = ESgUsageBitOpenVgImage | ESgUsageBitOpenVgSurface;
sl@0
   773
        imageInfo.iPixelFormat = iPixelFormat;
sl@0
   774
        imageInfo.iSizeInPixels = iImageSize;
sl@0
   775
sl@0
   776
        for(;;++index)
sl@0
   777
            {
sl@0
   778
            RSgImage sgImage;
sl@0
   779
            TInt res = sgImage.Create(imageInfo, NULL);
sl@0
   780
            if(res != KErrNone || sgImage.IsNull())
sl@0
   781
                {
sl@0
   782
                INFO_PRINTF5(_L("***Fail to create RSgImage after %d attempts, error: %d, expected: %d or %d"), index, res, KErrNoMemory, KErrNoGraphicsMemory);
sl@0
   783
                ASSERT_TRUE((res == KErrNoMemory) || (res == KErrNoGraphicsMemory));
sl@0
   784
                break;
sl@0
   785
                }
sl@0
   786
            
sl@0
   787
            EGLConfig currentConfig = 0;
sl@0
   788
            const EGLint KAttrib[] = { EGL_MATCH_NATIVE_PIXMAP,   (TInt)&sgImage,
sl@0
   789
                                       EGL_RENDERABLE_TYPE,       EGL_OPENVG_BIT,
sl@0
   790
                                       EGL_SURFACE_TYPE,          EGL_PIXMAP_BIT,
sl@0
   791
                                       EGL_NONE };
sl@0
   792
            
sl@0
   793
            EGLint config_size;
sl@0
   794
            ASSERT_EGL_TRUE(eglChooseConfig(iDisplay,KAttrib,&currentConfig,1,&config_size));
sl@0
   795
            ASSERT_TRUE(currentConfig!=0);
sl@0
   796
            
sl@0
   797
            // Create a pixmap surface from the native image
sl@0
   798
            EGLSurface surface = eglCreatePixmapSurface(iDisplay, currentConfig, &sgImage, NULL);
sl@0
   799
            EGLint eglError = eglGetError();
sl@0
   800
            if((surface == EGL_NO_SURFACE) || (eglError != EGL_SUCCESS))
sl@0
   801
                {
sl@0
   802
                INFO_PRINTF4(_L("***Fail to create Pixmap surface after %d attempts, error: %d, expected: %d"), index, eglError, EGL_BAD_ALLOC);
sl@0
   803
                ASSERT_TRUE(eglError == EGL_BAD_ALLOC);
sl@0
   804
                break;
sl@0
   805
                }            
sl@0
   806
            } //for
sl@0
   807
        SendIndexToMainProcessL(index);
sl@0
   808
        }
sl@0
   809
    Rendezvous(aIdx);
sl@0
   810
    
sl@0
   811
    //create the queue to send/receive Process ID between processes
sl@0
   812
    RMsgQueue<TProcessId> messageQueueProcId;
sl@0
   813
    User::LeaveIfError(messageQueueProcId.Open(EProcSlotMsgQueueProcId, EOwnerProcess));
sl@0
   814
    CleanupClosePushL(messageQueueProcId);
sl@0
   815
    
sl@0
   816
    if(aIdx == 0)
sl@0
   817
        {
sl@0
   818
        // Sending Process ID to other process... so that the other process can kill it.
sl@0
   819
        TProcessId procId = RProcess().Id();
sl@0
   820
        messageQueueProcId.SendBlocking(procId);
sl@0
   821
        CleanupStack::PopAndDestroy(&messageQueueProcId);
sl@0
   822
        //go into indefinite loop which will be terminated by the second process
sl@0
   823
        for(;;) { }
sl@0
   824
        }
sl@0
   825
    else
sl@0
   826
        {
sl@0
   827
        TProcessId procId;
sl@0
   828
        messageQueueProcId.ReceiveBlocking(procId);
sl@0
   829
        CleanupStack::PopAndDestroy(&messageQueueProcId);
sl@0
   830
sl@0
   831
        RProcess process;
sl@0
   832
        ASSERT_TRUE(process.Open(procId) == KErrNone);
sl@0
   833
        process.Kill(KErrNone);
sl@0
   834
		process.Close();
sl@0
   835
sl@0
   836
        // small delay to ensure the kernel finishes the clean-up
sl@0
   837
        User::After(1*1000*1000); // 1 second
sl@0
   838
        }
sl@0
   839
#endif //SYMBIAN_GRAPHICS_EGL_SGIMAGELITE
sl@0
   840
    }
sl@0
   841
sl@0
   842
/**
sl@0
   843
@SYMTestCaseID GRAPHICS-EGL-0441
sl@0
   844
sl@0
   845
@SYMTestPriority 1
sl@0
   846
sl@0
   847
@SYMPREQ 2637
sl@0
   848
sl@0
   849
@SYMTestCaseDesc
sl@0
   850
    OOM test – Free SgImages/Pixmap surfaces while the process which owns them exits gracefully
sl@0
   851
sl@0
   852
@SYMTestActions
sl@0
   853
Environmental settings:
sl@0
   854
•   Image Size: w50 h50
sl@0
   855
•   List of simulated load: 0%
sl@0
   856
•   List of pixel formats
sl@0
   857
ESgPixelFormatARGB_8888
sl@0
   858
•   Client process priorities - all the same
sl@0
   859
•   Client process random parameters:
sl@0
   860
-   None
sl@0
   861
sl@0
   862
The creation of RSgImages and launching of processes is along the lines of the method outlined in GRAPHICS-EGL-RSGIMAGE_LITE-0406
sl@0
   863
sl@0
   864
    From the main process:
sl@0
   865
    For i = 0 to N
sl@0
   866
        Spawn 1 client process.
sl@0
   867
        Signal client process to start by use of a semaphore
sl@0
   868
        Wait until client process exits
sl@0
   869
    If the test fails not due to the memory allocation record an error code to the log file then set a test result as a failure and skip further actions.
sl@0
   870
    End loop
sl@0
   871
    Exit
sl@0
   872
sl@0
   873
    From client process A:
sl@0
   874
    Get EGL display
sl@0
   875
    Initialize EGL
sl@0
   876
    Open RSgDriver
sl@0
   877
    Loop until exit condition met
sl@0
   878
    Start loop:
sl@0
   879
        Create SgImage
sl@0
   880
        Create Pixmap surface with underlying SgImage
sl@0
   881
        Exit condition – SgImage/Pixmap surface creation has failed.
sl@0
   882
    End loop:
sl@0
   883
    Log the last iteration number and exact operation which precedes a failure.
sl@0
   884
    CLose all allocated graphics resources (SgImages/Pixmap surfaces) 
sl@0
   885
    In the environment supporting NOK_resource_profiling2 extension retrieve for further analyzes the following GPU profiling data (if available):
sl@0
   886
        •   Total memory
sl@0
   887
        •   Used memory
sl@0
   888
        •   Process ID
sl@0
   889
        •   Process used private memory
sl@0
   890
        •   Process used shared memory
sl@0
   891
    Terminate EGL
sl@0
   892
    Close RSgDriver
sl@0
   893
sl@0
   894
@SYMTestExpectedResults
sl@0
   895
For each step from 0 to N in the main process, 
sl@0
   896
-   Image or surface allocation failure must happen at approximately the same iteration in process A. 
sl@0
   897
    MaxIterationNumber – MinIterationNumber < Threashold, 
sl@0
   898
    where Treashold will not exceeds 5 and exact value to be defined during implementation. 
sl@0
   899
-   GPU memory usage retrieved through NOK_resource_profiling2 extension, 
sl@0
   900
    if available, is consistent and doesn’t decrease over the time. 
sl@0
   901
*/
sl@0
   902
TVerdict CEglTest_OOM_ClosePixmapSurface::doTestStepL()
sl@0
   903
    {
sl@0
   904
    SetTestStepID(_L("GRAPHICS-EGL-0441"));
sl@0
   905
    SetTestStepName(KOOM_ClosePixmapSurface);
sl@0
   906
    INFO_PRINTF1(_L("CEglTest_OOM_ClosePixmapSurface::doTestStepL"));
sl@0
   907
sl@0
   908
#ifndef SYMBIAN_GRAPHICS_EGL_SGIMAGELITE
sl@0
   909
    INFO_PRINTF1(_L("CEglTest_OOM_ClosePixmapSurface can only be run with SgImage-Lite"));
sl@0
   910
#else
sl@0
   911
    TBool ret = CheckForExtensionL(KEGL_RSgimage | KEGL_KHR_image_base | KVG_KHR_EGL_image | KEGL_KHR_image_pixmap);
sl@0
   912
    if(ret)
sl@0
   913
        {
sl@0
   914
        // if the test fails not due to the memory allocation, then skip further actions
sl@0
   915
        for(TInt index = 0; (index < iNumIterations) && (TestStepResult()== EPass); index++)
sl@0
   916
            {
sl@0
   917
            // launch 1 process
sl@0
   918
            Test_MultiProcessL(KEglTestStepDllName, 1, TestStepName());
sl@0
   919
            RetrieveExtensionDataL();
sl@0
   920
            } //for
sl@0
   921
        CheckDeviation();
sl@0
   922
        }
sl@0
   923
#endif //SYMBIAN_GRAPHICS_EGL_SGIMAGELITE
sl@0
   924
sl@0
   925
    RecordTestResultL();
sl@0
   926
    CloseTMSGraphicsStep();
sl@0
   927
    return TestStepResult();
sl@0
   928
    }
sl@0
   929
sl@0
   930
void CEglTest_OOM_ClosePixmapSurface::doProcessFunctionL(TInt aIdx)
sl@0
   931
    {
sl@0
   932
    INFO_PRINTF2(_L("CEglTest_OOM_ClosePixmapSurface::doProcessFunctionL, Process %d"),aIdx);
sl@0
   933
#ifdef SYMBIAN_GRAPHICS_EGL_SGIMAGELITE
sl@0
   934
    GetDisplayL();
sl@0
   935
    CreateEglSessionL(aIdx);
sl@0
   936
    iEglSess->InitializeL();    
sl@0
   937
    iEglSess->OpenSgDriverL();
sl@0
   938
sl@0
   939
    TInt index = 0;
sl@0
   940
    TSgImageInfo imageInfo;
sl@0
   941
    imageInfo.iUsage = ESgUsageBitOpenVgImage | ESgUsageBitOpenVgSurface;
sl@0
   942
    imageInfo.iPixelFormat = iPixelFormat;
sl@0
   943
    imageInfo.iSizeInPixels = iImageSize;
sl@0
   944
sl@0
   945
    for(;;++index)
sl@0
   946
        {
sl@0
   947
        RSgImage sgImage;
sl@0
   948
        TInt res = sgImage.Create(imageInfo, NULL);
sl@0
   949
        if(res != KErrNone || sgImage.IsNull())
sl@0
   950
            {
sl@0
   951
            INFO_PRINTF5(_L("***Fail to create RSgImage after %d attempts, error: %d, expected: %d or %d"), index, res, KErrNoMemory, KErrNoGraphicsMemory);
sl@0
   952
            ASSERT_TRUE((res == KErrNoMemory) || (res == KErrNoGraphicsMemory));
sl@0
   953
            break;
sl@0
   954
            }
sl@0
   955
        iSgImages.AppendL(sgImage);
sl@0
   956
        
sl@0
   957
        EGLConfig currentConfig = 0;
sl@0
   958
        const EGLint KAttrib[] = { EGL_MATCH_NATIVE_PIXMAP,   (TInt)&sgImage,
sl@0
   959
                                   EGL_RENDERABLE_TYPE,       EGL_OPENVG_BIT,
sl@0
   960
                                   EGL_SURFACE_TYPE,          EGL_PIXMAP_BIT,
sl@0
   961
                                   EGL_NONE };
sl@0
   962
        
sl@0
   963
        EGLint config_size;
sl@0
   964
        ASSERT_EGL_TRUE(eglChooseConfig(iDisplay,KAttrib,&currentConfig,1,&config_size));
sl@0
   965
        ASSERT_TRUE(currentConfig!=0);
sl@0
   966
        
sl@0
   967
        // Create a pixmap surface from the native image
sl@0
   968
        EGLSurface surface = eglCreatePixmapSurface(iDisplay, currentConfig, &sgImage, NULL);
sl@0
   969
        EGLint eglError = eglGetError();
sl@0
   970
        if((surface == EGL_NO_SURFACE) || (eglError != EGL_SUCCESS))
sl@0
   971
            {
sl@0
   972
            INFO_PRINTF4(_L("***Fail to create Pixmap surface after %d attempts, error: %d, expected: %d "), index, eglError, EGL_BAD_ALLOC);
sl@0
   973
            ASSERT_TRUE(eglError == EGL_BAD_ALLOC);
sl@0
   974
            break;
sl@0
   975
            }       
sl@0
   976
        iSurfaces.AppendL(surface);
sl@0
   977
        } //for
sl@0
   978
    SendIndexToMainProcessL(index);
sl@0
   979
    //now clean everything
sl@0
   980
    CleanGraphicsResources();
sl@0
   981
    iEglSess->CloseSgDriver();
sl@0
   982
    CleanAll();
sl@0
   983
#endif    
sl@0
   984
    }    
sl@0
   985
sl@0
   986
/**
sl@0
   987
@SYMTestCaseID GRAPHICS-EGL-0442
sl@0
   988
sl@0
   989
@SYMTestPriority 1
sl@0
   990
sl@0
   991
@SYMPREQ 2637
sl@0
   992
sl@0
   993
@SYMTestCaseDesc
sl@0
   994
    OOM test – Check SgImages are removed when SgImage handles in multiple processes are closed
sl@0
   995
sl@0
   996
@SYMTestActions
sl@0
   997
Environmental settings:
sl@0
   998
•   Image Size: as per ini file
sl@0
   999
•   List of simulated load: 0%
sl@0
  1000
•   List of pixel formats
sl@0
  1001
ESgPixelFormatARGB_8888
sl@0
  1002
•   Client process priorities - all the same
sl@0
  1003
•   Client process random parameters:
sl@0
  1004
-   None
sl@0
  1005
sl@0
  1006
The creation of RSgImages and launching of processes is along the lines of the method outlined in GRAPHICS-EGL-RSGIMAGE_LITE-0406
sl@0
  1007
sl@0
  1008
    From the main process:
sl@0
  1009
        Spawn 2 client processes A and B.
sl@0
  1010
        Wait until client processes exit
sl@0
  1011
    If the test fails not due to the memory allocation record an error code to the log file then set a test result as a failure and skip further actions.
sl@0
  1012
    End loop
sl@0
  1013
    Exit
sl@0
  1014
sl@0
  1015
    From client process A:
sl@0
  1016
    Get EGL display
sl@0
  1017
    Initialize EGL
sl@0
  1018
    Open RSgDriver
sl@0
  1019
    Loop until exit condition met
sl@0
  1020
    Start loop:
sl@0
  1021
        Create SgImage
sl@0
  1022
        Exit condition – SgImage surface creation has failed.
sl@0
  1023
    End loop:
sl@0
  1024
    Make the process busy by putting it into the indefinite loop.
sl@0
  1025
    
sl@0
  1026
    From client process B:
sl@0
  1027
    Start loop:
sl@0
  1028
        Open SgImage
sl@0
  1029
        Close SgImage
sl@0
  1030
    End loop:
sl@0
  1031
sl@0
  1032
    From client process A:
sl@0
  1033
    Start loop:
sl@0
  1034
        Close SgImage
sl@0
  1035
    End loop:
sl@0
  1036
    Check all memory has been deallocated by starting a second loop
sl@0
  1037
        Start loop 2:
sl@0
  1038
            Create SgImage
sl@0
  1039
            Exit condition – SgImage surface creation has failed.
sl@0
  1040
        End loop:
sl@0
  1041
    Check that the amount of images created within this loop 2 is similar to loop 1,
sl@0
  1042
    meaning that all images were correctly freed.
sl@0
  1043
    Cleanup everything
sl@0
  1044
    
sl@0
  1045
    Terminate process A
sl@0
  1046
    Terminate process B
sl@0
  1047
    
sl@0
  1048
@SYMTestExpectedResults
sl@0
  1049
For each step from 0 to N in the main process, 
sl@0
  1050
-   Image or surface allocation failure must happen at approximately the same iteration 
sl@0
  1051
    in process A.  
sl@0
  1052
*/
sl@0
  1053
TVerdict CEglTest_OOM_CloseSgImageDifferentProcess::doTestStepL()
sl@0
  1054
    {
sl@0
  1055
    SetTestStepID(_L("GRAPHICS-EGL-0442"));
sl@0
  1056
    SetTestStepName(KOOM_CloseSgImageDifferentProcess);
sl@0
  1057
    INFO_PRINTF1(_L("CEglTest_OOM_CloseSgImageDifferentProcess::doTestStepL"));
sl@0
  1058
sl@0
  1059
#ifndef SYMBIAN_GRAPHICS_EGL_SGIMAGELITE
sl@0
  1060
    INFO_PRINTF1(_L("CEglTest_OOM_CloseSgImageDifferentProcess can only be run with SgImage-Lite"));
sl@0
  1061
#else
sl@0
  1062
    TBool ret = CheckForExtensionL(KEGL_RSgimage | KEGL_KHR_image_base | KVG_KHR_EGL_image | KEGL_KHR_image_pixmap);
sl@0
  1063
    if(ret)
sl@0
  1064
        {
sl@0
  1065
        // launch 2 processes
sl@0
  1066
        Test_MultiProcessL(KEglTestStepDllName, 2, TestStepName());
sl@0
  1067
        }
sl@0
  1068
    INFO_PRINTF1(_L("Exit: CEglTest_OOM_CloseSgImageDifferentProcess::doTestStepL"));
sl@0
  1069
#endif //SYMBIAN_GRAPHICS_EGL_SGIMAGELITE
sl@0
  1070
    RecordTestResultL();
sl@0
  1071
    CloseTMSGraphicsStep();
sl@0
  1072
    return TestStepResult();
sl@0
  1073
    }
sl@0
  1074
sl@0
  1075
void CEglTest_OOM_CloseSgImageDifferentProcess::doProcessFunctionL(TInt aIdx)
sl@0
  1076
    {
sl@0
  1077
    INFO_PRINTF2(_L("CEglTest_OOM_CloseSgImageDifferentProcess::doProcessFunctionL, Process %d"),aIdx);
sl@0
  1078
#ifdef SYMBIAN_GRAPHICS_EGL_SGIMAGELITE
sl@0
  1079
sl@0
  1080
    GetDisplayL();
sl@0
  1081
    CreateEglSessionL(aIdx);
sl@0
  1082
    iEglSess->InitializeL();
sl@0
  1083
    iEglSess->OpenSgDriverL();
sl@0
  1084
sl@0
  1085
    //create the queue to send/receive SgImage ID between processes
sl@0
  1086
    RMsgQueue<TSgDrawableId> messageQueueSgId;
sl@0
  1087
    User::LeaveIfError(messageQueueSgId.Open(EProcSlotMsgQueueSgId, EOwnerProcess));
sl@0
  1088
    CleanupClosePushL(messageQueueSgId);
sl@0
  1089
sl@0
  1090
    // create as many sgimages until it reaches out of memory
sl@0
  1091
    TInt numImages = 0;
sl@0
  1092
    if(aIdx == 0)
sl@0
  1093
        {
sl@0
  1094
        for(;;++numImages)
sl@0
  1095
            {
sl@0
  1096
            RSgImage sgImage;
sl@0
  1097
            TInt res = sgImage.Create(TSgImageInfo(iImageSize, KOOMPixelFormat, ESgUsageBitOpenVgImage));
sl@0
  1098
            if(res != KErrNone || sgImage.IsNull())
sl@0
  1099
                {
sl@0
  1100
                INFO_PRINTF5(_L("***Fail to create RSgImage after %d attempts, error: %d, expected: %d or %d"), numImages, res, KErrNoMemory, KErrNoGraphicsMemory);
sl@0
  1101
                ASSERT_TRUE((res == KErrNoMemory) || (res == KErrNoGraphicsMemory));
sl@0
  1102
                break;
sl@0
  1103
                }
sl@0
  1104
            iSgImages.AppendL(sgImage);
sl@0
  1105
            }
sl@0
  1106
        }
sl@0
  1107
    
sl@0
  1108
    // Send to process B how many images it needs to wait for
sl@0
  1109
    if(aIdx == 0)
sl@0
  1110
        {
sl@0
  1111
       // send a TInt as a  fake SgImage Id
sl@0
  1112
        messageQueueSgId.SendBlocking(reinterpret_cast<TSgDrawableId&>(numImages));
sl@0
  1113
        }
sl@0
  1114
    else if (aIdx == 1)
sl@0
  1115
        {
sl@0
  1116
        // receive the fake SgImage Id and convert it to a TInt
sl@0
  1117
        TSgDrawableId fakeId;
sl@0
  1118
        messageQueueSgId.ReceiveBlocking(fakeId);
sl@0
  1119
        numImages = reinterpret_cast<TInt&>(fakeId);
sl@0
  1120
        }
sl@0
  1121
    
sl@0
  1122
    // Wait for both processes to reach this point
sl@0
  1123
    Rendezvous(aIdx);
sl@0
  1124
    
sl@0
  1125
    // Now process B knows how many images needs to wait for
sl@0
  1126
    if(aIdx == 0)
sl@0
  1127
        {
sl@0
  1128
        for(TInt index = 0; index<numImages; ++index)
sl@0
  1129
            {
sl@0
  1130
            // send Id to other process
sl@0
  1131
            messageQueueSgId.SendBlocking(iSgImages[index].Id());
sl@0
  1132
            }
sl@0
  1133
        }
sl@0
  1134
    else if(aIdx == 1)
sl@0
  1135
        {
sl@0
  1136
        for(TInt index = 0; index<numImages; ++index)
sl@0
  1137
            {
sl@0
  1138
            // receive Id from other process
sl@0
  1139
            TSgDrawableId sgImageId;
sl@0
  1140
            messageQueueSgId.ReceiveBlocking(sgImageId);
sl@0
  1141
            
sl@0
  1142
            // open sgImage with received Id
sl@0
  1143
            RSgImage sgImage;
sl@0
  1144
            ASSERT_EQUALS(sgImage.Open(sgImageId), KErrNone);
sl@0
  1145
sl@0
  1146
            // close SgImage just created
sl@0
  1147
            sgImage.Close();
sl@0
  1148
            }
sl@0
  1149
        }
sl@0
  1150
sl@0
  1151
    // Wait for both processes to reach this point
sl@0
  1152
    Rendezvous(aIdx);
sl@0
  1153
sl@0
  1154
    // delete all sgImages created in first process
sl@0
  1155
    if(aIdx == 0)
sl@0
  1156
        {
sl@0
  1157
        CleanGraphicsResources();
sl@0
  1158
        }
sl@0
  1159
sl@0
  1160
    // create (again) as many sgimages until it reaches out of memory
sl@0
  1161
    // note that process B needs to be alive (hence the Rendezvous further down)
sl@0
  1162
    if(aIdx == 0)
sl@0
  1163
        {
sl@0
  1164
        TInt numImages2 = 0;
sl@0
  1165
        for(;;++numImages2)
sl@0
  1166
            {
sl@0
  1167
            RSgImage sgImage;
sl@0
  1168
            TInt res = sgImage.Create(TSgImageInfo(iImageSize, KOOMPixelFormat, ESgUsageBitOpenVgImage));
sl@0
  1169
            if(res != KErrNone || sgImage.IsNull())
sl@0
  1170
                {
sl@0
  1171
                INFO_PRINTF5(_L("***Fail to create RSgImage after %d attempts, error: %d, expected: %d or %d"), numImages2, res, KErrNoMemory, KErrNoGraphicsMemory);
sl@0
  1172
                ASSERT_TRUE((res == KErrNoMemory) || (res == KErrNoGraphicsMemory));
sl@0
  1173
                break;
sl@0
  1174
                }
sl@0
  1175
            iSgImages.AppendL(sgImage);
sl@0
  1176
            }
sl@0
  1177
        // clean up these images, we don't really need them
sl@0
  1178
        CleanGraphicsResources();
sl@0
  1179
        
sl@0
  1180
        // check numbers...
sl@0
  1181
        INFO_PRINTF2(_L("***Num sgImages created first time: %d."), numImages);
sl@0
  1182
        INFO_PRINTF2(_L("***Num sgImages created second time: %d."), numImages2);
sl@0
  1183
        TInt deviation = Abs(((numImages2*100) / numImages) - 100);
sl@0
  1184
        ASSERT_TRUE(deviation < KOOMSgImageDeviation);
sl@0
  1185
        INFO_PRINTF3(_L("***Deviation: %d%% (must be less than %d%%)"), deviation, KOOMSgImageDeviation);
sl@0
  1186
sl@0
  1187
        // This test does not need to send anything, but since OOM test framework expects something
sl@0
  1188
        // we can send a fake index so that the test is not waiting for it forever.
sl@0
  1189
        const TInt KTestNotUsedData = 0;
sl@0
  1190
        SendIndexToMainProcessL(KTestNotUsedData); 
sl@0
  1191
        }
sl@0
  1192
sl@0
  1193
    // Wait for both processes to reach this point
sl@0
  1194
    Rendezvous(aIdx);
sl@0
  1195
sl@0
  1196
    //now clean everything
sl@0
  1197
    CleanupStack::PopAndDestroy(&messageQueueSgId);
sl@0
  1198
    CleanGraphicsResources();
sl@0
  1199
    iEglSess->CloseSgDriver();
sl@0
  1200
    CleanAll();
sl@0
  1201
#endif //SYMBIAN_GRAPHICS_EGL_SGIMAGELITE
sl@0
  1202
    }
sl@0
  1203
sl@0
  1204
/**
sl@0
  1205
@SYMTestCaseID GRAPHICS-EGL-0443
sl@0
  1206
sl@0
  1207
@SYMTestPriority 1
sl@0
  1208
sl@0
  1209
@SYMPREQ 2637
sl@0
  1210
sl@0
  1211
@SYMTestCaseDesc
sl@0
  1212
    OOM test – Check SgImages are removed when SgImage handles in multiple processes are closed
sl@0
  1213
sl@0
  1214
@SYMTestActions
sl@0
  1215
Environmental settings:
sl@0
  1216
•   Image Size: as per ini file
sl@0
  1217
•   List of simulated load: 0%
sl@0
  1218
•   List of pixel formats
sl@0
  1219
ESgPixelFormatARGB_8888
sl@0
  1220
•   Client process priorities - all the same
sl@0
  1221
•   Client process random parameters:
sl@0
  1222
-   None
sl@0
  1223
sl@0
  1224
The creation of RSgImages and launching of processes is along the lines of the method outlined in GRAPHICS-EGL-RSGIMAGE_LITE-0406
sl@0
  1225
sl@0
  1226
    From the main process:
sl@0
  1227
    From client process A:
sl@0
  1228
    Get EGL display
sl@0
  1229
    Initialize EGL
sl@0
  1230
    Open RSgDriver
sl@0
  1231
    Loop until exit condition met
sl@0
  1232
    Start loop:
sl@0
  1233
        Create SgImage
sl@0
  1234
        Exit condition – SgImage surface creation has failed.
sl@0
  1235
    End loop:
sl@0
  1236
    Start loop:
sl@0
  1237
        Open SgImage
sl@0
  1238
        Close SgImage
sl@0
  1239
    End loop:
sl@0
  1240
    Start loop:
sl@0
  1241
        Close SgImage
sl@0
  1242
    End loop:
sl@0
  1243
    Check all memory has been deallocated by starting a second loop
sl@0
  1244
        Start loop 2:
sl@0
  1245
            Create SgImage
sl@0
  1246
            Exit condition – SgImage surface creation has failed.
sl@0
  1247
        End loop:
sl@0
  1248
    Check that the amount of images created within this loop 2 is similar to loop 1,
sl@0
  1249
    meaning that all images were correctly freed.
sl@0
  1250
    Cleanup everything
sl@0
  1251
    
sl@0
  1252
@SYMTestExpectedResults
sl@0
  1253
For each step from 0 to N in the main process, 
sl@0
  1254
-   Image or surface allocation failure must happen at approximately the same iteration 
sl@0
  1255
    in process A.  
sl@0
  1256
*/
sl@0
  1257
TVerdict CEglTest_OOM_CloseSgImageSameThread::doTestStepL()
sl@0
  1258
    {
sl@0
  1259
    SetTestStepID(_L("GRAPHICS-EGL-0443"));
sl@0
  1260
    SetTestStepName(KOOM_CloseSgImageSameThread);
sl@0
  1261
    INFO_PRINTF1(_L("CEglTest_OOM_CloseSgImageSameThread::doTestStepL"));
sl@0
  1262
sl@0
  1263
#ifndef SYMBIAN_GRAPHICS_EGL_SGIMAGELITE
sl@0
  1264
    INFO_PRINTF1(_L("CEglTest_OOM_CloseSgImageSameThread can only be run with SgImage-Lite"));
sl@0
  1265
#else
sl@0
  1266
    TBool ret = CheckForExtensionL(KEGL_RSgimage | KEGL_KHR_image_base | KVG_KHR_EGL_image | KEGL_KHR_image_pixmap);
sl@0
  1267
    if(ret)
sl@0
  1268
        {
sl@0
  1269
        GetDisplayL();
sl@0
  1270
        CreateEglSessionL(0);
sl@0
  1271
        iEglSess->InitializeL();
sl@0
  1272
        iEglSess->OpenSgDriverL();
sl@0
  1273
    
sl@0
  1274
        // create as many sgimages until it reaches out of memory
sl@0
  1275
        TInt numImages = 0;
sl@0
  1276
        for(;;++numImages)
sl@0
  1277
            {
sl@0
  1278
            RSgImage sgImage;
sl@0
  1279
            TInt res = sgImage.Create(TSgImageInfo(iImageSize, KOOMPixelFormat, ESgUsageBitOpenVgImage));
sl@0
  1280
            if(res != KErrNone || sgImage.IsNull())
sl@0
  1281
                {
sl@0
  1282
                INFO_PRINTF5(_L("***Fail to create RSgImage after %d attempts, error: %d, expected: %d or %d"), numImages, res, KErrNoMemory, KErrNoGraphicsMemory);
sl@0
  1283
                ASSERT_TRUE((res == KErrNoMemory) || (res == KErrNoGraphicsMemory));
sl@0
  1284
                break;
sl@0
  1285
                }
sl@0
  1286
            iSgImages.AppendL(sgImage);
sl@0
  1287
            }
sl@0
  1288
sl@0
  1289
        //open a duplicate handle for the created images (can close straightaway)
sl@0
  1290
        for(TInt index = 0; index<numImages; ++index)
sl@0
  1291
            {
sl@0
  1292
            RSgImage sgImage;
sl@0
  1293
            ASSERT_EQUALS(sgImage.Open(iSgImages[index].Id()), KErrNone);
sl@0
  1294
            // close SgImage just created
sl@0
  1295
            sgImage.Close();
sl@0
  1296
            }
sl@0
  1297
sl@0
  1298
        // clean up all (original) images
sl@0
  1299
        CleanGraphicsResources();
sl@0
  1300
sl@0
  1301
        // create (again) as many sgimages until it reaches out of memory
sl@0
  1302
        TInt numImages2 = 0;
sl@0
  1303
        for(;;++numImages2)
sl@0
  1304
            {
sl@0
  1305
            RSgImage sgImage;
sl@0
  1306
            TInt res = sgImage.Create(TSgImageInfo(iImageSize, KOOMPixelFormat, ESgUsageBitOpenVgImage));
sl@0
  1307
            if(res != KErrNone || sgImage.IsNull())
sl@0
  1308
                {
sl@0
  1309
                INFO_PRINTF5(_L("***Fail to create RSgImage after %d attempts, error: %d, expected: %d or %d"), numImages2, res, KErrNoMemory, KErrNoGraphicsMemory);
sl@0
  1310
                ASSERT_TRUE((res == KErrNoMemory) || (res == KErrNoGraphicsMemory));
sl@0
  1311
                break;
sl@0
  1312
                }
sl@0
  1313
            iSgImages.AppendL(sgImage);
sl@0
  1314
            }
sl@0
  1315
            
sl@0
  1316
        // clean up everything now
sl@0
  1317
        CleanGraphicsResources();
sl@0
  1318
        iEglSess->CloseSgDriver();
sl@0
  1319
        CleanAll();
sl@0
  1320
sl@0
  1321
        // check numbers...
sl@0
  1322
        INFO_PRINTF2(_L("***Num sgImages created first time: %d."), numImages);
sl@0
  1323
        INFO_PRINTF2(_L("***Num sgImages created second time: %d."), numImages2);
sl@0
  1324
        TInt deviation = Abs(((numImages2*100) / numImages) - 100);
sl@0
  1325
        ASSERT_TRUE(deviation < KOOMSgImageDeviation);
sl@0
  1326
        INFO_PRINTF3(_L("***Deviation: %d%% (must be less than %d%%)"), deviation, KOOMSgImageDeviation);
sl@0
  1327
        }
sl@0
  1328
    INFO_PRINTF1(_L("Exit: CEglTest_OOM_CloseSgImageSameThread::doTestStepL"));
sl@0
  1329
#endif //SYMBIAN_GRAPHICS_EGL_SGIMAGELITE
sl@0
  1330
sl@0
  1331
    RecordTestResultL();
sl@0
  1332
    CloseTMSGraphicsStep();
sl@0
  1333
    return TestStepResult();
sl@0
  1334
    }
sl@0
  1335